OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "gpu/command_buffer/service/gl_utils.h" | 11 #include "gpu/command_buffer/service/gl_utils.h" |
12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
13 #include "gpu/command_buffer/service/texture_manager.h" | |
13 #include "ui/gl/gl_version_info.h" | 14 #include "ui/gl/gl_version_info.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, | 18 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
18 0.0f, 1.0f, 0.0f, 0.0f, | 19 0.0f, 1.0f, 0.0f, 0.0f, |
19 0.0f, 0.0f, 1.0f, 0.0f, | 20 0.0f, 0.0f, 1.0f, 0.0f, |
20 0.0f, 0.0f, 0.0f, 1.0f}; | 21 0.0f, 0.0f, 0.0f, 1.0f}; |
21 | 22 |
22 enum FragmentShaderId { | 23 enum FragmentShaderId { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 case GL_TEXTURE_EXTERNAL_OES: | 80 case GL_TEXTURE_EXTERNAL_OES: |
80 return shader_ids[index][SAMPLER_EXTERNAL_OES]; | 81 return shader_ids[index][SAMPLER_EXTERNAL_OES]; |
81 default: | 82 default: |
82 break; | 83 break; |
83 } | 84 } |
84 | 85 |
85 NOTREACHED(); | 86 NOTREACHED(); |
86 return shader_ids[0][SAMPLER_2D]; | 87 return shader_ids[0][SAMPLER_2D]; |
87 } | 88 } |
88 | 89 |
89 const char* kShaderPrecisionPreamble = "\ | 90 const char* kShaderPrecisionPreamble = |
90 #ifdef GL_ES\n\ | 91 "#ifdef GL_ES\n" |
91 precision mediump float;\n\ | 92 "precision mediump float;\n" |
92 #define TexCoordPrecision mediump\n\ | 93 "#define TexCoordPrecision mediump\n" |
93 #else\n\ | 94 "#else\n" |
94 #define TexCoordPrecision\n\ | 95 "#define TexCoordPrecision\n" |
95 #endif\n"; | 96 "#endif\n"; |
96 | 97 |
97 std::string GetVertexShaderSource(const gl::GLVersionInfo& gl_version_info) { | 98 std::string GetVertexShaderSource(const gl::GLVersionInfo& gl_version_info) { |
98 std::string source; | 99 std::string source; |
99 | 100 |
100 // Preamble for core and compatibility mode. | 101 // Preamble for core and compatibility mode. |
101 if (gl_version_info.is_desktop_core_profile) { | 102 if (gl_version_info.is_desktop_core_profile) { |
102 source += std::string("\ | 103 source += std::string("#version 150\n"); |
Zhenyao Mo
2016/11/14 20:04:50
This is incorrect. Now we have
1) desktop core pr
qiankun
2016/11/18 01:25:40
I updated the shaders per underlying context. I th
| |
103 #version 150\n\ | |
104 #define ATTRIBUTE in\n\ | |
105 #define VARYING out\n"); | |
106 } else { | 104 } else { |
107 source += std::string("\ | 105 source += std::string("#version 300 es\n"); |
108 #define ATTRIBUTE attribute\n\ | |
109 #define VARYING varying\n"); | |
110 } | 106 } |
107 source += std::string( | |
108 "#define ATTRIBUTE in\n" | |
109 "#define VARYING out\n"); | |
111 | 110 |
112 // Preamble for texture precision. | 111 // Preamble for texture precision. |
113 source += std::string(kShaderPrecisionPreamble); | 112 source += std::string(kShaderPrecisionPreamble); |
114 | 113 |
115 // Main shader source. | 114 // Main shader source. |
116 source += std::string("\ | 115 source += std::string( |
117 uniform vec2 u_vertex_dest_mult;\n\ | 116 "uniform vec2 u_vertex_dest_mult;\n" |
118 uniform vec2 u_vertex_dest_add;\n\ | 117 "uniform vec2 u_vertex_dest_add;\n" |
119 uniform vec2 u_vertex_source_mult;\n\ | 118 "uniform vec2 u_vertex_source_mult;\n" |
120 uniform vec2 u_vertex_source_add;\n\ | 119 "uniform vec2 u_vertex_source_add;\n" |
121 ATTRIBUTE vec2 a_position;\n\ | 120 "ATTRIBUTE vec2 a_position;\n" |
122 VARYING TexCoordPrecision vec2 v_uv;\n\ | 121 "VARYING TexCoordPrecision vec2 v_uv;\n" |
123 void main(void) {\n\ | 122 "void main(void) {\n" |
124 gl_Position = vec4(0, 0, 0, 1);\n\ | 123 " gl_Position = vec4(0, 0, 0, 1);\n" |
125 gl_Position.xy = a_position.xy * u_vertex_dest_mult + \ | 124 " gl_Position.xy = a_position.xy * u_vertex_dest_mult + " |
126 u_vertex_dest_add;\n\ | 125 "u_vertex_dest_add;\n" |
127 v_uv = a_position.xy * u_vertex_source_mult + u_vertex_source_add;\n\ | 126 " v_uv = a_position.xy * u_vertex_source_mult + u_vertex_source_add;\n" |
128 }\n"); | 127 "}\n"); |
129 | 128 |
130 return source; | 129 return source; |
131 } | 130 } |
132 | 131 |
133 std::string GetFragmentShaderSource(const gl::GLVersionInfo& gl_version_info, | 132 std::string GetFragmentShaderSource(const gl::GLVersionInfo& gl_version_info, |
134 bool premultiply_alpha, | 133 bool premultiply_alpha, |
135 bool unpremultiply_alpha, | 134 bool unpremultiply_alpha, |
136 bool nv_egl_stream_consumer_external, | 135 bool nv_egl_stream_consumer_external, |
137 GLenum target) { | 136 GLenum target, |
137 GLenum source_format, | |
138 GLenum format) { | |
138 std::string source; | 139 std::string source; |
139 | 140 |
140 // Preamble for core and compatibility mode. | 141 // Preamble for core and compatibility mode. |
141 if (gl_version_info.is_desktop_core_profile) { | 142 if (gl_version_info.is_desktop_core_profile) { |
142 source += std::string("\ | 143 source += std::string("#version 150\n"); |
143 #version 150\n\ | |
144 out vec4 frag_color;\n\ | |
145 #define VARYING in\n\ | |
146 #define FRAGCOLOR frag_color\n\ | |
147 #define TextureLookup texture\n"); | |
148 } else { | 144 } else { |
149 switch (target) { | 145 source += std::string("#version 300 es\n"); |
150 case GL_TEXTURE_2D: | 146 if (target == GL_TEXTURE_EXTERNAL_OES) { |
151 source += std::string("#define TextureLookup texture2D\n"); | 147 source += std::string("#extension GL_OES_EGL_image_external : enable\n"); |
152 break; | |
153 case GL_TEXTURE_RECTANGLE_ARB: | |
154 source += std::string("#define TextureLookup texture2DRect\n"); | |
155 break; | |
156 case GL_TEXTURE_EXTERNAL_OES: | |
157 source += | |
158 std::string("#extension GL_OES_EGL_image_external : enable\n"); | |
159 | 148 |
160 if (nv_egl_stream_consumer_external) { | 149 if (nv_egl_stream_consumer_external) { |
161 source += std::string( | 150 source += std::string( |
162 "#extension GL_NV_EGL_stream_consumer_external : enable\n"); | 151 "#extension GL_NV_EGL_stream_consumer_external : enable\n"); |
163 } | 152 } |
153 } | |
154 } | |
164 | 155 |
165 source += std::string("#define TextureLookup texture2D\n"); | 156 // Preamble for texture precision. |
166 break; | 157 source += std::string(kShaderPrecisionPreamble); |
167 default: | 158 |
168 NOTREACHED(); | 159 if (gpu::gles2::GLES2Util::IsSignedIntegerFormat(format)) { |
169 break; | 160 source += std::string("#define TextureType ivec4\n"); |
161 if (gpu::gles2::GLES2Util::IsSignedIntegerFormat(source_format)) | |
162 source += std::string("#define InnerScaleValue 1\n"); | |
163 else if (gpu::gles2::GLES2Util::IsUnsignedIntegerFormat(source_format)) | |
164 source += std::string("#define InnerScaleValue 1u\n"); | |
165 else | |
166 source += std::string("#define InnerScaleValue 255.0\n"); | |
167 source += std::string("#define OuterScaleValue 1\n"); | |
168 } else if (gpu::gles2::GLES2Util::IsUnsignedIntegerFormat(format)) { | |
169 source += std::string("#define TextureType uvec4\n"); | |
170 if (gpu::gles2::GLES2Util::IsSignedIntegerFormat(source_format)) | |
171 source += std::string("#define InnerScaleValue 1\n"); | |
172 else if (gpu::gles2::GLES2Util::IsUnsignedIntegerFormat(source_format)) | |
173 source += std::string("#define InnerScaleValue 1u\n"); | |
174 else | |
175 source += std::string("#define InnerScaleValue 255.0\n"); | |
176 source += std::string("#define OuterScaleValue 1u\n"); | |
177 } else { | |
178 source += std::string("#define TextureType vec4\n"); | |
179 if (gpu::gles2::GLES2Util::IsSignedIntegerFormat(source_format)) { | |
180 source += std::string("#define InnerScaleValue 1\n"); | |
181 source += std::string("#define OuterScaleValue (1.0 / 255.0)\n"); | |
182 } else if (gpu::gles2::GLES2Util::IsUnsignedIntegerFormat(source_format)) { | |
183 source += std::string("#define InnerScaleValue 1u\n"); | |
184 source += std::string("#define OuterScaleValue (1.0 / 255.0)\n"); | |
185 } else { | |
186 source += std::string("#define InnerScaleValue 1.0\n"); | |
187 source += std::string("#define OuterScaleValue 1.0\n"); | |
170 } | 188 } |
171 source += std::string("\ | |
172 #define VARYING varying\n\ | |
173 #define FRAGCOLOR gl_FragColor\n"); | |
174 } | 189 } |
190 source += std::string( | |
191 "out TextureType frag_color;\n" | |
192 "#define VARYING in\n" | |
193 "#define FRAGCOLOR frag_color\n" | |
194 "#define TextureLookup texture\n"); | |
175 | 195 |
176 // Preamble for sampler type. | 196 // Preamble for sampler type. |
177 switch (target) { | 197 switch (target) { |
178 case GL_TEXTURE_2D: | 198 case GL_TEXTURE_2D: |
179 source += std::string("#define SamplerType sampler2D\n"); | 199 source += std::string("#define SamplerType sampler2D\n"); |
180 break; | 200 break; |
181 case GL_TEXTURE_RECTANGLE_ARB: | 201 case GL_TEXTURE_RECTANGLE_ARB: |
182 source += std::string("#define SamplerType sampler2DRect\n"); | 202 source += std::string("#define SamplerType sampler2DRect\n"); |
183 break; | 203 break; |
184 case GL_TEXTURE_EXTERNAL_OES: | 204 case GL_TEXTURE_EXTERNAL_OES: |
185 source += std::string("#define SamplerType samplerExternalOES\n"); | 205 source += std::string("#define SamplerType samplerExternalOES\n"); |
186 break; | 206 break; |
187 default: | 207 default: |
188 NOTREACHED(); | 208 NOTREACHED(); |
189 break; | 209 break; |
190 } | 210 } |
191 | 211 |
192 // Preamble for texture precision. | |
193 source += std::string(kShaderPrecisionPreamble); | |
194 | |
195 // Main shader source. | 212 // Main shader source. |
196 source += std::string("\ | 213 source += std::string( |
197 uniform SamplerType u_sampler;\n\ | 214 "uniform mediump SamplerType u_sampler;\n" |
198 uniform mat4 u_tex_coord_transform;\n\ | 215 "uniform mat4 u_tex_coord_transform;\n" |
199 VARYING TexCoordPrecision vec2 v_uv;\n\ | 216 "VARYING TexCoordPrecision vec2 v_uv;\n" |
200 void main(void) {\n\ | 217 "void main(void) {\n" |
201 TexCoordPrecision vec4 uv = u_tex_coord_transform * vec4(v_uv, 0, 1);\n\ | 218 " TexCoordPrecision vec4 uv = u_tex_coord_transform * vec4(v_uv, 0, " |
202 FRAGCOLOR = TextureLookup(u_sampler, uv.st);\n"); | 219 "1);\n" |
220 " vec4 color = TextureLookup(u_sampler, uv.st);\n" | |
221 " FRAGCOLOR = TextureType(color * InnerScaleValue) * " | |
222 "OuterScaleValue;\n"); | |
203 | 223 |
204 // Post-processing to premultiply or un-premultiply alpha. | 224 // Post-processing to premultiply or un-premultiply alpha. |
205 if (premultiply_alpha) { | 225 if (premultiply_alpha) { |
206 source += std::string(" FRAGCOLOR.rgb *= FRAGCOLOR.a;\n"); | 226 source += std::string("FRAGCOLOR.rgb *= FRAGCOLOR.a;\n"); |
207 } | 227 } |
208 if (unpremultiply_alpha) { | 228 if (unpremultiply_alpha) { |
209 source += std::string("\ | 229 source += std::string( |
210 if (FRAGCOLOR.a > 0.0)\n\ | 230 "if (FRAGCOLOR.a > 0.0)\n" |
211 FRAGCOLOR.rgb /= FRAGCOLOR.a;\n"); | 231 " FRAGCOLOR.rgb /= FRAGCOLOR.a;\n"); |
212 } | 232 } |
213 | 233 |
214 // Main function end. | 234 // Main function end. |
215 source += std::string(" }\n"); | 235 source += std::string("}\n"); |
216 | 236 |
217 return source; | 237 return source; |
218 } | 238 } |
219 | 239 |
240 GLenum getIntermediateFormat(GLenum format) { | |
241 switch (format) { | |
242 case GL_LUMINANCE_ALPHA: | |
243 case GL_LUMINANCE: | |
244 case GL_ALPHA: | |
245 case GL_R16F: | |
246 case GL_R32F: | |
247 case GL_RG16F: | |
248 case GL_RG32F: | |
249 case GL_R11F_G11F_B10F: | |
250 case GL_RGB9_E5: | |
251 case GL_RGB16F: | |
252 case GL_RGB32F: | |
253 case GL_RGBA16F: | |
254 case GL_RGBA32F: | |
255 return GL_RGBA; | |
256 case GL_SRGB8: | |
257 return GL_SRGB8_ALPHA8; | |
258 case GL_RGB8UI: | |
259 return GL_RGBA8UI; | |
260 default: | |
261 return format; | |
262 } | |
263 } | |
264 | |
220 void CompileShader(GLuint shader, const char* shader_source) { | 265 void CompileShader(GLuint shader, const char* shader_source) { |
221 glShaderSource(shader, 1, &shader_source, 0); | 266 glShaderSource(shader, 1, &shader_source, 0); |
222 glCompileShader(shader); | 267 glCompileShader(shader); |
223 #ifndef NDEBUG | 268 #ifndef NDEBUG |
224 GLint compile_status; | 269 GLint compile_status; |
225 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status); | 270 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status); |
226 if (GL_TRUE != compile_status) | 271 if (GL_TRUE != compile_status) { |
227 DLOG(ERROR) << "CopyTextureCHROMIUM: shader compilation failure."; | 272 DLOG(ERROR) << "CopyTextureCHROMIUM: shader compilation failure."; |
273 char buffer[1024]; | |
274 GLsizei length = 0; | |
275 glGetShaderInfoLog(shader, sizeof(buffer), &length, buffer); | |
276 std::string log(buffer, length); | |
277 } | |
228 #endif | 278 #endif |
229 } | 279 } |
230 | 280 |
231 void DeleteShader(GLuint shader) { | 281 void DeleteShader(GLuint shader) { |
232 if (shader) | 282 if (shader) |
233 glDeleteShader(shader); | 283 glDeleteShader(shader); |
234 } | 284 } |
235 | 285 |
236 bool BindFramebufferTexture2D(GLenum target, | 286 bool BindFramebufferTexture2D(GLenum target, |
237 GLuint texture_id, | 287 GLuint texture_id, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 GLenum source_target, | 462 GLenum source_target, |
413 GLuint source_id, | 463 GLuint source_id, |
414 GLenum source_internal_format, | 464 GLenum source_internal_format, |
415 GLenum dest_target, | 465 GLenum dest_target, |
416 GLuint dest_id, | 466 GLuint dest_id, |
417 GLenum dest_internal_format, | 467 GLenum dest_internal_format, |
418 GLsizei width, | 468 GLsizei width, |
419 GLsizei height, | 469 GLsizei height, |
420 bool flip_y, | 470 bool flip_y, |
421 bool premultiply_alpha, | 471 bool premultiply_alpha, |
422 bool unpremultiply_alpha) { | 472 bool unpremultiply_alpha, |
473 SupportedCopyMethodByFormat method) { | |
423 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 474 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
424 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | 475 |
425 // format does not contain a superset of the components required by the base | |
426 // format of internalformat. | |
427 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | |
428 bool source_format_contain_superset_of_dest_format = | |
429 (source_internal_format == dest_internal_format && | |
430 source_internal_format != GL_BGRA_EXT) || | |
431 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | |
432 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 476 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
433 // so restrict this to GL_TEXTURE_2D. | 477 // so restrict this to GL_TEXTURE_2D. |
434 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && | 478 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && |
435 !flip_y && !premultiply_alpha_change && | 479 !flip_y && !premultiply_alpha_change && method == DIRECT_COPY) { |
436 source_format_contain_superset_of_dest_format) { | |
437 DoCopyTexImage2D(decoder, | 480 DoCopyTexImage2D(decoder, |
438 source_target, | 481 source_target, |
439 source_id, | 482 source_id, |
440 dest_target, | 483 dest_target, |
441 dest_id, | 484 dest_id, |
442 dest_internal_format, | 485 dest_internal_format, |
443 width, | 486 width, |
444 height, | 487 height, |
445 framebuffer_); | 488 framebuffer_); |
446 return; | 489 return; |
447 } | 490 } |
448 | 491 |
492 GLenum adjusted_internal_format = getIntermediateFormat(dest_internal_format); | |
493 GLuint adjusted_texture = dest_id; | |
494 if (method == DRAW_AND_COPY) { | |
495 glGenTextures(1, &adjusted_texture); | |
496 glBindTexture(dest_target, adjusted_texture); | |
497 GLenum format = TextureManager::ExtractFormatFromStorageFormat( | |
498 adjusted_internal_format); | |
499 GLenum type = | |
500 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format); | |
501 | |
502 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0, | |
503 format, type, nullptr); | |
504 } | |
449 // Use kIdentityMatrix if no transform passed in. | 505 // Use kIdentityMatrix if no transform passed in. |
450 DoCopyTextureWithTransform(decoder, source_target, source_id, dest_target, | 506 DoCopyTextureWithTransform( |
451 dest_id, width, height, flip_y, premultiply_alpha, | 507 decoder, source_target, source_id, source_internal_format, dest_target, |
452 unpremultiply_alpha, kIdentityMatrix); | 508 adjusted_texture, adjusted_internal_format, width, height, flip_y, |
509 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); | |
510 | |
511 if (method == DRAW_AND_COPY) { | |
512 DoCopyTexImage2D(decoder, dest_target, adjusted_texture, dest_target, | |
513 dest_id, dest_internal_format, width, height, | |
514 framebuffer_); | |
515 } | |
453 } | 516 } |
454 | 517 |
455 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( | 518 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( |
456 const gles2::GLES2Decoder* decoder, | 519 const gles2::GLES2Decoder* decoder, |
457 GLenum source_target, | 520 GLenum source_target, |
458 GLuint source_id, | 521 GLuint source_id, |
459 GLenum source_internal_format, | 522 GLenum source_internal_format, |
460 GLenum dest_target, | 523 GLenum dest_target, |
461 GLuint dest_id, | 524 GLuint dest_id, |
462 GLenum dest_internal_format, | 525 GLenum dest_internal_format, |
463 GLint xoffset, | 526 GLint xoffset, |
464 GLint yoffset, | 527 GLint yoffset, |
465 GLint x, | 528 GLint x, |
466 GLint y, | 529 GLint y, |
467 GLsizei width, | 530 GLsizei width, |
468 GLsizei height, | 531 GLsizei height, |
469 GLsizei dest_width, | 532 GLsizei dest_width, |
470 GLsizei dest_height, | 533 GLsizei dest_height, |
471 GLsizei source_width, | 534 GLsizei source_width, |
472 GLsizei source_height, | 535 GLsizei source_height, |
473 bool flip_y, | 536 bool flip_y, |
474 bool premultiply_alpha, | 537 bool premultiply_alpha, |
475 bool unpremultiply_alpha) { | 538 bool unpremultiply_alpha, |
539 SupportedCopyMethodByFormat method) { | |
476 bool use_gl_copy_tex_sub_image_2d = true; | 540 bool use_gl_copy_tex_sub_image_2d = true; |
477 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 541 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
478 // glDrawArrays is faster than glCopyTexSubImage2D on IA Mesa driver, | 542 // glDrawArrays is faster than glCopyTexSubImage2D on IA Mesa driver, |
479 // although opposite in Android. | 543 // although opposite in Android. |
480 // TODO(dshwang): After Mesa fixes this issue, remove this hack. | 544 // TODO(dshwang): After Mesa fixes this issue, remove this hack. |
481 // https://bugs.freedesktop.org/show_bug.cgi?id=98478 crbug.com/535198 | 545 // https://bugs.freedesktop.org/show_bug.cgi?id=98478 crbug.com/535198 |
482 use_gl_copy_tex_sub_image_2d = false; | 546 use_gl_copy_tex_sub_image_2d = false; |
483 #endif | 547 #endif |
484 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 548 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
485 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | 549 |
486 // format does not contain a superset of the components required by the base | |
487 // format of internalformat. | |
488 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | |
489 bool source_format_contain_superset_of_dest_format = | |
490 (source_internal_format == dest_internal_format && | |
491 source_internal_format != GL_BGRA_EXT) || | |
492 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | |
493 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 550 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
494 // so restrict this to GL_TEXTURE_2D. | 551 // so restrict this to GL_TEXTURE_2D. |
495 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && | 552 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && |
496 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && | 553 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && |
497 source_format_contain_superset_of_dest_format) { | 554 method == DIRECT_COPY) { |
498 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id, | 555 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id, |
499 xoffset, yoffset, x, y, width, height, framebuffer_); | 556 xoffset, yoffset, x, y, width, height, framebuffer_); |
500 return; | 557 return; |
501 } | 558 } |
502 | 559 |
503 DoCopySubTextureWithTransform( | 560 DoCopySubTextureWithTransform( |
504 decoder, source_target, source_id, source_internal_format, dest_target, | 561 decoder, source_target, source_id, source_internal_format, dest_target, |
505 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, | 562 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, |
506 dest_width, dest_height, source_width, source_height, flip_y, | 563 dest_width, dest_height, source_width, source_height, flip_y, |
507 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); | 564 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); |
(...skipping 14 matching lines...) Expand all Loading... | |
522 GLsizei width, | 579 GLsizei width, |
523 GLsizei height, | 580 GLsizei height, |
524 GLsizei dest_width, | 581 GLsizei dest_width, |
525 GLsizei dest_height, | 582 GLsizei dest_height, |
526 GLsizei source_width, | 583 GLsizei source_width, |
527 GLsizei source_height, | 584 GLsizei source_height, |
528 bool flip_y, | 585 bool flip_y, |
529 bool premultiply_alpha, | 586 bool premultiply_alpha, |
530 bool unpremultiply_alpha, | 587 bool unpremultiply_alpha, |
531 const GLfloat transform_matrix[16]) { | 588 const GLfloat transform_matrix[16]) { |
532 DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id, | 589 DoCopyTextureInternal( |
533 xoffset, yoffset, x, y, width, height, dest_width, dest_height, | 590 decoder, source_target, source_id, source_internal_format, dest_target, |
534 source_width, source_height, flip_y, premultiply_alpha, | 591 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, |
535 unpremultiply_alpha, transform_matrix); | 592 dest_width, dest_height, source_width, source_height, flip_y, |
593 premultiply_alpha, unpremultiply_alpha, transform_matrix); | |
536 } | 594 } |
537 | 595 |
538 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( | 596 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( |
539 const gles2::GLES2Decoder* decoder, | 597 const gles2::GLES2Decoder* decoder, |
540 GLenum source_target, | 598 GLenum source_target, |
541 GLuint source_id, | 599 GLuint source_id, |
600 GLenum source_format, | |
542 GLenum dest_target, | 601 GLenum dest_target, |
543 GLuint dest_id, | 602 GLuint dest_id, |
603 GLenum dest_format, | |
544 GLsizei width, | 604 GLsizei width, |
545 GLsizei height, | 605 GLsizei height, |
546 bool flip_y, | 606 bool flip_y, |
547 bool premultiply_alpha, | 607 bool premultiply_alpha, |
548 bool unpremultiply_alpha, | 608 bool unpremultiply_alpha, |
549 const GLfloat transform_matrix[16]) { | 609 const GLfloat transform_matrix[16]) { |
550 GLsizei dest_width = width; | 610 GLsizei dest_width = width; |
551 GLsizei dest_height = height; | 611 GLsizei dest_height = height; |
552 DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id, | 612 DoCopyTextureInternal( |
553 0, 0, 0, 0, width, height, dest_width, dest_height, | 613 decoder, source_target, source_id, source_format, dest_target, dest_id, |
554 width, height, flip_y, premultiply_alpha, | 614 dest_format, 0, 0, 0, 0, width, height, dest_width, dest_height, width, |
555 unpremultiply_alpha, transform_matrix); | 615 height, flip_y, premultiply_alpha, unpremultiply_alpha, transform_matrix); |
556 } | 616 } |
557 | 617 |
558 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( | 618 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( |
559 const gles2::GLES2Decoder* decoder, | 619 const gles2::GLES2Decoder* decoder, |
560 GLenum source_target, | 620 GLenum source_target, |
561 GLuint source_id, | 621 GLuint source_id, |
622 GLenum source_format, | |
562 GLenum dest_target, | 623 GLenum dest_target, |
563 GLuint dest_id, | 624 GLuint dest_id, |
625 GLenum dest_format, | |
564 GLint xoffset, | 626 GLint xoffset, |
565 GLint yoffset, | 627 GLint yoffset, |
566 GLint x, | 628 GLint x, |
567 GLint y, | 629 GLint y, |
568 GLsizei width, | 630 GLsizei width, |
569 GLsizei height, | 631 GLsizei height, |
570 GLsizei dest_width, | 632 GLsizei dest_width, |
571 GLsizei dest_height, | 633 GLsizei dest_height, |
572 GLsizei source_width, | 634 GLsizei source_width, |
573 GLsizei source_height, | 635 GLsizei source_height, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 vertex_shader_ = glCreateShader(GL_VERTEX_SHADER); | 682 vertex_shader_ = glCreateShader(GL_VERTEX_SHADER); |
621 std::string source = GetVertexShaderSource(gl_version_info); | 683 std::string source = GetVertexShaderSource(gl_version_info); |
622 CompileShader(vertex_shader_, source.c_str()); | 684 CompileShader(vertex_shader_, source.c_str()); |
623 } | 685 } |
624 glAttachShader(info->program, vertex_shader_); | 686 glAttachShader(info->program, vertex_shader_); |
625 GLuint* fragment_shader = &fragment_shaders_[fragment_shader_id]; | 687 GLuint* fragment_shader = &fragment_shaders_[fragment_shader_id]; |
626 if (!*fragment_shader) { | 688 if (!*fragment_shader) { |
627 *fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); | 689 *fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); |
628 std::string source = GetFragmentShaderSource( | 690 std::string source = GetFragmentShaderSource( |
629 gl_version_info, premultiply_alpha, unpremultiply_alpha, | 691 gl_version_info, premultiply_alpha, unpremultiply_alpha, |
630 nv_egl_stream_consumer_external_, source_target); | 692 nv_egl_stream_consumer_external_, source_target, source_format, |
693 dest_format); | |
631 CompileShader(*fragment_shader, source.c_str()); | 694 CompileShader(*fragment_shader, source.c_str()); |
632 } | 695 } |
633 glAttachShader(info->program, *fragment_shader); | 696 glAttachShader(info->program, *fragment_shader); |
634 glBindAttribLocation(info->program, kVertexPositionAttrib, "a_position"); | 697 glBindAttribLocation(info->program, kVertexPositionAttrib, "a_position"); |
635 glLinkProgram(info->program); | 698 glLinkProgram(info->program); |
636 #ifndef NDEBUG | 699 #ifndef NDEBUG |
637 GLint linked; | 700 GLint linked; |
638 glGetProgramiv(info->program, GL_LINK_STATUS, &linked); | 701 glGetProgramiv(info->program, GL_LINK_STATUS, &linked); |
639 if (!linked) | 702 if (!linked) |
640 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure."; | 703 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure."; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 decoder->RestoreTextureUnitBindings(0); | 834 decoder->RestoreTextureUnitBindings(0); |
772 decoder->RestoreActiveTexture(); | 835 decoder->RestoreActiveTexture(); |
773 decoder->RestoreProgramBindings(); | 836 decoder->RestoreProgramBindings(); |
774 decoder->RestoreBufferBindings(); | 837 decoder->RestoreBufferBindings(); |
775 decoder->RestoreFramebufferBindings(); | 838 decoder->RestoreFramebufferBindings(); |
776 decoder->RestoreGlobalState(); | 839 decoder->RestoreGlobalState(); |
777 } | 840 } |
778 | 841 |
779 } // namespace gles2 | 842 } // namespace gles2 |
780 } // namespace gpu | 843 } // namespace gpu |
OLD | NEW |