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 | */ |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkBitmap.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkColorPriv.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 12 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkShader.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 14 | #include "include/core/SkSize.h" |
| 15 | #include "include/core/SkString.h" |
| 16 | #include "include/core/SkTileMode.h" |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 17 | |
| 18 | namespace skiagm { |
| 19 | |
| 20 | static SkBitmap make_bitmap() { |
| 21 | SkBitmap bm; |
Mike Reed | 304a07c | 2017-07-12 15:10:28 -0400 | [diff] [blame] | 22 | bm.allocN32Pixels(1, 1); |
| 23 | *bm.getAddr32(0, 0) = SkPackARGB32(0x80, 0x80, 0, 0); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 24 | return bm; |
| 25 | } |
| 26 | |
| 27 | class TinyBitmapGM : public GM { |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 28 | public: |
| 29 | TinyBitmapGM() { |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 30 | this->setBGColor(0xFFDDDDDD); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 31 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 32 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 33 | protected: |
| 34 | SkString onShortName() { |
| 35 | return SkString("tinybitmap"); |
| 36 | } |
| 37 | |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 38 | virtual SkISize onISize() { return SkISize::Make(100, 100); } |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 39 | |
| 40 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 41 | SkBitmap bm = make_bitmap(); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 42 | SkPaint paint; |
Mike Reed | 9407e24 | 2019-02-15 16:13:57 -0500 | [diff] [blame] | 43 | paint.setAlphaf(0.5f); |
Mike Reed | 50acf8f | 2019-04-08 13:20:23 -0400 | [diff] [blame] | 44 | paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kMirror)); |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 45 | canvas->drawPaint(paint); |
| 46 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 47 | |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 48 | private: |
| 49 | typedef GM INHERITED; |
| 50 | }; |
| 51 | |
| 52 | ////////////////////////////////////////////////////////////////////////////// |
| 53 | |
Hal Canary | e964c18 | 2019-01-23 10:22:01 -0500 | [diff] [blame] | 54 | DEF_GM( return new TinyBitmapGM; ) |
bsalomon@google.com | 1936f26 | 2011-07-18 21:19:31 +0000 | [diff] [blame] | 55 | |
| 56 | } |