| 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" |
| 11 | 11 |
| 12 #include "GrCaps.h" | 12 #include "GrCaps.h" |
| 13 #include "GrContext.h" | 13 #include "GrContext.h" |
| 14 #include "GrGpuResourcePriv.h" | 14 #include "GrGpuResourcePriv.h" |
| 15 #include "GrImageIDTextureAdjuster.h" | 15 #include "GrImageIDTextureAdjuster.h" |
| 16 #include "GrTextureParamsAdjuster.h" | 16 #include "GrTextureParamsAdjuster.h" |
| 17 #include "GrTypes.h" | 17 #include "GrTypes.h" |
| 18 #include "GrXferProcessor.h" | 18 #include "GrXferProcessor.h" |
| 19 #include "GrYUVProvider.h" | 19 #include "GrYUVProvider.h" |
| 20 | 20 |
| 21 #include "SkColorFilter.h" | 21 #include "SkColorFilter.h" |
| 22 #include "SkConfig8888.h" | 22 #include "SkConfig8888.h" |
| 23 #include "SkCanvas.h" | 23 #include "SkCanvas.h" |
| 24 #include "SkData.h" | 24 #include "SkData.h" |
| 25 #include "SkEncodedFormat.h" |
| 25 #include "SkErrorInternals.h" | 26 #include "SkErrorInternals.h" |
| 26 #include "SkGrPixelRef.h" | 27 #include "SkGrPixelRef.h" |
| 27 #include "SkMessageBus.h" | 28 #include "SkMessageBus.h" |
| 28 #include "SkMipMap.h" | 29 #include "SkMipMap.h" |
| 29 #include "SkPixelRef.h" | 30 #include "SkPixelRef.h" |
| 30 #include "SkResourceCache.h" | 31 #include "SkResourceCache.h" |
| 31 #include "SkTemplates.h" | 32 #include "SkTemplates.h" |
| 32 #include "SkTextureCompressor.h" | 33 #include "SkTextureCompressor.h" |
| 33 #include "SkYUVPlanesCache.h" | 34 #include "SkYUVPlanesCache.h" |
| 34 #include "effects/GrBicubicEffect.h" | 35 #include "effects/GrBicubicEffect.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 59 SkASSERT(!imageBounds.isEmpty()); | 60 SkASSERT(!imageBounds.isEmpty()); |
| 60 static const GrUniqueKey::Domain kImageIDDomain = GrUniqueKey::GenerateDomai
n(); | 61 static const GrUniqueKey::Domain kImageIDDomain = GrUniqueKey::GenerateDomai
n(); |
| 61 GrUniqueKey::Builder builder(key, kImageIDDomain, 5); | 62 GrUniqueKey::Builder builder(key, kImageIDDomain, 5); |
| 62 builder[0] = imageID; | 63 builder[0] = imageID; |
| 63 builder[1] = imageBounds.fLeft; | 64 builder[1] = imageBounds.fLeft; |
| 64 builder[2] = imageBounds.fTop; | 65 builder[2] = imageBounds.fTop; |
| 65 builder[3] = imageBounds.fRight; | 66 builder[3] = imageBounds.fRight; |
| 66 builder[4] = imageBounds.fBottom; | 67 builder[4] = imageBounds.fBottom; |
| 67 } | 68 } |
| 68 | 69 |
| 70 bool GrIsCompressedFormatPossiblySupported(GrContext* ctx, SkEncodedFormat forma
t) { |
| 71 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 72 if (!ctx->caps()->isConfigTexturable(kETC1_GrPixelConfig)) { |
| 73 return false; |
| 74 } |
| 75 switch (format) { |
| 76 case kPKM_SkEncodedFormat: // file format for ETC1 |
| 77 return true; |
| 78 default: |
| 79 return false; |
| 80 } |
| 81 #endif |
| 82 return false; |
| 83 } |
| 84 |
| 85 bool GrIsCompressedTextureDataPossiblySupported(GrContext* ctx, const void* data
, size_t size) { |
| 86 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 87 if (!ctx->caps()->isConfigTexturable(kETC1_GrPixelConfig)) { |
| 88 return false; |
| 89 } |
| 90 |
| 91 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data); |
| 92 if (size > ETC_PKM_HEADER_SIZE && etc1_pkm_is_valid(bytes)) { |
| 93 return true; |
| 94 } else if (SkKTXFile::is_ktx(bytes, size)) { |
| 95 return true; |
| 96 } |
| 97 #endif |
| 98 return false; |
| 99 } |
| 100 |
| 69 GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data, | 101 GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data, |
| 70 int expectedW, int expectedH, | 102 int expectedW, int expectedH, |
| 71 const void** outStartOfDataToUp
load) { | 103 const void** outStartOfDataToUp
load) { |
| 72 *outStartOfDataToUpload = nullptr; | 104 *outStartOfDataToUpload = nullptr; |
| 73 #ifndef SK_IGNORE_ETC1_SUPPORT | 105 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 74 if (!ctx->caps()->isConfigTexturable(kETC1_GrPixelConfig)) { | 106 if (!ctx->caps()->isConfigTexturable(kETC1_GrPixelConfig)) { |
| 75 return kUnknown_GrPixelConfig; | 107 return kUnknown_GrPixelConfig; |
| 76 } | 108 } |
| 77 | 109 |
| 78 const uint8_t* bytes = data->bytes(); | 110 const uint8_t* bytes = data->bytes(); |
| 79 if (data->size() > ETC_PKM_HEADER_SIZE && etc1_pkm_is_valid(bytes)) { | 111 if (data->size() > ETC_PKM_HEADER_SIZE && etc1_pkm_is_valid(bytes)) { |
| 80 // Does the data match the dimensions of the bitmap? If not, | 112 // Does the data match the dimensions of the bitmap? If not, |
| 81 // then we don't know how to scale the image to match it... | 113 // then we don't know how to scale the image to match it... |
| 82 if (etc1_pkm_get_width(bytes) != (unsigned)expectedW || | 114 if (etc1_pkm_get_width(bytes) != (unsigned)expectedW || |
| 83 etc1_pkm_get_height(bytes) != (unsigned)expectedH) | 115 etc1_pkm_get_height(bytes) != (unsigned)expectedH) |
| 84 { | 116 { |
| 85 return kUnknown_GrPixelConfig; | 117 return kUnknown_GrPixelConfig; |
| 86 } | 118 } |
| 87 | 119 |
| 88 *outStartOfDataToUpload = bytes + ETC_PKM_HEADER_SIZE; | 120 *outStartOfDataToUpload = bytes + ETC_PKM_HEADER_SIZE; |
| 89 return kETC1_GrPixelConfig; | 121 return kETC1_GrPixelConfig; |
| 90 } else if (SkKTXFile::is_ktx(bytes)) { | 122 } else if (SkKTXFile::is_ktx(bytes, data->size())) { |
| 91 SkKTXFile ktx(data); | 123 SkKTXFile ktx(data); |
| 92 | 124 |
| 93 // Is it actually an ETC1 texture? | 125 // Is it actually an ETC1 texture? |
| 94 if (!ktx.isCompressedFormat(SkTextureCompressor::kETC1_Format)) { | 126 if (!ktx.isCompressedFormat(SkTextureCompressor::kETC1_Format)) { |
| 95 return kUnknown_GrPixelConfig; | 127 return kUnknown_GrPixelConfig; |
| 96 } | 128 } |
| 97 | 129 |
| 98 // Does the data match the dimensions of the bitmap? If not, | 130 // Does the data match the dimensions of the bitmap? If not, |
| 99 // then we don't know how to scale the image to match it... | 131 // then we don't know how to scale the image to match it... |
| 100 if (ktx.width() != expectedW || ktx.height() != expectedH) { | 132 if (ktx.width() != expectedW || ktx.height() != expectedH) { |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 SkErrorInternals::SetError( kInvalidPaint_SkError, | 788 SkErrorInternals::SetError( kInvalidPaint_SkError, |
| 757 "Sorry, I don't understand the filtering
" | 789 "Sorry, I don't understand the filtering
" |
| 758 "mode you asked for. Falling back to " | 790 "mode you asked for. Falling back to " |
| 759 "MIPMaps."); | 791 "MIPMaps."); |
| 760 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 792 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
| 761 break; | 793 break; |
| 762 | 794 |
| 763 } | 795 } |
| 764 return textureFilterMode; | 796 return textureFilterMode; |
| 765 } | 797 } |
| OLD | NEW |