Chromium Code Reviews| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 * Takes the current active set of markers and stores them for later use. An y current marker | 367 * Takes the current active set of markers and stores them for later use. An y current marker |
| 368 * in the active set is removed from the active set and the targets remove f unction is called. | 368 * in the active set is removed from the active set and the targets remove f unction is called. |
| 369 * These functions do not work as a stack so you cannot call save a second t ime before calling | 369 * These functions do not work as a stack so you cannot call save a second t ime before calling |
| 370 * restore. Also, it is assumed that when restore is called the current acti ve set of markers | 370 * restore. Also, it is assumed that when restore is called the current acti ve set of markers |
| 371 * is empty. When the stored markers are added back into the active set, the targets add marker | 371 * is empty. When the stored markers are added back into the active set, the targets add marker |
| 372 * is called. | 372 * is called. |
| 373 */ | 373 */ |
| 374 void saveActiveTraceMarkers(); | 374 void saveActiveTraceMarkers(); |
| 375 void restoreActiveTraceMarkers(); | 375 void restoreActiveTraceMarkers(); |
| 376 | 376 |
| 377 /** | |
| 378 * Query to find out if the vertex or index source is reserved. | |
| 379 */ | |
| 380 bool hasReservedVerticesOrIndices() const { | |
| 381 return GrDrawTarget::kReserved_GeometrySrcType == this->getGeomSrc().fVe rtexSrc || | |
| 382 GrDrawTarget::kReserved_GeometrySrcType == this->getGeomSrc().fIn dexSrc; | |
| 383 } | |
| 384 | |
| 385 // Called to determine whether an onCopySurface call would succeed or not. T his is useful for | 377 // Called to determine whether an onCopySurface call would succeed or not. T his is useful for |
| 386 // proxy subclasses to test whether the copy would succeed without executing it yet. Derived | 378 // proxy subclasses to test whether the copy would succeed without executing it yet. Derived |
| 387 // classes must keep this consistent with their implementation of onCopySurf ace(). The inputs | 379 // classes must keep this consistent with their implementation of onCopySurf ace(). The inputs |
| 388 // are the same as onCopySurface(), i.e. srcRect and dstPoint are clipped to be inside the src | 380 // are the same as onCopySurface(), i.e. srcRect and dstPoint are clipped to be inside the src |
| 389 // and dst bounds. | 381 // and dst bounds. |
| 390 virtual bool canCopySurface(GrSurface* dst, | 382 virtual bool canCopySurface(GrSurface* dst, |
| 391 GrSurface* src, | 383 GrSurface* src, |
| 392 const SkIRect& srcRect, | 384 const SkIRect& srcRect, |
| 393 const SkIPoint& dstPoint) = 0; | 385 const SkIPoint& dstPoint) = 0; |
| 394 | 386 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 413 | 405 |
| 414 /** | 406 /** |
| 415 * Sets source of index data for the next indexed draw. Data does not have | 407 * Sets source of index data for the next indexed draw. Data does not have |
| 416 * to be in the buffer until drawIndexed. | 408 * to be in the buffer until drawIndexed. |
| 417 * | 409 * |
| 418 * @param buffer index buffer containing indices. Must be unlocked | 410 * @param buffer index buffer containing indices. Must be unlocked |
| 419 * before indexed draw call. | 411 * before indexed draw call. |
| 420 */ | 412 */ |
| 421 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); | 413 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
| 422 | 414 |
| 423 /** | |
| 424 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex | |
| 425 * source to reserved, array, or buffer before next draw. May be able to fre e | |
| 426 * up temporary storage allocated by setVertexSourceToArray or | |
| 427 * reserveVertexSpace. | |
| 428 */ | |
| 429 void resetVertexSource(); | |
| 430 | |
| 431 /** | |
| 432 * Resets index source. Indexed Drawing from reset indices is illegal. Set | |
| 433 * index source to reserved, array, or buffer before next indexed draw. May | |
| 434 * be able to free up temporary storage allocated by setIndexSourceToArray | |
| 435 * or reserveIndexSpace. | |
| 436 */ | |
| 437 void resetIndexSource(); | |
| 438 | |
| 439 /** | |
| 440 * Pushes and resets the vertex/index sources. Any reserved vertex / index | |
| 441 * data is finalized (i.e. cannot be updated after the matching pop but can | |
| 442 * be drawn from). Must be balanced by a pop. | |
| 443 */ | |
| 444 void pushGeometrySource(); | |
| 445 | |
| 446 /** | |
| 447 * Pops the vertex / index sources from the matching push. | |
| 448 */ | |
| 449 void popGeometrySource(); | |
| 450 | |
| 451 protected: | 415 protected: |
| 452 DrawType PrimTypeToDrawType(GrPrimitiveType type) { | 416 DrawType PrimTypeToDrawType(GrPrimitiveType type) { |
| 453 switch (type) { | 417 switch (type) { |
| 454 case kTriangles_GrPrimitiveType: | 418 case kTriangles_GrPrimitiveType: |
| 455 case kTriangleStrip_GrPrimitiveType: | 419 case kTriangleStrip_GrPrimitiveType: |
| 456 case kTriangleFan_GrPrimitiveType: | 420 case kTriangleFan_GrPrimitiveType: |
| 457 return kDrawTriangles_DrawType; | 421 return kDrawTriangles_DrawType; |
| 458 case kPoints_GrPrimitiveType: | 422 case kPoints_GrPrimitiveType: |
| 459 return kDrawPoints_DrawType; | 423 return kDrawPoints_DrawType; |
| 460 case kLines_GrPrimitiveType: | 424 case kLines_GrPrimitiveType: |
| 461 case kLineStrip_GrPrimitiveType: | 425 case kLineStrip_GrPrimitiveType: |
| 462 return kDrawLines_DrawType; | 426 return kDrawLines_DrawType; |
| 463 default: | 427 default: |
| 464 SkFAIL("Unexpected primitive type"); | 428 SkFAIL("Unexpected primitive type"); |
| 465 return kDrawTriangles_DrawType; | 429 return kDrawTriangles_DrawType; |
| 466 } | 430 } |
| 467 } | 431 } |
| 468 | 432 |
| 469 // Functions used to map clip-respecting stencil tests into normal | 433 // Functions used to map clip-respecting stencil tests into normal |
| 470 // stencil funcs supported by GPUs. | 434 // stencil funcs supported by GPUs. |
| 471 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, | 435 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, |
| 472 GrStencilFunc func); | 436 GrStencilFunc func); |
| 473 static void ConvertStencilFuncAndMask(GrStencilFunc func, | 437 static void ConvertStencilFuncAndMask(GrStencilFunc func, |
| 474 bool clipInStencil, | 438 bool clipInStencil, |
| 475 unsigned int clipBit, | 439 unsigned int clipBit, |
| 476 unsigned int userBits, | 440 unsigned int userBits, |
| 477 unsigned int* ref, | 441 unsigned int* ref, |
| 478 unsigned int* mask); | 442 unsigned int* mask); |
| 479 | 443 |
| 480 // subclasses must call this in their destructors to ensure all vertex | 444 struct GeometrySrcState { |
| 481 // and index sources have been released (including those held by | 445 GeometrySrcState() : fVertexBuffer(NULL), fIndexBuffer(NULL), fVertexSiz e(0) {} |
| 482 // pushGeometrySource()) | 446 const GrVertexBuffer* fVertexBuffer; |
| 483 void releaseGeometry(); | 447 const GrIndexBuffer* fIndexBuffer; |
| 448 size_t fVertexSize; | |
| 449 }; | |
| 484 | 450 |
| 485 // accessors for derived classes | 451 // accessors for derived classes |
| 486 const GrDrawTarget::GeometrySrcState& getGeomSrc() const { return fGeoSrcSta teStack.back(); } | 452 const GeometrySrcState& getGeomSrc() const { return fGeoSrcState; } |
| 487 | 453 |
| 488 // it is preferable to call this rather than getGeomSrc()->fVertexSize becau se of the assert. | 454 // it is preferable to call this rather than getGeomSrc()->fVertexSize becau se of the assert. |
| 489 size_t getVertexSize() const { | 455 size_t getVertexSize() const { |
| 490 // the vertex layout is only valid if a vertex source has been specified . | 456 // the vertex layout is only valid if a vertex source has been specified . |
| 491 SkASSERT(this->getGeomSrc().fVertexSrc != GrDrawTarget::kNone_GeometrySr cType); | 457 SkASSERT(this->getGeomSrc().fVertexBuffer); |
| 492 return this->getGeomSrc().fVertexSize; | 458 return this->getGeomSrc().fVertexSize; |
| 493 } | 459 } |
| 494 | 460 |
| 495 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; } | 461 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; } |
| 496 | 462 |
| 497 GrContext::GPUStats fGPUStats; | 463 GrContext::GPUStats fGPUStats; |
| 498 | 464 |
| 499 struct GeometryPoolState { | 465 struct GeometryPoolState { |
|
bsalomon
2014/11/07 20:04:31
delete?
| |
| 500 const GrVertexBuffer* fPoolVertexBuffer; | 466 const GrVertexBuffer* fPoolVertexBuffer; |
| 501 int fPoolStartVertex; | 467 int fPoolStartVertex; |
| 502 | 468 |
| 503 const GrIndexBuffer* fPoolIndexBuffer; | 469 const GrIndexBuffer* fPoolIndexBuffer; |
| 504 int fPoolStartIndex; | 470 int fPoolStartIndex; |
| 505 }; | 471 }; |
| 506 const GeometryPoolState& getGeomPoolState() { | |
| 507 return fGeomPoolStateStack.back(); | |
| 508 } | |
| 509 | |
| 510 // Helpers for setting up geometry state | |
| 511 void finalizeReservedVertices(); | |
| 512 void finalizeReservedIndices(); | |
| 513 | 472 |
| 514 SkAutoTDelete<GrPathRendering> fPathRendering; | 473 SkAutoTDelete<GrPathRendering> fPathRendering; |
| 515 | 474 |
| 516 // Subclass must initialize this in its constructor. | 475 // Subclass must initialize this in its constructor. |
| 517 SkAutoTUnref<const GrDrawTargetCaps> fCaps; | 476 SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
| 518 | 477 |
| 519 private: | 478 private: |
| 520 // GrDrawTarget overrides | |
| 521 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices); | |
| 522 virtual bool onReserveIndexSpace(int indexCount, void** indices); | |
| 523 virtual void releaseReservedVertexSpace(); | |
| 524 virtual void releaseReservedIndexSpace(); | |
| 525 virtual void geometrySourceWillPush(); | |
| 526 virtual void geometrySourceWillPop(const GrDrawTarget::GeometrySrcState& res toredState); | |
| 527 | |
| 528 // called when the 3D context state is unknown. Subclass should emit any | 479 // called when the 3D context state is unknown. Subclass should emit any |
| 529 // assumed 3D context state and dirty any state cache. | 480 // assumed 3D context state and dirty any state cache. |
| 530 virtual void onResetContext(uint32_t resetBits) = 0; | 481 virtual void onResetContext(uint32_t resetBits) = 0; |
| 531 | 482 |
| 532 // overridden by backend-specific derived class to create objects. | 483 // overridden by backend-specific derived class to create objects. |
| 533 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, | 484 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, |
| 534 const void* srcData, | 485 const void* srcData, |
| 535 size_t rowBytes) = 0; | 486 size_t rowBytes) = 0; |
| 536 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, | 487 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| 537 const void* srcData) = 0; | 488 const void* srcData) = 0; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 int count, | 558 int count, |
| 608 const float transforms[], | 559 const float transforms[], |
| 609 GrDrawTarget::PathTransformType, | 560 GrDrawTarget::PathTransformType, |
| 610 const GrClipMaskManager::ScissorState&, | 561 const GrClipMaskManager::ScissorState&, |
| 611 const GrStencilSettings&, | 562 const GrStencilSettings&, |
| 612 const GrDeviceCoordTexture*); | 563 const GrDeviceCoordTexture*); |
| 613 | 564 |
| 614 virtual void didAddGpuTraceMarker() = 0; | 565 virtual void didAddGpuTraceMarker() = 0; |
| 615 virtual void didRemoveGpuTraceMarker() = 0; | 566 virtual void didRemoveGpuTraceMarker() = 0; |
| 616 | 567 |
| 617 | |
| 618 // readies the pools to provide vertex/index data. | |
| 619 void prepareVertexPool(); | |
| 620 void prepareIndexPool(); | |
| 621 | |
| 622 void resetContext() { | 568 void resetContext() { |
| 623 this->onResetContext(fResetBits); | 569 this->onResetContext(fResetBits); |
| 624 fResetBits = 0; | 570 fResetBits = 0; |
| 625 ++fResetTimestamp; | 571 ++fResetTimestamp; |
| 626 } | 572 } |
| 627 | 573 |
| 628 void handleDirtyContext() { | 574 void handleDirtyContext() { |
| 629 if (fResetBits) { | 575 if (fResetBits) { |
| 630 this->resetContext(); | 576 this->resetContext(); |
| 631 } | 577 } |
| 632 } | 578 } |
| 633 | 579 |
| 634 // called when setting a new vert/idx source to unref prev vb/ib | 580 GeometrySrcState fGeoSrcS tate; |
| 635 void releasePreviousVertexSource(); | |
| 636 void releasePreviousIndexSource(); | |
| 637 | |
| 638 enum { | |
| 639 kPreallocGeoSrcStateStackCnt = 4, | |
| 640 }; | |
| 641 SkSTArray<kPreallocGeoSrcStateStackCnt, GrDrawTarget::GeometrySrcState, true > fGeoSrcStateStack; | |
| 642 | |
| 643 enum { | |
| 644 kPreallocGeomPoolStateStackCnt = 4, | |
| 645 }; | |
| 646 SkSTArray<kPreallocGeomPoolStateStackCnt, GeometryPoolState, true> fGeomPoo lStateStack; | |
| 647 ResetTimestamp fResetTi mestamp; | 581 ResetTimestamp fResetTi mestamp; |
| 648 uint32_t fResetBi ts; | 582 uint32_t fResetBi ts; |
| 649 GrVertexBufferAllocPool* fVertexP ool; | |
| 650 GrIndexBufferAllocPool* fIndexPo ol; | |
| 651 // counts number of uses of vertex/index pool in the geometry stack | |
| 652 int fVertexP oolUseCnt; | |
| 653 int fIndexPo olUseCnt; | |
| 654 // these are mutable so they can be created on-demand | 583 // these are mutable so they can be created on-demand |
| 655 mutable GrIndexBuffer* fQuadInd exBuffer; | 584 mutable GrIndexBuffer* fQuadInd exBuffer; |
| 656 GrDrawState fDefaultDraw State; | 585 GrDrawState fDefault DrawState; |
| 657 GrDrawState* fDrawSta te; | 586 GrDrawState* fDrawSta te; |
| 658 // To keep track that we always have at least as many debug marker adds as r emoves | 587 // To keep track that we always have at least as many debug marker adds as r emoves |
| 659 int fGpuTrac eMarkerCount; | 588 int fGpuTrac eMarkerCount; |
| 660 GrTraceMarkerSet fActiveT raceMarkers; | 589 GrTraceMarkerSet fActiveT raceMarkers; |
| 661 GrTraceMarkerSet fStoredT raceMarkers; | 590 GrTraceMarkerSet fStoredT raceMarkers; |
| 662 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. | 591 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
| 663 GrContext* fContext ; | 592 GrContext* fContext ; |
| 664 | 593 |
| 665 // TODO fix this | 594 // TODO fix this |
| 666 friend class GrInOrderDrawBuffer; | 595 friend class GrInOrderDrawBuffer; |
| 667 | 596 |
| 668 typedef SkRefCnt INHERITED; | 597 typedef SkRefCnt INHERITED; |
| 669 }; | 598 }; |
| 670 | 599 |
| 671 #endif | 600 #endif |
| OLD | NEW |