Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: src/image/SkSurface_Gpu.cpp

Issue 1686163002: Allow client to force an SkImage snapshot to be unique (and uniquely own its backing store). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix enum to bool warning Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkSurface_Gpu.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkSurface_Gpu.cpp
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 24ac6d33124b82a237f3bfffd6a07d25bcdb8e64..03fdecef3a720115cf531c22bdf69c8e1df1cba2 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -76,10 +76,27 @@ SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
&this->props());
}
-SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) {
+SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted, ForceCopyMode forceCopyMode) {
+ GrRenderTarget* rt = fDevice->accessRenderTarget();
+ SkASSERT(rt);
+ GrTexture* tex = rt->asTexture();
+ SkAutoTUnref<GrTexture> copy;
+ // TODO: Force a copy when the rt is an external resource.
+ if (kYes_ForceCopyMode == forceCopyMode || !tex) {
+ GrSurfaceDesc desc = fDevice->accessRenderTarget()->desc();
+ GrContext* ctx = fDevice->context();
+ desc.fFlags = desc.fFlags & !kRenderTarget_GrSurfaceFlag;
brucedawson 2016/02/25 01:27:26 This line looks odd (/analyze flagged it as odd).
bsalomon 2016/02/25 01:37:41 d'oh. Yes, should be ~, will fix.
+ copy.reset(ctx->textureProvider()->createTexture(desc, kYes_Budgeted == budgeted));
+ if (!copy) {
+ return nullptr;
+ }
+ if (!ctx->copySurface(copy, rt)) {
+ return nullptr;
+ }
+ tex = copy;
+ }
const SkImageInfo info = fDevice->imageInfo();
SkImage* image = nullptr;
- GrTexture* tex = fDevice->accessRenderTarget()->asTexture();
if (tex) {
image = new SkImage_Gpu(info.width(), info.height(), kNeedNewImageUniqueID,
info.alphaType(), tex, budgeted);
@@ -94,7 +111,7 @@ void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
GrRenderTarget* rt = fDevice->accessRenderTarget();
// are we sharing our render target with the image? Note this call should never create a new
// image because onCopyOnWrite is only called when there is a cached image.
- SkImage* image = this->getCachedImage(kNo_Budgeted);
+ SkAutoTUnref<SkImage> image(this->refCachedImage(kNo_Budgeted, kNo_ForceUnique));
SkASSERT(image);
if (rt->asTexture() == as_IB(image)->getTexture()) {
this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode == mode);
« no previous file with comments | « src/image/SkSurface_Gpu.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698