blob: 519b8eac79a7f654229046c37c2a61ef7a042d5f [file] [log] [blame]
scroggo@google.com9f686f32012-11-29 21:05:37 +00001/*
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"
tfarinabcbc1782014-06-18 14:32:48 -07009
10#include "Resources.h"
scroggo@google.com9f686f32012-11-29 21:05:37 +000011#include "SkCanvas.h"
12#include "SkData.h"
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000013#include "SkDiscardableMemoryPool.h"
14#include "SkDiscardablePixelRef.h"
scroggo@google.comf8d7d272013-02-22 21:38:35 +000015#include "SkImageDecoder.h"
commit-bot@chromium.org2d970b52014-05-27 14:14:22 +000016#include "SkImageGeneratorPriv.h"
scroggo@google.comccd7afb2013-05-28 16:45:07 +000017#include "SkOSFile.h"
scroggo@google.com9f686f32012-11-29 21:05:37 +000018#include "SkStream.h"
19
20namespace skiagm {
21
22/**
23 * Draw a PNG created by SkBitmapFactory.
24 */
25class FactoryGM : public GM {
26public:
27 FactoryGM() {}
28
29protected:
mtklein36352bf2015-03-25 18:17:31 -070030 void onOnceBeforeDraw() override {
scroggo@google.com9f686f32012-11-29 21:05:37 +000031 // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
tfarinac846f4a2014-07-01 12:35:49 -070032 SkString pngFilename = GetResourcePath("plane.png");
33 SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str()));
bsalomon49f085d2014-09-05 13:34:00 -070034 if (data.get()) {
scroggo@google.comf8d7d272013-02-22 21:38:35 +000035 // Create a cache which will boot the pixels out anytime the
36 // bitmap is unlocked.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000037 SkAutoTUnref<SkDiscardableMemoryPool> pool(
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +000038 SkDiscardableMemoryPool::Create(1));
reed5965c8a2015-01-07 18:04:45 -080039 SkAssertResult(SkInstallDiscardablePixelRef(SkImageGenerator::NewFromData(data),
40 &fBitmap, pool));
scroggo@google.com9f686f32012-11-29 21:05:37 +000041 }
42 }
43
mtklein36352bf2015-03-25 18:17:31 -070044 virtual SkString onShortName() override {
scroggo@google.com9f686f32012-11-29 21:05:37 +000045 return SkString("factory");
46 }
47
mtklein36352bf2015-03-25 18:17:31 -070048 virtual SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070049 return SkISize::Make(640, 480);
scroggo@google.com9f686f32012-11-29 21:05:37 +000050 }
51
mtklein36352bf2015-03-25 18:17:31 -070052 virtual void onDraw(SkCanvas* canvas) override {
scroggo@google.com9f686f32012-11-29 21:05:37 +000053 canvas->drawBitmap(fBitmap, 0, 0);
54 }
55
scroggo@google.com9f686f32012-11-29 21:05:37 +000056private:
57 SkBitmap fBitmap;
58
59 typedef GM INHERITED;
60};
61
62//////////////////////////////////////////////////////////////////////////////
63
64static GM* MyFactory(void*) { return new FactoryGM; }
65static GMRegistry reg(MyFactory);
66
halcanary@google.com3d50ea12014-01-02 13:15:13 +000067} // namespace skiagm