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() { |
reed@google.com | 0a6151d | 2013-10-10 14:44:56 +0000 | [diff] [blame] | 17 | const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) }; |
| 18 | SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c)); |
| 19 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 20 | SkBitmap bm; |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 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 { |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 32 | public: |
| 33 | TinyBitmapGM() { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 34 | this->setBGColor(0xFFDDDDDD); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 35 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 36 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 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) { |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 45 | SkBitmap bm = make_bitmap(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 46 | SkShader* s = |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 47 | SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 48 | SkShader::kMirror_TileMode); |
| 49 | SkPaint paint; |
| 50 | paint.setAlpha(0x80); |
| 51 | paint.setShader(s)->unref(); |
| 52 | canvas->drawPaint(paint); |
| 53 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 54 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 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 | } |