• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/GrTextBlobCache.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(DrawVerticesOp);
55 DRAW_OP_TEST_EXTERN(DIEllipseOp);
56 DRAW_OP_TEST_EXTERN(EllipseOp);
57 DRAW_OP_TEST_EXTERN(FillRectOp);
58 DRAW_OP_TEST_EXTERN(NonAALatticeOp);
59 DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
60 DRAW_OP_TEST_EXTERN(RegionOp);
61 DRAW_OP_TEST_EXTERN(RRectOp);
62 DRAW_OP_TEST_EXTERN(ShadowRRectOp);
63 DRAW_OP_TEST_EXTERN(SmallPathOp);
64 DRAW_OP_TEST_EXTERN(TextureOpImpl);
65 DRAW_OP_TEST_EXTERN(TriangulatingPathOp);
66 
GrDrawRandomOp(SkRandom * random,skgpu::v1::SurfaceDrawContext * sdc,GrPaint && paint)67 void GrDrawRandomOp(SkRandom* random, skgpu::v1::SurfaceDrawContext* sdc, GrPaint&& paint) {
68     auto rContext = sdc->recordingContext();
69     using MakeDrawOpFn = GrOp::Owner (GrPaint&&,
70                                       SkRandom*,
71                                       GrRecordingContext*,
72                                       skgpu::v1::SurfaceDrawContext*,
73                                       int numSamples);
74     static constexpr MakeDrawOpFn* gFactories[] = {
75             DRAW_OP_TEST_ENTRY(AAConvexPathOp),
76             DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
77             DRAW_OP_TEST_ENTRY(AAHairlineOp),
78             DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
79             DRAW_OP_TEST_ENTRY(AtlasTextOp),
80             DRAW_OP_TEST_ENTRY(ButtCapDashedCircleOp),
81             DRAW_OP_TEST_ENTRY(CircleOp),
82             DRAW_OP_TEST_ENTRY(DashOpImpl),
83             DRAW_OP_TEST_ENTRY(DefaultPathOp),
84             DRAW_OP_TEST_ENTRY(DrawAtlasOp),
85             DRAW_OP_TEST_ENTRY(DrawVerticesOp),
86             DRAW_OP_TEST_ENTRY(DIEllipseOp),
87             DRAW_OP_TEST_ENTRY(EllipseOp),
88             DRAW_OP_TEST_ENTRY(FillRectOp),
89             DRAW_OP_TEST_ENTRY(NonAALatticeOp),
90             DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
91             DRAW_OP_TEST_ENTRY(RegionOp),
92             DRAW_OP_TEST_ENTRY(RRectOp),
93             DRAW_OP_TEST_ENTRY(ShadowRRectOp),
94             DRAW_OP_TEST_ENTRY(SmallPathOp),
95             DRAW_OP_TEST_ENTRY(TextureOpImpl),
96             DRAW_OP_TEST_ENTRY(TriangulatingPathOp),
97     };
98 
99     static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
100     uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
101     auto op = gFactories[index](std::move(paint),
102                                 random,
103                                 rContext,
104                                 sdc,
105                                 sdc->numSamples());
106 
107     // Creating a GrAtlasTextOp my not produce an op if for example, it is totally outside the
108     // render target context.
109     if (op) {
110         sdc->addDrawOp(std::move(op));
111     }
112 }
113