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/image_transport_surface.h" | 5 #include "content/common/gpu/image_transport_surface.h" |
6 | 6 |
7 // This conflicts with the defines in Xlib.h and must come first. | 7 // This conflicts with the defines in Xlib.h and must come first. |
8 #include "content/common/gpu/gpu_messages.h" | 8 #include "content/common/gpu/gpu_messages.h" |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 virtual void OnBuffersSwappedACK() OVERRIDE; | 102 virtual void OnBuffersSwappedACK() OVERRIDE; |
103 virtual void OnPostSubBufferACK() OVERRIDE; | 103 virtual void OnPostSubBufferACK() OVERRIDE; |
104 virtual void OnResizeViewACK() OVERRIDE; | 104 virtual void OnResizeViewACK() OVERRIDE; |
105 virtual void OnResize(gfx::Size size) OVERRIDE; | 105 virtual void OnResize(gfx::Size size) OVERRIDE; |
106 | 106 |
107 private: | 107 private: |
108 virtual ~EGLImageTransportSurface() OVERRIDE; | 108 virtual ~EGLImageTransportSurface() OVERRIDE; |
109 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); | 109 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); |
110 void SendBuffersSwapped(); | 110 void SendBuffersSwapped(); |
111 void SendPostSubBuffer(int x, int y, int width, int height); | 111 void SendPostSubBuffer(int x, int y, int width, int height); |
112 void GetRegionsToCopy(const gfx::Rect& new_damage_rect, | |
113 std::vector<gfx::Rect>* regions); | |
114 | 112 |
115 // Tracks the current surface visibility state. | 113 // Tracks the current surface visibility state. |
116 VisibilityState visibility_state_; | 114 VisibilityState visibility_state_; |
117 | 115 |
118 uint32 fbo_id_; | 116 uint32 fbo_id_; |
119 | 117 |
120 scoped_refptr<EGLAcceleratedSurface> back_surface_; | 118 scoped_refptr<EGLAcceleratedSurface> back_surface_; |
121 scoped_refptr<EGLAcceleratedSurface> front_surface_; | 119 scoped_refptr<EGLAcceleratedSurface> front_surface_; |
122 gfx::Rect previous_damage_rect_; | 120 gfx::Rect previous_damage_rect_; |
123 | 121 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 int x, int y, int width, int height) { | 427 int x, int y, int width, int height) { |
430 | 428 |
431 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 429 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
432 gfx::Size expected_size = back_surface_->size(); | 430 gfx::Size expected_size = back_surface_->size(); |
433 bool surfaces_same_size = front_surface_.get() && | 431 bool surfaces_same_size = front_surface_.get() && |
434 front_surface_->size() == expected_size; | 432 front_surface_->size() == expected_size; |
435 | 433 |
436 const gfx::Rect new_damage_rect = gfx::Rect(x, y, width, height); | 434 const gfx::Rect new_damage_rect = gfx::Rect(x, y, width, height); |
437 if (surfaces_same_size) { | 435 if (surfaces_same_size) { |
438 std::vector<gfx::Rect> regions_to_copy; | 436 std::vector<gfx::Rect> regions_to_copy; |
439 GetRegionsToCopy(new_damage_rect, ®ions_to_copy); | 437 GetRegionsToCopy(previous_damage_rect_, new_damage_rect, ®ions_to_copy); |
440 | 438 |
441 GLint previous_texture_id = 0; | 439 GLint previous_texture_id = 0; |
442 glGetIntegerv(GL_ACTIVE_TEXTURE, &previous_texture_id); | 440 glGetIntegerv(GL_ACTIVE_TEXTURE, &previous_texture_id); |
443 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 441 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
444 GL_COLOR_ATTACHMENT0, | 442 GL_COLOR_ATTACHMENT0, |
445 GL_TEXTURE_2D, | 443 GL_TEXTURE_2D, |
446 front_surface_->texture(), | 444 front_surface_->texture(), |
447 0); | 445 0); |
448 glBindTexture(GL_TEXTURE_2D, back_surface_->texture()); | 446 glBindTexture(GL_TEXTURE_2D, back_surface_->texture()); |
449 | 447 |
(...skipping 30 matching lines...) Expand all Loading... |
480 params.surface_handle = front_surface_->pixmap(); | 478 params.surface_handle = front_surface_->pixmap(); |
481 params.x = x; | 479 params.x = x; |
482 params.y = y; | 480 params.y = y; |
483 params.width = width; | 481 params.width = width; |
484 params.height = height; | 482 params.height = height; |
485 | 483 |
486 helper_->SendAcceleratedSurfacePostSubBuffer(params); | 484 helper_->SendAcceleratedSurfacePostSubBuffer(params); |
487 helper_->SetScheduled(false); | 485 helper_->SetScheduled(false); |
488 } | 486 } |
489 | 487 |
490 void EGLImageTransportSurface::GetRegionsToCopy( | |
491 const gfx::Rect& new_damage_rect, | |
492 std::vector<gfx::Rect>* regions) { | |
493 DCHECK(front_surface_->size() == back_surface_->size()); | |
494 gfx::Rect intersection = previous_damage_rect_.Intersect(new_damage_rect); | |
495 | |
496 if (intersection.IsEmpty()) { | |
497 regions->push_back(previous_damage_rect_); | |
498 return; | |
499 } | |
500 | |
501 // Top (above the intersection). | |
502 regions->push_back(gfx::Rect(previous_damage_rect_.x(), | |
503 previous_damage_rect_.y(), | |
504 previous_damage_rect_.width(), | |
505 intersection.y() - previous_damage_rect_.y())); | |
506 | |
507 // Left (of the intersection). | |
508 regions->push_back(gfx::Rect(previous_damage_rect_.x(), | |
509 intersection.y(), | |
510 intersection.x() - previous_damage_rect_.x(), | |
511 intersection.height())); | |
512 | |
513 // Right (of the intersection). | |
514 regions->push_back(gfx::Rect(intersection.right(), | |
515 intersection.y(), | |
516 previous_damage_rect_.right() - intersection.right(), | |
517 intersection.height())); | |
518 | |
519 // Bottom (below the intersection). | |
520 regions->push_back(gfx::Rect(previous_damage_rect_.x(), | |
521 intersection.bottom(), | |
522 previous_damage_rect_.width(), | |
523 previous_damage_rect_.bottom() - intersection.bottom())); | |
524 } | |
525 | |
526 std::string EGLImageTransportSurface::GetExtensions() { | 488 std::string EGLImageTransportSurface::GetExtensions() { |
527 std::string extensions = gfx::GLSurface::GetExtensions(); | 489 std::string extensions = gfx::GLSurface::GetExtensions(); |
528 extensions += extensions.empty() ? "" : " "; | 490 extensions += extensions.empty() ? "" : " "; |
529 extensions += "GL_CHROMIUM_front_buffer_cached "; | 491 extensions += "GL_CHROMIUM_front_buffer_cached "; |
530 extensions += "GL_CHROMIUM_post_sub_buffer"; | 492 extensions += "GL_CHROMIUM_post_sub_buffer"; |
531 return extensions; | 493 return extensions; |
532 } | 494 } |
533 | 495 |
534 gfx::Size EGLImageTransportSurface::GetSize() { | 496 gfx::Size EGLImageTransportSurface::GetSize() { |
535 return back_surface_->size(); | 497 return back_surface_->size(); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 stub, | 933 stub, |
972 surface.get(), | 934 surface.get(), |
973 handle.transport); | 935 handle.transport); |
974 } | 936 } |
975 | 937 |
976 if (surface->Initialize()) | 938 if (surface->Initialize()) |
977 return surface; | 939 return surface; |
978 else | 940 else |
979 return NULL; | 941 return NULL; |
980 } | 942 } |
OLD | NEW |