blob: e6c90e5f2db8a1a7632cd015b16f3be6e749ded8 [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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 Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=bfd18e9cac896cdf94c9f154ccf94be8
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Canvas_drawImageRect, 256, 64, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void 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 Reeddc607e32020-12-23 11:50:36 -050015 sk_sp<SkImage> image = redBorder.asImage();
Mike Reedb339d052021-01-28 11:20:41 -050016 SkSamplingOptions sampling;
Hal Canary87515122019-03-15 14:22:51 -040017 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 Reedb339d052021-01-28 11:20:41 -050022 SkRect::MakeLTRB(16, 16, 48, 48), sampling, nullptr, constraint);
23 sampling = SkSamplingOptions(SkFilterMode::kLinear);
Hal Canary87515122019-03-15 14:22:51 -040024 canvas->translate(80, 0);
25 }
26}
27} // END FIDDLE