aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/tinybitmap.cpp
blob: d532b5b49975961a3a301b2d84fcf4f273ce5528 (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

/*
 * Copyright 2011 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 "SkColorPriv.h"
#include "SkShader.h"
#include "SkCanvas.h"
#include "SkUtils.h"

namespace skiagm {

static SkBitmap make_bitmap() {
    SkBitmap bm;

    SkColorTable* ctable = new SkColorTable(1);
    SkPMColor* c = ctable->lockColors();
    c[0] = SkPackARGB32(0x80, 0x80, 0, 0);
    ctable->unlockColors(true);

    bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
    bm.allocPixels(ctable);
    ctable->unref();

    bm.lockPixels();
    *bm.getAddr8(0, 0) = 0;
    bm.unlockPixels();
    return bm;
}

class TinyBitmapGM : public GM {
    SkBitmap    fBM;
public:
    TinyBitmapGM() {
        this->setBGColor(0xFFDDDDDD);
        fBM = make_bitmap();
    }
    
protected:
    SkString onShortName() {
        return SkString("tinybitmap");
    }

    virtual SkISize onISize() { return make_isize(100, 100); }

    virtual void onDraw(SkCanvas* canvas) {
        SkShader* s = 
            SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMode,
                                         SkShader::kMirror_TileMode);
        SkPaint paint;
        paint.setAlpha(0x80);
        paint.setShader(s)->unref();
        canvas->drawPaint(paint);
    }
    
private:
    typedef GM INHERITED;
};

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

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

}