epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 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 | 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 | |
| 34 | class TinyBitmapGM : public GM { |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 35 | public: |
| 36 | TinyBitmapGM() { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 37 | this->setBGColor(0xFFDDDDDD); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 38 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 39 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 40 | protected: |
| 41 | SkString onShortName() { |
| 42 | return SkString("tinybitmap"); |
| 43 | } |
| 44 | |
| 45 | virtual SkISize onISize() { return make_isize(100, 100); } |
| 46 | |
| 47 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 48 | SkBitmap bm = make_bitmap(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 49 | SkShader* s = |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 50 | SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 51 | SkShader::kMirror_TileMode); |
| 52 | SkPaint paint; |
| 53 | paint.setAlpha(0x80); |
| 54 | paint.setShader(s)->unref(); |
| 55 | canvas->drawPaint(paint); |
| 56 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 57 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 58 | private: |
| 59 | typedef GM INHERITED; |
| 60 | }; |
| 61 | |
| 62 | ////////////////////////////////////////////////////////////////////////////// |
| 63 | |
| 64 | static GM* MyFactory(void*) { return new TinyBitmapGM; } |
| 65 | static GMRegistry reg(MyFactory); |
| 66 | |
| 67 | } |