Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrMockOpTarget.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 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#ifndef GrMockOpTarget_DEFINED
9#define GrMockOpTarget_DEFINED
10
27
28#include <cstddef>
29#include <cstdint>
30#include <utility>
31
32class GrAtlasManager;
33class GrCaps;
38class GrSurfaceProxy;
41
42namespace skgpu { namespace ganesh { class SmallPathAtlasMgr; } }
43namespace sktext { namespace gpu { class StrikeCache; } }
44
45
46// This is a mock GrMeshDrawTarget implementation that just gives back pointers into
47// pre-allocated CPU buffers, rather than allocating and mapping GPU buffers.
49public:
57 const GrDirectContext* mockContext() const { return fMockContext.get(); }
58 const GrCaps& caps() const override { return *fMockContext->priv().caps(); }
60 return fMockContext->priv().threadSafeCache();
61 }
63 return fMockContext->priv().resourceProvider();
64 }
65#ifndef SK_ENABLE_OPTIMIZE_SIZE
66 skgpu::ganesh::SmallPathAtlasMgr* smallPathAtlasManager() const override { return nullptr; }
67#endif
69 SkArenaAlloc* allocator() override { return &fAllocator; }
70 void putBackVertices(int vertices, size_t vertexStride) override { /* no-op */ }
72 const GrDstProxyView& dstProxyView() const override { return fDstProxyView; }
74 GrLoadOp colorLoadOp() const override { return GrLoadOp::kLoad; }
75
76 void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>* buffer,
77 int* startVertex) override {
78 if (vertexSize * vertexCount > sizeof(fStaticVertexData)) {
79 SK_ABORT("FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
80 vertexSize * vertexCount, sizeof(fStaticVertexData));
81 }
83 *startVertex = 0;
84 return fStaticVertexData;
85 }
86
87 void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount,
88 sk_sp<const GrBuffer>* buffer, int* startVertex,
89 int* actualVertexCount) override {
90 if (vertexSize * minVertexCount > sizeof(fStaticVertexData)) {
91 SK_ABORT("FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
92 vertexSize * minVertexCount, sizeof(fStaticVertexData));
93 }
95 *startVertex = 0;
96 *actualVertexCount = sizeof(fStaticVertexData) / vertexSize;
97 return fStaticVertexData;
98 }
99
101 size_t* offsetInBytes) override {
102 if (sizeof(GrDrawIndirectCommand) * drawCount > sizeof(fStaticIndirectData)) {
103 SK_ABORT("FATAL: wanted %zu bytes of static indirect data; only have %zu.\n",
104 sizeof(GrDrawIndirectCommand) * drawCount, sizeof(fStaticIndirectData));
105 }
107 *offsetInBytes = 0;
108 return fStaticIndirectData;
109 }
110
111 void putBackIndirectDraws(int count) override { /* no-op */ }
112
115 size_t* offsetInBytes) override {
116 if (sizeof(GrDrawIndexedIndirectCommand) * drawCount > sizeof(fStaticIndirectData)) {
117 SK_ABORT("FATAL: wanted %zu bytes of static indirect data; only have %zu.\n",
118 sizeof(GrDrawIndexedIndirectCommand) * drawCount, sizeof(fStaticIndirectData));
119 }
121 *offsetInBytes = 0;
122 return fStaticIndirectData;
123 }
124
125 void putBackIndexedIndirectDraws(int count) override { /* no-op */ }
126
127 // Call these methods to see what got written after the previous call to make*Space.
128 const void* peekStaticVertexData() const { return fStaticVertexData; }
129 const void* peekStaticIndirectData() const { return fStaticIndirectData; }
130
131#define UNIMPL(...) __VA_ARGS__ override { SK_ABORT("unimplemented."); }
132 UNIMPL(void recordDraw(const GrGeometryProcessor*, const GrSimpleMesh[], int,
133 const GrSurfaceProxy* const[], GrPrimitiveType))
134 UNIMPL(uint16_t* makeIndexSpace(int, sk_sp<const GrBuffer>*, int*))
135 UNIMPL(uint16_t* makeIndexSpaceAtLeast(int, int, sk_sp<const GrBuffer>*, int*, int*))
136 UNIMPL(void putBackIndices(int))
138 UNIMPL(const GrSurfaceProxyView& writeView() const)
139 UNIMPL(const GrAppliedClip* appliedClip() const)
140 UNIMPL(bool usesMSAASurface() const)
141 UNIMPL(sktext::gpu::StrikeCache* strikeCache() const)
145#undef UNIMPL
146
147private:
148 sk_sp<GrDirectContext> fMockContext;
149 char fStaticVertexData[6 * 1024 * 1024];
155};
156
157#endif
int count
#define UNIMPL(...)
GrPrimitiveType
Definition GrTypesPriv.h:42
@ kDynamic_GrAccessPattern
GrLoadOp
GrXferBarrierFlags
#define SK_ABORT(message,...)
Definition SkAssert.h:70
static GrAppliedClip Disabled()
GrGpu * getGpu() const
sk_sp< GrGpuBuffer > createBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern accessPattern)
Definition GrGpu.cpp:393
virtual const GrAppliedClip * appliedClip() const =0
virtual bool usesMSAASurface() const =0
virtual void recordDraw(const GrGeometryProcessor *, const GrSimpleMesh[], int meshCnt, const GrSurfaceProxy *const primProcProxies[], GrPrimitiveType)=0
virtual GrAtlasManager * atlasManager() const =0
virtual uint16_t * makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount, sk_sp< const GrBuffer > *, int *startIndex, int *actualIndexCount)=0
virtual const GrSurfaceProxyView & writeView() const =0
virtual skia_private::TArray< GrSurfaceProxy *, true > * sampledProxyArray()=0
virtual GrDeferredUploadTarget * deferredUploadTarget()=0
virtual GrRenderTargetProxy * rtProxy() const =0
virtual void putBackIndices(int indices)=0
virtual sktext::gpu::StrikeCache * strikeCache() const =0
virtual uint16_t * makeIndexSpace(int indexCount, sk_sp< const GrBuffer > *, int *startIndex)=0
SkSTArenaAllocWithReset< 1024 *1024 > fAllocator
const void * peekStaticVertexData() const
char fStaticIndirectData[sizeof(GrDrawIndexedIndirectCommand) *32]
GrDrawIndexedIndirectWriter makeDrawIndexedIndirectSpace(int drawCount, sk_sp< const GrBuffer > *buffer, size_t *offsetInBytes) override
const void * peekStaticIndirectData() const
void * makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp< const GrBuffer > *buffer, int *startVertex) override
GrResourceProvider * resourceProvider() const override
sk_sp< GrGpuBuffer > fStaticIndirectBuffer
GrMockOpTarget(sk_sp< GrDirectContext > mockContext)
SkArenaAlloc * allocator() override
GrDstProxyView fDstProxyView
UNIMPL(void recordDraw(const GrGeometryProcessor *, const GrSimpleMesh fStaticVertexData[], int, const GrSurfaceProxy *const [], GrPrimitiveType)) private char[6 *1024 *1024]
void putBackVertices(int vertices, size_t vertexStride) override
void * makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount, sk_sp< const GrBuffer > *buffer, int *startVertex, int *actualVertexCount) override
GrAppliedClip detachAppliedClip() override
GrXferBarrierFlags renderPassBarriers() const override
const GrDstProxyView & dstProxyView() const override
skgpu::ganesh::SmallPathAtlasMgr * smallPathAtlasManager() const override
void putBackIndexedIndirectDraws(int count) override
const GrCaps & caps() const override
GrDrawIndirectWriter makeDrawIndirectSpace(int drawCount, sk_sp< const GrBuffer > *buffer, size_t *offsetInBytes) override
GrLoadOp colorLoadOp() const override
sk_sp< GrGpuBuffer > fStaticVertexBuffer
void putBackIndirectDraws(int count) override
GrThreadSafeCache * threadSafeCache() const override
const GrDirectContext * mockContext() const
GrResourceProviderPriv priv()
static const uint8_t buffer[]
Definition ref_ptr.h:256