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 GrMockOpsRenderPass_DEFINED 9 #define GrMockOpsRenderPass_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/private/gpu/ganesh/GrTypesPriv.h" 13 #include "src/gpu/ganesh/GrDeferredUpload.h" 14 #include "src/gpu/ganesh/GrOpsRenderPass.h" 15 #include "src/gpu/ganesh/GrRenderTarget.h" 16 #include "src/gpu/ganesh/GrTexture.h" 17 #include "src/gpu/ganesh/mock/GrMockGpu.h" 18 19 #include <array> 20 #include <cstddef> 21 #include <cstdint> 22 23 class GrBuffer; 24 class GrGeometryProcessor; 25 class GrGpu; 26 class GrOpFlushState; 27 class GrPipeline; 28 class GrProgramInfo; 29 class GrScissorState; 30 class GrSurfaceProxy; 31 enum GrSurfaceOrigin : int; 32 struct SkIRect; 33 struct SkRect; 34 35 class GrMockOpsRenderPass : public GrOpsRenderPass { 36 public: GrMockOpsRenderPass(GrMockGpu * gpu,GrRenderTarget * rt,GrSurfaceOrigin origin,LoadAndStoreInfo colorInfo)37 GrMockOpsRenderPass(GrMockGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin, 38 LoadAndStoreInfo colorInfo) 39 : INHERITED(rt, origin) 40 , fGpu(gpu) 41 , fColorLoadOp(colorInfo.fLoadOp) { 42 } 43 gpu()44 GrGpu* gpu() override { return fGpu; } inlineUpload(GrOpFlushState *,GrDeferredTextureUploadFn &)45 void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) override {} 46 numDraws()47 int numDraws() const { return fNumDraws; } 48 49 private: onBegin()50 void onBegin() override { 51 if (GrLoadOp::kClear == fColorLoadOp) { 52 this->markRenderTargetDirty(); 53 } 54 } onBindPipeline(const GrProgramInfo &,const SkRect &)55 bool onBindPipeline(const GrProgramInfo&, const SkRect&) override { return true; } onSetScissorRect(const SkIRect &)56 void onSetScissorRect(const SkIRect&) override {} onBindTextures(const GrGeometryProcessor &,const GrSurfaceProxy * const geomProcTextures[],const GrPipeline &)57 bool onBindTextures(const GrGeometryProcessor&, 58 const GrSurfaceProxy* const geomProcTextures[], 59 const GrPipeline&) override { 60 return true; 61 } onBindBuffers(sk_sp<const GrBuffer> indexBuffer,sk_sp<const GrBuffer> instanceBuffer,sk_sp<const GrBuffer> vertexBuffer,GrPrimitiveRestart)62 void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer, 63 sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override {} onDraw(int,int)64 void onDraw(int, int) override { this->noopDraw(); } onDrawIndexed(int,int,uint16_t,uint16_t,int)65 void onDrawIndexed(int, int, uint16_t, uint16_t, int) override { this->noopDraw(); } onDrawInstanced(int,int,int,int)66 void onDrawInstanced(int, int, int, int) override { this->noopDraw(); } onDrawIndexedInstanced(int,int,int,int,int)67 void onDrawIndexedInstanced(int, int, int, int, int) override { this->noopDraw(); } onDrawIndirect(const GrBuffer *,size_t,int)68 void onDrawIndirect(const GrBuffer*, size_t, int) override { this->noopDraw(); } onDrawIndexedIndirect(const GrBuffer *,size_t,int)69 void onDrawIndexedIndirect(const GrBuffer*, size_t, int) override { this->noopDraw(); } onClear(const GrScissorState & scissor,std::array<float,4>)70 void onClear(const GrScissorState& scissor, std::array<float, 4>) override { 71 this->markRenderTargetDirty(); 72 } onClearStencilClip(const GrScissorState & scissor,bool insideStencilMask)73 void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override {} noopDraw()74 void noopDraw() { 75 this->markRenderTargetDirty(); 76 ++fNumDraws; 77 } markRenderTargetDirty()78 void markRenderTargetDirty() { 79 if (auto* tex = fRenderTarget->asTexture()) { 80 tex->markMipmapsDirty(); 81 } 82 } 83 84 GrMockGpu* fGpu; 85 GrLoadOp fColorLoadOp; 86 int fNumDraws = 0; 87 88 using INHERITED = GrOpsRenderPass; 89 }; 90 91 #endif 92