Coverage Report

Created: 2024-09-14 07:19

/src/skia/modules/sksg/src/SkSGDraw.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2017 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 "include/core/SkCanvas.h"
9
#include "include/core/SkPaint.h"
10
#include "include/core/SkPath.h"
11
#include "include/core/SkPathUtils.h"
12
#include "include/core/SkPoint.h"
13
#include "include/private/base/SkAssert.h"
14
#include "modules/sksg/include/SkSGDraw.h"
15
#include "modules/sksg/include/SkSGGeometryNode.h"
16
#include "modules/sksg/include/SkSGNode.h"
17
#include "modules/sksg/include/SkSGPaint.h"
18
19
class SkMatrix;
20
21
namespace sksg {
22
23
Draw::Draw(sk_sp<GeometryNode> geometry, sk_sp<PaintNode> paint)
24
    : fGeometry(std::move(geometry))
25
199k
    , fPaint(std::move(paint)) {
26
199k
    this->observeInval(fGeometry);
27
199k
    this->observeInval(fPaint);
28
199k
}
29
30
199k
Draw::~Draw() {
31
199k
    this->unobserveInval(fGeometry);
32
199k
    this->unobserveInval(fPaint);
33
199k
}
34
35
52.1k
void Draw::onRender(SkCanvas* canvas, const RenderContext* ctx) const {
36
52.1k
    auto paint = fPaint->makePaint();
37
52.1k
    if (ctx) {
38
30.5k
        ctx->modulatePaint(canvas->getTotalMatrix(), &paint);
39
30.5k
    }
40
41
52.1k
    const auto skipDraw = paint.nothingToDraw() ||
42
52.1k
            (paint.getStyle() == SkPaint::kStroke_Style && paint.getStrokeWidth() <= 0);
43
44
52.1k
    if (!skipDraw) {
45
51.5k
        fGeometry->draw(canvas, paint);
46
51.5k
    }
47
52.1k
}
48
49
0
const RenderNode* Draw::onNodeAt(const SkPoint& p) const {
50
0
    const auto paint = fPaint->makePaint();
51
52
0
    if (!paint.getAlpha()) {
53
0
        return nullptr;
54
0
    }
55
56
0
    if (paint.getStyle() == SkPaint::Style::kFill_Style && fGeometry->contains(p)) {
57
0
        return this;
58
0
    }
59
60
0
    SkPath stroke_path;
61
0
    if (!skpathutils::FillPathWithPaint(fGeometry->asPath(), paint, &stroke_path)) {
62
0
        return nullptr;
63
0
    }
64
65
0
    return stroke_path.contains(p.x(), p.y()) ? this : nullptr;
66
0
}
67
68
185k
SkRect Draw::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
69
185k
    SkASSERT(this->hasInval());
70
71
185k
    auto bounds = fGeometry->revalidate(ic, ctm);
72
185k
    fPaint->revalidate(ic, ctm);
73
74
185k
    const auto paint = fPaint->makePaint();
75
185k
    SkASSERT(paint.canComputeFastBounds());
76
77
185k
    return paint.computeFastBounds(bounds, &bounds);
78
185k
}
79
80
} // namespace sksg