2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "Resources.h"
13 #include "SkDecodingImageGenerator.h"
14 #include "SkDiscardableMemoryPool.h"
15 #include "SkDiscardablePixelRef.h"
16 #include "SkImageDecoder.h"
17 #include "SkImageGeneratorPriv.h"
24 * Draw a PNG created by SkBitmapFactory.
26 class FactoryGM : public GM {
31 virtual void onOnceBeforeDraw() SK_OVERRIDE {
32 // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
33 SkString pngFilename = GetResourcePath("plane.png");
34 SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str()));
35 if (NULL != data.get()) {
36 // Create a cache which will boot the pixels out anytime the
37 // bitmap is unlocked.
38 SkAutoTUnref<SkDiscardableMemoryPool> pool(
39 SkDiscardableMemoryPool::Create(1));
40 SkAssertResult(SkInstallDiscardablePixelRef(
41 SkDecodingImageGenerator::Create(
42 data, SkDecodingImageGenerator::Options()),
47 virtual SkString onShortName() {
48 return SkString("factory");
51 virtual SkISize onISize() {
52 return SkISize::Make(640, 480);
55 virtual void onDraw(SkCanvas* canvas) {
56 canvas->drawBitmap(fBitmap, 0, 0);
59 // 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;
70 //////////////////////////////////////////////////////////////////////////////
72 static GM* MyFactory(void*) { return new FactoryGM; }
73 static GMRegistry reg(MyFactory);