• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2016 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 GrOpsRenderPass_DEFINED
9 #define GrOpsRenderPass_DEFINED
10 
11 #include "include/core/SkDrawable.h"
12 #include "src/gpu/GrPipeline.h"
13 #include "src/gpu/ops/GrDrawOp.h"
14 
15 class GrOpFlushState;
16 class GrFixedClip;
17 class GrGpu;
18 class GrMesh;
19 class GrPipeline;
20 class GrPrimitiveProcessor;
21 class GrProgramInfo;
22 class GrRenderTarget;
23 class GrSemaphore;
24 struct SkIRect;
25 struct SkRect;
26 
27 /**
28  * The GrOpsRenderPass is a series of commands (draws, clears, and discards), which all target the
29  * same render target. It is possible that these commands execute immediately (GL), or get buffered
30  * up for later execution (Vulkan). GrOps execute into a GrOpsRenderPass.
31  */
32 class GrOpsRenderPass {
33 public:
~GrOpsRenderPass()34     virtual ~GrOpsRenderPass() {}
35 
36     struct LoadAndStoreInfo {
37         GrLoadOp    fLoadOp;
38         GrStoreOp   fStoreOp;
39         SkPMColor4f fClearColor;
40     };
41 
42     // Load-time clears of the stencil buffer are always to 0 so we don't store
43     // an 'fStencilClearValue'
44     struct StencilLoadAndStoreInfo {
45         GrLoadOp  fLoadOp;
46         GrStoreOp fStoreOp;
47     };
48 
49     virtual void begin() = 0;
50     // Signals the end of recording to the GrOpsRenderPass and that it can now be submitted.
51     virtual void end() = 0;
52 
53     // Updates the internal pipeline state for drawing with the provided GrProgramInfo.
54     // Returns false if the state could not be set.
55     void bindPipeline(const GrProgramInfo&, const SkRect& drawBounds);
56 
57     // Draws the given array of meshes using the current pipeline state. The client must call
58     // bindPipeline() before using this method.
59     //
60     // NOTE: This method will soon be replaced by individual calls for each draw type (indexed,
61     // instanced, indexed-patterned, indirect, etc.).
62     void drawMeshes(const GrProgramInfo&, const GrMesh[], int meshCount);
63 
64     // Performs an upload of vertex data in the middle of a set of a set of draws
65     virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0;
66 
67     /**
68      * Clear the owned render target. Ignores the draw state and clip.
69      */
70     void clear(const GrFixedClip&, const SkPMColor4f&);
71 
72     void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
73 
74     /**
75      * Executes the SkDrawable object for the underlying backend.
76      */
77     void executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>);
78 
79 protected:
GrOpsRenderPass()80     GrOpsRenderPass() : fOrigin(kTopLeft_GrSurfaceOrigin), fRenderTarget(nullptr) {}
81 
GrOpsRenderPass(GrRenderTarget * rt,GrSurfaceOrigin origin)82     GrOpsRenderPass(GrRenderTarget* rt, GrSurfaceOrigin origin)
83             : fOrigin(origin)
84             , fRenderTarget(rt) {
85     }
86 
set(GrRenderTarget * rt,GrSurfaceOrigin origin)87     void set(GrRenderTarget* rt, GrSurfaceOrigin origin) {
88         SkASSERT(!fRenderTarget);
89 
90         fRenderTarget = rt;
91         fOrigin = origin;
92     }
93 
94     GrSurfaceOrigin fOrigin;
95     GrRenderTarget* fRenderTarget;
96 
97 private:
98     virtual GrGpu* gpu() = 0;
99 
100     // overridden by backend-specific derived class to perform the rendering command.
101     virtual bool onBindPipeline(const GrProgramInfo&, const SkRect& drawBounds) = 0;
102     virtual void onDrawMeshes(const GrProgramInfo&, const GrMesh[], int meshCount) = 0;
103     virtual void onClear(const GrFixedClip&, const SkPMColor4f&) = 0;
104     virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0;
onExecuteDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>)105     virtual void onExecuteDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {}
106 
107     enum class DrawPipelineStatus {
108         kOk = 0,
109         kNotConfigured,
110         kFailedToBind
111     };
112 
113     DrawPipelineStatus fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
114 
115     typedef GrOpsRenderPass INHERITED;
116 };
117 
118 #endif
119