| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 #ifndef NDEBUG | 252 #ifndef NDEBUG |
| 253 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | 253 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 254 if (GL_FRAMEBUFFER_COMPLETE != fb_status) { | 254 if (GL_FRAMEBUFFER_COMPLETE != fb_status) { |
| 255 DLOG(ERROR) << "CopyTextureCHROMIUM: Incomplete framebuffer."; | 255 DLOG(ERROR) << "CopyTextureCHROMIUM: Incomplete framebuffer."; |
| 256 return false; | 256 return false; |
| 257 } | 257 } |
| 258 #endif | 258 #endif |
| 259 return true; | 259 return true; |
| 260 } | 260 } |
| 261 | 261 |
| 262 void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder, | 262 void DoCopyTexImage2DInternal(const gpu::gles2::GLES2Decoder* decoder, |
| 263 GLenum source_target, | 263 GLenum source_target, |
| 264 GLuint source_id, | 264 GLuint source_id, |
| 265 GLenum dest_target, | 265 GLenum dest_target, |
| 266 GLuint dest_id, | 266 GLuint dest_id, |
| 267 GLenum dest_internal_format, | 267 GLenum dest_internal_format, |
| 268 GLsizei width, | 268 GLsizei width, |
| 269 GLsizei height, | 269 GLsizei height, |
| 270 GLuint framebuffer) { | 270 GLuint framebuffer) { |
| 271 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), source_target); | 271 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), source_target); |
| 272 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); | 272 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); |
| 273 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { | 273 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { |
| 274 glBindTexture(dest_target, dest_id); | 274 glBindTexture(dest_target, dest_id); |
| 275 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 275 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 276 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 276 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 277 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 277 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 278 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 278 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 279 glCopyTexImage2D(dest_target, 0 /* level */, dest_internal_format, | 279 glCopyTexImage2D(dest_target, 0 /* level */, dest_internal_format, |
| 280 0 /* x */, 0 /* y */, width, height, 0 /* border */); | 280 0 /* x */, 0 /* y */, width, height, 0 /* border */); |
| 281 } | 281 } |
| 282 | 282 |
| 283 decoder->RestoreTextureState(source_id); | 283 decoder->RestoreTextureState(source_id); |
| 284 decoder->RestoreTextureState(dest_id); | 284 decoder->RestoreTextureState(dest_id); |
| 285 decoder->RestoreTextureUnitBindings(0); | 285 decoder->RestoreTextureUnitBindings(0); |
| 286 decoder->RestoreActiveTexture(); | 286 decoder->RestoreActiveTexture(); |
| 287 decoder->RestoreFramebufferBindings(); | 287 decoder->RestoreFramebufferBindings(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder, | 290 void DoCopyTexSubImage2DInternal(const gpu::gles2::GLES2Decoder* decoder, |
| 291 GLenum source_target, | 291 GLenum source_target, |
| 292 GLuint source_id, | 292 GLuint source_id, |
| 293 GLenum dest_target, | 293 GLenum dest_target, |
| 294 GLuint dest_id, | 294 GLuint dest_id, |
| 295 GLint xoffset, | 295 GLint xoffset, |
| 296 GLint yoffset, | 296 GLint yoffset, |
| 297 GLint source_x, | 297 GLint source_x, |
| 298 GLint source_y, | 298 GLint source_y, |
| 299 GLsizei source_width, | 299 GLsizei source_width, |
| 300 GLsizei source_height, | 300 GLsizei source_height, |
| 301 GLuint framebuffer) { | 301 GLuint framebuffer) { |
| 302 DCHECK(source_target == GL_TEXTURE_2D || | 302 DCHECK(source_target == GL_TEXTURE_2D || |
| 303 source_target == GL_TEXTURE_RECTANGLE_ARB); | 303 source_target == GL_TEXTURE_RECTANGLE_ARB); |
| 304 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); | 304 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); |
| 305 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { | 305 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { |
| 306 glBindTexture(dest_target, dest_id); | 306 glBindTexture(dest_target, dest_id); |
| 307 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 307 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 308 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 308 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 309 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 309 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 310 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 310 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 311 glCopyTexSubImage2D(dest_target, 0 /* level */, xoffset, yoffset, | 311 glCopyTexSubImage2D(dest_target, 0 /* level */, xoffset, yoffset, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | 427 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml |
| 428 bool source_format_contain_superset_of_dest_format = | 428 bool source_format_contain_superset_of_dest_format = |
| 429 (source_internal_format == dest_internal_format && | 429 (source_internal_format == dest_internal_format && |
| 430 source_internal_format != GL_BGRA_EXT) || | 430 source_internal_format != GL_BGRA_EXT) || |
| 431 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | 431 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); |
| 432 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 432 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
| 433 // so restrict this to GL_TEXTURE_2D. | 433 // so restrict this to GL_TEXTURE_2D. |
| 434 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && | 434 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && |
| 435 !flip_y && !premultiply_alpha_change && | 435 !flip_y && !premultiply_alpha_change && |
| 436 source_format_contain_superset_of_dest_format) { | 436 source_format_contain_superset_of_dest_format) { |
| 437 DoCopyTexImage2D(decoder, | 437 DoCopyTexImage2DInternal(decoder, |
| 438 source_target, | 438 source_target, |
| 439 source_id, | 439 source_id, |
| 440 dest_target, | 440 dest_target, |
| 441 dest_id, | 441 dest_id, |
| 442 dest_internal_format, | 442 dest_internal_format, |
| 443 width, | 443 width, |
| 444 height, | 444 height, |
| 445 framebuffer_); | 445 framebuffer_); |
| 446 return; | 446 return; |
| 447 } | 447 } |
| 448 | 448 |
| 449 // Use kIdentityMatrix if no transform passed in. | 449 // Use kIdentityMatrix if no transform passed in. |
| 450 DoCopyTextureWithTransform(decoder, source_target, source_id, dest_target, | 450 DoCopyTextureWithTransform(decoder, source_target, source_id, dest_target, |
| 451 dest_id, width, height, flip_y, premultiply_alpha, | 451 dest_id, width, height, flip_y, premultiply_alpha, |
| 452 unpremultiply_alpha, kIdentityMatrix); | 452 unpremultiply_alpha, kIdentityMatrix); |
| 453 } | 453 } |
| 454 | 454 |
| 455 void CopyTextureCHROMIUMResourceManager::DoCopyTexImage2D( |
| 456 const gpu::gles2::GLES2Decoder* decoder, |
| 457 GLenum source_target, |
| 458 GLuint source_id, |
| 459 GLenum dest_target, |
| 460 GLuint dest_id, |
| 461 GLenum dest_internal_format, |
| 462 GLsizei width, |
| 463 GLsizei height) { |
| 464 DoCopyTexImage2DInternal(decoder, |
| 465 source_target, |
| 466 source_id, |
| 467 dest_target, |
| 468 dest_id, |
| 469 dest_internal_format, |
| 470 width, |
| 471 height, |
| 472 framebuffer_); |
| 473 return; |
| 474 } |
| 475 |
| 455 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( | 476 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( |
| 456 const gles2::GLES2Decoder* decoder, | 477 const gles2::GLES2Decoder* decoder, |
| 457 GLenum source_target, | 478 GLenum source_target, |
| 458 GLuint source_id, | 479 GLuint source_id, |
| 459 GLenum source_internal_format, | 480 GLenum source_internal_format, |
| 460 GLenum dest_target, | 481 GLenum dest_target, |
| 461 GLuint dest_id, | 482 GLuint dest_id, |
| 462 GLenum dest_internal_format, | 483 GLenum dest_internal_format, |
| 463 GLint xoffset, | 484 GLint xoffset, |
| 464 GLint yoffset, | 485 GLint yoffset, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 488 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | 509 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml |
| 489 bool source_format_contain_superset_of_dest_format = | 510 bool source_format_contain_superset_of_dest_format = |
| 490 (source_internal_format == dest_internal_format && | 511 (source_internal_format == dest_internal_format && |
| 491 source_internal_format != GL_BGRA_EXT) || | 512 source_internal_format != GL_BGRA_EXT) || |
| 492 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | 513 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); |
| 493 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 514 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
| 494 // so restrict this to GL_TEXTURE_2D. | 515 // so restrict this to GL_TEXTURE_2D. |
| 495 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && | 516 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && |
| 496 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && | 517 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && |
| 497 source_format_contain_superset_of_dest_format) { | 518 source_format_contain_superset_of_dest_format) { |
| 498 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id, | 519 DoCopyTexSubImage2DInternal(decoder, source_target, source_id, dest_target, |
| 499 xoffset, yoffset, x, y, width, height, framebuffer_); | 520 dest_id, xoffset, yoffset, x, y, width, height, |
| 521 framebuffer_); |
| 500 return; | 522 return; |
| 501 } | 523 } |
| 502 | 524 |
| 503 DoCopySubTextureWithTransform( | 525 DoCopySubTextureWithTransform( |
| 504 decoder, source_target, source_id, source_internal_format, dest_target, | 526 decoder, source_target, source_id, source_internal_format, dest_target, |
| 505 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, | 527 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, |
| 506 dest_width, dest_height, source_width, source_height, flip_y, | 528 dest_width, dest_height, source_width, source_height, flip_y, |
| 507 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); | 529 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); |
| 508 } | 530 } |
| 509 | 531 |
| 532 void CopyTextureCHROMIUMResourceManager::DoCopyTexSubImage2D( |
| 533 const gpu::gles2::GLES2Decoder* decoder, |
| 534 GLenum source_target, |
| 535 GLuint source_id, |
| 536 GLenum dest_target, |
| 537 GLuint dest_id, |
| 538 GLint xoffset, |
| 539 GLint yoffset, |
| 540 GLint x, |
| 541 GLint y, |
| 542 GLsizei width, |
| 543 GLsizei height) { |
| 544 DoCopyTexSubImage2DInternal(decoder, source_target, source_id, dest_target, |
| 545 dest_id, xoffset, yoffset, x, y, width, height, |
| 546 framebuffer_); |
| 547 } |
| 548 |
| 510 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform( | 549 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform( |
| 511 const gles2::GLES2Decoder* decoder, | 550 const gles2::GLES2Decoder* decoder, |
| 512 GLenum source_target, | 551 GLenum source_target, |
| 513 GLuint source_id, | 552 GLuint source_id, |
| 514 GLenum source_internal_format, | 553 GLenum source_internal_format, |
| 515 GLenum dest_target, | 554 GLenum dest_target, |
| 516 GLuint dest_id, | 555 GLuint dest_id, |
| 517 GLenum dest_internal_format, | 556 GLenum dest_internal_format, |
| 518 GLint xoffset, | 557 GLint xoffset, |
| 519 GLint yoffset, | 558 GLint yoffset, |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 decoder->RestoreTextureUnitBindings(0); | 810 decoder->RestoreTextureUnitBindings(0); |
| 772 decoder->RestoreActiveTexture(); | 811 decoder->RestoreActiveTexture(); |
| 773 decoder->RestoreProgramBindings(); | 812 decoder->RestoreProgramBindings(); |
| 774 decoder->RestoreBufferBindings(); | 813 decoder->RestoreBufferBindings(); |
| 775 decoder->RestoreFramebufferBindings(); | 814 decoder->RestoreFramebufferBindings(); |
| 776 decoder->RestoreGlobalState(); | 815 decoder->RestoreGlobalState(); |
| 777 } | 816 } |
| 778 | 817 |
| 779 } // namespace gles2 | 818 } // namespace gles2 |
| 780 } // namespace gpu | 819 } // namespace gpu |
| OLD | NEW |