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 | |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 19 | #include "batches/GrDrawBatch.h" |
| 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" |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 29 | #include "SkXfermode.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 30 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 31 | class GrAuditTrail; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 32 | class GrBatch; |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 33 | class GrClearBatch; |
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 | |
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 { |
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 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 55 | GrRenderTargetOpList(GrRenderTarget*, GrGpu*, GrResourceProvider*, |
| 56 | GrAuditTrail*, const Options&); |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 57 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 58 | ~GrRenderTargetOpList() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 59 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 60 | void makeClosed() override { |
| 61 | INHERITED::makeClosed(); |
| 62 | |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 63 | fLastFullClearBatch = nullptr; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 64 | this->forwardCombine(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 65 | } |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 66 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 67 | /** |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 68 | * Empties the draw buffer of any queued up draws. |
| 69 | */ |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 70 | void reset() override; |
| 71 | |
| 72 | void abandonGpuResources() override; |
| 73 | void freeGpuResources() override; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 76 | * Together these two functions flush all queued up draws to GrCommandBuffer. The return value |
| 77 | * of drawBatches() indicates whether any commands were actually issued to the GPU. |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 78 | */ |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 79 | void prepareBatches(GrBatchFlushState* flushState) override; |
| 80 | bool drawBatches(GrBatchFlushState* flushState) override; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 83 | * Gets the capabilities of the draw target. |
| 84 | */ |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 85 | const GrCaps* caps() const { return fGpu->caps(); } |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 86 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 87 | void drawBatch(const GrPipelineBuilder&, GrRenderTargetContext*, const GrClip&, GrDrawBatch*); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 88 | |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 89 | void addBatch(sk_sp<GrBatch>); |
| 90 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 91 | /** |
csmartdalton | 5c6fc4f | 2016-08-12 15:11:51 -0700 | [diff] [blame] | 92 | * Draws the path into user stencil bits. Upon return, all user stencil values |
| 93 | * inside the path will be nonzero. The path's fill must be either even/odd or |
| 94 | * winding (notnverse or hairline).It will respect the HW antialias boolean (if |
| 95 | * possible in the 3D API). Note, we will never have an inverse fill with |
| 96 | * stencil path. |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 97 | */ |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 98 | void stencilPath(GrRenderTargetContext*, |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 99 | const GrClip&, |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 100 | bool useHWAA, |
| 101 | const SkMatrix& viewMatrix, |
| 102 | const GrPath*); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 103 | |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 104 | /** Clears the entire render target */ |
| 105 | void fullClear(GrRenderTarget*, GrColor color); |
| 106 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 107 | /** Discards the contents render target. */ |
| 108 | void discard(GrRenderTarget*); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 109 | |
| 110 | /** |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 111 | * Copies a pixel rectangle from one surface to another. This call may finalize |
| 112 | * reserved vertex/index data (as though a draw call was made). The src pixels |
| 113 | * copied are specified by srcRect. They are copied to a rect of the same |
| 114 | * size in dst with top left at dstPoint. If the src rect is clipped by the |
| 115 | * src bounds then pixel values in the dst rect corresponding to area clipped |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 116 | * 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] | 117 | * depending on the type of surface, configs, etc, and the backend-specific |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 118 | * limitations. |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 119 | */ |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 120 | bool copySurface(GrSurface* dst, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 121 | GrSurface* src, |
| 122 | const SkIRect& srcRect, |
| 123 | const SkIPoint& dstPoint); |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 124 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 125 | gr_instanced::InstancedRendering* instancedRendering() const { |
| 126 | SkASSERT(fInstancedRendering); |
| 127 | return fInstancedRendering; |
| 128 | } |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 129 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 130 | SkDEBUGCODE(void dump() const override;) |
| 131 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 132 | private: |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 133 | friend class GrRenderTargetContextPriv; // for clearStencilClip |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 134 | |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 135 | // Returns the batch that the input batch was combined with or the input batch if it wasn't |
| 136 | // combined. |
| 137 | GrBatch* recordBatch(GrBatch*, const SkRect& clippedBounds); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 138 | void forwardCombine(); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 139 | |
| 140 | // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required |
| 141 | // but couldn't be made. Otherwise, returns true. This method needs to be protected because it |
| 142 | // needs to be accessed by GLPrograms to setup a correct drawstate |
| 143 | bool setupDstReadIfNecessary(const GrPipelineBuilder&, |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 144 | GrRenderTarget*, |
| 145 | const GrClip&, |
| 146 | const GrPipelineOptimizations& optimizations, |
| 147 | GrXferProcessor::DstTexture*, |
| 148 | const SkRect& batchBounds); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 149 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame^] | 150 | // Used only via GrRenderTargetContextPriv. |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 151 | void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTarget*); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 152 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 153 | struct RecordedBatch { |
| 154 | sk_sp<GrBatch> fBatch; |
| 155 | SkRect fClippedBounds; |
| 156 | }; |
| 157 | SkSTArray<256, RecordedBatch, true> fRecordedBatches; |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 158 | GrClearBatch* fLastFullClearBatch; |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 159 | // The context is only in service of the GrClip, remove once it doesn't need this. |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 160 | GrContext* fContext; |
| 161 | GrGpu* fGpu; |
| 162 | GrResourceProvider* fResourceProvider; |
joshualitt | 3bdd7dc | 2014-10-31 08:27:39 -0700 | [diff] [blame] | 163 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 164 | bool fClipBatchToBounds; |
| 165 | bool fDrawBatchBounds; |
| 166 | int fMaxBatchLookback; |
| 167 | int fMaxBatchLookahead; |
| 168 | |
| 169 | SkAutoTDelete<gr_instanced::InstancedRendering> fInstancedRendering; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 170 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 171 | typedef GrOpList INHERITED; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 174 | #endif |