1 /*
2  * Copyright 2011 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 #include "gm.h"
8 #include "sk_tool_utils.h"
9 #include "SkColorPriv.h"
10 #include "SkShader.h"
11 #include "SkCanvas.h"
12 #include "SkUtils.h"
13 
14 namespace skiagm {
15 
make_bitmap()16 static SkBitmap make_bitmap() {
17     const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) };
18     SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c));
19 
20     SkBitmap bm;
21     bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
22                                      kPremul_SkAlphaType),
23                    nullptr, ctable);
24     ctable->unref();
25 
26     bm.lockPixels();
27     *bm.getAddr8(0, 0) = 0;
28     bm.unlockPixels();
29     return bm;
30 }
31 
32 class TinyBitmapGM : public GM {
33 public:
TinyBitmapGM()34     TinyBitmapGM() {
35         this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
36     }
37 
38 protected:
onShortName()39     SkString onShortName() {
40         return SkString("tinybitmap");
41     }
42 
onISize()43     virtual SkISize onISize() { return SkISize::Make(100, 100); }
44 
onDraw(SkCanvas * canvas)45     virtual void onDraw(SkCanvas* canvas) {
46         SkBitmap bm = make_bitmap();
47         SkPaint paint;
48         paint.setAlpha(0x80);
49         paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
50                                                    SkShader::kMirror_TileMode));
51         canvas->drawPaint(paint);
52     }
53 
54 private:
55     typedef GM INHERITED;
56 };
57 
58 //////////////////////////////////////////////////////////////////////////////
59 
MyFactory(void *)60 static GM* MyFactory(void*) { return new TinyBitmapGM; }
61 static GMRegistry reg(MyFactory);
62 
63 }
64