blob: 9ccba4943ad57f12f853c8c8fc47831629e0307f [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=85a76163138a2720ac003691d6363938
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Image_makeWithFilter, 256, 256, false, 5) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
Michael Ludwiga8611062019-08-01 16:38:24 -04007 sk_sp<SkImageFilter> shadowFilter = SkImageFilters::DropShadow(
8 -10.0f * frame, 5.0f * frame, 3.0f, 3.0f, SK_ColorBLUE, nullptr);
9 sk_sp<SkImageFilter> offsetFilter = SkImageFilters::Offset(40, 40, shadowFilter, nullptr);
Hal Canary87515122019-03-15 14:22:51 -040010 SkIRect subset = image->bounds();
11 SkIRect clipBounds = image->bounds();
12 clipBounds.outset(60, 60);
13 SkIRect outSubset;
14 SkIPoint offset;
Adlai Holler247835b2020-07-21 16:50:06 -040015 sk_sp<SkImage> filtered(image->makeWithFilter(canvas->recordingContext(), offsetFilter.get(),
16 subset, clipBounds, &outSubset, &offset));
Hal Canary87515122019-03-15 14:22:51 -040017 SkPaint paint;
18 paint.setAntiAlias(true);
19 paint.setStyle(SkPaint::kStroke_Style);
20 canvas->drawLine(0, 0, offset.fX, offset.fY, paint);
21 canvas->translate(offset.fX, offset.fY);
22 canvas->drawImage(filtered, 0, 0);
23 canvas->drawRect(SkRect::Make(outSubset), paint);
24}
25} // END FIDDLE