Flutter Engine
The Flutter Engine
SkSGImage.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
15
16namespace sksg {
17
19
20void Image::onRender(SkCanvas* canvas, const RenderContext* ctx) const {
21 if (!fImage) {
22 return;
23 }
24
26 paint.setAntiAlias(fAntiAlias);
27
28 sksg::RenderNode::ScopedRenderContext local_ctx(canvas, ctx);
29 if (ctx) {
30 if (ctx->fMaskShader) {
31 // Mask shaders cannot be applied via drawImage - we need layer isolation.
32 // TODO: remove after clipShader conversion.
33 local_ctx.setIsolation(this->bounds(), canvas->getTotalMatrix(), true);
34 }
35 local_ctx->modulatePaint(canvas->getTotalMatrix(), &paint);
36 }
37
38 canvas->drawImage(fImage, 0, 0, fSamplingOptions, &paint);
39}
40
41const RenderNode* Image::onNodeAt(const SkPoint& p) const {
42 SkASSERT(this->bounds().contains(p.x(), p.y()));
43 return this;
44}
45
47 return fImage ? SkRect::Make(fImage->bounds()) : SkRect::MakeEmpty();
48}
49
50} // namespace sksg
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkMatrix getTotalMatrix() const
Definition: SkCanvas.cpp:1629
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
SkIRect bounds() const
Definition: SkImage.h:303
const RenderNode * onNodeAt(const SkPoint &) const override
Definition: SkSGImage.cpp:41
void onRender(SkCanvas *, const RenderContext *) const override
Definition: SkSGImage.cpp:20
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Definition: SkSGImage.cpp:46
Image(sk_sp< SkImage >)
Definition: SkSGImage.cpp:18
const SkRect & bounds() const
Definition: SkSGNode.h:55
ScopedRenderContext && setIsolation(const SkRect &bounds, const SkMatrix &ctm, bool do_isolate)
const Paint & paint
Definition: color_source.cc:38
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Definition: Skottie.h:32
constexpr bool contains(std::string_view str, std::string_view needle)
Definition: SkStringView.h:41
Definition: ref_ptr.h:256
constexpr float x() const
Definition: SkPoint_impl.h:181
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595
void modulatePaint(const SkMatrix &ctm, SkPaint *, bool is_layer_paint=false) const