epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 7 | #include "gm.h" |
| 8 | #include "SkColorPriv.h" |
| 9 | #include "SkShader.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkUtils.h" |
| 12 | |
| 13 | namespace skiagm { |
| 14 | |
| 15 | static SkBitmap make_bitmap() { |
reed@google.com | 0a6151d | 2013-10-10 14:44:56 +0000 | [diff] [blame] | 16 | const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) }; |
| 17 | SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c)); |
| 18 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 19 | SkBitmap bm; |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 20 | bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType, |
| 21 | kPremul_SkAlphaType), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 22 | nullptr, ctable); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 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() { |
caryclark | 65cdba6 | 2015-06-15 06:51:08 -0700 | [diff] [blame] | 34 | this->setBGColor(sk_tool_utils::color_to_565(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 | |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 42 | virtual SkISize onISize() { return SkISize::Make(100, 100); } |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 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(); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 46 | SkPaint paint; |
| 47 | paint.setAlpha(0x80); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 48 | paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, |
| 49 | SkShader::kMirror_TileMode)); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 50 | canvas->drawPaint(paint); |
| 51 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 52 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 53 | private: |
| 54 | typedef GM INHERITED; |
| 55 | }; |
| 56 | |
| 57 | ////////////////////////////////////////////////////////////////////////////// |
| 58 | |
| 59 | static GM* MyFactory(void*) { return new TinyBitmapGM; } |
| 60 | static GMRegistry reg(MyFactory); |
| 61 | |
| 62 | } |