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" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 8 | #include "sk_tool_utils.h" |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 9 | #include "SkColorPriv.h" |
| 10 | #include "SkShader.h" |
| 11 | #include "SkCanvas.h" |
Hal Canary | ea60b95 | 2018-08-21 11:45:46 -0400 | [diff] [blame] | 12 | #include "SkUTF.h" |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 13 | |
| 14 | namespace skiagm { |
| 15 | |
| 16 | static SkBitmap make_bitmap() { |
| 17 | SkBitmap bm; |
Mike Reed | 304a07c | 2017-07-12 15:10:28 -0400 | [diff] [blame] | 18 | bm.allocN32Pixels(1, 1); |
| 19 | *bm.getAddr32(0, 0) = SkPackARGB32(0x80, 0x80, 0, 0); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 20 | return bm; |
| 21 | } |
| 22 | |
| 23 | class TinyBitmapGM : public GM { |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 24 | public: |
| 25 | TinyBitmapGM() { |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 26 | this->setBGColor(0xFFDDDDDD); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 27 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 28 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 29 | protected: |
| 30 | SkString onShortName() { |
| 31 | return SkString("tinybitmap"); |
| 32 | } |
| 33 | |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 34 | virtual SkISize onISize() { return SkISize::Make(100, 100); } |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 35 | |
| 36 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 37 | SkBitmap bm = make_bitmap(); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 38 | SkPaint paint; |
| 39 | paint.setAlpha(0x80); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 40 | paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, |
| 41 | SkShader::kMirror_TileMode)); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 42 | canvas->drawPaint(paint); |
| 43 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 44 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 45 | private: |
| 46 | typedef GM INHERITED; |
| 47 | }; |
| 48 | |
| 49 | ////////////////////////////////////////////////////////////////////////////// |
| 50 | |
| 51 | static GM* MyFactory(void*) { return new TinyBitmapGM; } |
| 52 | static GMRegistry reg(MyFactory); |
| 53 | |
| 54 | } |