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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/image/SkSurface_Gpu.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkSurface_Gpu.h" 8 #include "SkSurface_Gpu.h"
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { 70 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
71 GrRenderTarget* rt = fDevice->accessRenderTarget(); 71 GrRenderTarget* rt = fDevice->accessRenderTarget();
72 int sampleCount = rt->numColorSamples(); 72 int sampleCount = rt->numColorSamples();
73 // TODO: Make caller specify this (change virtual signature of onNewSurface) . 73 // TODO: Make caller specify this (change virtual signature of onNewSurface) .
74 static const Budgeted kBudgeted = kNo_Budgeted; 74 static const Budgeted kBudgeted = kNo_Budgeted;
75 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl eCount, 75 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl eCount,
76 &this->props()); 76 &this->props());
77 } 77 }
78 78
79 SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) { 79 SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted, ForceCopyMode forc eCopyMode) {
80 GrRenderTarget* rt = fDevice->accessRenderTarget();
81 SkASSERT(rt);
82 GrTexture* tex = rt->asTexture();
83 SkAutoTUnref<GrTexture> copy;
84 // TODO: Force a copy when the rt is an external resource.
85 if (kYes_ForceCopyMode == forceCopyMode || !tex) {
86 GrSurfaceDesc desc = fDevice->accessRenderTarget()->desc();
87 GrContext* ctx = fDevice->context();
88 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.
89 copy.reset(ctx->textureProvider()->createTexture(desc, kYes_Budgeted == budgeted));
90 if (!copy) {
91 return nullptr;
92 }
93 if (!ctx->copySurface(copy, rt)) {
94 return nullptr;
95 }
96 tex = copy;
97 }
80 const SkImageInfo info = fDevice->imageInfo(); 98 const SkImageInfo info = fDevice->imageInfo();
81 SkImage* image = nullptr; 99 SkImage* image = nullptr;
82 GrTexture* tex = fDevice->accessRenderTarget()->asTexture();
83 if (tex) { 100 if (tex) {
84 image = new SkImage_Gpu(info.width(), info.height(), kNeedNewImageUnique ID, 101 image = new SkImage_Gpu(info.width(), info.height(), kNeedNewImageUnique ID,
85 info.alphaType(), tex, budgeted); 102 info.alphaType(), tex, budgeted);
86 } 103 }
87 return image; 104 return image;
88 } 105 }
89 106
90 // Create a new render target and, if necessary, copy the contents of the old 107 // Create a new render target and, if necessary, copy the contents of the old
91 // render target into it. Note that this flushes the SkGpuDevice but 108 // render target into it. Note that this flushes the SkGpuDevice but
92 // doesn't force an OpenGL flush. 109 // doesn't force an OpenGL flush.
93 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { 110 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
94 GrRenderTarget* rt = fDevice->accessRenderTarget(); 111 GrRenderTarget* rt = fDevice->accessRenderTarget();
95 // are we sharing our render target with the image? Note this call should ne ver create a new 112 // are we sharing our render target with the image? Note this call should ne ver create a new
96 // image because onCopyOnWrite is only called when there is a cached image. 113 // image because onCopyOnWrite is only called when there is a cached image.
97 SkImage* image = this->getCachedImage(kNo_Budgeted); 114 SkAutoTUnref<SkImage> image(this->refCachedImage(kNo_Budgeted, kNo_ForceUniq ue));
98 SkASSERT(image); 115 SkASSERT(image);
99 if (rt->asTexture() == as_IB(image)->getTexture()) { 116 if (rt->asTexture() == as_IB(image)->getTexture()) {
100 this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode == mode); 117 this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode == mode);
101 SkTextureImageApplyBudgetedDecision(image); 118 SkTextureImageApplyBudgetedDecision(image);
102 } else if (kDiscard_ContentChangeMode == mode) { 119 } else if (kDiscard_ContentChangeMode == mode) {
103 this->SkSurface_Gpu::onDiscard(); 120 this->SkSurface_Gpu::onDiscard();
104 } 121 }
105 } 122 }
106 123
107 void SkSurface_Gpu::onDiscard() { 124 void SkSurface_Gpu::onDiscard() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 181 }
165 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, 182 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props,
166 SkGpuDevice::kUninit_In itContents)); 183 SkGpuDevice::kUninit_In itContents));
167 if (!device) { 184 if (!device) {
168 return nullptr; 185 return nullptr;
169 } 186 }
170 return new SkSurface_Gpu(device); 187 return new SkSurface_Gpu(device);
171 } 188 }
172 189
173 #endif 190 #endif
OLDNEW
« 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