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.
3 #include "tools/fiddle/examples.h"
4 // HASH=bfd18e9cac896cdf94c9f154ccf94be8
5 REG_FIDDLE(Canvas_drawImageRect, 256, 64, false, 0) {
draw(SkCanvas * canvas)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]));
15 sk_sp<SkImage> image = redBorder.asImage();
16 SkSamplingOptions sampling;
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),
22 SkRect::MakeLTRB(16, 16, 48, 48), sampling, nullptr, constraint);
23 sampling = SkSamplingOptions(SkFilterMode::kLinear);
24 canvas->translate(80, 0);
25 }
26 }
27 } // END FIDDLE
28