1*c8dee2aaSAndroid Build Coastguard Worker // Copyright 2019 Google LLC.
2*c8dee2aaSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3*c8dee2aaSAndroid Build Coastguard Worker #include "tools/fiddle/examples.h"
4*c8dee2aaSAndroid Build Coastguard Worker REG_FIDDLE(Canvas_drawImageRect, 256, 64, false, 0) {
draw(SkCanvas * canvas)5*c8dee2aaSAndroid Build Coastguard Worker void draw(SkCanvas* canvas) {
6*c8dee2aaSAndroid Build Coastguard Worker uint32_t pixels[][4] = {
7*c8dee2aaSAndroid Build Coastguard Worker { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 },
8*c8dee2aaSAndroid Build Coastguard Worker { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 },
9*c8dee2aaSAndroid Build Coastguard Worker { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 },
10*c8dee2aaSAndroid Build Coastguard Worker { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } };
11*c8dee2aaSAndroid Build Coastguard Worker SkBitmap redBorder;
12*c8dee2aaSAndroid Build Coastguard Worker redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4),
13*c8dee2aaSAndroid Build Coastguard Worker (void*) pixels, sizeof(pixels[0]));
14*c8dee2aaSAndroid Build Coastguard Worker sk_sp<SkImage> image = redBorder.asImage();
15*c8dee2aaSAndroid Build Coastguard Worker SkSamplingOptions sampling;
16*c8dee2aaSAndroid Build Coastguard Worker for (auto constraint : {
17*c8dee2aaSAndroid Build Coastguard Worker SkCanvas::kFast_SrcRectConstraint,
18*c8dee2aaSAndroid Build Coastguard Worker SkCanvas::kStrict_SrcRectConstraint,
19*c8dee2aaSAndroid Build Coastguard Worker SkCanvas::kFast_SrcRectConstraint } ) {
20*c8dee2aaSAndroid Build Coastguard Worker canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3),
21*c8dee2aaSAndroid Build Coastguard Worker SkRect::MakeLTRB(16, 16, 48, 48), sampling, nullptr, constraint);
22*c8dee2aaSAndroid Build Coastguard Worker sampling = SkSamplingOptions(SkFilterMode::kLinear);
23*c8dee2aaSAndroid Build Coastguard Worker canvas->translate(80, 0);
24*c8dee2aaSAndroid Build Coastguard Worker }
25*c8dee2aaSAndroid Build Coastguard Worker }
26*c8dee2aaSAndroid Build Coastguard Worker } // END FIDDLE
27