Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / gpu / gl / GrGLTexture.h
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8
9 #ifndef GrGLTexture_DEFINED
10 #define GrGLTexture_DEFINED
11
12 #include "GrGpu.h"
13 #include "GrTexture.h"
14 #include "GrGLUtil.h"
15
16
17 class GrGLTexture : public GrTexture {
18
19 public:
20     struct TexParams {
21         GrGLenum fMinFilter;
22         GrGLenum fMagFilter;
23         GrGLenum fWrapS;
24         GrGLenum fWrapT;
25         GrGLenum fSwizzleRGBA[4];
26         void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
27     };
28
29     struct IDDesc {
30         GrGLuint        fTextureID;
31         bool            fIsWrapped;
32     };
33
34     GrGLTexture(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&);
35
36     virtual ~GrGLTexture() { this->release(); }
37
38     virtual GrBackendObject getTextureHandle() const SK_OVERRIDE;
39
40     virtual void textureParamsModified() SK_OVERRIDE { fTexParams.invalidate(); }
41
42     // These functions are used to track the texture parameters associated with the texture.
43     const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
44         *timestamp = fTexParamsTimestamp;
45         return fTexParams;
46     }
47
48     void setCachedTexParams(const TexParams& texParams,
49                             GrGpu::ResetTimestamp timestamp) {
50         fTexParams = texParams;
51         fTexParamsTimestamp = timestamp;
52     }
53
54     GrGLuint textureID() const { return fTextureID; }
55
56 protected:
57     // The public constructor registers this object with the cache. However, only the most derived
58     // class should register with the cache. This constructor does not do the registration and
59     // rather moves that burden onto the derived class.
60     enum Derived { kDerived };
61     GrGLTexture(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&, Derived);
62
63     void init(const GrSurfaceDesc&, const IDDesc&);
64
65     virtual void onAbandon() SK_OVERRIDE;
66     virtual void onRelease() SK_OVERRIDE;
67
68 private:
69     TexParams                       fTexParams;
70     GrGpu::ResetTimestamp           fTexParamsTimestamp;
71     GrGLuint                        fTextureID;
72
73     typedef GrTexture INHERITED;
74 };
75
76 #endif