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" |
22 #include "SkPixelRef.h" | 23 #include "SkPixelRef.h" |
23 #include "SkResourceCache.h" | 24 #include "SkResourceCache.h" |
24 #include "SkTextureCompressor.h" | 25 #include "SkTextureCompressor.h" |
25 #include "SkYUVPlanesCache.h" | 26 #include "SkYUVPlanesCache.h" |
26 #include "effects/GrBicubicEffect.h" | 27 #include "effects/GrBicubicEffect.h" |
27 #include "effects/GrDitherEffect.h" | 28 #include "effects/GrDitherEffect.h" |
28 #include "effects/GrPorterDuffXferProcessor.h" | 29 #include "effects/GrPorterDuffXferProcessor.h" |
29 #include "effects/GrYUVtoRGBEffect.h" | 30 #include "effects/GrYUVtoRGBEffect.h" |
30 | 31 |
31 #ifndef SK_IGNORE_ETC1_SUPPORT | 32 #ifndef SK_IGNORE_ETC1_SUPPORT |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 const GrTextureParams::FilterMode filters[] = { | 630 const GrTextureParams::FilterMode filters[] = { |
630 GrTextureParams::kNone_FilterMode, // kUntiled_SkImageUsageType | 631 GrTextureParams::kNone_FilterMode, // kUntiled_SkImageUsageType |
631 GrTextureParams::kNone_FilterMode, // kTiled_Unfiltered_SkImageUsag
eType | 632 GrTextureParams::kNone_FilterMode, // kTiled_Unfiltered_SkImageUsag
eType |
632 GrTextureParams::kBilerp_FilterMode, // kTiled_Filtered_SkImageUsageT
ype | 633 GrTextureParams::kBilerp_FilterMode, // kTiled_Filtered_SkImageUsageT
ype |
633 }; | 634 }; |
634 | 635 |
635 GrTextureParams params(tiles[usage], filters[usage]); | 636 GrTextureParams params(tiles[usage], filters[usage]); |
636 return GrRefCachedBitmapTexture(ctx, bitmap, ¶ms); | 637 return GrRefCachedBitmapTexture(ctx, bitmap, ¶ms); |
637 } | 638 } |
638 | 639 |
| 640 GrTexture* GrMipMapTexture(GrContext* ctx, |
| 641 const SkBitmap& bitmap, |
| 642 SkDiscardableFactoryProc fact) { |
| 643 // If the SkBitmap is already backed by a texture, we do not want to read th
e contents back |
| 644 // to the cpu and generate the mipmap only to send it back to the GPU. |
| 645 SkASSERT(!bitmap.getTexture()); |
| 646 |
| 647 GrSurfaceDesc desc; |
| 648 generate_bitmap_texture_desc(bitmap, &desc); |
| 649 |
| 650 auto mipmap = SkMipMap::Build(bitmap, fact); |
| 651 if (mipmap == NULL) { |
| 652 // could not create the mipmap |
| 653 return NULL; |
| 654 } else { |
| 655 auto mipLevelCount = mipmap->getLevelsCount(); |
| 656 desc.fIsMipMapped = mipLevelCount > 1; |
| 657 SkTArray<SkMipMapLevel> texels(mipLevelCount); |
| 658 for (int i = 0; i < mipLevelCount; i++) { |
| 659 SkMipMap::Level level; |
| 660 mipmap->getLevel(i, &level); |
| 661 |
| 662 SkMipMapLevel currentMipLevel(level.fPixels, level.fRowBytes); |
| 663 |
| 664 texels.push_back(currentMipLevel); |
| 665 } |
| 666 return ctx->textureProvider()->createTexture(desc, true, texels); |
| 667 // TODO: BitmapInvalidator support |
| 668 } |
| 669 } |
| 670 |
639 /////////////////////////////////////////////////////////////////////////////// | 671 /////////////////////////////////////////////////////////////////////////////// |
640 | 672 |
641 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass | 673 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass |
642 // alpha info, that will be considered. | 674 // alpha info, that will be considered. |
643 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf
ileType pt) { | 675 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf
ileType pt) { |
644 switch (ct) { | 676 switch (ct) { |
645 case kUnknown_SkColorType: | 677 case kUnknown_SkColorType: |
646 return kUnknown_GrPixelConfig; | 678 return kUnknown_GrPixelConfig; |
647 case kAlpha_8_SkColorType: | 679 case kAlpha_8_SkColorType: |
648 return kAlpha_8_GrPixelConfig; | 680 return kAlpha_8_GrPixelConfig; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 SkErrorInternals::SetError( kInvalidPaint_SkError, | 881 SkErrorInternals::SetError( kInvalidPaint_SkError, |
850 "Sorry, I don't understand the filtering
" | 882 "Sorry, I don't understand the filtering
" |
851 "mode you asked for. Falling back to " | 883 "mode you asked for. Falling back to " |
852 "MIPMaps."); | 884 "MIPMaps."); |
853 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 885 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
854 break; | 886 break; |
855 | 887 |
856 } | 888 } |
857 return textureFilterMode; | 889 return textureFilterMode; |
858 } | 890 } |
OLD | NEW |