reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 8 | #ifndef GrRenderTargetOpList_DEFINED |
| 9 | #define GrRenderTargetOpList_DEFINED |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 11 | #include "GrClip.h" |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 12 | #include "GrContext.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 13 | #include "GrOpList.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 14 | #include "GrPathProcessor.h" |
| 15 | #include "GrPrimitiveProcessor.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 16 | #include "GrPathRendering.h" |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 17 | #include "GrXferProcessor.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 18 | |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 19 | #include "ops/GrDrawOp.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 20 | |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 21 | #include "SkClipStack.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 22 | #include "SkMatrix.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 23 | #include "SkPath.h" |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 24 | #include "SkStringUtils.h" |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 25 | #include "SkStrokeRec.h" |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 26 | #include "SkTArray.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 27 | #include "SkTLazy.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 28 | #include "SkTypes.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 29 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 30 | class GrAuditTrail; |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 31 | class GrClearOp; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 32 | class GrClip; |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 33 | class GrCaps; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 34 | class GrPath; |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 35 | class GrDrawPathOpBase; |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 36 | class GrOp; |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 37 | class GrPipelineBuilder; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 38 | class GrRenderTargetProxy; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 39 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 40 | class GrRenderTargetOpList final : public GrOpList { |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 41 | public: |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 42 | /** Options for GrRenderTargetOpList behavior. */ |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 43 | struct Options { |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 44 | bool fClipDrawOpsToBounds = false; |
| 45 | int fMaxOpCombineLookback = -1; |
| 46 | int fMaxOpCombineLookahead = -1; |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 47 | }; |
| 48 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 49 | GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrResourceProvider*, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 50 | GrAuditTrail*, const Options&); |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 51 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 52 | ~GrRenderTargetOpList() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 53 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 54 | void makeClosed() override { |
| 55 | INHERITED::makeClosed(); |
| 56 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 57 | fLastFullClearOp = nullptr; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 58 | this->forwardCombine(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 59 | } |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 60 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 61 | /** |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 62 | * Empties the draw buffer of any queued up draws. |
| 63 | */ |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 64 | void reset() override; |
| 65 | |
| 66 | void abandonGpuResources() override; |
| 67 | void freeGpuResources() override; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 70 | * Together these two functions flush all queued up draws to GrCommandBuffer. The return value |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 71 | * of executeOps() indicates whether any commands were actually issued to the GPU. |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 72 | */ |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 73 | void prepareOps(GrOpFlushState* flushState) override; |
| 74 | bool executeOps(GrOpFlushState* flushState) override; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 77 | * Gets the capabilities of the draw target. |
| 78 | */ |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 79 | const GrCaps* caps() const { return fGpu->caps(); } |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 80 | |
Brian Salomon | 21aa35f | 2016-12-09 16:01:53 -0500 | [diff] [blame] | 81 | void addDrawOp(const GrPipelineBuilder&, GrRenderTargetContext*, const GrClip&, |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 82 | std::unique_ptr<GrDrawOp>); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 83 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 84 | void addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 85 | this->recordOp(std::move(op), renderTargetContext); |
| 86 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 87 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 88 | /** |
csmartdalton | 5c6fc4f | 2016-08-12 15:11:51 -0700 | [diff] [blame] | 89 | * Draws the path into user stencil bits. Upon return, all user stencil values |
| 90 | * inside the path will be nonzero. The path's fill must be either even/odd or |
| 91 | * winding (notnverse or hairline).It will respect the HW antialias boolean (if |
| 92 | * possible in the 3D API). Note, we will never have an inverse fill with |
| 93 | * stencil path. |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 94 | */ |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 95 | void stencilPath(GrRenderTargetContext*, |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 96 | const GrClip&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 97 | GrAAType aa, |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 98 | const SkMatrix& viewMatrix, |
| 99 | const GrPath*); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 100 | |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 101 | /** Clears the entire render target */ |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 102 | void fullClear(GrRenderTargetContext*, GrColor color); |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 103 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 104 | /** Discards the contents render target. */ |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 105 | void discard(GrRenderTargetContext*); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 106 | |
| 107 | /** |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 108 | * Copies a pixel rectangle from one surface to another. This call may finalize |
| 109 | * reserved vertex/index data (as though a draw call was made). The src pixels |
| 110 | * copied are specified by srcRect. They are copied to a rect of the same |
| 111 | * size in dst with top left at dstPoint. If the src rect is clipped by the |
| 112 | * src bounds then pixel values in the dst rect corresponding to area clipped |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 113 | * by the src rect are not overwritten. This method is not guaranteed to succeed |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 114 | * depending on the type of surface, configs, etc, and the backend-specific |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 115 | * limitations. |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 116 | */ |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 117 | bool copySurface(GrSurface* dst, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 118 | GrSurface* src, |
| 119 | const SkIRect& srcRect, |
| 120 | const SkIPoint& dstPoint); |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 121 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 122 | gr_instanced::InstancedRendering* instancedRendering() const { |
| 123 | SkASSERT(fInstancedRendering); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 124 | return fInstancedRendering.get(); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 125 | } |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 126 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 127 | GrRenderTargetOpList* asRenderTargetOpList() override { return this; } |
| 128 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 129 | SkDEBUGCODE(void dump() const override;) |
| 130 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 131 | private: |
csmartdalton | 7cdda99 | 2016-11-01 07:03:03 -0700 | [diff] [blame] | 132 | friend class GrRenderTargetContextPriv; // for clearStencilClip and stencil clip state. |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 133 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 134 | // If the input op is combined with an earlier op, this returns the combined op. Otherwise, it |
| 135 | // returns the input op. |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 136 | GrOp* recordOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) { |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 137 | SkRect bounds = op->bounds(); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 138 | return this->recordOp(std::move(op), renderTargetContext, bounds); |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | // Variant that allows an explicit bounds (computed from the Op's bounds and a clip). |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 142 | GrOp* recordOp(std::unique_ptr<GrOp>, GrRenderTargetContext*, const SkRect& clippedBounds); |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 143 | |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 144 | void forwardCombine(); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 145 | |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 146 | // Makes a copy of the dst if it is necessary for the draw and returns the texture that should |
| 147 | // be used by GrXferProcessor to access the destination color. If the texture is nullptr then |
| 148 | // a texture copy could not be made. |
| 149 | void setupDstTexture(GrRenderTarget*, |
| 150 | const GrClip&, |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 151 | const SkRect& opBounds, |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 152 | GrXferProcessor::DstTexture*); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 153 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 154 | // Used only via GrRenderTargetContextPriv. |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 155 | void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTargetContext*); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 156 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 157 | struct RecordedOp { |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 158 | std::unique_ptr<GrOp> fOp; |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 159 | SkRect fClippedBounds; |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 160 | // TODO: Use proxy ID instead of instantiated render target ID. |
| 161 | GrGpuResource::UniqueID fRenderTargetID; |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 162 | }; |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 163 | SkSTArray<256, RecordedOp, true> fRecordedOps; |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 164 | |
| 165 | GrClearOp* fLastFullClearOp = nullptr; |
| 166 | GrGpuResource::UniqueID fLastFullClearRenderTargetID = GrGpuResource::UniqueID::InvalidID(); |
| 167 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 168 | // The context is only in service of the GrClip, remove once it doesn't need this. |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 169 | GrContext* fContext; |
| 170 | GrGpu* fGpu; |
| 171 | GrResourceProvider* fResourceProvider; |
joshualitt | 3bdd7dc | 2014-10-31 08:27:39 -0700 | [diff] [blame] | 172 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 173 | bool fClipOpToBounds; |
| 174 | int fMaxOpLookback; |
| 175 | int fMaxOpLookahead; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 176 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 177 | std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 178 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 179 | int32_t fLastClipStackGenID; |
| 180 | SkIRect fLastClipStackRect; |
| 181 | SkIPoint fLastClipOrigin; |
csmartdalton | 7cdda99 | 2016-11-01 07:03:03 -0700 | [diff] [blame] | 182 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 183 | typedef GrOpList INHERITED; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 186 | #endif |