robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 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 GrTextureObj_DEFINED |
| 10 | #define GrTextureObj_DEFINED |
| 11 | |
| 12 | #include "GrFBBindableObj.h" |
| 13 | |
| 14 | class GrTextureUnitObj; |
| 15 | |
| 16 | //////////////////////////////////////////////////////////////////////////////// |
| 17 | class GrTextureObj : public GrFBBindableObj { |
| 18 | GR_DEFINE_CREATOR(GrTextureObj); |
| 19 | |
| 20 | public: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 21 | GrTextureObj() |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 22 | : GrFBBindableObj() { |
| 23 | } |
| 24 | |
| 25 | virtual ~GrTextureObj() { |
| 26 | GrAlwaysAssert(0 == fTextureUnitReferees.count()); |
| 27 | } |
| 28 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 29 | void setBound(GrTextureUnitObj *referee) { |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 30 | fTextureUnitReferees.append(1, &referee); |
| 31 | } |
| 32 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 33 | void resetBound(GrTextureUnitObj *referee) { |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 34 | int index = fTextureUnitReferees.find(referee); |
| 35 | GrAlwaysAssert(0 <= index); |
| 36 | fTextureUnitReferees.removeShuffle(index); |
| 37 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 38 | bool getBound(GrTextureUnitObj *referee) const { |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 39 | int index = fTextureUnitReferees.find(referee); |
| 40 | return 0 <= index; |
| 41 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 42 | bool getBound() const { |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 43 | return 0 != fTextureUnitReferees.count(); |
| 44 | } |
| 45 | |
robertphillips@google.com | 0dd84a3 | 2012-04-16 16:24:35 +0000 | [diff] [blame] | 46 | virtual void deleteAction() SK_OVERRIDE; |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 47 | |
| 48 | protected: |
| 49 | |
| 50 | private: |
| 51 | // texture units that bind this texture (via "glBindTexture") |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 52 | SkTDArray<GrTextureUnitObj *> fTextureUnitReferees; |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 53 | |
| 54 | typedef GrFBBindableObj INHERITED; |
| 55 | }; |
| 56 | |
| 57 | #endif // GrTextureObj_DEFINED |