blob: 7942b4266afb3e27a492ac5e4f29ecd725e0ab1f [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
bsalomon@google.com1936f262011-07-18 21:19:31 +00008#include "gm.h"
9#include "SkColorPriv.h"
10#include "SkShader.h"
11#include "SkCanvas.h"
12#include "SkUtils.h"
13
14namespace skiagm {
15
16static SkBitmap make_bitmap() {
reed@google.com0a6151d2013-10-10 14:44:56 +000017 const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) };
18 SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c));
19
bsalomon@google.com1936f262011-07-18 21:19:31 +000020 SkBitmap bm;
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +000021 bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
22 kPremul_SkAlphaType),
halcanary96fcdcc2015-08-27 07:41:13 -070023 nullptr, ctable);
bsalomon@google.com1936f262011-07-18 21:19:31 +000024 ctable->unref();
25
26 bm.lockPixels();
27 *bm.getAddr8(0, 0) = 0;
28 bm.unlockPixels();
29 return bm;
30}
31
32class TinyBitmapGM : public GM {
bsalomon@google.com1936f262011-07-18 21:19:31 +000033public:
34 TinyBitmapGM() {
caryclark65cdba62015-06-15 06:51:08 -070035 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
bsalomon@google.com1936f262011-07-18 21:19:31 +000036 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000037
bsalomon@google.com1936f262011-07-18 21:19:31 +000038protected:
39 SkString onShortName() {
40 return SkString("tinybitmap");
41 }
42
tfarinaf5393182014-06-09 23:59:03 -070043 virtual SkISize onISize() { return SkISize::Make(100, 100); }
bsalomon@google.com1936f262011-07-18 21:19:31 +000044
45 virtual void onDraw(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000046 SkBitmap bm = make_bitmap();
rmistry@google.comae933ce2012-08-23 18:19:56 +000047 SkShader* s =
reed@google.com7775d662012-11-27 15:15:58 +000048 SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
bsalomon@google.com1936f262011-07-18 21:19:31 +000049 SkShader::kMirror_TileMode);
50 SkPaint paint;
51 paint.setAlpha(0x80);
52 paint.setShader(s)->unref();
53 canvas->drawPaint(paint);
54 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000055
bsalomon@google.com1936f262011-07-18 21:19:31 +000056private:
57 typedef GM INHERITED;
58};
59
60//////////////////////////////////////////////////////////////////////////////
61
62static GM* MyFactory(void*) { return new TinyBitmapGM; }
63static GMRegistry reg(MyFactory);
64
65}