aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/factory.cpp
blob: a9bf519c0003bca0c992f92ea778531b9d9fb166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"

#include "Resources.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDecodingImageGenerator.h"
#include "SkDiscardableMemoryPool.h"
#include "SkDiscardablePixelRef.h"
#include "SkImageDecoder.h"
#include "SkImageGeneratorPriv.h"
#include "SkOSFile.h"
#include "SkStream.h"

namespace skiagm {

/**
 *  Draw a PNG created by SkBitmapFactory.
 */
class FactoryGM : public GM {
public:
    FactoryGM() {}

protected:
    virtual void onOnceBeforeDraw() SK_OVERRIDE {
        // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
        SkString pngFilename = GetResourcePath("plane.png");
        SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str()));
        if (data.get()) {
            // Create a cache which will boot the pixels out anytime the
            // bitmap is unlocked.
            SkAutoTUnref<SkDiscardableMemoryPool> pool(
                SkDiscardableMemoryPool::Create(1));
            SkAssertResult(SkInstallDiscardablePixelRef(
                SkDecodingImageGenerator::Create(
                    data, SkDecodingImageGenerator::Options()),
                &fBitmap, pool));
        }
    }

    virtual SkString onShortName() {
        return SkString("factory");
    }

    virtual SkISize onISize() {
        return SkISize::Make(640, 480);
    }

    virtual void onDraw(SkCanvas* canvas) {
        canvas->drawBitmap(fBitmap, 0, 0);
    }

    // Skip cross process pipe due to https://code.google.com/p/skia/issues/detail?id=1520
    virtual uint32_t onGetFlags() const {
        return INHERITED::onGetFlags() | kSkipPipeCrossProcess_Flag;
    }

private:
    SkBitmap fBitmap;

    typedef GM INHERITED;
};

//////////////////////////////////////////////////////////////////////////////

static GM* MyFactory(void*) { return new FactoryGM; }
static GMRegistry reg(MyFactory);

}  // namespace skiagm