Coverage Report

Created: 2021-08-22 09:07

/src/skia/src/core/SkPictureCommon.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2015 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
#ifndef SkPictureCommon_DEFINED
9
#define SkPictureCommon_DEFINED
10
11
// Some shared code used by both SkBigPicture and SkMiniPicture.
12
//   SkTextHunter   -- SkRecord visitor that returns true when the op draws text.
13
//   SkPathCounter  -- SkRecord visitor that counts paths that draw slowly on the GPU.
14
15
#include "include/core/SkPathEffect.h"
16
#include "include/core/SkShader.h"
17
#include "include/private/SkTLogic.h"
18
#include "src/core/SkRecords.h"
19
20
// TODO: might be nicer to have operator() return an int (the number of slow paths) ?
21
struct SkPathCounter {
22
    // Some ops have a paint, some have an optional paint.  Either way, get back a pointer.
23
0
    static const SkPaint* AsPtr(const SkPaint& p) { return &p; }
24
0
    static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return p; }
25
26
0
    SkPathCounter() : fNumSlowPathsAndDashEffects(0) {}
27
28
0
    void checkPaint(const SkPaint* paint) {
29
0
        if (paint && paint->getPathEffect()) {
30
0
            // Initially assume it's slow.
31
0
            fNumSlowPathsAndDashEffects++;
32
0
        }
33
0
    }
34
35
0
    void operator()(const SkRecords::DrawPoints& op) {
36
0
        this->checkPaint(&op.paint);
37
0
        const SkPathEffect* effect = op.paint.getPathEffect();
38
0
        if (effect) {
39
0
            SkPathEffect::DashInfo info;
40
0
            SkPathEffect::DashType dashType = effect->asADash(&info);
41
0
            if (2 == op.count && SkPaint::kRound_Cap != op.paint.getStrokeCap() &&
42
0
                SkPathEffect::kDash_DashType == dashType && 2 == info.fCount) {
43
0
                fNumSlowPathsAndDashEffects--;
44
0
            }
45
0
        }
46
0
    }
47
48
0
    void operator()(const SkRecords::DrawPath& op) {
49
0
        this->checkPaint(&op.paint);
50
0
        if (op.paint.isAntiAlias() && !op.path.isConvex()) {
51
0
            SkPaint::Style paintStyle = op.paint.getStyle();
52
0
            const SkRect& pathBounds = op.path.getBounds();
53
0
            if (SkPaint::kStroke_Style == paintStyle &&
54
0
                0 == op.paint.getStrokeWidth()) {
55
0
                // AA hairline concave path is not slow.
56
0
            } else if (SkPaint::kFill_Style == paintStyle && pathBounds.width() < 64.f &&
57
0
                       pathBounds.height() < 64.f && !op.path.isVolatile()) {
58
0
                // AADF eligible concave path is not slow.
59
0
            } else {
60
0
                fNumSlowPathsAndDashEffects++;
61
0
            }
62
0
        }
63
0
    }
64
65
0
    void operator()(const SkRecords::ClipPath& op) {
66
0
        // TODO: does the SkRegion op matter?
67
0
        if (op.opAA.aa() && !op.path.isConvex()) {
68
0
            fNumSlowPathsAndDashEffects++;
69
0
        }
70
0
    }
71
72
0
    void operator()(const SkRecords::SaveLayer& op) {
73
0
        this->checkPaint(AsPtr(op.paint));
74
0
    }
75
76
    template <typename T>
77
    std::enable_if_t<T::kTags & SkRecords::kHasPaint_Tag, void> operator()(const T& op) {
78
        this->checkPaint(AsPtr(op.paint));
79
    }
80
81
    template <typename T>
82
    std::enable_if_t<!(T::kTags & SkRecords::kHasPaint_Tag), void>
83
      operator()(const T& op) { /* do nothing */ }
84
85
    int fNumSlowPathsAndDashEffects;
86
};
87
88
sk_sp<SkImage> ImageDeserializer_SkDeserialImageProc(const void*, size_t, void* imagedeserializer);
89
90
bool SkPicture_StreamIsSKP(SkStream*, SkPictInfo*);
91
92
#endif  // SkPictureCommon_DEFINED