OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef GrDrawTarget_DEFINED | 10 #ifndef GrDrawTarget_DEFINED |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 const SkRect* devBounds = NULL); | 324 const SkRect* devBounds = NULL); |
325 | 325 |
326 /** | 326 /** |
327 * Draws path into the stencil buffer. The fill must be either even/odd or | 327 * Draws path into the stencil buffer. The fill must be either even/odd or |
328 * winding (not inverse or hairline). It will respect the HW antialias flag | 328 * winding (not inverse or hairline). It will respect the HW antialias flag |
329 * on the draw state (if possible in the 3D API). | 329 * on the draw state (if possible in the 3D API). |
330 */ | 330 */ |
331 void stencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill); | 331 void stencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill); |
332 | 332 |
333 /** | 333 /** |
334 * Helper function for drawing rects. This does not use the current index | 334 * Helper function for drawing rects. It performs a geometry src push and po p |
335 * and vertex sources. After returning, the vertex and index sources may | 335 * and thus will finalize any reserved geometry. |
336 * have changed. They should be reestablished before the next draw call. | |
337 * This cannot be called between reserving and releasing | |
338 * geometry. | |
339 * | |
340 * A subclass may override this to perform more optimal rect rendering. Its | |
341 * draws should be funneled through one of the public GrDrawTarget draw meth ods | |
342 * (e.g. drawNonIndexed, drawIndexedInstances, ...). The base class draws a two | |
343 * triangle fan using drawNonIndexed from reserved vertex space. | |
344 * | 336 * |
345 * @param rect the rect to draw | 337 * @param rect the rect to draw |
346 * @param matrix optional matrix applied to rect (before viewMatrix) | 338 * @param matrix optional matrix applied to rect (before viewMatrix) |
347 * @param localRect optional rect that specifies local coords to map onto | 339 * @param localRect optional rect that specifies local coords to map onto |
348 * rect. If NULL then rect serves as the local coords. | 340 * rect. If NULL then rect serves as the local coords. |
349 * @param localMatrix optional matrix applied to localRect. If | 341 * @param localMatrix optional matrix applied to localRect. If |
350 * srcRect is non-NULL and srcMatrix is non-NULL | 342 * srcRect is non-NULL and srcMatrix is non-NULL |
351 * then srcRect will be transformed by srcMatrix. | 343 * then srcRect will be transformed by srcMatrix. |
352 * srcMatrix can be NULL when no srcMatrix is desired. | 344 * srcMatrix can be NULL when no srcMatrix is desired. |
353 */ | 345 */ |
354 virtual void drawRect(const GrRect& rect, | 346 void drawRect(const GrRect& rect, |
355 const SkMatrix* matrix, | 347 const SkMatrix* matrix, |
356 const GrRect* localRect, | 348 const GrRect* localRect, |
357 const SkMatrix* localMatrix); | 349 const SkMatrix* localMatrix) { |
350 AutoGeometryPush agp(this); | |
351 this->onDrawRect(rect, matrix, localRect, localMatrix); | |
352 } | |
358 | 353 |
359 /** | 354 /** |
360 * Helper for drawRect when the caller doesn't need separate local rects or matrices. | 355 * Helper for drawRect when the caller doesn't need separate local rects or matrices. |
361 */ | 356 */ |
362 void drawSimpleRect(const GrRect& rect, const SkMatrix* matrix = NULL) { | 357 void drawSimpleRect(const GrRect& rect, const SkMatrix* matrix = NULL) { |
363 drawRect(rect, matrix, NULL, NULL); | 358 drawRect(rect, matrix, NULL, NULL); |
364 } | 359 } |
365 void drawSimpleRect(const GrIRect& irect, const SkMatrix* matrix = NULL) { | 360 void drawSimpleRect(const GrIRect& irect, const SkMatrix* matrix = NULL) { |
366 SkRect rect = SkRect::MakeFromIRect(irect); | 361 SkRect rect = SkRect::MakeFromIRect(irect); |
367 this->drawRect(rect, matrix, NULL, NULL); | 362 this->drawRect(rect, matrix, NULL, NULL); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 } | 521 } |
527 private: | 522 private: |
528 GrDrawTarget* fTarget; | 523 GrDrawTarget* fTarget; |
529 const GrClipData* fClip; | 524 const GrClipData* fClip; |
530 SkTLazy<SkClipStack> fStack; | 525 SkTLazy<SkClipStack> fStack; |
531 GrClipData fReplacementClip; | 526 GrClipData fReplacementClip; |
532 }; | 527 }; |
533 | 528 |
534 //////////////////////////////////////////////////////////////////////////// | 529 //////////////////////////////////////////////////////////////////////////// |
535 | 530 |
536 class AutoGeometryAndStatePush : ::GrNoncopyable { | 531 /** |
532 * Saves the geometry src state at construction and restores in the destruct or. It also saves | |
533 * and then restores the vertex attrib state. | |
534 */ | |
535 class AutoGeometryPush : ::GrNoncopyable { | |
537 public: | 536 public: |
538 AutoGeometryAndStatePush(GrDrawTarget* target, ASRInit init) | 537 AutoGeometryPush(GrDrawTarget* target) |
539 : fState(target, init) { | 538 : fAttribRestore(target->drawState()) { |
540 GrAssert(NULL != target); | 539 GrAssert(NULL != target); |
541 fTarget = target; | 540 fTarget = target; |
542 target->pushGeometrySource(); | 541 target->pushGeometrySource(); |
543 } | 542 } |
544 ~AutoGeometryAndStatePush() { | 543 |
545 fTarget->popGeometrySource(); | 544 ~AutoGeometryPush() { fTarget->popGeometrySource(); } |
545 | |
546 private: | |
547 GrDrawTarget* fTarget; | |
548 GrDrawState::AutoVertexAttribRestore fAttribRestore; | |
549 }; | |
550 | |
551 /** | |
552 * Combination of AutoGeometryPush and AutoStateRestore. The vertex attribs will be in default | |
553 * state regardless of ASRInit value. | |
jvanverth1
2013/04/02 18:45:35
Maybe I'm misunderstanding. What happens if the pu
bsalomon
2013/04/02 18:47:39
It's already using an AutoStateRestore. So it will
| |
554 */ | |
555 class AutoGeometryAndStatePush : ::GrNoncopyable { | |
556 public: | |
557 AutoGeometryAndStatePush(GrDrawTarget* target, ASRInit init) | |
558 : fState(target, init){ | |
559 GrAssert(NULL != target); | |
560 fTarget = target; | |
561 target->pushGeometrySource(); | |
562 if (kPreserve_ASRInit == init) { | |
563 target->drawState()->setDefaultVertexAttribs(); | |
564 } | |
546 } | 565 } |
566 | |
567 ~AutoGeometryAndStatePush() { fTarget->popGeometrySource(); } | |
568 | |
547 private: | 569 private: |
570 AutoStateRestore fState; | |
548 GrDrawTarget* fTarget; | 571 GrDrawTarget* fTarget; |
549 AutoStateRestore fState; | |
550 }; | 572 }; |
551 | 573 |
552 protected: | 574 protected: |
553 | 575 |
554 enum GeometrySrcType { | 576 enum GeometrySrcType { |
555 kNone_GeometrySrcType, //<! src has not been specified | 577 kNone_GeometrySrcType, //<! src has not been specified |
556 kReserved_GeometrySrcType, //<! src was set using reserve*Space | 578 kReserved_GeometrySrcType, //<! src was set using reserve*Space |
557 kArray_GeometrySrcType, //<! src was set using set*SourceToArray | 579 kArray_GeometrySrcType, //<! src was set using set*SourceToArray |
558 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer | 580 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer |
559 }; | 581 }; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCou nt) = 0; | 732 virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCou nt) = 0; |
711 virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) = 0; | 733 virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) = 0; |
712 // subclass is notified that geom source will be set away from an array | 734 // subclass is notified that geom source will be set away from an array |
713 virtual void releaseVertexArray() = 0; | 735 virtual void releaseVertexArray() = 0; |
714 virtual void releaseIndexArray() = 0; | 736 virtual void releaseIndexArray() = 0; |
715 // subclass overrides to be notified just before geo src state is pushed/pop ped. | 737 // subclass overrides to be notified just before geo src state is pushed/pop ped. |
716 virtual void geometrySourceWillPush() = 0; | 738 virtual void geometrySourceWillPush() = 0; |
717 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; | 739 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; |
718 // subclass called to perform drawing | 740 // subclass called to perform drawing |
719 virtual void onDraw(const DrawInfo&) = 0; | 741 virtual void onDraw(const DrawInfo&) = 0; |
742 // Implementation of drawRect. The geometry src and vertex attribs will alre ady | |
743 // be saved before this is called and restored afterwards. A subclass may ov erride | |
744 // this to perform more optimal rect rendering. Its draws should be funneled through | |
745 // one of the public GrDrawTarget draw methods (e.g. drawNonIndexed, | |
746 // drawIndexedInstances, ...). The base class draws a two triangle fan using | |
747 // drawNonIndexed from reserved vertex space. | |
748 virtual void onDrawRect(const GrRect& rect, | |
749 const SkMatrix* matrix, | |
750 const GrRect* localRect, | |
751 const SkMatrix* localMatrix); | |
720 virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath: :FillType fill) = 0; | 752 virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath: :FillType fill) = 0; |
721 | 753 |
722 // helpers for reserving vertex and index space. | 754 // helpers for reserving vertex and index space. |
723 bool reserveVertexSpace(size_t vertexSize, | 755 bool reserveVertexSpace(size_t vertexSize, |
724 int vertexCount, | 756 int vertexCount, |
725 void** vertices); | 757 void** vertices); |
726 bool reserveIndexSpace(int indexCount, void** indices); | 758 bool reserveIndexSpace(int indexCount, void** indices); |
727 | 759 |
728 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to | 760 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to |
729 // indicate non-indexed drawing. | 761 // indicate non-indexed drawing. |
(...skipping 15 matching lines...) Expand all Loading... | |
745 const GrClipData* fClip; | 777 const GrClipData* fClip; |
746 GrDrawState* fDrawState; | 778 GrDrawState* fDrawState; |
747 GrDrawState fDefaultDraw State; | 779 GrDrawState fDefaultDraw State; |
748 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get. | 780 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get. |
749 GrContext* fContext; | 781 GrContext* fContext; |
750 | 782 |
751 typedef GrRefCnt INHERITED; | 783 typedef GrRefCnt INHERITED; |
752 }; | 784 }; |
753 | 785 |
754 #endif | 786 #endif |
OLD | NEW |