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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 * from compressed ETC1 data. | 76 * from compressed ETC1 data. |
77 */ | 77 */ |
78 class ETC1BitmapGM : public GM { | 78 class ETC1BitmapGM : public GM { |
79 public: | 79 public: |
80 ETC1BitmapGM() { } | 80 ETC1BitmapGM() { } |
81 virtual ~ETC1BitmapGM() { } | 81 virtual ~ETC1BitmapGM() { } |
82 | 82 |
83 protected: | 83 protected: |
84 virtual SkString onShortName() SK_OVERRIDE { | 84 virtual SkString onShortName() SK_OVERRIDE { |
85 SkString str = SkString("etc1bitmap_"); | 85 SkString str = SkString("etc1bitmap_"); |
86 str.append(this->fileExtension()); | 86 str.append(this->fileExtension()); |
robertphillips
2014/09/10 20:29:48
this-> ?
sugoi1
2014/09/10 20:32:44
Done.
| |
87 if (isVolatile()) { | |
88 str.append("_volatile"); | |
89 } | |
87 return str; | 90 return str; |
88 } | 91 } |
89 | 92 |
90 virtual SkISize onISize() SK_OVERRIDE { | 93 virtual SkISize onISize() SK_OVERRIDE { |
91 return SkISize::Make(128, 128); | 94 return SkISize::Make(128, 128); |
92 } | 95 } |
93 | 96 |
97 virtual bool isVolatile() const { return false; } | |
98 | |
94 virtual SkString fileExtension() const = 0; | 99 virtual SkString fileExtension() const = 0; |
95 | 100 |
96 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 101 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
97 SkBitmap bm; | 102 SkBitmap bm; |
98 SkString filename = GetResourcePath("mandrill_128."); | 103 SkString filename = GetResourcePath("mandrill_128."); |
99 filename.append(this->fileExtension()); | 104 filename.append(this->fileExtension()); |
100 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str())) ; | 105 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str())) ; |
101 if (NULL == fileData) { | 106 if (NULL == fileData) { |
102 SkDebugf("Could not open the file. Did you forget to set the resourc ePath?\n"); | 107 SkDebugf("Could not open the file. Did you forget to set the resourc ePath?\n"); |
103 return; | 108 return; |
104 } | 109 } |
105 | 110 |
106 if (!SkInstallDiscardablePixelRef( | 111 if (!SkInstallDiscardablePixelRef( |
107 SkDecodingImageGenerator::Create( | 112 SkDecodingImageGenerator::Create( |
108 fileData, SkDecodingImageGenerator::Options()), &bm)) { | 113 fileData, SkDecodingImageGenerator::Options()), &bm)) { |
109 SkDebugf("Could not install discardable pixel ref.\n"); | 114 SkDebugf("Could not install discardable pixel ref.\n"); |
110 return; | 115 return; |
111 } | 116 } |
112 | 117 |
robertphillips
2014/09/10 20:29:48
this-> ?
sugoi1
2014/09/10 20:32:44
Done.
| |
118 bm.setIsVolatile(isVolatile()); | |
119 | |
113 canvas->drawBitmap(bm, 0, 0); | 120 canvas->drawBitmap(bm, 0, 0); |
114 } | 121 } |
115 | 122 |
116 private: | 123 private: |
117 typedef GM INHERITED; | 124 typedef GM INHERITED; |
118 }; | 125 }; |
119 | 126 |
120 // This class specializes ETC1BitmapGM to load the mandrill_128.pkm file. | 127 // This class specializes ETC1BitmapGM to load the mandrill_128.pkm file. |
121 class ETC1Bitmap_PKM_GM : public ETC1BitmapGM { | 128 class ETC1Bitmap_PKM_GM : public ETC1BitmapGM { |
122 public: | 129 public: |
123 ETC1Bitmap_PKM_GM() : ETC1BitmapGM() { } | 130 ETC1Bitmap_PKM_GM() : ETC1BitmapGM() { } |
124 virtual ~ETC1Bitmap_PKM_GM() { } | 131 virtual ~ETC1Bitmap_PKM_GM() { } |
125 | 132 |
126 protected: | 133 protected: |
127 | 134 |
128 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("pkm"); } | 135 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("pkm"); } |
129 | 136 |
130 private: | 137 private: |
131 typedef ETC1BitmapGM INHERITED; | 138 typedef ETC1BitmapGM INHERITED; |
132 }; | 139 }; |
133 | 140 |
141 // This class specializes ETC1BitmapGM to load the mandrill_128.pkm file in a vo latile bitmap. | |
142 class ETC1Bitmap_PKM_VOLATILE_GM : public ETC1BitmapGM { | |
143 public: | |
144 ETC1Bitmap_PKM_VOLATILE_GM() : ETC1BitmapGM() { } | |
145 virtual ~ETC1Bitmap_PKM_VOLATILE_GM() { } | |
146 | |
147 protected: | |
148 | |
149 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("pkm"); } | |
150 virtual bool isVolatile() const SK_OVERRIDE { return true; } | |
151 | |
152 private: | |
153 typedef ETC1BitmapGM INHERITED; | |
154 }; | |
155 | |
134 // This class specializes ETC1BitmapGM to load the mandrill_128.ktx file. | 156 // This class specializes ETC1BitmapGM to load the mandrill_128.ktx file. |
135 class ETC1Bitmap_KTX_GM : public ETC1BitmapGM { | 157 class ETC1Bitmap_KTX_GM : public ETC1BitmapGM { |
136 public: | 158 public: |
137 ETC1Bitmap_KTX_GM() : ETC1BitmapGM() { } | 159 ETC1Bitmap_KTX_GM() : ETC1BitmapGM() { } |
138 virtual ~ETC1Bitmap_KTX_GM() { } | 160 virtual ~ETC1Bitmap_KTX_GM() { } |
139 | 161 |
140 protected: | 162 protected: |
141 | 163 |
142 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("ktx"); } | 164 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("ktx"); } |
143 | 165 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 private: | 239 private: |
218 typedef GM INHERITED; | 240 typedef GM INHERITED; |
219 }; | 241 }; |
220 #endif // SK_IGNORE_ETC1_SUPPORT | 242 #endif // SK_IGNORE_ETC1_SUPPORT |
221 | 243 |
222 } // namespace skiagm | 244 } // namespace skiagm |
223 | 245 |
224 ////////////////////////////////////////////////////////////////////////////// | 246 ////////////////////////////////////////////////////////////////////////////// |
225 | 247 |
226 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_PKM_GM); ) | 248 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_PKM_GM); ) |
249 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_PKM_VOLATILE_GM); ) | |
227 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_KTX_GM); ) | 250 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_KTX_GM); ) |
228 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_R11_KTX_GM); ) | 251 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_R11_KTX_GM); ) |
229 | 252 |
230 #ifndef SK_IGNORE_ETC1_SUPPORT | 253 #ifndef SK_IGNORE_ETC1_SUPPORT |
231 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_NPOT_GM); ) | 254 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_NPOT_GM); ) |
232 #endif // SK_IGNORE_ETC1_SUPPORT | 255 #endif // SK_IGNORE_ETC1_SUPPORT |
OLD | NEW |