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