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

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

Issue 1814533003: Revert of sRGB support in Ganesh. Several pieces: (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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, const GrCaps& ca ps) { 46 GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo& info) {
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, caps); 51 desc.fConfig = SkImageInfo2GrPixelConfig(info);
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(), *ctx->caps()); 216 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info());
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); 233 return GrUploadPixmapToTexture(ctx, pixmap);
234 } 234 }
235 235
236 GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap) { 236 GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap) {
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());
241 const GrCaps* caps = ctx->caps(); 242 const GrCaps* caps = ctx->caps();
242 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps);
243 243
244 if (kIndex_8_SkColorType == pixmap.colorType()) { 244 if (kIndex_8_SkColorType == pixmap.colorType()) {
245 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { 245 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) {
246 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig , 246 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig ,
247 pixmap.width(), pixmap .height()); 247 pixmap.width(), pixmap .height());
248 SkAutoMalloc storage(imageSize); 248 SkAutoMalloc storage(imageSize);
249 build_index8_data(storage.get(), pixmap); 249 build_index8_data(storage.get(), pixmap);
250 250
251 // our compressed data will be trimmed, so pass width() for its 251 // our compressed data will be trimmed, so pass width() for its
252 // "rowBytes", since they are the same now. 252 // "rowBytes", since they are the same now.
253 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, storage.get(), 253 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, storage.get(),
254 pixmap.width()); 254 pixmap.width());
255 } else { 255 } else {
256 SkImageInfo info = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap .height()); 256 SkImageInfo info = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap .height());
257 tmpBitmap.allocPixels(info); 257 tmpBitmap.allocPixels(info);
258 if (!pixmap.readPixels(info, tmpBitmap.getPixels(), tmpBitmap.rowByt es())) { 258 if (!pixmap.readPixels(info, tmpBitmap.getPixels(), tmpBitmap.rowByt es())) {
259 return nullptr; 259 return nullptr;
260 } 260 }
261 if (!tmpBitmap.peekPixels(&tmpPixmap)) { 261 if (!tmpBitmap.peekPixels(&tmpPixmap)) {
262 return nullptr; 262 return nullptr;
263 } 263 }
264 pmap = &tmpPixmap; 264 pmap = &tmpPixmap;
265 // must rebuild desc, since we've forced the info to be N32 265 // must rebuild desc, since we've forced the info to be N32
266 desc = GrImageInfoToSurfaceDesc(pmap->info(), *caps); 266 desc = GrImageInfoToSurfaceDesc(pmap->info());
267 } 267 }
268 } 268 }
269 269
270 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, pmap->a ddr(), 270 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, pmap->a ddr(),
271 pmap->rowBytes()); 271 pmap->rowBytes());
272 } 272 }
273 273
274 274
275 //////////////////////////////////////////////////////////////////////////////// 275 ////////////////////////////////////////////////////////////////////////////////
276 276
277 void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix elRef) { 277 void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix elRef) {
278 class Invalidator : public SkPixelRef::GenIDChangeListener { 278 class Invalidator : public SkPixelRef::GenIDChangeListener {
279 public: 279 public:
280 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} 280 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {}
281 private: 281 private:
282 GrUniqueKeyInvalidatedMessage fMsg; 282 GrUniqueKeyInvalidatedMessage fMsg;
283 283
284 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>:: Post(fMsg); } 284 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>:: Post(fMsg); }
285 }; 285 };
286 286
287 pixelRef->addGenIDChangeListener(new Invalidator(key)); 287 pixelRef->addGenIDChangeListener(new Invalidator(key));
288 } 288 }
289 289
290 GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b itmap) 290 GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b itmap)
291 { 291 {
292 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps()); 292 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info());
293 if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) { 293 if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) {
294 GrTexture* texture = load_etc1_texture(ctx, bitmap, desc); 294 GrTexture* texture = load_etc1_texture(ctx, bitmap, desc);
295 if (texture) { 295 if (texture) {
296 return texture; 296 return texture;
297 } 297 }
298 } 298 }
299 299
300 GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc); 300 GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc);
301 if (texture) { 301 if (texture) {
302 return texture; 302 return texture;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if (bitmap.getTexture()) { 351 if (bitmap.getTexture()) {
352 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr); 352 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr);
353 } 353 }
354 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params); 354 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params);
355 } 355 }
356 356
357 /////////////////////////////////////////////////////////////////////////////// 357 ///////////////////////////////////////////////////////////////////////////////
358 358
359 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass 359 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass
360 // alpha info, that will be considered. 360 // alpha info, that will be considered.
361 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf ileType pt, 361 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf ileType pt) {
362 const GrCaps& caps) { 362 switch (ct) {
363 if (kSRGB_SkColorProfileType == pt && caps.srgbSupport()) { 363 case kUnknown_SkColorType:
364 switch (ct) { 364 return kUnknown_GrPixelConfig;
365 case kRGBA_8888_SkColorType: 365 case kAlpha_8_SkColorType:
366 return kSRGBA_8888_GrPixelConfig; 366 return kAlpha_8_GrPixelConfig;
367 case kBGRA_8888_SkColorType: 367 case kRGB_565_SkColorType:
368 return kSBGRA_8888_GrPixelConfig; 368 return kRGB_565_GrPixelConfig;
369 default: 369 case kARGB_4444_SkColorType:
370 break; 370 return kRGBA_4444_GrPixelConfig;
371 } 371 case kRGBA_8888_SkColorType:
372 } else { 372 //if (kSRGB_SkColorProfileType == pt) {
373 switch (ct) { 373 // return kSRGBA_8888_GrPixelConfig;
374 case kUnknown_SkColorType: 374 //}
375 return kUnknown_GrPixelConfig; 375 return kRGBA_8888_GrPixelConfig;
376 case kAlpha_8_SkColorType: 376 case kBGRA_8888_SkColorType:
377 return kAlpha_8_GrPixelConfig; 377 return kBGRA_8888_GrPixelConfig;
378 case kRGB_565_SkColorType: 378 case kIndex_8_SkColorType:
379 return kRGB_565_GrPixelConfig; 379 return kIndex_8_GrPixelConfig;
380 case kARGB_4444_SkColorType: 380 case kGray_8_SkColorType:
381 return kRGBA_4444_GrPixelConfig; 381 return kAlpha_8_GrPixelConfig; // TODO: gray8 support on gpu
382 case kRGBA_8888_SkColorType: 382 case kRGBA_F16_SkColorType:
383 return kRGBA_8888_GrPixelConfig; 383 return kRGBA_half_GrPixelConfig;
384 case kBGRA_8888_SkColorType:
385 return kBGRA_8888_GrPixelConfig;
386 case kIndex_8_SkColorType:
387 return kIndex_8_GrPixelConfig;
388 case kGray_8_SkColorType:
389 return kAlpha_8_GrPixelConfig; // TODO: gray8 support on gpu
390 case kRGBA_F16_SkColorType:
391 return kRGBA_half_GrPixelConfig;
392 }
393 } 384 }
394 SkASSERT(0); // shouldn't get here 385 SkASSERT(0); // shouldn't get here
395 return kUnknown_GrPixelConfig; 386 return kUnknown_GrPixelConfig;
396 } 387 }
397 388
398 bool GrPixelConfig2ColorAndProfileType(GrPixelConfig config, SkColorType* ctOut, 389 bool GrPixelConfig2ColorAndProfileType(GrPixelConfig config, SkColorType* ctOut,
399 SkColorProfileType* ptOut) { 390 SkColorProfileType* ptOut) {
400 SkColorType ct; 391 SkColorType ct;
401 SkColorProfileType pt = kLinear_SkColorProfileType; 392 SkColorProfileType pt = kLinear_SkColorProfileType;
402 switch (config) { 393 switch (config) {
(...skipping 12 matching lines...) Expand all
415 case kRGBA_8888_GrPixelConfig: 406 case kRGBA_8888_GrPixelConfig:
416 ct = kRGBA_8888_SkColorType; 407 ct = kRGBA_8888_SkColorType;
417 break; 408 break;
418 case kBGRA_8888_GrPixelConfig: 409 case kBGRA_8888_GrPixelConfig:
419 ct = kBGRA_8888_SkColorType; 410 ct = kBGRA_8888_SkColorType;
420 break; 411 break;
421 case kSRGBA_8888_GrPixelConfig: 412 case kSRGBA_8888_GrPixelConfig:
422 ct = kRGBA_8888_SkColorType; 413 ct = kRGBA_8888_SkColorType;
423 pt = kSRGB_SkColorProfileType; 414 pt = kSRGB_SkColorProfileType;
424 break; 415 break;
425 case kSBGRA_8888_GrPixelConfig:
426 ct = kBGRA_8888_SkColorType;
427 pt = kSRGB_SkColorProfileType;
428 break;
429 default: 416 default:
430 return false; 417 return false;
431 } 418 }
432 if (ctOut) { 419 if (ctOut) {
433 *ctOut = ct; 420 *ctOut = ct;
434 } 421 }
435 if (ptOut) { 422 if (ptOut) {
436 *ptOut = pt; 423 *ptOut = pt;
437 } 424 }
438 return true; 425 return true;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 SkErrorInternals::SetError( kInvalidPaint_SkError, 695 SkErrorInternals::SetError( kInvalidPaint_SkError,
709 "Sorry, I don't understand the filtering " 696 "Sorry, I don't understand the filtering "
710 "mode you asked for. Falling back to " 697 "mode you asked for. Falling back to "
711 "MIPMaps."); 698 "MIPMaps.");
712 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 699 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
713 break; 700 break;
714 701
715 } 702 }
716 return textureFilterMode; 703 return textureFilterMode;
717 } 704 }
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