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 "SkDiscardableMemoryPool.h" |
| 14 | #include "SkDiscardablePixelRef.h" |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 15 | #include "SkImageDecoder.h" |
commit-bot@chromium.org | 2d970b5 | 2014-05-27 14:14:22 +0000 | [diff] [blame] | 16 | #include "SkImageGeneratorPriv.h" |
scroggo@google.com | ccd7afb | 2013-05-28 16:45:07 +0000 | [diff] [blame] | 17 | #include "SkOSFile.h" |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 18 | #include "SkStream.h" |
| 19 | |
| 20 | namespace skiagm { |
| 21 | |
| 22 | /** |
| 23 | * Draw a PNG created by SkBitmapFactory. |
| 24 | */ |
| 25 | class FactoryGM : public GM { |
| 26 | public: |
| 27 | FactoryGM() {} |
| 28 | |
| 29 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 30 | void onOnceBeforeDraw() override { |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 31 | // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo |
tfarina | c846f4a | 2014-07-01 12:35:49 -0700 | [diff] [blame] | 32 | SkString pngFilename = GetResourcePath("plane.png"); |
| 33 | SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str())); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 34 | if (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( |
commit-bot@chromium.org | cf2f008 | 2014-04-04 16:43:38 +0000 | [diff] [blame] | 38 | SkDiscardableMemoryPool::Create(1)); |
reed | d114645 | 2015-09-25 06:56:57 -0700 | [diff] [blame] | 39 | SkAssertResult(SkDEPRECATED_InstallDiscardablePixelRef( |
| 40 | SkImageGenerator::NewFromEncoded(data), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 41 | nullptr, &fBitmap, pool)); |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 45 | SkString onShortName() override { |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 46 | return SkString("factory"); |
| 47 | } |
| 48 | |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 49 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 50 | return SkISize::Make(640, 480); |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 51 | } |
| 52 | |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 53 | void onDraw(SkCanvas* canvas) override { |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 54 | canvas->drawBitmap(fBitmap, 0, 0); |
| 55 | } |
| 56 | |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 57 | private: |
| 58 | SkBitmap fBitmap; |
| 59 | |
| 60 | typedef GM INHERITED; |
| 61 | }; |
| 62 | |
| 63 | ////////////////////////////////////////////////////////////////////////////// |
| 64 | |
| 65 | static GM* MyFactory(void*) { return new FactoryGM; } |
| 66 | static GMRegistry reg(MyFactory); |
| 67 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 68 | } // namespace skiagm |