• 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 "GrGpu.h"
12 #include "GrSemaphore.h"
13 #include "GrTexture.h"
14 #include "SkTHash.h"
15 
16 class GrMockGpuCommandBuffer;
17 struct GrMockOptions;
18 class GrPipeline;
19 
20 class GrMockGpu : public GrGpu {
21 public:
22     static GrGpu* Create(GrBackendContext, const GrContextOptions&, GrContext*);
23 
~GrMockGpu()24     ~GrMockGpu() override {}
25 
onGetReadPixelsInfo(GrSurface * srcSurface,int readWidth,int readHeight,size_t rowBytes,GrPixelConfig readConfig,DrawPreference *,ReadPixelTempDrawInfo *)26     bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
27                              GrPixelConfig readConfig, DrawPreference*,
28                              ReadPixelTempDrawInfo*) override { return true; }
29 
onGetWritePixelsInfo(GrSurface * dstSurface,int width,int height,GrPixelConfig srcConfig,DrawPreference *,WritePixelTempDrawInfo *)30     bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
31                               GrPixelConfig srcConfig, DrawPreference*,
32                               WritePixelTempDrawInfo*) override { return true; }
33 
onCopySurface(GrSurface * dst,GrSurface * src,const SkIRect & srcRect,const SkIPoint & dstPoint)34     bool onCopySurface(GrSurface* dst,
35                        GrSurface* src,
36                        const SkIRect& srcRect,
37                        const SkIPoint& dstPoint) override { return true; }
38 
onQueryMultisampleSpecs(GrRenderTarget * rt,const GrStencilSettings &,int * effectiveSampleCnt,SamplePattern *)39     void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
40                                  int* effectiveSampleCnt, SamplePattern*) override {
41         *effectiveSampleCnt = rt->numStencilSamples();
42     }
43 
44     GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&,
45                                             const GrGpuCommandBuffer::LoadAndStoreInfo&) override;
46 
insertFence()47     GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
waitFence(GrFence,uint64_t)48     bool waitFence(GrFence, uint64_t) override { return true; }
deleteFence(GrFence)49     void deleteFence(GrFence) const override {}
50 
makeSemaphore(bool isOwned)51     sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override {
52         return nullptr;
53     }
wrapBackendSemaphore(const GrBackendSemaphore & semaphore,GrWrapOwnership ownership)54     sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
55                                             GrWrapOwnership ownership) override { return nullptr; }
insertSemaphore(sk_sp<GrSemaphore> semaphore,bool flush)56     void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override {}
waitSemaphore(sk_sp<GrSemaphore> semaphore)57     void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
prepareTextureForCrossContextUsage(GrTexture *)58     sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; }
59 
60     void submitCommandBuffer(const GrMockGpuCommandBuffer*);
61 
62 private:
63     GrMockGpu(GrContext* context, const GrMockOptions&, const GrContextOptions&);
64 
onResetContext(uint32_t resetBits)65     void onResetContext(uint32_t resetBits) override {}
66 
xferBarrier(GrRenderTarget *,GrXferBarrierType)67     void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
68 
69     sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, SkBudgeted,
70                                      const GrMipLevel texels[], int mipLevelCount) override;
71 
onWrapBackendTexture(const GrBackendTexture &,GrSurfaceOrigin,GrBackendTextureFlags,int sampleCnt,GrWrapOwnership)72     sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
73                                           GrSurfaceOrigin,
74                                           GrBackendTextureFlags,
75                                           int sampleCnt,
76                                           GrWrapOwnership) override {
77         return nullptr;
78     }
79 
onWrapBackendRenderTarget(const GrBackendRenderTarget &,GrSurfaceOrigin)80     sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
81                                                     GrSurfaceOrigin) override {
82         return nullptr;
83     }
84 
onWrapBackendTextureAsRenderTarget(const GrBackendTexture &,GrSurfaceOrigin,int sampleCnt)85     sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
86                                                              GrSurfaceOrigin,
87                                                              int sampleCnt) override {
88         return nullptr;
89     }
90 
91     GrBuffer* onCreateBuffer(size_t sizeInBytes, GrBufferType, GrAccessPattern,
92                              const void*) override;
93 
onCreateInstancedRendering()94     gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
95 
onReadPixels(GrSurface * surface,int left,int top,int width,int height,GrPixelConfig,void * buffer,size_t rowBytes)96     bool onReadPixels(GrSurface* surface,
97                       int left, int top, int width, int height,
98                       GrPixelConfig,
99                       void* buffer,
100                       size_t rowBytes) override {
101         return true;
102     }
103 
onWritePixels(GrSurface * surface,int left,int top,int width,int height,GrPixelConfig config,const GrMipLevel texels[],int mipLevelCount)104     bool onWritePixels(GrSurface* surface,
105                        int left, int top, int width, int height,
106                        GrPixelConfig config,
107                        const GrMipLevel texels[], int mipLevelCount) override {
108         return true;
109     }
110 
onTransferPixels(GrTexture * texture,int left,int top,int width,int height,GrPixelConfig config,GrBuffer * transferBuffer,size_t offset,size_t rowBytes)111     bool onTransferPixels(GrTexture* texture,
112                           int left, int top, int width, int height,
113                           GrPixelConfig config, GrBuffer* transferBuffer,
114                           size_t offset, size_t rowBytes) override {
115         return true;
116     }
117 
onResolveRenderTarget(GrRenderTarget * target)118     void onResolveRenderTarget(GrRenderTarget* target) override { return; }
119 
120     GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
121                                                                 int width,
122                                                                 int height) override;
clearStencil(GrRenderTarget * target)123     void clearStencil(GrRenderTarget* target) override  {}
124 
125     GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, GrPixelConfig,
126                                                     bool isRT) override;
127 
128     bool isTestingOnlyBackendTexture(GrBackendObject) const override;
129 
130     void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override;
131 
132     static int NextInternalTextureID();
133     static int NextExternalTextureID();
134 
135     SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
136 
137     typedef GrGpu INHERITED;
138 };
139 
140 #endif
141