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 matrix; | |
greggman
2013/04/08 17:29:47
nit: we've tried to have uniforms start with u_, v
hkuang
2013/04/09 00:49:54
Good style that I need to follow. I did not notice
| |
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 = 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 GLenum source_target, | 307 GLenum source_target, |
307 GLenum dest_target, | 308 GLenum dest_target, |
308 GLuint source_id, | 309 GLuint source_id, |
309 GLuint dest_id, | 310 GLuint dest_id, |
310 GLint level, | 311 GLint level, |
311 GLsizei width, | 312 GLsizei width, |
312 GLsizei height, | 313 GLsizei height, |
313 bool flip_y, | 314 bool flip_y, |
314 bool premultiply_alpha, | 315 bool premultiply_alpha, |
315 bool unpremultiply_alpha) { | 316 bool unpremultiply_alpha) { |
317 // Use default transform matrix if no transform passed in. | |
318 const GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, | |
greggman
2013/04/08 17:29:47
any reason not to make this static? Otherwise code
hkuang
2013/04/09 00:49:54
No reason that I do not make it static.
Done.
On
| |
319 0.0f, 1.0f, 0.0f, 0.0f, | |
320 0.0f, 0.0f, 1.0f, 0.0f, | |
321 0.0f, 0.0f, 0.0f, 1.0f}; | |
322 DoCopyTextureWithTransform(decoder, source_target, dest_target, source_id, | |
323 dest_id, level, width, height, flip_y, premultiply_alpha, | |
324 unpremultiply_alpha, default_matrix); | |
325 } | |
326 | |
327 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( | |
328 const gles2::GLES2Decoder* decoder, | |
329 GLenum source_target, | |
330 GLenum dest_target, | |
331 GLuint source_id, | |
332 GLuint dest_id, | |
333 GLint level, | |
334 GLsizei width, | |
335 GLsizei height, | |
336 bool flip_y, | |
337 bool premultiply_alpha, | |
338 bool unpremultiply_alpha, | |
339 const GLfloat transform_matrix[16]) { | |
316 DCHECK(source_target == GL_TEXTURE_2D || | 340 DCHECK(source_target == GL_TEXTURE_2D || |
317 source_target == GL_TEXTURE_EXTERNAL_OES); | 341 source_target == GL_TEXTURE_EXTERNAL_OES); |
318 if (!initialized_) { | 342 if (!initialized_) { |
319 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; | 343 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; |
320 return; | 344 return; |
321 } | 345 } |
322 | 346 |
323 GLuint program = GetProgram( | 347 GLuint program = GetProgram( |
324 flip_y, premultiply_alpha, unpremultiply_alpha, | 348 flip_y, premultiply_alpha, unpremultiply_alpha, |
325 source_target == GL_TEXTURE_EXTERNAL_OES); | 349 source_target == GL_TEXTURE_EXTERNAL_OES); |
326 glUseProgram(programs_[program]); | 350 glUseProgram(programs_[program]); |
327 | 351 |
328 #ifndef NDEBUG | 352 #ifndef NDEBUG |
329 glValidateProgram(programs_[program]); | 353 glValidateProgram(programs_[program]); |
330 GLint validation_status; | 354 GLint validation_status; |
331 glGetProgramiv(programs_[program], GL_VALIDATE_STATUS, &validation_status); | 355 glGetProgramiv(programs_[program], GL_VALIDATE_STATUS, &validation_status); |
332 if (GL_TRUE != validation_status) { | 356 if (GL_TRUE != validation_status) { |
333 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader."; | 357 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader."; |
334 return; | 358 return; |
335 } | 359 } |
336 #endif | 360 #endif |
337 | 361 |
362 GLuint matrix_handle_ = glGetUniformLocation(programs_[program], "matrix"); | |
greggman
2013/04/08 17:29:47
Looking up uniforms is slow. this should happen at
hkuang
2013/04/09 00:49:54
Done.
| |
363 glUniformMatrix4fv(matrix_handle_, 1, GL_FALSE, transform_matrix); | |
338 glActiveTexture(GL_TEXTURE0); | 364 glActiveTexture(GL_TEXTURE0); |
339 glBindTexture(GL_TEXTURE_2D, dest_id); | 365 glBindTexture(GL_TEXTURE_2D, dest_id); |
340 // NVidia drivers require texture settings to be a certain way | 366 // NVidia drivers require texture settings to be a certain way |
341 // or they won't report FRAMEBUFFER_COMPLETE. | 367 // or they won't report FRAMEBUFFER_COMPLETE. |
342 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 368 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); | 369 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 370 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 371 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
346 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_); | 372 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_); |
347 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dest_target, | 373 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); | 412 decoder->RestoreTextureState(dest_id); |
387 decoder->RestoreActiveTexture(); | 413 decoder->RestoreActiveTexture(); |
388 decoder->RestoreProgramBindings(); | 414 decoder->RestoreProgramBindings(); |
389 decoder->RestoreBufferBindings(); | 415 decoder->RestoreBufferBindings(); |
390 decoder->RestoreFramebufferBindings(); | 416 decoder->RestoreFramebufferBindings(); |
391 decoder->RestoreGlobalState(); | 417 decoder->RestoreGlobalState(); |
392 } | 418 } |
393 | 419 |
394 } // namespace | 420 } // namespace |
395 | 421 |
OLD | NEW |