| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrDrawTarget_DEFINED | 8 #ifndef GrDrawTarget_DEFINED |
| 9 #define GrDrawTarget_DEFINED | 9 #define GrDrawTarget_DEFINED |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 void setClip(const GrClipData* clip); | 60 void setClip(const GrClipData* clip); |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Gets the current clip. | 63 * Gets the current clip. |
| 64 * | 64 * |
| 65 * @return the clip. | 65 * @return the clip. |
| 66 */ | 66 */ |
| 67 const GrClipData* getClip() const; | 67 const GrClipData* getClip() const; |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * Sets the draw state object for the draw target. Note that this does not | |
| 71 * make a copy. The GrDrawTarget will take a reference to passed object. | |
| 72 * Passing NULL will cause the GrDrawTarget to use its own internal draw | |
| 73 * state object rather than an externally provided one. | |
| 74 */ | |
| 75 void setDrawState(GrDrawState* drawState); | |
| 76 | |
| 77 /** | |
| 78 * Read-only access to the GrDrawTarget's current draw state. | |
| 79 */ | |
| 80 const GrDrawState& getDrawState() const { return *fDrawState; } | |
| 81 | |
| 82 /** | |
| 83 * Read-write access to the GrDrawTarget's current draw state. Note that | |
| 84 * this doesn't ref. | |
| 85 */ | |
| 86 GrDrawState* drawState() { return fDrawState; } | |
| 87 | |
| 88 /** When we're using coverage AA but the blend is incompatible (given gpu | |
| 89 * limitations) we should disable AA. */ | |
| 90 bool shouldDisableCoverageAAForBlend() const { | |
| 91 // Enable below if we should draw with AA even when it produces | |
| 92 // incorrect blending. | |
| 93 // return false; | |
| 94 return !this->getDrawState().couldApplyCoverage(*this->caps()); | |
| 95 } | |
| 96 | |
| 97 /** | |
| 98 * There are three types of "sources" of geometry (vertices and indices) for | 70 * There are three types of "sources" of geometry (vertices and indices) for |
| 99 * draw calls made on the target. When performing an indexed draw, the | 71 * draw calls made on the target. When performing an indexed draw, the |
| 100 * indices and vertices can use different source types. Once a source is | 72 * indices and vertices can use different source types. Once a source is |
| 101 * specified it can be used for multiple draws. However, the time at which | 73 * specified it can be used for multiple draws. However, the time at which |
| 102 * the geometry data is no longer editable depends on the source type. | 74 * the geometry data is no longer editable depends on the source type. |
| 103 * | 75 * |
| 104 * Sometimes it is necessary to perform a draw while upstack code has | 76 * Sometimes it is necessary to perform a draw while upstack code has |
| 105 * already specified geometry that it isn't finished with. So there are push | 77 * already specified geometry that it isn't finished with. So there are push |
| 106 * and pop methods. This allows the client to push the sources, draw | 78 * and pop methods. This allows the client to push the sources, draw |
| 107 * something using alternate sources, and then pop to restore the original | 79 * something using alternate sources, and then pop to restore the original |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 * | 133 * |
| 162 * @param vertexCount the number of vertices to reserve space for. Can be | 134 * @param vertexCount the number of vertices to reserve space for. Can be |
| 163 * 0. Vertex size is queried from the current GrDrawStat
e. | 135 * 0. Vertex size is queried from the current GrDrawStat
e. |
| 164 * @param indexCount the number of indices to reserve space for. Can be 0. | 136 * @param indexCount the number of indices to reserve space for. Can be 0. |
| 165 * @param vertices will point to reserved vertex space if vertexCount is | 137 * @param vertices will point to reserved vertex space if vertexCount is |
| 166 * non-zero. Illegal to pass NULL if vertexCount > 0. | 138 * non-zero. Illegal to pass NULL if vertexCount > 0. |
| 167 * @param indices will point to reserved index space if indexCount is | 139 * @param indices will point to reserved index space if indexCount is |
| 168 * non-zero. Illegal to pass NULL if indexCount > 0. | 140 * non-zero. Illegal to pass NULL if indexCount > 0. |
| 169 */ | 141 */ |
| 170 bool reserveVertexAndIndexSpace(int vertexCount, | 142 bool reserveVertexAndIndexSpace(int vertexCount, |
| 143 size_t vertexStride, |
| 171 int indexCount, | 144 int indexCount, |
| 172 void** vertices, | 145 void** vertices, |
| 173 void** indices); | 146 void** indices); |
| 174 | 147 |
| 175 /** | 148 /** |
| 176 * Provides hints to caller about the number of vertices and indices | 149 * Provides hints to caller about the number of vertices and indices |
| 177 * that can be allocated cheaply. This can be useful if caller is reserving | 150 * that can be allocated cheaply. This can be useful if caller is reserving |
| 178 * space but doesn't know exactly how much geometry is needed. | 151 * space but doesn't know exactly how much geometry is needed. |
| 179 * | 152 * |
| 180 * Also may hint whether the draw target should be flushed first. This is | 153 * Also may hint whether the draw target should be flushed first. This is |
| 181 * useful for deferred targets. | 154 * useful for deferred targets. |
| 182 * | 155 * |
| 183 * @param vertexCount in: hint about how many vertices the caller would | 156 * @param vertexCount in: hint about how many vertices the caller would |
| 184 * like to allocate. Vertex size is queried from the | 157 * like to allocate. Vertex size is queried from the |
| 185 * current GrDrawState. | 158 * current GrDrawState. |
| 186 * out: a hint about the number of vertices that can be | 159 * out: a hint about the number of vertices that can be |
| 187 * allocated cheaply. Negative means no hint. | 160 * allocated cheaply. Negative means no hint. |
| 188 * Ignored if NULL. | 161 * Ignored if NULL. |
| 189 * @param indexCount in: hint about how many indices the caller would | 162 * @param indexCount in: hint about how many indices the caller would |
| 190 * like to allocate. | 163 * like to allocate. |
| 191 * out: a hint about the number of indices that can be | 164 * out: a hint about the number of indices that can be |
| 192 * allocated cheaply. Negative means no hint. | 165 * allocated cheaply. Negative means no hint. |
| 193 * Ignored if NULL. | 166 * Ignored if NULL. |
| 194 * | 167 * |
| 195 * @return true if target should be flushed based on the input values. | 168 * @return true if target should be flushed based on the input values. |
| 196 */ | 169 */ |
| 197 virtual bool geometryHints(int* vertexCount, | 170 virtual bool geometryHints(size_t vertexStride, int* vertexCount, int* index
Count) const; |
| 198 int* indexCount) const; | |
| 199 | 171 |
| 200 /** | 172 /** |
| 201 * Sets source of vertex data for the next draw. Data does not have to be | 173 * Sets source of vertex data for the next draw. Data does not have to be |
| 202 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. | 174 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. |
| 203 * | 175 * |
| 204 * @param buffer vertex buffer containing vertex data. Must be | 176 * @param buffer vertex buffer containing vertex data. Must be |
| 205 * unlocked before draw call. Vertex size is queried | 177 * unlocked before draw call. Vertex size is queried |
| 206 * from current GrDrawState. | 178 * from current GrDrawState. |
| 207 */ | 179 */ |
| 208 void setVertexSourceToBuffer(const GrVertexBuffer* buffer); | 180 void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStri
de); |
| 209 | 181 |
| 210 /** | 182 /** |
| 211 * Sets source of index data for the next indexed draw. Data does not have | 183 * Sets source of index data for the next indexed draw. Data does not have |
| 212 * to be in the buffer until drawIndexed. | 184 * to be in the buffer until drawIndexed. |
| 213 * | 185 * |
| 214 * @param buffer index buffer containing indices. Must be unlocked | 186 * @param buffer index buffer containing indices. Must be unlocked |
| 215 * before indexed draw call. | 187 * before indexed draw call. |
| 216 */ | 188 */ |
| 217 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); | 189 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
| 218 | 190 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 * @param startVertex the vertex in the vertex array/buffer corresponding | 232 * @param startVertex the vertex in the vertex array/buffer corresponding |
| 261 * to index 0 | 233 * to index 0 |
| 262 * @param startIndex first index to read from index src. | 234 * @param startIndex first index to read from index src. |
| 263 * @param vertexCount one greater than the max index. | 235 * @param vertexCount one greater than the max index. |
| 264 * @param indexCount the number of index elements to read. The index count | 236 * @param indexCount the number of index elements to read. The index count |
| 265 * is effectively trimmed to the last completely | 237 * is effectively trimmed to the last completely |
| 266 * specified primitive. | 238 * specified primitive. |
| 267 * @param devBounds optional bounds hint. This is a promise from the call
er, | 239 * @param devBounds optional bounds hint. This is a promise from the call
er, |
| 268 * not a request for clipping. | 240 * not a request for clipping. |
| 269 */ | 241 */ |
| 270 void drawIndexed(GrPrimitiveType type, | 242 void drawIndexed(GrDrawState*, |
| 243 GrPrimitiveType type, |
| 271 int startVertex, | 244 int startVertex, |
| 272 int startIndex, | 245 int startIndex, |
| 273 int vertexCount, | 246 int vertexCount, |
| 274 int indexCount, | 247 int indexCount, |
| 275 const SkRect* devBounds = NULL); | 248 const SkRect* devBounds = NULL); |
| 276 | 249 |
| 277 /** | 250 /** |
| 278 * Draws non-indexed geometry using the current state and current vertex | 251 * Draws non-indexed geometry using the current state and current vertex |
| 279 * sources. | 252 * sources. |
| 280 * | 253 * |
| 281 * @param type The type of primitives to draw. | 254 * @param type The type of primitives to draw. |
| 282 * @param startVertex the vertex in the vertex array/buffer corresponding | 255 * @param startVertex the vertex in the vertex array/buffer corresponding |
| 283 * to index 0 | 256 * to index 0 |
| 284 * @param vertexCount one greater than the max index. | 257 * @param vertexCount one greater than the max index. |
| 285 * @param devBounds optional bounds hint. This is a promise from the call
er, | 258 * @param devBounds optional bounds hint. This is a promise from the call
er, |
| 286 * not a request for clipping. | 259 * not a request for clipping. |
| 287 */ | 260 */ |
| 288 void drawNonIndexed(GrPrimitiveType type, | 261 void drawNonIndexed(GrDrawState*, |
| 262 GrPrimitiveType type, |
| 289 int startVertex, | 263 int startVertex, |
| 290 int vertexCount, | 264 int vertexCount, |
| 291 const SkRect* devBounds = NULL); | 265 const SkRect* devBounds = NULL); |
| 292 | 266 |
| 293 /** | 267 /** |
| 294 * Draws path into the stencil buffer. The fill must be either even/odd or | 268 * Draws path into the stencil buffer. The fill must be either even/odd or |
| 295 * winding (not inverse or hairline). It will respect the HW antialias flag | 269 * winding (not inverse or hairline). It will respect the HW antialias flag |
| 296 * on the draw state (if possible in the 3D API). Note, we will never have
an inverse fill | 270 * on the draw state (if possible in the 3D API). Note, we will never have
an inverse fill |
| 297 * with stencil path | 271 * with stencil path |
| 298 */ | 272 */ |
| 299 void stencilPath(const GrPath*, GrPathRendering::FillType fill); | 273 void stencilPath(GrDrawState*, const GrPath*, GrPathRendering::FillType fill
); |
| 300 | 274 |
| 301 /** | 275 /** |
| 302 * Draws a path. Fill must not be a hairline. It will respect the HW | 276 * Draws a path. Fill must not be a hairline. It will respect the HW |
| 303 * antialias flag on the draw state (if possible in the 3D API). | 277 * antialias flag on the draw state (if possible in the 3D API). |
| 304 */ | 278 */ |
| 305 void drawPath(const GrPath*, GrPathRendering::FillType fill); | 279 void drawPath(GrDrawState*, const GrPath*, GrPathRendering::FillType fill); |
| 306 | 280 |
| 307 /** | 281 /** |
| 308 * Draws many paths. It will respect the HW | 282 * Draws many paths. It will respect the HW |
| 309 * antialias flag on the draw state (if possible in the 3D API). | 283 * antialias flag on the draw state (if possible in the 3D API). |
| 310 * | 284 * |
| 311 * @param pathRange Source of paths to draw from | 285 * @param pathRange Source of paths to draw from |
| 312 * @param indices Array of indices into the the pathRange | 286 * @param indices Array of indices into the the pathRange |
| 313 * @param count Number of paths to draw (length of indices array) | 287 * @param count Number of paths to draw (length of indices array) |
| 314 * @param transforms Array of individual transforms, one for each path | 288 * @param transforms Array of individual transforms, one for each path |
| 315 * @param transformsType Type of transformations in the array. Array contai
ns | 289 * @param transformsType Type of transformations in the array. Array contai
ns |
| 316 PathTransformSize(transformsType) * count elements | 290 PathTransformSize(transformsType) * count elements |
| 317 * @param fill Fill type for drawing all the paths | 291 * @param fill Fill type for drawing all the paths |
| 318 */ | 292 */ |
| 319 void drawPaths(const GrPathRange* pathRange, | 293 void drawPaths(GrDrawState*, const GrPathRange* pathRange, |
| 320 const uint32_t indices[], int count, | 294 const uint32_t indices[], |
| 321 const float transforms[], PathTransformType transformsType, | 295 int count, |
| 296 const float transforms[], |
| 297 PathTransformType transformsType, |
| 322 GrPathRendering::FillType fill); | 298 GrPathRendering::FillType fill); |
| 323 | 299 |
| 324 /** | 300 /** |
| 325 * Helper function for drawing rects. It performs a geometry src push and po
p | 301 * Helper function for drawing rects. It performs a geometry src push and po
p |
| 326 * and thus will finalize any reserved geometry. | 302 * and thus will finalize any reserved geometry. |
| 327 * | 303 * |
| 328 * @param rect the rect to draw | 304 * @param rect the rect to draw |
| 329 * @param localRect optional rect that specifies local coords to map onto | 305 * @param localRect optional rect that specifies local coords to map onto |
| 330 * rect. If NULL then rect serves as the local coords. | 306 * rect. If NULL then rect serves as the local coords. |
| 331 * @param localMatrix optional matrix applied to localRect. If | 307 * @param localMatrix optional matrix applied to localRect. If |
| 332 * srcRect is non-NULL and srcMatrix is non-NULL | 308 * srcRect is non-NULL and srcMatrix is non-NULL |
| 333 * then srcRect will be transformed by srcMatrix. | 309 * then srcRect will be transformed by srcMatrix. |
| 334 * srcMatrix can be NULL when no srcMatrix is desired. | 310 * srcMatrix can be NULL when no srcMatrix is desired. |
| 335 */ | 311 */ |
| 336 void drawRect(const SkRect& rect, | 312 void drawRect(GrDrawState* ds, |
| 313 const SkRect& rect, |
| 337 const SkRect* localRect, | 314 const SkRect* localRect, |
| 338 const SkMatrix* localMatrix) { | 315 const SkMatrix* localMatrix) { |
| 339 AutoGeometryPush agp(this); | 316 AutoGeometryPush agp(this); |
| 340 this->onDrawRect(rect, localRect, localMatrix); | 317 this->onDrawRect(ds, rect, localRect, localMatrix); |
| 341 } | 318 } |
| 342 | 319 |
| 343 /** | 320 /** |
| 344 * Helper for drawRect when the caller doesn't need separate local rects or
matrices. | 321 * Helper for drawRect when the caller doesn't need separate local rects or
matrices. |
| 345 */ | 322 */ |
| 346 void drawSimpleRect(const SkRect& rect) { | 323 void drawSimpleRect(GrDrawState* ds, const SkRect& rect) { |
| 347 this->drawRect(rect, NULL, NULL); | 324 this->drawRect(ds, rect, NULL, NULL); |
| 348 } | 325 } |
| 349 void drawSimpleRect(const SkIRect& irect) { | 326 void drawSimpleRect(GrDrawState* ds, const SkIRect& irect) { |
| 350 SkRect rect = SkRect::Make(irect); | 327 SkRect rect = SkRect::Make(irect); |
| 351 this->drawRect(rect, NULL, NULL); | 328 this->drawRect(ds, rect, NULL, NULL); |
| 352 } | 329 } |
| 353 | 330 |
| 354 /** | 331 /** |
| 355 * This call is used to draw multiple instances of some geometry with a | 332 * This call is used to draw multiple instances of some geometry with a |
| 356 * given number of vertices (V) and indices (I) per-instance. The indices in | 333 * given number of vertices (V) and indices (I) per-instance. The indices in |
| 357 * the index source must have the form i[k+I] == i[k] + V. Also, all indices | 334 * the index source must have the form i[k+I] == i[k] + V. Also, all indices |
| 358 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a | 335 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a |
| 359 * concrete example, the following index buffer for drawing a series of | 336 * concrete example, the following index buffer for drawing a series of |
| 360 * quads each as two triangles each satisfies these conditions with V=4 and | 337 * quads each as two triangles each satisfies these conditions with V=4 and |
| 361 * I=6: | 338 * I=6: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 374 * consists of verticesPerInstance vertices indexed by | 351 * consists of verticesPerInstance vertices indexed by |
| 375 * indicesPerInstance indices drawn as the primitive | 352 * indicesPerInstance indices drawn as the primitive |
| 376 * type specified by type. | 353 * type specified by type. |
| 377 * @param verticesPerInstance The number of vertices in each instance (V | 354 * @param verticesPerInstance The number of vertices in each instance (V |
| 378 * in the above description). | 355 * in the above description). |
| 379 * @param indicesPerInstance The number of indices in each instance (I | 356 * @param indicesPerInstance The number of indices in each instance (I |
| 380 * in the above description). | 357 * in the above description). |
| 381 * @param devBounds optional bounds hint. This is a promise from the call
er, | 358 * @param devBounds optional bounds hint. This is a promise from the call
er, |
| 382 * not a request for clipping. | 359 * not a request for clipping. |
| 383 */ | 360 */ |
| 384 void drawIndexedInstances(GrPrimitiveType type, | 361 void drawIndexedInstances(GrDrawState*, |
| 362 GrPrimitiveType type, |
| 385 int instanceCount, | 363 int instanceCount, |
| 386 int verticesPerInstance, | 364 int verticesPerInstance, |
| 387 int indicesPerInstance, | 365 int indicesPerInstance, |
| 388 const SkRect* devBounds = NULL); | 366 const SkRect* devBounds = NULL); |
| 389 | 367 |
| 390 /** | 368 /** |
| 391 * Clear the passed in render target. Ignores the draw state and clip. Clear
s the whole thing if | 369 * Clear the passed in render target. Ignores the draw state and clip. Clear
s the whole thing if |
| 392 * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the e
ntire render target | 370 * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the e
ntire render target |
| 393 * can be optionally cleared. | 371 * can be optionally cleared. |
| 394 */ | 372 */ |
| 395 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, | 373 void clear(const SkIRect* rect, |
| 374 GrColor color, |
| 375 bool canIgnoreRect, |
| 396 GrRenderTarget* renderTarget); | 376 GrRenderTarget* renderTarget); |
| 397 | 377 |
| 398 /** | 378 /** |
| 399 * Discards the contents render target. | 379 * Discards the contents render target. |
| 400 **/ | 380 **/ |
| 401 virtual void discard(GrRenderTarget*) = 0; | 381 virtual void discard(GrRenderTarget*) = 0; |
| 402 | 382 |
| 403 /** | 383 /** |
| 404 * Called at start and end of gpu trace marking | 384 * Called at start and end of gpu trace marking |
| 405 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call th
ese at the start | 385 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call th
ese at the start |
| (...skipping 25 matching lines...) Expand all Loading... |
| 431 * true is returned since there is no actual copy necessary to succeed. | 411 * true is returned since there is no actual copy necessary to succeed. |
| 432 */ | 412 */ |
| 433 virtual bool copySurface(GrSurface* dst, | 413 virtual bool copySurface(GrSurface* dst, |
| 434 GrSurface* src, | 414 GrSurface* src, |
| 435 const SkIRect& srcRect, | 415 const SkIRect& srcRect, |
| 436 const SkIPoint& dstPoint); | 416 const SkIPoint& dstPoint); |
| 437 /** | 417 /** |
| 438 * Function that determines whether a copySurface call would succeed without | 418 * Function that determines whether a copySurface call would succeed without |
| 439 * performing the copy. | 419 * performing the copy. |
| 440 */ | 420 */ |
| 441 virtual bool canCopySurface(GrSurface* dst, | 421 virtual bool canCopySurface(const GrSurface* dst, |
| 442 GrSurface* src, | 422 const GrSurface* src, |
| 443 const SkIRect& srcRect, | 423 const SkIRect& srcRect, |
| 444 const SkIPoint& dstPoint); | 424 const SkIPoint& dstPoint); |
| 445 | 425 |
| 446 /** | 426 /** |
| 447 * This is can be called before allocating a texture to be a dst for copySur
face. It will | 427 * This is can be called before allocating a texture to be a dst for copySur
face. It will |
| 448 * populate the origin, config, and flags fields of the desc such that copyS
urface is more | 428 * populate the origin, config, and flags fields of the desc such that copyS
urface is more |
| 449 * likely to succeed and be efficient. | 429 * likely to succeed and be efficient. |
| 450 */ | 430 */ |
| 451 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des
c); | 431 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des
c); |
| 452 | 432 |
| 453 | 433 |
| 454 /** | 434 /** |
| 455 * Release any resources that are cached but not currently in use. This | 435 * Release any resources that are cached but not currently in use. This |
| 456 * is intended to give an application some recourse when resources are low. | 436 * is intended to give an application some recourse when resources are low. |
| 457 */ | 437 */ |
| 458 virtual void purgeResources() {}; | 438 virtual void purgeResources() {}; |
| 459 | 439 |
| 460 class DrawInfo; | |
| 461 /** | |
| 462 * For subclass internal use to invoke a call to onDraw(). See DrawInfo belo
w. | |
| 463 */ | |
| 464 void executeDraw(const DrawInfo& info, | |
| 465 const GrClipMaskManager::ScissorState& scissorState) { | |
| 466 this->onDraw(info, scissorState); | |
| 467 } | |
| 468 | |
| 469 /** | |
| 470 * For subclass internal use to invoke a call to onStencilPath(). | |
| 471 */ | |
| 472 void executeStencilPath(const GrPath* path, | |
| 473 const GrClipMaskManager::ScissorState& scissorState, | |
| 474 const GrStencilSettings& stencilSettings) { | |
| 475 this->onStencilPath(path, scissorState, stencilSettings); | |
| 476 } | |
| 477 | |
| 478 /** | |
| 479 * For subclass internal use to invoke a call to onDrawPath(). | |
| 480 */ | |
| 481 void executeDrawPath(const GrPath* path, | |
| 482 const GrClipMaskManager::ScissorState& scissorState, | |
| 483 const GrStencilSettings& stencilSettings, | |
| 484 const GrDeviceCoordTexture* dstCopy) { | |
| 485 this->onDrawPath(path, scissorState, stencilSettings, dstCopy); | |
| 486 } | |
| 487 | |
| 488 /** | |
| 489 * For subclass internal use to invoke a call to onDrawPaths(). | |
| 490 */ | |
| 491 void executeDrawPaths(const GrPathRange* pathRange, | |
| 492 const uint32_t indices[], | |
| 493 int count, | |
| 494 const float transforms[], | |
| 495 PathTransformType transformsType, | |
| 496 const GrClipMaskManager::ScissorState& scissorState, | |
| 497 const GrStencilSettings& stencilSettings, | |
| 498 const GrDeviceCoordTexture* dstCopy) { | |
| 499 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, | |
| 500 scissorState, stencilSettings, dstCopy); | |
| 501 } | |
| 502 | |
| 503 //////////////////////////////////////////////////////////////////////////// | |
| 504 | |
| 505 /** | |
| 506 * See AutoStateRestore below. | |
| 507 */ | |
| 508 enum ASRInit { | |
| 509 kPreserve_ASRInit, | |
| 510 kReset_ASRInit | |
| 511 }; | |
| 512 | |
| 513 /** | |
| 514 * Saves off the current state and restores it in the destructor. It will | |
| 515 * install a new GrDrawState object on the target (setDrawState) and restore | |
| 516 * the previous one in the destructor. The caller should call drawState() to | |
| 517 * get the new draw state after the ASR is installed. | |
| 518 * | |
| 519 * GrDrawState* state = target->drawState(); | |
| 520 * AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit). | |
| 521 * state->setRenderTarget(rt); // state refers to the GrDrawState set on | |
| 522 * // target before asr was initialized. | |
| 523 * // Therefore, rt is set on the GrDrawState | |
| 524 * // that will be restored after asr's | |
| 525 * // destructor rather than target's current | |
| 526 * // GrDrawState. | |
| 527 */ | |
| 528 class AutoStateRestore : public ::SkNoncopyable { | |
| 529 public: | |
| 530 /** | |
| 531 * Default ASR will have no effect unless set() is subsequently called. | |
| 532 */ | |
| 533 AutoStateRestore(); | |
| 534 | |
| 535 /** | |
| 536 * Saves the state on target. The state will be restored when the ASR | |
| 537 * is destroyed. If this constructor is used do not call set(). | |
| 538 * | |
| 539 * @param init Should the newly installed GrDrawState be a copy of the | |
| 540 * previous state or a default-initialized GrDrawState. | |
| 541 * @param viewMatrix Optional view matrix. If init = kPreserve then the
draw state's | |
| 542 * matrix will be preconcat'ed with the param. All sta
ges will be | |
| 543 updated to compensate for the matrix change. If ini
t == kReset | |
| 544 then the draw state's matrix will be this matrix. | |
| 545 */ | |
| 546 AutoStateRestore(GrDrawTarget* target, ASRInit init, const SkMatrix* vie
wMatrix = NULL); | |
| 547 | |
| 548 ~AutoStateRestore(); | |
| 549 | |
| 550 /** | |
| 551 * Saves the state on target. The state will be restored when the ASR | |
| 552 * is destroyed. This should only be called once per ASR object and only | |
| 553 * when the default constructor was used. For nested saves use multiple | |
| 554 * ASR objects. | |
| 555 * | |
| 556 * @param init Should the newly installed GrDrawState be a copy of the | |
| 557 * previous state or a default-initialized GrDrawState. | |
| 558 * @param viewMatrix Optional view matrix. If init = kPreserve then the
draw state's | |
| 559 * matrix will be preconcat'ed with the param. All sta
ges will be | |
| 560 updated to compensate for the matrix change. If ini
t == kReset | |
| 561 then the draw state's matrix will be this matrix. | |
| 562 */ | |
| 563 void set(GrDrawTarget* target, ASRInit init, const SkMatrix* viewMatrix
= NULL); | |
| 564 | |
| 565 /** | |
| 566 * Like set() but makes the view matrix identity. When init is kReset it
is as though | |
| 567 * NULL was passed to set's viewMatrix param. When init is kPreserve it
is as though | |
| 568 * the inverse view matrix was passed. If kPreserve is passed and the dr
aw state's matrix | |
| 569 * is not invertible then this may fail. | |
| 570 */ | |
| 571 bool setIdentity(GrDrawTarget* target, ASRInit init); | |
| 572 | |
| 573 private: | |
| 574 GrDrawTarget* fDrawTarget; | |
| 575 SkTLazy<GrDrawState> fTempState; | |
| 576 GrDrawState* fSavedState; | |
| 577 }; | |
| 578 | |
| 579 //////////////////////////////////////////////////////////////////////////// | 440 //////////////////////////////////////////////////////////////////////////// |
| 580 | 441 |
| 581 class AutoReleaseGeometry : public ::SkNoncopyable { | 442 class AutoReleaseGeometry : public ::SkNoncopyable { |
| 582 public: | 443 public: |
| 583 AutoReleaseGeometry(GrDrawTarget* target, | 444 AutoReleaseGeometry(GrDrawTarget* target, |
| 584 int vertexCount, | 445 int vertexCount, |
| 446 size_t vertexStride, |
| 585 int indexCount); | 447 int indexCount); |
| 586 AutoReleaseGeometry(); | 448 AutoReleaseGeometry(); |
| 587 ~AutoReleaseGeometry(); | 449 ~AutoReleaseGeometry(); |
| 588 bool set(GrDrawTarget* target, | 450 bool set(GrDrawTarget* target, |
| 589 int vertexCount, | 451 int vertexCount, |
| 452 size_t vertexStride, |
| 590 int indexCount); | 453 int indexCount); |
| 591 bool succeeded() const { return SkToBool(fTarget); } | 454 bool succeeded() const { return SkToBool(fTarget); } |
| 592 void* vertices() const { SkASSERT(this->succeeded()); return fVertices;
} | 455 void* vertices() const { SkASSERT(this->succeeded()); return fVertices;
} |
| 593 void* indices() const { SkASSERT(this->succeeded()); return fIndices; } | 456 void* indices() const { SkASSERT(this->succeeded()); return fIndices; } |
| 594 SkPoint* positions() const { | 457 SkPoint* positions() const { |
| 595 return static_cast<SkPoint*>(this->vertices()); | 458 return static_cast<SkPoint*>(this->vertices()); |
| 596 } | 459 } |
| 597 | 460 |
| 598 private: | 461 private: |
| 599 void reset(); | 462 void reset(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 625 }; | 488 }; |
| 626 | 489 |
| 627 //////////////////////////////////////////////////////////////////////////// | 490 //////////////////////////////////////////////////////////////////////////// |
| 628 | 491 |
| 629 /** | 492 /** |
| 630 * Saves the geometry src state at construction and restores in the destruct
or. It also saves | 493 * Saves the geometry src state at construction and restores in the destruct
or. It also saves |
| 631 * and then restores the vertex attrib state. | 494 * and then restores the vertex attrib state. |
| 632 */ | 495 */ |
| 633 class AutoGeometryPush : public ::SkNoncopyable { | 496 class AutoGeometryPush : public ::SkNoncopyable { |
| 634 public: | 497 public: |
| 635 AutoGeometryPush(GrDrawTarget* target) | 498 AutoGeometryPush(GrDrawTarget* target) { |
| 636 : fAttribRestore(target->drawState()) { | |
| 637 SkASSERT(target); | 499 SkASSERT(target); |
| 638 fTarget = target; | 500 fTarget = target; |
| 639 target->pushGeometrySource(); | 501 target->pushGeometrySource(); |
| 640 } | 502 } |
| 641 | 503 |
| 642 ~AutoGeometryPush() { fTarget->popGeometrySource(); } | 504 ~AutoGeometryPush() { fTarget->popGeometrySource(); } |
| 643 | 505 |
| 644 private: | 506 private: |
| 645 GrDrawTarget* fTarget; | 507 GrDrawTarget* fTarget; |
| 646 GrDrawState::AutoVertexAttribRestore fAttribRestore; | |
| 647 }; | |
| 648 | |
| 649 /** | |
| 650 * Combination of AutoGeometryPush and AutoStateRestore. The vertex attribs
will be in default | |
| 651 * state regardless of ASRInit value. | |
| 652 */ | |
| 653 class AutoGeometryAndStatePush : public ::SkNoncopyable { | |
| 654 public: | |
| 655 AutoGeometryAndStatePush(GrDrawTarget* target, | |
| 656 ASRInit init, | |
| 657 const SkMatrix* viewMatrix = NULL) | |
| 658 : fState(target, init, viewMatrix) { | |
| 659 SkASSERT(target); | |
| 660 fTarget = target; | |
| 661 target->pushGeometrySource(); | |
| 662 if (kPreserve_ASRInit == init) { | |
| 663 target->drawState()->setDefaultVertexAttribs(); | |
| 664 } | |
| 665 } | |
| 666 | |
| 667 ~AutoGeometryAndStatePush() { fTarget->popGeometrySource(); } | |
| 668 | |
| 669 private: | |
| 670 AutoStateRestore fState; | |
| 671 GrDrawTarget* fTarget; | |
| 672 }; | 508 }; |
| 673 | 509 |
| 674 /////////////////////////////////////////////////////////////////////////// | 510 /////////////////////////////////////////////////////////////////////////// |
| 675 // Draw execution tracking (for font atlases and other resources) | 511 // Draw execution tracking (for font atlases and other resources) |
| 676 class DrawToken { | 512 class DrawToken { |
| 677 public: | 513 public: |
| 678 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : | 514 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : |
| 679 fDrawTarget(drawTarget), fDrawID(drawID) {} | 515 fDrawTarget(drawTarget), fDrawID(drawID) {} |
| 680 | 516 |
| 681 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID);
} | 517 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID);
} |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 } | 659 } |
| 824 | 660 |
| 825 // Subclass must initialize this in its constructor. | 661 // Subclass must initialize this in its constructor. |
| 826 SkAutoTUnref<const GrDrawTargetCaps> fCaps; | 662 SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
| 827 | 663 |
| 828 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } | 664 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } |
| 829 | 665 |
| 830 // Makes a copy of the dst if it is necessary for the draw. Returns false if
a copy is required | 666 // Makes a copy of the dst if it is necessary for the draw. Returns false if
a copy is required |
| 831 // but couldn't be made. Otherwise, returns true. This method needs to be p
rotected because it | 667 // but couldn't be made. Otherwise, returns true. This method needs to be p
rotected because it |
| 832 // needs to be accessed by GLPrograms to setup a correct drawstate | 668 // needs to be accessed by GLPrograms to setup a correct drawstate |
| 833 bool setupDstReadIfNecessary(DrawInfo* info) { | 669 bool setupDstReadIfNecessary(GrDrawState* ds, DrawInfo* info) { |
| 834 return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds
()); | 670 return this->setupDstReadIfNecessary(ds, &info->fDstCopy, info->getDevBo
unds()); |
| 835 } | 671 } |
| 836 bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* dr
awBounds); | 672 bool setupDstReadIfNecessary(GrDrawState*, |
| 673 GrDeviceCoordTexture* dstCopy, |
| 674 const SkRect* drawBounds); |
| 837 | 675 |
| 838 private: | 676 private: |
| 839 // A subclass can optionally overload this function to be notified before | 677 // A subclass can optionally overload this function to be notified before |
| 840 // vertex and index space is reserved. | 678 // vertex and index space is reserved. |
| 841 virtual void willReserveVertexAndIndexSpace(int vertexCount, int indexCount)
{} | 679 virtual void willReserveVertexAndIndexSpace(int vertexCount, |
| 680 size_t vertexStride, |
| 681 int indexCount) {} |
| 842 | 682 |
| 843 // implemented by subclass to allocate space for reserved geom | 683 // implemented by subclass to allocate space for reserved geom |
| 844 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void**
vertices) = 0; | 684 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void**
vertices) = 0; |
| 845 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; | 685 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; |
| 846 // implemented by subclass to handle release of reserved geom space | 686 // implemented by subclass to handle release of reserved geom space |
| 847 virtual void releaseReservedVertexSpace() = 0; | 687 virtual void releaseReservedVertexSpace() = 0; |
| 848 virtual void releaseReservedIndexSpace() = 0; | 688 virtual void releaseReservedIndexSpace() = 0; |
| 849 // subclass overrides to be notified just before geo src state is pushed/pop
ped. | 689 // subclass overrides to be notified just before geo src state is pushed/pop
ped. |
| 850 virtual void geometrySourceWillPush() = 0; | 690 virtual void geometrySourceWillPush() = 0; |
| 851 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) =
0; | 691 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) =
0; |
| 852 // subclass called to perform drawing | 692 // subclass called to perform drawing |
| 853 virtual void onDraw(const DrawInfo&, const GrClipMaskManager::ScissorState&)
= 0; | 693 virtual void onDraw(const GrDrawState&, |
| 694 const DrawInfo&, |
| 695 const GrClipMaskManager::ScissorState&) = 0; |
| 854 // TODO copy in order drawbuffer onDrawRect to here | 696 // TODO copy in order drawbuffer onDrawRect to here |
| 855 virtual void onDrawRect(const SkRect& rect, | 697 virtual void onDrawRect(GrDrawState*, |
| 698 const SkRect& rect, |
| 856 const SkRect* localRect, | 699 const SkRect* localRect, |
| 857 const SkMatrix* localMatrix) = 0; | 700 const SkMatrix* localMatrix) = 0; |
| 858 | 701 |
| 859 virtual void onStencilPath(const GrPath*, | 702 virtual void onStencilPath(const GrDrawState&, |
| 703 const GrPath*, |
| 860 const GrClipMaskManager::ScissorState&, | 704 const GrClipMaskManager::ScissorState&, |
| 861 const GrStencilSettings&) = 0; | 705 const GrStencilSettings&) = 0; |
| 862 virtual void onDrawPath(const GrPath*, | 706 virtual void onDrawPath(const GrDrawState&, |
| 707 const GrPath*, |
| 863 const GrClipMaskManager::ScissorState&, | 708 const GrClipMaskManager::ScissorState&, |
| 864 const GrStencilSettings&, | 709 const GrStencilSettings&, |
| 865 const GrDeviceCoordTexture* dstCopy) = 0; | 710 const GrDeviceCoordTexture* dstCopy) = 0; |
| 866 virtual void onDrawPaths(const GrPathRange*, | 711 virtual void onDrawPaths(const GrDrawState&, |
| 712 const GrPathRange*, |
| 867 const uint32_t indices[], | 713 const uint32_t indices[], |
| 868 int count, | 714 int count, |
| 869 const float transforms[], | 715 const float transforms[], |
| 870 PathTransformType, | 716 PathTransformType, |
| 871 const GrClipMaskManager::ScissorState&, | 717 const GrClipMaskManager::ScissorState&, |
| 872 const GrStencilSettings&, | 718 const GrStencilSettings&, |
| 873 const GrDeviceCoordTexture*) = 0; | 719 const GrDeviceCoordTexture*) = 0; |
| 874 | 720 |
| 875 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, | 721 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, |
| 876 GrRenderTarget* renderTarget) = 0; | 722 GrRenderTarget* renderTarget) = 0; |
| 877 | 723 |
| 878 | 724 |
| 879 // helpers for reserving vertex and index space. | 725 // helpers for reserving vertex and index space. |
| 880 bool reserveVertexSpace(size_t vertexSize, | 726 bool reserveVertexSpace(size_t vertexSize, |
| 881 int vertexCount, | 727 int vertexCount, |
| 882 void** vertices); | 728 void** vertices); |
| 883 bool reserveIndexSpace(int indexCount, void** indices); | 729 bool reserveIndexSpace(int indexCount, void** indices); |
| 884 | 730 |
| 885 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to | 731 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to |
| 886 // indicate non-indexed drawing. | 732 // indicate non-indexed drawing. |
| 887 bool checkDraw(GrPrimitiveType type, int startVertex, | 733 bool checkDraw(const GrDrawState&, |
| 888 int startIndex, int vertexCount, | 734 GrPrimitiveType type, |
| 735 int startVertex, |
| 736 int startIndex, |
| 737 int vertexCount, |
| 889 int indexCount) const; | 738 int indexCount) const; |
| 890 // called when setting a new vert/idx source to unref prev vb/ib | 739 // called when setting a new vert/idx source to unref prev vb/ib |
| 891 void releasePreviousVertexSource(); | 740 void releasePreviousVertexSource(); |
| 892 void releasePreviousIndexSource(); | 741 void releasePreviousIndexSource(); |
| 893 | 742 |
| 894 // Check to see if this set of draw commands has been sent out | 743 // Check to see if this set of draw commands has been sent out |
| 895 virtual bool isIssued(uint32_t drawID) { return true; } | 744 virtual bool isIssued(uint32_t drawID) { return true; } |
| 896 void getPathStencilSettingsForFilltype(GrPathRendering::FillType, GrStencilS
ettings*); | 745 void getPathStencilSettingsForFilltype(GrPathRendering::FillType, |
| 746 const GrStencilBuffer*, |
| 747 GrStencilSettings*); |
| 897 virtual GrClipMaskManager* clipMaskManager() = 0; | 748 virtual GrClipMaskManager* clipMaskManager() = 0; |
| 898 virtual bool setupClip(const SkRect* devBounds, | 749 virtual bool setupClip(const SkRect* devBounds, |
| 899 GrDrawState::AutoRestoreEffects* are, | 750 GrDrawState::AutoRestoreEffects* are, |
| 900 GrDrawState::AutoRestoreStencil* ars, | 751 GrDrawState::AutoRestoreStencil* ars, |
| 752 GrDrawState*, |
| 901 GrClipMaskManager::ScissorState* scissorState) = 0; | 753 GrClipMaskManager::ScissorState* scissorState) = 0; |
| 902 | 754 |
| 903 enum { | 755 enum { |
| 904 kPreallocGeoSrcStateStackCnt = 4, | 756 kPreallocGeoSrcStateStackCnt = 4, |
| 905 }; | 757 }; |
| 906 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcState
Stack; | 758 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcState
Stack; |
| 907 const GrClipData* fClip; | 759 const GrClipData* fClip; |
| 908 GrDrawState* fDrawState; | |
| 909 GrDrawState fDefaultDraw
State; | |
| 910 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar
get. | 760 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar
get. |
| 911 GrContext* fContext; | 761 GrContext* fContext; |
| 912 // To keep track that we always have at least as many debug marker adds as r
emoves | 762 // To keep track that we always have at least as many debug marker adds as r
emoves |
| 913 int fGpuTraceMar
kerCount; | 763 int fGpuTraceMar
kerCount; |
| 914 GrTraceMarkerSet fActiveTrace
Markers; | 764 GrTraceMarkerSet fActiveTrace
Markers; |
| 915 GrTraceMarkerSet fStoredTrace
Markers; | 765 GrTraceMarkerSet fStoredTrace
Markers; |
| 916 | 766 |
| 917 typedef SkRefCnt INHERITED; | 767 typedef SkRefCnt INHERITED; |
| 918 }; | 768 }; |
| 919 | 769 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 | 802 |
| 953 protected: | 803 protected: |
| 954 GrClipMaskManager fClipMaskManager; | 804 GrClipMaskManager fClipMaskManager; |
| 955 | 805 |
| 956 private: | 806 private: |
| 957 GrClipMaskManager* clipMaskManager() { return &fClipMaskManager; } | 807 GrClipMaskManager* clipMaskManager() { return &fClipMaskManager; } |
| 958 | 808 |
| 959 virtual bool setupClip(const SkRect* devBounds, | 809 virtual bool setupClip(const SkRect* devBounds, |
| 960 GrDrawState::AutoRestoreEffects* are, | 810 GrDrawState::AutoRestoreEffects* are, |
| 961 GrDrawState::AutoRestoreStencil* ars, | 811 GrDrawState::AutoRestoreStencil* ars, |
| 812 GrDrawState*, |
| 962 GrClipMaskManager::ScissorState* scissorState) SK_OVE
RRIDE; | 813 GrClipMaskManager::ScissorState* scissorState) SK_OVE
RRIDE; |
| 963 | 814 |
| 964 typedef GrDrawTarget INHERITED; | 815 typedef GrDrawTarget INHERITED; |
| 965 }; | 816 }; |
| 966 | 817 |
| 967 #endif | 818 #endif |
| OLD | NEW |