Flutter Engine
The Flutter Engine
Image_makeWithFilter.cpp
Go to the documentation of this file.
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.
4REG_FIDDLE(Image_makeWithFilter, 256, 256, false, 5) {
5void draw(SkCanvas* canvas) {
7 -10.0f * frame, 5.0f * frame, 3.0f, 3.0f, SK_ColorBLUE, nullptr);
8 sk_sp<SkImageFilter> offsetFilter = SkImageFilters::Offset(40, 40, shadowFilter, nullptr);
9 SkIRect subset = image->bounds();
10 SkIRect clipBounds = image->bounds();
11 clipBounds.outset(60, 60);
12 SkIRect outSubset;
15
16 if (auto rContext = canvas->recordingContext()) {
17 filtered = SkImages::MakeWithFilter(rContext, image, offsetFilter.get(),
18 subset, clipBounds, &outSubset, &offset);
19 } else {
21 subset, clipBounds, &outSubset, &offset);
22 }
23
25 paint.setAntiAlias(true);
27 canvas->drawLine(0, 0, offset.fX, offset.fY, paint);
28 canvas->translate(offset.fX, offset.fY);
29 canvas->drawImage(filtered, 0, 0);
30 canvas->drawRect(SkRect::Make(outSubset), paint);
31}
32} // END FIDDLE
REG_FIDDLE(Image_makeWithFilter, 256, 256, false, 5)
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkImageFilter > DropShadow(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, SkColor color, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Offset(SkScalar dx, SkScalar dy, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
SkIRect bounds() const
Definition: SkImage.h:303
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
double frame
Definition: examples.cpp:31
SK_API sk_sp< SkImage > MakeWithFilter(sk_sp< SkImage > src, const SkImageFilter *filter, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
def filtered(names, to_skip)
Definition: zip_utils.py:20
SeparatedVector2 offset
Definition: SkRect.h:32
void outset(int32_t dx, int32_t dy)
Definition: SkRect.h:428
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669