blob: 9b7450e3a3229f936d645cd66fa854a0797824c0 [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"
scroggo@google.com9f686f32012-11-29 21:05:37 +00009#include "SkCanvas.h"
10#include "SkData.h"
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000011#include "SkDecodingImageGenerator.h"
12#include "SkDiscardableMemoryPool.h"
13#include "SkDiscardablePixelRef.h"
scroggo@google.comf8d7d272013-02-22 21:38:35 +000014#include "SkImageDecoder.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:
29 virtual void onOnceBeforeDraw() SK_OVERRIDE {
scroggo@google.com9f686f32012-11-29 21:05:37 +000030 // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
tfarina880914c2014-06-09 12:05:34 -070031 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "plane.png");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000032 SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
33 if (NULL != 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));
halcanary@google.com3d50ea12014-01-02 13:15:13 +000038 SkAssertResult(SkInstallDiscardablePixelRef(
39 SkDecodingImageGenerator::Create(
40 data, SkDecodingImageGenerator::Options()),
41 &fBitmap, pool));
scroggo@google.com9f686f32012-11-29 21:05:37 +000042 }
43 }
44
45 virtual SkString onShortName() {
46 return SkString("factory");
47 }
48
49 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070050 return SkISize::Make(640, 480);
scroggo@google.com9f686f32012-11-29 21:05:37 +000051 }
52
53 virtual void onDraw(SkCanvas* canvas) {
54 canvas->drawBitmap(fBitmap, 0, 0);
55 }
56
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +000057 // Skip cross process pipe due to https://code.google.com/p/skia/issues/detail?id=1520
58 virtual uint32_t onGetFlags() const {
59 return INHERITED::onGetFlags() | kSkipPipeCrossProcess_Flag;
60 }
61
scroggo@google.com9f686f32012-11-29 21:05:37 +000062private:
63 SkBitmap fBitmap;
64
65 typedef GM INHERITED;
66};
67
68//////////////////////////////////////////////////////////////////////////////
69
70static GM* MyFactory(void*) { return new FactoryGM; }
71static GMRegistry reg(MyFactory);
72
halcanary@google.com3d50ea12014-01-02 13:15:13 +000073} // namespace skiagm