| 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" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 void onDraw(SkCanvas* canvas) override { | 96 void onDraw(SkCanvas* canvas) 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 (nullptr == fileData) { | 101 if (nullptr == 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(fileData, &bm)) { | 106 SkAutoTUnref<SkImage> image(SkImage::NewFromEncoded(fileData)); |
| 107 SkDebugf("Could not install discardable pixel ref.\n"); | 107 canvas->drawImage(image, 0, 0); |
| 108 return; | |
| 109 } | |
| 110 | |
| 111 canvas->drawBitmap(bm, 0, 0); | |
| 112 } | 108 } |
| 113 | 109 |
| 114 private: | 110 private: |
| 115 typedef GM INHERITED; | 111 typedef GM INHERITED; |
| 116 }; | 112 }; |
| 117 | 113 |
| 118 // This class specializes ETC1BitmapGM to load the mandrill_128.pkm file. | 114 // This class specializes ETC1BitmapGM to load the mandrill_128.pkm file. |
| 119 class ETC1Bitmap_PKM_GM : public ETC1BitmapGM { | 115 class ETC1Bitmap_PKM_GM : public ETC1BitmapGM { |
| 120 public: | 116 public: |
| 121 ETC1Bitmap_PKM_GM() : ETC1BitmapGM() { } | 117 ETC1Bitmap_PKM_GM() : ETC1BitmapGM() { } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 SkDebugf("ETC1 Data is poorly formatted.\n"); | 191 SkDebugf("ETC1 Data is poorly formatted.\n"); |
| 196 return; | 192 return; |
| 197 } | 193 } |
| 198 | 194 |
| 199 SkASSERT(124 == width); | 195 SkASSERT(124 == width); |
| 200 SkASSERT(124 == height); | 196 SkASSERT(124 == height); |
| 201 | 197 |
| 202 size_t dataSz = etc1_get_encoded_data_size(width, height) + ETC_PKM_HEAD
ER_SIZE; | 198 size_t dataSz = etc1_get_encoded_data_size(width, height) + ETC_PKM_HEAD
ER_SIZE; |
| 203 SkAutoDataUnref nonPOTData(SkData::NewWithCopy(am.get(), dataSz)); | 199 SkAutoDataUnref nonPOTData(SkData::NewWithCopy(am.get(), dataSz)); |
| 204 | 200 |
| 205 if (!SkInstallDiscardablePixelRef(nonPOTData, &bm)) { | 201 SkAutoTUnref<SkImage> image(SkImage::NewFromEncoded(nonPOTData)); |
| 206 SkDebugf("Could not install discardable pixel ref.\n"); | 202 canvas->drawImage(image, 0, 0); |
| 207 return; | |
| 208 } | |
| 209 | |
| 210 canvas->drawBitmap(bm, 0, 0); | |
| 211 } | 203 } |
| 212 | 204 |
| 213 private: | 205 private: |
| 214 typedef GM INHERITED; | 206 typedef GM INHERITED; |
| 215 }; | 207 }; |
| 216 #endif // SK_IGNORE_ETC1_SUPPORT | 208 #endif // SK_IGNORE_ETC1_SUPPORT |
| 217 | 209 |
| 218 } // namespace skiagm | 210 } // namespace skiagm |
| 219 | 211 |
| 220 ////////////////////////////////////////////////////////////////////////////// | 212 ////////////////////////////////////////////////////////////////////////////// |
| 221 | 213 |
| 222 DEF_GM(return new skiagm::ETC1Bitmap_PKM_GM;) | 214 DEF_GM(return new skiagm::ETC1Bitmap_PKM_GM;) |
| 223 DEF_GM(return new skiagm::ETC1Bitmap_KTX_GM;) | 215 DEF_GM(return new skiagm::ETC1Bitmap_KTX_GM;) |
| 224 DEF_GM(return new skiagm::ETC1Bitmap_R11_KTX_GM;) | 216 DEF_GM(return new skiagm::ETC1Bitmap_R11_KTX_GM;) |
| 225 | 217 |
| 226 #ifndef SK_IGNORE_ETC1_SUPPORT | 218 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 227 DEF_GM(return new skiagm::ETC1Bitmap_NPOT_GM;) | 219 DEF_GM(return new skiagm::ETC1Bitmap_NPOT_GM;) |
| 228 #endif // SK_IGNORE_ETC1_SUPPORT | 220 #endif // SK_IGNORE_ETC1_SUPPORT |
| OLD | NEW |