• 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 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 
gpu()25     GrGpu* gpu() override { return fGpu; }
inlineUpload(GrOpFlushState *,GrDeferredTextureUploadFn &)26     void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) override {}
27 
numDraws()28     int numDraws() const { return fNumDraws; }
29 
30 private:
onBegin()31     void onBegin() override {
32         if (GrLoadOp::kClear == fColorLoadOp) {
33             this->markRenderTargetDirty();
34         }
35     }
onBindPipeline(const GrProgramInfo &,const SkRect &)36     bool onBindPipeline(const GrProgramInfo&, const SkRect&) override { return true; }
onSetScissorRect(const SkIRect &)37     void onSetScissorRect(const SkIRect&) override {}
onBindTextures(const GrGeometryProcessor &,const GrSurfaceProxy * const geomProcTextures[],const GrPipeline &)38     bool onBindTextures(const GrGeometryProcessor&,
39                         const GrSurfaceProxy* const geomProcTextures[],
40                         const GrPipeline&) override {
41         return true;
42     }
onBindBuffers(sk_sp<const GrBuffer> indexBuffer,sk_sp<const GrBuffer> instanceBuffer,sk_sp<const GrBuffer> vertexBuffer,GrPrimitiveRestart)43     void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
44                        sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override {}
onDraw(int,int)45     void onDraw(int, int) override { this->noopDraw(); }
onDrawIndexed(int,int,uint16_t,uint16_t,int)46     void onDrawIndexed(int, int, uint16_t, uint16_t, int) override { this->noopDraw(); }
onDrawInstanced(int,int,int,int)47     void onDrawInstanced(int, int, int, int) override { this->noopDraw(); }
onDrawIndexedInstanced(int,int,int,int,int)48     void onDrawIndexedInstanced(int, int, int, int, int) override { this->noopDraw(); }
onDrawIndirect(const GrBuffer *,size_t,int)49     void onDrawIndirect(const GrBuffer*, size_t, int) override { this->noopDraw(); }
onDrawIndexedIndirect(const GrBuffer *,size_t,int)50     void onDrawIndexedIndirect(const GrBuffer*, size_t, int) override { this->noopDraw(); }
onClear(const GrScissorState & scissor,std::array<float,4>)51     void onClear(const GrScissorState& scissor, std::array<float, 4>) override {
52         this->markRenderTargetDirty();
53     }
onClearStencilClip(const GrScissorState & scissor,bool insideStencilMask)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