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