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

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

Issue 2069173002: Lots of progress switching to SkColorSpace rather than SkColorProfileType (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix bad assert Created 4 years, 6 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/gpu/SkGr.cpp ('k') | src/image/SkImage_Gpu.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 2010 Google Inc. 2 * Copyright 2010 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 8
9 9
10 #include "SkGrPixelRef.h" 10 #include "SkGrPixelRef.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 fBitmap.unlockPixels(); 43 fBitmap.unlockPixels();
44 } 44 }
45 45
46 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { 46 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const {
47 return false; 47 return false;
48 } 48 }
49 49
50 /////////////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////////////
51 51
52 static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp e dstCT, 52 static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp e dstCT,
53 SkColorProfileType dstPT, cons t SkIRect* subset) { 53 SkColorSpace* dstCS, const SkI Rect* subset) {
54 if (nullptr == texture || kUnknown_SkColorType == dstCT) { 54 if (nullptr == texture || kUnknown_SkColorType == dstCT) {
55 return nullptr; 55 return nullptr;
56 } 56 }
57 GrContext* context = texture->getContext(); 57 GrContext* context = texture->getContext();
58 if (nullptr == context) { 58 if (nullptr == context) {
59 return nullptr; 59 return nullptr;
60 } 60 }
61 GrSurfaceDesc desc; 61 GrSurfaceDesc desc;
62 62
63 SkIRect srcRect; 63 SkIRect srcRect;
64 64
65 if (!subset) { 65 if (!subset) {
66 desc.fWidth = texture->width(); 66 desc.fWidth = texture->width();
67 desc.fHeight = texture->height(); 67 desc.fHeight = texture->height();
68 srcRect = SkIRect::MakeWH(texture->width(), texture->height()); 68 srcRect = SkIRect::MakeWH(texture->width(), texture->height());
69 } else { 69 } else {
70 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(* subset)); 70 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(* subset));
71 // Create a new texture that is the size of subset. 71 // Create a new texture that is the size of subset.
72 desc.fWidth = subset->width(); 72 desc.fWidth = subset->width();
73 desc.fHeight = subset->height(); 73 desc.fHeight = subset->height();
74 srcRect = *subset; 74 srcRect = *subset;
75 } 75 }
76 desc.fFlags = kRenderTarget_GrSurfaceFlag; 76 desc.fFlags = kRenderTarget_GrSurfaceFlag;
77 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT, *context->caps()); 77 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstCS, *context->caps());
78 desc.fIsMipMapped = false; 78 desc.fIsMipMapped = false;
79 79
80 GrTexture* dst = context->textureProvider()->createTexture(desc, SkBudgeted: :kNo, nullptr, 0); 80 GrTexture* dst = context->textureProvider()->createTexture(desc, SkBudgeted: :kNo, nullptr, 0);
81 if (nullptr == dst) { 81 if (nullptr == dst) {
82 return nullptr; 82 return nullptr;
83 } 83 }
84 84
85 // Blink is relying on the above copy being sent to GL immediately in the ca se when the source 85 // Blink is relying on the above copy being sent to GL immediately in the ca se when the source
86 // is a WebGL canvas backing store. We could have a TODO to remove this flus h, but we have 86 // is a WebGL canvas backing store. We could have a TODO to remove this flus h, but we have
87 // a larger TODO to remove SkGrPixelRef entirely. 87 // a larger TODO to remove SkGrPixelRef entirely.
88 context->copySurface(dst, texture, srcRect, SkIPoint::Make(0,0)); 88 context->copySurface(dst, texture, srcRect, SkIPoint::Make(0,0));
89 context->flushSurfaceWrites(dst); 89 context->flushSurfaceWrites(dst);
90 90
91 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem ul_SkAlphaType, 91 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem ul_SkAlphaType,
92 dstPT); 92 sk_ref_sp(dstCS));
93 SkGrPixelRef* pixelRef = new SkGrPixelRef(info, dst); 93 SkGrPixelRef* pixelRef = new SkGrPixelRef(info, dst);
94 SkSafeUnref(dst); 94 SkSafeUnref(dst);
95 return pixelRef; 95 return pixelRef;
96 } 96 }
97 97
98 /////////////////////////////////////////////////////////////////////////////// 98 ///////////////////////////////////////////////////////////////////////////////
99 99
100 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface) : INHERI TED(info) { 100 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface) : INHERI TED(info) {
101 // For surfaces that are both textures and render targets, the texture owns the 101 // For surfaces that are both textures and render targets, the texture owns the
102 // render target but not vice versa. So we ref the texture to keep both aliv e for 102 // render target but not vice versa. So we ref the texture to keep both aliv e for
(...skipping 20 matching lines...) Expand all
123 return nullptr; 123 return nullptr;
124 } 124 }
125 125
126 void SkGrPixelRef::onNotifyPixelsChanged() { 126 void SkGrPixelRef::onNotifyPixelsChanged() {
127 GrTexture* texture = this->getTexture(); 127 GrTexture* texture = this->getTexture();
128 if (texture) { 128 if (texture) {
129 texture->texturePriv().dirtyMipMaps(true); 129 texture->texturePriv().dirtyMipMaps(true);
130 } 130 }
131 } 131 }
132 132
133 SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, SkColorProfileType dstPT, 133 SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, SkColorSpace* dstCS, const SkIRect* subset) {
134 const SkIRect* subset) {
135 if (nullptr == fSurface) { 134 if (nullptr == fSurface) {
136 return nullptr; 135 return nullptr;
137 } 136 }
138 137
139 // Note that when copying a render-target-backed pixel ref, we 138 // Note that when copying a render-target-backed pixel ref, we
140 // return a texture-backed pixel ref instead. This is because 139 // return a texture-backed pixel ref instead. This is because
141 // render-target pixel refs are usually created in conjunction with 140 // render-target pixel refs are usually created in conjunction with
142 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live 141 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live
143 // independently of that texture. Texture-backed pixel refs, on the other 142 // independently of that texture. Texture-backed pixel refs, on the other
144 // hand, own their GrTextures, and are thus self-contained. 143 // hand, own their GrTextures, and are thus self-contained.
145 return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, dstPT, sub set); 144 return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, dstCS, sub set);
146 } 145 }
147 146
148 static bool tryAllocBitmapPixels(SkBitmap* bitmap) { 147 static bool tryAllocBitmapPixels(SkBitmap* bitmap) {
149 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); 148 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator();
150 if (nullptr != allocator) { 149 if (nullptr != allocator) {
151 return allocator->allocPixelRef(bitmap, 0); 150 return allocator->allocPixelRef(bitmap, 0);
152 } else { 151 } else {
153 // DiscardableMemory is not available, fallback to default allocator 152 // DiscardableMemory is not available, fallback to default allocator
154 return bitmap->tryAllocPixels(); 153 return bitmap->tryAllocPixels();
155 } 154 }
(...skipping 20 matching lines...) Expand all
176 bounds = SkIRect::MakeWH(this->info().width(), this->info().height()); 175 bounds = SkIRect::MakeWH(this->info().width(), this->info().height());
177 } 176 }
178 177
179 //Check the cache 178 //Check the cache
180 if(!SkBitmapCache::Find(this->getGenerationID(), bounds, dst)) { 179 if(!SkBitmapCache::Find(this->getGenerationID(), bounds, dst)) {
181 //Cache miss 180 //Cache miss
182 181
183 SkBitmap cachedBitmap; 182 SkBitmap cachedBitmap;
184 cachedBitmap.setInfo(SkImageInfo::Make(bounds.width(), bounds.height(), colorType, 183 cachedBitmap.setInfo(SkImageInfo::Make(bounds.width(), bounds.height(), colorType,
185 this->info().alphaType(), 184 this->info().alphaType(),
186 this->info().profileType())); 185 sk_ref_sp(this->info().colorSpace ())));
187 186
188 // If we can't alloc the pixels, then fail 187 // If we can't alloc the pixels, then fail
189 if (!tryAllocBitmapPixels(&cachedBitmap)) { 188 if (!tryAllocBitmapPixels(&cachedBitmap)) {
190 return false; 189 return false;
191 } 190 }
192 191
193 // Try to read the pixels from the surface 192 // Try to read the pixels from the surface
194 void* buffer = cachedBitmap.getPixels(); 193 void* buffer = cachedBitmap.getPixels();
195 bool readPixelsOk = fSurface->readPixels(bounds.fLeft, bounds.fTop, 194 bool readPixelsOk = fSurface->readPixels(bounds.fLeft, bounds.fTop,
196 bounds.width(), bounds.height(), 195 bounds.width(), bounds.height(),
197 config, buffer, cachedBitmap.rowBytes()); 196 config, buffer, cachedBitmap.rowBytes());
198 197
199 if (!readPixelsOk) { 198 if (!readPixelsOk) {
200 return false; 199 return false;
201 } 200 }
202 201
203 // If we are here, pixels were read correctly from the surface. 202 // If we are here, pixels were read correctly from the surface.
204 cachedBitmap.setImmutable(); 203 cachedBitmap.setImmutable();
205 //Add to the cache 204 //Add to the cache
206 SkBitmapCache::Add(this, bounds, cachedBitmap); 205 SkBitmapCache::Add(this, bounds, cachedBitmap);
207 206
208 dst->swap(cachedBitmap); 207 dst->swap(cachedBitmap);
209 } 208 }
210 209
211 return true; 210 return true;
212 211
213 } 212 }
OLDNEW
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | src/image/SkImage_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698