blob: 4d36574daa5b9f1b6e11d9dbd6394ec5a3efcb2f [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));
reedd1146452015-09-25 06:56:57 -070039 SkAssertResult(SkDEPRECATED_InstallDiscardablePixelRef(
40 SkImageGenerator::NewFromEncoded(data),
halcanary96fcdcc2015-08-27 07:41:13 -070041 nullptr, &fBitmap, pool));
scroggo@google.com9f686f32012-11-29 21:05:37 +000042 }
43 }
44
reed871872f2015-06-22 12:48:26 -070045 SkString onShortName() override {
scroggo@google.com9f686f32012-11-29 21:05:37 +000046 return SkString("factory");
47 }
48
reed871872f2015-06-22 12:48:26 -070049 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070050 return SkISize::Make(640, 480);
scroggo@google.com9f686f32012-11-29 21:05:37 +000051 }
52
reed871872f2015-06-22 12:48:26 -070053 void onDraw(SkCanvas* canvas) override {
scroggo@google.com9f686f32012-11-29 21:05:37 +000054 canvas->drawBitmap(fBitmap, 0, 0);
55 }
56
scroggo@google.com9f686f32012-11-29 21:05:37 +000057private:
58 SkBitmap fBitmap;
59
60 typedef GM INHERITED;
61};
62
63//////////////////////////////////////////////////////////////////////////////
64
65static GM* MyFactory(void*) { return new FactoryGM; }
66static GMRegistry reg(MyFactory);
67
halcanary@google.com3d50ea12014-01-02 13:15:13 +000068} // namespace skiagm