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
8 #include "include/core/SkString.h"
9 #include "include/gpu/GrBackendSurface.h"
10 #include "include/gpu/GrContextOptions.h"
11 #include "include/gpu/GrRecordingContext.h"
12 #include "include/private/SkTo.h"
13 #include "src/core/SkMathPriv.h"
14 #include "src/gpu/GrClip.h"
15 #include "src/gpu/GrDirectContextPriv.h"
16 #include "src/gpu/GrDrawOpAtlas.h"
17 #include "src/gpu/GrDrawingManager.h"
18 #include "src/gpu/GrGpu.h"
19 #include "src/gpu/GrGpuResourceCacheAccess.h"
20 #include "src/gpu/GrMemoryPool.h"
21 #include "src/gpu/GrRecordingContextPriv.h"
22 #include "src/gpu/GrRenderTargetProxy.h"
23 #include "src/gpu/GrResourceCache.h"
24 #include "src/gpu/GrSemaphore.h"
25 #include "src/gpu/GrTexture.h"
26 #include "src/gpu/SkGr.h"
27 #include "src/gpu/text/GrStrikeCache.h"
28 #include "src/gpu/text/GrTextBlobRedrawCoordinator.h"
29 #include "src/gpu/v1/SurfaceDrawContext_v1.h"
30 #include "src/image/SkImage_Gpu.h"
31
32 #include <algorithm>
33
34 //////////////////////////////////////////////////////////////////////////////
35
36 #define DRAW_OP_TEST_EXTERN(Op) \
37 extern GrOp::Owner Op##__Test(GrPaint&&, \
38 SkRandom*, \
39 GrRecordingContext*, \
40 skgpu::v1::SurfaceDrawContext*, \
41 int)
42 #define DRAW_OP_TEST_ENTRY(Op) Op##__Test
43
44 DRAW_OP_TEST_EXTERN(AAConvexPathOp);
45 DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
46 DRAW_OP_TEST_EXTERN(AAHairlineOp);
47 DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
48 DRAW_OP_TEST_EXTERN(AtlasTextOp);
49 DRAW_OP_TEST_EXTERN(ButtCapDashedCircleOp);
50 DRAW_OP_TEST_EXTERN(CircleOp);
51 DRAW_OP_TEST_EXTERN(DashOpImpl);
52 DRAW_OP_TEST_EXTERN(DefaultPathOp);
53 DRAW_OP_TEST_EXTERN(DrawAtlasOp);
54 DRAW_OP_TEST_EXTERN(DIEllipseOp);
55 DRAW_OP_TEST_EXTERN(EllipseOp);
56 DRAW_OP_TEST_EXTERN(FillRectOp);
57 DRAW_OP_TEST_EXTERN(NonAALatticeOp);
58 DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
59 DRAW_OP_TEST_EXTERN(RegionOp);
60 DRAW_OP_TEST_EXTERN(RRectOp);
61 DRAW_OP_TEST_EXTERN(ShadowRRectOp);
62 DRAW_OP_TEST_EXTERN(SmallPathOp);
63 DRAW_OP_TEST_EXTERN(TextureOpImpl);
64 DRAW_OP_TEST_EXTERN(TriangulatingPathOp);
65
GrDrawRandomOp(SkRandom * random,skgpu::v1::SurfaceDrawContext * sdc,GrPaint && paint)66 void GrDrawRandomOp(SkRandom* random, skgpu::v1::SurfaceDrawContext* sdc, GrPaint&& paint) {
67 auto rContext = sdc->recordingContext();
68 using MakeDrawOpFn = GrOp::Owner (GrPaint&&,
69 SkRandom*,
70 GrRecordingContext*,
71 skgpu::v1::SurfaceDrawContext*,
72 int numSamples);
73 static constexpr MakeDrawOpFn* gFactories[] = {
74 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
75 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
76 DRAW_OP_TEST_ENTRY(AAHairlineOp),
77 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
78 DRAW_OP_TEST_ENTRY(AtlasTextOp),
79 DRAW_OP_TEST_ENTRY(ButtCapDashedCircleOp),
80 DRAW_OP_TEST_ENTRY(CircleOp),
81 DRAW_OP_TEST_ENTRY(DashOpImpl),
82 DRAW_OP_TEST_ENTRY(DefaultPathOp),
83 DRAW_OP_TEST_ENTRY(DrawAtlasOp),
84 DRAW_OP_TEST_ENTRY(DIEllipseOp),
85 DRAW_OP_TEST_ENTRY(EllipseOp),
86 DRAW_OP_TEST_ENTRY(FillRectOp),
87 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
88 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
89 DRAW_OP_TEST_ENTRY(RegionOp),
90 DRAW_OP_TEST_ENTRY(RRectOp),
91 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
92 DRAW_OP_TEST_ENTRY(SmallPathOp),
93 DRAW_OP_TEST_ENTRY(TextureOpImpl),
94 DRAW_OP_TEST_ENTRY(TriangulatingPathOp),
95 };
96
97 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
98 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
99 auto op = gFactories[index](std::move(paint),
100 random,
101 rContext,
102 sdc,
103 sdc->numSamples());
104
105 // Creating a GrAtlasTextOp my not produce an op if for example, it is totally outside the
106 // render target context.
107 if (op) {
108 sdc->addDrawOp(std::move(op));
109 }
110 }
111