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 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 8 | #ifndef GrOpsRenderPass_DEFINED |
| 9 | #define GrOpsRenderPass_DEFINED |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkDrawable.h" |
| 12 | #include "src/gpu/GrPipeline.h" |
| 13 | #include "src/gpu/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; |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 22 | class GrSemaphore; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 23 | struct SkIRect; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 24 | struct SkRect; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 25 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 26 | /** |
| 27 | * The GrOpsRenderPass is a series of commands (draws, clears, and discards), which all target the |
| 28 | * same render target. It is possible that these commands execute immediately (GL), or get buffered |
| 29 | * up for later execution (Vulkan). GrOps execute into a GrOpsRenderPass. |
| 30 | */ |
| 31 | class GrOpsRenderPass { |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 32 | public: |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 33 | virtual ~GrOpsRenderPass() {} |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 34 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 35 | virtual void insertEventMarker(const char*) = 0; |
| 36 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 37 | struct LoadAndStoreInfo { |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 38 | GrLoadOp fLoadOp; |
| 39 | GrStoreOp fStoreOp; |
| 40 | SkPMColor4f fClearColor; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 43 | // Load-time clears of the stencil buffer are always to 0 so we don't store |
| 44 | // an 'fStencilClearValue' |
| 45 | struct StencilLoadAndStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 46 | GrLoadOp fLoadOp; |
| 47 | GrStoreOp fStoreOp; |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 50 | virtual void begin() = 0; |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 51 | // Signals the end of recording to the GrOpsRenderPass and that it can now be submitted. |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 52 | virtual void end() = 0; |
| 53 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 54 | // We pass in an array of meshCount GrMesh to the draw. The backend should loop over each |
| 55 | // GrMesh object and emit a draw for it. Each draw will use the same GrPipeline and |
| 56 | // GrPrimitiveProcessor. This may fail if the draw would exceed any resource limits (e.g. |
| 57 | // number of vertex attributes is too large). |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 58 | bool draw(const GrPrimitiveProcessor&, |
| 59 | const GrPipeline&, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 60 | const GrPipeline::FixedDynamicState*, |
| 61 | const GrPipeline::DynamicStateArrays*, |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 62 | const GrMesh[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 63 | int meshCount, |
| 64 | const SkRect& bounds); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 65 | |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 66 | // 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] | 67 | virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 68 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 69 | /** |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 70 | * Clear the owned render target. Ignores the draw state and clip. |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 71 | */ |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 72 | void clear(const GrFixedClip&, const SkPMColor4f&); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 73 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 74 | void clearStencilClip(const GrFixedClip&, bool insideStencilMask); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 75 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 76 | /** |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 77 | * Executes the SkDrawable object for the underlying backend. |
| 78 | */ |
| 79 | virtual void executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {} |
| 80 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 81 | protected: |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 82 | GrOpsRenderPass() : fOrigin(kTopLeft_GrSurfaceOrigin), fRenderTarget(nullptr) {} |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 83 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 84 | GrOpsRenderPass(GrRenderTarget* rt, GrSurfaceOrigin origin) |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 85 | : fOrigin(origin) |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 86 | , fRenderTarget(rt) { |
| 87 | } |
| 88 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 89 | void set(GrRenderTarget* rt, GrSurfaceOrigin origin) { |
| 90 | SkASSERT(!fRenderTarget); |
| 91 | |
| 92 | fRenderTarget = rt; |
| 93 | fOrigin = origin; |
| 94 | } |
| 95 | |
| 96 | GrSurfaceOrigin fOrigin; |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 97 | GrRenderTarget* fRenderTarget; |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 98 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 99 | private: |
| 100 | virtual GrGpu* gpu() = 0; |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 101 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 102 | // overridden by backend-specific derived class to perform the draw call. |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 103 | virtual void onDraw(const GrPrimitiveProcessor&, |
| 104 | const GrPipeline&, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 105 | const GrPipeline::FixedDynamicState*, |
| 106 | const GrPipeline::DynamicStateArrays*, |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 107 | const GrMesh[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 108 | int meshCount, |
| 109 | const SkRect& bounds) = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 110 | |
| 111 | // overridden by backend-specific derived class to perform the clear. |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 112 | virtual void onClear(const GrFixedClip&, const SkPMColor4f&) = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 113 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 114 | virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 115 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 116 | typedef GrOpsRenderPass INHERITED; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | #endif |