1 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 */ 8 #include "gm.h" 9 #include "SkColorPriv.h" 10 #include "SkShader.h" 11 #include "SkCanvas.h" 12 #include "SkUtils.h" 13 14 namespace skiagm { 15 16 static SkBitmap make_bitmap() { 17 const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) }; 18 SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c)); 19 20 SkBitmap bm; 21 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 31 class TinyBitmapGM : public GM { 32 public: 33 TinyBitmapGM() { 34 this->setBGColor(0xFFDDDDDD); 35 } 36 37 protected: 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) { 45 SkBitmap bm = make_bitmap(); 46 SkShader* s = 47 SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, 48 SkShader::kMirror_TileMode); 49 SkPaint paint; 50 paint.setAlpha(0x80); 51 paint.setShader(s)->unref(); 52 canvas->drawPaint(paint); 53 } 54 55 private: 56 typedef GM INHERITED; 57 }; 58 59 ////////////////////////////////////////////////////////////////////////////// 60 61 static GM* MyFactory(void*) { return new TinyBitmapGM; } 62 static GMRegistry reg(MyFactory); 63 64 } 65