blob: fc226c11f4205fd17f58c6f3fbfe5e8905c3d322 [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"
8#include "SkColorPriv.h"
9#include "SkShader.h"
10#include "SkCanvas.h"
11#include "SkUtils.h"
12
13namespace skiagm {
14
15static SkBitmap make_bitmap() {
reed@google.com0a6151d2013-10-10 14:44:56 +000016 const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) };
17 SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c));
18
bsalomon@google.com1936f262011-07-18 21:19:31 +000019 SkBitmap bm;
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +000020 bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
21 kPremul_SkAlphaType),
halcanary96fcdcc2015-08-27 07:41:13 -070022 nullptr, ctable);
bsalomon@google.com1936f262011-07-18 21:19:31 +000023 ctable->unref();
24
25 bm.lockPixels();
26 *bm.getAddr8(0, 0) = 0;
27 bm.unlockPixels();
28 return bm;
29}
30
31class TinyBitmapGM : public GM {
bsalomon@google.com1936f262011-07-18 21:19:31 +000032public:
33 TinyBitmapGM() {
caryclark65cdba62015-06-15 06:51:08 -070034 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
bsalomon@google.com1936f262011-07-18 21:19:31 +000035 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000036
bsalomon@google.com1936f262011-07-18 21:19:31 +000037protected:
38 SkString onShortName() {
39 return SkString("tinybitmap");
40 }
41
tfarinaf5393182014-06-09 23:59:03 -070042 virtual SkISize onISize() { return SkISize::Make(100, 100); }
bsalomon@google.com1936f262011-07-18 21:19:31 +000043
44 virtual void onDraw(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000045 SkBitmap bm = make_bitmap();
bsalomon@google.com1936f262011-07-18 21:19:31 +000046 SkPaint paint;
47 paint.setAlpha(0x80);
reed1a9b9642016-03-13 14:13:58 -070048 paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
49 SkShader::kMirror_TileMode));
bsalomon@google.com1936f262011-07-18 21:19:31 +000050 canvas->drawPaint(paint);
51 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000052
bsalomon@google.com1936f262011-07-18 21:19:31 +000053private:
54 typedef GM INHERITED;
55};
56
57//////////////////////////////////////////////////////////////////////////////
58
59static GM* MyFactory(void*) { return new TinyBitmapGM; }
60static GMRegistry reg(MyFactory);
61
62}