1 | /* |
2 | * Copyright 2017 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 GrMockGpu_DEFINED |
9 | #define GrMockGpu_DEFINED |
10 | |
11 | #include "include/private/SkTHash.h" |
12 | #include "src/gpu/GrGpu.h" |
13 | #include "src/gpu/GrRenderTarget.h" |
14 | #include "src/gpu/GrSemaphore.h" |
15 | #include "src/gpu/GrTexture.h" |
16 | |
17 | class GrMockOpsRenderPass; |
18 | struct GrMockOptions; |
19 | class GrPipeline; |
20 | |
21 | class GrMockGpu : public GrGpu { |
22 | public: |
23 | static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrDirectContext*); |
24 | |
25 | ~GrMockGpu() override {} |
26 | |
27 | GrOpsRenderPass* getOpsRenderPass( |
28 | GrRenderTarget*, |
29 | GrStencilAttachment*, |
30 | GrSurfaceOrigin, |
31 | const SkIRect&, |
32 | const GrOpsRenderPass::LoadAndStoreInfo&, |
33 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
34 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies) override; |
35 | |
36 | GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; } |
37 | bool waitFence(GrFence) override { return true; } |
38 | void deleteFence(GrFence) const override {} |
39 | |
40 | std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override { |
41 | return nullptr; |
42 | } |
43 | std::unique_ptr<GrSemaphore> wrapBackendSemaphore( |
44 | const GrBackendSemaphore& semaphore, |
45 | GrResourceProvider::SemaphoreWrapType wrapType, |
46 | GrWrapOwnership ownership) override { |
47 | return nullptr; |
48 | } |
49 | void insertSemaphore(GrSemaphore* semaphore) override {} |
50 | void waitSemaphore(GrSemaphore* semaphore) override {} |
51 | std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { |
52 | return nullptr; |
53 | } |
54 | |
55 | void submit(GrOpsRenderPass* renderPass) override; |
56 | |
57 | void checkFinishProcs() override {} |
58 | |
59 | private: |
60 | GrMockGpu(GrDirectContext*, const GrMockOptions&, const GrContextOptions&); |
61 | |
62 | void onResetContext(uint32_t resetBits) override {} |
63 | |
64 | void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override; |
65 | |
66 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
67 | |
68 | sk_sp<GrTexture> onCreateTexture(SkISize, |
69 | const GrBackendFormat&, |
70 | GrRenderable, |
71 | int renderTargetSampleCnt, |
72 | SkBudgeted, |
73 | GrProtected, |
74 | int mipLevelCount, |
75 | uint32_t levelClearMask) override; |
76 | |
77 | sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, |
78 | const GrBackendFormat&, |
79 | SkBudgeted, |
80 | GrMipmapped, |
81 | GrProtected, |
82 | const void* data, size_t dataSize) override; |
83 | |
84 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, |
85 | GrWrapOwnership, |
86 | GrWrapCacheable, |
87 | GrIOType) override; |
88 | sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&, |
89 | GrWrapOwnership, |
90 | GrWrapCacheable) override; |
91 | |
92 | sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
93 | int sampleCnt, |
94 | GrWrapOwnership, |
95 | GrWrapCacheable) override; |
96 | |
97 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; |
98 | |
99 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
100 | int sampleCnt) override; |
101 | |
102 | sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern, |
103 | const void*) override; |
104 | |
105 | bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, |
106 | GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, |
107 | size_t rowBytes) override { |
108 | return true; |
109 | } |
110 | |
111 | bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, |
112 | GrColorType surfaceColorType, GrColorType srcColorType, |
113 | const GrMipLevel texels[], int mipLevelCount, |
114 | bool prepForTexSampling) override { |
115 | return true; |
116 | } |
117 | |
118 | bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height, |
119 | GrColorType surfaceColorType, GrColorType bufferColorType, |
120 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override { |
121 | return true; |
122 | } |
123 | bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
124 | GrColorType surfaceColorType, GrColorType bufferColorType, |
125 | GrGpuBuffer* transferBuffer, size_t offset) override { |
126 | return true; |
127 | } |
128 | bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
129 | const SkIPoint& dstPoint) override { |
130 | return true; |
131 | } |
132 | |
133 | bool onRegenerateMipMapLevels(GrTexture*) override { return true; } |
134 | |
135 | void onResolveRenderTarget(GrRenderTarget* target, const SkIRect&) override {} |
136 | |
137 | void addFinishedProc(GrGpuFinishedProc finishedProc, |
138 | GrGpuFinishedContext finishedContext) override { |
139 | SkASSERT(finishedProc); |
140 | finishedProc(finishedContext); |
141 | } |
142 | |
143 | bool onSubmitToGpu(bool syncCpu) override { |
144 | return true; |
145 | } |
146 | |
147 | GrStencilAttachment* createStencilAttachmentForRenderTarget( |
148 | const GrRenderTarget*, int width, int height, int numStencilSamples) override; |
149 | GrBackendTexture onCreateBackendTexture(SkISize dimensions, |
150 | const GrBackendFormat&, |
151 | GrRenderable, |
152 | GrMipmapped, |
153 | GrProtected) override; |
154 | |
155 | bool onUpdateBackendTexture(const GrBackendTexture&, |
156 | sk_sp<GrRefCntedCallback> finishedCallback, |
157 | const BackendTextureData*) override { |
158 | return true; |
159 | } |
160 | |
161 | GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions, |
162 | const GrBackendFormat&, |
163 | GrMipmapped, |
164 | GrProtected) override; |
165 | |
166 | bool onUpdateCompressedBackendTexture(const GrBackendTexture&, |
167 | sk_sp<GrRefCntedCallback> finishedCallback, |
168 | const BackendTextureData*) override { |
169 | return true; |
170 | } |
171 | |
172 | void deleteBackendTexture(const GrBackendTexture&) override; |
173 | |
174 | bool compile(const GrProgramDesc&, const GrProgramInfo&) override { return false; } |
175 | |
176 | #if GR_TEST_UTILS |
177 | bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; |
178 | |
179 | GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; |
180 | void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; |
181 | |
182 | void testingOnly_flushGpuAndSync() override {} |
183 | #endif |
184 | |
185 | const GrMockOptions fMockOptions; |
186 | |
187 | static int NextInternalTextureID(); |
188 | static int NextExternalTextureID(); |
189 | static int NextInternalRenderTargetID(); |
190 | static int NextExternalRenderTargetID(); |
191 | |
192 | SkTHashSet<int> fOutstandingTestingOnlyTextureIDs; |
193 | |
194 | typedef GrGpu INHERITED; |
195 | }; |
196 | |
197 | #endif |
198 | |