180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc.
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef GrTextureObj_DEFINED
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GrTextureObj_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrFBBindableObj.h"
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass GrTextureUnitObj;
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////////
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass GrTextureObj : public GrFBBindableObj {
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GR_DEFINE_CREATOR(GrTextureObj);
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTextureObj()
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        : GrFBBindableObj() {
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual ~GrTextureObj() {
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAlwaysAssert(0 == fTextureUnitReferees.count());
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setBound(GrTextureUnitObj *referee) {
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fTextureUnitReferees.append(1, &referee);
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void resetBound(GrTextureUnitObj *referee) {
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int index = fTextureUnitReferees.find(referee);
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAlwaysAssert(0 <= index);
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fTextureUnitReferees.removeShuffle(index);
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool getBound(GrTextureUnitObj *referee) const {
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int index = fTextureUnitReferees.find(referee);
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return 0 <= index;
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool getBound() const {
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return 0 != fTextureUnitReferees.count();
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual void deleteAction() SK_OVERRIDE;
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprotected:
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // texture units that bind this texture (via "glBindTexture")
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkTDArray<GrTextureUnitObj *> fTextureUnitReferees;
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    typedef GrFBBindableObj INHERITED;
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif // GrTextureObj_DEFINED
58