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 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 source_x, source_y, source_width, source_height); | 312 source_x, source_y, source_width, source_height); |
313 } | 313 } |
314 | 314 |
315 decoder->RestoreTextureState(source_id); | 315 decoder->RestoreTextureState(source_id); |
316 decoder->RestoreTextureState(dest_id); | 316 decoder->RestoreTextureState(dest_id); |
317 decoder->RestoreTextureUnitBindings(0); | 317 decoder->RestoreTextureUnitBindings(0); |
318 decoder->RestoreActiveTexture(); | 318 decoder->RestoreActiveTexture(); |
319 decoder->RestoreFramebufferBindings(); | 319 decoder->RestoreFramebufferBindings(); |
320 } | 320 } |
321 | 321 |
322 GLenum UnsizedFormatFrom(GLenum internal_format) { | |
323 switch (internal_format) { | |
324 case GL_RGB: | |
325 case GL_RGB8: | |
326 return GL_RGB; | |
327 case GL_RGBA: | |
328 case GL_RGBA8: | |
329 return GL_RGBA; | |
330 case GL_BGRA_EXT: | |
331 case GL_BGRA8_EXT: | |
332 return GL_BGRA_EXT; | |
333 default: | |
334 NOTREACHED(); | |
piman
2016/11/01 19:04:59
I think this needs to be expanded to more formats.
dshwang
2016/11/01 19:30:05
exactly, this DCHECK causes crash. Done.
dshwang
2016/11/01 19:35:17
I gave up this non-trivial change which cause lots
| |
335 return GL_RGBA; | |
336 } | |
337 } | |
338 | |
339 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | |
340 // format does not contain a superset of the components required by the base | |
341 // format of internalformat. | |
342 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | |
343 bool SourceFormatContainSupersetOfDestFormat(GLenum source_internal_format, | |
344 GLenum dest_internal_format) { | |
345 return (UnsizedFormatFrom(source_internal_format) == | |
346 UnsizedFormatFrom(dest_internal_format) && | |
347 UnsizedFormatFrom(source_internal_format) != GL_BGRA_EXT) || | |
348 (UnsizedFormatFrom(source_internal_format) == GL_RGBA && | |
349 UnsizedFormatFrom(dest_internal_format) == GL_RGB); | |
350 } | |
351 | |
322 } // namespace | 352 } // namespace |
323 | 353 |
324 namespace gpu { | 354 namespace gpu { |
325 namespace gles2 { | 355 namespace gles2 { |
326 | 356 |
327 CopyTextureCHROMIUMResourceManager::CopyTextureCHROMIUMResourceManager() | 357 CopyTextureCHROMIUMResourceManager::CopyTextureCHROMIUMResourceManager() |
328 : initialized_(false), | 358 : initialized_(false), |
329 nv_egl_stream_consumer_external_(false), | 359 nv_egl_stream_consumer_external_(false), |
330 vertex_shader_(0u), | 360 vertex_shader_(0u), |
331 fragment_shaders_(NUM_FRAGMENT_SHADERS, 0u), | 361 fragment_shaders_(NUM_FRAGMENT_SHADERS, 0u), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 GLenum source_internal_format, | 444 GLenum source_internal_format, |
415 GLenum dest_target, | 445 GLenum dest_target, |
416 GLuint dest_id, | 446 GLuint dest_id, |
417 GLenum dest_internal_format, | 447 GLenum dest_internal_format, |
418 GLsizei width, | 448 GLsizei width, |
419 GLsizei height, | 449 GLsizei height, |
420 bool flip_y, | 450 bool flip_y, |
421 bool premultiply_alpha, | 451 bool premultiply_alpha, |
422 bool unpremultiply_alpha) { | 452 bool unpremultiply_alpha) { |
423 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 453 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
424 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | |
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 = | 454 bool source_format_contain_superset_of_dest_format = |
429 (source_internal_format == dest_internal_format && | 455 SourceFormatContainSupersetOfDestFormat(source_internal_format, |
430 source_internal_format != GL_BGRA_EXT) || | 456 dest_internal_format); |
431 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | |
432 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 457 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
433 // so restrict this to GL_TEXTURE_2D. | 458 // so restrict this to GL_TEXTURE_2D. |
434 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && | 459 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && |
435 !flip_y && !premultiply_alpha_change && | 460 !flip_y && !premultiply_alpha_change && |
436 source_format_contain_superset_of_dest_format) { | 461 source_format_contain_superset_of_dest_format) { |
437 DoCopyTexImage2D(decoder, | 462 DoCopyTexImage2D(decoder, |
438 source_target, | 463 source_target, |
439 source_id, | 464 source_id, |
440 dest_target, | 465 dest_target, |
441 dest_id, | 466 dest_id, |
(...skipping 24 matching lines...) Expand all Loading... | |
466 GLint y, | 491 GLint y, |
467 GLsizei width, | 492 GLsizei width, |
468 GLsizei height, | 493 GLsizei height, |
469 GLsizei dest_width, | 494 GLsizei dest_width, |
470 GLsizei dest_height, | 495 GLsizei dest_height, |
471 GLsizei source_width, | 496 GLsizei source_width, |
472 GLsizei source_height, | 497 GLsizei source_height, |
473 bool flip_y, | 498 bool flip_y, |
474 bool premultiply_alpha, | 499 bool premultiply_alpha, |
475 bool unpremultiply_alpha) { | 500 bool unpremultiply_alpha) { |
501 bool use_gl_copy_tex_sub_image_2d = true; | |
502 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
503 // glDrawArrays is faster than glCopyTexSubImage2D on IA Mesa driver, | |
504 // although opposite in Android. | |
505 // TODO(dshwang): After Mesa fixes this issue, remove this hack. | |
506 // https://bugs.freedesktop.org/show_bug.cgi?id=98478 crbug.com/535198 | |
507 use_gl_copy_tex_sub_image_2d = false; | |
508 #endif | |
476 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 509 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
477 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | |
478 // format does not contain a superset of the components required by the base | |
479 // format of internalformat. | |
480 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | |
481 bool source_format_contain_superset_of_dest_format = | 510 bool source_format_contain_superset_of_dest_format = |
482 (source_internal_format == dest_internal_format && | 511 SourceFormatContainSupersetOfDestFormat(source_internal_format, |
483 source_internal_format != GL_BGRA_EXT) || | 512 dest_internal_format); |
484 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | |
485 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 513 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
486 // so restrict this to GL_TEXTURE_2D. | 514 // so restrict this to GL_TEXTURE_2D. |
487 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && | 515 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && |
488 !flip_y && !premultiply_alpha_change && | 516 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && |
489 source_format_contain_superset_of_dest_format) { | 517 source_format_contain_superset_of_dest_format) { |
490 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id, | 518 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id, |
491 xoffset, yoffset, x, y, width, height, framebuffer_); | 519 xoffset, yoffset, x, y, width, height, framebuffer_); |
492 return; | 520 return; |
493 } | 521 } |
494 | 522 |
495 DoCopySubTextureWithTransform( | 523 DoCopySubTextureWithTransform( |
496 decoder, source_target, source_id, source_internal_format, dest_target, | 524 decoder, source_target, source_id, source_internal_format, dest_target, |
497 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, | 525 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, |
498 dest_width, dest_height, source_width, source_height, flip_y, | 526 dest_width, dest_height, source_width, source_height, flip_y, |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 decoder->RestoreTextureUnitBindings(0); | 791 decoder->RestoreTextureUnitBindings(0); |
764 decoder->RestoreActiveTexture(); | 792 decoder->RestoreActiveTexture(); |
765 decoder->RestoreProgramBindings(); | 793 decoder->RestoreProgramBindings(); |
766 decoder->RestoreBufferBindings(); | 794 decoder->RestoreBufferBindings(); |
767 decoder->RestoreFramebufferBindings(); | 795 decoder->RestoreFramebufferBindings(); |
768 decoder->RestoreGlobalState(); | 796 decoder->RestoreGlobalState(); |
769 } | 797 } |
770 | 798 |
771 } // namespace gles2 | 799 } // namespace gles2 |
772 } // namespace gpu | 800 } // namespace gpu |
OLD | NEW |