blob: 831cff0b9f90f693b6686288bc51ec77611575bb [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");
32 SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str()));
bsalomon49f085d2014-09-05 13:34:00 -070033 if (data.get()) {
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));
reedd1146452015-09-25 06:56:57 -070038 SkAssertResult(SkDEPRECATED_InstallDiscardablePixelRef(
39 SkImageGenerator::NewFromEncoded(data),
halcanary96fcdcc2015-08-27 07:41:13 -070040 nullptr, &fBitmap, pool));
scroggo@google.com9f686f32012-11-29 21:05:37 +000041 }
42 }
43
reed871872f2015-06-22 12:48:26 -070044 SkString onShortName() override {
scroggo@google.com9f686f32012-11-29 21:05:37 +000045 return SkString("factory");
46 }
47
reed871872f2015-06-22 12:48:26 -070048 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
reed871872f2015-06-22 12:48:26 -070052 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