blob: 77da3b851a95928c823c9901d8f5412c9c201f4d [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"
commit-bot@chromium.org2d970b52014-05-27 14:14:22 +000015#include "SkImageGeneratorPriv.h"
scroggo@google.comccd7afb2013-05-28 16:45:07 +000016#include "SkOSFile.h"
scroggo@google.com9f686f32012-11-29 21:05:37 +000017#include "SkStream.h"
18
19namespace skiagm {
20
21/**
22 * Draw a PNG created by SkBitmapFactory.
23 */
24class FactoryGM : public GM {
25public:
26 FactoryGM() {}
27
28protected:
mtklein36352bf2015-03-25 18:17:31 -070029 void onOnceBeforeDraw() override {
scroggo@google.com9f686f32012-11-29 21:05:37 +000030 // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
tfarinac846f4a2014-07-01 12:35:49 -070031 SkString pngFilename = GetResourcePath("plane.png");
bungeman38d909e2016-08-02 14:40:46 -070032 sk_sp<SkData> data(SkData::MakeFromFileName(pngFilename.c_str()));
33 if (data) {
scroggo@google.comf8d7d272013-02-22 21:38:35 +000034 // Create a cache which will boot the pixels out anytime the
35 // bitmap is unlocked.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000036 SkAutoTUnref<SkDiscardableMemoryPool> pool(
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +000037 SkDiscardableMemoryPool::Create(1));
scroggo8e6c7ad2016-09-16 08:20:38 -070038 SkDEPRECATED_InstallDiscardablePixelRef(SkImageGenerator::NewFromEncoded(data.get()),
39 nullptr, &fBitmap, pool);
scroggo@google.com9f686f32012-11-29 21:05:37 +000040 }
41 }
42
reed871872f2015-06-22 12:48:26 -070043 SkString onShortName() override {
scroggo@google.com9f686f32012-11-29 21:05:37 +000044 return SkString("factory");
45 }
46
reed871872f2015-06-22 12:48:26 -070047 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070048 return SkISize::Make(640, 480);
scroggo@google.com9f686f32012-11-29 21:05:37 +000049 }
50
reed871872f2015-06-22 12:48:26 -070051 void onDraw(SkCanvas* canvas) override {
scroggo@google.com9f686f32012-11-29 21:05:37 +000052 canvas->drawBitmap(fBitmap, 0, 0);
53 }
54
scroggo@google.com9f686f32012-11-29 21:05:37 +000055private:
56 SkBitmap fBitmap;
57
58 typedef GM INHERITED;
59};
60
61//////////////////////////////////////////////////////////////////////////////
62
63static GM* MyFactory(void*) { return new FactoryGM; }
64static GMRegistry reg(MyFactory);
65
halcanary@google.com3d50ea12014-01-02 13:15:13 +000066} // namespace skiagm