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); }
SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted) { if (fWeOwnThePixels) { // SkImage_raster requires these pixels are immutable for its full lifetime. // We'll undo this via onRestoreBackingMutability() if we can avoid the COW. if (SkPixelRef* pr = fBitmap.pixelRef()) { pr->setTemporarilyImmutable(); } } // Our pixels are in memory, so read access on the snapshot SkImage could be cheap. // Lock the shared pixel ref to ensure peekPixels() is usable. return SkNewImageFromRasterBitmap(fBitmap, fWeOwnThePixels ? kNo_ForceCopyMode : kYes_ForceCopyMode); }
SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted) { return SkNewImageFromRasterBitmap(fBitmap, fWeOwnThePixels, &this->props()); }