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; |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 21 | bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType, |
| 22 | kPremul_SkAlphaType), |
| 23 | NULL, ctable); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 24 | ctable->unref(); |
| 25 | |
| 26 | bm.lockPixels(); |
| 27 | *bm.getAddr8(0, 0) = 0; |
| 28 | bm.unlockPixels(); |
| 29 | return bm; |
| 30 | } |
| 31 | |
| 32 | class TinyBitmapGM : public GM { |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 33 | public: |
| 34 | TinyBitmapGM() { |
caryclark | 0bdb08b | 2015-06-15 05:28:00 -0700 | [diff] [blame^] | 35 | this->setBGColor(0xFFDDDDDD); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 36 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 37 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 38 | protected: |
| 39 | SkString onShortName() { |
| 40 | return SkString("tinybitmap"); |
| 41 | } |
| 42 | |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 43 | virtual SkISize onISize() { return SkISize::Make(100, 100); } |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 44 | |
| 45 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 46 | SkBitmap bm = make_bitmap(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 47 | SkShader* s = |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 48 | SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 49 | SkShader::kMirror_TileMode); |
| 50 | SkPaint paint; |
| 51 | paint.setAlpha(0x80); |
| 52 | paint.setShader(s)->unref(); |
| 53 | canvas->drawPaint(paint); |
| 54 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 55 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 56 | private: |
| 57 | typedef GM INHERITED; |
| 58 | }; |
| 59 | |
| 60 | ////////////////////////////////////////////////////////////////////////////// |
| 61 | |
| 62 | static GM* MyFactory(void*) { return new TinyBitmapGM; } |
| 63 | static GMRegistry reg(MyFactory); |
| 64 | |
| 65 | } |