blob: 9abcc20fc712777870ffba939ef405f97105e62c [file] [log] [blame]
egdaniel066df7c2016-06-08 14:02:27 -07001/*
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 GrGpuCommandBuffer_DEFINED
9#define GrGpuCommandBuffer_DEFINED
10
11#include "GrColor.h"
12
egdaniel9cb63402016-06-23 08:37:05 -070013class GrGpu;
14class GrMesh;
15class GrPipeline;
16class GrPrimitiveProcessor;
egdaniel066df7c2016-06-08 14:02:27 -070017class GrRenderTarget;
egdaniel9cb63402016-06-23 08:37:05 -070018struct SkIRect;
egdaniel066df7c2016-06-08 14:02:27 -070019
egdaniel9cb63402016-06-23 08:37:05 -070020/**
21 * The GrGpuCommandBuffer is a series of commands (draws, clears, and discards), which all target
22 * the same render target. It is possible that these commands execute immediately (GL), or get
23 * buffered up for later execution (Vulkan). GrBatches will execute their draw commands into a
24 * GrGpuCommandBuffer.
25 */
egdaniel066df7c2016-06-08 14:02:27 -070026class GrGpuCommandBuffer {
27public:
egdaniel9cb63402016-06-23 08:37:05 -070028 enum class LoadOp {
29 kLoad,
30 kClear,
31 kDiscard,
32 };
33
34 enum class StoreOp {
35 kStore,
36 kDiscard,
37 };
38
39 struct LoadAndStoreInfo {
40 LoadOp fLoadOp;
41 StoreOp fStoreOp;
42 GrColor fClearColor;
egdaniel066df7c2016-06-08 14:02:27 -070043 };
44
45 GrGpuCommandBuffer() {}
46 virtual ~GrGpuCommandBuffer() {}
47
48 // Signals the end of recording to the command buffer and that it can now be submitted.
49 virtual void end() = 0;
50
51 // Sends the command buffer off to the GPU object to execute the commands built up in the
52 // buffer. The gpu object is allowed to defer execution of the commands until it is flushed.
egdaniel9cb63402016-06-23 08:37:05 -070053 // The bounds should represent the bounds of all the draws put into the command buffer.
54 void submit(const SkIRect& bounds);
55
56 // We pass in an array of meshCount GrMesh to the draw. The backend should loop over each
57 // GrMesh object and emit a draw for it. Each draw will use the same GrPipeline and
58 // GrPrimitiveProcessor. This may fail if the draw would exceed any resource limits (e.g.
59 // number of vertex attributes is too large).
60 bool draw(const GrPipeline&,
61 const GrPrimitiveProcessor&,
62 const GrMesh*,
63 int meshCount);
64
65 /**
66 * Clear the passed in render target. Ignores the draw state and clip.
67 */
68 void clear(const SkIRect& rect, GrColor color, GrRenderTarget* renderTarget);
69
70 void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* renderTarget);
71 /**
72 * Discards the contents render target. nullptr indicates that the current render target should
73 * be discarded.
74 **/
75 // TODO: This should be removed in the future to favor using the load and store ops for discard
76 virtual void discard(GrRenderTarget* = nullptr) = 0;
77
78private:
79 virtual GrGpu* gpu() = 0;
80 virtual void onSubmit(const SkIRect& bounds) = 0;
81
82 // overridden by backend-specific derived class to perform the draw call.
83 virtual void onDraw(const GrPipeline&,
84 const GrPrimitiveProcessor&,
85 const GrMesh*,
86 int meshCount) = 0;
87
88 // overridden by backend-specific derived class to perform the clear.
89 virtual void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) = 0;
90
91 virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) = 0;
92
egdaniel066df7c2016-06-08 14:02:27 -070093};
94
95#endif