Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc

Issue 1143373004: gpu: Extend CopyTextureCHROMIUM with support for copying part of source texture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: keep TODO for now Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 decoder->RestoreActiveTexture(); 243 decoder->RestoreActiveTexture();
244 decoder->RestoreFramebufferBindings(); 244 decoder->RestoreFramebufferBindings();
245 } 245 }
246 246
247 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder, 247 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder,
248 GLenum source_target, 248 GLenum source_target,
249 GLuint source_id, 249 GLuint source_id,
250 GLuint dest_id, 250 GLuint dest_id,
251 GLint xoffset, 251 GLint xoffset,
252 GLint yoffset, 252 GLint yoffset,
253 GLint source_x,
254 GLint source_y,
253 GLsizei source_width, 255 GLsizei source_width,
254 GLsizei source_height, 256 GLsizei source_height,
255 GLuint framebuffer) { 257 GLuint framebuffer) {
256 DCHECK(source_target == GL_TEXTURE_2D || 258 DCHECK(source_target == GL_TEXTURE_2D ||
257 source_target == GL_TEXTURE_RECTANGLE_ARB); 259 source_target == GL_TEXTURE_RECTANGLE_ARB);
258 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { 260 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) {
259 glBindTexture(GL_TEXTURE_2D, dest_id); 261 glBindTexture(GL_TEXTURE_2D, dest_id);
260 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 262 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
261 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 263 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
264 glCopyTexSubImage2D(GL_TEXTURE_2D, 0 /* level */, xoffset, yoffset, 266 glCopyTexSubImage2D(GL_TEXTURE_2D, 0 /* level */, xoffset, yoffset,
265 0 /* x */, 0 /* y */, source_width, source_height); 267 source_x, source_y, source_width, source_height);
266 } 268 }
267 269
268 decoder->RestoreTextureState(source_id); 270 decoder->RestoreTextureState(source_id);
269 decoder->RestoreTextureState(dest_id); 271 decoder->RestoreTextureState(dest_id);
270 decoder->RestoreTextureUnitBindings(0); 272 decoder->RestoreTextureUnitBindings(0);
271 decoder->RestoreActiveTexture(); 273 decoder->RestoreActiveTexture();
272 decoder->RestoreFramebufferBindings(); 274 decoder->RestoreFramebufferBindings();
273 } 275 }
274 276
275 // Copy from SkMatrix44::preTranslate 277 // Copy from SkMatrix44::preTranslate
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 393
392 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( 394 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture(
393 const gles2::GLES2Decoder* decoder, 395 const gles2::GLES2Decoder* decoder,
394 GLenum source_target, 396 GLenum source_target,
395 GLuint source_id, 397 GLuint source_id,
396 GLenum source_internal_format, 398 GLenum source_internal_format,
397 GLuint dest_id, 399 GLuint dest_id,
398 GLenum dest_internal_format, 400 GLenum dest_internal_format,
399 GLint xoffset, 401 GLint xoffset,
400 GLint yoffset, 402 GLint yoffset,
403 GLint x,
404 GLint y,
405 GLsizei width,
406 GLsizei height,
401 GLsizei dest_width, 407 GLsizei dest_width,
402 GLsizei dest_height, 408 GLsizei dest_height,
403 GLsizei source_width, 409 GLsizei source_width,
404 GLsizei source_height, 410 GLsizei source_height,
405 bool flip_y, 411 bool flip_y,
406 bool premultiply_alpha, 412 bool premultiply_alpha,
407 bool unpremultiply_alpha) { 413 bool unpremultiply_alpha) {
408 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; 414 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha;
409 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's 415 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's
410 // format does not contain a superset of the components required by the base 416 // format does not contain a superset of the components required by the base
411 // format of internalformat. 417 // format of internalformat.
412 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml 418 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml
413 bool source_format_contain_superset_of_dest_format = 419 bool source_format_contain_superset_of_dest_format =
414 (source_internal_format == dest_internal_format && 420 (source_internal_format == dest_internal_format &&
415 source_internal_format != GL_BGRA_EXT) || 421 source_internal_format != GL_BGRA_EXT) ||
416 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); 422 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB);
417 // 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,
418 // so restrict this to GL_TEXTURE_2D. 424 // so restrict this to GL_TEXTURE_2D.
419 if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && 425 if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change &&
420 source_format_contain_superset_of_dest_format) { 426 source_format_contain_superset_of_dest_format) {
421 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_id, xoffset, 427 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_id, xoffset,
422 yoffset, source_width, source_height, framebuffer_); 428 yoffset, x, y, width, height, framebuffer_);
423 return; 429 return;
424 } 430 }
425 431
426 // Use kIdentityMatrix if no transform passed in. 432 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, xoffset - x,
427 DoCopySubTextureWithTransform( 433 yoffset - y, dest_width, dest_height, source_width,
428 decoder, source_target, source_id, dest_id, xoffset, yoffset, dest_width, 434 source_height, flip_y, premultiply_alpha,
429 dest_height, source_width, source_height, flip_y, premultiply_alpha, 435 unpremultiply_alpha, kIdentityMatrix, xoffset, yoffset,
430 unpremultiply_alpha, kIdentityMatrix); 436 width, height);
431 } 437 }
432 438
433 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( 439 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform(
434 const gles2::GLES2Decoder* decoder, 440 const gles2::GLES2Decoder* decoder,
435 GLenum source_target, 441 GLenum source_target,
436 GLuint source_id, 442 GLuint source_id,
437 GLuint dest_id, 443 GLuint dest_id,
438 GLsizei width, 444 GLsizei width,
439 GLsizei height, 445 GLsizei height,
440 bool flip_y, 446 bool flip_y,
441 bool premultiply_alpha, 447 bool premultiply_alpha,
442 bool unpremultiply_alpha, 448 bool unpremultiply_alpha,
443 const GLfloat transform_matrix[16]) { 449 const GLfloat transform_matrix[16]) {
444 GLsizei dest_width = width; 450 GLsizei dest_width = width;
445 GLsizei dest_height = height; 451 GLsizei dest_height = height;
446 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, 0, 0, 452 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, 0, 0,
447 dest_width, dest_height, width, height, flip_y, 453 dest_width, dest_height, width, height, flip_y,
448 premultiply_alpha, unpremultiply_alpha, 454 premultiply_alpha, unpremultiply_alpha,
449 transform_matrix); 455 transform_matrix, 0, 0, dest_width, dest_height);
450 }
451
452 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform(
453 const gles2::GLES2Decoder* decoder,
454 GLenum source_target,
455 GLuint source_id,
456 GLuint dest_id,
457 GLint xoffset,
458 GLint yoffset,
459 GLsizei dest_width,
460 GLsizei dest_height,
461 GLsizei source_width,
462 GLsizei source_height,
463 bool flip_y,
464 bool premultiply_alpha,
465 bool unpremultiply_alpha,
466 const GLfloat transform_matrix[16]) {
467 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, xoffset,
468 yoffset, dest_width, dest_height, source_width,
469 source_height, flip_y, premultiply_alpha,
470 unpremultiply_alpha, transform_matrix);
471 } 456 }
472 457
473 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( 458 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal(
474 const gles2::GLES2Decoder* decoder, 459 const gles2::GLES2Decoder* decoder,
475 GLenum source_target, 460 GLenum source_target,
476 GLuint source_id, 461 GLuint source_id,
477 GLuint dest_id, 462 GLuint dest_id,
478 GLint xoffset, 463 GLint xoffset,
479 GLint yoffset, 464 GLint yoffset,
480 GLsizei dest_width, 465 GLsizei dest_width,
481 GLsizei dest_height, 466 GLsizei dest_height,
482 GLsizei source_width, 467 GLsizei source_width,
483 GLsizei source_height, 468 GLsizei source_height,
484 bool flip_y, 469 bool flip_y,
485 bool premultiply_alpha, 470 bool premultiply_alpha,
486 bool unpremultiply_alpha, 471 bool unpremultiply_alpha,
487 const GLfloat transform_matrix[16]) { 472 const GLfloat transform_matrix[16],
473 GLint scissor_x,
474 GLint scissor_y,
475 GLsizei scissor_width,
476 GLsizei scissor_height) {
488 DCHECK(source_target == GL_TEXTURE_2D || 477 DCHECK(source_target == GL_TEXTURE_2D ||
489 source_target == GL_TEXTURE_RECTANGLE_ARB || 478 source_target == GL_TEXTURE_RECTANGLE_ARB ||
490 source_target == GL_TEXTURE_EXTERNAL_OES); 479 source_target == GL_TEXTURE_EXTERNAL_OES);
491 DCHECK(xoffset >= 0 && xoffset + source_width <= dest_width); 480 DCHECK(xoffset >= 0 && xoffset + source_width <= dest_width);
492 DCHECK(yoffset >= 0 && yoffset + source_height <= dest_height); 481 DCHECK(yoffset >= 0 && yoffset + source_height <= dest_height);
493 if (!initialized_) { 482 if (!initialized_) {
494 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; 483 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager.";
495 return; 484 return;
496 } 485 }
497 486
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 562
574 glUniform1i(info->sampler_handle, 0); 563 glUniform1i(info->sampler_handle, 0);
575 564
576 glBindTexture(source_target, source_id); 565 glBindTexture(source_target, source_id);
577 glTexParameterf(source_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 566 glTexParameterf(source_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
578 glTexParameterf(source_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 567 glTexParameterf(source_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
579 glTexParameteri(source_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 568 glTexParameteri(source_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
580 glTexParameteri(source_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 569 glTexParameteri(source_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
581 570
582 glDisable(GL_DEPTH_TEST); 571 glDisable(GL_DEPTH_TEST);
583 glDisable(GL_SCISSOR_TEST);
584 glDisable(GL_STENCIL_TEST); 572 glDisable(GL_STENCIL_TEST);
585 glDisable(GL_CULL_FACE); 573 glDisable(GL_CULL_FACE);
586 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 574 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
587 glDepthMask(GL_FALSE); 575 glDepthMask(GL_FALSE);
588 glDisable(GL_BLEND); 576 glDisable(GL_BLEND);
589 577
578 glEnable(GL_SCISSOR_TEST);
579 glScissor(scissor_x, scissor_y, scissor_width, scissor_height);
590 glViewport(0, 0, dest_width, dest_height); 580 glViewport(0, 0, dest_width, dest_height);
591 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 581 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
592 } 582 }
593 583
594 decoder->RestoreAllAttributes(); 584 decoder->RestoreAllAttributes();
595 decoder->RestoreTextureState(source_id); 585 decoder->RestoreTextureState(source_id);
596 decoder->RestoreTextureState(dest_id); 586 decoder->RestoreTextureState(dest_id);
597 decoder->RestoreTextureUnitBindings(0); 587 decoder->RestoreTextureUnitBindings(0);
598 decoder->RestoreActiveTexture(); 588 decoder->RestoreActiveTexture();
599 decoder->RestoreProgramBindings(); 589 decoder->RestoreProgramBindings();
600 decoder->RestoreBufferBindings(); 590 decoder->RestoreBufferBindings();
601 decoder->RestoreFramebufferBindings(); 591 decoder->RestoreFramebufferBindings();
602 decoder->RestoreGlobalState(); 592 decoder->RestoreGlobalState();
603 } 593 }
604 594
605 } // namespace gpu 595 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698