| 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 <string.h> | 7 #include <string.h> |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "gpu/command_buffer/common/types.h" | 9 #include "gpu/command_buffer/common/types.h" |
| 10 #include "gpu/command_buffer/service/gl_utils.h" | 10 #include "gpu/command_buffer/service/gl_utils.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 struct ShaderInfo { | 49 struct ShaderInfo { |
| 50 bool needs_egl_image_external; | 50 bool needs_egl_image_external; |
| 51 const char* source; | 51 const char* source; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 const ShaderInfo shader_infos[] = { | 54 const ShaderInfo shader_infos[] = { |
| 55 // VERTEX_SHADER_POS_TEX | 55 // VERTEX_SHADER_POS_TEX |
| 56 SHADER( | 56 SHADER( |
| 57 uniform mat4 u_matrix; |
| 57 attribute vec4 a_position; | 58 attribute vec4 a_position; |
| 58 varying vec2 v_uv; | 59 varying vec2 v_uv; |
| 59 void main(void) { | 60 void main(void) { |
| 60 gl_Position = a_position; | 61 gl_Position = u_matrix * a_position; |
| 61 v_uv = a_position.xy * 0.5 + vec2(0.5, 0.5); | 62 v_uv = a_position.xy * 0.5 + vec2(0.5, 0.5); |
| 62 }), | 63 }), |
| 63 // FRAGMENT_SHADER_TEX | 64 // FRAGMENT_SHADER_TEX |
| 64 SHADER( | 65 SHADER( |
| 65 uniform sampler2D u_texSampler; | 66 uniform sampler2D u_texSampler; |
| 66 varying vec2 v_uv; | 67 varying vec2 v_uv; |
| 67 void main(void) { | 68 void main(void) { |
| 68 gl_FragColor = texture2D(u_texSampler, v_uv.st); | 69 gl_FragColor = texture2D(u_texSampler, v_uv.st); |
| 69 }), | 70 }), |
| 70 // FRAGMENT_SHADER_TEX_FLIP_Y | 71 // FRAGMENT_SHADER_TEX_FLIP_Y |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 glLinkProgram(programs_[program]); | 273 glLinkProgram(programs_[program]); |
| 273 #ifndef NDEBUG | 274 #ifndef NDEBUG |
| 274 GLint linked; | 275 GLint linked; |
| 275 glGetProgramiv(programs_[program], GL_LINK_STATUS, &linked); | 276 glGetProgramiv(programs_[program], GL_LINK_STATUS, &linked); |
| 276 if (!linked) | 277 if (!linked) |
| 277 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure."; | 278 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure."; |
| 278 #endif | 279 #endif |
| 279 | 280 |
| 280 sampler_locations_[program] = glGetUniformLocation(programs_[program], | 281 sampler_locations_[program] = glGetUniformLocation(programs_[program], |
| 281 "u_texSampler"); | 282 "u_texSampler"); |
| 283 |
| 284 matrix_handle_[program] = glGetUniformLocation(programs_[program], |
| 285 "u_matrix"); |
| 282 } | 286 } |
| 283 | 287 |
| 284 for (int shader = 0; shader < kNumShaders; ++shader) | 288 for (int shader = 0; shader < kNumShaders; ++shader) |
| 285 glDeleteShader(shaders[shader]); | 289 glDeleteShader(shaders[shader]); |
| 286 | 290 |
| 287 decoder->RestoreBufferBindings(); | 291 decoder->RestoreBufferBindings(); |
| 288 | 292 |
| 289 initialized_ = true; | 293 initialized_ = true; |
| 290 } | 294 } |
| 291 | 295 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 306 GLenum source_target, | 310 GLenum source_target, |
| 307 GLenum dest_target, | 311 GLenum dest_target, |
| 308 GLuint source_id, | 312 GLuint source_id, |
| 309 GLuint dest_id, | 313 GLuint dest_id, |
| 310 GLint level, | 314 GLint level, |
| 311 GLsizei width, | 315 GLsizei width, |
| 312 GLsizei height, | 316 GLsizei height, |
| 313 bool flip_y, | 317 bool flip_y, |
| 314 bool premultiply_alpha, | 318 bool premultiply_alpha, |
| 315 bool unpremultiply_alpha) { | 319 bool unpremultiply_alpha) { |
| 320 // Use default transform matrix if no transform passed in. |
| 321 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
| 322 0.0f, 1.0f, 0.0f, 0.0f, |
| 323 0.0f, 0.0f, 1.0f, 0.0f, |
| 324 0.0f, 0.0f, 0.0f, 1.0f}; |
| 325 DoCopyTextureWithTransform(decoder, source_target, dest_target, source_id, |
| 326 dest_id, level, width, height, flip_y, premultiply_alpha, |
| 327 unpremultiply_alpha, default_matrix); |
| 328 } |
| 329 |
| 330 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( |
| 331 const gles2::GLES2Decoder* decoder, |
| 332 GLenum source_target, |
| 333 GLenum dest_target, |
| 334 GLuint source_id, |
| 335 GLuint dest_id, |
| 336 GLint level, |
| 337 GLsizei width, |
| 338 GLsizei height, |
| 339 bool flip_y, |
| 340 bool premultiply_alpha, |
| 341 bool unpremultiply_alpha, |
| 342 const GLfloat transform_matrix[16]) { |
| 316 DCHECK(source_target == GL_TEXTURE_2D || | 343 DCHECK(source_target == GL_TEXTURE_2D || |
| 317 source_target == GL_TEXTURE_EXTERNAL_OES); | 344 source_target == GL_TEXTURE_EXTERNAL_OES); |
| 318 if (!initialized_) { | 345 if (!initialized_) { |
| 319 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; | 346 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; |
| 320 return; | 347 return; |
| 321 } | 348 } |
| 322 | 349 |
| 323 GLuint program = GetProgram( | 350 GLuint program = GetProgram( |
| 324 flip_y, premultiply_alpha, unpremultiply_alpha, | 351 flip_y, premultiply_alpha, unpremultiply_alpha, |
| 325 source_target == GL_TEXTURE_EXTERNAL_OES); | 352 source_target == GL_TEXTURE_EXTERNAL_OES); |
| 326 glUseProgram(programs_[program]); | 353 glUseProgram(programs_[program]); |
| 327 | 354 |
| 328 #ifndef NDEBUG | 355 #ifndef NDEBUG |
| 329 glValidateProgram(programs_[program]); | 356 glValidateProgram(programs_[program]); |
| 330 GLint validation_status; | 357 GLint validation_status; |
| 331 glGetProgramiv(programs_[program], GL_VALIDATE_STATUS, &validation_status); | 358 glGetProgramiv(programs_[program], GL_VALIDATE_STATUS, &validation_status); |
| 332 if (GL_TRUE != validation_status) { | 359 if (GL_TRUE != validation_status) { |
| 333 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader."; | 360 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader."; |
| 334 return; | 361 return; |
| 335 } | 362 } |
| 336 #endif | 363 #endif |
| 337 | 364 |
| 365 glUniformMatrix4fv(matrix_handle_[program], 1, GL_FALSE, transform_matrix); |
| 338 glActiveTexture(GL_TEXTURE0); | 366 glActiveTexture(GL_TEXTURE0); |
| 339 glBindTexture(GL_TEXTURE_2D, dest_id); | 367 glBindTexture(GL_TEXTURE_2D, dest_id); |
| 340 // NVidia drivers require texture settings to be a certain way | 368 // NVidia drivers require texture settings to be a certain way |
| 341 // or they won't report FRAMEBUFFER_COMPLETE. | 369 // or they won't report FRAMEBUFFER_COMPLETE. |
| 342 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 370 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 343 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 371 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 372 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 346 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_); | 374 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_); |
| 347 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dest_target, | 375 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dest_target, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 decoder->RestoreTextureState(dest_id); | 414 decoder->RestoreTextureState(dest_id); |
| 387 decoder->RestoreActiveTexture(); | 415 decoder->RestoreActiveTexture(); |
| 388 decoder->RestoreProgramBindings(); | 416 decoder->RestoreProgramBindings(); |
| 389 decoder->RestoreBufferBindings(); | 417 decoder->RestoreBufferBindings(); |
| 390 decoder->RestoreFramebufferBindings(); | 418 decoder->RestoreFramebufferBindings(); |
| 391 decoder->RestoreGlobalState(); | 419 decoder->RestoreGlobalState(); |
| 392 } | 420 } |
| 393 | 421 |
| 394 } // namespace | 422 } // namespace |
| 395 | 423 |
| OLD | NEW |