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

Side by Side Diff: src/gpu/SkGrPixelRef.cpp

Issue 607993002: Change GrContext::copyTexture to go through GrDrawTarget (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: response to feedback Created 6 years, 2 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
« src/gpu/GrContext.cpp ('K') | « src/gpu/GrContext.cpp ('k') | no next file » | 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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 void SkROLockPixelsPixelRef::onUnlockPixels() { 46 void SkROLockPixelsPixelRef::onUnlockPixels() {
47 fBitmap.unlockPixels(); 47 fBitmap.unlockPixels();
48 } 48 }
49 49
50 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { 50 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const {
51 return false; 51 return false;
52 } 52 }
53 53
54 /////////////////////////////////////////////////////////////////////////////// 54 ///////////////////////////////////////////////////////////////////////////////
55 55
56 static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkColorType dstCT , 56 static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp e dstCT,
robertphillips 2014/09/29 12:14:23 line this up?
57 const SkIRect* subset) { 57 const SkIRect* subset) {
58 if (NULL == texture || kUnknown_SkColorType == dstCT) { 58 if (NULL == texture || kUnknown_SkColorType == dstCT) {
59 return NULL; 59 return NULL;
60 } 60 }
61 GrContext* context = texture->getContext(); 61 GrContext* context = texture->getContext();
62 if (NULL == context) { 62 if (NULL == context) {
63 return NULL; 63 return NULL;
64 } 64 }
65 GrTextureDesc desc; 65 GrTextureDesc desc;
66 66
(...skipping 14 matching lines...) Expand all
81 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; 81 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
82 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType); 82 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType);
83 83
84 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); 84 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
85 if (NULL == dst) { 85 if (NULL == dst) {
86 return NULL; 86 return NULL;
87 } 87 }
88 88
89 context->copyTexture(texture, dst->asRenderTarget(), topLeft); 89 context->copyTexture(texture, dst->asRenderTarget(), topLeft);
90 90
91 // TODO: figure out if this is responsible for Chrome canvas errors 91 // Blink is relying on the above copy being sent to GL immediately in the ca se when the source
92 #if 0 92 // is a WebGL canvas backing store. We could have a TODO to remove this flus h, but we have a
93 // The render texture we have created (to perform the copy) isn't fully 93 // larger TODO to remove SkGrPixelRef entirely.
94 // functional (since it doesn't have a stencil buffer). Release it here 94 context->flush();
95 // so the caller doesn't try to render to it.
96 // TODO: we can undo this release when dynamic stencil buffer attach/
97 // detach has been implemented
98 dst->releaseRenderTarget();
99 #endif
100 95
101 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem ul_SkAlphaType); 96 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem ul_SkAlphaType);
102 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); 97 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst));
103 SkSafeUnref(dst); 98 SkSafeUnref(dst);
104 return pixelRef; 99 return pixelRef;
105 } 100 }
106 101
107 /////////////////////////////////////////////////////////////////////////////// 102 ///////////////////////////////////////////////////////////////////////////////
108 103
109 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, 104 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (NULL == fSurface) { 140 if (NULL == fSurface) {
146 return NULL; 141 return NULL;
147 } 142 }
148 143
149 // Note that when copying a render-target-backed pixel ref, we 144 // Note that when copying a render-target-backed pixel ref, we
150 // return a texture-backed pixel ref instead. This is because 145 // return a texture-backed pixel ref instead. This is because
151 // render-target pixel refs are usually created in conjunction with 146 // render-target pixel refs are usually created in conjunction with
152 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live 147 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live
153 // independently of that texture. Texture-backed pixel refs, on the other 148 // independently of that texture. Texture-backed pixel refs, on the other
154 // hand, own their GrTextures, and are thus self-contained. 149 // hand, own their GrTextures, and are thus self-contained.
155 return copyToTexturePixelRef(fSurface->asTexture(), dstCT, subset); 150 return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, subset);
156 } 151 }
157 152
158 static bool tryAllocBitmapPixels(SkBitmap* bitmap) { 153 static bool tryAllocBitmapPixels(SkBitmap* bitmap) {
159 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); 154 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator();
160 if (NULL != allocator) { 155 if (NULL != allocator) {
161 return allocator->allocPixelRef(bitmap, 0); 156 return allocator->allocPixelRef(bitmap, 0);
162 } else { 157 } else {
163 // DiscardableMemory is not available, fallback to default allocator 158 // DiscardableMemory is not available, fallback to default allocator
164 return bitmap->tryAllocPixels(); 159 return bitmap->tryAllocPixels();
165 } 160 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 cachedBitmap.setImmutable(); 199 cachedBitmap.setImmutable();
205 //Add to the cache 200 //Add to the cache
206 SkBitmapCache::Add(this->getGenerationID(), bounds, cachedBitmap); 201 SkBitmapCache::Add(this->getGenerationID(), bounds, cachedBitmap);
207 202
208 dst->swap(cachedBitmap); 203 dst->swap(cachedBitmap);
209 } 204 }
210 205
211 return true; 206 return true;
212 207
213 } 208 }
OLDNEW
« src/gpu/GrContext.cpp ('K') | « src/gpu/GrContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698