本文整理汇总了C++中SkAutoTUnref::get方法的典型用法代码示例。如果您正苦于以下问题:C++ SkAutoTUnref::get方法的具体用法?C++ SkAutoTUnref::get怎么用?C++ SkAutoTUnref::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkAutoTUnref
的用法示例。
在下文中一共展示了SkAutoTUnref::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SkPaintToGrPaintWithTexture
bool SkPaintToGrPaintWithTexture(GrContext* context,
const SkPaint& paint,
const SkMatrix& viewM,
const GrFragmentProcessor* fp,
bool textureIsAlphaOnly,
GrPaint* grPaint) {
SkAutoTUnref<const GrFragmentProcessor> shaderFP;
if (textureIsAlphaOnly) {
if (const SkShader* shader = paint.getShader()) {
shaderFP.reset(shader->asFragmentProcessor(context,
viewM,
nullptr,
paint.getFilterQuality()));
if (!shaderFP) {
return false;
}
const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp };
shaderFP.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2));
} else {
shaderFP.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp));
}
} else {
shaderFP.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
}
return SkPaintToGrPaintReplaceShader(context, paint, shaderFP.get(), grPaint);
}
示例2: onNewPictureSnapshot
SkPicture* onNewPictureSnapshot() override {
SkBigPicture::SnapshotArray* pictList = NULL;
if (fDrawableList) {
// TODO: should we plumb-down the BBHFactory and recordFlags from our host
// PictureRecorder?
pictList = fDrawableList->newDrawableSnapshot();
}
SkAutoTUnref<SkLayerInfo> saveLayerData;
if (fBBH && fDoSaveLayerInfo) {
saveLayerData.reset(SkNEW(SkLayerInfo));
SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (received in constructor)
// TODO: update saveLayer info computation to reuse the already computed
// bounds in 'fBBH'
SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerData);
}
size_t subPictureBytes = 0;
for (int i = 0; pictList && i < pictList->count(); i++) {
subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin()[i]);
}
// SkBigPicture will take ownership of a ref on both fRecord and fBBH.
// We're not willing to give up our ownership, so we must ref them for SkPicture.
return SkNEW_ARGS(SkBigPicture, (fBounds,
SkRef(fRecord.get()),
pictList,
SkSafeRef(fBBH.get()),
saveLayerData.detach(),
subPictureBytes));
}
示例3: createTypefaceFromFontId
SkTypeface* SkFontMgr_Indirect::createTypefaceFromFontId(const SkFontIdentity& id) const {
if (id.fDataId == SkFontIdentity::kInvalidDataId) {
return nullptr;
}
SkAutoMutexAcquire ama(fDataCacheMutex);
SkAutoTUnref<SkTypeface> dataTypeface;
int dataTypefaceIndex = 0;
for (int i = 0; i < fDataCache.count(); ++i) {
const DataEntry& entry = fDataCache[i];
if (entry.fDataId == id.fDataId) {
if (entry.fTtcIndex == id.fTtcIndex &&
!entry.fTypeface->weak_expired() && entry.fTypeface->try_ref())
{
return entry.fTypeface;
}
if (dataTypeface.get() == nullptr &&
!entry.fTypeface->weak_expired() && entry.fTypeface->try_ref())
{
dataTypeface.reset(entry.fTypeface);
dataTypefaceIndex = entry.fTtcIndex;
}
}
if (entry.fTypeface->weak_expired()) {
fDataCache.removeShuffle(i);
--i;
}
}
// No exact match, but did find a data match.
if (dataTypeface.get() != nullptr) {
SkAutoTDelete<SkStreamAsset> stream(dataTypeface->openStream(nullptr));
if (stream.get() != nullptr) {
return fImpl->createFromStream(stream.release(), dataTypefaceIndex);
}
}
// No data match, request data and add entry.
SkAutoTDelete<SkStreamAsset> stream(fProxy->getData(id.fDataId));
if (stream.get() == nullptr) {
return nullptr;
}
SkAutoTUnref<SkTypeface> typeface(fImpl->createFromStream(stream.release(), id.fTtcIndex));
if (typeface.get() == nullptr) {
return nullptr;
}
DataEntry& newEntry = fDataCache.push_back();
typeface->weak_ref();
newEntry.fDataId = id.fDataId;
newEntry.fTtcIndex = id.fTtcIndex;
newEntry.fTypeface = typeface.get(); // weak reference passed to new entry.
return typeface.release();
}
示例4: GLInterfaceValidationTest
static void GLInterfaceValidationTest(skiatest::Reporter* reporter) {
typedef const GrGLInterface* (*interfaceFactory)();
struct {
interfaceFactory fFactory;
const char* fName;
} interfaceFactories[] = {
#if SK_ANGLE
{GrGLCreateANGLEInterface, "ANGLE"},
#endif
{GrGLCreateNativeInterface, "Native"},
#if SK_MESA
{GrGLCreateMesaInterface, "Mesa"},
#endif
{GrGLCreateDebugInterface, "Debug"},
{GrGLCreateNullInterface, "Null"},
};
// On some platforms GrGLCreateNativeInterface will fail unless an OpenGL
// context has been created. Also, preserve the current context that may
// be in use by outer test harness.
SkNativeGLContext::AutoContextRestore nglacr;
SkNativeGLContext nglctx;
static const int gBOGUS_SIZE = 16;
bool nativeContextInit = nglctx.init(gBOGUS_SIZE, gBOGUS_SIZE);
REPORTER_ASSERT(reporter, nativeContextInit);
if (!nativeContextInit) {
return;
}
#if SK_MESA
// We must have a current OSMesa context to initialize an OSMesa
// GrGLInterface
SkMesaGLContext::AutoContextRestore mglacr;
SkMesaGLContext mglctx;
bool mesaContextInit = mglctx.init(gBOGUS_SIZE, gBOGUS_SIZE);
REPORTER_ASSERT(reporter, mesaContextInit);
if(!mesaContextInit) {
return;
}
#endif
SkAutoTUnref<const GrGLInterface> iface;
for (size_t i = 0; i < SK_ARRAY_COUNT(interfaceFactories); ++i) {
iface.reset(interfaceFactories[i].fFactory());
REPORTER_ASSERT(reporter, NULL != iface.get());
if (iface.get()) {
for (GrGLBinding binding = kFirstGrGLBinding;
binding <= kLastGrGLBinding;
binding = static_cast<GrGLBinding>(binding << 1)) {
if (iface.get()->fBindingsExported & binding) {
REPORTER_ASSERT(reporter, iface.get()->validate(binding));
}
}
}
}
}
示例5: processMediumRequest
/*
* Modulo internal errors, this should always succeed *if* the matrix is downscaling
* (in this case, we have the inverse, so it succeeds if fInvMatrix is upscaling)
*/
bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmapProvider& provider) {
SkASSERT(fQuality <= kMedium_SkFilterQuality);
if (fQuality != kMedium_SkFilterQuality) {
return false;
}
// Our default return state is to downgrade the request to Low, w/ or w/o setting fBitmap
// to a valid bitmap.
fQuality = kLow_SkFilterQuality;
SkSize invScaleSize;
if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) {
return false;
}
// Use the largest (non-inverse) scale, to ensure anisotropic consistency.
SkASSERT(invScaleSize.width() >= 0 && invScaleSize.height() >= 0);
const SkScalar invScale = SkTMin(invScaleSize.width(), invScaleSize.height());
if (invScale > SK_Scalar1) {
fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc()));
if (nullptr == fCurrMip.get()) {
SkBitmap orig;
if (!provider.asBitmap(&orig)) {
return false;
}
fCurrMip.reset(SkMipMapCache::AddAndRef(orig));
if (nullptr == fCurrMip.get()) {
return false;
}
}
// diagnostic for a crasher...
if (nullptr == fCurrMip->data()) {
sk_throw();
}
SkScalar levelScale = SkScalarInvert(invScale);
SkMipMap::Level level;
if (fCurrMip->extractLevel(levelScale, &level)) {
const SkSize& invScaleFixup = level.fScale;
fInvMatrix.postScale(invScaleFixup.width(), invScaleFixup.height());
// todo: if we could wrap the fCurrMip in a pixelref, then we could just install
// that here, and not need to explicitly track it ourselves.
return fResultBitmap.installPixels(level.fPixmap);
} else {
// failed to extract, so release the mipmap
fCurrMip.reset(nullptr);
}
}
return false;
}
示例6: Create
static GrEffectRef* Create(bool stroke) {
// we go through this so we only have one copy of each effect (stroked/filled)
static SkAutoTUnref<GrEffectRef> gCircleStrokeEdgeEffectRef(
CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(CircleEdgeEffect, (true)))));
static SkAutoTUnref<GrEffectRef> gCircleFillEdgeEffectRef(
CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(CircleEdgeEffect, (false)))));
if (stroke) {
gCircleStrokeEdgeEffectRef.get()->ref();
return gCircleStrokeEdgeEffectRef;
} else {
gCircleFillEdgeEffectRef.get()->ref();
return gCircleFillEdgeEffectRef;
}
}
示例7: onDraw
void onDraw(SkCanvas* canvas) override {
SkPaint paint;
paint.setAntiAlias(true);
paint.setLCDRenderText(true);
paint.setSubpixelText(true);
paint.setTextSize(17);
static const char* gNames[] = {
"Helvetica Neue", "Arial"
};
SkAutoTUnref<SkFontStyleSet> fset;
for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
fset.reset(fFM->matchFamily(gNames[i]));
if (fset->count() > 0) {
break;
}
}
if (nullptr == fset.get()) {
return;
}
canvas->translate(20, 40);
this->exploreFamily(canvas, paint, fset);
canvas->translate(150, 0);
this->iterateFamily(canvas, paint, fset);
}
示例8: movie_decodeAsset
static jobject movie_decodeAsset(JNIEnv* env, jobject clazz, jlong native_asset) {
android::Asset* asset = reinterpret_cast<android::Asset*>(native_asset);
if (asset == NULL) return NULL;
SkAutoTUnref<SkStreamRewindable> stream (new android::AssetStreamAdaptor(asset));
SkMovie* moov = SkMovie::DecodeStream(stream.get());
return create_jmovie(env, moov);
}
示例9: processMediumRequest
/*
* Modulo internal errors, this should always succeed *if* the matrix is downscaling
* (in this case, we have the inverse, so it succeeds if fInvMatrix is upscaling)
*/
bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmap& origBitmap) {
SkASSERT(fQuality <= kMedium_SkFilterQuality);
if (fQuality != kMedium_SkFilterQuality) {
return false;
}
// Our default return state is to downgrade the request to Low, w/ or w/o setting fBitmap
// to a valid bitmap.
fQuality = kLow_SkFilterQuality;
SkSize invScaleSize;
if (!fInvMatrix.decomposeScale(&invScaleSize, NULL)) {
return false;
}
SkScalar invScale = SkScalarSqrt(invScaleSize.width() * invScaleSize.height());
if (invScale > SK_Scalar1) {
fCurrMip.reset(SkMipMapCache::FindAndRef(origBitmap));
if (NULL == fCurrMip.get()) {
fCurrMip.reset(SkMipMapCache::AddAndRef(origBitmap));
if (NULL == fCurrMip.get()) {
return false;
}
}
// diagnostic for a crasher...
if (NULL == fCurrMip->data()) {
sk_throw();
}
SkScalar levelScale = SkScalarInvert(invScale);
SkMipMap::Level level;
if (fCurrMip->extractLevel(levelScale, &level)) {
SkScalar invScaleFixup = level.fScale;
fInvMatrix.postScale(invScaleFixup, invScaleFixup);
const SkImageInfo info = origBitmap.info().makeWH(level.fWidth, level.fHeight);
// todo: if we could wrap the fCurrMip in a pixelref, then we could just install
// that here, and not need to explicitly track it ourselves.
return fResultBitmap.installPixels(info, level.fPixels, level.fRowBytes);
} else {
// failed to extract, so release the mipmap
fCurrMip.reset(NULL);
}
}
return false;
}
示例10: asFragmentProcessor
const GrFragmentProcessor* SkImageShader::asFragmentProcessor(GrContext* context,
const SkMatrix& viewM,
const SkMatrix* localMatrix,
SkFilterQuality filterQuality,
GrProcessorDataManager* mgr) const {
SkMatrix matrix;
matrix.setIDiv(fImage->width(), fImage->height());
SkMatrix lmInverse;
if (!this->getLocalMatrix().invert(&lmInverse)) {
return nullptr;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return nullptr;
}
lmInverse.postConcat(inv);
}
matrix.preConcat(lmInverse);
SkShader::TileMode tm[] = { fTileModeX, fTileModeY };
// Must set wrap and filter on the sampler before requesting a texture. In two places below
// we check the matrix scale factors to determine how to interpret the filter quality setting.
// This completely ignores the complexity of the drawVertices case where explicit local coords
// are provided by the caller.
bool doBicubic;
GrTextureParams::FilterMode textureFilterMode =
GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix(), &doBicubic);
GrTextureParams params(tm, textureFilterMode);
SkImageUsageType usageType;
if (kClamp_TileMode == fTileModeX && kClamp_TileMode == fTileModeY) {
usageType = kUntiled_SkImageUsageType;
} else if (GrTextureParams::kNone_FilterMode == textureFilterMode) {
usageType = kTiled_Unfiltered_SkImageUsageType;
} else {
usageType = kTiled_Filtered_SkImageUsageType;
}
SkAutoTUnref<GrTexture> texture(as_IB(fImage)->asTextureRef(context, usageType));
if (!texture) {
return nullptr;
}
SkAutoTUnref<GrFragmentProcessor> inner;
if (doBicubic) {
inner.reset(GrBicubicEffect::Create(mgr, texture, matrix, tm));
} else {
inner.reset(GrSimpleTextureEffect::Create(mgr, texture, matrix, params));
}
if (GrPixelConfigIsAlphaOnly(texture->config())) {
return SkRef(inner.get());
}
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
}
示例11: compare_to_expectations_if_necessary
/**
* If --readExpectationsPath is set, compare this bitmap to the json expectations
* provided.
*
* @param digest GmResultDigest, computed from the decoded bitmap, to compare to
* the existing expectation.
* @param filename String used to find the expected value. Will be combined with the
* preferred config, as specified by "--config", to match the pattern of
* gm_json.py's IMAGE_FILENAME_PATTERN: "filename_config.png". The resulting
* key will be used to find the proper expectations.
* @param failureArray Array to add a failure message to on failure.
* @param missingArray Array to add failure message to when missing image
* expectation.
* @param ignoreArray Array to add failure message to when the image does not match
* the expectation, but this is a failure we can ignore.
* @return bool True in any of these cases:
* - the bitmap matches the expectation.
* False in any of these cases:
* - there is no expectations file.
* - there is an expectations file, but no expectation for this bitmap.
* - there is an expectation for this bitmap, but it did not match.
* - expectation could not be computed from the bitmap.
*/
static bool compare_to_expectations_if_necessary(const skiagm::GmResultDigest& digest,
const char* filename,
SkTArray<SkString, false>* failureArray,
SkTArray<SkString, false>* missingArray,
SkTArray<SkString, false>* ignoreArray) {
// For both writing and reading, the key for this entry will include the name
// of the file and the pref config, matching the pattern of gm_json.py's
// IMAGE_FILENAME_PATTERN: "name_config.png"
const SkString name_config = create_json_key(filename);
if (!digest.isValid()) {
if (failureArray != NULL) {
failureArray->push_back().printf("decoded %s, but could not create a GmResultDigest.",
filename);
}
return false;
}
if (NULL == gJsonExpectations.get()) {
return false;
}
skiagm::Expectations jsExpectation = gJsonExpectations->get(name_config.c_str());
if (jsExpectation.empty()) {
if (missingArray != NULL) {
missingArray->push_back().printf("decoded %s, but could not find expectation.",
filename);
}
return false;
}
if (jsExpectation.match(digest)) {
return true;
}
if (jsExpectation.ignoreFailure()) {
ignoreArray->push_back().printf("%s does not match expectation, but this is known.",
filename);
} else if (failureArray != NULL) {
failureArray->push_back().printf("decoded %s, but the result does not match "
"expectations.",
filename);
}
return false;
}
示例12:
~ImageRenderingContext()
{
if (IsGpu)
{
SkAutoTUnref<SkImage> image;
image.reset(Surface->newImageSnapshot(SkSurface::kNo_Budgeted));
image.get()->readPixels(Image->Bitmap.info(), Image->Bitmap.getPixels(), Image->Bitmap.rowBytes(), 0, 0);
}
Surface.reset(nullptr);
}
示例13: setupCanvas
SkCanvas* PictureRenderer::setupCanvas(int width, int height) {
SkCanvas* canvas;
switch(fDeviceType) {
case kBitmap_DeviceType: {
SkBitmap bitmap;
sk_tools::setup_bitmap(&bitmap, width, height);
canvas = SkNEW_ARGS(SkCanvas, (bitmap));
}
break;
#if SK_SUPPORT_GPU
#if SK_ANGLE
case kAngle_DeviceType:
// fall through
#endif
#if SK_MESA
case kMesa_DeviceType:
// fall through
#endif
case kGPU_DeviceType:
case kNVPR_DeviceType: {
SkAutoTUnref<GrSurface> target;
if (fGrContext) {
// create a render target to back the device
GrTextureDesc desc;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fFlags = kRenderTarget_GrTextureFlagBit;
desc.fWidth = width;
desc.fHeight = height;
desc.fSampleCnt = fSampleCount;
target.reset(fGrContext->createUncachedTexture(desc, NULL, 0));
}
if (NULL == target.get()) {
SkASSERT(0);
return NULL;
}
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(target));
canvas = SkNEW_ARGS(SkCanvas, (device.get()));
break;
}
#endif
default:
SkASSERT(0);
return NULL;
}
setUpFilter(canvas, fDrawFilters);
this->scaleToScaleFactor(canvas);
// Pictures often lie about their extent (i.e., claim to be 100x100 but
// only ever draw to 90x100). Clear here so the undrawn portion will have
// a consistent color
canvas->clear(SK_ColorTRANSPARENT);
return canvas;
}
示例14: asFragmentProcessor
const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* context,
const SkMatrix& viewM, const SkMatrix* localMatrix,
SkFilterQuality filterQuality,
GrProcessorDataManager* procDataManager) const {
SkMatrix matrix;
matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());
SkMatrix lmInverse;
if (!this->getLocalMatrix().invert(&lmInverse)) {
return nullptr;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return nullptr;
}
lmInverse.postConcat(inv);
}
matrix.preConcat(lmInverse);
SkShader::TileMode tm[] = {
(TileMode)fTileModeX,
(TileMode)fTileModeY,
};
// Must set wrap and filter on the sampler before requesting a texture. In two places below
// we check the matrix scale factors to determine how to interpret the filter quality setting.
// This completely ignores the complexity of the drawVertices case where explicit local coords
// are provided by the caller.
bool doBicubic;
GrTextureParams::FilterMode textureFilterMode =
GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix(),
&doBicubic);
GrTextureParams params(tm, textureFilterMode);
SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap, ¶ms));
if (!texture) {
SkErrorInternals::SetError( kInternalError_SkError,
"Couldn't convert bitmap to texture.");
return nullptr;
}
SkAutoTUnref<GrFragmentProcessor> inner;
if (doBicubic) {
inner.reset(GrBicubicEffect::Create(procDataManager, texture, matrix, tm));
} else {
inner.reset(GrSimpleTextureEffect::Create(procDataManager, texture, matrix, params));
}
if (kAlpha_8_SkColorType == fRawBitmap.colorType()) {
return SkRef(inner.get());
}
return GrExtractAlphaFragmentProcessor::Create(inner);
}
示例15: CreateImage
// static
SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
const SkIRect& srcRect,
SkPicture::EncodeBitmap encoder) {
if (bitmap.colorType() == kUnknown_SkColorType) {
return NULL;
}
bool isTransparent = false;
SkAutoTUnref<SkStream> alphaData;
if (!bitmap.isOpaque()) {
// Note that isOpaque is not guaranteed to return false for bitmaps
// with alpha support but a completely opaque alpha channel,
// so alphaData may still be NULL if we have a completely opaque
// (or transparent) bitmap.
alphaData.reset(
extract_image_data(bitmap, srcRect, true, &isTransparent));
}
if (isTransparent) {
return NULL;
}
SkPDFImage* image;
SkColorType colorType = bitmap.colorType();
if (alphaData.get() != NULL && (kN32_SkColorType == colorType ||
kARGB_4444_SkColorType == colorType)) {
SkBitmap unpremulBitmap = unpremultiply_bitmap(bitmap, srcRect);
image = SkNEW_ARGS(SkPDFImage, (NULL, unpremulBitmap, false,
SkIRect::MakeWH(srcRect.width(), srcRect.height()),
encoder));
} else {
image = SkNEW_ARGS(SkPDFImage, (NULL, bitmap, false, srcRect, encoder));
}
if (alphaData.get() != NULL) {
SkAutoTUnref<SkPDFImage> mask(
SkNEW_ARGS(SkPDFImage, (alphaData.get(), bitmap,
true, srcRect, NULL)));
image->addSMask(mask);
}
return image;
}