| 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: |
| 37 |
GrMockOpsRenderPass(GrMockGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin, |
| 38 |
LoadAndStoreInfo colorInfo) |
| 39 |
: INHERITED(rt, origin) |
| 40 |
, fGpu(gpu) |
| 41 |
, fColorLoadOp(colorInfo.fLoadOp) { |
| 42 |
} |
| 43 |
|
| 44 |
GrGpu* gpu() override { return fGpu; } |
| 45 |
void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) override {} |
| 46 |
|
| 47 |
int numDraws() const { return fNumDraws; } |
| 48 |
|
| 49 |
private: |
| 50 |
void onBegin() override { |
| 51 |
if (GrLoadOp::kClear == fColorLoadOp) { |
| 52 |
this->markRenderTargetDirty(); |
| 53 |
} |
| 54 |
} |
| 55 |
bool onBindPipeline(const GrProgramInfo&, const SkRect&) override { return true; } |
| 56 |
void onSetScissorRect(const SkIRect&) override {} |
| 57 |
bool onBindTextures(const GrGeometryProcessor&, |
| 58 |
const GrSurfaceProxy* const geomProcTextures[], |
| 59 |
const GrPipeline&) override { |
| 60 |
return true; |
| 61 |
} |
| 62 |
void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer, |
| 63 |
sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override {} |
| 64 |
void onDraw(int, int) override { this->noopDraw(); } |
| 65 |
void onDrawIndexed(int, int, uint16_t, uint16_t, int) override { this->noopDraw(); } |
| 66 |
void onDrawInstanced(int, int, int, int) override { this->noopDraw(); } |
| 67 |
void onDrawIndexedInstanced(int, int, int, int, int) override { this->noopDraw(); } |
| 68 |
void onDrawIndirect(const GrBuffer*, size_t, int) override { this->noopDraw(); } |
| 69 |
void onDrawIndexedIndirect(const GrBuffer*, size_t, int) override { this->noopDraw(); } |
| 70 |
void onClear(const GrScissorState& scissor, std::array<float, 4>) override { |
| 71 |
this->markRenderTargetDirty(); |
| 72 |
} |
| 73 |
void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override {} |
| 74 |
void noopDraw() { |
| 75 |
this->markRenderTargetDirty(); |
| 76 |
++fNumDraws; |
| 77 |
} |
| 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 |