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

Side by Side Diff: src/image/SkImage_Gpu.cpp

Issue 2165703003: Adding an SkColorSpace to SkImage_Gpu (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: s/NULL/nullptr/ Created 4 years, 5 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/SkImage_Gpu.h ('k') | src/image/SkSurface_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 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 "SkAutoPixmapStorage.h" 8 #include "SkAutoPixmapStorage.h"
9 #include "GrCaps.h" 9 #include "GrCaps.h"
10 #include "GrContext.h" 10 #include "GrContext.h"
11 #include "GrDrawContext.h" 11 #include "GrDrawContext.h"
12 #include "GrImageIDTextureAdjuster.h" 12 #include "GrImageIDTextureAdjuster.h"
13 #include "effects/GrYUVEffect.h" 13 #include "effects/GrYUVEffect.h"
14 #include "SkCanvas.h" 14 #include "SkCanvas.h"
15 #include "SkBitmapCache.h" 15 #include "SkBitmapCache.h"
16 #include "SkGrPixelRef.h" 16 #include "SkGrPixelRef.h"
17 #include "SkGrPriv.h" 17 #include "SkGrPriv.h"
18 #include "SkImage_Gpu.h" 18 #include "SkImage_Gpu.h"
19 #include "SkMipMap.h" 19 #include "SkMipMap.h"
20 #include "SkPixelRef.h" 20 #include "SkPixelRef.h"
21 21
22 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText ure* tex, 22 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText ure* tex,
23 SkBudgeted budgeted) 23 sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted)
24 : INHERITED(w, h, uniqueID) 24 : INHERITED(w, h, uniqueID)
25 , fTexture(SkRef(tex)) 25 , fTexture(SkRef(tex))
26 , fAlphaType(at) 26 , fAlphaType(at)
27 , fBudgeted(budgeted) 27 , fBudgeted(budgeted)
28 , fColorSpace(std::move(colorSpace))
28 , fAddedRasterVersionToCache(false) 29 , fAddedRasterVersionToCache(false)
29 { 30 {
30 SkASSERT(tex->width() == w); 31 SkASSERT(tex->width() == w);
31 SkASSERT(tex->height() == h); 32 SkASSERT(tex->height() == h);
32 } 33 }
33 34
34 SkImage_Gpu::~SkImage_Gpu() { 35 SkImage_Gpu::~SkImage_Gpu() {
35 if (fAddedRasterVersionToCache.load()) { 36 if (fAddedRasterVersionToCache.load()) {
36 SkNotifyBitmapGenIDIsStale(this->uniqueID()); 37 SkNotifyBitmapGenIDIsStale(this->uniqueID());
37 } 38 }
38 } 39 }
39 40
40 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { 41 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
41 if (as_IB(image)->peekTexture()) { 42 if (as_IB(image)->peekTexture()) {
42 ((SkImage_Gpu*)image)->applyBudgetDecision(); 43 ((SkImage_Gpu*)image)->applyBudgetDecision();
43 } 44 }
44 } 45 }
45 46
46 static SkImageInfo make_info(int w, int h, bool isOpaque) { 47 static SkImageInfo make_info(int w, int h, bool isOpaque, sk_sp<SkColorSpace> co lorSpace) {
47 return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_S kAlphaType); 48 return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_S kAlphaType,
49 std::move(colorSpace));
48 } 50 }
49 51
50 bool SkImage_Gpu::getROPixels(SkBitmap* dst, CachingHint chint) const { 52 bool SkImage_Gpu::getROPixels(SkBitmap* dst, CachingHint chint) const {
51 if (SkBitmapCache::Find(this->uniqueID(), dst)) { 53 if (SkBitmapCache::Find(this->uniqueID(), dst)) {
52 SkASSERT(dst->getGenerationID() == this->uniqueID()); 54 SkASSERT(dst->getGenerationID() == this->uniqueID());
53 SkASSERT(dst->isImmutable()); 55 SkASSERT(dst->isImmutable());
54 SkASSERT(dst->getPixels()); 56 SkASSERT(dst->getPixels());
55 return true; 57 return true;
56 } 58 }
57 59
58 if (!dst->tryAllocPixels(make_info(this->width(), this->height(), this->isOp aque()))) { 60 if (!dst->tryAllocPixels(make_info(this->width(), this->height(), this->isOp aque(),
61 this->fColorSpace))) {
59 return false; 62 return false;
60 } 63 }
61 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix elConfig, 64 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix elConfig,
62 dst->getPixels(), dst->rowBytes())) { 65 dst->getPixels(), dst->rowBytes())) {
63 return false; 66 return false;
64 } 67 }
65 68
66 dst->pixelRef()->setImmutableWithID(this->uniqueID()); 69 dst->pixelRef()->setImmutableWithID(this->uniqueID());
67 if (kAllow_CachingHint == chint) { 70 if (kAllow_CachingHint == chint) {
68 SkBitmapCache::Add(this->uniqueID(), *dst); 71 SkBitmapCache::Add(this->uniqueID(), *dst);
69 fAddedRasterVersionToCache.store(true); 72 fAddedRasterVersionToCache.store(true);
70 } 73 }
71 return true; 74 return true;
72 } 75 }
73 76
74 bool SkImage_Gpu::asBitmapForImageFilters(SkBitmap* bitmap) const { 77 bool SkImage_Gpu::asBitmapForImageFilters(SkBitmap* bitmap) const {
75 bitmap->setInfo(make_info(this->width(), this->height(), this->isOpaque())); 78 bitmap->setInfo(make_info(this->width(), this->height(), this->isOpaque(), f ColorSpace));
76 bitmap->setPixelRef(new SkGrPixelRef(bitmap->info(), fTexture))->unref(); 79 bitmap->setPixelRef(new SkGrPixelRef(bitmap->info(), fTexture))->unref();
77 bitmap->pixelRef()->setImmutableWithID(this->uniqueID()); 80 bitmap->pixelRef()->setImmutableWithID(this->uniqueID());
78 return true; 81 return true;
79 } 82 }
80 83
81 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para ms, 84 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para ms,
82 SkSourceGammaTreatment gammaTreatment) cons t { 85 SkSourceGammaTreatment gammaTreatment) cons t {
83 return GrImageTextureAdjuster(as_IB(this)).refTextureSafeForParams(params, g ammaTreatment, 86 return GrImageTextureAdjuster(as_IB(this)).refTextureSafeForParams(params, g ammaTreatment,
84 nullptr); 87 nullptr);
85 } 88 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 GrSurfaceDesc desc = fTexture->desc(); 143 GrSurfaceDesc desc = fTexture->desc();
141 desc.fWidth = subset.width(); 144 desc.fWidth = subset.width();
142 desc.fHeight = subset.height(); 145 desc.fHeight = subset.height();
143 146
144 sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, fBudgeted )); 147 sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, fBudgeted ));
145 if (!subTx) { 148 if (!subTx) {
146 return nullptr; 149 return nullptr;
147 } 150 }
148 ctx->copySurface(subTx.get(), fTexture, subset, SkIPoint::Make(0, 0)); 151 ctx->copySurface(subTx.get(), fTexture, subset, SkIPoint::Make(0, 0));
149 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID, 152 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID,
150 fAlphaType, subTx.get(), fBudgeted); 153 fAlphaType, subTx.get(), fColorSpace, fBudget ed);
151 } 154 }
152 155
153 //////////////////////////////////////////////////////////////////////////////// /////////////////// 156 //////////////////////////////////////////////////////////////////////////////// ///////////////////
154 157
155 static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend TextureDesc& desc, 158 static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend TextureDesc& desc,
156 SkAlphaType at, GrWrapOwnership ownership, 159 SkAlphaType at, sk_sp<SkColorSp ace> colorSpace,
160 GrWrapOwnership ownership,
157 SkImage::TextureReleaseProc rel easeProc, 161 SkImage::TextureReleaseProc rel easeProc,
158 SkImage::ReleaseContext release Ctx) { 162 SkImage::ReleaseContext release Ctx) {
159 if (desc.fWidth <= 0 || desc.fHeight <= 0) { 163 if (desc.fWidth <= 0 || desc.fHeight <= 0) {
160 return nullptr; 164 return nullptr;
161 } 165 }
162 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership)); 166 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership));
163 if (!tex) { 167 if (!tex) {
164 return nullptr; 168 return nullptr;
165 } 169 }
166 if (releaseProc) { 170 if (releaseProc) {
167 tex->setRelease(releaseProc, releaseCtx); 171 tex->setRelease(releaseProc, releaseCtx);
168 } 172 }
169 173
170 const SkBudgeted budgeted = SkBudgeted::kNo; 174 const SkBudgeted budgeted = SkBudgeted::kNo;
171 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID, 175 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID,
172 at, tex, budgeted); 176 at, tex, colorSpace, budgeted);
173 } 177 }
174 178
175 sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDe sc& desc, 179 sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDe sc& desc,
176 SkAlphaType at, TextureReleaseProc relea seP, 180 SkAlphaType at, sk_sp<SkColorSpace> cs,
177 ReleaseContext releaseC) { 181 TextureReleaseProc releaseP, ReleaseCont ext releaseC) {
178 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re leaseP, releaseC); 182 return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kBorrow_GrWr apOwnership,
183 releaseP, releaseC);
179 } 184 }
180 185
181 sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTe xtureDesc& desc, 186 sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTe xtureDesc& desc,
182 SkAlphaType at) { 187 SkAlphaType at, sk_sp<SkColorSpac e> cs) {
183 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul lptr, nullptr); 188 return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kAdopt_GrWra pOwnership,
189 nullptr, nullptr);
184 } 190 }
185 191
186 static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac e colorSpace, 192 static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac e colorSpace,
187 bool nv12, 193 bool nv12,
188 const GrBackendObject yuvTextu reHandles[], 194 const GrBackendObject yuvTextu reHandles[],
189 const SkISize yuvSizes[], 195 const SkISize yuvSizes[],
190 GrSurfaceOrigin origin) { 196 GrSurfaceOrigin origin,
197 sk_sp<SkColorSpace> imageColor Space) {
191 const SkBudgeted budgeted = SkBudgeted::kYes; 198 const SkBudgeted budgeted = SkBudgeted::kYes;
192 199
193 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || yuvSizes[1].fWidt h <= 0 || 200 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || yuvSizes[1].fWidt h <= 0 ||
194 yuvSizes[1].fHeight <= 0) { 201 yuvSizes[1].fHeight <= 0) {
195 return nullptr; 202 return nullptr;
196 } 203 }
197 if (!nv12 && (yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0)) { 204 if (!nv12 && (yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0)) {
198 return nullptr; 205 return nullptr;
199 } 206 }
200 207
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 GrPaint paint; 262 GrPaint paint;
256 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 263 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
257 paint.addColorFragmentProcessor( 264 paint.addColorFragmentProcessor(
258 GrYUVEffect::MakeYUVToRGB(yTex.get(), uTex.get(), vTex.get(), yuvSizes, colorSpace, nv12)); 265 GrYUVEffect::MakeYUVToRGB(yTex.get(), uTex.get(), vTex.get(), yuvSizes, colorSpace, nv12));
259 266
260 const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh t)); 267 const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh t));
261 268
262 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect); 269 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect);
263 ctx->flushSurfaceWrites(drawContext->accessRenderTarget()); 270 ctx->flushSurfaceWrites(drawContext->accessRenderTarget());
264 return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID, 271 return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID,
265 kOpaque_SkAlphaType, 272 kOpaque_SkAlphaType, drawContext->asTexture() .get(),
266 drawContext->asTexture().get(), budgeted); 273 std::move(imageColorSpace), budgeted);
267 } 274 }
268 275
269 sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, 276 sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace,
270 const GrBackendObject yuvTexture Handles[3], 277 const GrBackendObject yuvTexture Handles[3],
271 const SkISize yuvSizes[3], GrSur faceOrigin origin) { 278 const SkISize yuvSizes[3], GrSur faceOrigin origin,
272 return make_from_yuv_textures_copy(ctx, colorSpace, false, yuvTextureHandles , yuvSizes, origin); 279 sk_sp<SkColorSpace> imageColorSp ace) {
280 return make_from_yuv_textures_copy(ctx, colorSpace, false, yuvTextureHandles , yuvSizes, origin,
281 std::move(imageColorSpace));
273 } 282 }
274 283
275 sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, 284 sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace,
276 const GrBackendObject yuvTextur eHandles[2], 285 const GrBackendObject yuvTextur eHandles[2],
277 const SkISize yuvSizes[2], 286 const SkISize yuvSizes[2],
278 GrSurfaceOrigin origin) { 287 GrSurfaceOrigin origin,
279 return make_from_yuv_textures_copy(ctx, colorSpace, true, yuvTextureHandles, yuvSizes, origin); 288 sk_sp<SkColorSpace> imageColorS pace) {
289 return make_from_yuv_textures_copy(ctx, colorSpace, true, yuvTextureHandles, yuvSizes, origin,
290 std::move(imageColorSpace));
280 } 291 }
281 292
282 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) { 293 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
283 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams:: ClampNoFilter(), 294 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams:: ClampNoFilter(),
284 SkSourceGammaTrea tment::kRespect)); 295 SkSourceGammaTrea tment::kRespect));
285 if (!texture) { 296 if (!texture) {
286 return nullptr; 297 return nullptr;
287 } 298 }
288 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture, 299 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture,
289 SkBudgeted::kNo); 300 sk_ref_sp(maker->getColorSpace()), SkBudgeted ::kNo);
290 } 301 }
291 302
292 sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const { 303 sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const {
293 if (!context) { 304 if (!context) {
294 return nullptr; 305 return nullptr;
295 } 306 }
296 if (GrTexture* peek = as_IB(this)->peekTexture()) { 307 if (GrTexture* peek = as_IB(this)->peekTexture()) {
297 return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(th is)) : nullptr; 308 return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(th is)) : nullptr;
298 } 309 }
299 // No way to check whether a image is premul or not? 310 // No way to check whether a image is premul or not?
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pi xmap, 350 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pi xmap,
340 SkBudgeted budgeted) { 351 SkBudgeted budgeted) {
341 if (!ctx) { 352 if (!ctx) {
342 return nullptr; 353 return nullptr;
343 } 354 }
344 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgete d)); 355 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgete d));
345 if (!texture) { 356 if (!texture) {
346 return nullptr; 357 return nullptr;
347 } 358 }
348 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, 359 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
349 pixmap.alphaType(), texture, budgeted); 360 pixmap.alphaType(), texture,
361 sk_ref_sp(pixmap.info().colorSpace()), budget ed);
350 } 362 }
351 363
352 //////////////////////////////////////////////////////////////////////////////// /////////////////// 364 //////////////////////////////////////////////////////////////////////////////// ///////////////////
353 365
354 class DeferredTextureImage { 366 class DeferredTextureImage {
355 public: 367 public:
356 SkImage* newImage(GrContext* context, SkBudgeted) const; 368 SkImage* newImage(GrContext* context, SkBudgeted) const;
357 369
358 private: 370 private:
359 uint32_t fContextUniqueID; 371 uint32_t fContextUniqueID;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 const GrMipLevel* texels, int mipL evelCount, 549 const GrMipLevel* texels, int mipL evelCount,
538 SkBudgeted budgeted) { 550 SkBudgeted budgeted) {
539 if (!ctx) { 551 if (!ctx) {
540 return nullptr; 552 return nullptr;
541 } 553 }
542 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount)); 554 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount));
543 if (!texture) { 555 if (!texture) {
544 return nullptr; 556 return nullptr;
545 } 557 }
546 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, 558 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
547 info.alphaType(), texture, budgeted); 559 info.alphaType(), texture, sk_ref_sp(info.col orSpace()),
560 budgeted);
548 } 561 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698