Chromium Code Reviews| 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" | |
| 11 #include "SkDecodingImageGenerator.h" | |
| 10 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
| 11 #include "SkOSFile.h" | 13 #include "SkOSFile.h" |
| 12 | 14 |
| 13 namespace skiagm { | 15 namespace skiagm { |
| 14 | 16 |
| 15 /** | 17 /** |
| 16 * Test decoding an image from a PKM file and then | 18 * Test decoding an image from a PKM file and then |
| 17 * from compressed ETC1 data. | 19 * from compressed ETC1 data. |
| 18 */ | 20 */ |
| 19 class ETC1BitmapGM : public GM { | 21 class ETC1BitmapGM : public GM { |
| 20 public: | 22 public: |
| 21 ETC1BitmapGM() { } | 23 ETC1BitmapGM() { } |
| 22 virtual ~ETC1BitmapGM() { } | 24 virtual ~ETC1BitmapGM() { } |
| 23 | 25 |
| 24 protected: | 26 protected: |
| 25 virtual SkString onShortName() SK_OVERRIDE { | 27 virtual SkString onShortName() SK_OVERRIDE { |
| 26 return SkString("etc1bitmap"); | 28 return SkString("etc1bitmap"); |
| 27 } | 29 } |
| 28 | 30 |
| 29 virtual SkISize onISize() SK_OVERRIDE { | 31 virtual SkISize onISize() SK_OVERRIDE { |
| 30 return make_isize(512, 512); | 32 return make_isize(512, 512); |
| 31 } | 33 } |
| 32 | 34 |
| 33 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 35 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 34 | 36 |
| 35 SkBitmap bm; | 37 SkBitmap bm; |
| 36 SkString filename = SkOSPath::SkPathJoin( | 38 SkString filename = SkOSPath::SkPathJoin( |
| 37 INHERITED::gResourcePath.c_str(), "mandrill_512.pkm"); | 39 INHERITED::gResourcePath.c_str(), "mandrill_512.pkm"); |
| 38 if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm, | 40 |
| 39 SkBitmap::kARGB_8888_Config, | 41 SkData *fileData = SkData::NewFromFileName(filename.c_str()); |
|
robertphillips
2014/05/27 22:01:50
NULL == fileData ?
krajcevski
2014/05/27 22:19:29
Done.
| |
| 40 SkImageDecoder::kDecodePixels_Mode)) { | 42 if (!fileData) { |
| 41 SkDebugf("Could not decode the file. Did you forget to set the " | 43 SkDebugf("Could not open the file. Did you forget to set the resourc ePath?\n"); |
| 42 "resourcePath?\n"); | |
| 43 return; | 44 return; |
| 44 } | 45 } |
| 46 | |
| 47 if (!SkInstallDiscardablePixelRef( | |
| 48 SkDecodingImageGenerator::Create( | |
| 49 fileData, SkDecodingImageGenerator::Options()), &bm)) { | |
| 50 SkDebugf("Could not install discardable pixel ref.\n"); | |
| 51 return; | |
| 52 } | |
| 53 | |
| 45 canvas->drawBitmap(bm, 0, 0); | 54 canvas->drawBitmap(bm, 0, 0); |
| 46 } | 55 } |
| 47 | 56 |
| 48 private: | 57 private: |
| 49 typedef GM INHERITED; | 58 typedef GM INHERITED; |
| 50 }; | 59 }; |
| 51 | 60 |
| 52 } // namespace skiagm | 61 } // namespace skiagm |
| 53 | 62 |
| 54 ////////////////////////////////////////////////////////////////////////////// | 63 ////////////////////////////////////////////////////////////////////////////// |
| 55 | 64 |
| 56 DEF_GM( return SkNEW(skiagm::ETC1BitmapGM); ) | 65 DEF_GM( return SkNEW(skiagm::ETC1BitmapGM); ) |
| OLD | NEW |