本文整理汇总了C++中SkAutoTUnref类的典型用法代码示例。如果您正苦于以下问题:C++ SkAutoTUnref类的具体用法?C++ SkAutoTUnref怎么用?C++ SkAutoTUnref使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkAutoTUnref类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DEF_TEST
DEF_TEST(Picture_BitmapLeak, r) {
SkBitmap mut, immut;
mut.allocN32Pixels(300, 200);
immut.allocN32Pixels(300, 200);
immut.setImmutable();
SkASSERT(!mut.isImmutable());
SkASSERT(immut.isImmutable());
// No one can hold a ref on our pixels yet.
REPORTER_ASSERT(r, mut.pixelRef()->unique());
REPORTER_ASSERT(r, immut.pixelRef()->unique());
SkAutoTUnref<const SkPicture> pic;
{
// we want the recorder to go out of scope before our subsequent checks, so we
// place it inside local braces.
SkPictureRecorder rec;
SkCanvas* canvas = rec.beginRecording(1920, 1200);
canvas->drawBitmap(mut, 0, 0);
canvas->drawBitmap(immut, 800, 600);
pic.reset(rec.endRecording());
}
// The picture shares the immutable pixels but copies the mutable ones.
REPORTER_ASSERT(r, mut.pixelRef()->unique());
REPORTER_ASSERT(r, !immut.pixelRef()->unique());
// When the picture goes away, it's just our bitmaps holding the refs.
pic.reset(NULL);
REPORTER_ASSERT(r, mut.pixelRef()->unique());
REPORTER_ASSERT(r, immut.pixelRef()->unique());
}
示例2: drawVertices_rp
static void drawVertices_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
unsigned flags = DrawOp_unpackFlags(op32);
SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader->readU32();
int vertexCount = reader->readU32();
const SkPoint* verts = skip<SkPoint>(reader, vertexCount);
const SkPoint* texs = NULL;
if (flags & kDrawVertices_HasTexs_DrawOpFlag) {
texs = skip<SkPoint>(reader, vertexCount);
}
const SkColor* colors = NULL;
if (flags & kDrawVertices_HasColors_DrawOpFlag) {
colors = skip<SkColor>(reader, vertexCount);
}
SkAutoTUnref<SkXfermode> xfer;
if (flags & kDrawVertices_HasXfermode_DrawOpFlag) {
SkXfermode::Mode mode = (SkXfermode::Mode)reader->readU32();
xfer.reset(SkXfermode::Create(mode));
}
int indexCount = 0;
const uint16_t* indices = NULL;
if (flags & kDrawVertices_HasIndices_DrawOpFlag) {
indexCount = reader->readU32();
indices = skipAlign<uint16_t>(reader, indexCount);
}
if (state->shouldDraw()) {
canvas->drawVertices(vmode, vertexCount, verts, texs, colors, xfer,
indices, indexCount, state->paint());
}
}
示例3: 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));
}
示例4: Create
GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) {
const GrGLInterface* glInterface = NULL;
SkAutoTUnref<const GrGLInterface> glInterfaceUnref;
if (kOpenGL_GrBackend == backend) {
glInterface = reinterpret_cast<const GrGLInterface*>(backendContext);
if (NULL == glInterface) {
glInterface = GrGLDefaultInterface();
// By calling GrGLDefaultInterface we've taken a ref on the
// returned object. We only want to hold that ref until after
// the GrGpu is constructed and has taken ownership.
glInterfaceUnref.reset(glInterface);
}
if (NULL == glInterface) {
#ifdef SK_DEBUG
GrPrintf("No GL interface provided!\n");
#endif
return NULL;
}
GrGLContext ctx(glInterface);
if (ctx.isInitialized()) {
return SkNEW_ARGS(GrGpuGL, (ctx, context));
}
}
return NULL;
}
示例5: SkMakeImageFromRasterBitmap
sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
SkPixelRef* pr = bm.pixelRef();
if (nullptr == pr) {
return nullptr;
}
#if SK_SUPPORT_GPU
if (GrTexture* tex = pr->getTexture()) {
SkAutoTUnref<GrTexture> unrefCopy;
if (!bm.isImmutable()) {
tex = GrDeepCopyTexture(tex, SkBudgeted::kNo);
if (nullptr == tex) {
return nullptr;
}
unrefCopy.reset(tex);
}
const SkImageInfo info = bm.info();
return sk_make_sp<SkImage_Gpu>(info.width(), info.height(), bm.getGenerationID(),
info.alphaType(), tex, sk_ref_sp(info.colorSpace()),
SkBudgeted::kNo);
}
#endif
// This will check for immutable (share or copy)
return SkMakeImageFromRasterBitmap(bm);
}
示例6: pixelStorage
bool SkImageGenerator::tryGenerateBitmap(SkBitmap* bitmap, const SkImageInfo* infoPtr) {
const SkImageInfo info = infoPtr ? *infoPtr : this->getInfo();
const size_t rowBytes = info.minRowBytes();
const size_t pixelSize = info.getSafeSize(rowBytes);
if (0 == pixelSize) {
return false;
}
SkAutoFree pixelStorage(sk_malloc_flags(pixelSize, 0));
void* pixels = pixelStorage.get();
if (!pixels) {
return false;
}
SkPMColor ctStorage[256];
int ctCount = 0;
if (!this->getPixels(info, pixels, rowBytes, ctStorage, &ctCount)) {
return false;
}
SkAutoTUnref<SkColorTable> ctable;
if (ctCount > 0) {
SkASSERT(kIndex_8_SkColorType == info.colorType());
ctable.reset(new SkColorTable(ctStorage, ctCount));
} else {
SkASSERT(kIndex_8_SkColorType != info.colorType());
}
return bitmap->installPixels(info, pixelStorage.detach(), rowBytes, ctable,
release_malloc_proc, nullptr);
}
示例7: drawHere
void drawHere(SkCanvas* canvas, SkFilterQuality filter, SkScalar dx, SkScalar dy) {
SkCanvas* origCanvas = canvas;
SkAutoCanvasRestore acr(canvas, true);
SkISize size = SkISize::Make(fImage->width(), fImage->height());
SkAutoTUnref<SkSurface> surface;
if (fShowFatBits) {
// scale up so we don't clip rotations
SkImageInfo info = SkImageInfo::MakeN32(fImage->width() * 2, fImage->height() * 2,
kOpaque_SkAlphaType);
surface.reset(make_surface(canvas, info));
canvas = surface->getCanvas();
canvas->drawColor(SK_ColorWHITE);
size.set(info.width(), info.height());
} else {
canvas->translate(SkScalarHalf(fCell.width() - fImage->width()),
SkScalarHalf(fCell.height() - fImage->height()));
}
this->drawTheImage(canvas, size, filter, dx, dy);
if (surface) {
SkAutoTUnref<SkImage> orig(surface->newImageSnapshot());
SkAutoTUnref<SkImage> zoomed(zoom_up(orig));
origCanvas->drawImage(zoomed,
SkScalarHalf(fCell.width() - zoomed->width()),
SkScalarHalf(fCell.height() - zoomed->height()));
}
}
示例8: DEF_TEST
// Make sure the abort callback works
DEF_TEST(RecordReplaceDraw_Abort, r) {
SkAutoTUnref<const SkPicture> pic;
{
// Record two commands.
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight));
canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)), SkPaint());
canvas->clipRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)));
pic.reset(recorder.endRecording());
}
SkRecord rerecord;
SkRecorder canvas(&rerecord, kWidth, kHeight);
JustOneDraw callback;
GrRecordReplaceDraw(pic, &canvas, nullptr, SkMatrix::I(), &callback);
switch (rerecord.count()) {
case 3:
assert_type<SkRecords::Save>(r, rerecord, 0);
assert_type<SkRecords::DrawRect>(r, rerecord, 1);
assert_type<SkRecords::Restore>(r, rerecord, 2);
break;
case 1:
assert_type<SkRecords::DrawRect>(r, rerecord, 0);
break;
default:
REPORTER_ASSERT(r, false);
}
}
示例9: 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);
}
示例10: create_sk_window
SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
printf("Started\n");
SkCommandLineFlags::Parse(argc, argv);
// Get the default Isolate created at startup.
Isolate* isolate = Isolate::GetCurrent();
Global* global = new Global(isolate);
// Set up things to look like a browser by creating
// a console object that invokes our print function.
const char* startupScript =
"function Console() {}; \n"
"Console.prototype.log = function() { \n"
" var args = Array.prototype.slice.call(arguments).join(' '); \n"
" print(args); \n"
"}; \n"
"console = new Console(); \n";
if (!global->parseScript(startupScript)) {
printf("Failed to parse startup script: %s.\n", FLAGS_infile[0]);
exit(1);
}
const char* script =
"function onDraw(canvas) { \n"
" canvas.fillStyle = '#00FF00'; \n"
" canvas.fillRect(20, 20, 100, 100); \n"
" canvas.inval(); \n"
"} \n";
SkAutoTUnref<SkData> data;
if (FLAGS_infile.count()) {
data.reset(SkData::NewFromFileName(FLAGS_infile[0]));
script = static_cast<const char*>(data->data());
}
if (NULL == script) {
printf("Could not load file: %s.\n", FLAGS_infile[0]);
exit(1);
}
Path2D::AddToGlobal(global);
if (!global->parseScript(script)) {
printf("Failed to parse file: %s.\n", FLAGS_infile[0]);
exit(1);
}
JsContext* jsContext = new JsContext(global);
if (!jsContext->initialize()) {
printf("Failed to initialize.\n");
exit(1);
}
SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext);
global->setWindow(win);
return win;
}
示例11: SkASSERT
sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyMode forceCopyMode) {
GrRenderTarget* rt = fDevice->accessDrawContext()->accessRenderTarget();
SkASSERT(rt);
GrTexture* tex = rt->asTexture();
SkAutoTUnref<GrTexture> copy;
// If the original render target is a buffer originally created by the client, then we don't
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
// copy-on-write.
if (kYes_ForceCopyMode == forceCopyMode || !tex || rt->resourcePriv().refsWrappedObjects()) {
GrSurfaceDesc desc = fDevice->accessDrawContext()->desc();
GrContext* ctx = fDevice->context();
desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
copy.reset(ctx->textureProvider()->createTexture(desc, budgeted));
if (!copy) {
return nullptr;
}
if (!ctx->copySurface(copy, rt)) {
return nullptr;
}
tex = copy;
}
const SkImageInfo info = fDevice->imageInfo();
sk_sp<SkImage> image;
if (tex) {
image = sk_make_sp<SkImage_Gpu>(info.width(), info.height(), kNeedNewImageUniqueID,
info.alphaType(), tex, sk_ref_sp(info.colorSpace()),
budgeted);
}
return image;
}
示例12: CreateProc
SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
SkAutoTUnref<SkPicture> picture;
SkRect cropRect;
if (buffer.isCrossProcess() && SkPicture::PictureIOSecurityPrecautionsEnabled()) {
buffer.validate(!buffer.readBool());
} else {
if (buffer.readBool()) {
picture.reset(SkPicture::CreateFromBuffer(buffer));
}
}
buffer.readRect(&cropRect);
PictureResolution pictureResolution;
if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) {
pictureResolution = kDeviceSpace_PictureResolution;
} else {
pictureResolution = (PictureResolution)buffer.readInt();
}
if (kLocalSpace_PictureResolution == pictureResolution) {
//filterLevel is only serialized if pictureResolution is LocalSpace
SkFilterQuality filterQuality;
if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterLevel_Version)) {
filterQuality = kLow_SkFilterQuality;
} else {
filterQuality = (SkFilterQuality)buffer.readInt();
}
return CreateForLocalSpace(picture, cropRect, filterQuality);
}
return Create(picture, cropRect);
}
示例13: NewFromBitmap
SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
SkPixelRef* pr = bm.pixelRef();
if (nullptr == pr) {
return nullptr;
}
#if SK_SUPPORT_GPU
if (GrTexture* tex = pr->getTexture()) {
SkAutoTUnref<GrTexture> unrefCopy;
if (!bm.isImmutable()) {
const bool notBudgeted = false;
tex = GrDeepCopyTexture(tex, notBudgeted);
if (nullptr == tex) {
return nullptr;
}
unrefCopy.reset(tex);
}
const SkImageInfo info = bm.info();
return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID(), info.alphaType(),
tex, 0, SkSurface::kNo_Budgeted);
}
#endif
// This will check for immutable (share or copy)
return SkNewImageFromRasterBitmap(bm, nullptr);
}
示例14: onGetPixels
virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
const Options&,
SkPMColor ctableEntries[], int* ctableCount) override {
SkMemoryStream stream(fData->data(), fData->size(), false);
SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocator,
(info, pixels, rowBytes)));
fDecoder->setAllocator(allocator);
fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.alphaType());
SkBitmap bm;
const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, info.colorType(),
SkImageDecoder::kDecodePixels_Mode);
if (SkImageDecoder::kFailure == result) {
return kInvalidInput;
}
SkASSERT(info.colorType() == bm.info().colorType());
if (kIndex_8_SkColorType == info.colorType()) {
SkASSERT(ctableEntries);
SkColorTable* ctable = bm.getColorTable();
if (NULL == ctable) {
return kInvalidConversion;
}
const int count = ctable->count();
memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor));
*ctableCount = count;
}
if (SkImageDecoder::kPartialSuccess == result) {
return kIncompleteInput;
}
return kSuccess;
}
示例15: DEF_TEST
// Tests that SkNewImageFromBitmap obeys pixelref origin.
DEF_TEST(SkImageFromBitmap_extractSubset, reporter) {
SkAutoTUnref<SkImage> image;
{
SkBitmap srcBitmap;
srcBitmap.allocN32Pixels(gWidth, gHeight);
srcBitmap.eraseColor(SK_ColorRED);
SkBitmapDevice dev(srcBitmap);
SkCanvas canvas(&dev);
SkIRect r = SkIRect::MakeXYWH(5, 5, gWidth - 5, gWidth - 5);
SkPaint p;
p.setColor(SK_ColorGREEN);
canvas.drawIRect(r, p);
SkBitmap dstBitmap;
srcBitmap.extractSubset(&dstBitmap, r);
image.reset(SkNewImageFromBitmap(dstBitmap, true, NULL));
}
SkBitmap tgt;
tgt.allocN32Pixels(gWidth, gHeight);
SkBitmapDevice dev(tgt);
SkCanvas canvas(&dev);
canvas.clear(SK_ColorTRANSPARENT);
canvas.drawImage(image, 0, 0, NULL);
uint32_t pixel = 0;
SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
canvas.readPixels(info, &pixel, 4, 0, 0);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
canvas.readPixels(info, &pixel, 4, gWidth - 6, gWidth - 6);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
canvas.readPixels(info, &pixel, 4, gWidth - 5, gWidth - 5);
REPORTER_ASSERT(reporter, pixel == SK_ColorTRANSPARENT);
}