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 } 23 ~GrFBBindableObj()24 virtual ~GrFBBindableObj() { 25 GrAlwaysAssert(0 == fColorReferees.count()); 26 GrAlwaysAssert(0 == fDepthReferees.count()); 27 GrAlwaysAssert(0 == fStencilReferees.count()); 28 } 29 setColorBound(GrFakeRefObj * referee)30 void setColorBound(GrFakeRefObj *referee) { 31 fColorReferees.append(1, &referee); 32 } resetColorBound(GrFakeRefObj * referee)33 void resetColorBound(GrFakeRefObj *referee) { 34 int index = fColorReferees.find(referee); 35 GrAlwaysAssert(0 <= index); 36 fColorReferees.removeShuffle(index); 37 } getColorBound(GrFakeRefObj * referee)38 bool getColorBound(GrFakeRefObj *referee) const { 39 int index = fColorReferees.find(referee); 40 return 0 <= index; 41 } getColorBound()42 bool getColorBound() const { 43 return 0 != fColorReferees.count(); 44 } 45 setDepthBound(GrFakeRefObj * referee)46 void setDepthBound(GrFakeRefObj *referee) { 47 fDepthReferees.append(1, &referee); 48 } resetDepthBound(GrFakeRefObj * referee)49 void resetDepthBound(GrFakeRefObj *referee) { 50 int index = fDepthReferees.find(referee); 51 GrAlwaysAssert(0 <= index); 52 fDepthReferees.removeShuffle(index); 53 } getDepthBound(GrFakeRefObj * referee)54 bool getDepthBound(GrFakeRefObj *referee) const { 55 int index = fDepthReferees.find(referee); 56 return 0 <= index; 57 } getDepthBound()58 bool getDepthBound() const { 59 return 0 != fDepthReferees.count(); 60 } 61 setStencilBound(GrFakeRefObj * referee)62 void setStencilBound(GrFakeRefObj *referee) { 63 fStencilReferees.append(1, &referee); 64 } resetStencilBound(GrFakeRefObj * referee)65 void resetStencilBound(GrFakeRefObj *referee) { 66 int index = fStencilReferees.find(referee); 67 GrAlwaysAssert(0 <= index); 68 fStencilReferees.removeShuffle(index); 69 } getStencilBound(GrFakeRefObj * referee)70 bool getStencilBound(GrFakeRefObj *referee) const { 71 int index = fStencilReferees.find(referee); 72 return 0 <= index; 73 } getStencilBound()74 bool getStencilBound() const { 75 return 0 != fStencilReferees.count(); 76 } 77 78 79 protected: 80 private: 81 SkTDArray<GrFakeRefObj *> fColorReferees; // frame buffers that use this as a color buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D") 82 SkTDArray<GrFakeRefObj *> fDepthReferees; // frame buffers that use this as a depth buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D") 83 SkTDArray<GrFakeRefObj *> fStencilReferees; // frame buffers that use this as a stencil buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D") 84 85 typedef GrFakeRefObj INHERITED; 86 }; 87 88 #endif // GrFBBindableObj_DEFINED 89