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