blob: 6cb9eded73944c1f7fd400ebbea9842e8755ae72 [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;
bsalomon@google.com1936f262011-07-18 21:19:31 +000021 bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
22 bm.allocPixels(ctable);
23 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() {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000034 this->setBGColor(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
42 virtual SkISize onISize() { return make_isize(100, 100); }
43
44 virtual void onDraw(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000045 SkBitmap bm = make_bitmap();
rmistry@google.comae933ce2012-08-23 18:19:56 +000046 SkShader* s =
reed@google.com7775d662012-11-27 15:15:58 +000047 SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
bsalomon@google.com1936f262011-07-18 21:19:31 +000048 SkShader::kMirror_TileMode);
49 SkPaint paint;
50 paint.setAlpha(0x80);
51 paint.setShader(s)->unref();
52 canvas->drawPaint(paint);
53 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000054
bsalomon@google.com1936f262011-07-18 21:19:31 +000055private:
56 typedef GM INHERITED;
57};
58
59//////////////////////////////////////////////////////////////////////////////
60
61static GM* MyFactory(void*) { return new TinyBitmapGM; }
62static GMRegistry reg(MyFactory);
63
64}