| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "gm.h" | 8 #include "gm.h" |
| 9 | 9 |
| 10 #include "Resources.h" | 10 #include "Resources.h" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkData.h" | 12 #include "SkData.h" |
| 13 #include "SkDecodingImageGenerator.h" | 13 #include "SkImageGenerator.h" |
| 14 #include "SkImageDecoder.h" | 14 #include "SkImageDecoder.h" |
| 15 #include "SkOSFile.h" | 15 #include "SkOSFile.h" |
| 16 | 16 |
| 17 #ifndef SK_IGNORE_ETC1_SUPPORT | 17 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 18 | 18 |
| 19 #include "etc1.h" | 19 #include "etc1.h" |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Remove the last row and column of ETC1 blocks, effectively | 22 * Remove the last row and column of ETC1 blocks, effectively |
| 23 * making a texture that started as power of two into a texture | 23 * making a texture that started as power of two into a texture |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 96 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 97 SkBitmap bm; | 97 SkBitmap bm; |
| 98 SkString filename = GetResourcePath("mandrill_128."); | 98 SkString filename = GetResourcePath("mandrill_128."); |
| 99 filename.append(this->fileExtension()); | 99 filename.append(this->fileExtension()); |
| 100 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str()))
; | 100 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str()))
; |
| 101 if (NULL == fileData) { | 101 if (NULL == fileData) { |
| 102 SkDebugf("Could not open the file. Did you forget to set the resourc
ePath?\n"); | 102 SkDebugf("Could not open the file. Did you forget to set the resourc
ePath?\n"); |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 | 105 |
| 106 if (!SkInstallDiscardablePixelRef( | 106 if (!SkInstallDiscardablePixelRef(fileData, &bm)) { |
| 107 SkDecodingImageGenerator::Create( | |
| 108 fileData, SkDecodingImageGenerator::Options()), &bm)) { | |
| 109 SkDebugf("Could not install discardable pixel ref.\n"); | 107 SkDebugf("Could not install discardable pixel ref.\n"); |
| 110 return; | 108 return; |
| 111 } | 109 } |
| 112 | 110 |
| 113 canvas->drawBitmap(bm, 0, 0); | 111 canvas->drawBitmap(bm, 0, 0); |
| 114 } | 112 } |
| 115 | 113 |
| 116 private: | 114 private: |
| 117 typedef GM INHERITED; | 115 typedef GM INHERITED; |
| 118 }; | 116 }; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 SkDebugf("ETC1 Data is poorly formatted.\n"); | 195 SkDebugf("ETC1 Data is poorly formatted.\n"); |
| 198 return; | 196 return; |
| 199 } | 197 } |
| 200 | 198 |
| 201 SkASSERT(124 == width); | 199 SkASSERT(124 == width); |
| 202 SkASSERT(124 == height); | 200 SkASSERT(124 == height); |
| 203 | 201 |
| 204 size_t dataSz = etc1_get_encoded_data_size(width, height) + ETC_PKM_HEAD
ER_SIZE; | 202 size_t dataSz = etc1_get_encoded_data_size(width, height) + ETC_PKM_HEAD
ER_SIZE; |
| 205 SkAutoDataUnref nonPOTData(SkData::NewWithCopy(am.get(), dataSz)); | 203 SkAutoDataUnref nonPOTData(SkData::NewWithCopy(am.get(), dataSz)); |
| 206 | 204 |
| 207 if (!SkInstallDiscardablePixelRef( | 205 if (!SkInstallDiscardablePixelRef(nonPOTData, &bm)) { |
| 208 SkDecodingImageGenerator::Create( | |
| 209 nonPOTData, SkDecodingImageGenerator::Options()), &bm)) { | |
| 210 SkDebugf("Could not install discardable pixel ref.\n"); | 206 SkDebugf("Could not install discardable pixel ref.\n"); |
| 211 return; | 207 return; |
| 212 } | 208 } |
| 213 | 209 |
| 214 canvas->drawBitmap(bm, 0, 0); | 210 canvas->drawBitmap(bm, 0, 0); |
| 215 } | 211 } |
| 216 | 212 |
| 217 private: | 213 private: |
| 218 typedef GM INHERITED; | 214 typedef GM INHERITED; |
| 219 }; | 215 }; |
| 220 #endif // SK_IGNORE_ETC1_SUPPORT | 216 #endif // SK_IGNORE_ETC1_SUPPORT |
| 221 | 217 |
| 222 } // namespace skiagm | 218 } // namespace skiagm |
| 223 | 219 |
| 224 ////////////////////////////////////////////////////////////////////////////// | 220 ////////////////////////////////////////////////////////////////////////////// |
| 225 | 221 |
| 226 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_PKM_GM); ) | 222 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_PKM_GM); ) |
| 227 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_KTX_GM); ) | 223 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_KTX_GM); ) |
| 228 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_R11_KTX_GM); ) | 224 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_R11_KTX_GM); ) |
| 229 | 225 |
| 230 #ifndef SK_IGNORE_ETC1_SUPPORT | 226 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 231 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_NPOT_GM); ) | 227 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_NPOT_GM); ) |
| 232 #endif // SK_IGNORE_ETC1_SUPPORT | 228 #endif // SK_IGNORE_ETC1_SUPPORT |
| OLD | NEW |