Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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
13#include "src/base/SkMathPriv.h"
14#include "src/base/SkRandom.h"
27#include "src/gpu/ganesh/SkGr.h"
32
33#include <algorithm>
34
35//////////////////////////////////////////////////////////////////////////////
36
37#define DRAW_OP_TEST_EXTERN(Op) \
38 extern GrOp::Owner Op##__Test( \
39 GrPaint&&, SkRandom*, GrRecordingContext*, skgpu::ganesh::SurfaceDrawContext*, int)
40#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
41
42DRAW_OP_TEST_EXTERN(AAConvexPathOp);
43DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
44DRAW_OP_TEST_EXTERN(AAHairlineOp);
45DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
47#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
50#endif
52DRAW_OP_TEST_EXTERN(DefaultPathOp);
54#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
57#endif
59DRAW_OP_TEST_EXTERN(NonAALatticeOp);
60DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
62#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
64#endif
65DRAW_OP_TEST_EXTERN(ShadowRRectOp);
66#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
68#endif
69DRAW_OP_TEST_EXTERN(TextureOpImpl);
70#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
71DRAW_OP_TEST_EXTERN(TriangulatingPathOp);
72#endif
73
75 auto rContext = sdc->recordingContext();
76 using MakeDrawOpFn = GrOp::Owner(GrPaint&&,
77 SkRandom*,
80 int numSamples);
81 static constexpr MakeDrawOpFn* gFactories[] = {
82 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
83 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
84 DRAW_OP_TEST_ENTRY(AAHairlineOp),
85 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
86 DRAW_OP_TEST_ENTRY(AtlasTextOp),
87#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
90#endif
91 DRAW_OP_TEST_ENTRY(DashOpImpl),
92 DRAW_OP_TEST_ENTRY(DefaultPathOp),
93 DRAW_OP_TEST_ENTRY(DrawAtlasOp),
94#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
97#endif
98 DRAW_OP_TEST_ENTRY(FillRectOp),
99 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
100 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
101 DRAW_OP_TEST_ENTRY(RegionOp),
102#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
103 DRAW_OP_TEST_ENTRY(RRectOp),
104#endif
105 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
106#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
107 DRAW_OP_TEST_ENTRY(SmallPathOp),
108#endif
109 DRAW_OP_TEST_ENTRY(TextureOpImpl),
110#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
111 DRAW_OP_TEST_ENTRY(TriangulatingPathOp),
112#endif
113 };
114
115 static constexpr size_t kTotal = std::size(gFactories);
116 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
117 auto op = gFactories[index](std::move(paint),
118 random,
119 rContext,
120 sdc,
121 sdc->numSamples());
122
123 // Creating a GrAtlasTextOp my not produce an op if for example, it is totally outside the
124 // render target context.
125 if (op) {
126 sdc->addDrawOp(std::move(op));
127 }
128}
#define DRAW_OP_TEST_EXTERN(Op)
Definition GrTest.cpp:37
#define DRAW_OP_TEST_ENTRY(Op)
Definition GrTest.cpp:40
void GrDrawRandomOp(SkRandom *random, skgpu::ganesh::SurfaceDrawContext *sdc, GrPaint &&paint)
Definition GrTest.cpp:74
std::unique_ptr< GrOp > Owner
Definition GrOp.h:72
uint32_t nextULessThan(uint32_t count)
Definition SkRandom.h:93
GrRecordingContext * recordingContext() const
void addDrawOp(const GrClip *, GrOp::Owner, const std::function< WillAddOpFn > &=std::function< WillAddOpFn >())
const Paint & paint