dd705323badecb1833e85a8da0353fb8b1dbd7f3
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright (c) 2012 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_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_
7
8 #include <vector>
9
10 #include "base/containers/hash_tables.h"
11 #include "base/macros.h"
12 #include "gpu/command_buffer/service/feature_info.h"
13 #include "gpu/command_buffer/service/gl_utils.h"
14 #include "gpu/gpu_export.h"
15
16 namespace gpu {
17 namespace gles2 {
18
19 class GLES2Decoder;
20
21 // This class encapsulates the resources required to implement the
22 // GL_CHROMIUM_copy_texture extension.  The copy operation is performed
23 // via glCopyTexImage2D() or a blit to a framebuffer object.
24 // The target of |dest_id| texture must be GL_TEXTURE_2D.
25 class GPU_EXPORT CopyTextureCHROMIUMResourceManager {
26  public:
27   CopyTextureCHROMIUMResourceManager();
28   ~CopyTextureCHROMIUMResourceManager();
29
30   void Initialize(const gles2::GLES2Decoder* decoder,
31                   const gles2::FeatureInfo::FeatureFlags& feature_flags);
32   void Destroy();
33
34   void DoCopyTexture(const gles2::GLES2Decoder* decoder,
35                      GLenum source_target,
36                      GLuint source_id,
37                      GLenum source_internal_format,
38                      GLenum dest_target,
39                      GLuint dest_id,
40                      GLenum dest_internal_format,
41                      GLsizei width,
42                      GLsizei height,
43                      bool flip_y,
44                      bool premultiply_alpha,
45                      bool unpremultiply_alpha);
46
47   void DoCopySubTexture(const gles2::GLES2Decoder* decoder,
48                         GLenum source_target,
49                         GLuint source_id,
50                         GLenum source_internal_format,
51                         GLenum dest_target,
52                         GLuint dest_id,
53                         GLenum dest_internal_format,
54                         GLint xoffset,
55                         GLint yoffset,
56                         GLint x,
57                         GLint y,
58                         GLsizei width,
59                         GLsizei height,
60                         GLsizei dest_width,
61                         GLsizei dest_height,
62                         GLsizei source_width,
63                         GLsizei source_height,
64                         bool flip_y,
65                         bool premultiply_alpha,
66                         bool unpremultiply_alpha);
67
68   void DoCopySubTextureWithTransform(const gles2::GLES2Decoder* decoder,
69                                      GLenum source_target,
70                                      GLuint source_id,
71                                      GLenum source_internal_format,
72                                      GLenum dest_target,
73                                      GLuint dest_id,
74                                      GLenum dest_internal_format,
75                                      GLint xoffset,
76                                      GLint yoffset,
77                                      GLint x,
78                                      GLint y,
79                                      GLsizei width,
80                                      GLsizei height,
81                                      GLsizei dest_width,
82                                      GLsizei dest_height,
83                                      GLsizei source_width,
84                                      GLsizei source_height,
85                                      bool flip_y,
86                                      bool premultiply_alpha,
87                                      bool unpremultiply_alpha,
88                                      const GLfloat transform_matrix[16]);
89
90   // This will apply a transform on the texture coordinates before sampling
91   // the source texture and copying to the destination texture. The transform
92   // matrix should be given in column-major form, so it can be passed
93   // directly to GL.
94   void DoCopyTextureWithTransform(const gles2::GLES2Decoder* decoder,
95                                   GLenum source_target,
96                                   GLuint source_id,
97                                   GLenum dest_target,
98                                   GLuint dest_id,
99                                   GLsizei width,
100                                   GLsizei height,
101                                   bool flip_y,
102                                   bool premultiply_alpha,
103                                   bool unpremultiply_alpha,
104                                   const GLfloat transform_matrix[16]);
105
106   // The attributes used during invocation of the extension.
107   static const GLuint kVertexPositionAttrib = 0;
108
109  private:
110   struct ProgramInfo {
111     ProgramInfo()
112         : program(0u),
113           vertex_dest_mult_handle(0u),
114           vertex_dest_add_handle(0u),
115           vertex_source_mult_handle(0u),
116           vertex_source_add_handle(0u),
117           tex_coord_transform_handle(0u),
118           sampler_handle(0u) {}
119
120     GLuint program;
121
122     // Transformations that map from the original quad coordinates [-1, 1] into
123     // the destination texture's quad coordinates.
124     GLuint vertex_dest_mult_handle;
125     GLuint vertex_dest_add_handle;
126
127     // Transformations that map from the original quad coordinates [-1, 1] into
128     // the source texture's texture coordinates.
129     GLuint vertex_source_mult_handle;
130     GLuint vertex_source_add_handle;
131
132     GLuint tex_coord_transform_handle;
133     GLuint sampler_handle;
134   };
135
136   void DoCopyTextureInternal(const gles2::GLES2Decoder* decoder,
137                              GLenum source_target,
138                              GLuint source_id,
139                              GLenum dest_target,
140                              GLuint dest_id,
141                              GLint xoffset,
142                              GLint yoffset,
143                              GLint x,
144                              GLint y,
145                              GLsizei width,
146                              GLsizei height,
147                              GLsizei dest_width,
148                              GLsizei dest_height,
149                              GLsizei source_width,
150                              GLsizei source_height,
151                              bool flip_y,
152                              bool premultiply_alpha,
153                              bool unpremultiply_alpha,
154                              const GLfloat transform_matrix[16]);
155
156   bool initialized_;
157   bool nv_egl_stream_consumer_external_;
158   typedef std::vector<GLuint> ShaderVector;
159   GLuint vertex_shader_;
160   ShaderVector fragment_shaders_;
161   typedef int ProgramMapKey;
162   typedef base::hash_map<ProgramMapKey, ProgramInfo> ProgramMap;
163   ProgramMap programs_;
164   GLuint vertex_array_object_id_;
165   GLuint buffer_id_;
166   GLuint framebuffer_;
167
168   DISALLOW_COPY_AND_ASSIGN(CopyTextureCHROMIUMResourceManager);
169 };
170
171 }  // namespace gles2
172 }  // namespace gpu
173
174 #endif  // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_