2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SampleCode.h"
9 #include "SkColorPriv.h"
15 static SkBitmap make_bitmap() {
19 for (int i = 0; i < N; i++) {
20 c[i] = SkPackARGB32(0x80, 0x80, 0, 0);
24 bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
26 SkColorTable::Make(c, N));
28 for (int y = 0; y < bm.height(); y++) {
29 uint8_t* p = bm.getAddr8(0, y);
30 for (int x = 0; x < bm.width(); x++) {
37 class TinyBitmapView : public SampleView {
42 this->setBGColor(0xFFDDDDDD);
46 bool onQuery(SkEvent* evt) override {
47 if (SampleCode::TitleQ(*evt)) {
48 SampleCode::TitleR(evt, "TinyBitmap");
51 return this->INHERITED::onQuery(evt);
54 static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
55 bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
58 void onDrawContent(SkCanvas* canvas) override {
60 paint.setShader(SkShader::MakeBitmapShader(fBM, SkShader::kRepeat_TileMode,
61 SkShader::kMirror_TileMode));
62 canvas->drawPaint(paint);
66 typedef SkView INHERITED;
69 //////////////////////////////////////////////////////////////////////////////
71 static SkView* MyFactory() { return new TinyBitmapView; }
72 static SkViewRegister reg(MyFactory);