blob: ac03100d1a56a093dab784d4b33340506091c27e [file] [log] [blame]
commit-bot@chromium.org78a10782013-08-21 19:27:48 +00001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkString.h"
9#include "include/gpu/GrBackendSurface.h"
10#include "include/gpu/GrContextOptions.h"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040011#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/private/SkTo.h"
13#include "src/core/SkMathPriv.h"
14#include "src/gpu/GrClip.h"
Adlai Hollera0693042020-10-14 11:23:11 -040015#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#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"
Greg Danielf91aeb22019-06-18 09:58:02 -040022#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/GrResourceCache.h"
24#include "src/gpu/GrSemaphore.h"
Brian Salomoneebe7352020-12-09 16:37:04 -050025#include "src/gpu/GrSurfaceDrawContext.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000026#include "src/gpu/GrTexture.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/gpu/SkGr.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050028#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
29#include "src/gpu/ops/GrMeshDrawOp.h"
30#include "src/gpu/text/GrStrikeCache.h"
31#include "src/gpu/text/GrTextBlobCache.h"
32#include "src/image/SkImage_Gpu.h"
Hal Canary8a001442018-09-19 11:31:27 -040033
Hal Canaryc640d0d2018-06-13 09:59:02 -040034#include <algorithm>
joshualitte8042922015-12-11 06:11:21 -080035
bsalomonddf30e62015-02-19 11:38:44 -080036///////////////////////////////////////////////////////////////////////////////
37
38void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -080039
Brian Salomon1090da62017-01-06 12:04:19 -050040#ifdef SK_DEBUG
41int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
42 int count = 0;
Mike Kleincff63962020-03-14 16:22:45 -050043 fUniqueHash.foreach([&](const GrGpuResource& resource){
44 if (0 == strcmp(tag, resource.getUniqueKey().tag())) {
Brian Salomon1090da62017-01-06 12:04:19 -050045 ++count;
46 }
Mike Kleincff63962020-03-14 16:22:45 -050047 });
Brian Salomon1090da62017-01-06 12:04:19 -050048 return count;
49}
50#endif
51
Brian Salomon17726632017-05-12 14:09:46 -040052//////////////////////////////////////////////////////////////////////////////
53
Brian Salomon17726632017-05-12 14:09:46 -040054#define DRAW_OP_TEST_EXTERN(Op) \
Herb Derbyc76d4092020-10-07 16:46:15 -040055 extern GrOp::Owner Op##__Test(GrPaint&&, SkRandom*, \
Herb Derby0b1228d2021-04-05 18:38:35 -040056 GrRecordingContext*, GrSurfaceDrawContext*, int)
Brian Salomon17726632017-05-12 14:09:46 -040057#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
58
Brian Salomon10978a62017-06-15 16:21:49 -040059DRAW_OP_TEST_EXTERN(AAConvexPathOp);
Brian Salomonb2955732017-07-13 16:42:55 -040060DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
Brian Salomona531f252017-07-07 13:29:28 -040061DRAW_OP_TEST_EXTERN(AAHairlineOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -040062DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
Brian Salomon815486c2017-07-11 08:52:13 -040063DRAW_OP_TEST_EXTERN(CircleOp);
Brian Salomon98222ac2017-07-12 15:27:54 -040064DRAW_OP_TEST_EXTERN(DashOp);
Brian Salomonee3e0ba2017-07-13 16:40:46 -040065DRAW_OP_TEST_EXTERN(DefaultPathOp);
Brian Salomon05441c42017-05-15 16:45:49 -040066DRAW_OP_TEST_EXTERN(DIEllipseOp);
67DRAW_OP_TEST_EXTERN(EllipseOp);
Michael Ludwig69858532018-11-28 15:34:34 -050068DRAW_OP_TEST_EXTERN(FillRectOp);
Brian Salomon44acb5b2017-07-18 19:59:24 -040069DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
Brian Osman4d92b892019-03-24 00:53:23 +000070DRAW_OP_TEST_EXTERN(DrawAtlasOp);
Robert Phillipsb6e9d3c2019-02-11 14:29:34 -050071DRAW_OP_TEST_EXTERN(DrawVerticesOp);
Brian Salomon815486c2017-07-11 08:52:13 -040072DRAW_OP_TEST_EXTERN(NonAALatticeOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -040073DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
Brian Salomon05969092017-07-13 11:20:51 -040074DRAW_OP_TEST_EXTERN(ShadowRRectOp);
Brian Salomonfebbd232017-07-11 15:52:02 -040075DRAW_OP_TEST_EXTERN(SmallPathOp);
Brian Salomonf0366322017-07-11 15:53:05 -040076DRAW_OP_TEST_EXTERN(RegionOp);
Brian Salomon05441c42017-05-15 16:45:49 -040077DRAW_OP_TEST_EXTERN(RRectOp);
Chris Dalton17dc4182020-03-25 16:18:16 -060078DRAW_OP_TEST_EXTERN(TriangulatingPathOp);
Brian Salomon34169692017-08-28 15:32:01 -040079DRAW_OP_TEST_EXTERN(TextureOp);
Brian Salomon17726632017-05-12 14:09:46 -040080
Brian Salomon1aa1f5f2020-12-11 17:25:17 -050081void GrDrawRandomOp(SkRandom* random, GrSurfaceDrawContext* surfaceDrawContext, GrPaint&& paint) {
82 auto context = surfaceDrawContext->recordingContext();
Herb Derbyc76d4092020-10-07 16:46:15 -040083 using MakeDrawOpFn = GrOp::Owner (GrPaint&&, SkRandom*,
Herb Derby0b1228d2021-04-05 18:38:35 -040084 GrRecordingContext*, GrSurfaceDrawContext*, int numSamples);
Brian Salomon17726632017-05-12 14:09:46 -040085 static constexpr MakeDrawOpFn* gFactories[] = {
Brian Salomon34169692017-08-28 15:32:01 -040086 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
Brian Salomon34169692017-08-28 15:32:01 -040087 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
88 DRAW_OP_TEST_ENTRY(AAHairlineOp),
89 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
90 DRAW_OP_TEST_ENTRY(CircleOp),
91 DRAW_OP_TEST_ENTRY(DashOp),
92 DRAW_OP_TEST_ENTRY(DefaultPathOp),
93 DRAW_OP_TEST_ENTRY(DIEllipseOp),
94 DRAW_OP_TEST_ENTRY(EllipseOp),
Michael Ludwig69858532018-11-28 15:34:34 -050095 DRAW_OP_TEST_ENTRY(FillRectOp),
Brian Salomon34169692017-08-28 15:32:01 -040096 DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
Brian Osman4d92b892019-03-24 00:53:23 +000097 DRAW_OP_TEST_ENTRY(DrawAtlasOp),
Robert Phillipsb6e9d3c2019-02-11 14:29:34 -050098 DRAW_OP_TEST_ENTRY(DrawVerticesOp),
Brian Salomon34169692017-08-28 15:32:01 -040099 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
100 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
101 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
102 DRAW_OP_TEST_ENTRY(SmallPathOp),
103 DRAW_OP_TEST_ENTRY(RegionOp),
104 DRAW_OP_TEST_ENTRY(RRectOp),
Chris Dalton17dc4182020-03-25 16:18:16 -0600105 DRAW_OP_TEST_ENTRY(TriangulatingPathOp),
Brian Salomon34169692017-08-28 15:32:01 -0400106 DRAW_OP_TEST_ENTRY(TextureOp),
Brian Salomon17726632017-05-12 14:09:46 -0400107 };
108
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400109 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
Brian Salomon17726632017-05-12 14:09:46 -0400110 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
Herb Derby0b1228d2021-04-05 18:38:35 -0400111 auto op = gFactories[index](std::move(paint),
112 random,
113 context,
114 surfaceDrawContext,
115 surfaceDrawContext->numSamples());
Herb Derby411e7aa2020-07-09 16:02:08 -0400116
117 // Creating a GrAtlasTextOp my not produce an op if for example, it is totally outside the
118 // render target context.
Ben Wagner525e8762020-07-09 16:19:35 -0400119 if (op) {
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500120 surfaceDrawContext->addDrawOp(std::move(op));
Ben Wagner525e8762020-07-09 16:19:35 -0400121 }
Brian Salomon17726632017-05-12 14:09:46 -0400122}