blob: efd817db7dd255e88a4ac63b93568c9b8e4e1653 [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"
halcanary@google.com3d50ea12014-01-02 13:15:13 +000015#include "SkImageGenerator.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
scroggo@google.comccd7afb2013-05-28 16:45:07 +000031 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str(),
32 "plane.png");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000033 SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
34 if (NULL != 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(
38 SkNEW_ARGS(SkDiscardableMemoryPool, (1)));
halcanary@google.com3d50ea12014-01-02 13:15:13 +000039 SkAssertResult(SkInstallDiscardablePixelRef(
40 SkDecodingImageGenerator::Create(
41 data, SkDecodingImageGenerator::Options()),
42 &fBitmap, pool));
scroggo@google.com9f686f32012-11-29 21:05:37 +000043 }
44 }
45
46 virtual SkString onShortName() {
47 return SkString("factory");
48 }
49
50 virtual SkISize onISize() {
51 return make_isize(640, 480);
52 }
53
54 virtual void onDraw(SkCanvas* canvas) {
55 canvas->drawBitmap(fBitmap, 0, 0);
56 }
57
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +000058 // Skip cross process pipe due to https://code.google.com/p/skia/issues/detail?id=1520
59 virtual uint32_t onGetFlags() const {
60 return INHERITED::onGetFlags() | kSkipPipeCrossProcess_Flag;
61 }
62
scroggo@google.com9f686f32012-11-29 21:05:37 +000063private:
64 SkBitmap fBitmap;
65
66 typedef GM INHERITED;
67};
68
69//////////////////////////////////////////////////////////////////////////////
70
71static GM* MyFactory(void*) { return new FactoryGM; }
72static GMRegistry reg(MyFactory);
73
halcanary@google.com3d50ea12014-01-02 13:15:13 +000074} // namespace skiagm