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 | 10 |
11 #include "GrCaps.h" | 11 #include "GrCaps.h" |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #include "GrTextureParamsAdjuster.h" | |
14 #include "GrGpuResourcePriv.h" | 13 #include "GrGpuResourcePriv.h" |
15 #include "GrImageIDTextureAdjuster.h" | 14 #include "GrImageIDTextureAdjuster.h" |
| 15 #include "GrTextureParamsAdjuster.h" |
| 16 #include "GrTypes.h" |
16 #include "GrXferProcessor.h" | 17 #include "GrXferProcessor.h" |
17 #include "GrYUVProvider.h" | 18 #include "GrYUVProvider.h" |
18 | 19 |
19 #include "SkColorFilter.h" | 20 #include "SkColorFilter.h" |
20 #include "SkConfig8888.h" | 21 #include "SkConfig8888.h" |
21 #include "SkCanvas.h" | 22 #include "SkCanvas.h" |
22 #include "SkData.h" | 23 #include "SkData.h" |
23 #include "SkErrorInternals.h" | 24 #include "SkErrorInternals.h" |
24 #include "SkGrPixelRef.h" | 25 #include "SkGrPixelRef.h" |
25 #include "SkMessageBus.h" | 26 #include "SkMessageBus.h" |
| 27 #include "SkMipMap.h" |
26 #include "SkPixelRef.h" | 28 #include "SkPixelRef.h" |
27 #include "SkResourceCache.h" | 29 #include "SkResourceCache.h" |
| 30 #include "SkTemplates.h" |
28 #include "SkTextureCompressor.h" | 31 #include "SkTextureCompressor.h" |
29 #include "SkYUVPlanesCache.h" | 32 #include "SkYUVPlanesCache.h" |
30 #include "effects/GrBicubicEffect.h" | 33 #include "effects/GrBicubicEffect.h" |
31 #include "effects/GrConstColorProcessor.h" | 34 #include "effects/GrConstColorProcessor.h" |
32 #include "effects/GrDitherEffect.h" | 35 #include "effects/GrDitherEffect.h" |
33 #include "effects/GrPorterDuffXferProcessor.h" | 36 #include "effects/GrPorterDuffXferProcessor.h" |
34 #include "effects/GrXfermodeFragmentProcessor.h" | 37 #include "effects/GrXfermodeFragmentProcessor.h" |
35 #include "effects/GrYUVEffect.h" | 38 #include "effects/GrYUVEffect.h" |
36 | 39 |
37 #ifndef SK_IGNORE_ETC1_SUPPORT | 40 #ifndef SK_IGNORE_ETC1_SUPPORT |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} | 281 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} |
279 private: | 282 private: |
280 GrUniqueKeyInvalidatedMessage fMsg; | 283 GrUniqueKeyInvalidatedMessage fMsg; |
281 | 284 |
282 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::
Post(fMsg); } | 285 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::
Post(fMsg); } |
283 }; | 286 }; |
284 | 287 |
285 pixelRef->addGenIDChangeListener(new Invalidator(key)); | 288 pixelRef->addGenIDChangeListener(new Invalidator(key)); |
286 } | 289 } |
287 | 290 |
| 291 GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b
itmap) |
| 292 { |
| 293 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info()); |
| 294 if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) { |
| 295 GrTexture* texture = load_etc1_texture(ctx, bitmap, desc); |
| 296 if (texture) { |
| 297 return texture; |
| 298 } |
| 299 } |
| 300 |
| 301 GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc); |
| 302 if (texture) { |
| 303 return texture; |
| 304 } |
| 305 |
| 306 SkASSERT(sizeof(int) <= sizeof(uint32_t)); |
| 307 if (bitmap.width() < 0 || bitmap.height() < 0) { |
| 308 return nullptr; |
| 309 } |
| 310 |
| 311 SkAutoPixmapUnlock srcUnlocker; |
| 312 if (!bitmap.requestLock(&srcUnlocker)) { |
| 313 return nullptr; |
| 314 } |
| 315 const SkPixmap& pixmap = srcUnlocker.pixmap(); |
| 316 // Try to catch where we might have returned nullptr for src crbug.com/49281
8 |
| 317 if (nullptr == pixmap.addr()) { |
| 318 sk_throw(); |
| 319 } |
| 320 |
| 321 SkAutoTDelete<SkMipMap> mipmaps(SkMipMap::Build(pixmap, nullptr)); |
| 322 if (!mipmaps) { |
| 323 return nullptr; |
| 324 } |
| 325 |
| 326 const int mipLevelCount = mipmaps->countLevels() + 1; |
| 327 if (mipLevelCount < 1) { |
| 328 return nullptr; |
| 329 } |
| 330 |
| 331 const bool isMipMapped = mipLevelCount > 1; |
| 332 desc.fIsMipMapped = isMipMapped; |
| 333 |
| 334 SkAutoTDeleteArray<GrMipLevel> texels(new GrMipLevel[mipLevelCount]); |
| 335 |
| 336 texels[0].fPixels = pixmap.addr(); |
| 337 texels[0].fRowBytes = pixmap.rowBytes(); |
| 338 |
| 339 for (int i = 1; i < mipLevelCount; ++i) { |
| 340 SkMipMap::Level generatedMipLevel; |
| 341 mipmaps->getLevel(i - 1, &generatedMipLevel); |
| 342 texels[i].fPixels = generatedMipLevel.fPixmap.addr(); |
| 343 texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes(); |
| 344 } |
| 345 |
| 346 return ctx->textureProvider()->createMipMappedTexture(desc, SkBudgeted::kYes
, texels.get(), |
| 347 mipLevelCount); |
| 348 } |
| 349 |
288 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, | 350 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, |
289 const GrTextureParams& params) { | 351 const GrTextureParams& params) { |
290 if (bitmap.getTexture()) { | 352 if (bitmap.getTexture()) { |
291 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params,
nullptr); | 353 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params,
nullptr); |
292 } | 354 } |
293 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params); | 355 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params); |
294 } | 356 } |
295 | 357 |
296 /////////////////////////////////////////////////////////////////////////////// | 358 /////////////////////////////////////////////////////////////////////////////// |
297 | 359 |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 SkErrorInternals::SetError( kInvalidPaint_SkError, | 696 SkErrorInternals::SetError( kInvalidPaint_SkError, |
635 "Sorry, I don't understand the filtering
" | 697 "Sorry, I don't understand the filtering
" |
636 "mode you asked for. Falling back to " | 698 "mode you asked for. Falling back to " |
637 "MIPMaps."); | 699 "MIPMaps."); |
638 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 700 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
639 break; | 701 break; |
640 | 702 |
641 } | 703 } |
642 return textureFilterMode; | 704 return textureFilterMode; |
643 } | 705 } |
OLD | NEW |