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" |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 12 | #include "GrPipeline.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 13 | #include "ops/GrDrawOp.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 14 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 15 | class GrOpFlushState; |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 16 | class GrFixedClip; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 17 | class GrGpu; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 18 | class GrMesh; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 19 | class GrPipeline; |
| 20 | class GrPrimitiveProcessor; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 21 | class GrRenderTarget; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 22 | struct SkIRect; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 23 | struct SkRect; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 24 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 25 | class GrGpuRTCommandBuffer; |
| 26 | |
| 27 | class GrGpuCommandBuffer { |
| 28 | public: |
| 29 | virtual ~GrGpuCommandBuffer() {} |
| 30 | |
| 31 | // Copy src into current surface owned by either a GrGpuTextureCommandBuffer or |
| 32 | // GrGpuRenderTargetCommandBuffer. |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 33 | virtual void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, |
| 34 | const SkIRect& srcRect, const SkIPoint& dstPoint) = 0; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 35 | |
| 36 | virtual void insertEventMarker(const char*) = 0; |
| 37 | |
| 38 | virtual GrGpuRTCommandBuffer* asRTCommandBuffer() { return nullptr; } |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class GrGpuTextureCommandBuffer : public GrGpuCommandBuffer{ |
| 42 | public: |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 43 | void set(GrTexture* texture, GrSurfaceOrigin origin) { |
| 44 | SkASSERT(!fTexture); |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 45 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 46 | fOrigin = origin; |
| 47 | fTexture = texture; |
| 48 | } |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 49 | |
| 50 | protected: |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 51 | GrGpuTextureCommandBuffer() : fOrigin(kTopLeft_GrSurfaceOrigin), fTexture(nullptr) {} |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 52 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 53 | GrGpuTextureCommandBuffer(GrTexture* texture, GrSurfaceOrigin origin) |
| 54 | : fOrigin(origin) |
| 55 | , fTexture(texture) { |
| 56 | } |
| 57 | |
| 58 | GrSurfaceOrigin fOrigin; |
| 59 | GrTexture* fTexture; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | typedef GrGpuCommandBuffer INHERITED; |
| 63 | }; |
| 64 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 65 | /** |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 66 | * The GrGpuRenderTargetCommandBuffer is a series of commands (draws, clears, and discards), which |
| 67 | * all target the same render target. It is possible that these commands execute immediately (GL), |
| 68 | * or get buffered up for later execution (Vulkan). GrOps will execute their draw commands into a |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 69 | * GrGpuCommandBuffer. |
| 70 | */ |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 71 | class GrGpuRTCommandBuffer : public GrGpuCommandBuffer { |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 72 | public: |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 73 | struct LoadAndStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 74 | GrLoadOp fLoadOp; |
| 75 | GrStoreOp fStoreOp; |
| 76 | GrColor fClearColor; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 79 | // Load-time clears of the stencil buffer are always to 0 so we don't store |
| 80 | // an 'fStencilClearValue' |
| 81 | struct StencilLoadAndStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 82 | GrLoadOp fLoadOp; |
| 83 | GrStoreOp fStoreOp; |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 84 | }; |
| 85 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 86 | GrGpuRTCommandBuffer* asRTCommandBuffer() { return this; } |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 87 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 88 | virtual void begin() = 0; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 89 | // Signals the end of recording to the command buffer and that it can now be submitted. |
| 90 | virtual void end() = 0; |
| 91 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 92 | // We pass in an array of meshCount GrMesh to the draw. The backend should loop over each |
| 93 | // GrMesh object and emit a draw for it. Each draw will use the same GrPipeline and |
| 94 | // GrPrimitiveProcessor. This may fail if the draw would exceed any resource limits (e.g. |
| 95 | // number of vertex attributes is too large). |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 96 | bool draw(const GrPrimitiveProcessor&, |
| 97 | const GrPipeline&, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 98 | const GrPipeline::FixedDynamicState*, |
| 99 | const GrPipeline::DynamicStateArrays*, |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 100 | const GrMesh[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 101 | int meshCount, |
| 102 | const SkRect& bounds); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 103 | |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 104 | // Performs an upload of vertex data in the middle of a set of a set of draws |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 105 | virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 106 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 107 | /** |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 108 | * Clear the owned render target. Ignores the draw state and clip. |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 109 | */ |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 110 | void clear(const GrFixedClip&, GrColor); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 111 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 112 | void clearStencilClip(const GrFixedClip&, bool insideStencilMask); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 113 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 114 | /** |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 115 | * Discards the contents render target. |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 116 | */ |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 117 | // TODO: This should be removed in the future to favor using the load and store ops for discard |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 118 | virtual void discard() = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 119 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 120 | protected: |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 121 | GrGpuRTCommandBuffer() : fOrigin(kTopLeft_GrSurfaceOrigin), fRenderTarget(nullptr) {} |
| 122 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 123 | GrGpuRTCommandBuffer(GrRenderTarget* rt, GrSurfaceOrigin origin) |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 124 | : fOrigin(origin) |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 125 | , fRenderTarget(rt) { |
| 126 | } |
| 127 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 128 | void set(GrRenderTarget* rt, GrSurfaceOrigin origin) { |
| 129 | SkASSERT(!fRenderTarget); |
| 130 | |
| 131 | fRenderTarget = rt; |
| 132 | fOrigin = origin; |
| 133 | } |
| 134 | |
| 135 | GrSurfaceOrigin fOrigin; |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 136 | GrRenderTarget* fRenderTarget; |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 137 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 138 | private: |
| 139 | virtual GrGpu* gpu() = 0; |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 140 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 141 | // overridden by backend-specific derived class to perform the draw call. |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 142 | virtual void onDraw(const GrPrimitiveProcessor&, |
| 143 | const GrPipeline&, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 144 | const GrPipeline::FixedDynamicState*, |
| 145 | const GrPipeline::DynamicStateArrays*, |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 146 | const GrMesh[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 147 | int meshCount, |
| 148 | const SkRect& bounds) = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 149 | |
| 150 | // overridden by backend-specific derived class to perform the clear. |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 151 | virtual void onClear(const GrFixedClip&, GrColor) = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 152 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 153 | virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 154 | |
| 155 | typedef GrGpuCommandBuffer INHERITED; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | #endif |