Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=bfd18e9cac896cdf94c9f154ccf94be8 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Canvas_drawImageRect, 256, 64, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | uint32_t pixels[][4] = { |
| 8 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 }, |
| 9 | { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 }, |
| 10 | { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 }, |
| 11 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } }; |
| 12 | SkBitmap redBorder; |
| 13 | redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4), |
| 14 | (void*) pixels, sizeof(pixels[0])); |
Mike Reed | dc607e3 | 2020-12-23 11:50:36 -0500 | [diff] [blame] | 15 | sk_sp<SkImage> image = redBorder.asImage(); |
Mike Reed | b339d05 | 2021-01-28 11:20:41 -0500 | [diff] [blame] | 16 | SkSamplingOptions sampling; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 17 | for (auto constraint : { |
| 18 | SkCanvas::kFast_SrcRectConstraint, |
| 19 | SkCanvas::kStrict_SrcRectConstraint, |
| 20 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 21 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
Mike Reed | b339d05 | 2021-01-28 11:20:41 -0500 | [diff] [blame] | 22 | SkRect::MakeLTRB(16, 16, 48, 48), sampling, nullptr, constraint); |
| 23 | sampling = SkSamplingOptions(SkFilterMode::kLinear); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 24 | canvas->translate(80, 0); |
| 25 | } |
| 26 | } |
| 27 | } // END FIDDLE |