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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "gpu/command_buffer/service/gl_utils.h" | 10 #include "gpu/command_buffer/service/gl_utils.h" |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | 422 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); |
423 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 423 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
424 // so restrict this to GL_TEXTURE_2D. | 424 // so restrict this to GL_TEXTURE_2D. |
425 if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && | 425 if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && |
426 source_format_contain_superset_of_dest_format) { | 426 source_format_contain_superset_of_dest_format) { |
427 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_id, xoffset, | 427 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_id, xoffset, |
428 yoffset, x, y, width, height, framebuffer_); | 428 yoffset, x, y, width, height, framebuffer_); |
429 return; | 429 return; |
430 } | 430 } |
431 | 431 |
432 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, xoffset - x, | 432 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, xoffset, |
433 yoffset - y, dest_width, dest_height, source_width, | 433 yoffset, x, y, width, height, dest_width, dest_height, |
434 source_height, flip_y, premultiply_alpha, | 434 source_width, source_height, flip_y, premultiply_alpha, |
435 unpremultiply_alpha, kIdentityMatrix, xoffset, yoffset, | 435 unpremultiply_alpha, kIdentityMatrix); |
436 width, height); | |
437 } | 436 } |
438 | 437 |
439 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( | 438 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( |
440 const gles2::GLES2Decoder* decoder, | 439 const gles2::GLES2Decoder* decoder, |
441 GLenum source_target, | 440 GLenum source_target, |
442 GLuint source_id, | 441 GLuint source_id, |
443 GLuint dest_id, | 442 GLuint dest_id, |
444 GLsizei width, | 443 GLsizei width, |
445 GLsizei height, | 444 GLsizei height, |
446 bool flip_y, | 445 bool flip_y, |
447 bool premultiply_alpha, | 446 bool premultiply_alpha, |
448 bool unpremultiply_alpha, | 447 bool unpremultiply_alpha, |
449 const GLfloat transform_matrix[16]) { | 448 const GLfloat transform_matrix[16]) { |
450 GLsizei dest_width = width; | 449 GLsizei dest_width = width; |
451 GLsizei dest_height = height; | 450 GLsizei dest_height = height; |
452 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, 0, 0, | 451 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, 0, 0, 0, 0, |
453 dest_width, dest_height, width, height, flip_y, | 452 width, height, dest_width, dest_height, width, height, |
454 premultiply_alpha, unpremultiply_alpha, | 453 flip_y, premultiply_alpha, unpremultiply_alpha, |
455 transform_matrix, 0, 0, dest_width, dest_height); | 454 transform_matrix); |
456 } | 455 } |
457 | 456 |
458 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( | 457 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( |
459 const gles2::GLES2Decoder* decoder, | 458 const gles2::GLES2Decoder* decoder, |
460 GLenum source_target, | 459 GLenum source_target, |
461 GLuint source_id, | 460 GLuint source_id, |
462 GLuint dest_id, | 461 GLuint dest_id, |
463 GLint xoffset, | 462 GLint xoffset, |
464 GLint yoffset, | 463 GLint yoffset, |
| 464 GLint x, |
| 465 GLint y, |
| 466 GLsizei width, |
| 467 GLsizei height, |
465 GLsizei dest_width, | 468 GLsizei dest_width, |
466 GLsizei dest_height, | 469 GLsizei dest_height, |
467 GLsizei source_width, | 470 GLsizei source_width, |
468 GLsizei source_height, | 471 GLsizei source_height, |
469 bool flip_y, | 472 bool flip_y, |
470 bool premultiply_alpha, | 473 bool premultiply_alpha, |
471 bool unpremultiply_alpha, | 474 bool unpremultiply_alpha, |
472 const GLfloat transform_matrix[16], | 475 const GLfloat transform_matrix[16]) { |
473 GLint scissor_x, | |
474 GLint scissor_y, | |
475 GLsizei scissor_width, | |
476 GLsizei scissor_height) { | |
477 DCHECK(source_target == GL_TEXTURE_2D || | 476 DCHECK(source_target == GL_TEXTURE_2D || |
478 source_target == GL_TEXTURE_RECTANGLE_ARB || | 477 source_target == GL_TEXTURE_RECTANGLE_ARB || |
479 source_target == GL_TEXTURE_EXTERNAL_OES); | 478 source_target == GL_TEXTURE_EXTERNAL_OES); |
480 DCHECK(xoffset >= 0 && xoffset + source_width <= dest_width); | 479 DCHECK(xoffset >= 0 && xoffset + source_width <= dest_width); |
481 DCHECK(yoffset >= 0 && yoffset + source_height <= dest_height); | 480 DCHECK(yoffset >= 0 && yoffset + source_height <= dest_height); |
482 if (!initialized_) { | 481 if (!initialized_) { |
483 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; | 482 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; |
484 return; | 483 return; |
485 } | 484 } |
486 | 485 |
(...skipping 28 matching lines...) Expand all Loading... |
515 glGetProgramiv(info->program, GL_LINK_STATUS, &linked); | 514 glGetProgramiv(info->program, GL_LINK_STATUS, &linked); |
516 if (!linked) | 515 if (!linked) |
517 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure."; | 516 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure."; |
518 #endif | 517 #endif |
519 info->matrix_handle = glGetUniformLocation(info->program, "u_matrix"); | 518 info->matrix_handle = glGetUniformLocation(info->program, "u_matrix"); |
520 info->half_size_handle = glGetUniformLocation(info->program, "u_half_size"); | 519 info->half_size_handle = glGetUniformLocation(info->program, "u_half_size"); |
521 info->sampler_handle = glGetUniformLocation(info->program, "u_sampler"); | 520 info->sampler_handle = glGetUniformLocation(info->program, "u_sampler"); |
522 } | 521 } |
523 glUseProgram(info->program); | 522 glUseProgram(info->program); |
524 | 523 |
525 if (!xoffset && !yoffset) { | 524 GLint x_translate = xoffset - x; |
| 525 GLint y_translate = yoffset - y; |
| 526 if (!x_translate && !y_translate) { |
526 glUniformMatrix4fv(info->matrix_handle, 1, GL_FALSE, transform_matrix); | 527 glUniformMatrix4fv(info->matrix_handle, 1, GL_FALSE, transform_matrix); |
527 } else { | 528 } else { |
528 // transform offsets from ([0, dest_width], [0, dest_height]) coord. | 529 // transform offsets from ([0, dest_width], [0, dest_height]) coord. |
529 // to ([-1, 1], [-1, 1]) coord. | 530 // to ([-1, 1], [-1, 1]) coord. |
530 GLfloat xoffset_on_vertex = ((2.f * xoffset) / dest_width); | 531 GLfloat x_translate_on_vertex = ((2.f * x_translate) / dest_width); |
531 GLfloat yoffset_on_vertex = ((2.f * yoffset) / dest_height); | 532 GLfloat y_translate_on_vertex = ((2.f * y_translate) / dest_height); |
532 | 533 |
533 // Pass view_matrix * offset_matrix to the program. | 534 // Pass view_matrix * offset_matrix to the program. |
534 GLfloat view_transform[16]; | 535 GLfloat view_transform[16]; |
535 memcpy(view_transform, transform_matrix, 16 * sizeof(GLfloat)); | 536 memcpy(view_transform, transform_matrix, 16 * sizeof(GLfloat)); |
536 PreTranslate(view_transform, xoffset_on_vertex, yoffset_on_vertex, 0); | 537 PreTranslate(view_transform, x_translate_on_vertex, y_translate_on_vertex, |
| 538 0); |
537 glUniformMatrix4fv(info->matrix_handle, 1, GL_FALSE, view_transform); | 539 glUniformMatrix4fv(info->matrix_handle, 1, GL_FALSE, view_transform); |
538 } | 540 } |
539 if (source_target == GL_TEXTURE_RECTANGLE_ARB) | 541 if (source_target == GL_TEXTURE_RECTANGLE_ARB) |
540 glUniform2f(info->half_size_handle, source_width / 2.0f, | 542 glUniform2f(info->half_size_handle, source_width / 2.0f, |
541 source_height / 2.0f); | 543 source_height / 2.0f); |
542 else | 544 else |
543 glUniform2f(info->half_size_handle, 0.5f, 0.5f); | 545 glUniform2f(info->half_size_handle, 0.5f, 0.5f); |
544 | 546 |
545 if (BindFramebufferTexture2D(GL_TEXTURE_2D, dest_id, framebuffer_)) { | 547 if (BindFramebufferTexture2D(GL_TEXTURE_2D, dest_id, framebuffer_)) { |
546 #ifndef NDEBUG | 548 #ifndef NDEBUG |
(...skipping 21 matching lines...) Expand all Loading... |
568 glTexParameteri(source_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 570 glTexParameteri(source_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
569 glTexParameteri(source_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 571 glTexParameteri(source_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
570 | 572 |
571 glDisable(GL_DEPTH_TEST); | 573 glDisable(GL_DEPTH_TEST); |
572 glDisable(GL_STENCIL_TEST); | 574 glDisable(GL_STENCIL_TEST); |
573 glDisable(GL_CULL_FACE); | 575 glDisable(GL_CULL_FACE); |
574 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 576 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
575 glDepthMask(GL_FALSE); | 577 glDepthMask(GL_FALSE); |
576 glDisable(GL_BLEND); | 578 glDisable(GL_BLEND); |
577 | 579 |
578 glEnable(GL_SCISSOR_TEST); | 580 bool need_scissor = |
579 glScissor(scissor_x, scissor_y, scissor_width, scissor_height); | 581 xoffset || yoffset || width != dest_width || height != dest_height; |
| 582 if (need_scissor) { |
| 583 glEnable(GL_SCISSOR_TEST); |
| 584 glScissor(xoffset, yoffset, width, height); |
| 585 } |
580 glViewport(0, 0, dest_width, dest_height); | 586 glViewport(0, 0, dest_width, dest_height); |
581 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 587 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
582 } | 588 } |
583 | 589 |
584 decoder->RestoreAllAttributes(); | 590 decoder->RestoreAllAttributes(); |
585 decoder->RestoreTextureState(source_id); | 591 decoder->RestoreTextureState(source_id); |
586 decoder->RestoreTextureState(dest_id); | 592 decoder->RestoreTextureState(dest_id); |
587 decoder->RestoreTextureUnitBindings(0); | 593 decoder->RestoreTextureUnitBindings(0); |
588 decoder->RestoreActiveTexture(); | 594 decoder->RestoreActiveTexture(); |
589 decoder->RestoreProgramBindings(); | 595 decoder->RestoreProgramBindings(); |
590 decoder->RestoreBufferBindings(); | 596 decoder->RestoreBufferBindings(); |
591 decoder->RestoreFramebufferBindings(); | 597 decoder->RestoreFramebufferBindings(); |
592 decoder->RestoreGlobalState(); | 598 decoder->RestoreGlobalState(); |
593 } | 599 } |
594 | 600 |
595 } // namespace gpu | 601 } // namespace gpu |
OLD | NEW |