blob: ec71d8daa56843344d4d95469f09ac018190e3fb [file] [log] [blame]
robertphillips@google.com8cf81e02014-05-22 18:40:29 +00001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
krajcevski9c0e6292014-06-02 07:38:14 -070010#include "SkData.h"
11#include "SkDecodingImageGenerator.h"
robertphillips@google.com8cf81e02014-05-22 18:40:29 +000012#include "SkImageDecoder.h"
13#include "SkOSFile.h"
14
15namespace skiagm {
16
17/**
krajcevski99ffe242014-06-03 13:04:35 -070018 * Test decoding an image from a PKM or KTX file and then
robertphillips@google.com8cf81e02014-05-22 18:40:29 +000019 * from compressed ETC1 data.
20 */
21class ETC1BitmapGM : public GM {
22public:
23 ETC1BitmapGM() { }
24 virtual ~ETC1BitmapGM() { }
25
26protected:
27 virtual SkString onShortName() SK_OVERRIDE {
krajcevski99ffe242014-06-03 13:04:35 -070028 SkString str = SkString("etc1bitmap_");
29 str.append(this->fileExtension());
30 return str;
robertphillips@google.com8cf81e02014-05-22 18:40:29 +000031 }
32
33 virtual SkISize onISize() SK_OVERRIDE {
krajcevski99ffe242014-06-03 13:04:35 -070034 return make_isize(128, 128);
robertphillips@google.com8cf81e02014-05-22 18:40:29 +000035 }
36
krajcevski99ffe242014-06-03 13:04:35 -070037 virtual SkString fileExtension() const = 0;
robertphillips@google.com8cf81e02014-05-22 18:40:29 +000038
krajcevski99ffe242014-06-03 13:04:35 -070039 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
robertphillips@google.com8cf81e02014-05-22 18:40:29 +000040 SkBitmap bm;
41 SkString filename = SkOSPath::SkPathJoin(
krajcevski99ffe242014-06-03 13:04:35 -070042 INHERITED::gResourcePath.c_str(), "mandrill_128.");
43 filename.append(this->fileExtension());
krajcevski9c0e6292014-06-02 07:38:14 -070044
mtklein04cd3682014-06-03 09:04:33 -070045 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str()));
krajcevski9c0e6292014-06-02 07:38:14 -070046 if (NULL == fileData) {
47 SkDebugf("Could not open the file. Did you forget to set the resourcePath?\n");
robertphillips@google.com8cf81e02014-05-22 18:40:29 +000048 return;
49 }
krajcevski9c0e6292014-06-02 07:38:14 -070050
51 if (!SkInstallDiscardablePixelRef(
52 SkDecodingImageGenerator::Create(
53 fileData, SkDecodingImageGenerator::Options()), &bm)) {
54 SkDebugf("Could not install discardable pixel ref.\n");
55 return;
56 }
57
robertphillips@google.com8cf81e02014-05-22 18:40:29 +000058 canvas->drawBitmap(bm, 0, 0);
59 }
60
61private:
62 typedef GM INHERITED;
63};
64
krajcevski99ffe242014-06-03 13:04:35 -070065// This class specializes ETC1BitmapGM to load the mandrill_128.pkm file.
66class ETC1Bitmap_PKM_GM : public ETC1BitmapGM {
67public:
68 ETC1Bitmap_PKM_GM() : ETC1BitmapGM() { }
69 virtual ~ETC1Bitmap_PKM_GM() { }
70
71protected:
72
73 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("pkm"); }
74
75private:
76 typedef ETC1BitmapGM INHERITED;
77};
78
79// This class specializes ETC1BitmapGM to load the mandrill_128.ktx file.
80class ETC1Bitmap_KTX_GM : public ETC1BitmapGM {
81public:
82 ETC1Bitmap_KTX_GM() : ETC1BitmapGM() { }
83 virtual ~ETC1Bitmap_KTX_GM() { }
84
85protected:
86
87 virtual SkString fileExtension() const SK_OVERRIDE { return SkString("ktx"); }
88
89private:
90 typedef ETC1BitmapGM INHERITED;
91};
92
robertphillips@google.com8cf81e02014-05-22 18:40:29 +000093} // namespace skiagm
94
95//////////////////////////////////////////////////////////////////////////////
96
krajcevski99ffe242014-06-03 13:04:35 -070097DEF_GM( return SkNEW(skiagm::ETC1Bitmap_PKM_GM); )
98DEF_GM( return SkNEW(skiagm::ETC1Bitmap_KTX_GM); )