| 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/GrTexturePriv.h" | 
| 14 | #include "src/gpu/mock/GrMockGpu.h" | 
| 15 |  | 
| 16 | class GrMockOpsRenderPass : public GrOpsRenderPass { | 
| 17 | public: | 
| 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 |  | 
| 28 |     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 GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[], | 
| 39 |                         const GrPipeline&) override { return true; } | 
| 40 |     void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer, | 
| 41 |                        const GrBuffer* vertexBuffer, GrPrimitiveRestart) override {} | 
| 42 |     void onDraw(int, int) override { this->dummyDraw(); } | 
| 43 |     void onDrawIndexed(int, int, uint16_t, uint16_t, int) override { this->dummyDraw(); } | 
| 44 |     void onDrawInstanced(int, int, int, int) override { this->dummyDraw(); } | 
| 45 |     void onDrawIndexedInstanced(int, int, int, int, int) override { this->dummyDraw(); } | 
| 46 |     void onDrawIndirect(const GrBuffer*, size_t, int) override { this->dummyDraw(); } | 
| 47 |     void onDrawIndexedIndirect(const GrBuffer*, size_t, int) override { this->dummyDraw(); } | 
| 48 |     void onClear(const GrFixedClip&, const SkPMColor4f&) override { this->markRenderTargetDirty(); } | 
| 49 |     void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override {} | 
| 50 |     void dummyDraw() { | 
| 51 |         this->markRenderTargetDirty(); | 
| 52 |         ++fNumDraws; | 
| 53 |     } | 
| 54 |     void markRenderTargetDirty() { | 
| 55 |         if (auto* tex = fRenderTarget->asTexture()) { | 
| 56 |             tex->texturePriv().markMipMapsDirty(); | 
| 57 |         } | 
| 58 |     } | 
| 59 |  | 
| 60 |     GrMockGpu* fGpu; | 
| 61 |     GrLoadOp fColorLoadOp; | 
| 62 |     int fNumDraws = 0; | 
| 63 |  | 
| 64 |     typedef GrOpsRenderPass INHERITED; | 
| 65 | }; | 
| 66 |  | 
| 67 | #endif | 
| 68 |  |