| 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: | 
|---|
| 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(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer, | 
|---|
| 41 | sk_sp<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 GrScissorState& scissor, const SkPMColor4f&) override { | 
|---|
| 49 | this->markRenderTargetDirty(); | 
|---|
| 50 | } | 
|---|
| 51 | void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override {} | 
|---|
| 52 | void dummyDraw() { | 
|---|
| 53 | this->markRenderTargetDirty(); | 
|---|
| 54 | ++fNumDraws; | 
|---|
| 55 | } | 
|---|
| 56 | void markRenderTargetDirty() { | 
|---|
| 57 | if (auto* tex = fRenderTarget->asTexture()) { | 
|---|
| 58 | tex->markMipmapsDirty(); | 
|---|
| 59 | } | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | GrMockGpu* fGpu; | 
|---|
| 63 | GrLoadOp fColorLoadOp; | 
|---|
| 64 | int fNumDraws = 0; | 
|---|
| 65 |  | 
|---|
| 66 | typedef GrOpsRenderPass INHERITED; | 
|---|
| 67 | }; | 
|---|
| 68 |  | 
|---|
| 69 | #endif | 
|---|
| 70 |  | 
|---|