Coverage Report

Created: 2021-08-22 09:07

/src/skia/src/gpu/ops/GrMeshDrawOp.cpp
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
#include "src/gpu/ops/GrMeshDrawOp.h"
9
10
#include "src/gpu/GrOpFlushState.h"
11
#include "src/gpu/GrOpsRenderPass.h"
12
#include "src/gpu/GrRecordingContextPriv.h"
13
#include "src/gpu/GrResourceProvider.h"
14
15
155k
GrMeshDrawOp::GrMeshDrawOp(uint32_t classID) : INHERITED(classID) {}
16
17
117k
void GrMeshDrawOp::onPrepare(GrOpFlushState* state) { this->onPrepareDraws(state); }
18
19
115k
void GrMeshDrawOp::createProgramInfo(GrMeshDrawTarget* target) {
20
115k
    this->createProgramInfo(&target->caps(),
21
115k
                            target->allocator(),
22
115k
                            target->writeView(),
23
115k
                            target->usesMSAASurface(),
24
115k
                            target->detachAppliedClip(),
25
115k
                            target->dstProxyView(),
26
115k
                            target->renderPassBarriers(),
27
115k
                            target->colorLoadOp());
28
115k
}
29
30
bool GrMeshDrawOp::CombinedQuadCountWillOverflow(GrAAType aaType,
31
                                                 bool willBeUpgradedToAA,
32
66.3k
                                                 int combinedQuadCount) {
33
66.3k
    bool willBeAA = (aaType == GrAAType::kCoverage) || willBeUpgradedToAA;
34
35
752
    return combinedQuadCount > (willBeAA ? GrResourceProvider::MaxNumAAQuads()
36
65.6k
                                         : GrResourceProvider::MaxNumNonAAQuads());
37
66.3k
}
38
39
// This onPrepareDraws implementation assumes the derived Op only has a single programInfo -
40
// which is the majority of the cases.
41
void GrMeshDrawOp::onPrePrepareDraws(GrRecordingContext* context,
42
                                     const GrSurfaceProxyView& writeView,
43
                                     GrAppliedClip* clip,
44
                                     const GrDstProxyView& dstProxyView,
45
                                     GrXferBarrierFlags renderPassXferBarriers,
46
0
                                     GrLoadOp colorLoadOp) {
47
0
    SkArenaAlloc* arena = context->priv().recordTimeAllocator();
48
49
    // http://skbug.com/12201 -- DDL does not yet support DMSAA.
50
0
    bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1;
51
52
    // This is equivalent to a GrOpFlushState::detachAppliedClip
53
0
    GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip::Disabled();
54
55
0
    this->createProgramInfo(context->priv().caps(), arena, writeView, usesMSAASurface,
56
0
                            std::move(appliedClip), dstProxyView, renderPassXferBarriers,
57
0
                            colorLoadOp);
58
59
    // TODO: at this point we've created both the program info and desc in the recording context's
60
    // arena. In the DDL case, it would be cool if 'recordProgramInfo' could return the
61
    // pre-existing versions if the program has already been seen. We could then return the
62
    // memory for the current copy to the arena.
63
0
    context->priv().recordProgramInfo(this->programInfo());
64
0
}
65
66
//////////////////////////////////////////////////////////////////////////////
67
68
GrMeshDrawOp::PatternHelper::PatternHelper(GrMeshDrawTarget* target, GrPrimitiveType primitiveType,
69
                                           size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
70
                                           int verticesPerRepetition, int indicesPerRepetition,
71
2.49k
                                           int repeatCount, int maxRepetitions) {
72
2.49k
    this->init(target, primitiveType, vertexStride, std::move(indexBuffer), verticesPerRepetition,
73
2.49k
               indicesPerRepetition, repeatCount, maxRepetitions);
74
2.49k
}
75
76
void GrMeshDrawOp::PatternHelper::init(GrMeshDrawTarget* target, GrPrimitiveType primitiveType,
77
                                       size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
78
                                       int verticesPerRepetition, int indicesPerRepetition,
79
2.50k
                                       int repeatCount, int maxRepetitions) {
80
2.50k
    SkASSERT(target);
81
2.50k
    if (!indexBuffer) {
82
0
        return;
83
0
    }
84
2.50k
    sk_sp<const GrBuffer> vertexBuffer;
85
2.50k
    int firstVertex;
86
2.50k
    int vertexCount = verticesPerRepetition * repeatCount;
87
2.50k
    fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex);
88
2.50k
    if (!fVertices) {
89
0
        SkDebugf("Vertices could not be allocated for patterned rendering.");
90
0
        return;
91
0
    }
92
2.50k
    SkASSERT(vertexBuffer);
93
2.50k
    fMesh = target->allocMesh();
94
2.50k
    fPrimitiveType = primitiveType;
95
96
2.50k
    SkASSERT(maxRepetitions ==
97
2.50k
             static_cast<int>(indexBuffer->size() / (sizeof(uint16_t) * indicesPerRepetition)));
98
2.50k
    fMesh->setIndexedPatterned(std::move(indexBuffer), indicesPerRepetition, repeatCount,
99
2.50k
                               maxRepetitions, std::move(vertexBuffer), verticesPerRepetition,
100
2.50k
                               firstVertex);
101
2.50k
}
102
103
void GrMeshDrawOp::PatternHelper::recordDraw(GrMeshDrawTarget* target,
104
0
                                             const GrGeometryProcessor* gp) const {
105
0
    target->recordDraw(gp, fMesh, 1, fPrimitiveType);
106
0
}
107
108
void GrMeshDrawOp::PatternHelper::recordDraw(
109
        GrMeshDrawTarget* target,
110
        const GrGeometryProcessor* gp,
111
0
        const GrSurfaceProxy* const primProcProxies[]) const {
112
0
    target->recordDraw(gp, fMesh, 1, primProcProxies, fPrimitiveType);
113
0
}
114
115
//////////////////////////////////////////////////////////////////////////////
116
117
GrMeshDrawOp::QuadHelper::QuadHelper(GrMeshDrawTarget* target,
118
                                     size_t vertexStride,
119
6
                                     int quadsToDraw) {
120
6
    sk_sp<const GrGpuBuffer> indexBuffer = target->resourceProvider()->refNonAAQuadIndexBuffer();
121
6
    if (!indexBuffer) {
122
0
        SkDebugf("Could not get quad index buffer.");
123
0
        return;
124
0
    }
125
6
    this->init(target, GrPrimitiveType::kTriangles, vertexStride, std::move(indexBuffer),
126
6
               GrResourceProvider::NumVertsPerNonAAQuad(),
127
6
               GrResourceProvider::NumIndicesPerNonAAQuad(), quadsToDraw,
128
6
               GrResourceProvider::MaxNumNonAAQuads());
129
6
}