Chromium Code Reviews| 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 #include "SkGr.h" | 8 #include "SkGr.h" |
| 9 | 9 |
| 10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
| 11 #include "GrDrawContext.h" | 11 #include "GrDrawContext.h" |
| 12 #include "GrXferProcessor.h" | 12 #include "GrXferProcessor.h" |
| 13 #include "GrYUVProvider.h" | 13 #include "GrYUVProvider.h" |
| 14 | 14 |
| 15 #include "SkColorFilter.h" | 15 #include "SkColorFilter.h" |
| 16 #include "SkConfig8888.h" | 16 #include "SkConfig8888.h" |
| 17 #include "SkCanvas.h" | 17 #include "SkCanvas.h" |
| 18 #include "SkData.h" | 18 #include "SkData.h" |
| 19 #include "SkErrorInternals.h" | 19 #include "SkErrorInternals.h" |
| 20 #include "SkGrPixelRef.h" | 20 #include "SkGrPixelRef.h" |
| 21 #include "SkMessageBus.h" | 21 #include "SkMessageBus.h" |
| 22 #include "SkMipMap.h" | |
| 23 #include "SkMipMapLevel.h" | |
| 22 #include "SkPixelRef.h" | 24 #include "SkPixelRef.h" |
| 23 #include "SkResourceCache.h" | 25 #include "SkResourceCache.h" |
| 24 #include "SkTextureCompressor.h" | 26 #include "SkTextureCompressor.h" |
| 25 #include "SkYUVPlanesCache.h" | 27 #include "SkYUVPlanesCache.h" |
| 26 #include "effects/GrBicubicEffect.h" | 28 #include "effects/GrBicubicEffect.h" |
| 27 #include "effects/GrDitherEffect.h" | 29 #include "effects/GrDitherEffect.h" |
| 28 #include "effects/GrPorterDuffXferProcessor.h" | 30 #include "effects/GrPorterDuffXferProcessor.h" |
| 29 #include "effects/GrYUVtoRGBEffect.h" | 31 #include "effects/GrYUVtoRGBEffect.h" |
| 30 | 32 |
| 31 #ifndef SK_IGNORE_ETC1_SUPPORT | 33 #ifndef SK_IGNORE_ETC1_SUPPORT |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 GrTexture* texture = provider.refAsTexture(ctx, desc, useCache); | 416 GrTexture* texture = provider.refAsTexture(ctx, desc, useCache); |
| 415 if (!texture) { | 417 if (!texture) { |
| 416 return nullptr; | 418 return nullptr; |
| 417 } | 419 } |
| 418 | 420 |
| 419 if (useCache) { | 421 if (useCache) { |
| 420 BitmapInvalidator* listener = new BitmapInvalidator(optionalKey); | 422 BitmapInvalidator* listener = new BitmapInvalidator(optionalKey); |
| 421 pixelRef->addGenIDChangeListener(listener); | 423 pixelRef->addGenIDChangeListener(listener); |
| 422 ctx->textureProvider()->assignUniqueKeyToTexture(optionalKey, texture); | 424 ctx->textureProvider()->assignUniqueKeyToTexture(optionalKey, texture); |
| 423 } | 425 } |
| 424 return texture; | 426 return texture; |
| 425 } | 427 } |
| 426 | 428 |
| 427 static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, | 429 static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, |
| 428 const SkBitmap& origBitmap, | 430 const SkBitmap& origBitmap, |
| 429 const GrUniqueKey& optionalK ey) { | 431 const GrUniqueKey& optionalK ey) { |
| 430 if (origBitmap.width() < ctx->caps()->minTextureSize() || | 432 if (origBitmap.width() < ctx->caps()->minTextureSize() || |
| 431 origBitmap.height() < ctx->caps()->minTextureSize()) { | 433 origBitmap.height() < ctx->caps()->minTextureSize()) { |
| 432 return nullptr; | 434 return nullptr; |
| 433 } | 435 } |
| 434 SkBitmap tmpBitmap; | 436 SkBitmap tmpBitmap; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 | 555 |
| 554 bool GrIsBitmapInCache(const GrContext* ctx, const SkBitmap& bitmap, | 556 bool GrIsBitmapInCache(const GrContext* ctx, const SkBitmap& bitmap, |
| 555 const GrTextureParams* params) { | 557 const GrTextureParams* params) { |
| 556 if (bitmap.isVolatile()) { | 558 if (bitmap.isVolatile()) { |
| 557 return false; // we don't cache volatile bitmaps. | 559 return false; // we don't cache volatile bitmaps. |
| 558 } | 560 } |
| 559 return GrIsImageInCache(ctx, bitmap.getGenerationID(), bitmap.getSubset(), b itmap.getTexture(), | 561 return GrIsImageInCache(ctx, bitmap.getGenerationID(), bitmap.getSubset(), b itmap.getTexture(), |
| 560 params); | 562 params); |
| 561 } | 563 } |
| 562 | 564 |
| 565 static GrTexture* create_mipmapped_texture(GrContext* ctx, | |
|
bsalomon
2015/09/30 18:01:29
You should coordinate with reed@ about landing thi
cblume
2015/10/08 09:27:57
I rebased ontop of those changes. There was a conf
| |
| 566 const SkBitmap& bitmap, | |
| 567 const GrUniqueKey& optionalKey, | |
| 568 SkDiscardableFactoryProc fact) { | |
| 569 GrTexture* texture = bitmap.getTexture(); | |
| 570 // If the SkBitmap is already backed by a texture, we do not want to read th e contents back | |
| 571 // to the cpu and generate the mipmap only to send it back to the GPU. | |
| 572 SkASSERT(!texture); | |
| 573 | |
| 574 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info()); | |
| 575 | |
| 576 SkMipMap* mipmap = SkMipMap::Build(bitmap, fact); | |
| 577 if (mipmap == nullptr) { | |
| 578 // could not create the mipmap | |
| 579 return nullptr; | |
| 580 } else { | |
| 581 int mipLevelCount = mipmap->getLevelsCount() + 1; | |
| 582 desc.fIsMipMapped = mipLevelCount > 1; | |
| 583 SkTArray<SkMipMapLevel> texels(mipLevelCount); | |
| 584 | |
| 585 SkAutoPixmapUnlock srcUnlocker; | |
| 586 if (!bitmap.requestLock(&srcUnlocker)) { | |
| 587 return nullptr; | |
| 588 } | |
| 589 const SkPixmap& srcPixmap = srcUnlocker.pixmap(); | |
| 590 if (nullptr == srcPixmap.addr()) { | |
| 591 return nullptr; | |
| 592 } | |
| 593 | |
| 594 int width = bitmap.width(); | |
| 595 int height = bitmap.height(); | |
| 596 if (width < 0 || height < 0) { | |
| 597 return nullptr; | |
| 598 } | |
| 599 uint32_t baseLevelWidth = width; | |
| 600 uint32_t baseLevelHeight = height; | |
| 601 SkMipMapLevel baseLevel(srcPixmap.addr(), bitmap.rowBytes(), baseLevelWi dth, | |
| 602 baseLevelHeight); | |
| 603 texels.push_back(baseLevel); | |
| 604 | |
| 605 for (int i = 1; i < mipLevelCount; i++) { | |
| 606 SkMipMap::Level level; | |
| 607 if (!mipmap->getLevel(i, &level)) { | |
| 608 return nullptr; | |
| 609 } | |
| 610 | |
| 611 SkMipMapLevel currentMipLevel(level.fPixels, level.fRowBytes, level. fWidth, | |
| 612 level.fHeight); | |
| 613 texels.push_back(currentMipLevel); | |
| 614 } | |
| 615 | |
| 616 SkPixelRef* pixelRef = bitmap.pixelRef(); | |
| 617 if (optionalKey.isValid()) { | |
| 618 BitmapInvalidator* listener = new BitmapInvalidator(optionalKey); | |
| 619 pixelRef->addGenIDChangeListener(listener); | |
| 620 ctx->textureProvider()->assignUniqueKeyToTexture(optionalKey, textur e); | |
| 621 } | |
| 622 | |
| 623 return ctx->textureProvider()->createTexture(desc, true, texels); | |
| 624 } | |
| 625 } | |
| 626 | |
| 563 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, | 627 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, |
| 564 const SkBitmap& bitmap, | 628 const SkBitmap& bitmap, |
| 565 const GrTextureParams* params) { | 629 const GrTextureParams* params) { |
| 566 | 630 |
| 567 Stretch stretch; | 631 Stretch stretch; |
| 568 get_stretch(ctx, bitmap.width(), bitmap.height(), params, &stretch); | 632 get_stretch(ctx, bitmap.width(), bitmap.height(), params, &stretch); |
| 569 | 633 |
| 570 GrTexture* result = bitmap.getTexture(); | 634 GrTexture* result = bitmap.getTexture(); |
| 571 if (result) { | 635 if (result) { |
| 572 if (Stretch::kNone_Type == stretch.fType) { | 636 if (Stretch::kNone_Type == stretch.fType) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 594 // If the bitmap isn't changing try to find a cached copy first. | 658 // If the bitmap isn't changing try to find a cached copy first. |
| 595 make_image_keys(bitmap.getGenerationID(), bitmap.getSubset(), stretch, & key, &resizedKey); | 659 make_image_keys(bitmap.getGenerationID(), bitmap.getSubset(), stretch, & key, &resizedKey); |
| 596 | 660 |
| 597 result = ctx->textureProvider()->findAndRefTextureByUniqueKey( | 661 result = ctx->textureProvider()->findAndRefTextureByUniqueKey( |
| 598 resizedKey.isValid() ? resizedKey : key); | 662 resizedKey.isValid() ? resizedKey : key); |
| 599 if (result) { | 663 if (result) { |
| 600 return result; | 664 return result; |
| 601 } | 665 } |
| 602 } | 666 } |
| 603 | 667 |
| 604 result = create_bitmap_texture(ctx, bitmap, stretch, key, resizedKey); | 668 if (params && params->filterMode() == GrTextureParams::kMipMap_FilterMode) { |
| 669 const SkDiscardableFactoryProc fact = nullptr; | |
| 670 result = create_mipmapped_texture(ctx, bitmap, key, fact); | |
| 671 } else { | |
| 672 result = create_bitmap_texture(ctx, bitmap, stretch, key, resizedKey); | |
| 673 } | |
| 674 | |
| 605 if (result) { | 675 if (result) { |
| 606 return result; | 676 return result; |
| 607 } | 677 } |
| 608 | 678 |
| 609 SkErrorInternals::SetError( kInternalError_SkError, | 679 SkErrorInternals::SetError( kInternalError_SkError, |
| 610 "---- failed to create texture for cache [%d %d] \n", | 680 "---- failed to create texture for cache [%d %d] \n", |
| 611 bitmap.width(), bitmap.height()); | 681 bitmap.width(), bitmap.height()); |
| 612 | 682 |
| 613 return nullptr; | 683 return nullptr; |
| 614 } | 684 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 833 SkErrorInternals::SetError( kInvalidPaint_SkError, | 903 SkErrorInternals::SetError( kInvalidPaint_SkError, |
| 834 "Sorry, I don't understand the filtering " | 904 "Sorry, I don't understand the filtering " |
| 835 "mode you asked for. Falling back to " | 905 "mode you asked for. Falling back to " |
| 836 "MIPMaps."); | 906 "MIPMaps."); |
| 837 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 907 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
| 838 break; | 908 break; |
| 839 | 909 |
| 840 } | 910 } |
| 841 return textureFilterMode; | 911 return textureFilterMode; |
| 842 } | 912 } |
| OLD | NEW |