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

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

Issue 12843026: Make GrDrawTarget::Caps ref counted and GrGLCaps derive from it. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months 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 | Annotate | Revision Log
OLDNEW
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 10
(...skipping 12 matching lines...) Expand all
23 #include "SkTArray.h" 23 #include "SkTArray.h"
24 #include "SkXfermode.h" 24 #include "SkXfermode.h"
25 25
26 class GrClipData; 26 class GrClipData;
27 class GrPath; 27 class GrPath;
28 class GrVertexBuffer; 28 class GrVertexBuffer;
29 class SkStrokeRec; 29 class SkStrokeRec;
30 30
31 class GrDrawTarget : public GrRefCnt { 31 class GrDrawTarget : public GrRefCnt {
32 protected: 32 protected:
33 /** This helper class allows GrDrawTarget subclasses to set the caps values without having to be 33 class DrawInfo;
34 made a friend of GrDrawTarget::Caps. */ 34
35 class CapsInternals { 35 public:
36 SK_DECLARE_INST_COUNT(GrDrawTarget)
37
38 /**
39 * Represents the draw target capabilities.
40 */
41 class Caps : public SkRefCnt {
36 public: 42 public:
43 Caps() { this->reset(); }
44 Caps(const Caps& c) { *this = c; }
45 Caps& operator= (const Caps& c);
46
47 virtual void reset();
48 virtual void print() const;
49
50 bool eightBitPaletteSupport() const { return f8BitPaletteSupport; }
51 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
52 bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
53 bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
54 bool hwAALineSupport() const { return fHWAALineSupport; }
55 bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; }
56 bool geometryShaderSupport() const { return fGeometryShaderSupport; }
57 bool dualSourceBlendingSupport() const { return fDualSourceBlendingSuppo rt; }
58 bool bufferLockSupport() const { return fBufferLockSupport; }
59 bool pathStencilingSupport() const { return fPathStencilingSupport; }
60
61 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
62 int maxTextureSize() const { return fMaxTextureSize; }
63 // Will be 0 if MSAA is not supported
64 int maxSampleCount() const { return fMaxSampleCount; }
65 protected:
66
37 bool f8BitPaletteSupport : 1; 67 bool f8BitPaletteSupport : 1;
38 bool fNPOTTextureTileSupport : 1; 68 bool fNPOTTextureTileSupport : 1;
39 bool fTwoSidedStencilSupport : 1; 69 bool fTwoSidedStencilSupport : 1;
40 bool fStencilWrapOpsSupport : 1; 70 bool fStencilWrapOpsSupport : 1;
41 bool fHWAALineSupport : 1; 71 bool fHWAALineSupport : 1;
42 bool fShaderDerivativeSupport : 1; 72 bool fShaderDerivativeSupport : 1;
43 bool fGeometryShaderSupport : 1; 73 bool fGeometryShaderSupport : 1;
44 bool fFSAASupport : 1;
45 bool fDualSourceBlendingSupport : 1; 74 bool fDualSourceBlendingSupport : 1;
46 bool fBufferLockSupport : 1; 75 bool fBufferLockSupport : 1;
47 bool fPathStencilingSupport : 1; 76 bool fPathStencilingSupport : 1;
48 77
49 int fMaxRenderTargetSize; 78 int fMaxRenderTargetSize;
50 int fMaxTextureSize; 79 int fMaxTextureSize;
51 int fMaxSampleCount; 80 int fMaxSampleCount;
52 }; 81 };
53 82
54 class DrawInfo;
55
56 public:
57 SK_DECLARE_INST_COUNT(GrDrawTarget)
58
59 /**
60 * Represents the draw target capabilities.
61 */
62 class Caps {
63 public:
64 Caps() { memset(this, 0, sizeof(Caps)); }
65 Caps(const Caps& c) { *this = c; }
66 Caps& operator= (const Caps& c) {
67 memcpy(this, &c, sizeof(Caps));
68 return *this;
69 }
70 void print() const;
71
72 bool eightBitPaletteSupport() const { return fInternals.f8BitPaletteSupp ort; }
73 bool npotTextureTileSupport() const { return fInternals.fNPOTTextureTile Support; }
74 bool twoSidedStencilSupport() const { return fInternals.fTwoSidedStencil Support; }
75 bool stencilWrapOpsSupport() const { return fInternals.fStencilWrapOpsS upport; }
76 bool hwAALineSupport() const { return fInternals.fHWAALineSupport; }
77 bool shaderDerivativeSupport() const { return fInternals.fShaderDerivati veSupport; }
78 bool geometryShaderSupport() const { return fInternals.fGeometryShaderSu pport; }
79 bool fsaaSupport() const { return fInternals.fFSAASupport; }
80 bool dualSourceBlendingSupport() const { return fInternals.fDualSourceBl endingSupport; }
81 bool bufferLockSupport() const { return fInternals.fBufferLockSupport; }
82 bool pathStencilingSupport() const { return fInternals.fPathStencilingSu pport; }
83
84 int maxRenderTargetSize() const { return fInternals.fMaxRenderTargetSize ; }
85 int maxTextureSize() const { return fInternals.fMaxTextureSize; }
86 // Will be 0 if MSAA is not supported
87 int maxSampleCount() const { return fInternals.fMaxSampleCount; }
88 private:
89 CapsInternals fInternals;
90 friend class GrDrawTarget; // to set values of fInternals
91 };
92
93 /////////////////////////////////////////////////////////////////////////// 83 ///////////////////////////////////////////////////////////////////////////
94 84
95 // The context may not be fully constructed and should not be used during Gr DrawTarget 85 // The context may not be fully constructed and should not be used during Gr DrawTarget
96 // construction. 86 // construction.
97 GrDrawTarget(GrContext* context); 87 GrDrawTarget(GrContext* context);
98 virtual ~GrDrawTarget(); 88 virtual ~GrDrawTarget();
99 89
100 /** 90 /**
101 * Gets the capabilities of the draw target. 91 * Gets the capabilities of the draw target.
102 */ 92 */
103 const Caps& getCaps() const { return fCaps; } 93 const Caps* caps() const { return fCaps.get(); }
104 94
105 /** 95 /**
106 * Sets the current clip to the region specified by clip. All draws will be 96 * Sets the current clip to the region specified by clip. All draws will be
107 * clipped against this clip if kClip_StateBit is enabled. 97 * clipped against this clip if kClip_StateBit is enabled.
108 * 98 *
109 * Setting the clip may (or may not) zero out the client's stencil bits. 99 * Setting the clip may (or may not) zero out the client's stencil bits.
110 * 100 *
111 * @param description of the clipping region 101 * @param description of the clipping region
112 */ 102 */
113 void setClip(const GrClipData* clip); 103 void setClip(const GrClipData* clip);
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 return src.fIndexBuffer->sizeInBytes() / sizeof(uint16_t); 635 return src.fIndexBuffer->sizeInBytes() / sizeof(uint16_t);
646 default: 636 default:
647 GrCrash("Unexpected Index Source."); 637 GrCrash("Unexpected Index Source.");
648 return 0; 638 return 0;
649 } 639 }
650 } 640 }
651 641
652 GrContext* getContext() { return fContext; } 642 GrContext* getContext() { return fContext; }
653 const GrContext* getContext() const { return fContext; } 643 const GrContext* getContext() const { return fContext; }
654 644
655 // allows derived class to set the caps
656 CapsInternals* capsInternals() { return &fCaps.fInternals; }
657
658 // A subclass may override this function if it wishes to be notified when th e clip is changed. 645 // A subclass may override this function if it wishes to be notified when th e clip is changed.
659 // The override should call INHERITED::clipWillBeSet(). 646 // The override should call INHERITED::clipWillBeSet().
660 virtual void clipWillBeSet(const GrClipData* clipData); 647 virtual void clipWillBeSet(const GrClipData* clipData);
661 648
662 // subclasses must call this in their destructors to ensure all vertex 649 // subclasses must call this in their destructors to ensure all vertex
663 // and index sources have been released (including those held by 650 // and index sources have been released (including those held by
664 // pushGeometrySource()) 651 // pushGeometrySource())
665 void releaseGeometry(); 652 void releaseGeometry();
666 653
667 // accessors for derived classes 654 // accessors for derived classes
668 const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back() ; } 655 const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back() ; }
669 // it is preferable to call this rather than getGeomSrc()->fVertexSize becau se of the assert. 656 // it is preferable to call this rather than getGeomSrc()->fVertexSize becau se of the assert.
670 size_t getVertexSize() const { 657 size_t getVertexSize() const {
671 // the vertex layout is only valid if a vertex source has been specified . 658 // the vertex layout is only valid if a vertex source has been specified .
672 GrAssert(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); 659 GrAssert(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
673 return this->getGeomSrc().fVertexSize; 660 return this->getGeomSrc().fVertexSize;
674 } 661 }
675 662
676 Caps fCaps; 663 // Subclass must initialize this in its constructor.
664 SkAutoTUnref<const Caps> fCaps;
677 665
678 /** 666 /**
679 * Used to communicate draws to subclass's onDraw function. 667 * Used to communicate draws to subclass's onDraw function.
680 */ 668 */
681 class DrawInfo { 669 class DrawInfo {
682 public: 670 public:
683 DrawInfo(const DrawInfo& di) { (*this) = di; } 671 DrawInfo(const DrawInfo& di) { (*this) = di; }
684 DrawInfo& operator =(const DrawInfo& di); 672 DrawInfo& operator =(const DrawInfo& di);
685 673
686 GrPrimitiveType primitiveType() const { return fPrimitiveType; } 674 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 const GrClipData* fClip; 766 const GrClipData* fClip;
779 GrDrawState* fDrawState; 767 GrDrawState* fDrawState;
780 GrDrawState fDefaultDraw State; 768 GrDrawState fDefaultDraw State;
781 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get. 769 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get.
782 GrContext* fContext; 770 GrContext* fContext;
783 771
784 typedef GrRefCnt INHERITED; 772 typedef GrRefCnt INHERITED;
785 }; 773 };
786 774
787 #endif 775 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrDrawTarget.cpp » ('j') | src/gpu/gl/GrGLContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698