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 DoCopyTexImage2D(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->MarkFramebufferBindingsChanged(); |
288 } | 288 } |
289 | 289 |
290 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder, | 290 void DoCopyTexSubImage2D(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, |
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->MarkFramebufferBindingsChanged(); |
320 } | 320 } |
321 | 321 |
322 } // namespace | 322 } // namespace |
323 | 323 |
324 namespace gpu { | 324 namespace gpu { |
325 | 325 |
326 CopyTextureCHROMIUMResourceManager::CopyTextureCHROMIUMResourceManager() | 326 CopyTextureCHROMIUMResourceManager::CopyTextureCHROMIUMResourceManager() |
327 : initialized_(false), | 327 : initialized_(false), |
328 vertex_shader_(0u), | 328 vertex_shader_(0u), |
329 fragment_shaders_(NUM_FRAGMENT_SHADERS, 0u), | 329 fragment_shaders_(NUM_FRAGMENT_SHADERS, 0u), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 ++it) { | 396 ++it) { |
397 const ProgramInfo& info = it->second; | 397 const ProgramInfo& info = it->second; |
398 glDeleteProgram(info.program); | 398 glDeleteProgram(info.program); |
399 } | 399 } |
400 | 400 |
401 glDeleteBuffersARB(1, &buffer_id_); | 401 glDeleteBuffersARB(1, &buffer_id_); |
402 buffer_id_ = 0; | 402 buffer_id_ = 0; |
403 } | 403 } |
404 | 404 |
405 void CopyTextureCHROMIUMResourceManager::DoCopyTexture( | 405 void CopyTextureCHROMIUMResourceManager::DoCopyTexture( |
406 const gles2::GLES2Decoder* decoder, | 406 gles2::GLES2Decoder* decoder, |
407 GLenum source_target, | 407 GLenum source_target, |
408 GLuint source_id, | 408 GLuint source_id, |
409 GLenum source_internal_format, | 409 GLenum source_internal_format, |
410 GLenum dest_target, | 410 GLenum dest_target, |
411 GLuint dest_id, | 411 GLuint dest_id, |
412 GLenum dest_internal_format, | 412 GLenum dest_internal_format, |
413 GLsizei width, | 413 GLsizei width, |
414 GLsizei height, | 414 GLsizei height, |
415 bool flip_y, | 415 bool flip_y, |
416 bool premultiply_alpha, | 416 bool premultiply_alpha, |
(...skipping 24 matching lines...) Expand all Loading... |
441 return; | 441 return; |
442 } | 442 } |
443 | 443 |
444 // Use kIdentityMatrix if no transform passed in. | 444 // Use kIdentityMatrix if no transform passed in. |
445 DoCopyTextureWithTransform(decoder, source_target, source_id, dest_target, | 445 DoCopyTextureWithTransform(decoder, source_target, source_id, dest_target, |
446 dest_id, width, height, flip_y, premultiply_alpha, | 446 dest_id, width, height, flip_y, premultiply_alpha, |
447 unpremultiply_alpha, kIdentityMatrix); | 447 unpremultiply_alpha, kIdentityMatrix); |
448 } | 448 } |
449 | 449 |
450 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( | 450 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( |
451 const gles2::GLES2Decoder* decoder, | 451 gles2::GLES2Decoder* decoder, |
452 GLenum source_target, | 452 GLenum source_target, |
453 GLuint source_id, | 453 GLuint source_id, |
454 GLenum source_internal_format, | 454 GLenum source_internal_format, |
455 GLenum dest_target, | 455 GLenum dest_target, |
456 GLuint dest_id, | 456 GLuint dest_id, |
457 GLenum dest_internal_format, | 457 GLenum dest_internal_format, |
458 GLint xoffset, | 458 GLint xoffset, |
459 GLint yoffset, | 459 GLint yoffset, |
460 GLint x, | 460 GLint x, |
461 GLint y, | 461 GLint y, |
(...skipping 26 matching lines...) Expand all Loading... |
488 } | 488 } |
489 | 489 |
490 DoCopySubTextureWithTransform( | 490 DoCopySubTextureWithTransform( |
491 decoder, source_target, source_id, source_internal_format, dest_target, | 491 decoder, source_target, source_id, source_internal_format, dest_target, |
492 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, | 492 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, |
493 dest_width, dest_height, source_width, source_height, flip_y, | 493 dest_width, dest_height, source_width, source_height, flip_y, |
494 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); | 494 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); |
495 } | 495 } |
496 | 496 |
497 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform( | 497 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform( |
498 const gles2::GLES2Decoder* decoder, | 498 gles2::GLES2Decoder* decoder, |
499 GLenum source_target, | 499 GLenum source_target, |
500 GLuint source_id, | 500 GLuint source_id, |
501 GLenum source_internal_format, | 501 GLenum source_internal_format, |
502 GLenum dest_target, | 502 GLenum dest_target, |
503 GLuint dest_id, | 503 GLuint dest_id, |
504 GLenum dest_internal_format, | 504 GLenum dest_internal_format, |
505 GLint xoffset, | 505 GLint xoffset, |
506 GLint yoffset, | 506 GLint yoffset, |
507 GLint x, | 507 GLint x, |
508 GLint y, | 508 GLint y, |
509 GLsizei width, | 509 GLsizei width, |
510 GLsizei height, | 510 GLsizei height, |
511 GLsizei dest_width, | 511 GLsizei dest_width, |
512 GLsizei dest_height, | 512 GLsizei dest_height, |
513 GLsizei source_width, | 513 GLsizei source_width, |
514 GLsizei source_height, | 514 GLsizei source_height, |
515 bool flip_y, | 515 bool flip_y, |
516 bool premultiply_alpha, | 516 bool premultiply_alpha, |
517 bool unpremultiply_alpha, | 517 bool unpremultiply_alpha, |
518 const GLfloat transform_matrix[16]) { | 518 const GLfloat transform_matrix[16]) { |
519 DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id, | 519 DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id, |
520 xoffset, yoffset, x, y, width, height, dest_width, dest_height, | 520 xoffset, yoffset, x, y, width, height, dest_width, dest_height, |
521 source_width, source_height, flip_y, premultiply_alpha, | 521 source_width, source_height, flip_y, premultiply_alpha, |
522 unpremultiply_alpha, transform_matrix); | 522 unpremultiply_alpha, transform_matrix); |
523 } | 523 } |
524 | 524 |
525 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( | 525 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( |
526 const gles2::GLES2Decoder* decoder, | 526 gles2::GLES2Decoder* decoder, |
527 GLenum source_target, | 527 GLenum source_target, |
528 GLuint source_id, | 528 GLuint source_id, |
529 GLenum dest_target, | 529 GLenum dest_target, |
530 GLuint dest_id, | 530 GLuint dest_id, |
531 GLsizei width, | 531 GLsizei width, |
532 GLsizei height, | 532 GLsizei height, |
533 bool flip_y, | 533 bool flip_y, |
534 bool premultiply_alpha, | 534 bool premultiply_alpha, |
535 bool unpremultiply_alpha, | 535 bool unpremultiply_alpha, |
536 const GLfloat transform_matrix[16]) { | 536 const GLfloat transform_matrix[16]) { |
537 GLsizei dest_width = width; | 537 GLsizei dest_width = width; |
538 GLsizei dest_height = height; | 538 GLsizei dest_height = height; |
539 DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id, | 539 DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id, |
540 0, 0, 0, 0, width, height, dest_width, dest_height, | 540 0, 0, 0, 0, width, height, dest_width, dest_height, |
541 width, height, flip_y, premultiply_alpha, | 541 width, height, flip_y, premultiply_alpha, |
542 unpremultiply_alpha, transform_matrix); | 542 unpremultiply_alpha, transform_matrix); |
543 } | 543 } |
544 | 544 |
545 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( | 545 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( |
546 const gles2::GLES2Decoder* decoder, | 546 gles2::GLES2Decoder* decoder, |
547 GLenum source_target, | 547 GLenum source_target, |
548 GLuint source_id, | 548 GLuint source_id, |
549 GLenum dest_target, | 549 GLenum dest_target, |
550 GLuint dest_id, | 550 GLuint dest_id, |
551 GLint xoffset, | 551 GLint xoffset, |
552 GLint yoffset, | 552 GLint yoffset, |
553 GLint x, | 553 GLint x, |
554 GLint y, | 554 GLint y, |
555 GLsizei width, | 555 GLsizei width, |
556 GLsizei height, | 556 GLsizei height, |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 750 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
751 } | 751 } |
752 | 752 |
753 decoder->RestoreAllAttributes(); | 753 decoder->RestoreAllAttributes(); |
754 decoder->RestoreTextureState(source_id); | 754 decoder->RestoreTextureState(source_id); |
755 decoder->RestoreTextureState(dest_id); | 755 decoder->RestoreTextureState(dest_id); |
756 decoder->RestoreTextureUnitBindings(0); | 756 decoder->RestoreTextureUnitBindings(0); |
757 decoder->RestoreActiveTexture(); | 757 decoder->RestoreActiveTexture(); |
758 decoder->RestoreProgramBindings(); | 758 decoder->RestoreProgramBindings(); |
759 decoder->RestoreBufferBindings(); | 759 decoder->RestoreBufferBindings(); |
760 decoder->RestoreFramebufferBindings(); | 760 decoder->MarkFramebufferBindingsChanged(); |
761 decoder->RestoreGlobalState(); | 761 decoder->RestoreGlobalState(); |
762 } | 762 } |
763 | 763 |
764 } // namespace gpu | 764 } // namespace gpu |
OLD | NEW |