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