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.
11 #include "SkDecodingImageGenerator.h"
12 #include "SkDiscardableMemoryPool.h"
13 #include "SkDiscardablePixelRef.h"
14 #include "SkImageDecoder.h"
15 #include "SkImageGenerator.h"
22 * Draw a PNG created by SkBitmapFactory.
24 class FactoryGM : public GM {
29 virtual void onOnceBeforeDraw() SK_OVERRIDE {
30 // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
31 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str(),
33 SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
34 if (NULL != data.get()) {
35 // Create a cache which will boot the pixels out anytime the
36 // bitmap is unlocked.
37 SkAutoTUnref<SkDiscardableMemoryPool> pool(
38 SkDiscardableMemoryPool::Create(1));
39 SkAssertResult(SkInstallDiscardablePixelRef(
40 SkDecodingImageGenerator::Create(
41 data, SkDecodingImageGenerator::Options()),
46 virtual SkString onShortName() {
47 return SkString("factory");
50 virtual SkISize onISize() {
51 return make_isize(640, 480);
54 virtual void onDraw(SkCanvas* canvas) {
55 canvas->drawBitmap(fBitmap, 0, 0);
58 // 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;
69 //////////////////////////////////////////////////////////////////////////////
71 static GM* MyFactory(void*) { return new FactoryGM; }
72 static GMRegistry reg(MyFactory);