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" |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 12 | #include "GrClipMaskManager.h" |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 14 | #include "GrPathProcessor.h" |
| 15 | #include "GrPrimitiveProcessor.h" |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 16 | #include "GrIndexBuffer.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 17 | #include "GrPathRendering.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 18 | #include "GrPipelineBuilder.h" |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 19 | #include "GrTraceMarker.h" |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 20 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 22 | #include "SkClipStack.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 23 | #include "SkMatrix.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 24 | #include "SkPath.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 | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 31 | class GrBatch; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame^] | 32 | class GrClip; |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 33 | class GrDrawTargetCaps; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 34 | class GrPath; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 35 | class GrPathRange; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 36 | class GrPipeline; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 37 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 38 | class GrDrawTarget : public SkRefCnt { |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 39 | public: |
| 40 | SK_DECLARE_INST_COUNT(GrDrawTarget) |
| 41 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 42 | typedef GrPathRange::PathIndexType PathIndexType; |
| 43 | typedef GrPathRendering::PathTransformType PathTransformType; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 44 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | /////////////////////////////////////////////////////////////////////////// |
| 46 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 47 | // The context may not be fully constructed and should not be used during GrDrawTarget |
| 48 | // construction. |
| 49 | GrDrawTarget(GrContext* context); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 50 | virtual ~GrDrawTarget(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | |
| 52 | /** |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 53 | * Gets the capabilities of the draw target. |
| 54 | */ |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 55 | const GrDrawTargetCaps* caps() const { return fCaps.get(); } |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 58 | * There are two types of "sources" of geometry (vertices and indices) for |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 59 | * draw calls made on the target. When performing an indexed draw, the |
| 60 | * indices and vertices can use different source types. Once a source is |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 61 | * specified it can be used for multiple draws. However, the time at which |
| 62 | * the geometry data is no longer editable depends on the source type. |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 63 | * |
| 64 | * Sometimes it is necessary to perform a draw while upstack code has |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 65 | * already specified geometry that it isn't finished with. So there are push |
| 66 | * and pop methods. This allows the client to push the sources, draw |
| 67 | * something using alternate sources, and then pop to restore the original |
| 68 | * sources. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 69 | * |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 70 | * Aside from pushes and pops, a source remains valid until another source |
| 71 | * is set or resetVertexSource / resetIndexSource is called. Drawing from |
| 72 | * a reset source is an error. |
| 73 | * |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 74 | * The two types of sources are: |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 75 | * |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 76 | * 1. Reserve. This is most useful when the caller has data it must |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 77 | * transform before drawing and is not long-lived. The caller requests |
| 78 | * that the draw target make room for some amount of vertex and/or index |
| 79 | * data. The target provides ptrs to hold the vertex and/or index data. |
| 80 | * |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 81 | * The data is writable up until the next drawIndexed, drawNonIndexed, |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 82 | * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At |
| 83 | * this point the data is frozen and the ptrs are no longer valid. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 84 | * |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 85 | * Where the space is allocated and how it is uploaded to the GPU is |
| 86 | * subclass-dependent. |
| 87 | * |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 88 | * 2. Vertex and Index Buffers. This is most useful for geometry that will |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 89 | * is long-lived. When the data in the buffer is consumed depends on the |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 90 | * GrDrawTarget subclass. For deferred subclasses the caller has to |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 91 | * guarantee that the data is still available in the buffers at playback. |
| 92 | * (TODO: Make this more automatic as we have done for read/write pixels) |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 93 | */ |
| 94 | |
| 95 | /** |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 96 | * Reserves space for vertices and/or indices. Zero can be specifed as |
| 97 | * either the vertex or index count if the caller desires to only reserve |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 98 | * space for only indices or only vertices. If zero is specifed for |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 99 | * vertexCount then the vertex source will be unmodified and likewise for |
| 100 | * indexCount. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 101 | * |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 102 | * If the function returns true then the reserve suceeded and the vertices |
| 103 | * and indices pointers will point to the space created. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 104 | * |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 105 | * If the target cannot make space for the request then this function will |
| 106 | * return false. If vertexCount was non-zero then upon failure the vertex |
| 107 | * source is reset and likewise for indexCount. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 108 | * |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 109 | * The pointers to the space allocated for vertices and indices remain valid |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 110 | * until a drawIndexed, drawNonIndexed, drawIndexedInstances, drawRect, |
| 111 | * copySurface, or push/popGeomtrySource is called. At that point logically a |
| 112 | * snapshot of the data is made and the pointers are invalid. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 113 | * |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 114 | * @param vertexCount the number of vertices to reserve space for. Can be |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 115 | * 0. Vertex size is queried from the current GrPipelineBuilder. |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 116 | * @param indexCount the number of indices to reserve space for. Can be 0. |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 117 | * @param vertices will point to reserved vertex space if vertexCount is |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 118 | * non-zero. Illegal to pass NULL if vertexCount > 0. |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 119 | * @param indices will point to reserved index space if indexCount is |
| 120 | * non-zero. Illegal to pass NULL if indexCount > 0. |
| 121 | */ |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 122 | bool reserveVertexAndIndexSpace(int vertexCount, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 123 | size_t vertexStride, |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 124 | int indexCount, |
| 125 | void** vertices, |
| 126 | void** indices); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 127 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 128 | /** |
| 129 | * Provides hints to caller about the number of vertices and indices |
| 130 | * that can be allocated cheaply. This can be useful if caller is reserving |
| 131 | * space but doesn't know exactly how much geometry is needed. |
| 132 | * |
| 133 | * Also may hint whether the draw target should be flushed first. This is |
| 134 | * useful for deferred targets. |
| 135 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 136 | * @param vertexCount in: hint about how many vertices the caller would |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 137 | * like to allocate. Vertex size is queried from the |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 138 | * current GrPipelineBuilder. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 139 | * out: a hint about the number of vertices that can be |
| 140 | * allocated cheaply. Negative means no hint. |
| 141 | * Ignored if NULL. |
| 142 | * @param indexCount in: hint about how many indices the caller would |
| 143 | * like to allocate. |
| 144 | * out: a hint about the number of indices that can be |
| 145 | * allocated cheaply. Negative means no hint. |
| 146 | * Ignored if NULL. |
| 147 | * |
| 148 | * @return true if target should be flushed based on the input values. |
| 149 | */ |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 150 | virtual bool geometryHints(size_t vertexStride, int* vertexCount, int* indexCount) const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 151 | |
| 152 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 153 | * Sets source of vertex data for the next draw. Data does not have to be |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 154 | * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 155 | * |
| 156 | * @param buffer vertex buffer containing vertex data. Must be |
skia.committer@gmail.com | ae68392 | 2013-02-06 07:01:54 +0000 | [diff] [blame] | 157 | * unlocked before draw call. Vertex size is queried |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 158 | * from current GrPipelineBuilder. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 159 | */ |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 160 | void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * Sets source of index data for the next indexed draw. Data does not have |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 164 | * to be in the buffer until drawIndexed. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 165 | * |
| 166 | * @param buffer index buffer containing indices. Must be unlocked |
| 167 | * before indexed draw call. |
| 168 | */ |
| 169 | void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 170 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 171 | /** |
| 172 | * Resets vertex source. Drawing from reset vertices is illegal. Set vertex |
| 173 | * source to reserved, array, or buffer before next draw. May be able to free |
| 174 | * up temporary storage allocated by setVertexSourceToArray or |
| 175 | * reserveVertexSpace. |
| 176 | */ |
| 177 | void resetVertexSource(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 178 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 179 | /** |
| 180 | * Resets index source. Indexed Drawing from reset indices is illegal. Set |
| 181 | * index source to reserved, array, or buffer before next indexed draw. May |
| 182 | * be able to free up temporary storage allocated by setIndexSourceToArray |
| 183 | * or reserveIndexSpace. |
| 184 | */ |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 185 | void resetIndexSource(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 186 | |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 187 | /** |
| 188 | * Query to find out if the vertex or index source is reserved. |
| 189 | */ |
| 190 | bool hasReservedVerticesOrIndices() const { |
bsalomon@google.com | 73d98aa | 2012-03-13 14:41:19 +0000 | [diff] [blame] | 191 | return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc || |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 192 | kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; |
| 193 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 194 | |
| 195 | /** |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 196 | * Pushes and resets the vertex/index sources. Any reserved vertex / index |
| 197 | * data is finalized (i.e. cannot be updated after the matching pop but can |
| 198 | * be drawn from). Must be balanced by a pop. |
| 199 | */ |
| 200 | void pushGeometrySource(); |
| 201 | |
| 202 | /** |
| 203 | * Pops the vertex / index sources from the matching push. |
| 204 | */ |
| 205 | void popGeometrySource(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 206 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 207 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 208 | * Draws indexed geometry using the current state and current vertex / index |
| 209 | * sources. |
| 210 | * |
| 211 | * @param type The type of primitives to draw. |
| 212 | * @param startVertex the vertex in the vertex array/buffer corresponding |
| 213 | * to index 0 |
| 214 | * @param startIndex first index to read from index src. |
| 215 | * @param vertexCount one greater than the max index. |
| 216 | * @param indexCount the number of index elements to read. The index count |
| 217 | * is effectively trimmed to the last completely |
| 218 | * specified primitive. |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 219 | * @param devBounds optional bounds hint. This is a promise from the caller, |
| 220 | * not a request for clipping. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 221 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 222 | void drawIndexed(GrPipelineBuilder*, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 223 | const GrGeometryProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 224 | GrPrimitiveType type, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 225 | int startVertex, |
| 226 | int startIndex, |
| 227 | int vertexCount, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 228 | int indexCount, |
| 229 | const SkRect* devBounds = NULL); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * Draws non-indexed geometry using the current state and current vertex |
| 233 | * sources. |
| 234 | * |
| 235 | * @param type The type of primitives to draw. |
| 236 | * @param startVertex the vertex in the vertex array/buffer corresponding |
| 237 | * to index 0 |
| 238 | * @param vertexCount one greater than the max index. |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 239 | * @param devBounds optional bounds hint. This is a promise from the caller, |
| 240 | * not a request for clipping. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 241 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 242 | void drawNonIndexed(GrPipelineBuilder*, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 243 | const GrGeometryProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 244 | GrPrimitiveType type, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 245 | int startVertex, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 246 | int vertexCount, |
| 247 | const SkRect* devBounds = NULL); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 248 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 249 | // TODO devbounds should live on the batch |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame^] | 250 | void drawBatch(GrPipelineBuilder*, GrBatch*, const SkRect* devBounds = NULL); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 251 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 252 | /** |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 253 | * Draws path into the stencil buffer. The fill must be either even/odd or |
| 254 | * winding (not inverse or hairline). It will respect the HW antialias flag |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 255 | * on the GrPipelineBuilder (if possible in the 3D API). Note, we will never have an inverse |
| 256 | * fill with stencil path |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 257 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 258 | void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*, |
| 259 | GrPathRendering::FillType); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 260 | |
| 261 | /** |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 262 | * Draws a path. Fill must not be a hairline. It will respect the HW |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 263 | * antialias flag on the GrPipelineBuilder (if possible in the 3D API). |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 264 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 265 | void drawPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*, |
| 266 | GrPathRendering::FillType); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 267 | |
| 268 | /** |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 269 | * Draws the aggregate path from combining multiple. Note that this will not |
| 270 | * always be equivalent to back-to-back calls to drawPath(). It will respect |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 271 | * the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API). |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 272 | * |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 273 | * @param pathRange Source paths to draw from |
| 274 | * @param indices Array of path indices to draw |
| 275 | * @param indexType Data type of the array elements in indexBuffer |
| 276 | * @param transformValues Array of transforms for the individual paths |
| 277 | * @param transformType Type of transforms in transformBuffer |
| 278 | * @param count Number of paths to draw |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 279 | * @param fill Fill type for drawing all the paths |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 280 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 281 | void drawPaths(GrPipelineBuilder*, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 282 | const GrPathProcessor*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 283 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 284 | const void* indices, |
| 285 | PathIndexType indexType, |
| 286 | const float transformValues[], |
| 287 | PathTransformType transformType, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 288 | int count, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 289 | GrPathRendering::FillType fill); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 290 | |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 291 | /** |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 292 | * Helper function for drawing rects. It performs a geometry src push and pop |
| 293 | * and thus will finalize any reserved geometry. |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 294 | * |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 295 | * @param rect the rect to draw |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 296 | * @param localRect optional rect that specifies local coords to map onto |
| 297 | * rect. If NULL then rect serves as the local coords. |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 298 | * @param localMatrix Optional local matrix. The local coordinates are specified by localRect, |
| 299 | * or if it is NULL by rect. This matrix applies to the coordinate implied by |
| 300 | * that rectangle before it is input to GrCoordTransforms that read local |
| 301 | * coordinates |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 302 | */ |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 303 | void drawRect(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 304 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 305 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 306 | const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 307 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 308 | const SkMatrix* localMatrix) { |
| 309 | AutoGeometryPush agp(this); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 310 | this->onDrawRect(pipelineBuilder, color, viewMatrix, rect, localRect, localMatrix); |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 311 | } |
jvanverth@google.com | 3976825 | 2013-02-14 15:25:44 +0000 | [diff] [blame] | 312 | |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 313 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 314 | * Helper for drawRect when the caller doesn't need separate local rects or matrices. |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 315 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 316 | void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM, |
| 317 | const SkRect& rect) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 318 | this->drawRect(ds, color, viewM, rect, NULL, NULL); |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 319 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 320 | void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 321 | const SkIRect& irect) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 322 | SkRect rect = SkRect::Make(irect); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 323 | this->drawRect(ds, color, viewM, rect, NULL, NULL); |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 324 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 325 | |
| 326 | /** |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 327 | * This call is used to draw multiple instances of some geometry with a |
| 328 | * given number of vertices (V) and indices (I) per-instance. The indices in |
| 329 | * the index source must have the form i[k+I] == i[k] + V. Also, all indices |
| 330 | * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a |
| 331 | * concrete example, the following index buffer for drawing a series of |
| 332 | * quads each as two triangles each satisfies these conditions with V=4 and |
| 333 | * I=6: |
| 334 | * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...) |
| 335 | * |
| 336 | * The call assumes that the pattern of indices fills the entire index |
| 337 | * source. The size of the index buffer limits the number of instances that |
| 338 | * can be drawn by the GPU in a single draw. However, the caller may specify |
| 339 | * any (positive) number for instanceCount and if necessary multiple GPU |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 340 | * draws will be issued. Moreover, when drawIndexedInstances is called |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 341 | * multiple times it may be possible for GrDrawTarget to group them into a |
| 342 | * single GPU draw. |
| 343 | * |
| 344 | * @param type the type of primitives to draw |
| 345 | * @param instanceCount the number of instances to draw. Each instance |
| 346 | * consists of verticesPerInstance vertices indexed by |
| 347 | * indicesPerInstance indices drawn as the primitive |
| 348 | * type specified by type. |
| 349 | * @param verticesPerInstance The number of vertices in each instance (V |
| 350 | * in the above description). |
| 351 | * @param indicesPerInstance The number of indices in each instance (I |
| 352 | * in the above description). |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 353 | * @param devBounds optional bounds hint. This is a promise from the caller, |
| 354 | * not a request for clipping. |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 355 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 356 | void drawIndexedInstances(GrPipelineBuilder*, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 357 | const GrGeometryProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 358 | GrPrimitiveType type, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 359 | int instanceCount, |
| 360 | int verticesPerInstance, |
| 361 | int indicesPerInstance, |
| 362 | const SkRect* devBounds = NULL); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 363 | |
| 364 | /** |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 365 | * Clear the passed in render target. Ignores the GrPipelineBuilder and clip. Clears the whole |
| 366 | * thing if rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire |
| 367 | * render target can be optionally cleared. |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 368 | */ |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 369 | void clear(const SkIRect* rect, |
| 370 | GrColor color, |
| 371 | bool canIgnoreRect, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 372 | GrRenderTarget* renderTarget); |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 373 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 374 | /** |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 375 | * Discards the contents render target. |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 376 | **/ |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 377 | virtual void discard(GrRenderTarget*) = 0; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 378 | |
| 379 | /** |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 380 | * Called at start and end of gpu trace marking |
| 381 | * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start |
| 382 | * and end of a code block respectively |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 383 | */ |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 384 | void addGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 385 | void removeGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 386 | |
| 387 | /** |
| 388 | * Takes the current active set of markers and stores them for later use. Any current marker |
| 389 | * in the active set is removed from the active set and the targets remove function is called. |
| 390 | * These functions do not work as a stack so you cannot call save a second time before calling |
| 391 | * restore. Also, it is assumed that when restore is called the current active set of markers |
| 392 | * is empty. When the stored markers are added back into the active set, the targets add marker |
| 393 | * is called. |
| 394 | */ |
| 395 | void saveActiveTraceMarkers(); |
| 396 | void restoreActiveTraceMarkers(); |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 397 | |
| 398 | /** |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 399 | * Copies a pixel rectangle from one surface to another. This call may finalize |
| 400 | * reserved vertex/index data (as though a draw call was made). The src pixels |
| 401 | * copied are specified by srcRect. They are copied to a rect of the same |
| 402 | * size in dst with top left at dstPoint. If the src rect is clipped by the |
| 403 | * src bounds then pixel values in the dst rect corresponding to area clipped |
| 404 | * by the src rect are not overwritten. This method can fail and return false |
| 405 | * depending on the type of surface, configs, etc, and the backend-specific |
| 406 | * limitations. If rect is clipped out entirely by the src or dst bounds then |
| 407 | * true is returned since there is no actual copy necessary to succeed. |
| 408 | */ |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 409 | bool copySurface(GrSurface* dst, |
| 410 | GrSurface* src, |
| 411 | const SkIRect& srcRect, |
| 412 | const SkIPoint& dstPoint); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 413 | /** |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 414 | * Function that determines whether a copySurface call would succeed without actually |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 415 | * performing the copy. |
| 416 | */ |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 417 | bool canCopySurface(const GrSurface* dst, |
| 418 | const GrSurface* src, |
| 419 | const SkIRect& srcRect, |
| 420 | const SkIPoint& dstPoint); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 421 | |
| 422 | /** |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 423 | * Release any resources that are cached but not currently in use. This |
| 424 | * is intended to give an application some recourse when resources are low. |
| 425 | */ |
| 426 | virtual void purgeResources() {}; |
| 427 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 428 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 429 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 430 | class AutoReleaseGeometry : public ::SkNoncopyable { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 431 | public: |
| 432 | AutoReleaseGeometry(GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 433 | int vertexCount, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 434 | size_t vertexStride, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 435 | int indexCount); |
| 436 | AutoReleaseGeometry(); |
| 437 | ~AutoReleaseGeometry(); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 438 | bool set(GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 439 | int vertexCount, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 440 | size_t vertexStride, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 441 | int indexCount); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 442 | bool succeeded() const { return SkToBool(fTarget); } |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 443 | void* vertices() const { SkASSERT(this->succeeded()); return fVertices; } |
| 444 | void* indices() const { SkASSERT(this->succeeded()); return fIndices; } |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 445 | SkPoint* positions() const { |
| 446 | return static_cast<SkPoint*>(this->vertices()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | private: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 450 | void reset(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 451 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 452 | GrDrawTarget* fTarget; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 453 | void* fVertices; |
| 454 | void* fIndices; |
| 455 | }; |
| 456 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 457 | //////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 458 | |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 459 | /** |
| 460 | * Saves the geometry src state at construction and restores in the destructor. It also saves |
| 461 | * and then restores the vertex attrib state. |
| 462 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 463 | class AutoGeometryPush : public ::SkNoncopyable { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 464 | public: |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 465 | AutoGeometryPush(GrDrawTarget* target) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 466 | SkASSERT(target); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 467 | fTarget = target; |
| 468 | target->pushGeometrySource(); |
| 469 | } |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 470 | |
| 471 | ~AutoGeometryPush() { fTarget->popGeometrySource(); } |
| 472 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 473 | private: |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 474 | GrDrawTarget* fTarget; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 475 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 476 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 477 | /////////////////////////////////////////////////////////////////////////// |
| 478 | // Draw execution tracking (for font atlases and other resources) |
| 479 | class DrawToken { |
| 480 | public: |
| 481 | DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : |
| 482 | fDrawTarget(drawTarget), fDrawID(drawID) {} |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 483 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 484 | bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); } |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 485 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 486 | private: |
| 487 | GrDrawTarget* fDrawTarget; |
| 488 | uint32_t fDrawID; // this may wrap, but we're doing direct comparison |
| 489 | // so that should be okay |
| 490 | }; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 491 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 492 | virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 493 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 494 | /** |
| 495 | * Used to communicate draws to GPUs / subclasses |
| 496 | */ |
| 497 | class DrawInfo { |
| 498 | public: |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 499 | DrawInfo() { fDevBounds = NULL; } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 500 | DrawInfo(const DrawInfo& di) { (*this) = di; } |
| 501 | DrawInfo& operator =(const DrawInfo& di); |
| 502 | |
| 503 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 504 | int startVertex() const { return fStartVertex; } |
| 505 | int startIndex() const { return fStartIndex; } |
| 506 | int vertexCount() const { return fVertexCount; } |
| 507 | int indexCount() const { return fIndexCount; } |
| 508 | int verticesPerInstance() const { return fVerticesPerInstance; } |
| 509 | int indicesPerInstance() const { return fIndicesPerInstance; } |
| 510 | int instanceCount() const { return fInstanceCount; } |
| 511 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 512 | void setPrimitiveType(GrPrimitiveType type) { fPrimitiveType = type; } |
| 513 | void setStartVertex(int startVertex) { fStartVertex = startVertex; } |
| 514 | void setStartIndex(int startIndex) { fStartIndex = startIndex; } |
| 515 | void setVertexCount(int vertexCount) { fVertexCount = vertexCount; } |
| 516 | void setIndexCount(int indexCount) { fIndexCount = indexCount; } |
| 517 | void setVerticesPerInstance(int verticesPerI) { fVerticesPerInstance = verticesPerI; } |
| 518 | void setIndicesPerInstance(int indicesPerI) { fIndicesPerInstance = indicesPerI; } |
| 519 | void setInstanceCount(int instanceCount) { fInstanceCount = instanceCount; } |
| 520 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 521 | bool isIndexed() const { return fIndexCount > 0; } |
| 522 | #ifdef SK_DEBUG |
| 523 | bool isInstanced() const; // this version is longer because of asserts |
| 524 | #else |
| 525 | bool isInstanced() const { return fInstanceCount > 0; } |
| 526 | #endif |
| 527 | |
| 528 | // adds or remove instances |
| 529 | void adjustInstanceCount(int instanceOffset); |
| 530 | // shifts the start vertex |
| 531 | void adjustStartVertex(int vertexOffset); |
| 532 | // shifts the start index |
| 533 | void adjustStartIndex(int indexOffset); |
| 534 | |
| 535 | void setDevBounds(const SkRect& bounds) { |
| 536 | fDevBoundsStorage = bounds; |
| 537 | fDevBounds = &fDevBoundsStorage; |
| 538 | } |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 539 | const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } |
| 540 | const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
| 541 | void setVertexBuffer(const GrVertexBuffer* vb) { |
| 542 | fVertexBuffer.reset(vb); |
| 543 | } |
| 544 | void setIndexBuffer(const GrIndexBuffer* ib) { |
| 545 | fIndexBuffer.reset(ib); |
| 546 | } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 547 | const SkRect* getDevBounds() const { return fDevBounds; } |
| 548 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 549 | private: |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 550 | friend class GrDrawTarget; |
| 551 | |
| 552 | GrPrimitiveType fPrimitiveType; |
| 553 | |
| 554 | int fStartVertex; |
| 555 | int fStartIndex; |
| 556 | int fVertexCount; |
| 557 | int fIndexCount; |
| 558 | |
| 559 | int fInstanceCount; |
| 560 | int fVerticesPerInstance; |
| 561 | int fIndicesPerInstance; |
| 562 | |
| 563 | SkRect fDevBoundsStorage; |
| 564 | SkRect* fDevBounds; |
| 565 | |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 566 | GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; |
| 567 | GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 568 | }; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 569 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 570 | /** |
| 571 | * Used to populate the vertex and index buffer on the draw info before onDraw is called. |
| 572 | */ |
| 573 | virtual void setDrawBuffers(DrawInfo*, size_t vertexStride) = 0;; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 574 | bool programUnitTest(int maxStages); |
| 575 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 576 | protected: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 577 | enum GeometrySrcType { |
| 578 | kNone_GeometrySrcType, //<! src has not been specified |
| 579 | kReserved_GeometrySrcType, //<! src was set using reserve*Space |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 580 | kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer |
| 581 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 582 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 583 | struct GeometrySrcState { |
| 584 | GeometrySrcType fVertexSrc; |
| 585 | union { |
| 586 | // valid if src type is buffer |
| 587 | const GrVertexBuffer* fVertexBuffer; |
| 588 | // valid if src type is reserved or array |
| 589 | int fVertexCount; |
| 590 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 591 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 592 | GeometrySrcType fIndexSrc; |
| 593 | union { |
| 594 | // valid if src type is buffer |
| 595 | const GrIndexBuffer* fIndexBuffer; |
| 596 | // valid if src type is reserved or array |
| 597 | int fIndexCount; |
| 598 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 599 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 600 | size_t fVertexSize; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 601 | }; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 602 | |
| 603 | int indexCountInCurrentSource() const { |
| 604 | const GeometrySrcState& src = this->getGeomSrc(); |
| 605 | switch (src.fIndexSrc) { |
| 606 | case kNone_GeometrySrcType: |
| 607 | return 0; |
| 608 | case kReserved_GeometrySrcType: |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 609 | return src.fIndexCount; |
| 610 | case kBuffer_GeometrySrcType: |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 611 | return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t)); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 612 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 613 | SkFAIL("Unexpected Index Source."); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 614 | return 0; |
| 615 | } |
| 616 | } |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 617 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 618 | GrContext* getContext() { return fContext; } |
| 619 | const GrContext* getContext() const { return fContext; } |
| 620 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 621 | // subclasses must call this in their destructors to ensure all vertex |
| 622 | // and index sources have been released (including those held by |
| 623 | // pushGeometrySource()) |
| 624 | void releaseGeometry(); |
| 625 | |
| 626 | // accessors for derived classes |
| 627 | const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); } |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 628 | // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert. |
| 629 | size_t getVertexSize() const { |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 630 | // the vertex layout is only valid if a vertex source has been specified. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 631 | SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 632 | return this->getGeomSrc().fVertexSize; |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 633 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 634 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 635 | // Subclass must initialize this in its constructor. |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 636 | SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 637 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 638 | const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; } |
| 639 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 640 | // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required |
| 641 | // but couldn't be made. Otherwise, returns true. This method needs to be protected because it |
| 642 | // needs to be accessed by GLPrograms to setup a correct drawstate |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 643 | bool setupDstReadIfNecessary(const GrPipelineBuilder&, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 644 | const GrProcOptInfo& colorPOI, |
| 645 | const GrProcOptInfo& coveragePOI, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 646 | GrDeviceCoordTexture* dstCopy, |
| 647 | const SkRect* drawBounds); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 648 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 649 | struct PipelineInfo { |
| 650 | PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor, |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame^] | 651 | const GrPrimitiveProcessor* primProc, |
| 652 | const SkRect* devBounds, GrDrawTarget* target); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 653 | |
| 654 | PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor, |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame^] | 655 | const GrBatch* batch, const SkRect* devBounds, |
| 656 | GrDrawTarget* target); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 657 | |
| 658 | bool willBlendWithDst(const GrPrimitiveProcessor* primProc) const { |
| 659 | return fPipelineBuilder->willBlendWithDst(primProc); |
| 660 | } |
| 661 | private: |
| 662 | friend class GrDrawTarget; |
| 663 | |
| 664 | bool mustSkipDraw() const { return (NULL == fPipelineBuilder); } |
| 665 | |
| 666 | GrPipelineBuilder* fPipelineBuilder; |
| 667 | GrScissorState* fScissor; |
| 668 | GrProcOptInfo fColorPOI; |
| 669 | GrProcOptInfo fCoveragePOI; |
| 670 | GrDeviceCoordTexture fDstCopy; |
| 671 | }; |
| 672 | |
| 673 | void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline); |
| 674 | |
robertphillips | 54fac8b | 2015-02-16 09:35:50 -0800 | [diff] [blame] | 675 | // A subclass can optionally overload this function to be notified before |
| 676 | // vertex and index space is reserved. |
| 677 | virtual void willReserveVertexAndIndexSpace(int vertexCount, |
| 678 | size_t vertexStride, |
| 679 | int indexCount) {} |
| 680 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 681 | private: |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 682 | /** |
| 683 | * This will be called before allocating a texture as a dst for copySurface. This function |
| 684 | * populates the dstDesc's config, flags, and origin so as to maximize efficiency and guarantee |
| 685 | * success of the copySurface call. |
| 686 | */ |
| 687 | void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) { |
| 688 | if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) { |
| 689 | dstDesc->fOrigin = kDefault_GrSurfaceOrigin; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 690 | dstDesc->fFlags = kRenderTarget_GrSurfaceFlag; |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 691 | dstDesc->fConfig = src->config(); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | /** Internal implementation of canCopySurface. */ |
| 696 | bool internalCanCopySurface(const GrSurface* dst, |
| 697 | const GrSurface* src, |
| 698 | const SkIRect& clippedSrcRect, |
| 699 | const SkIPoint& clippedDstRect); |
| 700 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 701 | // implemented by subclass to allocate space for reserved geom |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 702 | virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 703 | virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; |
| 704 | // implemented by subclass to handle release of reserved geom space |
| 705 | virtual void releaseReservedVertexSpace() = 0; |
| 706 | virtual void releaseReservedIndexSpace() = 0; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 707 | // subclass overrides to be notified just before geo src state is pushed/popped. |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 708 | virtual void geometrySourceWillPush() = 0; |
| 709 | virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; |
| 710 | // subclass called to perform drawing |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 711 | virtual void onDraw(const GrGeometryProcessor*, const DrawInfo&, const PipelineInfo&) = 0; |
| 712 | virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0; |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 713 | // TODO copy in order drawbuffer onDrawRect to here |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 714 | virtual void onDrawRect(GrPipelineBuilder*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 715 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 716 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 717 | const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 718 | const SkRect* localRect, |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 719 | const SkMatrix* localMatrix) = 0; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 720 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 721 | virtual void onStencilPath(const GrPipelineBuilder&, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 722 | const GrPathProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 723 | const GrPath*, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 724 | const GrScissorState&, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 725 | const GrStencilSettings&) = 0; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 726 | virtual void onDrawPath(const GrPathProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 727 | const GrPath*, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 728 | const GrStencilSettings&, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 729 | const PipelineInfo&) = 0; |
| 730 | virtual void onDrawPaths(const GrPathProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 731 | const GrPathRange*, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 732 | const void* indices, |
| 733 | PathIndexType, |
| 734 | const float transformValues[], |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 735 | PathTransformType, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 736 | int count, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 737 | const GrStencilSettings&, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 738 | const PipelineInfo&) = 0; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 739 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 740 | virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, |
| 741 | GrRenderTarget* renderTarget) = 0; |
| 742 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 743 | /** The subclass will get a chance to copy the surface for falling back to the default |
| 744 | implementation, which simply draws a rectangle (and fails if dst isn't a render target). It |
| 745 | should assume that any clipping has already been performed on the rect and point. It won't |
| 746 | be called if the copy can be skipped. */ |
| 747 | virtual bool onCopySurface(GrSurface* dst, |
| 748 | GrSurface* src, |
| 749 | const SkIRect& srcRect, |
| 750 | const SkIPoint& dstPoint) = 0; |
| 751 | |
| 752 | /** Indicates whether onCopySurface would succeed. It should assume that any clipping has |
| 753 | already been performed on the rect and point. It won't be called if the copy can be |
| 754 | skipped. */ |
| 755 | virtual bool onCanCopySurface(const GrSurface* dst, |
| 756 | const GrSurface* src, |
| 757 | const SkIRect& srcRect, |
| 758 | const SkIPoint& dstPoint) = 0; |
| 759 | /** |
| 760 | * This will be called before allocating a texture to be a dst for onCopySurface. Only the |
| 761 | * dstDesc's config, flags, and origin need be set by the function. If the subclass cannot |
| 762 | * create a surface that would succeed its implementation of onCopySurface, it should return |
| 763 | * false. The base class will fall back to creating a render target to draw into using the src. |
| 764 | */ |
| 765 | virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) = 0; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 766 | |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 767 | // helpers for reserving vertex and index space. |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 768 | bool reserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 769 | int vertexCount, |
| 770 | void** vertices); |
| 771 | bool reserveIndexSpace(int indexCount, void** indices); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 772 | |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 773 | // called by drawIndexed and drawNonIndexed. Use a negative indexCount to |
| 774 | // indicate non-indexed drawing. |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 775 | bool checkDraw(const GrPipelineBuilder&, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 776 | const GrGeometryProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 777 | GrPrimitiveType type, |
| 778 | int startVertex, |
| 779 | int startIndex, |
| 780 | int vertexCount, |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 781 | int indexCount) const; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 782 | // called when setting a new vert/idx source to unref prev vb/ib |
| 783 | void releasePreviousVertexSource(); |
| 784 | void releasePreviousIndexSource(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 785 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 786 | // Check to see if this set of draw commands has been sent out |
| 787 | virtual bool isIssued(uint32_t drawID) { return true; } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 788 | void getPathStencilSettingsForFilltype(GrPathRendering::FillType, |
| 789 | const GrStencilBuffer*, |
| 790 | GrStencilSettings*); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 791 | virtual GrClipMaskManager* clipMaskManager() = 0; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 792 | virtual bool setupClip(GrPipelineBuilder*, |
| 793 | GrPipelineBuilder::AutoRestoreEffects* are, |
| 794 | GrPipelineBuilder::AutoRestoreStencil* ars, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 795 | GrScissorState* scissorState, |
| 796 | const SkRect* devBounds) = 0; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 797 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 798 | enum { |
| 799 | kPreallocGeoSrcStateStackCnt = 4, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 800 | }; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 801 | SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 802 | // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget. |
| 803 | GrContext* fContext; |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 804 | // To keep track that we always have at least as many debug marker adds as removes |
| 805 | int fGpuTraceMarkerCount; |
| 806 | GrTraceMarkerSet fActiveTraceMarkers; |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 807 | GrTraceMarkerSet fStoredTraceMarkers; |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 808 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 809 | typedef SkRefCnt INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 810 | }; |
| 811 | |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 812 | /* |
| 813 | * This class is JUST for clip mask manager. Everyone else should just use draw target above. |
| 814 | */ |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 815 | class GrClipTarget : public GrDrawTarget { |
| 816 | public: |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 817 | GrClipTarget(GrContext* context) : INHERITED(context) { |
| 818 | fClipMaskManager.setClipTarget(this); |
| 819 | } |
| 820 | |
| 821 | /* Clip mask manager needs access to the context. |
| 822 | * TODO we only need a very small subset of context in the CMM. |
| 823 | */ |
| 824 | GrContext* getContext() { return INHERITED::getContext(); } |
| 825 | const GrContext* getContext() const { return INHERITED::getContext(); } |
| 826 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 827 | /** |
| 828 | * Clip Mask Manager(and no one else) needs to clear private stencil bits. |
| 829 | * ClipTarget subclass sets clip bit in the stencil buffer. The subclass |
| 830 | * is free to clear the remaining bits to zero if masked clears are more |
| 831 | * expensive than clearing all bits. |
| 832 | */ |
| 833 | virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0; |
| 834 | |
joshualitt | 3bdd7dc | 2014-10-31 08:27:39 -0700 | [diff] [blame] | 835 | /** |
| 836 | * Release any resources that are cached but not currently in use. This |
| 837 | * is intended to give an application some recourse when resources are low. |
| 838 | */ |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 839 | void purgeResources() SK_OVERRIDE { |
joshualitt | 3bdd7dc | 2014-10-31 08:27:39 -0700 | [diff] [blame] | 840 | // The clip mask manager can rebuild all its clip masks so just |
| 841 | // get rid of them all. |
| 842 | fClipMaskManager.purgeResources(); |
| 843 | }; |
| 844 | |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 845 | protected: |
| 846 | GrClipMaskManager fClipMaskManager; |
| 847 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 848 | private: |
tfarina | 912ed6e | 2014-12-14 15:20:10 -0800 | [diff] [blame] | 849 | GrClipMaskManager* clipMaskManager() SK_OVERRIDE { return &fClipMaskManager; } |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 850 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 851 | virtual bool setupClip(GrPipelineBuilder*, |
| 852 | GrPipelineBuilder::AutoRestoreEffects* are, |
| 853 | GrPipelineBuilder::AutoRestoreStencil* ars, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 854 | GrScissorState* scissorState, |
| 855 | const SkRect* devBounds) SK_OVERRIDE; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 856 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 857 | typedef GrDrawTarget INHERITED; |
| 858 | }; |
| 859 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 860 | #endif |