OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 GrGpu_DEFINED | 8 #ifndef GrGpu_DEFINED |
9 #define GrGpu_DEFINED | 9 #define GrGpu_DEFINED |
10 | 10 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 287 |
288 // This timestamp is always older than the current timestamp | 288 // This timestamp is always older than the current timestamp |
289 static const ResetTimestamp kExpiredTimestamp = 0; | 289 static const ResetTimestamp kExpiredTimestamp = 0; |
290 // Returns a timestamp based on the number of times the context was reset. | 290 // Returns a timestamp based on the number of times the context was reset. |
291 // This timestamp can be used to lazily detect when cached 3D context state | 291 // This timestamp can be used to lazily detect when cached 3D context state |
292 // is dirty. | 292 // is dirty. |
293 ResetTimestamp getResetTimestamp() const { | 293 ResetTimestamp getResetTimestamp() const { |
294 return fResetTimestamp; | 294 return fResetTimestamp; |
295 } | 295 } |
296 | 296 |
297 /** | |
298 * These methods are called by the clip manager's setupClipping function | |
299 * which (called as part of GrGpu's implementation of onDraw and | |
300 * onStencilPath member functions.) The GrGpu subclass should flush the | |
301 * stencil state to the 3D API in its implementation of flushGraphicsState. | |
302 */ | |
303 void enableScissor(const SkIRect& rect) { | |
304 fScissorState.fEnabled = true; | |
305 fScissorState.fRect = rect; | |
306 } | |
307 void disableScissor() { fScissorState.fEnabled = false; } | |
308 | |
309 // GrGpu subclass sets clip bit in the stencil buffer. The subclass is | 297 // GrGpu subclass sets clip bit in the stencil buffer. The subclass is |
310 // free to clear the remaining bits to zero if masked clears are more | 298 // free to clear the remaining bits to zero if masked clears are more |
311 // expensive than clearing all bits. | 299 // expensive than clearing all bits. |
312 virtual void clearStencilClip(GrRenderTarget*, const SkIRect& rect, bool ins
ideClip) = 0; | 300 virtual void clearStencilClip(GrRenderTarget*, const SkIRect& rect, bool ins
ideClip) = 0; |
313 | 301 |
314 enum PrivateDrawStateStateBits { | 302 enum PrivateDrawStateStateBits { |
315 kFirstBit = (GrDrawState::kLastPublicStateBit << 1), | 303 kFirstBit = (GrDrawState::kLastPublicStateBit << 1), |
316 | 304 |
317 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify | 305 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify |
318 // stencil bits used for | 306 // stencil bits used for |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 return kDrawLines_DrawType; | 338 return kDrawLines_DrawType; |
351 default: | 339 default: |
352 SkFAIL("Unexpected primitive type"); | 340 SkFAIL("Unexpected primitive type"); |
353 return kDrawTriangles_DrawType; | 341 return kDrawTriangles_DrawType; |
354 } | 342 } |
355 } | 343 } |
356 | 344 |
357 // prepares clip flushes gpu state before a draw | 345 // prepares clip flushes gpu state before a draw |
358 bool setupClipAndFlushState(DrawType, | 346 bool setupClipAndFlushState(DrawType, |
359 const GrDeviceCoordTexture* dstCopy, | 347 const GrDeviceCoordTexture* dstCopy, |
360 GrDrawState::AutoRestoreEffects*, | 348 const SkRect* devBounds, |
361 const SkRect* devBounds); | 349 GrDrawState::AutoRestoreEffects*); |
362 | 350 |
363 // Functions used to map clip-respecting stencil tests into normal | 351 // Functions used to map clip-respecting stencil tests into normal |
364 // stencil funcs supported by GPUs. | 352 // stencil funcs supported by GPUs. |
365 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, | 353 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, |
366 GrStencilFunc func); | 354 GrStencilFunc func); |
367 static void ConvertStencilFuncAndMask(GrStencilFunc func, | 355 static void ConvertStencilFuncAndMask(GrStencilFunc func, |
368 bool clipInStencil, | 356 bool clipInStencil, |
369 unsigned int clipBit, | 357 unsigned int clipBit, |
370 unsigned int userBits, | 358 unsigned int userBits, |
371 unsigned int* ref, | 359 unsigned int* ref, |
372 unsigned int* mask); | 360 unsigned int* mask); |
373 | 361 |
374 GrClipMaskManager fClipMaskManager; | 362 GrClipMaskManager fClipMaskManager; |
375 | 363 |
376 GrContext::GPUStats fGPUStats; | 364 GrContext::GPUStats fGPUStats; |
377 | 365 |
378 struct GeometryPoolState { | 366 struct GeometryPoolState { |
379 const GrVertexBuffer* fPoolVertexBuffer; | 367 const GrVertexBuffer* fPoolVertexBuffer; |
380 int fPoolStartVertex; | 368 int fPoolStartVertex; |
381 | 369 |
382 const GrIndexBuffer* fPoolIndexBuffer; | 370 const GrIndexBuffer* fPoolIndexBuffer; |
383 int fPoolStartIndex; | 371 int fPoolStartIndex; |
384 }; | 372 }; |
385 const GeometryPoolState& getGeomPoolState() { | 373 const GeometryPoolState& getGeomPoolState() { |
386 return fGeomPoolStateStack.back(); | 374 return fGeomPoolStateStack.back(); |
387 } | 375 } |
388 | 376 |
389 // The state of the scissor is controlled by the clip manager | |
390 struct ScissorState { | |
391 bool fEnabled; | |
392 SkIRect fRect; | |
393 } fScissorState; | |
394 | |
395 // Helpers for setting up geometry state | 377 // Helpers for setting up geometry state |
396 void finalizeReservedVertices(); | 378 void finalizeReservedVertices(); |
397 void finalizeReservedIndices(); | 379 void finalizeReservedIndices(); |
398 | 380 |
399 SkAutoTDelete<GrPathRendering> fPathRendering; | 381 SkAutoTDelete<GrPathRendering> fPathRendering; |
400 | 382 |
401 private: | 383 private: |
402 // GrDrawTarget overrides | 384 // GrDrawTarget overrides |
403 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void**
vertices) SK_OVERRIDE; | 385 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void**
vertices) SK_OVERRIDE; |
404 virtual bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE
; | 386 virtual bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE
; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 // not be created. | 439 // not be created. |
458 virtual bool createStencilBufferForRenderTarget(GrRenderTarget*, int width,
int height) = 0; | 440 virtual bool createStencilBufferForRenderTarget(GrRenderTarget*, int width,
int height) = 0; |
459 | 441 |
460 // attaches an existing SB to an existing RT. | 442 // attaches an existing SB to an existing RT. |
461 virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTar
get*) = 0; | 443 virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTar
get*) = 0; |
462 | 444 |
463 // The GrGpu typically records the clients requested state and then flushes | 445 // The GrGpu typically records the clients requested state and then flushes |
464 // deltas from previous state at draw time. This function does the | 446 // deltas from previous state at draw time. This function does the |
465 // backend-specific flush of the state. | 447 // backend-specific flush of the state. |
466 // returns false if current state is unsupported. | 448 // returns false if current state is unsupported. |
467 virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCop
y) = 0; | 449 virtual bool flushGraphicsState(DrawType, |
| 450 const ScissorState&, |
| 451 const GrDeviceCoordTexture* dstCopy) = 0; |
468 | 452 |
469 // clears target's entire stencil buffer to 0 | 453 // clears target's entire stencil buffer to 0 |
470 virtual void clearStencil(GrRenderTarget* target) = 0; | 454 virtual void clearStencil(GrRenderTarget* target) = 0; |
471 | 455 |
472 // Given a rt, find or create a stencil buffer and attach it | 456 // Given a rt, find or create a stencil buffer and attach it |
473 bool attachStencilBufferToRenderTarget(GrRenderTarget* target); | 457 bool attachStencilBufferToRenderTarget(GrRenderTarget* target); |
474 | 458 |
475 // GrDrawTarget overrides | 459 // GrDrawTarget overrides |
476 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; | 460 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; |
477 virtual void onStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; | 461 virtual void onStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 // counts number of uses of vertex/index pool in the geometry stack | 497 // counts number of uses of vertex/index pool in the geometry stack |
514 int fVertexP
oolUseCnt; | 498 int fVertexP
oolUseCnt; |
515 int fIndexPo
olUseCnt; | 499 int fIndexPo
olUseCnt; |
516 // these are mutable so they can be created on-demand | 500 // these are mutable so they can be created on-demand |
517 mutable GrIndexBuffer* fQuadInd
exBuffer; | 501 mutable GrIndexBuffer* fQuadInd
exBuffer; |
518 | 502 |
519 typedef GrDrawTarget INHERITED; | 503 typedef GrDrawTarget INHERITED; |
520 }; | 504 }; |
521 | 505 |
522 #endif | 506 #endif |
OLD | NEW |