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 "content/common/gpu/texture_image_transport_surface.h" | 5 #include "content/common/gpu/texture_image_transport_surface.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "content/common/gpu/gl_scoped_binders.h" | 11 #include "content/common/gpu/gl_scoped_binders.h" |
12 #include "content/common/gpu/gpu_channel.h" | 12 #include "content/common/gpu/gpu_channel.h" |
13 #include "content/common/gpu/gpu_channel_manager.h" | 13 #include "content/common/gpu/gpu_channel_manager.h" |
14 #include "content/common/gpu/gpu_messages.h" | 14 #include "content/common/gpu/gpu_messages.h" |
15 #include "content/common/gpu/sync_point_manager.h" | 15 #include "content/common/gpu/sync_point_manager.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "gpu/command_buffer/service/context_group.h" | 17 #include "gpu/command_buffer/service/context_group.h" |
18 #include "gpu/command_buffer/service/gpu_scheduler.h" | 18 #include "gpu/command_buffer/service/gpu_scheduler.h" |
19 #include "gpu/command_buffer/service/texture_manager.h" | 19 #include "gpu/command_buffer/service/texture_manager.h" |
20 | 20 |
21 using gpu::gles2::ContextGroup; | 21 using gpu::gles2::ContextGroup; |
22 using gpu::gles2::TextureManager; | 22 using gpu::gles2::TextureManager; |
23 typedef TextureManager::TextureInfo TextureInfo; | 23 typedef TextureManager::TextureInfo TextureInfo; |
24 | 24 |
| 25 namespace content { |
| 26 |
25 TextureImageTransportSurface::Texture::Texture() | 27 TextureImageTransportSurface::Texture::Texture() |
26 : client_id(0), | 28 : client_id(0), |
27 sent_to_client(false) { | 29 sent_to_client(false) { |
28 } | 30 } |
29 | 31 |
30 TextureImageTransportSurface::Texture::~Texture() { | 32 TextureImageTransportSurface::Texture::~Texture() { |
31 } | 33 } |
32 | 34 |
33 TextureImageTransportSurface::TextureImageTransportSurface( | 35 TextureImageTransportSurface::TextureImageTransportSurface( |
34 GpuChannelManager* manager, | 36 GpuChannelManager* manager, |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 int back_texture_service_id = textures_[back()].info->service_id(); | 300 int back_texture_service_id = textures_[back()].info->service_id(); |
299 int front_texture_service_id = textures_[front()].info->service_id(); | 301 int front_texture_service_id = textures_[front()].info->service_id(); |
300 | 302 |
301 gfx::Size expected_size = textures_[back()].size; | 303 gfx::Size expected_size = textures_[back()].size; |
302 bool surfaces_same_size = textures_[front()].size == expected_size; | 304 bool surfaces_same_size = textures_[front()].size == expected_size; |
303 | 305 |
304 if (surfaces_same_size) { | 306 if (surfaces_same_size) { |
305 std::vector<gfx::Rect> regions_to_copy; | 307 std::vector<gfx::Rect> regions_to_copy; |
306 GetRegionsToCopy(previous_damage_rect_, new_damage_rect, ®ions_to_copy); | 308 GetRegionsToCopy(previous_damage_rect_, new_damage_rect, ®ions_to_copy); |
307 | 309 |
308 content::ScopedFrameBufferBinder fbo_binder(fbo_id_); | 310 ScopedFrameBufferBinder fbo_binder(fbo_id_); |
309 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 311 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
310 GL_COLOR_ATTACHMENT0, | 312 GL_COLOR_ATTACHMENT0, |
311 GL_TEXTURE_2D, | 313 GL_TEXTURE_2D, |
312 front_texture_service_id, | 314 front_texture_service_id, |
313 0); | 315 0); |
314 content::ScopedTextureBinder texture_binder(back_texture_service_id); | 316 ScopedTextureBinder texture_binder(back_texture_service_id); |
315 | 317 |
316 for (size_t i = 0; i < regions_to_copy.size(); ++i) { | 318 for (size_t i = 0; i < regions_to_copy.size(); ++i) { |
317 const gfx::Rect& region_to_copy = regions_to_copy[i]; | 319 const gfx::Rect& region_to_copy = regions_to_copy[i]; |
318 if (!region_to_copy.IsEmpty()) { | 320 if (!region_to_copy.IsEmpty()) { |
319 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, region_to_copy.x(), | 321 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, region_to_copy.x(), |
320 region_to_copy.y(), region_to_copy.x(), region_to_copy.y(), | 322 region_to_copy.y(), region_to_copy.x(), region_to_copy.y(), |
321 region_to_copy.width(), region_to_copy.height()); | 323 region_to_copy.width(), region_to_copy.height()); |
322 } | 324 } |
323 } | 325 } |
324 } else { | 326 } else { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 Texture& texture = textures_[id]; | 440 Texture& texture = textures_[id]; |
439 TextureInfo* info = texture.info; | 441 TextureInfo* info = texture.info; |
440 DCHECK(info); | 442 DCHECK(info); |
441 | 443 |
442 GLuint service_id = info->service_id(); | 444 GLuint service_id = info->service_id(); |
443 if (!service_id) | 445 if (!service_id) |
444 return; | 446 return; |
445 info->SetServiceId(0); | 447 info->SetServiceId(0); |
446 | 448 |
447 { | 449 { |
448 content::ScopedFrameBufferBinder fbo_binder(fbo_id_); | 450 ScopedFrameBufferBinder fbo_binder(fbo_id_); |
449 glDeleteTextures(1, &service_id); | 451 glDeleteTextures(1, &service_id); |
450 } | 452 } |
451 glFlush(); | 453 glFlush(); |
452 CHECK_GL_ERROR(); | 454 CHECK_GL_ERROR(); |
453 } | 455 } |
454 | 456 |
455 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { | 457 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { |
456 if (!parent_stub_) | 458 if (!parent_stub_) |
457 return; | 459 return; |
458 Texture& texture = textures_[back()]; | 460 Texture& texture = textures_[back()]; |
(...skipping 22 matching lines...) Expand all Loading... |
481 size.width(), | 483 size.width(), |
482 size.height(), | 484 size.height(), |
483 1, | 485 1, |
484 0, | 486 0, |
485 GL_RGBA, | 487 GL_RGBA, |
486 GL_UNSIGNED_BYTE, | 488 GL_UNSIGNED_BYTE, |
487 true); | 489 true); |
488 } | 490 } |
489 | 491 |
490 { | 492 { |
491 content::ScopedTextureBinder texture_binder(service_id); | 493 ScopedTextureBinder texture_binder(service_id); |
492 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 494 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
493 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 495 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
494 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
495 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 497 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
496 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, | 498 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, |
497 size.width(), size.height(), 0, | 499 size.width(), size.height(), 0, |
498 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 500 GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
499 CHECK_GL_ERROR(); | 501 CHECK_GL_ERROR(); |
500 } | 502 } |
501 | 503 |
502 AttachBackTextureToFBO(); | 504 AttachBackTextureToFBO(); |
503 | 505 |
504 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 506 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
505 params.width = size.width(); | 507 params.width = size.width(); |
506 params.height = size.height(); | 508 params.height = size.height(); |
507 params.surface_handle = texture.client_id; | 509 params.surface_handle = texture.client_id; |
508 helper_->SendAcceleratedSurfaceNew(params); | 510 helper_->SendAcceleratedSurfaceNew(params); |
509 texture.sent_to_client = true; | 511 texture.sent_to_client = true; |
510 } | 512 } |
511 | 513 |
512 void TextureImageTransportSurface::AttachBackTextureToFBO() { | 514 void TextureImageTransportSurface::AttachBackTextureToFBO() { |
513 if (!parent_stub_) | 515 if (!parent_stub_) |
514 return; | 516 return; |
515 TextureInfo* info = textures_[back()].info; | 517 TextureInfo* info = textures_[back()].info; |
516 DCHECK(info); | 518 DCHECK(info); |
517 | 519 |
518 content::ScopedFrameBufferBinder fbo_binder(fbo_id_); | 520 ScopedFrameBufferBinder fbo_binder(fbo_id_); |
519 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 521 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
520 GL_COLOR_ATTACHMENT0, | 522 GL_COLOR_ATTACHMENT0, |
521 GL_TEXTURE_2D, | 523 GL_TEXTURE_2D, |
522 info->service_id(), | 524 info->service_id(), |
523 0); | 525 0); |
524 glFlush(); | 526 glFlush(); |
525 CHECK_GL_ERROR(); | 527 CHECK_GL_ERROR(); |
526 | 528 |
527 #ifndef NDEBUG | 529 #ifndef NDEBUG |
528 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | 530 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
(...skipping 10 matching lines...) Expand all Loading... |
539 Texture& texture = textures_[i]; | 541 Texture& texture = textures_[i]; |
540 texture.info = NULL; | 542 texture.info = NULL; |
541 if (!texture.sent_to_client) | 543 if (!texture.sent_to_client) |
542 continue; | 544 continue; |
543 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 545 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
544 params.identifier = texture.client_id; | 546 params.identifier = texture.client_id; |
545 helper_->SendAcceleratedSurfaceRelease(params); | 547 helper_->SendAcceleratedSurfaceRelease(params); |
546 } | 548 } |
547 parent_stub_ = NULL; | 549 parent_stub_ = NULL; |
548 } | 550 } |
| 551 |
| 552 } // namespace content |
OLD | NEW |