Coverage Report

Created: 2024-05-20 07:14

/src/skia/src/gpu/ganesh/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/ganesh/ops/GrMeshDrawOp.h"
9
10
#include "src/gpu/ganesh/GrOpFlushState.h"
11
#include "src/gpu/ganesh/GrOpsRenderPass.h"
12
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
13
#include "src/gpu/ganesh/GrResourceProvider.h"
14
15
165k
GrMeshDrawOp::GrMeshDrawOp(uint32_t classID) : INHERITED(classID) {}
16
17
116k
void GrMeshDrawOp::onPrepare(GrOpFlushState* state) { this->onPrepareDraws(state); }
18
19
114k
void GrMeshDrawOp::createProgramInfo(GrMeshDrawTarget* target) {
20
114k
    this->createProgramInfo(&target->caps(),
21
114k
                            target->allocator(),
22
114k
                            target->writeView(),
23
114k
                            target->usesMSAASurface(),
24
114k
                            target->detachAppliedClip(),
25
114k
                            target->dstProxyView(),
26
114k
                            target->renderPassBarriers(),
27
114k
                            target->colorLoadOp());
28
114k
}
29
30
bool GrMeshDrawOp::CombinedQuadCountWillOverflow(GrAAType aaType,
31
                                                 bool willBeUpgradedToAA,
32
68.7k
                                                 int combinedQuadCount) {
33
68.7k
    bool willBeAA = (aaType == GrAAType::kCoverage) || willBeUpgradedToAA;
34
35
68.7k
    return combinedQuadCount > (willBeAA ? GrResourceProvider::MaxNumAAQuads()
36
68.7k
                                         : GrResourceProvider::MaxNumNonAAQuads());
37
68.7k
}
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
3.91k
                                           int repeatCount, int maxRepetitions) {
72
3.91k
    this->init(target, primitiveType, vertexStride, std::move(indexBuffer), verticesPerRepetition,
73
3.91k
               indicesPerRepetition, repeatCount, maxRepetitions);
74
3.91k
}
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
3.91k
                                       int repeatCount, int maxRepetitions) {
80
3.91k
    SkASSERT(target);
81
3.91k
    if (!indexBuffer) {
82
0
        return;
83
0
    }
84
3.91k
    sk_sp<const GrBuffer> vertexBuffer;
85
3.91k
    int firstVertex;
86
3.91k
    int vertexCount = verticesPerRepetition * repeatCount;
87
3.91k
    fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex);
88
3.91k
    if (!fVertices) {
89
0
        SkDebugf("Vertices could not be allocated for patterned rendering.");
90
0
        return;
91
0
    }
92
3.91k
    SkASSERT(vertexBuffer);
93
3.91k
    fMesh = target->allocMesh();
94
3.91k
    fPrimitiveType = primitiveType;
95
96
3.91k
    SkASSERT(maxRepetitions ==
97
3.91k
             static_cast<int>(indexBuffer->size() / (sizeof(uint16_t) * indicesPerRepetition)));
98
3.91k
    fMesh->setIndexedPatterned(std::move(indexBuffer), indicesPerRepetition, repeatCount,
99
3.91k
                               maxRepetitions, std::move(vertexBuffer), verticesPerRepetition,
100
3.91k
                               firstVertex);
101
3.91k
}
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
5
                                     int quadsToDraw) {
120
5
    sk_sp<const GrGpuBuffer> indexBuffer = target->resourceProvider()->refNonAAQuadIndexBuffer();
121
5
    if (!indexBuffer) {
122
0
        SkDebugf("Could not get quad index buffer.");
123
0
        return;
124
0
    }
125
5
    this->init(target, GrPrimitiveType::kTriangles, vertexStride, std::move(indexBuffer),
126
5
               GrResourceProvider::NumVertsPerNonAAQuad(),
127
5
               GrResourceProvider::NumIndicesPerNonAAQuad(), quadsToDraw,
128
5
               GrResourceProvider::MaxNumNonAAQuads());
129
5
}