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