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

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

Issue 1789663002: sRGB support in Ganesh. Several pieces: (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Squelch assert when blurring sRGB Created 4 years, 9 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/SkGpuDevice.cpp ('k') | src/gpu/SkGrPixelRef.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 #include "SkGr.h" 9 #include "SkGr.h"
10 #include "SkGrPriv.h" 10 #include "SkGrPriv.h"
(...skipping 25 matching lines...) Expand all
36 #include "effects/GrDitherEffect.h" 36 #include "effects/GrDitherEffect.h"
37 #include "effects/GrPorterDuffXferProcessor.h" 37 #include "effects/GrPorterDuffXferProcessor.h"
38 #include "effects/GrXfermodeFragmentProcessor.h" 38 #include "effects/GrXfermodeFragmentProcessor.h"
39 #include "effects/GrYUVEffect.h" 39 #include "effects/GrYUVEffect.h"
40 40
41 #ifndef SK_IGNORE_ETC1_SUPPORT 41 #ifndef SK_IGNORE_ETC1_SUPPORT
42 # include "ktx.h" 42 # include "ktx.h"
43 # include "etc1.h" 43 # include "etc1.h"
44 #endif 44 #endif
45 45
46 GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo& info) { 46 GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo& info, const GrCaps& ca ps) {
47 GrSurfaceDesc desc; 47 GrSurfaceDesc desc;
48 desc.fFlags = kNone_GrSurfaceFlags; 48 desc.fFlags = kNone_GrSurfaceFlags;
49 desc.fWidth = info.width(); 49 desc.fWidth = info.width();
50 desc.fHeight = info.height(); 50 desc.fHeight = info.height();
51 desc.fConfig = SkImageInfo2GrPixelConfig(info); 51 desc.fConfig = SkImageInfo2GrPixelConfig(info, caps);
52 desc.fSampleCnt = 0; 52 desc.fSampleCnt = 0;
53 return desc; 53 return desc;
54 } 54 }
55 55
56 void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& ima geBounds) { 56 void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& ima geBounds) {
57 SkASSERT(key); 57 SkASSERT(key);
58 SkASSERT(imageID); 58 SkASSERT(imageID);
59 SkASSERT(!imageBounds.isEmpty()); 59 SkASSERT(!imageBounds.isEmpty());
60 static const GrUniqueKey::Domain kImageIDDomain = GrUniqueKey::GenerateDomai n(); 60 static const GrUniqueKey::Domain kImageIDDomain = GrUniqueKey::GenerateDomai n();
61 GrUniqueKey::Builder builder(key, kImageIDDomain, 5); 61 GrUniqueKey::Builder builder(key, kImageIDDomain, 5);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 desc.fConfig = GrIsCompressedTextureDataSupported(ctx, data, bm.width(), bm. height(), 206 desc.fConfig = GrIsCompressedTextureDataSupported(ctx, data, bm.width(), bm. height(),
207 &startOfTexData); 207 &startOfTexData);
208 if (kUnknown_GrPixelConfig == desc.fConfig) { 208 if (kUnknown_GrPixelConfig == desc.fConfig) {
209 return nullptr; 209 return nullptr;
210 } 210 }
211 211
212 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, startOf TexData, 0); 212 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, startOf TexData, 0);
213 } 213 }
214 214
215 GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bitmap) { 215 GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bitmap) {
216 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info()); 216 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps());
217 if (GrTexture *texture = load_etc1_texture(ctx, bitmap, desc)) { 217 if (GrTexture *texture = load_etc1_texture(ctx, bitmap, desc)) {
218 return texture; 218 return texture;
219 } 219 }
220 220
221 if (GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc)) { 221 if (GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc)) {
222 return texture; 222 return texture;
223 } 223 }
224 224
225 SkAutoLockPixels alp(bitmap); 225 SkAutoLockPixels alp(bitmap);
226 if (!bitmap.readyToDraw()) { 226 if (!bitmap.readyToDraw()) {
227 return nullptr; 227 return nullptr;
228 } 228 }
229 SkPixmap pixmap; 229 SkPixmap pixmap;
230 if (!bitmap.peekPixels(&pixmap)) { 230 if (!bitmap.peekPixels(&pixmap)) {
231 return nullptr; 231 return nullptr;
232 } 232 }
233 return GrUploadPixmapToTexture(ctx, pixmap, SkBudgeted::kYes); 233 return GrUploadPixmapToTexture(ctx, pixmap, SkBudgeted::kYes);
234 } 234 }
235 235
236 GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap, SkBud geted budgeted) { 236 GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap, SkBud geted budgeted) {
237 const SkPixmap* pmap = &pixmap; 237 const SkPixmap* pmap = &pixmap;
238 SkPixmap tmpPixmap; 238 SkPixmap tmpPixmap;
239 SkBitmap tmpBitmap; 239 SkBitmap tmpBitmap;
240 240
241 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info());
242 const GrCaps* caps = ctx->caps(); 241 const GrCaps* caps = ctx->caps();
242 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps);
243 243
244 if (kIndex_8_SkColorType == pixmap.colorType()) { 244 if (caps->srgbSupport() && !GrPixelConfigIsSRGB(desc.fConfig) &&
245 kSRGB_SkColorProfileType == pixmap.info().profileType()) {
246 // We we supplied sRGB as the profile type, but we don't have a suitable pixel config.
247 // Convert to 8888 sRGB so we can handle the data correctly. The raster backend doesn't
248 // handle sRGB Index8 -> sRGB 8888 correctly (yet), so lie about both th e source and
249 // destination (claim they're linear):
250 SkImageInfo linSrcInfo = SkImageInfo::Make(pixmap.width(), pixmap.height (),
251 pixmap.colorType(), pixmap.al phaType());
252 SkPixmap linSrcPixmap(linSrcInfo, pixmap.addr(), pixmap.rowBytes(), pixm ap.ctable());
253
254 SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap. height(),
255 kSRGB_SkColorProfileTyp e);
256 tmpBitmap.allocPixels(dstInfo);
257
258 SkImageInfo linDstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixm ap.height());
259 if (!linSrcPixmap.readPixels(linDstInfo, tmpBitmap.getPixels(), tmpBitma p.rowBytes())) {
260 return nullptr;
261 }
262 if (!tmpBitmap.peekPixels(&tmpPixmap)) {
263 return nullptr;
264 }
265 pmap = &tmpPixmap;
266 // must rebuild desc, since we've forced the info to be N32
267 desc = GrImageInfoToSurfaceDesc(pmap->info(), *caps);
268 } else if (kIndex_8_SkColorType == pixmap.colorType()) {
245 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { 269 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) {
246 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig , 270 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig ,
247 pixmap.width(), pixmap .height()); 271 pixmap.width(), pixmap .height());
248 SkAutoMalloc storage(imageSize); 272 SkAutoMalloc storage(imageSize);
249 build_index8_data(storage.get(), pixmap); 273 build_index8_data(storage.get(), pixmap);
250 274
251 // our compressed data will be trimmed, so pass width() for its 275 // our compressed data will be trimmed, so pass width() for its
252 // "rowBytes", since they are the same now. 276 // "rowBytes", since they are the same now.
253 return ctx->textureProvider()->createTexture(desc, budgeted, storage .get(), 277 return ctx->textureProvider()->createTexture(desc, budgeted, storage .get(),
254 pixmap.width()); 278 pixmap.width());
255 } else { 279 } else {
256 SkImageInfo info = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap .height()); 280 SkImageInfo info = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap .height());
257 tmpBitmap.allocPixels(info); 281 tmpBitmap.allocPixels(info);
258 if (!pixmap.readPixels(info, tmpBitmap.getPixels(), tmpBitmap.rowByt es())) { 282 if (!pixmap.readPixels(info, tmpBitmap.getPixels(), tmpBitmap.rowByt es())) {
259 return nullptr; 283 return nullptr;
260 } 284 }
261 if (!tmpBitmap.peekPixels(&tmpPixmap)) { 285 if (!tmpBitmap.peekPixels(&tmpPixmap)) {
262 return nullptr; 286 return nullptr;
263 } 287 }
264 pmap = &tmpPixmap; 288 pmap = &tmpPixmap;
265 // must rebuild desc, since we've forced the info to be N32 289 // must rebuild desc, since we've forced the info to be N32
266 desc = GrImageInfoToSurfaceDesc(pmap->info()); 290 desc = GrImageInfoToSurfaceDesc(pmap->info(), *caps);
267 } 291 }
268 } 292 }
269 293
270 return ctx->textureProvider()->createTexture(desc, budgeted, pmap->addr(), 294 return ctx->textureProvider()->createTexture(desc, budgeted, pmap->addr(),
271 pmap->rowBytes()); 295 pmap->rowBytes());
272 } 296 }
273 297
274 298
275 //////////////////////////////////////////////////////////////////////////////// 299 ////////////////////////////////////////////////////////////////////////////////
276 300
277 void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix elRef) { 301 void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix elRef) {
278 class Invalidator : public SkPixelRef::GenIDChangeListener { 302 class Invalidator : public SkPixelRef::GenIDChangeListener {
279 public: 303 public:
280 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} 304 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {}
281 private: 305 private:
282 GrUniqueKeyInvalidatedMessage fMsg; 306 GrUniqueKeyInvalidatedMessage fMsg;
283 307
284 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>:: Post(fMsg); } 308 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>:: Post(fMsg); }
285 }; 309 };
286 310
287 pixelRef->addGenIDChangeListener(new Invalidator(key)); 311 pixelRef->addGenIDChangeListener(new Invalidator(key));
288 } 312 }
289 313
290 GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b itmap) 314 GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b itmap)
291 { 315 {
292 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info()); 316 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps());
293 if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) { 317 if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) {
294 GrTexture* texture = load_etc1_texture(ctx, bitmap, desc); 318 GrTexture* texture = load_etc1_texture(ctx, bitmap, desc);
295 if (texture) { 319 if (texture) {
296 return texture; 320 return texture;
297 } 321 }
298 } 322 }
299 323
300 GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc); 324 GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc);
301 if (texture) { 325 if (texture) {
302 return texture; 326 return texture;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if (bitmap.getTexture()) { 375 if (bitmap.getTexture()) {
352 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr); 376 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr);
353 } 377 }
354 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params); 378 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params);
355 } 379 }
356 380
357 /////////////////////////////////////////////////////////////////////////////// 381 ///////////////////////////////////////////////////////////////////////////////
358 382
359 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass 383 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass
360 // alpha info, that will be considered. 384 // alpha info, that will be considered.
361 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf ileType pt) { 385 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf ileType pt,
386 const GrCaps& caps) {
387 // We intentionally ignore profile type for non-8888 formats. Anything we ca n't support
388 // in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture.
362 switch (ct) { 389 switch (ct) {
363 case kUnknown_SkColorType: 390 case kUnknown_SkColorType:
364 return kUnknown_GrPixelConfig; 391 return kUnknown_GrPixelConfig;
365 case kAlpha_8_SkColorType: 392 case kAlpha_8_SkColorType:
366 return kAlpha_8_GrPixelConfig; 393 return kAlpha_8_GrPixelConfig;
367 case kRGB_565_SkColorType: 394 case kRGB_565_SkColorType:
368 return kRGB_565_GrPixelConfig; 395 return kRGB_565_GrPixelConfig;
369 case kARGB_4444_SkColorType: 396 case kARGB_4444_SkColorType:
370 return kRGBA_4444_GrPixelConfig; 397 return kRGBA_4444_GrPixelConfig;
371 case kRGBA_8888_SkColorType: 398 case kRGBA_8888_SkColorType:
372 //if (kSRGB_SkColorProfileType == pt) { 399 return (kSRGB_SkColorProfileType == pt && caps.srgbSupport())
373 // return kSRGBA_8888_GrPixelConfig; 400 ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
374 //}
375 return kRGBA_8888_GrPixelConfig;
376 case kBGRA_8888_SkColorType: 401 case kBGRA_8888_SkColorType:
377 return kBGRA_8888_GrPixelConfig; 402 return (kSRGB_SkColorProfileType == pt && caps.srgbSupport())
403 ? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig;
378 case kIndex_8_SkColorType: 404 case kIndex_8_SkColorType:
379 return kIndex_8_GrPixelConfig; 405 return kIndex_8_GrPixelConfig;
380 case kGray_8_SkColorType: 406 case kGray_8_SkColorType:
381 return kAlpha_8_GrPixelConfig; // TODO: gray8 support on gpu 407 return kAlpha_8_GrPixelConfig; // TODO: gray8 support on gpu
382 case kRGBA_F16_SkColorType: 408 case kRGBA_F16_SkColorType:
383 return kRGBA_half_GrPixelConfig; 409 return kRGBA_half_GrPixelConfig;
384 } 410 }
385 SkASSERT(0); // shouldn't get here 411 SkASSERT(0); // shouldn't get here
386 return kUnknown_GrPixelConfig; 412 return kUnknown_GrPixelConfig;
387 } 413 }
(...skipping 18 matching lines...) Expand all
406 case kRGBA_8888_GrPixelConfig: 432 case kRGBA_8888_GrPixelConfig:
407 ct = kRGBA_8888_SkColorType; 433 ct = kRGBA_8888_SkColorType;
408 break; 434 break;
409 case kBGRA_8888_GrPixelConfig: 435 case kBGRA_8888_GrPixelConfig:
410 ct = kBGRA_8888_SkColorType; 436 ct = kBGRA_8888_SkColorType;
411 break; 437 break;
412 case kSRGBA_8888_GrPixelConfig: 438 case kSRGBA_8888_GrPixelConfig:
413 ct = kRGBA_8888_SkColorType; 439 ct = kRGBA_8888_SkColorType;
414 pt = kSRGB_SkColorProfileType; 440 pt = kSRGB_SkColorProfileType;
415 break; 441 break;
442 case kSBGRA_8888_GrPixelConfig:
443 ct = kBGRA_8888_SkColorType;
444 pt = kSRGB_SkColorProfileType;
445 break;
416 default: 446 default:
417 return false; 447 return false;
418 } 448 }
419 if (ctOut) { 449 if (ctOut) {
420 *ctOut = ct; 450 *ctOut = ct;
421 } 451 }
422 if (ptOut) { 452 if (ptOut) {
423 *ptOut = pt; 453 *ptOut = pt;
424 } 454 }
425 return true; 455 return true;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 SkErrorInternals::SetError( kInvalidPaint_SkError, 725 SkErrorInternals::SetError( kInvalidPaint_SkError,
696 "Sorry, I don't understand the filtering " 726 "Sorry, I don't understand the filtering "
697 "mode you asked for. Falling back to " 727 "mode you asked for. Falling back to "
698 "MIPMaps."); 728 "MIPMaps.");
699 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 729 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
700 break; 730 break;
701 731
702 } 732 }
703 return textureFilterMode; 733 return textureFilterMode;
704 } 734 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698