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" | 13 #include "GrTextureParamsAdjuster.h" |
14 #include "GrGpuResourcePriv.h" | 14 #include "GrGpuResourcePriv.h" |
15 #include "GrImageIDTextureAdjuster.h" | 15 #include "GrImageIDTextureAdjuster.h" |
16 #include "GrXferProcessor.h" | 16 #include "GrXferProcessor.h" |
17 #include "GrYUVProvider.h" | 17 #include "GrYUVProvider.h" |
18 | 18 |
19 #include "SkColorFilter.h" | 19 #include "SkColorFilter.h" |
20 #include "SkConfig8888.h" | 20 #include "SkConfig8888.h" |
21 #include "SkCanvas.h" | 21 #include "SkCanvas.h" |
22 #include "SkData.h" | 22 #include "SkData.h" |
23 #include "SkErrorInternals.h" | 23 #include "SkErrorInternals.h" |
24 #include "SkGrPixelRef.h" | 24 #include "SkGrPixelRef.h" |
25 #include "SkMessageBus.h" | 25 #include "SkMessageBus.h" |
| 26 #include "SkMipMap.h" |
| 27 #include "SkMipMapLevel.h" |
26 #include "SkPixelRef.h" | 28 #include "SkPixelRef.h" |
27 #include "SkResourceCache.h" | 29 #include "SkResourceCache.h" |
28 #include "SkTextureCompressor.h" | 30 #include "SkTextureCompressor.h" |
29 #include "SkYUVPlanesCache.h" | 31 #include "SkYUVPlanesCache.h" |
30 #include "effects/GrBicubicEffect.h" | 32 #include "effects/GrBicubicEffect.h" |
31 #include "effects/GrConstColorProcessor.h" | 33 #include "effects/GrConstColorProcessor.h" |
32 #include "effects/GrDitherEffect.h" | 34 #include "effects/GrDitherEffect.h" |
33 #include "effects/GrPorterDuffXferProcessor.h" | 35 #include "effects/GrPorterDuffXferProcessor.h" |
34 #include "effects/GrXfermodeFragmentProcessor.h" | 36 #include "effects/GrXfermodeFragmentProcessor.h" |
35 #include "effects/GrYUVtoRGBEffect.h" | 37 #include "effects/GrYUVtoRGBEffect.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} | 280 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} |
279 private: | 281 private: |
280 GrUniqueKeyInvalidatedMessage fMsg; | 282 GrUniqueKeyInvalidatedMessage fMsg; |
281 | 283 |
282 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::
Post(fMsg); } | 284 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::
Post(fMsg); } |
283 }; | 285 }; |
284 | 286 |
285 pixelRef->addGenIDChangeListener(new Invalidator(key)); | 287 pixelRef->addGenIDChangeListener(new Invalidator(key)); |
286 } | 288 } |
287 | 289 |
| 290 GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b
itmap) |
| 291 { |
| 292 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info()); |
| 293 if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) { |
| 294 GrTexture *texture = load_etc1_texture(ctx, bitmap, desc); |
| 295 if (texture) { |
| 296 return texture; |
| 297 } |
| 298 } |
| 299 |
| 300 GrTexture *texture = create_texture_from_yuv(ctx, bitmap, desc); |
| 301 if (texture) { |
| 302 return texture; |
| 303 } |
| 304 |
| 305 SkASSERT(sizeof(int) <= sizeof(uint32_t)); |
| 306 if (bitmap.width() < 0 || bitmap.height() < 0) { |
| 307 return nullptr; |
| 308 } |
| 309 |
| 310 SkAutoLockPixels alp(bitmap); |
| 311 if (!bitmap.readyToDraw()) { |
| 312 return nullptr; |
| 313 } |
| 314 |
| 315 SkMipMap* mipmaps = SkMipMap::Build(bitmap, nullptr); |
| 316 if (!mipmaps) { |
| 317 return nullptr; |
| 318 } |
| 319 |
| 320 const int mipLevelCount = mipmaps->getLevelsCount(); |
| 321 |
| 322 const bool isMipMapped = mipLevelCount > 1; |
| 323 desc.fIsMipMapped = isMipMapped; |
| 324 |
| 325 SkTArray<SkMipMapLevel> texels(mipLevelCount); |
| 326 |
| 327 SkMipMapLevel baseLevel(bitmap.getPixels(), bitmap.rowBytes(), bitmap.width(
), |
| 328 bitmap.height()); |
| 329 texels.push_back(baseLevel); |
| 330 |
| 331 for (int i = 1; i <= mipLevelCount; ++i) { |
| 332 SkMipMap::Level generatedMipLevel; |
| 333 mipmaps->getLevel(i, &generatedMipLevel); |
| 334 SkMipMapLevel currentMipLevel(generatedMipLevel.fPixmap.addr(), |
| 335 generatedMipLevel.fPixmap.rowBytes(), |
| 336 generatedMipLevel.fPixmap.width(), |
| 337 generatedMipLevel.fPixmap.height()); |
| 338 texels.push_back(currentMipLevel); |
| 339 } |
| 340 |
| 341 return ctx->textureProvider()->createTexture(desc, true, texels); |
| 342 } |
| 343 |
288 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, | 344 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, |
289 const GrTextureParams& params) { | 345 const GrTextureParams& params) { |
290 if (bitmap.getTexture()) { | 346 if (bitmap.getTexture()) { |
291 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params,
nullptr); | 347 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params,
nullptr); |
292 } | 348 } |
293 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params); | 349 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params); |
294 } | 350 } |
295 | 351 |
296 /////////////////////////////////////////////////////////////////////////////// | 352 /////////////////////////////////////////////////////////////////////////////// |
297 | 353 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 SkErrorInternals::SetError( kInvalidPaint_SkError, | 683 SkErrorInternals::SetError( kInvalidPaint_SkError, |
628 "Sorry, I don't understand the filtering
" | 684 "Sorry, I don't understand the filtering
" |
629 "mode you asked for. Falling back to " | 685 "mode you asked for. Falling back to " |
630 "MIPMaps."); | 686 "MIPMaps."); |
631 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 687 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
632 break; | 688 break; |
633 | 689 |
634 } | 690 } |
635 return textureFilterMode; | 691 return textureFilterMode; |
636 } | 692 } |
OLD | NEW |