• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     GrThreadSafePipelineBuilder* pipelineBuilder() override;
28     sk_sp<GrThreadSafePipelineBuilder> refPipelineBuilder() override;
29 
insertFence()30     GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
waitFence(GrFence)31     bool waitFence(GrFence) override { return true; }
deleteFence(GrFence)32     void deleteFence(GrFence) const override {}
33 
makeSemaphore(bool isOwned)34     std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override {
35         return nullptr;
36     }
wrapBackendSemaphore(const GrBackendSemaphore &,GrSemaphoreWrapType,GrWrapOwnership)37     std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& /* semaphore */,
38                                                       GrSemaphoreWrapType /* wraptype */,
39                                                       GrWrapOwnership /* ownership */) override {
40         return nullptr;
41     }
insertSemaphore(GrSemaphore * semaphore)42     void insertSemaphore(GrSemaphore* semaphore) override {}
waitSemaphore(GrSemaphore * semaphore)43     void waitSemaphore(GrSemaphore* semaphore) override {}
prepareTextureForCrossContextUsage(GrTexture *)44     std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override {
45         return nullptr;
46     }
47 
48     void submit(GrOpsRenderPass* renderPass) override;
49 
checkFinishProcs()50     void checkFinishProcs() override {}
finishOutstandingGpuWork()51     void finishOutstandingGpuWork() override {}
52 
53 private:
54     GrMockGpu(GrDirectContext*, const GrMockOptions&, const GrContextOptions&);
55 
xferBarrier(GrRenderTarget *,GrXferBarrierType)56     void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
57 
58     sk_sp<GrTexture> onCreateTexture(SkISize,
59                                      const GrBackendFormat&,
60                                      GrRenderable,
61                                      int renderTargetSampleCnt,
62                                      SkBudgeted,
63                                      GrProtected,
64                                      int mipLevelCount,
65                                      uint32_t levelClearMask) override;
66 
67     sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions,
68                                                const GrBackendFormat&,
69                                                SkBudgeted,
70                                                GrMipmapped,
71                                                GrProtected,
72                                                const void* data, size_t dataSize) override;
73 
74     sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
75                                           GrWrapOwnership,
76                                           GrWrapCacheable,
77                                           GrIOType) override;
78     sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&,
79                                                     GrWrapOwnership,
80                                                     GrWrapCacheable) override;
81 
82     sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
83                                                     int sampleCnt,
84                                                     GrWrapOwnership,
85                                                     GrWrapCacheable) override;
86 
87     sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
88 
89     sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
90                                       const void*) override;
91 
onReadPixels(GrSurface *,SkIRect,GrColorType surfaceColorType,GrColorType dstColorType,void *,size_t rowBytes)92     bool onReadPixels(GrSurface*,
93                       SkIRect,
94                       GrColorType surfaceColorType,
95                       GrColorType dstColorType,
96                       void*,
97                       size_t rowBytes) override {
98         return true;
99     }
100 
onWritePixels(GrSurface *,SkIRect,GrColorType surfaceColorType,GrColorType srcColorType,const GrMipLevel[],int mipLevelCount,bool prepForTexSampling)101     bool onWritePixels(GrSurface*,
102                        SkIRect,
103                        GrColorType surfaceColorType,
104                        GrColorType srcColorType,
105                        const GrMipLevel[],
106                        int mipLevelCount,
107                        bool prepForTexSampling) override {
108         return true;
109     }
110 
onTransferPixelsTo(GrTexture *,SkIRect,GrColorType surfaceColorType,GrColorType bufferColorType,sk_sp<GrGpuBuffer>,size_t offset,size_t rowBytes)111     bool onTransferPixelsTo(GrTexture*,
112                             SkIRect,
113                             GrColorType surfaceColorType,
114                             GrColorType bufferColorType,
115                             sk_sp<GrGpuBuffer>,
116                             size_t offset,
117                             size_t rowBytes) override {
118         return true;
119     }
120 
onTransferPixelsFrom(GrSurface *,SkIRect,GrColorType surfaceColorType,GrColorType bufferColorType,sk_sp<GrGpuBuffer>,size_t offset)121     bool onTransferPixelsFrom(GrSurface*,
122                               SkIRect,
123                               GrColorType surfaceColorType,
124                               GrColorType bufferColorType,
125                               sk_sp<GrGpuBuffer>,
126                               size_t offset) override {
127         return true;
128     }
129 
onCopySurface(GrSurface * dst,GrSurface * src,const SkIRect & srcRect,const SkIPoint & dstPoint)130     bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
131                        const SkIPoint& dstPoint) override {
132         return true;
133     }
134 
onRegenerateMipMapLevels(GrTexture *)135     bool onRegenerateMipMapLevels(GrTexture*) override { return true; }
136 
onResolveRenderTarget(GrRenderTarget * target,const SkIRect &)137     void onResolveRenderTarget(GrRenderTarget* target, const SkIRect&) override {}
138 
addFinishedProc(GrGpuFinishedProc finishedProc,GrGpuFinishedContext finishedContext)139     void addFinishedProc(GrGpuFinishedProc finishedProc,
140                          GrGpuFinishedContext finishedContext) override {
141         SkASSERT(finishedProc);
142         finishedProc(finishedContext);
143     }
144 
145     GrOpsRenderPass* onGetOpsRenderPass(GrRenderTarget*,
146                                         bool useMSAASurface,
147                                         GrAttachment*,
148                                         GrSurfaceOrigin,
149                                         const SkIRect&,
150                                         const GrOpsRenderPass::LoadAndStoreInfo&,
151                                         const GrOpsRenderPass::StencilLoadAndStoreInfo&,
152                                         const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
153                                         GrXferBarrierFlags renderPassXferBarriers) override;
154 
onSubmitToGpu(bool syncCpu)155     bool onSubmitToGpu(bool syncCpu) override {
156         return true;
157     }
158 
159     sk_sp<GrAttachment> makeStencilAttachment(const GrBackendFormat& /*colorFormat*/,
160                                               SkISize dimensions, int numStencilSamples) override;
161 
getPreferredStencilFormat(const GrBackendFormat &)162     GrBackendFormat getPreferredStencilFormat(const GrBackendFormat&) override {
163         return GrBackendFormat::MakeMock(GrColorType::kUnknown, SkImage::CompressionType::kNone,
164                                          true);
165     }
166 
makeMSAAAttachment(SkISize dimensions,const GrBackendFormat & format,int numSamples,GrProtected isProtected,GrMemoryless isMemoryless)167     sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
168                                            const GrBackendFormat& format,
169                                            int numSamples,
170                                            GrProtected isProtected,
171                                            GrMemoryless isMemoryless) override {
172         return nullptr;
173     }
174 
175     GrBackendTexture onCreateBackendTexture(SkISize dimensions,
176                                             const GrBackendFormat&,
177                                             GrRenderable,
178                                             GrMipmapped,
179                                             GrProtected) override;
180 
onClearBackendTexture(const GrBackendTexture &,sk_sp<GrRefCntedCallback> finishedCallback,std::array<float,4> color)181     bool onClearBackendTexture(const GrBackendTexture&,
182                                sk_sp<GrRefCntedCallback> finishedCallback,
183                                std::array<float, 4> color) override {
184         return true;
185     }
186 
187     GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
188                                                       const GrBackendFormat&,
189                                                       GrMipmapped,
190                                                       GrProtected) override;
191 
onUpdateCompressedBackendTexture(const GrBackendTexture &,sk_sp<GrRefCntedCallback> finishedCallback,const void *,size_t)192     bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
193                                           sk_sp<GrRefCntedCallback> finishedCallback,
194                                           const void*,
195                                           size_t) override {
196         return true;
197     }
198 
199     void deleteBackendTexture(const GrBackendTexture&) override;
200 
compile(const GrProgramDesc &,const GrProgramInfo &)201     bool compile(const GrProgramDesc&, const GrProgramInfo&) override { return false; }
202 
203 #if GR_TEST_UTILS
204     bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
205 
206     GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions,
207                                                                GrColorType,
208                                                                int sampleCnt,
209                                                                GrProtected) override;
210     void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
211 #endif
212 
213     const GrMockOptions fMockOptions;
214 
215     static int NextInternalTextureID();
216     static int NextExternalTextureID();
217     static int NextInternalRenderTargetID();
218     static int NextExternalRenderTargetID();
219 
220     SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
221 
222     using INHERITED = GrGpu;
223 };
224 
225 #endif
226