blob: b23ee5646ceabdb83c8b783daed52b4729bb9ba3 [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
Greg Daniel2d41d0d2019-08-26 11:08:51 -04008#ifndef GrOpsRenderPass_DEFINED
9#define GrOpsRenderPass_DEFINED
egdaniel066df7c2016-06-08 14:02:27 -070010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkDrawable.h"
12#include "src/gpu/GrPipeline.h"
13#include "src/gpu/ops/GrDrawOp.h"
egdaniel066df7c2016-06-08 14:02:27 -070014
Brian Salomon742e31d2016-12-07 17:06:19 -050015class GrOpFlushState;
csmartdalton29df7602016-08-31 11:55:52 -070016class GrFixedClip;
egdaniel9cb63402016-06-23 08:37:05 -070017class GrGpu;
Chris Daltonbca46e22017-05-15 11:03:26 -060018class GrMesh;
egdaniel9cb63402016-06-23 08:37:05 -070019class GrPipeline;
20class GrPrimitiveProcessor;
egdaniel066df7c2016-06-08 14:02:27 -070021class GrRenderTarget;
Greg Daniel64cc9aa2018-10-19 13:54:56 -040022class GrSemaphore;
egdaniel9cb63402016-06-23 08:37:05 -070023struct SkIRect;
Greg Daniel36a77ee2016-10-18 10:33:25 -040024struct SkRect;
egdaniel066df7c2016-06-08 14:02:27 -070025
Greg Daniel2d41d0d2019-08-26 11:08:51 -040026/**
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 */
31class GrOpsRenderPass {
Greg Daniel500d58b2017-08-24 15:59:33 -040032public:
Greg Daniel2d41d0d2019-08-26 11:08:51 -040033 virtual ~GrOpsRenderPass() {}
Greg Daniel500d58b2017-08-24 15:59:33 -040034
Greg Daniel500d58b2017-08-24 15:59:33 -040035 virtual void insertEventMarker(const char*) = 0;
36
egdaniel9cb63402016-06-23 08:37:05 -070037 struct LoadAndStoreInfo {
Brian Osman9a9baae2018-11-05 15:06:26 -050038 GrLoadOp fLoadOp;
39 GrStoreOp fStoreOp;
40 SkPMColor4f fClearColor;
egdaniel066df7c2016-06-08 14:02:27 -070041 };
42
Robert Phillips95214472017-08-08 18:00:03 -040043 // Load-time clears of the stencil buffer are always to 0 so we don't store
44 // an 'fStencilClearValue'
45 struct StencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -040046 GrLoadOp fLoadOp;
47 GrStoreOp fStoreOp;
Robert Phillips95214472017-08-08 18:00:03 -040048 };
49
Robert Phillips95214472017-08-08 18:00:03 -040050 virtual void begin() = 0;
Greg Daniel2d41d0d2019-08-26 11:08:51 -040051 // Signals the end of recording to the GrOpsRenderPass and that it can now be submitted.
egdaniel066df7c2016-06-08 14:02:27 -070052 virtual void end() = 0;
53
egdaniel9cb63402016-06-23 08:37:05 -070054 // 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 Salomonff168d92018-06-23 15:17:27 -040058 bool draw(const GrPrimitiveProcessor&,
59 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -040060 const GrPipeline::FixedDynamicState*,
61 const GrPipeline::DynamicStateArrays*,
Chris Daltonbca46e22017-05-15 11:03:26 -060062 const GrMesh[],
Greg Daniel36a77ee2016-10-18 10:33:25 -040063 int meshCount,
64 const SkRect& bounds);
egdaniel9cb63402016-06-23 08:37:05 -070065
Greg Daniel77b53f62016-10-18 11:48:51 -040066 // Performs an upload of vertex data in the middle of a set of a set of draws
Brian Salomon943ed792017-10-30 09:37:55 -040067 virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0;
Greg Daniel77b53f62016-10-18 11:48:51 -040068
egdaniel9cb63402016-06-23 08:37:05 -070069 /**
Jim Van Verth6a40abc2017-11-02 16:56:09 +000070 * Clear the owned render target. Ignores the draw state and clip.
Greg Daniel77b53f62016-10-18 11:48:51 -040071 */
Brian Osman9a9baae2018-11-05 15:06:26 -050072 void clear(const GrFixedClip&, const SkPMColor4f&);
egdaniel9cb63402016-06-23 08:37:05 -070073
Robert Phillips19e51dc2017-08-09 09:30:51 -040074 void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
Greg Daniel36a77ee2016-10-18 10:33:25 -040075
egdaniel9cb63402016-06-23 08:37:05 -070076 /**
Greg Daniel64cc9aa2018-10-19 13:54:56 -040077 * Executes the SkDrawable object for the underlying backend.
78 */
79 virtual void executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {}
80
Robert Phillips19e51dc2017-08-09 09:30:51 -040081protected:
Greg Daniel2d41d0d2019-08-26 11:08:51 -040082 GrOpsRenderPass() : fOrigin(kTopLeft_GrSurfaceOrigin), fRenderTarget(nullptr) {}
Robert Phillips5b5d84c2018-08-09 15:12:18 -040083
Greg Daniel2d41d0d2019-08-26 11:08:51 -040084 GrOpsRenderPass(GrRenderTarget* rt, GrSurfaceOrigin origin)
Robert Phillips5b5d84c2018-08-09 15:12:18 -040085 : fOrigin(origin)
Greg Daniel500d58b2017-08-24 15:59:33 -040086 , fRenderTarget(rt) {
87 }
88
Robert Phillips5b5d84c2018-08-09 15:12:18 -040089 void set(GrRenderTarget* rt, GrSurfaceOrigin origin) {
90 SkASSERT(!fRenderTarget);
91
92 fRenderTarget = rt;
93 fOrigin = origin;
94 }
95
96 GrSurfaceOrigin fOrigin;
Robert Phillips19e51dc2017-08-09 09:30:51 -040097 GrRenderTarget* fRenderTarget;
Robert Phillips65a88fa2017-08-08 08:36:22 -040098
egdaniel9cb63402016-06-23 08:37:05 -070099private:
100 virtual GrGpu* gpu() = 0;
Greg Daniel65a09272016-10-12 09:47:22 -0400101
egdaniel9cb63402016-06-23 08:37:05 -0700102 // overridden by backend-specific derived class to perform the draw call.
Brian Salomonff168d92018-06-23 15:17:27 -0400103 virtual void onDraw(const GrPrimitiveProcessor&,
104 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -0400105 const GrPipeline::FixedDynamicState*,
106 const GrPipeline::DynamicStateArrays*,
Chris Dalton46983b72017-06-06 12:27:16 -0600107 const GrMesh[],
Greg Daniel36a77ee2016-10-18 10:33:25 -0400108 int meshCount,
109 const SkRect& bounds) = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700110
111 // overridden by backend-specific derived class to perform the clear.
Brian Osman9a9baae2018-11-05 15:06:26 -0500112 virtual void onClear(const GrFixedClip&, const SkPMColor4f&) = 0;
egdaniel9cb63402016-06-23 08:37:05 -0700113
Robert Phillips19e51dc2017-08-09 09:30:51 -0400114 virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0;
Greg Daniel500d58b2017-08-24 15:59:33 -0400115
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400116 typedef GrOpsRenderPass INHERITED;
egdaniel066df7c2016-06-08 14:02:27 -0700117};
118
119#endif