• 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/gpu/GrTexture.h"
12 #include "include/private/SkTHash.h"
13 #include "src/gpu/GrGpu.h"
14 #include "src/gpu/GrRenderTarget.h"
15 #include "src/gpu/GrSemaphore.h"
16 
17 class GrMockGpuRTCommandBuffer;
18 struct GrMockOptions;
19 class GrPipeline;
20 
21 class GrMockGpu : public GrGpu {
22 public:
23     static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrContext*);
24 
~GrMockGpu()25     ~GrMockGpu() override {}
26 
27     GrGpuRTCommandBuffer* getCommandBuffer(
28                                     GrRenderTarget*, GrSurfaceOrigin, const SkRect&,
29                                     const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
30                                     const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
31 
32     GrGpuTextureCommandBuffer* getCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
33 
insertFence()34     GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
waitFence(GrFence,uint64_t)35     bool waitFence(GrFence, uint64_t) override { return true; }
deleteFence(GrFence)36     void deleteFence(GrFence) const override {}
37 
makeSemaphore(bool isOwned)38     sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override {
39         return nullptr;
40     }
wrapBackendSemaphore(const GrBackendSemaphore & semaphore,GrResourceProvider::SemaphoreWrapType wrapType,GrWrapOwnership ownership)41     sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
42                                             GrResourceProvider::SemaphoreWrapType wrapType,
43                                             GrWrapOwnership ownership) override { return nullptr; }
insertSemaphore(sk_sp<GrSemaphore> semaphore)44     void insertSemaphore(sk_sp<GrSemaphore> semaphore) override {}
waitSemaphore(sk_sp<GrSemaphore> semaphore)45     void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
prepareTextureForCrossContextUsage(GrTexture *)46     sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; }
47 
48     void submit(GrGpuCommandBuffer* buffer) override;
49 
checkFinishProcs()50     void checkFinishProcs() override {}
51 
52 private:
53     GrMockGpu(GrContext* context, const GrMockOptions&, const GrContextOptions&);
54 
55     void submitCommandBuffer(const GrMockGpuRTCommandBuffer*);
56 
onResetContext(uint32_t resetBits)57     void onResetContext(uint32_t resetBits) override {}
58 
59     void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override;
60 
xferBarrier(GrRenderTarget *,GrXferBarrierType)61     void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
62 
63     sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&,
64                                      const GrBackendFormat&,
65                                      GrRenderable,
66                                      int renderTargetSampleCnt,
67                                      SkBudgeted,
68                                      GrProtected,
69                                      const GrMipLevel[],
70                                      int mipLevelCount) override;
71 
72     sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, const GrBackendFormat&,
73                                                SkImage::CompressionType, SkBudgeted,
74                                                const void* data) override;
75 
76     sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
77                                           GrWrapCacheable, GrIOType) override;
78 
79     sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
80                                                     int sampleCnt,
81                                                     GrColorType,
82                                                     GrWrapOwnership,
83                                                     GrWrapCacheable) override;
84 
85     sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
86                                                     GrColorType) override;
87 
88     sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
89                                                              int sampleCnt, GrColorType) override;
90 
91     sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
92                                       const void*) override;
93 
onReadPixels(GrSurface * surface,int left,int top,int width,int height,GrColorType surfaceColorType,GrColorType dstColorType,void * buffer,size_t rowBytes)94     bool onReadPixels(GrSurface* surface, int left, int top, int width, int height,
95                       GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
96                       size_t rowBytes) override {
97         return true;
98     }
99 
onWritePixels(GrSurface * surface,int left,int top,int width,int height,GrColorType surfaceColorType,GrColorType srcColorType,const GrMipLevel texels[],int mipLevelCount)100     bool onWritePixels(GrSurface* surface, int left, int top, int width, int height,
101                        GrColorType surfaceColorType, GrColorType srcColorType,
102                        const GrMipLevel texels[], int mipLevelCount) override {
103         return true;
104     }
105 
onTransferPixelsTo(GrTexture * texture,int left,int top,int width,int height,GrColorType surfaceColorType,GrColorType bufferColorType,GrGpuBuffer * transferBuffer,size_t offset,size_t rowBytes)106     bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
107                             GrColorType surfaceColorType, GrColorType bufferColorType,
108                             GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override {
109         return true;
110     }
onTransferPixelsFrom(GrSurface * surface,int left,int top,int width,int height,GrColorType surfaceColorType,GrColorType bufferColorType,GrGpuBuffer * transferBuffer,size_t offset)111     bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
112                               GrColorType surfaceColorType, GrColorType bufferColorType,
113                               GrGpuBuffer* transferBuffer, size_t offset) override {
114         return true;
115     }
onCopySurface(GrSurface * dst,GrSurface * src,const SkIRect & srcRect,const SkIPoint & dstPoint,bool canDiscardOutsideDstRect)116     bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
117                        const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override {
118         return true;
119     }
120 
onRegenerateMipMapLevels(GrTexture *)121     bool onRegenerateMipMapLevels(GrTexture*) override { return true; }
122 
onResolveRenderTarget(GrRenderTarget * target)123     void onResolveRenderTarget(GrRenderTarget* target) override { return; }
124 
onFinishFlush(GrSurfaceProxy * [],int n,SkSurface::BackendSurfaceAccess access,const GrFlushInfo & info,const GrPrepareForExternalIORequests &)125     void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
126                        const GrFlushInfo& info, const GrPrepareForExternalIORequests&) override {
127         if (info.fFinishedProc) {
128             info.fFinishedProc(info.fFinishedContext);
129         }
130     }
131 
132     GrStencilAttachment* createStencilAttachmentForRenderTarget(
133             const GrRenderTarget*, int width, int height, int numStencilSamples) override;
134     GrBackendTexture createBackendTexture(int w, int h, const GrBackendFormat&,
135                                           GrMipMapped, GrRenderable,
136                                           const void* pixels, size_t rowBytes,
137                                           const SkColor4f* color, GrProtected isProtected) override;
138     void deleteBackendTexture(const GrBackendTexture&) override;
139 
140 #if GR_TEST_UTILS
141     bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
142 
143     GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
144     void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
145 
testingOnly_flushGpuAndSync()146     void testingOnly_flushGpuAndSync() override {}
147 #endif
148 
149     const GrMockOptions fMockOptions;
150 
151     static int NextInternalTextureID();
152     static int NextExternalTextureID();
153     static int NextInternalRenderTargetID();
154     static int NextExternalRenderTargetID();
155 
156     SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
157 
158     typedef GrGpu INHERITED;
159 };
160 
161 #endif
162