scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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" |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
| 10 | #include "SkData.h" |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 11 | #include "SkDecodingImageGenerator.h" |
| 12 | #include "SkDiscardableMemoryPool.h" |
| 13 | #include "SkDiscardablePixelRef.h" |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 14 | #include "SkImageDecoder.h" |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 15 | #include "SkImageGenerator.h" |
scroggo@google.com | ccd7afb | 2013-05-28 16:45:07 +0000 | [diff] [blame] | 16 | #include "SkOSFile.h" |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 17 | #include "SkStream.h" |
| 18 | |
| 19 | namespace skiagm { |
| 20 | |
| 21 | /** |
| 22 | * Draw a PNG created by SkBitmapFactory. |
| 23 | */ |
| 24 | class FactoryGM : public GM { |
| 25 | public: |
| 26 | FactoryGM() {} |
| 27 | |
| 28 | protected: |
| 29 | virtual void onOnceBeforeDraw() SK_OVERRIDE { |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 30 | // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo |
scroggo@google.com | ccd7afb | 2013-05-28 16:45:07 +0000 | [diff] [blame] | 31 | SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str(), |
| 32 | "plane.png"); |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 33 | SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str())); |
| 34 | if (NULL != data.get()) { |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 35 | // Create a cache which will boot the pixels out anytime the |
| 36 | // bitmap is unlocked. |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 37 | SkAutoTUnref<SkDiscardableMemoryPool> pool( |
| 38 | SkNEW_ARGS(SkDiscardableMemoryPool, (1))); |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 39 | SkAssertResult(SkInstallDiscardablePixelRef( |
| 40 | SkDecodingImageGenerator::Create( |
| 41 | data, SkDecodingImageGenerator::Options()), |
| 42 | &fBitmap, pool)); |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | virtual SkString onShortName() { |
| 47 | return SkString("factory"); |
| 48 | } |
| 49 | |
| 50 | virtual SkISize onISize() { |
| 51 | return make_isize(640, 480); |
| 52 | } |
| 53 | |
| 54 | virtual void onDraw(SkCanvas* canvas) { |
| 55 | canvas->drawBitmap(fBitmap, 0, 0); |
| 56 | } |
| 57 | |
commit-bot@chromium.org | 805df1a | 2013-08-16 19:18:12 +0000 | [diff] [blame] | 58 | // Skip cross process pipe due to https://code.google.com/p/skia/issues/detail?id=1520 |
| 59 | virtual uint32_t onGetFlags() const { |
| 60 | return INHERITED::onGetFlags() | kSkipPipeCrossProcess_Flag; |
| 61 | } |
| 62 | |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 63 | private: |
| 64 | SkBitmap fBitmap; |
| 65 | |
| 66 | typedef GM INHERITED; |
| 67 | }; |
| 68 | |
| 69 | ////////////////////////////////////////////////////////////////////////////// |
| 70 | |
| 71 | static GM* MyFactory(void*) { return new FactoryGM; } |
| 72 | static GMRegistry reg(MyFactory); |
| 73 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 74 | } // namespace skiagm |