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 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
11 #include "SkDecodingImageGenerator.h" | 11 #include "SkDecodingImageGenerator.h" |
12 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
13 #include "SkOSFile.h" | 13 #include "SkOSFile.h" |
14 | 14 |
15 namespace skiagm { | 15 namespace skiagm { |
16 | 16 |
17 /** | 17 /** |
18 * Test decoding an image from a PKM file and then | 18 * Test decoding an image from a PKM file and then |
19 * from compressed ETC1 data. | 19 * from compressed ETC1 data. |
20 */ | 20 */ |
21 class ETC1BitmapGM : public GM { | 21 class ETC1BitmapGM : public GM { |
22 public: | 22 public: |
23 ETC1BitmapGM() { } | 23 ETC1BitmapGM() { } |
24 virtual ~ETC1BitmapGM() { } | 24 virtual ~ETC1BitmapGM() { } |
25 | 25 |
26 protected: | 26 protected: |
27 virtual SkString onShortName() SK_OVERRIDE { | 27 virtual SkString onShortName() SK_OVERRIDE { |
28 return SkString("etc1bitmap"); | 28 SkString str = SkString("etc1bitmap_"); |
robertphillips
2014/06/02 19:56:03
this->fileExtension ?
krajcevski
2014/06/02 20:01:58
Done.
| |
29 str.append(fileExtension()); | |
30 return str; | |
29 } | 31 } |
30 | 32 |
31 virtual SkISize onISize() SK_OVERRIDE { | 33 virtual SkISize onISize() SK_OVERRIDE { |
32 return make_isize(512, 512); | 34 return make_isize(128, 128); |
33 } | 35 } |
34 | 36 |
35 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 37 virtual SkString fileExtension() const = 0; |
36 | 38 |
robertphillips
2014/06/02 19:56:03
SK_OVERRIDE ?
krajcevski
2014/06/02 20:01:58
Done.
| |
39 virtual void onDraw(SkCanvas* canvas) { | |
37 SkBitmap bm; | 40 SkBitmap bm; |
38 SkString filename = SkOSPath::SkPathJoin( | 41 SkString filename = SkOSPath::SkPathJoin( |
39 INHERITED::gResourcePath.c_str(), "mandrill_512.pkm"); | 42 INHERITED::gResourcePath.c_str(), "mandrill_128."); |
robertphillips
2014/06/02 19:56:03
this->fileExtension ?
krajcevski
2014/06/02 20:01:58
Done.
| |
43 filename.append(fileExtension()); | |
40 | 44 |
41 SkData *fileData = SkData::NewFromFileName(filename.c_str()); | 45 SkData *fileData = SkData::NewFromFileName(filename.c_str()); |
42 if (NULL == fileData) { | 46 if (NULL == fileData) { |
43 SkDebugf("Could not open the file. Did you forget to set the resourc ePath?\n"); | 47 SkDebugf("Could not open the file. Did you forget to set the resourc ePath?\n"); |
44 return; | 48 return; |
45 } | 49 } |
46 | 50 |
47 if (!SkInstallDiscardablePixelRef( | 51 if (!SkInstallDiscardablePixelRef( |
48 SkDecodingImageGenerator::Create( | 52 SkDecodingImageGenerator::Create( |
49 fileData, SkDecodingImageGenerator::Options()), &bm)) { | 53 fileData, SkDecodingImageGenerator::Options()), &bm)) { |
50 SkDebugf("Could not install discardable pixel ref.\n"); | 54 SkDebugf("Could not install discardable pixel ref.\n"); |
51 return; | 55 return; |
52 } | 56 } |
53 | 57 |
54 canvas->drawBitmap(bm, 0, 0); | 58 canvas->drawBitmap(bm, 0, 0); |
55 } | 59 } |
56 | 60 |
57 private: | 61 private: |
58 typedef GM INHERITED; | 62 typedef GM INHERITED; |
59 }; | 63 }; |
60 | 64 |
robertphillips
2014/06/02 19:56:03
// This class specialized ETC1BitmapGM to pkm file
krajcevski
2014/06/02 20:01:58
Done.
| |
65 class ETC1Bitmap_PKM_GM : public ETC1BitmapGM { | |
66 public: | |
67 ETC1Bitmap_PKM_GM() : ETC1BitmapGM() { } | |
68 virtual ~ETC1Bitmap_PKM_GM() { } | |
69 | |
70 protected: | |
71 | |
72 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("pkm"); } | |
73 | |
74 private: | |
75 typedef ETC1BitmapGM INHERITED; | |
76 }; | |
77 | |
robertphillips
2014/06/02 19:56:03
// This class specialized ETC1BitmapGM to ktx file
krajcevski
2014/06/02 20:01:58
Done.
| |
78 class ETC1Bitmap_KTX_GM : public ETC1BitmapGM { | |
79 public: | |
80 ETC1Bitmap_KTX_GM() : ETC1BitmapGM() { } | |
81 virtual ~ETC1Bitmap_KTX_GM() { } | |
82 | |
83 protected: | |
84 | |
85 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("ktx"); } | |
86 | |
87 private: | |
88 typedef ETC1BitmapGM INHERITED; | |
89 }; | |
90 | |
61 } // namespace skiagm | 91 } // namespace skiagm |
62 | 92 |
63 ////////////////////////////////////////////////////////////////////////////// | 93 ////////////////////////////////////////////////////////////////////////////// |
64 | 94 |
65 DEF_GM( return SkNEW(skiagm::ETC1BitmapGM); ) | 95 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_PKM_GM); ) |
96 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_KTX_GM); ) | |
OLD | NEW |