blob: 3b1006c189a3ca65f4ebd26656b2321cbeac394f [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() {
17 SkBitmap bm;
18
19 SkColorTable* ctable = new SkColorTable(1);
20 SkPMColor* c = ctable->lockColors();
21 c[0] = SkPackARGB32(0x80, 0x80, 0, 0);
22 ctable->unlockColors(true);
23
24 bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
25 bm.allocPixels(ctable);
26 ctable->unref();
27
28 bm.lockPixels();
29 *bm.getAddr8(0, 0) = 0;
30 bm.unlockPixels();
31 return bm;
32}
33
34class TinyBitmapGM : public GM {
35 SkBitmap fBM;
36public:
37 TinyBitmapGM() {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000038 this->setBGColor(0xFFDDDDDD);
bsalomon@google.com1936f262011-07-18 21:19:31 +000039 fBM = make_bitmap();
40 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000041
bsalomon@google.com1936f262011-07-18 21:19:31 +000042protected:
43 SkString onShortName() {
44 return SkString("tinybitmap");
45 }
46
47 virtual SkISize onISize() { return make_isize(100, 100); }
48
49 virtual void onDraw(SkCanvas* canvas) {
rmistry@google.comae933ce2012-08-23 18:19:56 +000050 SkShader* s =
bsalomon@google.com1936f262011-07-18 21:19:31 +000051 SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMode,
52 SkShader::kMirror_TileMode);
53 SkPaint paint;
54 paint.setAlpha(0x80);
55 paint.setShader(s)->unref();
56 canvas->drawPaint(paint);
57 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000058
bsalomon@google.com1936f262011-07-18 21:19:31 +000059private:
60 typedef GM INHERITED;
61};
62
63//////////////////////////////////////////////////////////////////////////////
64
65static GM* MyFactory(void*) { return new TinyBitmapGM; }
66static GMRegistry reg(MyFactory);
67
68}