1 2 /* 3 * Copyright 2012 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 #ifndef GrFBBindableObj_DEFINED 10 #define GrFBBindableObj_DEFINED 11 12 #include "SkTDArray.h" 13 #include "GrFakeRefObj.h" 14 15 //////////////////////////////////////////////////////////////////////////////// 16 // A common base class for render buffers and textures 17 class GrFBBindableObj : public GrFakeRefObj { 18 19 public: GrFBBindableObj()20 GrFBBindableObj() 21 : GrFakeRefObj() 22 , fNumSamples(1) { 23 } 24 ~GrFBBindableObj()25 virtual ~GrFBBindableObj() { 26 GrAlwaysAssert(0 == fColorReferees.count()); 27 GrAlwaysAssert(0 == fDepthReferees.count()); 28 GrAlwaysAssert(0 == fStencilReferees.count()); 29 } 30 setColorBound(GrFakeRefObj * referee)31 void setColorBound(GrFakeRefObj *referee) { 32 fColorReferees.append(1, &referee); 33 } resetColorBound(GrFakeRefObj * referee)34 void resetColorBound(GrFakeRefObj *referee) { 35 int index = fColorReferees.find(referee); 36 GrAlwaysAssert(0 <= index); 37 fColorReferees.removeShuffle(index); 38 } getColorBound(GrFakeRefObj * referee)39 bool getColorBound(GrFakeRefObj *referee) const { 40 int index = fColorReferees.find(referee); 41 return 0 <= index; 42 } getColorBound()43 bool getColorBound() const { 44 return 0 != fColorReferees.count(); 45 } 46 setDepthBound(GrFakeRefObj * referee)47 void setDepthBound(GrFakeRefObj *referee) { 48 fDepthReferees.append(1, &referee); 49 } resetDepthBound(GrFakeRefObj * referee)50 void resetDepthBound(GrFakeRefObj *referee) { 51 int index = fDepthReferees.find(referee); 52 GrAlwaysAssert(0 <= index); 53 fDepthReferees.removeShuffle(index); 54 } getDepthBound(GrFakeRefObj * referee)55 bool getDepthBound(GrFakeRefObj *referee) const { 56 int index = fDepthReferees.find(referee); 57 return 0 <= index; 58 } getDepthBound()59 bool getDepthBound() const { 60 return 0 != fDepthReferees.count(); 61 } 62 setStencilBound(GrFakeRefObj * referee)63 void setStencilBound(GrFakeRefObj *referee) { 64 fStencilReferees.append(1, &referee); 65 } resetStencilBound(GrFakeRefObj * referee)66 void resetStencilBound(GrFakeRefObj *referee) { 67 int index = fStencilReferees.find(referee); 68 GrAlwaysAssert(0 <= index); 69 fStencilReferees.removeShuffle(index); 70 } getStencilBound(GrFakeRefObj * referee)71 bool getStencilBound(GrFakeRefObj *referee) const { 72 int index = fStencilReferees.find(referee); 73 return 0 <= index; 74 } getStencilBound()75 bool getStencilBound() const { 76 return 0 != fStencilReferees.count(); 77 } 78 numSamples()79 int numSamples() { return fNumSamples; } 80 81 protected: 82 int fNumSamples; 83 84 private: 85 SkTDArray<GrFakeRefObj *> fColorReferees; // frame buffers that use this as a color buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D") 86 SkTDArray<GrFakeRefObj *> fDepthReferees; // frame buffers that use this as a depth buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D") 87 SkTDArray<GrFakeRefObj *> fStencilReferees; // frame buffers that use this as a stencil buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D") 88 89 typedef GrFakeRefObj INHERITED; 90 }; 91 92 #endif // GrFBBindableObj_DEFINED 93