Add fixes & test for isConfigTexturable and isConfigRenderable
[platform/upstream/libSkiaSharp.git] / gm / tinybitmap.cpp
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
16 static SkBitmap make_bitmap() {
17     const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) };
18
19     SkBitmap bm;
20     bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
21                                      kPremul_SkAlphaType),
22                    SkColorTable::Make(c, SK_ARRAY_COUNT(c)));
23
24     *bm.getAddr8(0, 0) = 0;
25     return bm;
26 }
27
28 class TinyBitmapGM : public GM {
29 public:
30     TinyBitmapGM() {
31         this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
32     }
33
34 protected:
35     SkString onShortName() {
36         return SkString("tinybitmap");
37     }
38
39     virtual SkISize onISize() { return SkISize::Make(100, 100); }
40
41     virtual void onDraw(SkCanvas* canvas) {
42         SkBitmap bm = make_bitmap();
43         SkPaint paint;
44         paint.setAlpha(0x80);
45         paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
46                                                    SkShader::kMirror_TileMode));
47         canvas->drawPaint(paint);
48     }
49
50 private:
51     typedef GM INHERITED;
52 };
53
54 //////////////////////////////////////////////////////////////////////////////
55
56 static GM* MyFactory(void*) { return new TinyBitmapGM; }
57 static GMRegistry reg(MyFactory);
58
59 }