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 | /** |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 413 | * Clear the current render target if one isn't passed in. Ignores the |
| 414 | * clip and all other draw state (blend mode, stages, etc). Clears the |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 415 | * whole thing if rect is NULL, otherwise just the rect. If canIgnoreRect |
| 416 | * is set then the entire render target can be optionally cleared. |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 417 | */ |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 418 | virtual void clear(const SkIRect* rect, |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 419 | GrColor color, |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 420 | bool canIgnoreRect, |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 421 | GrRenderTarget* renderTarget = NULL) = 0; |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 422 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 423 | /** |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 424 | * Discards the contents render target. NULL indicates that the current render target should |
| 425 | * be discarded. |
| 426 | **/ |
| 427 | virtual void discard(GrRenderTarget* = NULL) = 0; |
| 428 | |
| 429 | /** |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 430 | * Called at start and end of gpu trace marking |
| 431 | * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start |
| 432 | * and end of a code block respectively |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 433 | */ |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 434 | void addGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 435 | void removeGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 436 | |
| 437 | /** |
| 438 | * Takes the current active set of markers and stores them for later use. Any current marker |
| 439 | * in the active set is removed from the active set and the targets remove function is called. |
| 440 | * These functions do not work as a stack so you cannot call save a second time before calling |
| 441 | * restore. Also, it is assumed that when restore is called the current active set of markers |
| 442 | * is empty. When the stored markers are added back into the active set, the targets add marker |
| 443 | * is called. |
| 444 | */ |
| 445 | void saveActiveTraceMarkers(); |
| 446 | void restoreActiveTraceMarkers(); |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 447 | |
| 448 | /** |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 449 | * Copies a pixel rectangle from one surface to another. This call may finalize |
| 450 | * reserved vertex/index data (as though a draw call was made). The src pixels |
| 451 | * copied are specified by srcRect. They are copied to a rect of the same |
| 452 | * size in dst with top left at dstPoint. If the src rect is clipped by the |
| 453 | * src bounds then pixel values in the dst rect corresponding to area clipped |
| 454 | * by the src rect are not overwritten. This method can fail and return false |
| 455 | * depending on the type of surface, configs, etc, and the backend-specific |
| 456 | * limitations. If rect is clipped out entirely by the src or dst bounds then |
| 457 | * true is returned since there is no actual copy necessary to succeed. |
| 458 | */ |
| 459 | bool copySurface(GrSurface* dst, |
| 460 | GrSurface* src, |
| 461 | const SkIRect& srcRect, |
| 462 | const SkIPoint& dstPoint); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 463 | /** |
| 464 | * Function that determines whether a copySurface call would succeed without |
| 465 | * performing the copy. |
| 466 | */ |
| 467 | bool canCopySurface(GrSurface* dst, |
| 468 | GrSurface* src, |
| 469 | const SkIRect& srcRect, |
| 470 | const SkIPoint& dstPoint); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 471 | |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 472 | /** |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 473 | * This is can be called before allocating a texture to be a dst for copySurface. It will |
| 474 | * populate the origin, config, and flags fields of the desc such that copySurface is more |
| 475 | * likely to succeed and be efficient. |
| 476 | */ |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 477 | virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 478 | |
| 479 | |
| 480 | /** |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 481 | * Release any resources that are cached but not currently in use. This |
| 482 | * is intended to give an application some recourse when resources are low. |
| 483 | */ |
| 484 | virtual void purgeResources() {}; |
| 485 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 486 | /** |
| 487 | * For subclass internal use to invoke a call to onDraw(). See DrawInfo below. |
| 488 | */ |
| 489 | void executeDraw(const DrawInfo& info) { this->onDraw(info); } |
| 490 | |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 491 | /** |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 492 | * For subclass internal use to invoke a call to onDrawPath(). |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 493 | */ |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame^] | 494 | void executeDrawPath(const GrPath* path, GrPathRendering::FillType fill, |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 495 | const GrDeviceCoordTexture* dstCopy) { |
| 496 | this->onDrawPath(path, fill, dstCopy); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 497 | } |
| 498 | |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 499 | /** |
| 500 | * For subclass internal use to invoke a call to onDrawPaths(). |
| 501 | */ |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 502 | void executeDrawPaths(const GrPathRange* pathRange, |
| 503 | const uint32_t indices[], int count, |
| 504 | const float transforms[], PathTransformType transformsType, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame^] | 505 | GrPathRendering::FillType fill, |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 506 | const GrDeviceCoordTexture* dstCopy) { |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 507 | this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fill, dstCopy); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 508 | } |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 509 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 510 | //////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 511 | |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 512 | /** |
| 513 | * See AutoStateRestore below. |
| 514 | */ |
| 515 | enum ASRInit { |
| 516 | kPreserve_ASRInit, |
| 517 | kReset_ASRInit |
| 518 | }; |
| 519 | |
| 520 | /** |
| 521 | * Saves off the current state and restores it in the destructor. It will |
| 522 | * install a new GrDrawState object on the target (setDrawState) and restore |
| 523 | * the previous one in the destructor. The caller should call drawState() to |
| 524 | * get the new draw state after the ASR is installed. |
| 525 | * |
| 526 | * GrDrawState* state = target->drawState(); |
| 527 | * AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit). |
| 528 | * state->setRenderTarget(rt); // state refers to the GrDrawState set on |
| 529 | * // target before asr was initialized. |
| 530 | * // Therefore, rt is set on the GrDrawState |
| 531 | * // that will be restored after asr's |
| 532 | * // destructor rather than target's current |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 533 | * // GrDrawState. |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 534 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 535 | class AutoStateRestore : public ::SkNoncopyable { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 536 | public: |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 537 | /** |
| 538 | * Default ASR will have no effect unless set() is subsequently called. |
| 539 | */ |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 540 | AutoStateRestore(); |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 541 | |
| 542 | /** |
| 543 | * Saves the state on target. The state will be restored when the ASR |
| 544 | * is destroyed. If this constructor is used do not call set(). |
| 545 | * |
| 546 | * @param init Should the newly installed GrDrawState be a copy of the |
| 547 | * previous state or a default-initialized GrDrawState. |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 548 | * @param viewMatrix Optional view matrix. If init = kPreserve then the draw state's |
| 549 | * matrix will be preconcat'ed with the param. All stages will be |
| 550 | updated to compensate for the matrix change. If init == kReset |
| 551 | then the draw state's matrix will be this matrix. |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 552 | */ |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 553 | AutoStateRestore(GrDrawTarget* target, ASRInit init, const SkMatrix* viewMatrix = NULL); |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 554 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 555 | ~AutoStateRestore(); |
| 556 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 557 | /** |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 558 | * Saves the state on target. The state will be restored when the ASR |
| 559 | * is destroyed. This should only be called once per ASR object and only |
| 560 | * when the default constructor was used. For nested saves use multiple |
| 561 | * ASR objects. |
| 562 | * |
| 563 | * @param init Should the newly installed GrDrawState be a copy of the |
| 564 | * previous state or a default-initialized GrDrawState. |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 565 | * @param viewMatrix Optional view matrix. If init = kPreserve then the draw state's |
| 566 | * matrix will be preconcat'ed with the param. All stages will be |
| 567 | updated to compensate for the matrix change. If init == kReset |
| 568 | then the draw state's matrix will be this matrix. |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 569 | */ |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 570 | void set(GrDrawTarget* target, ASRInit init, const SkMatrix* viewMatrix = NULL); |
| 571 | |
| 572 | /** |
| 573 | * Like set() but makes the view matrix identity. When init is kReset it is as though |
| 574 | * NULL was passed to set's viewMatrix param. When init is kPreserve it is as though |
| 575 | * the inverse view matrix was passed. If kPreserve is passed and the draw state's matrix |
| 576 | * is not invertible then this may fail. |
| 577 | */ |
| 578 | bool setIdentity(GrDrawTarget* target, ASRInit init); |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 579 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 580 | private: |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 581 | GrDrawTarget* fDrawTarget; |
| 582 | SkTLazy<GrDrawState> fTempState; |
| 583 | GrDrawState* fSavedState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 584 | }; |
| 585 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 586 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 587 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 588 | class AutoReleaseGeometry : public ::SkNoncopyable { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 589 | public: |
| 590 | AutoReleaseGeometry(GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 591 | int vertexCount, |
| 592 | int indexCount); |
| 593 | AutoReleaseGeometry(); |
| 594 | ~AutoReleaseGeometry(); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 595 | bool set(GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 596 | int vertexCount, |
| 597 | int indexCount); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 598 | bool succeeded() const { return SkToBool(fTarget); } |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 599 | void* vertices() const { SkASSERT(this->succeeded()); return fVertices; } |
| 600 | void* indices() const { SkASSERT(this->succeeded()); return fIndices; } |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 601 | SkPoint* positions() const { |
| 602 | return static_cast<SkPoint*>(this->vertices()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | private: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 606 | void reset(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 607 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 608 | GrDrawTarget* fTarget; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 609 | void* fVertices; |
| 610 | void* fIndices; |
| 611 | }; |
| 612 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 613 | //////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 614 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 615 | class AutoClipRestore : public ::SkNoncopyable { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 616 | public: |
| 617 | AutoClipRestore(GrDrawTarget* target) { |
| 618 | fTarget = target; |
| 619 | fClip = fTarget->getClip(); |
| 620 | } |
| 621 | |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 622 | AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip); |
| 623 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 624 | ~AutoClipRestore() { |
| 625 | fTarget->setClip(fClip); |
| 626 | } |
| 627 | private: |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 628 | GrDrawTarget* fTarget; |
| 629 | const GrClipData* fClip; |
| 630 | SkTLazy<SkClipStack> fStack; |
| 631 | GrClipData fReplacementClip; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 632 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 633 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 634 | //////////////////////////////////////////////////////////////////////////// |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 635 | |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 636 | /** |
| 637 | * Saves the geometry src state at construction and restores in the destructor. It also saves |
| 638 | * and then restores the vertex attrib state. |
| 639 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 640 | class AutoGeometryPush : public ::SkNoncopyable { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 641 | public: |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 642 | AutoGeometryPush(GrDrawTarget* target) |
| 643 | : fAttribRestore(target->drawState()) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 644 | SkASSERT(target); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 645 | fTarget = target; |
| 646 | target->pushGeometrySource(); |
| 647 | } |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 648 | |
| 649 | ~AutoGeometryPush() { fTarget->popGeometrySource(); } |
| 650 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 651 | private: |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 652 | GrDrawTarget* fTarget; |
| 653 | GrDrawState::AutoVertexAttribRestore fAttribRestore; |
| 654 | }; |
| 655 | |
| 656 | /** |
| 657 | * Combination of AutoGeometryPush and AutoStateRestore. The vertex attribs will be in default |
| 658 | * state regardless of ASRInit value. |
| 659 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 660 | class AutoGeometryAndStatePush : public ::SkNoncopyable { |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 661 | public: |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 662 | AutoGeometryAndStatePush(GrDrawTarget* target, |
| 663 | ASRInit init, |
| 664 | const SkMatrix* viewMatrix = NULL) |
| 665 | : fState(target, init, viewMatrix) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 666 | SkASSERT(target); |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 667 | fTarget = target; |
| 668 | target->pushGeometrySource(); |
| 669 | if (kPreserve_ASRInit == init) { |
| 670 | target->drawState()->setDefaultVertexAttribs(); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | ~AutoGeometryAndStatePush() { fTarget->popGeometrySource(); } |
| 675 | |
| 676 | private: |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 677 | AutoStateRestore fState; |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 678 | GrDrawTarget* fTarget; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 679 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 680 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 681 | /////////////////////////////////////////////////////////////////////////// |
| 682 | // Draw execution tracking (for font atlases and other resources) |
| 683 | class DrawToken { |
| 684 | public: |
| 685 | DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : |
| 686 | fDrawTarget(drawTarget), fDrawID(drawID) {} |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 687 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 688 | bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); } |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 689 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 690 | private: |
| 691 | GrDrawTarget* fDrawTarget; |
| 692 | uint32_t fDrawID; // this may wrap, but we're doing direct comparison |
| 693 | // so that should be okay |
| 694 | }; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 695 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 696 | virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 697 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 698 | protected: |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 699 | // Extend access to GrDrawState::convertToPEndeingExec to subclasses. |
| 700 | void convertDrawStateToPendingExec(GrDrawState* ds) { |
bsalomon | 2a9ca78 | 2014-09-05 14:27:43 -0700 | [diff] [blame] | 701 | ds->convertToPendingExec(); |
| 702 | } |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 703 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 704 | enum GeometrySrcType { |
| 705 | kNone_GeometrySrcType, //<! src has not been specified |
| 706 | kReserved_GeometrySrcType, //<! src was set using reserve*Space |
| 707 | kArray_GeometrySrcType, //<! src was set using set*SourceToArray |
| 708 | kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer |
| 709 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 710 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 711 | struct GeometrySrcState { |
| 712 | GeometrySrcType fVertexSrc; |
| 713 | union { |
| 714 | // valid if src type is buffer |
| 715 | const GrVertexBuffer* fVertexBuffer; |
| 716 | // valid if src type is reserved or array |
| 717 | int fVertexCount; |
| 718 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 719 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 720 | GeometrySrcType fIndexSrc; |
| 721 | union { |
| 722 | // valid if src type is buffer |
| 723 | const GrIndexBuffer* fIndexBuffer; |
| 724 | // valid if src type is reserved or array |
| 725 | int fIndexCount; |
| 726 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 727 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 728 | size_t fVertexSize; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 729 | }; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 730 | |
| 731 | int indexCountInCurrentSource() const { |
| 732 | const GeometrySrcState& src = this->getGeomSrc(); |
| 733 | switch (src.fIndexSrc) { |
| 734 | case kNone_GeometrySrcType: |
| 735 | return 0; |
| 736 | case kReserved_GeometrySrcType: |
| 737 | case kArray_GeometrySrcType: |
| 738 | return src.fIndexCount; |
| 739 | case kBuffer_GeometrySrcType: |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 740 | return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t)); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 741 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 742 | SkFAIL("Unexpected Index Source."); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 743 | return 0; |
| 744 | } |
| 745 | } |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 746 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 747 | // This method is called by copySurface The srcRect is guaranteed to be entirely within the |
| 748 | // src bounds. Likewise, the dst rect implied by dstPoint and srcRect's width and height falls |
| 749 | // entirely within the dst. The default implementation will draw a rect from the src to the |
| 750 | // dst if the src is a texture and the dst is a render target and fail otherwise. |
| 751 | virtual bool onCopySurface(GrSurface* dst, |
| 752 | GrSurface* src, |
| 753 | const SkIRect& srcRect, |
| 754 | const SkIPoint& dstPoint); |
| 755 | |
| 756 | // Called to determine whether an onCopySurface call would succeed or not. This is useful for |
| 757 | // proxy subclasses to test whether the copy would succeed without executing it yet. Derived |
| 758 | // classes must keep this consistent with their implementation of onCopySurface(). The inputs |
| 759 | // are the same as onCopySurface(), i.e. srcRect and dstPoint are clipped to be inside the src |
| 760 | // and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 761 | virtual bool onCanCopySurface(GrSurface* dst, |
| 762 | GrSurface* src, |
| 763 | const SkIRect& srcRect, |
| 764 | const SkIPoint& dstPoint); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 765 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 766 | GrContext* getContext() { return fContext; } |
| 767 | const GrContext* getContext() const { return fContext; } |
| 768 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 769 | // A subclass may override this function if it wishes to be notified when the clip is changed. |
| 770 | // The override should call INHERITED::clipWillBeSet(). |
| 771 | virtual void clipWillBeSet(const GrClipData* clipData); |
| 772 | |
| 773 | // subclasses must call this in their destructors to ensure all vertex |
| 774 | // and index sources have been released (including those held by |
| 775 | // pushGeometrySource()) |
| 776 | void releaseGeometry(); |
| 777 | |
| 778 | // accessors for derived classes |
| 779 | const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); } |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 780 | // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert. |
| 781 | size_t getVertexSize() const { |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 782 | // 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] | 783 | SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 784 | return this->getGeomSrc().fVertexSize; |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 785 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 786 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 787 | // Subclass must initialize this in its constructor. |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 788 | SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 789 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 790 | const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; } |
| 791 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 792 | /** |
| 793 | * Used to communicate draws to subclass's onDraw function. |
| 794 | */ |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 795 | class DrawInfo { |
| 796 | public: |
| 797 | DrawInfo(const DrawInfo& di) { (*this) = di; } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 798 | DrawInfo& operator =(const DrawInfo& di); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 799 | |
| 800 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 801 | int startVertex() const { return fStartVertex; } |
| 802 | int startIndex() const { return fStartIndex; } |
| 803 | int vertexCount() const { return fVertexCount; } |
| 804 | int indexCount() const { return fIndexCount; } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 805 | int verticesPerInstance() const { return fVerticesPerInstance; } |
| 806 | int indicesPerInstance() const { return fIndicesPerInstance; } |
| 807 | int instanceCount() const { return fInstanceCount; } |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 808 | |
| 809 | bool isIndexed() const { return fIndexCount > 0; } |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 810 | #ifdef SK_DEBUG |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 811 | bool isInstanced() const; // this version is longer because of asserts |
| 812 | #else |
| 813 | bool isInstanced() const { return fInstanceCount > 0; } |
| 814 | #endif |
| 815 | |
| 816 | // adds or remove instances |
| 817 | void adjustInstanceCount(int instanceOffset); |
| 818 | // shifts the start vertex |
| 819 | void adjustStartVertex(int vertexOffset); |
| 820 | // shifts the start index |
| 821 | void adjustStartIndex(int indexOffset); |
| 822 | |
| 823 | void setDevBounds(const SkRect& bounds) { |
| 824 | fDevBoundsStorage = bounds; |
| 825 | fDevBounds = &fDevBoundsStorage; |
| 826 | } |
| 827 | const SkRect* getDevBounds() const { return fDevBounds; } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 828 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 829 | // NULL if no copy of the dst is needed for the draw. |
| 830 | const GrDeviceCoordTexture* getDstCopy() const { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 831 | if (fDstCopy.texture()) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 832 | return &fDstCopy; |
| 833 | } else { |
| 834 | return NULL; |
| 835 | } |
| 836 | } |
| 837 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 838 | private: |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 839 | DrawInfo() { fDevBounds = NULL; } |
| 840 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 841 | friend class GrDrawTarget; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 842 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 843 | GrPrimitiveType fPrimitiveType; |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 844 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 845 | int fStartVertex; |
| 846 | int fStartIndex; |
| 847 | int fVertexCount; |
| 848 | int fIndexCount; |
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 | int fInstanceCount; |
| 851 | int fVerticesPerInstance; |
| 852 | int fIndicesPerInstance; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 853 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 854 | SkRect fDevBoundsStorage; |
| 855 | SkRect* fDevBounds; |
| 856 | |
| 857 | GrDeviceCoordTexture fDstCopy; |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 858 | }; |
| 859 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 860 | // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required |
| 861 | // but couldn't be made. Otherwise, returns true. This method needs to be protected because it |
| 862 | // needs to be accessed by GLPrograms to setup a correct drawstate |
| 863 | bool setupDstReadIfNecessary(DrawInfo* info) { |
| 864 | return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds()); |
| 865 | } |
| 866 | bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* drawBounds); |
| 867 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 868 | private: |
| 869 | // A subclass can optionally overload this function to be notified before |
| 870 | // vertex and index space is reserved. |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 871 | virtual void willReserveVertexAndIndexSpace(int vertexCount, int indexCount) {} |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 872 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 873 | // implemented by subclass to allocate space for reserved geom |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 874 | virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 875 | virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; |
| 876 | // implemented by subclass to handle release of reserved geom space |
| 877 | virtual void releaseReservedVertexSpace() = 0; |
| 878 | virtual void releaseReservedIndexSpace() = 0; |
| 879 | // subclass must consume array contents when set |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 880 | virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCount) = 0; |
| 881 | virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 882 | // subclass is notified that geom source will be set away from an array |
| 883 | virtual void releaseVertexArray() = 0; |
| 884 | virtual void releaseIndexArray() = 0; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 885 | // 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] | 886 | virtual void geometrySourceWillPush() = 0; |
| 887 | virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; |
| 888 | // subclass called to perform drawing |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 889 | virtual void onDraw(const DrawInfo&) = 0; |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 890 | // Implementation of drawRect. The geometry src and vertex attribs will already |
| 891 | // be saved before this is called and restored afterwards. A subclass may override |
| 892 | // this to perform more optimal rect rendering. Its draws should be funneled through |
| 893 | // one of the public GrDrawTarget draw methods (e.g. drawNonIndexed, |
| 894 | // drawIndexedInstances, ...). The base class draws a two triangle fan using |
| 895 | // drawNonIndexed from reserved vertex space. |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 896 | virtual void onDrawRect(const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 897 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 898 | const SkMatrix* localMatrix); |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 899 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame^] | 900 | virtual void onStencilPath(const GrPath*, GrPathRendering::FillType) = 0; |
| 901 | virtual void onDrawPath(const GrPath*, GrPathRendering::FillType, |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 902 | const GrDeviceCoordTexture* dstCopy) = 0; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 903 | virtual void onDrawPaths(const GrPathRange*, |
| 904 | const uint32_t indices[], int count, |
| 905 | const float transforms[], PathTransformType, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame^] | 906 | GrPathRendering::FillType, const GrDeviceCoordTexture*) = 0; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 907 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 908 | virtual void didAddGpuTraceMarker() = 0; |
| 909 | virtual void didRemoveGpuTraceMarker() = 0; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 910 | |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 911 | // helpers for reserving vertex and index space. |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 912 | bool reserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 913 | int vertexCount, |
| 914 | void** vertices); |
| 915 | bool reserveIndexSpace(int indexCount, void** indices); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 916 | |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 917 | // called by drawIndexed and drawNonIndexed. Use a negative indexCount to |
| 918 | // indicate non-indexed drawing. |
| 919 | bool checkDraw(GrPrimitiveType type, int startVertex, |
| 920 | int startIndex, int vertexCount, |
| 921 | int indexCount) const; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 922 | // called when setting a new vert/idx source to unref prev vb/ib |
| 923 | void releasePreviousVertexSource(); |
| 924 | void releasePreviousIndexSource(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 925 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 926 | // Check to see if this set of draw commands has been sent out |
| 927 | virtual bool isIssued(uint32_t drawID) { return true; } |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 928 | virtual GrClipMaskManager* getClipMaskManager() = 0; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 929 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 930 | enum { |
| 931 | kPreallocGeoSrcStateStackCnt = 4, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 932 | }; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 933 | SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack; |
| 934 | const GrClipData* fClip; |
| 935 | GrDrawState* fDrawState; |
| 936 | GrDrawState fDefaultDrawState; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 937 | // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget. |
| 938 | GrContext* fContext; |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 939 | // To keep track that we always have at least as many debug marker adds as removes |
| 940 | int fGpuTraceMarkerCount; |
| 941 | GrTraceMarkerSet fActiveTraceMarkers; |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 942 | GrTraceMarkerSet fStoredTraceMarkers; |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 943 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 944 | typedef SkRefCnt INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 945 | }; |
| 946 | |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 947 | /* |
| 948 | * This class is JUST for clip mask manager. Everyone else should just use draw target above. |
| 949 | */ |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 950 | class GrClipTarget : public GrDrawTarget { |
| 951 | public: |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 952 | GrClipTarget(GrContext* context) : INHERITED(context) { |
| 953 | fClipMaskManager.setClipTarget(this); |
| 954 | } |
| 955 | |
| 956 | /* Clip mask manager needs access to the context. |
| 957 | * TODO we only need a very small subset of context in the CMM. |
| 958 | */ |
| 959 | GrContext* getContext() { return INHERITED::getContext(); } |
| 960 | const GrContext* getContext() const { return INHERITED::getContext(); } |
| 961 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 962 | /** |
| 963 | * Clip Mask Manager(and no one else) needs to clear private stencil bits. |
| 964 | * ClipTarget subclass sets clip bit in the stencil buffer. The subclass |
| 965 | * is free to clear the remaining bits to zero if masked clears are more |
| 966 | * expensive than clearing all bits. |
| 967 | */ |
| 968 | virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0; |
| 969 | |
joshualitt | 3bdd7dc | 2014-10-31 08:27:39 -0700 | [diff] [blame] | 970 | /** |
| 971 | * Release any resources that are cached but not currently in use. This |
| 972 | * is intended to give an application some recourse when resources are low. |
| 973 | */ |
| 974 | virtual void purgeResources() SK_OVERRIDE { |
| 975 | // The clip mask manager can rebuild all its clip masks so just |
| 976 | // get rid of them all. |
| 977 | fClipMaskManager.purgeResources(); |
| 978 | }; |
| 979 | |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 980 | protected: |
| 981 | GrClipMaskManager fClipMaskManager; |
| 982 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 983 | private: |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 984 | GrClipMaskManager* getClipMaskManager() { return &fClipMaskManager; } |
| 985 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 986 | typedef GrDrawTarget INHERITED; |
| 987 | }; |
| 988 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 989 | #endif |