Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: src/gpu/GrDrawTarget.h

Issue 705593002: Refactor DrawTarget and GPU to be independent (Closed) Base URL: https://skia.googlesource.com/skia.git@early_clip
Patch Set: rebase on master Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrGpu.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 #include "SkTypes.h" 25 #include "SkTypes.h"
26 #include "SkXfermode.h" 26 #include "SkXfermode.h"
27 27
28 class GrClipData; 28 class GrClipData;
29 class GrDrawTargetCaps; 29 class GrDrawTargetCaps;
30 class GrPath; 30 class GrPath;
31 class GrPathRange; 31 class GrPathRange;
32 class GrVertexBuffer; 32 class GrVertexBuffer;
33 33
34 class GrDrawTarget : public SkRefCnt { 34 class GrDrawTarget : public SkRefCnt {
35 protected:
36 class DrawInfo;
37
38 public: 35 public:
39 SK_DECLARE_INST_COUNT(GrDrawTarget) 36 SK_DECLARE_INST_COUNT(GrDrawTarget)
40 37
41 typedef GrPathRendering::PathTransformType PathTransformType ; 38 typedef GrPathRendering::PathTransformType PathTransformType ;
42 39
43 /////////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////////
44 41
45 // The context may not be fully constructed and should not be used during Gr DrawTarget 42 // The context may not be fully constructed and should not be used during Gr DrawTarget
46 // construction. 43 // construction.
47 GrDrawTarget(GrContext* context); 44 GrDrawTarget(GrContext* context);
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 */ 450 */
454 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des c); 451 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des c);
455 452
456 453
457 /** 454 /**
458 * Release any resources that are cached but not currently in use. This 455 * Release any resources that are cached but not currently in use. This
459 * is intended to give an application some recourse when resources are low. 456 * is intended to give an application some recourse when resources are low.
460 */ 457 */
461 virtual void purgeResources() {}; 458 virtual void purgeResources() {};
462 459
460 class DrawInfo;
463 /** 461 /**
464 * For subclass internal use to invoke a call to onDraw(). See DrawInfo belo w. 462 * For subclass internal use to invoke a call to onDraw(). See DrawInfo belo w.
465 */ 463 */
466 void executeDraw(const DrawInfo& info, 464 void executeDraw(const DrawInfo& info,
467 const GrClipMaskManager::ScissorState& scissorState) { 465 const GrClipMaskManager::ScissorState& scissorState) {
468 this->onDraw(info, scissorState); 466 this->onDraw(info, scissorState);
469 } 467 }
470 468
471 /** 469 /**
472 * For subclass internal use to invoke a call to onStencilPath(). 470 * For subclass internal use to invoke a call to onStencilPath().
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); } 681 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); }
684 682
685 private: 683 private:
686 GrDrawTarget* fDrawTarget; 684 GrDrawTarget* fDrawTarget;
687 uint32_t fDrawID; // this may wrap, but we're doing direct compa rison 685 uint32_t fDrawID; // this may wrap, but we're doing direct compa rison
688 // so that should be okay 686 // so that should be okay
689 }; 687 };
690 688
691 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } 689 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); }
692 690
691 /**
692 * Used to communicate draws to GPUs / subclasses
693 */
694 class DrawInfo {
695 public:
696 DrawInfo(const DrawInfo& di) { (*this) = di; }
697 DrawInfo& operator =(const DrawInfo& di);
698
699 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
700 int startVertex() const { return fStartVertex; }
701 int startIndex() const { return fStartIndex; }
702 int vertexCount() const { return fVertexCount; }
703 int indexCount() const { return fIndexCount; }
704 int verticesPerInstance() const { return fVerticesPerInstance; }
705 int indicesPerInstance() const { return fIndicesPerInstance; }
706 int instanceCount() const { return fInstanceCount; }
707
708 bool isIndexed() const { return fIndexCount > 0; }
709 #ifdef SK_DEBUG
710 bool isInstanced() const; // this version is longer because of asserts
711 #else
712 bool isInstanced() const { return fInstanceCount > 0; }
713 #endif
714
715 // adds or remove instances
716 void adjustInstanceCount(int instanceOffset);
717 // shifts the start vertex
718 void adjustStartVertex(int vertexOffset);
719 // shifts the start index
720 void adjustStartIndex(int indexOffset);
721
722 void setDevBounds(const SkRect& bounds) {
723 fDevBoundsStorage = bounds;
724 fDevBounds = &fDevBoundsStorage;
725 }
726 const SkRect* getDevBounds() const { return fDevBounds; }
727
728 // NULL if no copy of the dst is needed for the draw.
729 const GrDeviceCoordTexture* getDstCopy() const {
730 if (fDstCopy.texture()) {
731 return &fDstCopy;
732 } else {
733 return NULL;
734 }
735 }
736
737 private:
738 DrawInfo() { fDevBounds = NULL; }
739
740 friend class GrDrawTarget;
741
742 GrPrimitiveType fPrimitiveType;
743
744 int fStartVertex;
745 int fStartIndex;
746 int fVertexCount;
747 int fIndexCount;
748
749 int fInstanceCount;
750 int fVerticesPerInstance;
751 int fIndicesPerInstance;
752
753 SkRect fDevBoundsStorage;
754 SkRect* fDevBounds;
755
756 GrDeviceCoordTexture fDstCopy;
757 };
693 758
694 bool programUnitTest(int maxStages); 759 bool programUnitTest(int maxStages);
695 760
696 protected: 761 protected:
697 // Extend access to GrDrawState::convertToPEndeingExec to subclasses. 762 // Extend access to GrDrawState::convertToPEndeingExec to subclasses.
698 void convertDrawStateToPendingExec(GrDrawState* ds) { 763 void convertDrawStateToPendingExec(GrDrawState* ds) {
699 ds->convertToPendingExec(); 764 ds->convertToPendingExec();
700 } 765 }
701 766
702 enum GeometrySrcType { 767 enum GeometrySrcType {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 // the vertex layout is only valid if a vertex source has been specified . 824 // the vertex layout is only valid if a vertex source has been specified .
760 SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); 825 SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
761 return this->getGeomSrc().fVertexSize; 826 return this->getGeomSrc().fVertexSize;
762 } 827 }
763 828
764 // Subclass must initialize this in its constructor. 829 // Subclass must initialize this in its constructor.
765 SkAutoTUnref<const GrDrawTargetCaps> fCaps; 830 SkAutoTUnref<const GrDrawTargetCaps> fCaps;
766 831
767 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; } 832 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers ; }
768 833
769 /**
770 * Used to communicate draws to subclass's onDraw function.
771 */
772 class DrawInfo {
773 public:
774 DrawInfo(const DrawInfo& di) { (*this) = di; }
775 DrawInfo& operator =(const DrawInfo& di);
776
777 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
778 int startVertex() const { return fStartVertex; }
779 int startIndex() const { return fStartIndex; }
780 int vertexCount() const { return fVertexCount; }
781 int indexCount() const { return fIndexCount; }
782 int verticesPerInstance() const { return fVerticesPerInstance; }
783 int indicesPerInstance() const { return fIndicesPerInstance; }
784 int instanceCount() const { return fInstanceCount; }
785
786 bool isIndexed() const { return fIndexCount > 0; }
787 #ifdef SK_DEBUG
788 bool isInstanced() const; // this version is longer because of asserts
789 #else
790 bool isInstanced() const { return fInstanceCount > 0; }
791 #endif
792
793 // adds or remove instances
794 void adjustInstanceCount(int instanceOffset);
795 // shifts the start vertex
796 void adjustStartVertex(int vertexOffset);
797 // shifts the start index
798 void adjustStartIndex(int indexOffset);
799
800 void setDevBounds(const SkRect& bounds) {
801 fDevBoundsStorage = bounds;
802 fDevBounds = &fDevBoundsStorage;
803 }
804 const SkRect* getDevBounds() const { return fDevBounds; }
805
806 // NULL if no copy of the dst is needed for the draw.
807 const GrDeviceCoordTexture* getDstCopy() const {
808 if (fDstCopy.texture()) {
809 return &fDstCopy;
810 } else {
811 return NULL;
812 }
813 }
814
815 private:
816 DrawInfo() { fDevBounds = NULL; }
817
818 friend class GrDrawTarget;
819
820 GrPrimitiveType fPrimitiveType;
821
822 int fStartVertex;
823 int fStartIndex;
824 int fVertexCount;
825 int fIndexCount;
826
827 int fInstanceCount;
828 int fVerticesPerInstance;
829 int fIndicesPerInstance;
830
831 SkRect fDevBoundsStorage;
832 SkRect* fDevBounds;
833
834 GrDeviceCoordTexture fDstCopy;
835 };
836
837 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required 834 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
838 // but couldn't be made. Otherwise, returns true. This method needs to be p rotected because it 835 // but couldn't be made. Otherwise, returns true. This method needs to be p rotected because it
839 // needs to be accessed by GLPrograms to setup a correct drawstate 836 // needs to be accessed by GLPrograms to setup a correct drawstate
840 bool setupDstReadIfNecessary(DrawInfo* info) { 837 bool setupDstReadIfNecessary(DrawInfo* info) {
841 return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds ()); 838 return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds ());
842 } 839 }
843 bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* dr awBounds); 840 bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* dr awBounds);
844 841
845 private: 842 private:
846 // A subclass can optionally overload this function to be notified before 843 // A subclass can optionally overload this function to be notified before
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 const GrClipData* fClip; 919 const GrClipData* fClip;
923 GrDrawState* fDrawState; 920 GrDrawState* fDrawState;
924 GrDrawState fDefaultDraw State; 921 GrDrawState fDefaultDraw State;
925 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get. 922 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get.
926 GrContext* fContext; 923 GrContext* fContext;
927 // To keep track that we always have at least as many debug marker adds as r emoves 924 // To keep track that we always have at least as many debug marker adds as r emoves
928 int fGpuTraceMar kerCount; 925 int fGpuTraceMar kerCount;
929 GrTraceMarkerSet fActiveTrace Markers; 926 GrTraceMarkerSet fActiveTrace Markers;
930 GrTraceMarkerSet fStoredTrace Markers; 927 GrTraceMarkerSet fStoredTrace Markers;
931 928
929 // TODO fix this
930 friend class GrGpu;
931 friend class GrGpuGL;
932
932 typedef SkRefCnt INHERITED; 933 typedef SkRefCnt INHERITED;
933 }; 934 };
934 935
935 /* 936 /*
936 * This class is JUST for clip mask manager. Everyone else should just use draw target above. 937 * This class is JUST for clip mask manager. Everyone else should just use draw target above.
937 */ 938 */
938 class GrClipTarget : public GrDrawTarget { 939 class GrClipTarget : public GrDrawTarget {
939 public: 940 public:
940 GrClipTarget(GrContext* context) : INHERITED(context) { 941 GrClipTarget(GrContext* context) : INHERITED(context) {
941 fClipMaskManager.setClipTarget(this); 942 fClipMaskManager.setClipTarget(this);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 974
974 virtual bool setupClip(const SkRect* devBounds, 975 virtual bool setupClip(const SkRect* devBounds,
975 GrDrawState::AutoRestoreEffects* are, 976 GrDrawState::AutoRestoreEffects* are,
976 GrDrawState::AutoRestoreStencil* ars, 977 GrDrawState::AutoRestoreStencil* ars,
977 GrClipMaskManager::ScissorState* scissorState) SK_OVE RRIDE; 978 GrClipMaskManager::ScissorState* scissorState) SK_OVE RRIDE;
978 979
979 typedef GrDrawTarget INHERITED; 980 typedef GrDrawTarget INHERITED;
980 }; 981 };
981 982
982 #endif 983 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrGpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698