6df4b86650ce9b0d7233f80ec87a4198d05ae37f
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / service / texture_definition.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_
7
8 #include <vector>
9
10 #include "base/memory/ref_counted.h"
11 #include "gpu/command_buffer/service/gl_utils.h"
12
13 namespace gfx {
14 class GLImage;
15 }
16
17 namespace gpu {
18 namespace gles2 {
19
20 class Texture;
21
22 class NativeImageBuffer : public base::RefCountedThreadSafe<NativeImageBuffer> {
23  public:
24   static scoped_refptr<NativeImageBuffer> Create(GLuint texture_id);
25
26   virtual void AddClient(gfx::GLImage* client) = 0;
27   virtual void RemoveClient(gfx::GLImage* client) = 0;
28   virtual bool IsClient(gfx::GLImage* client) = 0;
29   virtual void BindToTexture(GLenum target) = 0;
30   virtual void WillRead(gfx::GLImage* client) = 0;
31   virtual void WillWrite(gfx::GLImage* client) = 0;
32   virtual void DidRead(gfx::GLImage* client) = 0;
33   virtual void DidWrite(gfx::GLImage* client) = 0;
34
35  protected:
36   friend class base::RefCountedThreadSafe<NativeImageBuffer>;
37   NativeImageBuffer() {}
38   virtual ~NativeImageBuffer() {}
39
40   DISALLOW_COPY_AND_ASSIGN(NativeImageBuffer);
41 };
42
43 // An immutable description that can be used to create a texture that shares
44 // the underlying image buffer(s).
45 class TextureDefinition {
46  public:
47   TextureDefinition(GLenum target,
48                     Texture* texture,
49                     unsigned int version,
50                     const scoped_refptr<NativeImageBuffer>& image);
51   virtual ~TextureDefinition();
52
53   Texture* CreateTexture() const;
54   void UpdateTexture(Texture* texture) const;
55
56   unsigned int version() const { return version_; }
57   bool IsOlderThan(unsigned int version) const {
58     return (version - version_) < 0x80000000;
59   }
60   bool Matches(const Texture* texture) const;
61
62   scoped_refptr<NativeImageBuffer> image() { return image_buffer_; }
63
64  private:
65   struct LevelInfo {
66     LevelInfo(GLenum target,
67               GLenum internal_format,
68               GLsizei width,
69               GLsizei height,
70               GLsizei depth,
71               GLint border,
72               GLenum format,
73               GLenum type,
74               bool cleared);
75     ~LevelInfo();
76
77     GLenum target;
78     GLenum internal_format;
79     GLsizei width;
80     GLsizei height;
81     GLsizei depth;
82     GLint border;
83     GLenum format;
84     GLenum type;
85     bool cleared;
86   };
87
88   typedef std::vector<std::vector<LevelInfo> > LevelInfos;
89
90   unsigned int version_;
91   GLenum target_;
92   scoped_refptr<NativeImageBuffer> image_buffer_;
93   GLenum min_filter_;
94   GLenum mag_filter_;
95   GLenum wrap_s_;
96   GLenum wrap_t_;
97   GLenum usage_;
98   bool immutable_;
99   LevelInfos level_infos_;
100 };
101
102 }  // namespage gles2
103 }  // namespace gpu
104
105 #endif  // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_