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