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 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef GrDrawTarget_DEFINED |
| 9 | #define GrDrawTarget_DEFINED |
| 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" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 13 | #include "GrPathProcessor.h" |
| 14 | #include "GrPrimitiveProcessor.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 15 | #include "GrPathRendering.h" |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 16 | #include "GrXferProcessor.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 18 | #include "batches/GrDrawBatch.h" |
| 19 | |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 20 | #include "SkClipStack.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 21 | #include "SkMatrix.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 22 | #include "SkPath.h" |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 23 | #include "SkStringUtils.h" |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 24 | #include "SkStrokeRec.h" |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 25 | #include "SkTArray.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 26 | #include "SkTLazy.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 27 | #include "SkTypes.h" |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 28 | #include "SkXfermode.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 29 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 30 | //#define ENABLE_MDB 1 |
| 31 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 32 | class GrAuditTrail; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 33 | class GrBatch; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 34 | class GrClip; |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 35 | class GrCaps; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 36 | class GrPath; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 37 | class GrDrawPathBatchBase; |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 38 | class GrPipelineBuilder; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 39 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 40 | class GrDrawTarget final : public SkRefCnt { |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 41 | public: |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 42 | /** Options for GrDrawTarget behavior. */ |
| 43 | struct Options { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 44 | Options () |
| 45 | : fClipBatchToBounds(false) |
| 46 | , fDrawBatchBounds(false) |
| 47 | , fMaxBatchLookback(-1) |
| 48 | , fMaxBatchLookahead(-1) {} |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 49 | bool fClipBatchToBounds; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 50 | bool fDrawBatchBounds; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 51 | int fMaxBatchLookback; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 52 | int fMaxBatchLookahead; |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 53 | }; |
| 54 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 55 | GrDrawTarget(GrRenderTarget*, GrGpu*, GrResourceProvider*, GrAuditTrail*, const Options&); |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 56 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 57 | ~GrDrawTarget() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 59 | void makeClosed() { |
| 60 | // We only close drawTargets When MDB is enabled. When MDB is disabled there is only |
| 61 | // ever one drawTarget and all calls will be funnelled into it. |
| 62 | #ifdef ENABLE_MDB |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 63 | this->setFlag(kClosed_Flag); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 64 | #endif |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 65 | this->forwardCombine(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 66 | } |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 67 | |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 68 | bool isClosed() const { return this->isSetFlag(kClosed_Flag); } |
| 69 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 70 | // TODO: this entry point is only needed in the non-MDB world. Remove when |
| 71 | // we make the switch to MDB |
| 72 | void clearRT() { fRenderTarget = nullptr; } |
| 73 | |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 74 | /* |
| 75 | * Notify this drawTarget that it relies on the contents of 'dependedOn' |
| 76 | */ |
| 77 | void addDependency(GrSurface* dependedOn); |
| 78 | |
| 79 | /* |
| 80 | * Does this drawTarget depend on 'dependedOn'? |
| 81 | */ |
| 82 | bool dependsOn(GrDrawTarget* dependedOn) const { |
| 83 | return fDependencies.find(dependedOn) >= 0; |
| 84 | } |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 85 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Dump out the drawTarget dependency DAG |
| 88 | */ |
| 89 | SkDEBUGCODE(void dump() const;) |
| 90 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 91 | /** |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 92 | * Empties the draw buffer of any queued up draws. |
| 93 | */ |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 94 | void reset(); |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 97 | * Together these two functions flush all queued up draws to the Gpu. |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 98 | */ |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 99 | void prepareBatches(GrBatchFlushState* flushState); |
| 100 | void drawBatches(GrBatchFlushState* flushState); |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 103 | * Gets the capabilities of the draw target. |
| 104 | */ |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 105 | const GrCaps* caps() const { return fGpu->caps(); } |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 106 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 107 | void drawBatch(const GrPipelineBuilder&, GrDrawContext*, const GrClip&, GrDrawBatch*); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 108 | |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame^] | 109 | void addBatch(sk_sp<GrBatch>); |
| 110 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 111 | /** |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 112 | * Draws path into the stencil buffer. The fill must be either even/odd or |
| 113 | * winding (not inverse or hairline). It will respect the HW antialias flag |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 114 | * on the GrPipelineBuilder (if possible in the 3D API). Note, we will never have an inverse |
| 115 | * fill with stencil path |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 116 | */ |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 117 | void stencilPath(const GrPipelineBuilder&, GrDrawContext*, |
| 118 | const GrClip&, const SkMatrix& viewMatrix, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 119 | const GrPath*, GrPathRendering::FillType); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 120 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 121 | /** Discards the contents render target. */ |
| 122 | void discard(GrRenderTarget*); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 123 | |
| 124 | /** |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 125 | * Copies a pixel rectangle from one surface to another. This call may finalize |
| 126 | * reserved vertex/index data (as though a draw call was made). The src pixels |
| 127 | * copied are specified by srcRect. They are copied to a rect of the same |
| 128 | * size in dst with top left at dstPoint. If the src rect is clipped by the |
| 129 | * src bounds then pixel values in the dst rect corresponding to area clipped |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 130 | * 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] | 131 | * depending on the type of surface, configs, etc, and the backend-specific |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 132 | * limitations. |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 133 | */ |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 134 | bool copySurface(GrSurface* dst, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 135 | GrSurface* src, |
| 136 | const SkIRect& srcRect, |
| 137 | const SkIPoint& dstPoint); |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 138 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 139 | /** |
| 140 | * Gets the shape rendering object if it is supported on this platform. |
| 141 | */ |
| 142 | gr_instanced::InstancedRendering* instancedRendering() const { return fInstancedRendering; } |
| 143 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 144 | private: |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 145 | friend class GrDrawingManager; // for resetFlag & TopoSortTraits |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 146 | friend class GrDrawContextPriv; // for clearStencilClip |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 147 | |
| 148 | enum Flags { |
| 149 | kClosed_Flag = 0x01, //!< This drawTarget can't accept any more batches |
| 150 | |
| 151 | kWasOutput_Flag = 0x02, //!< Flag for topological sorting |
| 152 | kTempMark_Flag = 0x04, //!< Flag for topological sorting |
| 153 | }; |
| 154 | |
| 155 | void setFlag(uint32_t flag) { |
| 156 | fFlags |= flag; |
| 157 | } |
| 158 | |
| 159 | void resetFlag(uint32_t flag) { |
| 160 | fFlags &= ~flag; |
| 161 | } |
| 162 | |
| 163 | bool isSetFlag(uint32_t flag) const { |
| 164 | return SkToBool(fFlags & flag); |
| 165 | } |
| 166 | |
| 167 | struct TopoSortTraits { |
| 168 | static void Output(GrDrawTarget* dt, int /* index */) { |
| 169 | dt->setFlag(GrDrawTarget::kWasOutput_Flag); |
| 170 | } |
| 171 | static bool WasOutput(const GrDrawTarget* dt) { |
| 172 | return dt->isSetFlag(GrDrawTarget::kWasOutput_Flag); |
| 173 | } |
| 174 | static void SetTempMark(GrDrawTarget* dt) { |
| 175 | dt->setFlag(GrDrawTarget::kTempMark_Flag); |
| 176 | } |
| 177 | static void ResetTempMark(GrDrawTarget* dt) { |
| 178 | dt->resetFlag(GrDrawTarget::kTempMark_Flag); |
| 179 | } |
| 180 | static bool IsTempMarked(const GrDrawTarget* dt) { |
| 181 | return dt->isSetFlag(GrDrawTarget::kTempMark_Flag); |
| 182 | } |
| 183 | static int NumDependencies(const GrDrawTarget* dt) { |
| 184 | return dt->fDependencies.count(); |
| 185 | } |
| 186 | static GrDrawTarget* Dependency(GrDrawTarget* dt, int index) { |
| 187 | return dt->fDependencies[index]; |
| 188 | } |
| 189 | }; |
| 190 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 191 | void recordBatch(GrBatch*, const SkRect& clippedBounds); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 192 | void forwardCombine(); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 193 | |
| 194 | // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required |
| 195 | // but couldn't be made. Otherwise, returns true. This method needs to be protected because it |
| 196 | // needs to be accessed by GLPrograms to setup a correct drawstate |
| 197 | bool setupDstReadIfNecessary(const GrPipelineBuilder&, |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 198 | GrRenderTarget*, |
| 199 | const GrClip&, |
| 200 | const GrPipelineOptimizations& optimizations, |
| 201 | GrXferProcessor::DstTexture*, |
| 202 | const SkRect& batchBounds); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 203 | |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 204 | void addDependency(GrDrawTarget* dependedOn); |
| 205 | |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 206 | // Used only by drawContextPriv. |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 207 | void clearStencilClip(const SkIRect&, bool insideClip, GrRenderTarget*); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 208 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 209 | struct RecordedBatch { |
| 210 | sk_sp<GrBatch> fBatch; |
| 211 | SkRect fClippedBounds; |
| 212 | }; |
| 213 | SkSTArray<256, RecordedBatch, true> fRecordedBatches; |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 214 | // The context is only in service of the clip mask manager, remove once CMM doesn't need this. |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 215 | GrContext* fContext; |
| 216 | GrGpu* fGpu; |
| 217 | GrResourceProvider* fResourceProvider; |
| 218 | GrAuditTrail* fAuditTrail; |
joshualitt | 3bdd7dc | 2014-10-31 08:27:39 -0700 | [diff] [blame] | 219 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 220 | SkDEBUGCODE(int fDebugID;) |
| 221 | uint32_t fFlags; |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 222 | |
| 223 | // 'this' drawTarget relies on the output of the drawTargets in 'fDependencies' |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 224 | SkTDArray<GrDrawTarget*> fDependencies; |
| 225 | GrRenderTarget* fRenderTarget; |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 226 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 227 | bool fClipBatchToBounds; |
| 228 | bool fDrawBatchBounds; |
| 229 | int fMaxBatchLookback; |
| 230 | int fMaxBatchLookahead; |
| 231 | |
| 232 | SkAutoTDelete<gr_instanced::InstancedRendering> fInstancedRendering; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 233 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 234 | typedef SkRefCnt INHERITED; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 237 | #endif |