/src/skia/modules/sksg/src/SkSGImage.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
8 | | #include "modules/sksg/include/SkSGImage.h" |
9 | | |
10 | | #include "include/core/SkCanvas.h" |
11 | | #include "include/core/SkImage.h" |
12 | | #include "src/core/SkPaintPriv.h" |
13 | | |
14 | | namespace sksg { |
15 | | |
16 | 0 | Image::Image(sk_sp<SkImage> image) : fImage(std::move(image)) {} |
17 | | |
18 | 0 | void Image::onRender(SkCanvas* canvas, const RenderContext* ctx) const { |
19 | 0 | if (!fImage) { |
20 | 0 | return; |
21 | 0 | } |
22 | | |
23 | 0 | SkPaint paint; |
24 | 0 | paint.setAntiAlias(fAntiAlias); |
25 | |
|
26 | 0 | sksg::RenderNode::ScopedRenderContext local_ctx(canvas, ctx); |
27 | 0 | if (ctx) { |
28 | 0 | if (ctx->fMaskShader) { |
29 | | // Mask shaders cannot be applied via drawImage - we need layer isolation. |
30 | | // TODO: remove after clipShader conversion. |
31 | 0 | local_ctx.setIsolation(this->bounds(), canvas->getTotalMatrix(), true); |
32 | 0 | } |
33 | 0 | local_ctx->modulatePaint(canvas->getTotalMatrix(), &paint); |
34 | 0 | } |
35 | |
|
36 | 0 | canvas->drawImage(fImage, 0, 0, fSamplingOptions, &paint); |
37 | 0 | } |
38 | | |
39 | 0 | const RenderNode* Image::onNodeAt(const SkPoint& p) const { |
40 | 0 | SkASSERT(this->bounds().contains(p.x(), p.y())); |
41 | 0 | return this; |
42 | 0 | } |
43 | | |
44 | 0 | SkRect Image::onRevalidate(InvalidationController*, const SkMatrix& ctm) { |
45 | 0 | return fImage ? SkRect::Make(fImage->bounds()) : SkRect::MakeEmpty(); |
46 | 0 | } |
47 | | |
48 | | } // namespace sksg |