blob: 608c049dc37be6e53a2e682710ac174ad596acc1 [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 "SkDecodingImageGenerator.h"
14#include "SkDiscardableMemoryPool.h"
15#include "SkDiscardablePixelRef.h"
scroggo@google.comf8d7d272013-02-22 21:38:35 +000016#include "SkImageDecoder.h"
commit-bot@chromium.org2d970b52014-05-27 14:14:22 +000017#include "SkImageGeneratorPriv.h"
scroggo@google.comccd7afb2013-05-28 16:45:07 +000018#include "SkOSFile.h"
scroggo@google.com9f686f32012-11-29 21:05:37 +000019#include "SkStream.h"
20
21namespace skiagm {
22
23/**
24 * Draw a PNG created by SkBitmapFactory.
25 */
26class FactoryGM : public GM {
27public:
28 FactoryGM() {}
29
30protected:
31 virtual void onOnceBeforeDraw() SK_OVERRIDE {
scroggo@google.com9f686f32012-11-29 21:05:37 +000032 // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
tfarinac846f4a2014-07-01 12:35:49 -070033 SkString pngFilename = GetResourcePath("plane.png");
34 SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str()));
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000035 if (NULL != data.get()) {
scroggo@google.comf8d7d272013-02-22 21:38:35 +000036 // Create a cache which will boot the pixels out anytime the
37 // bitmap is unlocked.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000038 SkAutoTUnref<SkDiscardableMemoryPool> pool(
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +000039 SkDiscardableMemoryPool::Create(1));
halcanary@google.com3d50ea12014-01-02 13:15:13 +000040 SkAssertResult(SkInstallDiscardablePixelRef(
41 SkDecodingImageGenerator::Create(
42 data, SkDecodingImageGenerator::Options()),
43 &fBitmap, pool));
scroggo@google.com9f686f32012-11-29 21:05:37 +000044 }
45 }
46
47 virtual SkString onShortName() {
48 return SkString("factory");
49 }
50
51 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070052 return SkISize::Make(640, 480);
scroggo@google.com9f686f32012-11-29 21:05:37 +000053 }
54
55 virtual void onDraw(SkCanvas* canvas) {
56 canvas->drawBitmap(fBitmap, 0, 0);
57 }
58
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +000059 // Skip cross process pipe due to https://code.google.com/p/skia/issues/detail?id=1520
60 virtual uint32_t onGetFlags() const {
61 return INHERITED::onGetFlags() | kSkipPipeCrossProcess_Flag;
62 }
63
scroggo@google.com9f686f32012-11-29 21:05:37 +000064private:
65 SkBitmap fBitmap;
66
67 typedef GM INHERITED;
68};
69
70//////////////////////////////////////////////////////////////////////////////
71
72static GM* MyFactory(void*) { return new FactoryGM; }
73static GMRegistry reg(MyFactory);
74
halcanary@google.com3d50ea12014-01-02 13:15:13 +000075} // namespace skiagm