| 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 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 const GrCaps* caps = ctx->caps(); | 241 const GrCaps* caps = ctx->caps(); |
| 242 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps); | 242 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps); |
| 243 | 243 |
| 244 if (caps->srgbSupport() && !GrPixelConfigIsSRGB(desc.fConfig) && | 244 if (caps->srgbSupport() && !GrPixelConfigIsSRGB(desc.fConfig) && |
| 245 kSRGB_SkColorProfileType == pixmap.info().profileType()) { | 245 kSRGB_SkColorProfileType == pixmap.info().profileType()) { |
| 246 // We we supplied sRGB as the profile type, but we don't have a suitable
pixel config. | 246 // We were supplied sRGB as the profile type, but we don't have a suitab
le pixel config. |
| 247 // Convert to 8888 sRGB so we can handle the data correctly. The raster
backend doesn't | 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 | 248 // handle sRGB Index8 -> sRGB 8888 correctly (yet), so lie about both th
e source and |
| 249 // destination (claim they're linear): | 249 // destination (claim they're linear): |
| 250 SkImageInfo linSrcInfo = SkImageInfo::Make(pixmap.width(), pixmap.height
(), | 250 SkImageInfo linSrcInfo = SkImageInfo::Make(pixmap.width(), pixmap.height
(), |
| 251 pixmap.colorType(), pixmap.al
phaType()); | 251 pixmap.colorType(), pixmap.al
phaType()); |
| 252 SkPixmap linSrcPixmap(linSrcInfo, pixmap.addr(), pixmap.rowBytes(), pixm
ap.ctable()); | 252 SkPixmap linSrcPixmap(linSrcInfo, pixmap.addr(), pixmap.rowBytes(), pixm
ap.ctable()); |
| 253 | 253 |
| 254 SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap.
height(), | 254 SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap.
height(), |
| 255 kSRGB_SkColorProfileTyp
e); | 255 kSRGB_SkColorProfileTyp
e); |
| 256 tmpBitmap.allocPixels(dstInfo); | 256 tmpBitmap.allocPixels(dstInfo); |
| 257 | 257 |
| 258 SkImageInfo linDstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixm
ap.height()); | 258 SkImageInfo linDstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixm
ap.height()); |
| 259 if (!linSrcPixmap.readPixels(linDstInfo, tmpBitmap.getPixels(), tmpBitma
p.rowBytes())) { | 259 if (!linSrcPixmap.readPixels(linDstInfo, tmpBitmap.getPixels(), tmpBitma
p.rowBytes())) { |
| 260 return nullptr; | 260 return nullptr; |
| 261 } | 261 } |
| 262 if (!tmpBitmap.peekPixels(&tmpPixmap)) { | 262 if (!tmpBitmap.peekPixels(&tmpPixmap)) { |
| 263 return nullptr; | 263 return nullptr; |
| 264 } | 264 } |
| 265 pmap = &tmpPixmap; | 265 pmap = &tmpPixmap; |
| 266 // must rebuild desc, since we've forced the info to be N32 | 266 // must rebuild desc, since we've forced the info to be N32 |
| 267 desc = GrImageInfoToSurfaceDesc(pmap->info(), *caps); | 267 desc = GrImageInfoToSurfaceDesc(pmap->info(), *caps); |
| 268 } else if (kGray_8_SkColorType == pixmap.colorType()) { |
| 269 // We don't have Gray8 support as a pixel config, so expand to 8888 |
| 270 |
| 271 // We should have converted sRGB Gray8 above (if we have sRGB support): |
| 272 SkASSERT(!caps->srgbSupport() || kLinear_SkColorProfileType == pixmap.in
fo().profileType()); |
| 273 |
| 274 SkImageInfo info = SkImageInfo::MakeN32(pixmap.width(), pixmap.height(), |
| 275 kOpaque_SkAlphaType); |
| 276 tmpBitmap.allocPixels(info); |
| 277 if (!pixmap.readPixels(info, tmpBitmap.getPixels(), tmpBitmap.rowBytes()
)) { |
| 278 return nullptr; |
| 279 } |
| 280 if (!tmpBitmap.peekPixels(&tmpPixmap)) { |
| 281 return nullptr; |
| 282 } |
| 283 pmap = &tmpPixmap; |
| 284 // must rebuild desc, since we've forced the info to be N32 |
| 285 desc = GrImageInfoToSurfaceDesc(pmap->info(), *caps); |
| 268 } else if (kIndex_8_SkColorType == pixmap.colorType()) { | 286 } else if (kIndex_8_SkColorType == pixmap.colorType()) { |
| 269 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { | 287 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { |
| 270 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, | 288 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, |
| 271 pixmap.width(), pixmap
.height()); | 289 pixmap.width(), pixmap
.height()); |
| 272 SkAutoMalloc storage(imageSize); | 290 SkAutoMalloc storage(imageSize); |
| 273 build_index8_data(storage.get(), pixmap); | 291 build_index8_data(storage.get(), pixmap); |
| 274 | 292 |
| 275 // our compressed data will be trimmed, so pass width() for its | 293 // our compressed data will be trimmed, so pass width() for its |
| 276 // "rowBytes", since they are the same now. | 294 // "rowBytes", since they are the same now. |
| 277 return ctx->textureProvider()->createTexture(desc, budgeted, storage
.get(), | 295 return ctx->textureProvider()->createTexture(desc, budgeted, storage
.get(), |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 SkErrorInternals::SetError( kInvalidPaint_SkError, | 743 SkErrorInternals::SetError( kInvalidPaint_SkError, |
| 726 "Sorry, I don't understand the filtering
" | 744 "Sorry, I don't understand the filtering
" |
| 727 "mode you asked for. Falling back to " | 745 "mode you asked for. Falling back to " |
| 728 "MIPMaps."); | 746 "MIPMaps."); |
| 729 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 747 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
| 730 break; | 748 break; |
| 731 | 749 |
| 732 } | 750 } |
| 733 return textureFilterMode; | 751 return textureFilterMode; |
| 734 } | 752 } |
| OLD | NEW |