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.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_
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"
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 {
27 CopyTextureCHROMIUMResourceManager();
28 ~CopyTextureCHROMIUMResourceManager();
30 void Initialize(const gles2::GLES2Decoder* decoder,
31 const gles2::FeatureInfo::FeatureFlags& feature_flags);
34 void DoCopyTexture(const gles2::GLES2Decoder* decoder,
37 GLenum source_internal_format,
40 GLenum dest_internal_format,
44 bool premultiply_alpha,
45 bool unpremultiply_alpha);
47 void DoCopySubTexture(const gles2::GLES2Decoder* decoder,
50 GLenum source_internal_format,
53 GLenum dest_internal_format,
63 GLsizei source_height,
65 bool premultiply_alpha,
66 bool unpremultiply_alpha);
68 void DoCopySubTextureWithTransform(const gles2::GLES2Decoder* decoder,
71 GLenum source_internal_format,
74 GLenum dest_internal_format,
84 GLsizei source_height,
86 bool premultiply_alpha,
87 bool unpremultiply_alpha,
88 const GLfloat transform_matrix[16]);
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
94 void DoCopyTextureWithTransform(const gles2::GLES2Decoder* decoder,
102 bool premultiply_alpha,
103 bool unpremultiply_alpha,
104 const GLfloat transform_matrix[16]);
106 // The attributes used during invocation of the extension.
107 static const GLuint kVertexPositionAttrib = 0;
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) {}
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;
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;
132 GLuint tex_coord_transform_handle;
133 GLuint sampler_handle;
136 void DoCopyTextureInternal(const gles2::GLES2Decoder* decoder,
137 GLenum source_target,
149 GLsizei source_width,
150 GLsizei source_height,
152 bool premultiply_alpha,
153 bool unpremultiply_alpha,
154 const GLfloat transform_matrix[16]);
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_;
168 DISALLOW_COPY_AND_ASSIGN(CopyTextureCHROMIUMResourceManager);
174 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_