OLD | NEW |
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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 236 |
237 GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap, SkBud
geted budgeted) { | 237 GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap, SkBud
geted budgeted) { |
238 const SkPixmap* pmap = &pixmap; | 238 const SkPixmap* pmap = &pixmap; |
239 SkPixmap tmpPixmap; | 239 SkPixmap tmpPixmap; |
240 SkBitmap tmpBitmap; | 240 SkBitmap tmpBitmap; |
241 | 241 |
242 const GrCaps* caps = ctx->caps(); | 242 const GrCaps* caps = ctx->caps(); |
243 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps); | 243 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps); |
244 | 244 |
245 if (caps->srgbSupport() && !GrPixelConfigIsSRGB(desc.fConfig) && | 245 if (caps->srgbSupport() && !GrPixelConfigIsSRGB(desc.fConfig) && |
246 kSRGB_SkColorProfileType == pixmap.info().profileType()) { | 246 pixmap.info().colorSpace() && pixmap.info().colorSpace()->gammaCloseToSR
GB()) { |
247 // We were supplied sRGB as the profile type, but we don't have a suitab
le pixel config. | 247 // We were supplied an sRGB-like color space, but we don't have a suitab
le pixel config. |
248 // Convert to 8888 sRGB so we can handle the data correctly. The raster
backend doesn't | 248 // Convert to 8888 sRGB so we can handle the data correctly. The raster
backend doesn't |
249 // handle sRGB Index8 -> sRGB 8888 correctly (yet), so lie about both th
e source and | 249 // handle sRGB Index8 -> sRGB 8888 correctly (yet), so lie about both th
e source and |
250 // destination (claim they're linear): | 250 // destination (claim they're linear): |
251 SkImageInfo linSrcInfo = SkImageInfo::Make(pixmap.width(), pixmap.height
(), | 251 SkImageInfo linSrcInfo = SkImageInfo::Make(pixmap.width(), pixmap.height
(), |
252 pixmap.colorType(), pixmap.al
phaType()); | 252 pixmap.colorType(), pixmap.al
phaType()); |
253 SkPixmap linSrcPixmap(linSrcInfo, pixmap.addr(), pixmap.rowBytes(), pixm
ap.ctable()); | 253 SkPixmap linSrcPixmap(linSrcInfo, pixmap.addr(), pixmap.rowBytes(), pixm
ap.ctable()); |
254 | 254 |
255 SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap.
height(), | 255 SkImageInfo dstInfo = SkImageInfo::Make(pixmap.width(), pixmap.height(), |
256 kSRGB_SkColorProfileTyp
e); | 256 kN32_SkColorType, kPremul_SkAlph
aType, |
| 257 sk_ref_sp(pixmap.info().colorSpa
ce())); |
| 258 |
257 tmpBitmap.allocPixels(dstInfo); | 259 tmpBitmap.allocPixels(dstInfo); |
258 | 260 |
259 SkImageInfo linDstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixm
ap.height()); | 261 SkImageInfo linDstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixm
ap.height()); |
260 if (!linSrcPixmap.readPixels(linDstInfo, tmpBitmap.getPixels(), tmpBitma
p.rowBytes())) { | 262 if (!linSrcPixmap.readPixels(linDstInfo, tmpBitmap.getPixels(), tmpBitma
p.rowBytes())) { |
261 return nullptr; | 263 return nullptr; |
262 } | 264 } |
263 if (!tmpBitmap.peekPixels(&tmpPixmap)) { | 265 if (!tmpBitmap.peekPixels(&tmpPixmap)) { |
264 return nullptr; | 266 return nullptr; |
265 } | 267 } |
266 pmap = &tmpPixmap; | 268 pmap = &tmpPixmap; |
267 // must rebuild desc, since we've forced the info to be N32 | 269 // must rebuild desc, since we've forced the info to be N32 |
268 desc = GrImageInfoToSurfaceDesc(pmap->info(), *caps); | 270 desc = GrImageInfoToSurfaceDesc(pmap->info(), *caps); |
269 } else if (kGray_8_SkColorType == pixmap.colorType()) { | 271 } else if (kGray_8_SkColorType == pixmap.colorType()) { |
270 // We don't have Gray8 support as a pixel config, so expand to 8888 | 272 // We don't have Gray8 support as a pixel config, so expand to 8888 |
271 | 273 |
272 // We should have converted sRGB Gray8 above (if we have sRGB support): | 274 // We should have converted sRGB Gray8 above (if we have sRGB support): |
273 SkASSERT(!caps->srgbSupport() || kLinear_SkColorProfileType == pixmap.in
fo().profileType()); | 275 SkASSERT(!caps->srgbSupport() || !pixmap.info().colorSpace() || |
| 276 !pixmap.info().colorSpace()->gammaCloseToSRGB()); |
274 | 277 |
275 SkImageInfo info = SkImageInfo::MakeN32(pixmap.width(), pixmap.height(), | 278 SkImageInfo info = SkImageInfo::MakeN32(pixmap.width(), pixmap.height(), |
276 kOpaque_SkAlphaType); | 279 kOpaque_SkAlphaType); |
277 tmpBitmap.allocPixels(info); | 280 tmpBitmap.allocPixels(info); |
278 if (!pixmap.readPixels(info, tmpBitmap.getPixels(), tmpBitmap.rowBytes()
)) { | 281 if (!pixmap.readPixels(info, tmpBitmap.getPixels(), tmpBitmap.rowBytes()
)) { |
279 return nullptr; | 282 return nullptr; |
280 } | 283 } |
281 if (!tmpBitmap.peekPixels(&tmpPixmap)) { | 284 if (!tmpBitmap.peekPixels(&tmpPixmap)) { |
282 return nullptr; | 285 return nullptr; |
283 } | 286 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params,
gammaTreatment, | 414 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params,
gammaTreatment, |
412 nullptr)
; | 415 nullptr)
; |
413 } | 416 } |
414 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, gammaTr
eatment); | 417 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, gammaTr
eatment); |
415 } | 418 } |
416 | 419 |
417 /////////////////////////////////////////////////////////////////////////////// | 420 /////////////////////////////////////////////////////////////////////////////// |
418 | 421 |
419 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass | 422 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass |
420 // alpha info, that will be considered. | 423 // alpha info, that will be considered. |
421 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf
ileType pt, | 424 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, const SkCol
orSpace* cs, |
422 const GrCaps& caps) { | 425 const GrCaps& caps) { |
423 // We intentionally ignore profile type for non-8888 formats. Anything we ca
n't support | 426 // We intentionally ignore profile type for non-8888 formats. Anything we ca
n't support |
424 // in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture. | 427 // in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture. |
425 switch (ct) { | 428 switch (ct) { |
426 case kUnknown_SkColorType: | 429 case kUnknown_SkColorType: |
427 return kUnknown_GrPixelConfig; | 430 return kUnknown_GrPixelConfig; |
428 case kAlpha_8_SkColorType: | 431 case kAlpha_8_SkColorType: |
429 return kAlpha_8_GrPixelConfig; | 432 return kAlpha_8_GrPixelConfig; |
430 case kRGB_565_SkColorType: | 433 case kRGB_565_SkColorType: |
431 return kRGB_565_GrPixelConfig; | 434 return kRGB_565_GrPixelConfig; |
432 case kARGB_4444_SkColorType: | 435 case kARGB_4444_SkColorType: |
433 return kRGBA_4444_GrPixelConfig; | 436 return kRGBA_4444_GrPixelConfig; |
434 case kRGBA_8888_SkColorType: | 437 case kRGBA_8888_SkColorType: |
435 return (kSRGB_SkColorProfileType == pt && caps.srgbSupport()) | 438 return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB()) |
436 ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig; | 439 ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig; |
437 case kBGRA_8888_SkColorType: | 440 case kBGRA_8888_SkColorType: |
438 return (kSRGB_SkColorProfileType == pt && caps.srgbSupport()) | 441 return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB()) |
439 ? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig; | 442 ? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig; |
440 case kIndex_8_SkColorType: | 443 case kIndex_8_SkColorType: |
441 return kIndex_8_GrPixelConfig; | 444 return kIndex_8_GrPixelConfig; |
442 case kGray_8_SkColorType: | 445 case kGray_8_SkColorType: |
443 return kAlpha_8_GrPixelConfig; // TODO: gray8 support on gpu | 446 return kAlpha_8_GrPixelConfig; // TODO: gray8 support on gpu |
444 case kRGBA_F16_SkColorType: | 447 case kRGBA_F16_SkColorType: |
445 return kRGBA_half_GrPixelConfig; | 448 return kRGBA_half_GrPixelConfig; |
446 } | 449 } |
447 SkASSERT(0); // shouldn't get here | 450 SkASSERT(0); // shouldn't get here |
448 return kUnknown_GrPixelConfig; | 451 return kUnknown_GrPixelConfig; |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 SkErrorInternals::SetError( kInvalidPaint_SkError, | 771 SkErrorInternals::SetError( kInvalidPaint_SkError, |
769 "Sorry, I don't understand the filtering
" | 772 "Sorry, I don't understand the filtering
" |
770 "mode you asked for. Falling back to " | 773 "mode you asked for. Falling back to " |
771 "MIPMaps."); | 774 "MIPMaps."); |
772 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 775 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
773 break; | 776 break; |
774 | 777 |
775 } | 778 } |
776 return textureFilterMode; | 779 return textureFilterMode; |
777 } | 780 } |
OLD | NEW |