| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkDiscardableMemoryPool.h" | 12 #include "SkDiscardableMemoryPool.h" |
| 13 #include "SkDiscardablePixelRef.h" | 13 #include "SkDiscardablePixelRef.h" |
| 14 #include "SkImageDecoder.h" | 14 #include "SkImageDecoder.h" |
| 15 #include "SkImageGenerator.h" | |
| 16 #include "SkOSFile.h" | 15 #include "SkOSFile.h" |
| 17 #include "SkStream.h" | 16 #include "SkStream.h" |
| 18 | 17 |
| 19 namespace skiagm { | 18 namespace skiagm { |
| 20 | 19 |
| 21 /** | 20 /** |
| 22 * Draw a PNG created by SkBitmapFactory. | 21 * Draw a PNG created by SkBitmapFactory. |
| 23 */ | 22 */ |
| 24 class FactoryGM : public GM { | 23 class FactoryGM : public GM { |
| 25 public: | 24 public: |
| 26 FactoryGM() {} | 25 FactoryGM() {} |
| 27 | 26 |
| 28 protected: | 27 protected: |
| 29 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 28 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
| 30 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl
ane-by-ddoo | 29 // Copyright-free file from http://openclipart.org/detail/29213/paper-pl
ane-by-ddoo |
| 31 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str(
), | 30 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str(
), |
| 32 "plane.png"); | 31 "plane.png"); |
| 33 SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str())); | 32 SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str())); |
| 34 if (NULL != data.get()) { | 33 if (NULL != data.get()) { |
| 35 // Create a cache which will boot the pixels out anytime the | 34 // Create a cache which will boot the pixels out anytime the |
| 36 // bitmap is unlocked. | 35 // bitmap is unlocked. |
| 37 SkAutoTUnref<SkDiscardableMemoryPool> pool( | 36 SkAutoTUnref<SkDiscardableMemoryPool> pool( |
| 38 SkNEW_ARGS(SkDiscardableMemoryPool, (1))); | 37 SkNEW_ARGS(SkDiscardableMemoryPool, (1))); |
| 39 SkAssertResult(SkInstallDiscardablePixelRef( | 38 SkAssertResult(SkDecodingImageGenerator::Install(data, |
| 40 SkDecodingImageGenerator::Create( | 39 &fBitmap, pool)); |
| 41 data, SkDecodingImageGenerator::Options()), | |
| 42 &fBitmap, pool)); | |
| 43 } | 40 } |
| 44 } | 41 } |
| 45 | 42 |
| 46 virtual SkString onShortName() { | 43 virtual SkString onShortName() { |
| 47 return SkString("factory"); | 44 return SkString("factory"); |
| 48 } | 45 } |
| 49 | 46 |
| 50 virtual SkISize onISize() { | 47 virtual SkISize onISize() { |
| 51 return make_isize(640, 480); | 48 return make_isize(640, 480); |
| 52 } | 49 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 SkBitmap fBitmap; | 61 SkBitmap fBitmap; |
| 65 | 62 |
| 66 typedef GM INHERITED; | 63 typedef GM INHERITED; |
| 67 }; | 64 }; |
| 68 | 65 |
| 69 ////////////////////////////////////////////////////////////////////////////// | 66 ////////////////////////////////////////////////////////////////////////////// |
| 70 | 67 |
| 71 static GM* MyFactory(void*) { return new FactoryGM; } | 68 static GM* MyFactory(void*) { return new FactoryGM; } |
| 72 static GMRegistry reg(MyFactory); | 69 static GMRegistry reg(MyFactory); |
| 73 | 70 |
| 74 } // namespace skiagm | 71 } |
| OLD | NEW |