egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 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 GrGpuCommandBuffer_DEFINED |
| 9 | #define GrGpuCommandBuffer_DEFINED |
| 10 | |
| 11 | #include "GrColor.h" |
| 12 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 13 | class GrGpu; |
| 14 | class GrMesh; |
| 15 | class GrPipeline; |
| 16 | class GrPrimitiveProcessor; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 17 | class GrRenderTarget; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 18 | struct SkIRect; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 19 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 20 | /** |
| 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 | */ |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 26 | class GrGpuCommandBuffer { |
| 27 | public: |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 28 | 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; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 43 | }; |
| 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. |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 53 | // 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 | |
| 78 | private: |
| 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 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | #endif |