Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
static bool contains(const SkRect &r, SkPoint p)
SkMatrix getTotalMatrix() const
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
sk_sp< SkImage > image
Definition examples.cpp:29
Definition Skottie.h:32
Definition ref_ptr.h:256
constexpr float x() const
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