Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: gm/etc1bitmap.cpp

Issue 302333002: Initial KTX file decoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More code comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gyp/gpu.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 or KTX 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_");
29 str.append(this->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
37 virtual SkString fileExtension() const = 0;
38
35 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 39 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
36
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.");
43 filename.append(this->fileExtension());
40 44
41 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str())) ; 45 SkAutoTUnref<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
65 // This class specializes ETC1BitmapGM to load the mandrill_128.pkm file.
66 class ETC1Bitmap_PKM_GM : public ETC1BitmapGM {
67 public:
68 ETC1Bitmap_PKM_GM() : ETC1BitmapGM() { }
69 virtual ~ETC1Bitmap_PKM_GM() { }
70
71 protected:
72
73 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("pkm"); }
74
75 private:
76 typedef ETC1BitmapGM INHERITED;
77 };
78
79 // This class specializes ETC1BitmapGM to load the mandrill_128.ktx file.
80 class ETC1Bitmap_KTX_GM : public ETC1BitmapGM {
81 public:
82 ETC1Bitmap_KTX_GM() : ETC1BitmapGM() { }
83 virtual ~ETC1Bitmap_KTX_GM() { }
84
85 protected:
86
87 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("ktx"); }
88
89 private:
90 typedef ETC1BitmapGM INHERITED;
91 };
92
61 } // namespace skiagm 93 } // namespace skiagm
62 94
63 ////////////////////////////////////////////////////////////////////////////// 95 //////////////////////////////////////////////////////////////////////////////
64 96
65 DEF_GM( return SkNEW(skiagm::ETC1BitmapGM); ) 97 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_PKM_GM); )
98 DEF_GM( return SkNEW(skiagm::ETC1Bitmap_KTX_GM); )
OLDNEW
« no previous file with comments | « no previous file | gyp/gpu.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698