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