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 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 11 | #include "GrAppliedClip.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 12 | #include "GrOpList.h" |
Brian Salomon | c48af93 | 2017-03-16 19:51:42 +0000 | [diff] [blame] | 13 | #include "GrPathRendering.h" |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 14 | #include "GrPrimitiveProcessor.h" |
| 15 | #include "SkArenaAlloc.h" |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 16 | #include "SkClipStack.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 17 | #include "SkMatrix.h" |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 18 | #include "SkStringUtils.h" |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 19 | #include "SkStrokeRec.h" |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 20 | #include "SkTArray.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 21 | #include "SkTLazy.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 22 | #include "SkTypes.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 23 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 24 | class GrAuditTrail; |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 25 | class GrClearOp; |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 26 | class GrCaps; |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 27 | class GrOp; |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 28 | class GrPipelineBuilder; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 29 | class GrRenderTargetProxy; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 30 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 31 | class GrRenderTargetOpList final : public GrOpList { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 32 | private: |
| 33 | using DstTexture = GrXferProcessor::DstTexture; |
| 34 | |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 35 | public: |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 36 | /** Options for GrRenderTargetOpList behavior. */ |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 37 | struct Options { |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 38 | int fMaxOpCombineLookback = -1; |
| 39 | int fMaxOpCombineLookahead = -1; |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 40 | }; |
| 41 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 42 | GrRenderTargetOpList(sk_sp<GrRenderTargetProxy>, GrGpu*, GrResourceProvider*, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 43 | GrAuditTrail*, const Options&); |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 44 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 45 | ~GrRenderTargetOpList() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 47 | void makeClosed() override { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame^] | 48 | if (this->isClosed()) { |
| 49 | return; |
| 50 | } |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 51 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 52 | fLastFullClearOp = nullptr; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 53 | this->forwardCombine(); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame^] | 54 | |
| 55 | INHERITED::makeClosed(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 56 | } |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 57 | |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame^] | 58 | bool isEmpty() const { return fRecordedOps.empty(); } |
| 59 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | /** |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 61 | * Empties the draw buffer of any queued up draws. |
| 62 | */ |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 63 | void reset() override; |
| 64 | |
| 65 | void abandonGpuResources() override; |
| 66 | void freeGpuResources() override; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 69 | * 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] | 70 | * of executeOps() indicates whether any commands were actually issued to the GPU. |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 71 | */ |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 72 | void prepareOps(GrOpFlushState* flushState) override; |
| 73 | bool executeOps(GrOpFlushState* flushState) override; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 76 | * Gets the capabilities of the draw target. |
| 77 | */ |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 78 | const GrCaps* caps() const { return fGpu->caps(); } |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 79 | |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 80 | uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 81 | this->recordOp(std::move(op), renderTargetContext, nullptr, nullptr); |
| 82 | return this->uniqueID(); |
| 83 | } |
| 84 | uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext, |
| 85 | GrAppliedClip&& clip, const DstTexture& dstTexture) { |
| 86 | this->recordOp(std::move(op), renderTargetContext, clip.doesClip() ? &clip : nullptr, |
| 87 | &dstTexture); |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 88 | return this->uniqueID(); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 89 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 90 | |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 91 | /** Clears the entire render target */ |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 92 | void fullClear(GrRenderTargetContext*, GrColor color); |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 93 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 94 | /** |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 95 | * Copies a pixel rectangle from one surface to another. This call may finalize |
| 96 | * reserved vertex/index data (as though a draw call was made). The src pixels |
| 97 | * copied are specified by srcRect. They are copied to a rect of the same |
| 98 | * size in dst with top left at dstPoint. If the src rect is clipped by the |
| 99 | * src bounds then pixel values in the dst rect corresponding to area clipped |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 100 | * 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] | 101 | * depending on the type of surface, configs, etc, and the backend-specific |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 102 | * limitations. |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 103 | */ |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 104 | bool copySurface(GrResourceProvider* resourceProvider, |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 105 | GrRenderTargetContext* dst, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 106 | GrSurfaceProxy* src, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 107 | const SkIRect& srcRect, |
| 108 | const SkIPoint& dstPoint); |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 109 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 110 | gr_instanced::InstancedRendering* instancedRendering() const { |
| 111 | SkASSERT(fInstancedRendering); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 112 | return fInstancedRendering.get(); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 113 | } |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 114 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 115 | GrRenderTargetOpList* asRenderTargetOpList() override { return this; } |
| 116 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 117 | SkDEBUGCODE(void dump() const override;) |
| 118 | |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame] | 119 | SkDEBUGCODE(void validateTargetsSingleRenderTarget() const override;) |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 120 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 121 | private: |
Robert Phillips | b9a02a1 | 2017-04-06 11:08:40 -0400 | [diff] [blame] | 122 | friend class GrRenderTargetContextPriv; // for stencil clip state. TODO: this is invasive |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 123 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 124 | struct RecordedOp { |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 125 | RecordedOp(std::unique_ptr<GrOp> op, |
| 126 | GrRenderTarget* rt, |
| 127 | const GrAppliedClip* appliedClip, |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 128 | const DstTexture* dstTexture) |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 129 | : fOp(std::move(op)) |
| 130 | , fRenderTarget(rt) |
| 131 | , fAppliedClip(appliedClip) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 132 | if (dstTexture) { |
| 133 | fDstTexture = *dstTexture; |
| 134 | } |
| 135 | } |
| 136 | std::unique_ptr<GrOp> fOp; |
| 137 | // TODO: These ops will all to target the same render target and this won't be needed. |
| 138 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
| 139 | DstTexture fDstTexture; |
| 140 | const GrAppliedClip* fAppliedClip; |
| 141 | }; |
| 142 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 143 | // If the input op is combined with an earlier op, this returns the combined op. Otherwise, it |
| 144 | // returns the input op. |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 145 | GrOp* recordOp(std::unique_ptr<GrOp>, GrRenderTargetContext*, GrAppliedClip* = nullptr, |
| 146 | const DstTexture* = nullptr); |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 147 | |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 148 | void forwardCombine(); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 149 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 150 | // If this returns true then b has been merged into a's op. |
| 151 | bool combineIfPossible(const RecordedOp& a, GrOp* b, const GrAppliedClip* bClip, |
| 152 | const DstTexture* bDstTexture); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 153 | |
| 154 | GrClearOp* fLastFullClearOp = nullptr; |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 155 | GrGpuResource::UniqueID fLastFullClearResourceID = GrGpuResource::UniqueID::InvalidID(); |
| 156 | GrSurfaceProxy::UniqueID fLastFullClearProxyID = GrSurfaceProxy::UniqueID::InvalidID(); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 157 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 158 | GrGpu* fGpu; |
| 159 | GrResourceProvider* fResourceProvider; |
joshualitt | 3bdd7dc | 2014-10-31 08:27:39 -0700 | [diff] [blame] | 160 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 161 | int fMaxOpLookback; |
| 162 | int fMaxOpLookahead; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 163 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 164 | std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 165 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 166 | int32_t fLastClipStackGenID; |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 167 | SkIRect fLastDevClipBounds; |
csmartdalton | 7cdda99 | 2016-11-01 07:03:03 -0700 | [diff] [blame] | 168 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 169 | SkSTArray<256, RecordedOp, true> fRecordedOps; |
| 170 | |
| 171 | char fClipAllocatorStorage[4096]; |
| 172 | SkArenaAlloc fClipAllocator; |
| 173 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 174 | typedef GrOpList INHERITED; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 177 | #endif |