Chromium Code Reviews| 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, |
|
bsalomon
2014/11/14 21:51:02
one line?
| |
| 171 int* vertexCount, | |
| 198 int* indexCount) const; | 172 int* indexCount) const; |
| 199 | 173 |
| 200 /** | 174 /** |
| 201 * Sets source of vertex data for the next draw. Data does not have to be | 175 * Sets source of vertex data for the next draw. Data does not have to be |
| 202 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. | 176 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. |
| 203 * | 177 * |
| 204 * @param buffer vertex buffer containing vertex data. Must be | 178 * @param buffer vertex buffer containing vertex data. Must be |
| 205 * unlocked before draw call. Vertex size is queried | 179 * unlocked before draw call. Vertex size is queried |
| 206 * from current GrDrawState. | 180 * from current GrDrawState. |
| 207 */ | 181 */ |
| 208 void setVertexSourceToBuffer(const GrVertexBuffer* buffer); | 182 void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStri de); |
| 209 | 183 |
| 210 /** | 184 /** |
| 211 * Sets source of index data for the next indexed draw. Data does not have | 185 * Sets source of index data for the next indexed draw. Data does not have |
| 212 * to be in the buffer until drawIndexed. | 186 * to be in the buffer until drawIndexed. |
| 213 * | 187 * |
| 214 * @param buffer index buffer containing indices. Must be unlocked | 188 * @param buffer index buffer containing indices. Must be unlocked |
| 215 * before indexed draw call. | 189 * before indexed draw call. |
| 216 */ | 190 */ |
| 217 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); | 191 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
| 218 | 192 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 * @param startVertex the vertex in the vertex array/buffer corresponding | 234 * @param startVertex the vertex in the vertex array/buffer corresponding |
| 261 * to index 0 | 235 * to index 0 |
| 262 * @param startIndex first index to read from index src. | 236 * @param startIndex first index to read from index src. |
| 263 * @param vertexCount one greater than the max index. | 237 * @param vertexCount one greater than the max index. |
| 264 * @param indexCount the number of index elements to read. The index count | 238 * @param indexCount the number of index elements to read. The index count |
| 265 * is effectively trimmed to the last completely | 239 * is effectively trimmed to the last completely |
| 266 * specified primitive. | 240 * specified primitive. |
| 267 * @param devBounds optional bounds hint. This is a promise from the call er, | 241 * @param devBounds optional bounds hint. This is a promise from the call er, |
| 268 * not a request for clipping. | 242 * not a request for clipping. |
| 269 */ | 243 */ |
| 270 void drawIndexed(GrPrimitiveType type, | 244 void drawIndexed(GrDrawState*, |
| 245 GrPrimitiveType type, | |
| 271 int startVertex, | 246 int startVertex, |
| 272 int startIndex, | 247 int startIndex, |
| 273 int vertexCount, | 248 int vertexCount, |
| 274 int indexCount, | 249 int indexCount, |
| 275 const SkRect* devBounds = NULL); | 250 const SkRect* devBounds = NULL); |
| 276 | 251 |
| 277 /** | 252 /** |
| 278 * Draws non-indexed geometry using the current state and current vertex | 253 * Draws non-indexed geometry using the current state and current vertex |
| 279 * sources. | 254 * sources. |
| 280 * | 255 * |
| 281 * @param type The type of primitives to draw. | 256 * @param type The type of primitives to draw. |
| 282 * @param startVertex the vertex in the vertex array/buffer corresponding | 257 * @param startVertex the vertex in the vertex array/buffer corresponding |
| 283 * to index 0 | 258 * to index 0 |
| 284 * @param vertexCount one greater than the max index. | 259 * @param vertexCount one greater than the max index. |
| 285 * @param devBounds optional bounds hint. This is a promise from the call er, | 260 * @param devBounds optional bounds hint. This is a promise from the call er, |
| 286 * not a request for clipping. | 261 * not a request for clipping. |
| 287 */ | 262 */ |
| 288 void drawNonIndexed(GrPrimitiveType type, | 263 void drawNonIndexed(GrDrawState*, |
| 264 GrPrimitiveType type, | |
| 289 int startVertex, | 265 int startVertex, |
| 290 int vertexCount, | 266 int vertexCount, |
| 291 const SkRect* devBounds = NULL); | 267 const SkRect* devBounds = NULL); |
| 292 | 268 |
| 293 /** | 269 /** |
| 294 * Draws path into the stencil buffer. The fill must be either even/odd or | 270 * 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 | 271 * 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 | 272 * on the draw state (if possible in the 3D API). Note, we will never have an inverse fill |
| 297 * with stencil path | 273 * with stencil path |
| 298 */ | 274 */ |
| 299 void stencilPath(const GrPath*, GrPathRendering::FillType fill); | 275 void stencilPath(GrDrawState*, const GrPath*, GrPathRendering::FillType fill ); |
| 300 | 276 |
| 301 /** | 277 /** |
| 302 * Draws a path. Fill must not be a hairline. It will respect the HW | 278 * 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). | 279 * antialias flag on the draw state (if possible in the 3D API). |
| 304 */ | 280 */ |
| 305 void drawPath(const GrPath*, GrPathRendering::FillType fill); | 281 void drawPath(GrDrawState*, const GrPath*, GrPathRendering::FillType fill); |
| 306 | 282 |
| 307 /** | 283 /** |
| 308 * Draws many paths. It will respect the HW | 284 * Draws many paths. It will respect the HW |
| 309 * antialias flag on the draw state (if possible in the 3D API). | 285 * antialias flag on the draw state (if possible in the 3D API). |
| 310 * | 286 * |
| 311 * @param pathRange Source of paths to draw from | 287 * @param pathRange Source of paths to draw from |
| 312 * @param indices Array of indices into the the pathRange | 288 * @param indices Array of indices into the the pathRange |
| 313 * @param count Number of paths to draw (length of indices array) | 289 * @param count Number of paths to draw (length of indices array) |
| 314 * @param transforms Array of individual transforms, one for each path | 290 * @param transforms Array of individual transforms, one for each path |
| 315 * @param transformsType Type of transformations in the array. Array contai ns | 291 * @param transformsType Type of transformations in the array. Array contai ns |
| 316 PathTransformSize(transformsType) * count elements | 292 PathTransformSize(transformsType) * count elements |
| 317 * @param fill Fill type for drawing all the paths | 293 * @param fill Fill type for drawing all the paths |
| 318 */ | 294 */ |
| 319 void drawPaths(const GrPathRange* pathRange, | 295 void drawPaths(GrDrawState*, const GrPathRange* pathRange, |
| 320 const uint32_t indices[], int count, | 296 const uint32_t indices[], |
| 321 const float transforms[], PathTransformType transformsType, | 297 int count, |
| 298 const float transforms[], | |
| 299 PathTransformType transformsType, | |
| 322 GrPathRendering::FillType fill); | 300 GrPathRendering::FillType fill); |
| 323 | 301 |
| 324 /** | 302 /** |
| 325 * Helper function for drawing rects. It performs a geometry src push and po p | 303 * Helper function for drawing rects. It performs a geometry src push and po p |
| 326 * and thus will finalize any reserved geometry. | 304 * and thus will finalize any reserved geometry. |
| 327 * | 305 * |
| 328 * @param rect the rect to draw | 306 * @param rect the rect to draw |
| 329 * @param localRect optional rect that specifies local coords to map onto | 307 * @param localRect optional rect that specifies local coords to map onto |
| 330 * rect. If NULL then rect serves as the local coords. | 308 * rect. If NULL then rect serves as the local coords. |
| 331 * @param localMatrix optional matrix applied to localRect. If | 309 * @param localMatrix optional matrix applied to localRect. If |
| 332 * srcRect is non-NULL and srcMatrix is non-NULL | 310 * srcRect is non-NULL and srcMatrix is non-NULL |
| 333 * then srcRect will be transformed by srcMatrix. | 311 * then srcRect will be transformed by srcMatrix. |
| 334 * srcMatrix can be NULL when no srcMatrix is desired. | 312 * srcMatrix can be NULL when no srcMatrix is desired. |
| 335 */ | 313 */ |
| 336 void drawRect(const SkRect& rect, | 314 void drawRect(GrDrawState* ds, |
| 315 const SkRect& rect, | |
| 337 const SkRect* localRect, | 316 const SkRect* localRect, |
| 338 const SkMatrix* localMatrix) { | 317 const SkMatrix* localMatrix) { |
| 339 AutoGeometryPush agp(this); | 318 AutoGeometryPush agp(this); |
| 340 this->onDrawRect(rect, localRect, localMatrix); | 319 this->onDrawRect(ds, rect, localRect, localMatrix); |
| 341 } | 320 } |
| 342 | 321 |
| 343 /** | 322 /** |
| 344 * Helper for drawRect when the caller doesn't need separate local rects or matrices. | 323 * Helper for drawRect when the caller doesn't need separate local rects or matrices. |
| 345 */ | 324 */ |
| 346 void drawSimpleRect(const SkRect& rect) { | 325 void drawSimpleRect(GrDrawState* ds, const SkRect& rect) { |
| 347 this->drawRect(rect, NULL, NULL); | 326 this->drawRect(ds, rect, NULL, NULL); |
| 348 } | 327 } |
| 349 void drawSimpleRect(const SkIRect& irect) { | 328 void drawSimpleRect(GrDrawState* ds, const SkIRect& irect) { |
| 350 SkRect rect = SkRect::Make(irect); | 329 SkRect rect = SkRect::Make(irect); |
| 351 this->drawRect(rect, NULL, NULL); | 330 this->drawRect(ds, rect, NULL, NULL); |
| 352 } | 331 } |
| 353 | 332 |
| 354 /** | 333 /** |
| 355 * This call is used to draw multiple instances of some geometry with a | 334 * 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 | 335 * 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 | 336 * 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 | 337 * 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 | 338 * 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 | 339 * quads each as two triangles each satisfies these conditions with V=4 and |
| 361 * I=6: | 340 * I=6: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 374 * consists of verticesPerInstance vertices indexed by | 353 * consists of verticesPerInstance vertices indexed by |
| 375 * indicesPerInstance indices drawn as the primitive | 354 * indicesPerInstance indices drawn as the primitive |
| 376 * type specified by type. | 355 * type specified by type. |
| 377 * @param verticesPerInstance The number of vertices in each instance (V | 356 * @param verticesPerInstance The number of vertices in each instance (V |
| 378 * in the above description). | 357 * in the above description). |
| 379 * @param indicesPerInstance The number of indices in each instance (I | 358 * @param indicesPerInstance The number of indices in each instance (I |
| 380 * in the above description). | 359 * in the above description). |
| 381 * @param devBounds optional bounds hint. This is a promise from the call er, | 360 * @param devBounds optional bounds hint. This is a promise from the call er, |
| 382 * not a request for clipping. | 361 * not a request for clipping. |
| 383 */ | 362 */ |
| 384 void drawIndexedInstances(GrPrimitiveType type, | 363 void drawIndexedInstances(GrDrawState*, |
| 364 GrPrimitiveType type, | |
| 385 int instanceCount, | 365 int instanceCount, |
| 386 int verticesPerInstance, | 366 int verticesPerInstance, |
| 387 int indicesPerInstance, | 367 int indicesPerInstance, |
| 388 const SkRect* devBounds = NULL); | 368 const SkRect* devBounds = NULL); |
| 389 | 369 |
| 390 /** | 370 /** |
| 391 * Clear the passed in render target. Ignores the draw state and clip. Clear s the whole thing if | 371 * 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 | 372 * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the e ntire render target |
| 393 * can be optionally cleared. | 373 * can be optionally cleared. |
| 394 */ | 374 */ |
| 395 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, | 375 void clear(const SkIRect* rect, |
| 376 GrColor color, | |
| 377 bool canIgnoreRect, | |
| 396 GrRenderTarget* renderTarget); | 378 GrRenderTarget* renderTarget); |
| 397 | 379 |
| 398 /** | 380 /** |
| 399 * Discards the contents render target. | 381 * Discards the contents render target. |
| 400 **/ | 382 **/ |
| 401 virtual void discard(GrRenderTarget*) = 0; | 383 virtual void discard(GrRenderTarget*) = 0; |
| 402 | 384 |
| 403 /** | 385 /** |
| 404 * Called at start and end of gpu trace marking | 386 * 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 | 387 * 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. | 413 * true is returned since there is no actual copy necessary to succeed. |
| 432 */ | 414 */ |
| 433 virtual bool copySurface(GrSurface* dst, | 415 virtual bool copySurface(GrSurface* dst, |
| 434 GrSurface* src, | 416 GrSurface* src, |
| 435 const SkIRect& srcRect, | 417 const SkIRect& srcRect, |
| 436 const SkIPoint& dstPoint); | 418 const SkIPoint& dstPoint); |
| 437 /** | 419 /** |
| 438 * Function that determines whether a copySurface call would succeed without | 420 * Function that determines whether a copySurface call would succeed without |
| 439 * performing the copy. | 421 * performing the copy. |
| 440 */ | 422 */ |
| 441 virtual bool canCopySurface(GrSurface* dst, | 423 virtual bool canCopySurface(const GrSurface* dst, |
| 442 GrSurface* src, | 424 const GrSurface* src, |
| 443 const SkIRect& srcRect, | 425 const SkIRect& srcRect, |
| 444 const SkIPoint& dstPoint); | 426 const SkIPoint& dstPoint); |
| 445 | 427 |
| 446 /** | 428 /** |
| 447 * This is can be called before allocating a texture to be a dst for copySur face. It will | 429 * 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 | 430 * populate the origin, config, and flags fields of the desc such that copyS urface is more |
| 449 * likely to succeed and be efficient. | 431 * likely to succeed and be efficient. |
| 450 */ | 432 */ |
| 451 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des c); | 433 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des c); |
| 452 | 434 |
| 453 | 435 |
| 454 /** | 436 /** |
| 455 * Release any resources that are cached but not currently in use. This | 437 * 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. | 438 * is intended to give an application some recourse when resources are low. |
| 457 */ | 439 */ |
| 458 virtual void purgeResources() {}; | 440 virtual void purgeResources() {}; |
| 459 | 441 |
| 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 //////////////////////////////////////////////////////////////////////////// | 442 //////////////////////////////////////////////////////////////////////////// |
| 580 | 443 |
| 581 class AutoReleaseGeometry : public ::SkNoncopyable { | 444 class AutoReleaseGeometry : public ::SkNoncopyable { |
| 582 public: | 445 public: |
| 583 AutoReleaseGeometry(GrDrawTarget* target, | 446 AutoReleaseGeometry(GrDrawTarget* target, |
| 584 int vertexCount, | 447 int vertexCount, |
| 448 size_t vertexStride, | |
| 585 int indexCount); | 449 int indexCount); |
| 586 AutoReleaseGeometry(); | 450 AutoReleaseGeometry(); |
| 587 ~AutoReleaseGeometry(); | 451 ~AutoReleaseGeometry(); |
| 588 bool set(GrDrawTarget* target, | 452 bool set(GrDrawTarget* target, |
| 589 int vertexCount, | 453 int vertexCount, |
| 454 size_t vertexStride, | |
| 590 int indexCount); | 455 int indexCount); |
| 591 bool succeeded() const { return SkToBool(fTarget); } | 456 bool succeeded() const { return SkToBool(fTarget); } |
| 592 void* vertices() const { SkASSERT(this->succeeded()); return fVertices; } | 457 void* vertices() const { SkASSERT(this->succeeded()); return fVertices; } |
| 593 void* indices() const { SkASSERT(this->succeeded()); return fIndices; } | 458 void* indices() const { SkASSERT(this->succeeded()); return fIndices; } |
| 594 SkPoint* positions() const { | 459 SkPoint* positions() const { |
| 595 return static_cast<SkPoint*>(this->vertices()); | 460 return static_cast<SkPoint*>(this->vertices()); |
| 596 } | 461 } |
| 597 | 462 |
| 598 private: | 463 private: |
| 599 void reset(); | 464 void reset(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 625 }; | 490 }; |
| 626 | 491 |
| 627 //////////////////////////////////////////////////////////////////////////// | 492 //////////////////////////////////////////////////////////////////////////// |
| 628 | 493 |
| 629 /** | 494 /** |
| 630 * Saves the geometry src state at construction and restores in the destruct or. It also saves | 495 * Saves the geometry src state at construction and restores in the destruct or. It also saves |
| 631 * and then restores the vertex attrib state. | 496 * and then restores the vertex attrib state. |
| 632 */ | 497 */ |
| 633 class AutoGeometryPush : public ::SkNoncopyable { | 498 class AutoGeometryPush : public ::SkNoncopyable { |
| 634 public: | 499 public: |
| 635 AutoGeometryPush(GrDrawTarget* target) | 500 AutoGeometryPush(GrDrawTarget* target) { |
| 636 : fAttribRestore(target->drawState()) { | |
| 637 SkASSERT(target); | 501 SkASSERT(target); |
| 638 fTarget = target; | 502 fTarget = target; |
| 639 target->pushGeometrySource(); | 503 target->pushGeometrySource(); |
| 640 } | 504 } |
| 641 | 505 |
| 642 ~AutoGeometryPush() { fTarget->popGeometrySource(); } | 506 ~AutoGeometryPush() { fTarget->popGeometrySource(); } |
| 643 | 507 |
| 644 private: | 508 private: |
| 645 GrDrawTarget* fTarget; | 509 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 }; | 510 }; |
| 673 | 511 |
| 674 /////////////////////////////////////////////////////////////////////////// | 512 /////////////////////////////////////////////////////////////////////////// |
| 675 // Draw execution tracking (for font atlases and other resources) | 513 // Draw execution tracking (for font atlases and other resources) |
| 676 class DrawToken { | 514 class DrawToken { |
| 677 public: | 515 public: |
| 678 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : | 516 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : |
| 679 fDrawTarget(drawTarget), fDrawID(drawID) {} | 517 fDrawTarget(drawTarget), fDrawID(drawID) {} |
| 680 | 518 |
| 681 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); } | 519 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 823 } | 661 } |
| 824 | 662 |
| 825 // Subclass must initialize this in its constructor. | 663 // Subclass must initialize this in its constructor. |
| 826 SkAutoTUnref<const GrDrawTargetCaps> fCaps; | 664 SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
| 827 | 665 |
| 828 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; } | 666 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; } |
| 829 | 667 |
| 830 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required | 668 // 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 | 669 // 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 | 670 // needs to be accessed by GLPrograms to setup a correct drawstate |
| 833 bool setupDstReadIfNecessary(DrawInfo* info) { | 671 bool setupDstReadIfNecessary(GrDrawState* ds, DrawInfo* info) { |
| 834 return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds ()); | 672 return this->setupDstReadIfNecessary(ds, &info->fDstCopy, info->getDevBo unds()); |
| 835 } | 673 } |
| 836 bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* dr awBounds); | 674 bool setupDstReadIfNecessary(GrDrawState*, |
| 675 GrDeviceCoordTexture* dstCopy, | |
| 676 const SkRect* drawBounds); | |
| 837 | 677 |
| 838 private: | 678 private: |
| 839 // A subclass can optionally overload this function to be notified before | 679 // A subclass can optionally overload this function to be notified before |
| 840 // vertex and index space is reserved. | 680 // vertex and index space is reserved. |
| 841 virtual void willReserveVertexAndIndexSpace(int vertexCount, int indexCount) {} | 681 virtual void willReserveVertexAndIndexSpace(int vertexCount, |
| 682 size_t vertexStride, | |
| 683 int indexCount) {} | |
| 842 | 684 |
| 843 // implemented by subclass to allocate space for reserved geom | 685 // implemented by subclass to allocate space for reserved geom |
| 844 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0; | 686 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0; |
| 845 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; | 687 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; |
| 846 // implemented by subclass to handle release of reserved geom space | 688 // implemented by subclass to handle release of reserved geom space |
| 847 virtual void releaseReservedVertexSpace() = 0; | 689 virtual void releaseReservedVertexSpace() = 0; |
| 848 virtual void releaseReservedIndexSpace() = 0; | 690 virtual void releaseReservedIndexSpace() = 0; |
| 849 // subclass overrides to be notified just before geo src state is pushed/pop ped. | 691 // subclass overrides to be notified just before geo src state is pushed/pop ped. |
| 850 virtual void geometrySourceWillPush() = 0; | 692 virtual void geometrySourceWillPush() = 0; |
| 851 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; | 693 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; |
| 852 // subclass called to perform drawing | 694 // subclass called to perform drawing |
| 853 virtual void onDraw(const DrawInfo&, const GrClipMaskManager::ScissorState&) = 0; | 695 virtual void onDraw(const GrDrawState&, |
| 696 const DrawInfo&, | |
| 697 const GrClipMaskManager::ScissorState&) = 0; | |
| 854 // TODO copy in order drawbuffer onDrawRect to here | 698 // TODO copy in order drawbuffer onDrawRect to here |
| 855 virtual void onDrawRect(const SkRect& rect, | 699 virtual void onDrawRect(GrDrawState*, |
| 700 const SkRect& rect, | |
| 856 const SkRect* localRect, | 701 const SkRect* localRect, |
| 857 const SkMatrix* localMatrix) = 0; | 702 const SkMatrix* localMatrix) = 0; |
| 858 | 703 |
| 859 virtual void onStencilPath(const GrPath*, | 704 virtual void onStencilPath(const GrDrawState&, |
| 705 const GrPath*, | |
| 860 const GrClipMaskManager::ScissorState&, | 706 const GrClipMaskManager::ScissorState&, |
| 861 const GrStencilSettings&) = 0; | 707 const GrStencilSettings&) = 0; |
| 862 virtual void onDrawPath(const GrPath*, | 708 virtual void onDrawPath(const GrDrawState&, |
| 709 const GrPath*, | |
| 863 const GrClipMaskManager::ScissorState&, | 710 const GrClipMaskManager::ScissorState&, |
| 864 const GrStencilSettings&, | 711 const GrStencilSettings&, |
| 865 const GrDeviceCoordTexture* dstCopy) = 0; | 712 const GrDeviceCoordTexture* dstCopy) = 0; |
| 866 virtual void onDrawPaths(const GrPathRange*, | 713 virtual void onDrawPaths(const GrDrawState&, |
| 714 const GrPathRange*, | |
| 867 const uint32_t indices[], | 715 const uint32_t indices[], |
| 868 int count, | 716 int count, |
| 869 const float transforms[], | 717 const float transforms[], |
| 870 PathTransformType, | 718 PathTransformType, |
| 871 const GrClipMaskManager::ScissorState&, | 719 const GrClipMaskManager::ScissorState&, |
| 872 const GrStencilSettings&, | 720 const GrStencilSettings&, |
| 873 const GrDeviceCoordTexture*) = 0; | 721 const GrDeviceCoordTexture*) = 0; |
| 874 | 722 |
| 875 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, | 723 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, |
| 876 GrRenderTarget* renderTarget) = 0; | 724 GrRenderTarget* renderTarget) = 0; |
| 877 | 725 |
| 878 | 726 |
| 879 // helpers for reserving vertex and index space. | 727 // helpers for reserving vertex and index space. |
| 880 bool reserveVertexSpace(size_t vertexSize, | 728 bool reserveVertexSpace(size_t vertexSize, |
| 881 int vertexCount, | 729 int vertexCount, |
| 882 void** vertices); | 730 void** vertices); |
| 883 bool reserveIndexSpace(int indexCount, void** indices); | 731 bool reserveIndexSpace(int indexCount, void** indices); |
| 884 | 732 |
| 885 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to | 733 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to |
| 886 // indicate non-indexed drawing. | 734 // indicate non-indexed drawing. |
| 887 bool checkDraw(GrPrimitiveType type, int startVertex, | 735 bool checkDraw(const GrDrawState&, |
| 888 int startIndex, int vertexCount, | 736 GrPrimitiveType type, |
| 737 int startVertex, | |
| 738 int startIndex, | |
| 739 int vertexCount, | |
| 889 int indexCount) const; | 740 int indexCount) const; |
| 890 // called when setting a new vert/idx source to unref prev vb/ib | 741 // called when setting a new vert/idx source to unref prev vb/ib |
| 891 void releasePreviousVertexSource(); | 742 void releasePreviousVertexSource(); |
| 892 void releasePreviousIndexSource(); | 743 void releasePreviousIndexSource(); |
| 893 | 744 |
| 894 // Check to see if this set of draw commands has been sent out | 745 // Check to see if this set of draw commands has been sent out |
| 895 virtual bool isIssued(uint32_t drawID) { return true; } | 746 virtual bool isIssued(uint32_t drawID) { return true; } |
| 896 void getPathStencilSettingsForFilltype(GrPathRendering::FillType, GrStencilS ettings*); | 747 void getPathStencilSettingsForFilltype(GrPathRendering::FillType, |
| 748 const GrStencilBuffer*, | |
| 749 GrStencilSettings*); | |
| 897 virtual GrClipMaskManager* clipMaskManager() = 0; | 750 virtual GrClipMaskManager* clipMaskManager() = 0; |
| 898 virtual bool setupClip(const SkRect* devBounds, | 751 virtual bool setupClip(const SkRect* devBounds, |
| 899 GrDrawState::AutoRestoreEffects* are, | 752 GrDrawState::AutoRestoreEffects* are, |
| 900 GrDrawState::AutoRestoreStencil* ars, | 753 GrDrawState::AutoRestoreStencil* ars, |
| 754 GrDrawState*, | |
| 901 GrClipMaskManager::ScissorState* scissorState) = 0; | 755 GrClipMaskManager::ScissorState* scissorState) = 0; |
| 902 | 756 |
| 903 enum { | 757 enum { |
| 904 kPreallocGeoSrcStateStackCnt = 4, | 758 kPreallocGeoSrcStateStackCnt = 4, |
| 905 }; | 759 }; |
| 906 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcState Stack; | 760 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcState Stack; |
| 907 const GrClipData* fClip; | 761 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. | 762 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get. |
| 911 GrContext* fContext; | 763 GrContext* fContext; |
| 912 // To keep track that we always have at least as many debug marker adds as r emoves | 764 // To keep track that we always have at least as many debug marker adds as r emoves |
| 913 int fGpuTraceMar kerCount; | 765 int fGpuTraceMar kerCount; |
| 914 GrTraceMarkerSet fActiveTrace Markers; | 766 GrTraceMarkerSet fActiveTrace Markers; |
| 915 GrTraceMarkerSet fStoredTrace Markers; | 767 GrTraceMarkerSet fStoredTrace Markers; |
| 916 | 768 |
| 917 typedef SkRefCnt INHERITED; | 769 typedef SkRefCnt INHERITED; |
| 918 }; | 770 }; |
| 919 | 771 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 | 804 |
| 953 protected: | 805 protected: |
| 954 GrClipMaskManager fClipMaskManager; | 806 GrClipMaskManager fClipMaskManager; |
| 955 | 807 |
| 956 private: | 808 private: |
| 957 GrClipMaskManager* clipMaskManager() { return &fClipMaskManager; } | 809 GrClipMaskManager* clipMaskManager() { return &fClipMaskManager; } |
| 958 | 810 |
| 959 virtual bool setupClip(const SkRect* devBounds, | 811 virtual bool setupClip(const SkRect* devBounds, |
| 960 GrDrawState::AutoRestoreEffects* are, | 812 GrDrawState::AutoRestoreEffects* are, |
| 961 GrDrawState::AutoRestoreStencil* ars, | 813 GrDrawState::AutoRestoreStencil* ars, |
| 814 GrDrawState*, | |
| 962 GrClipMaskManager::ScissorState* scissorState) SK_OVE RRIDE; | 815 GrClipMaskManager::ScissorState* scissorState) SK_OVE RRIDE; |
| 963 | 816 |
| 964 typedef GrDrawTarget INHERITED; | 817 typedef GrDrawTarget INHERITED; |
| 965 }; | 818 }; |
| 966 | 819 |
| 967 #endif | 820 #endif |
| OLD | NEW |