blob: 641133c440430ffd5b373213b49f483f07a03bd6 [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 {
tfarinabcbc1782014-06-18 14:32:48 -070032 SkString resourcePath = GetResourcePath();
scroggo@google.com9f686f32012-11-29 21:05:37 +000033 // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
tfarinabcbc1782014-06-18 14:32:48 -070034 SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "plane.png");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000035 SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
36 if (NULL != data.get()) {
scroggo@google.comf8d7d272013-02-22 21:38:35 +000037 // Create a cache which will boot the pixels out anytime the
38 // bitmap is unlocked.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000039 SkAutoTUnref<SkDiscardableMemoryPool> pool(
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +000040 SkDiscardableMemoryPool::Create(1));
halcanary@google.com3d50ea12014-01-02 13:15:13 +000041 SkAssertResult(SkInstallDiscardablePixelRef(
42 SkDecodingImageGenerator::Create(
43 data, SkDecodingImageGenerator::Options()),
44 &fBitmap, pool));
scroggo@google.com9f686f32012-11-29 21:05:37 +000045 }
46 }
47
48 virtual SkString onShortName() {
49 return SkString("factory");
50 }
51
52 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070053 return SkISize::Make(640, 480);
scroggo@google.com9f686f32012-11-29 21:05:37 +000054 }
55
56 virtual void onDraw(SkCanvas* canvas) {
57 canvas->drawBitmap(fBitmap, 0, 0);
58 }
59
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +000060 // Skip cross process pipe due to https://code.google.com/p/skia/issues/detail?id=1520
61 virtual uint32_t onGetFlags() const {
62 return INHERITED::onGetFlags() | kSkipPipeCrossProcess_Flag;
63 }
64
scroggo@google.com9f686f32012-11-29 21:05:37 +000065private:
66 SkBitmap fBitmap;
67
68 typedef GM INHERITED;
69};
70
71//////////////////////////////////////////////////////////////////////////////
72
73static GM* MyFactory(void*) { return new FactoryGM; }
74static GMRegistry reg(MyFactory);
75
halcanary@google.com3d50ea12014-01-02 13:15:13 +000076} // namespace skiagm