blob: 0804e9208f4b5eb15a30e6e6008dd37b99f951ac [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
bsalomon@google.com1936f262011-07-18 21:19:31 +00007#include "gm.h"
Mike Klein33d20552017-03-22 13:47:51 -04008#include "sk_tool_utils.h"
bsalomon@google.com1936f262011-07-18 21:19:31 +00009#include "SkColorPriv.h"
10#include "SkShader.h"
11#include "SkCanvas.h"
12#include "SkUtils.h"
13
14namespace skiagm {
15
16static SkBitmap make_bitmap() {
17 SkBitmap bm;
Mike Reed304a07c2017-07-12 15:10:28 -040018 bm.allocN32Pixels(1, 1);
19 *bm.getAddr32(0, 0) = SkPackARGB32(0x80, 0x80, 0, 0);
bsalomon@google.com1936f262011-07-18 21:19:31 +000020 return bm;
21}
22
23class TinyBitmapGM : public GM {
bsalomon@google.com1936f262011-07-18 21:19:31 +000024public:
25 TinyBitmapGM() {
caryclark65cdba62015-06-15 06:51:08 -070026 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
bsalomon@google.com1936f262011-07-18 21:19:31 +000027 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000028
bsalomon@google.com1936f262011-07-18 21:19:31 +000029protected:
30 SkString onShortName() {
31 return SkString("tinybitmap");
32 }
33
tfarinaf5393182014-06-09 23:59:03 -070034 virtual SkISize onISize() { return SkISize::Make(100, 100); }
bsalomon@google.com1936f262011-07-18 21:19:31 +000035
36 virtual void onDraw(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000037 SkBitmap bm = make_bitmap();
bsalomon@google.com1936f262011-07-18 21:19:31 +000038 SkPaint paint;
39 paint.setAlpha(0x80);
reed1a9b9642016-03-13 14:13:58 -070040 paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
41 SkShader::kMirror_TileMode));
bsalomon@google.com1936f262011-07-18 21:19:31 +000042 canvas->drawPaint(paint);
43 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000044
bsalomon@google.com1936f262011-07-18 21:19:31 +000045private:
46 typedef GM INHERITED;
47};
48
49//////////////////////////////////////////////////////////////////////////////
50
51static GM* MyFactory(void*) { return new TinyBitmapGM; }
52static GMRegistry reg(MyFactory);
53
54}