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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 11475017: Revert 171569 as it broke some browser_tests on win_aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 29 matching lines...) Expand all
40 #include "ui/aura/root_window.h" 40 #include "ui/aura/root_window.h"
41 #include "ui/aura/window.h" 41 #include "ui/aura/window.h"
42 #include "ui/aura/window_observer.h" 42 #include "ui/aura/window_observer.h"
43 #include "ui/aura/window_tracker.h" 43 #include "ui/aura/window_tracker.h"
44 #include "ui/base/clipboard/scoped_clipboard_writer.h" 44 #include "ui/base/clipboard/scoped_clipboard_writer.h"
45 #include "ui/base/events/event.h" 45 #include "ui/base/events/event.h"
46 #include "ui/base/gestures/gesture_recognizer.h" 46 #include "ui/base/gestures/gesture_recognizer.h"
47 #include "ui/base/hit_test.h" 47 #include "ui/base/hit_test.h"
48 #include "ui/base/ime/input_method.h" 48 #include "ui/base/ime/input_method.h"
49 #include "ui/base/ui_base_types.h" 49 #include "ui/base/ui_base_types.h"
50 #include "ui/compositor/compositor.h"
50 #include "ui/compositor/layer.h" 51 #include "ui/compositor/layer.h"
51 #include "ui/gfx/canvas.h" 52 #include "ui/gfx/canvas.h"
52 #include "ui/gfx/display.h" 53 #include "ui/gfx/display.h"
53 #include "ui/gfx/rect_conversions.h" 54 #include "ui/gfx/rect_conversions.h"
54 #include "ui/gfx/screen.h" 55 #include "ui/gfx/screen.h"
55 #include "ui/gfx/skia_util.h" 56 #include "ui/gfx/skia_util.h"
56 57
57 #if defined(OS_WIN) 58 #if defined(OS_WIN)
58 #include "ui/base/win/hidden_window.h" 59 #include "ui/base/win/hidden_window.h"
59 #endif 60 #endif
60 61
61 using gfx::RectToSkIRect;
62 using gfx::SkIRectToRect;
63
64 using WebKit::WebScreenInfo; 62 using WebKit::WebScreenInfo;
65 using WebKit::WebTouchEvent; 63 using WebKit::WebTouchEvent;
66 64
67 namespace content { 65 namespace content {
68 namespace { 66 namespace {
69 67
70 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting 68 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting
71 // the border of the view, in order to get valid movement information. However, 69 // the border of the view, in order to get valid movement information. However,
72 // forcing the cursor back to the center of the view after each mouse move 70 // forcing the cursor back to the center of the view after each mouse move
73 // doesn't work well. It reduces the frequency of useful mouse move messages 71 // doesn't work well. It reduces the frequency of useful mouse move messages
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 private: 268 private:
271 aura::RootWindow* root_window_; 269 aura::RootWindow* root_window_;
272 gfx::Size new_size_; 270 gfx::Size new_size_;
273 scoped_refptr<ui::CompositorLock> compositor_lock_; 271 scoped_refptr<ui::CompositorLock> compositor_lock_;
274 base::WeakPtrFactory<ResizeLock> weak_ptr_factory_; 272 base::WeakPtrFactory<ResizeLock> weak_ptr_factory_;
275 bool defer_compositor_lock_; 273 bool defer_compositor_lock_;
276 274
277 DISALLOW_COPY_AND_ASSIGN(ResizeLock); 275 DISALLOW_COPY_AND_ASSIGN(ResizeLock);
278 }; 276 };
279 277
280 RenderWidgetHostViewAura::BufferPresentedParams::BufferPresentedParams(
281 int route_id,
282 int gpu_host_id,
283 uint64 surface_handle)
284 : route_id(route_id),
285 gpu_host_id(gpu_host_id),
286 surface_handle(surface_handle) {
287 }
288
289 RenderWidgetHostViewAura::BufferPresentedParams::~BufferPresentedParams() {
290 }
291
292 //////////////////////////////////////////////////////////////////////////////// 278 ////////////////////////////////////////////////////////////////////////////////
293 // RenderWidgetHostViewAura, public: 279 // RenderWidgetHostViewAura, public:
294 280
295 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) 281 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
296 : host_(RenderWidgetHostImpl::From(host)), 282 : host_(RenderWidgetHostImpl::From(host)),
297 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), 283 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
298 in_shutdown_(false), 284 in_shutdown_(false),
299 is_fullscreen_(false), 285 is_fullscreen_(false),
300 popup_parent_host_view_(NULL), 286 popup_parent_host_view_(NULL),
301 popup_child_host_view_(NULL), 287 popup_child_host_view_(NULL),
302 is_loading_(false), 288 is_loading_(false),
303 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 289 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
304 can_compose_inline_(true), 290 can_compose_inline_(true),
305 has_composition_text_(false), 291 has_composition_text_(false),
306 device_scale_factor_(1.0f), 292 device_scale_factor_(1.0f),
307 current_surface_(0), 293 current_surface_(0),
294 current_surface_is_protected_(true),
295 current_surface_in_use_by_compositor_(true),
296 protection_state_id_(0),
297 surface_route_id_(0),
308 paint_canvas_(NULL), 298 paint_canvas_(NULL),
309 synthetic_move_sent_(false), 299 synthetic_move_sent_(false),
310 accelerated_compositing_state_changed_(false), 300 accelerated_compositing_state_changed_(false),
311 can_lock_compositor_(YES) { 301 can_lock_compositor_(YES) {
312 host_->SetView(this); 302 host_->SetView(this);
313 window_observer_.reset(new WindowObserver(this)); 303 window_observer_.reset(new WindowObserver(this));
314 window_->AddObserver(window_observer_.get()); 304 window_->AddObserver(window_observer_.get());
315 aura::client::SetTooltipText(window_, &tooltip_); 305 aura::client::SetTooltipText(window_, &tooltip_);
316 aura::client::SetActivationDelegate(window_, this); 306 aura::client::SetActivationDelegate(window_, this);
317 gfx::Screen::GetScreenFor(window_)->AddObserver(this); 307 gfx::Screen::GetScreenFor(window_)->AddObserver(this);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 void RenderWidgetHostViewAura::WasShown() { 388 void RenderWidgetHostViewAura::WasShown() {
399 if (!host_->is_hidden()) 389 if (!host_->is_hidden())
400 return; 390 return;
401 host_->WasShown(); 391 host_->WasShown();
402 392
403 if (!current_surface_ && host_->is_accelerated_compositing_active() && 393 if (!current_surface_ && host_->is_accelerated_compositing_active() &&
404 !released_front_lock_.get()) { 394 !released_front_lock_.get()) {
405 released_front_lock_ = GetCompositor()->GetCompositorLock(); 395 released_front_lock_ = GetCompositor()->GetCompositorLock();
406 } 396 }
407 397
398 AdjustSurfaceProtection();
399
408 #if defined(OS_WIN) 400 #if defined(OS_WIN)
409 LPARAM lparam = reinterpret_cast<LPARAM>(this); 401 LPARAM lparam = reinterpret_cast<LPARAM>(this);
410 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); 402 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam);
411 #endif 403 #endif
412 } 404 }
413 405
414 void RenderWidgetHostViewAura::WasHidden() { 406 void RenderWidgetHostViewAura::WasHidden() {
415 if (host_->is_hidden()) 407 if (host_->is_hidden())
416 return; 408 return;
417 host_->WasHidden(); 409 host_->WasHidden();
418 410
419 released_front_lock_ = NULL; 411 released_front_lock_ = NULL;
420 412
413 if (ShouldReleaseFrontSurface() &&
414 host_->is_accelerated_compositing_active()) {
415 current_surface_ = 0;
416 UpdateExternalTexture();
417 }
418
419 AdjustSurfaceProtection();
420
421 #if defined(OS_WIN) 421 #if defined(OS_WIN)
422 aura::RootWindow* root_window = window_->GetRootWindow(); 422 aura::RootWindow* root_window = window_->GetRootWindow();
423 if (root_window) { 423 if (root_window) {
424 HWND parent = root_window->GetAcceleratedWidget(); 424 HWND parent = root_window->GetAcceleratedWidget();
425 LPARAM lparam = reinterpret_cast<LPARAM>(this); 425 LPARAM lparam = reinterpret_cast<LPARAM>(this);
426 426
427 EnumChildWindows(parent, HideWindowsCallback, lparam); 427 EnumChildWindows(parent, HideWindowsCallback, lparam);
428 } 428 }
429 #endif 429 #endif
430 } 430 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 718
719 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 719 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
720 GLHelper* gl_helper = factory->GetGLHelper(); 720 GLHelper* gl_helper = factory->GetGLHelper();
721 if (!gl_helper) 721 if (!gl_helper)
722 return; 722 return;
723 723
724 unsigned char* addr = static_cast<unsigned char*>( 724 unsigned char* addr = static_cast<unsigned char*>(
725 output->GetBitmap().getPixels()); 725 output->GetBitmap().getPixels());
726 scoped_callback_runner.Release(); 726 scoped_callback_runner.Release();
727 // Wrap the callback with an internal handler so that we can inject our 727 // Wrap the callback with an internal handler so that we can inject our
728 // own completion handlers (where we can try to free the frontbuffer). 728 // own completion handlers (where we can call AdjustSurfaceProtection).
729 base::Callback<void(bool)> wrapper_callback = base::Bind( 729 base::Callback<void(bool)> wrapper_callback = base::Bind(
730 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished, 730 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished,
731 AsWeakPtr(), 731 AsWeakPtr(),
732 callback); 732 callback);
733 ++pending_thumbnail_tasks_; 733 ++pending_thumbnail_tasks_;
734 734
735 // Convert |src_subrect| from the views coordinate (upper-left origin) into 735 // Convert |src_subrect| from the views coordinate (upper-left origin) into
736 // the OpenGL coordinate (lower-left origin). 736 // the OpenGL coordinate (lower-left origin).
737 gfx::Rect src_subrect_in_gl = src_subrect; 737 gfx::Rect src_subrect_in_gl = src_subrect;
738 src_subrect_in_gl.set_y(GetViewBounds().height() - src_subrect.bottom()); 738 src_subrect_in_gl.set_y(GetViewBounds().height() - src_subrect.bottom());
(...skipping 12 matching lines...) Expand all
751 // switching to software mode or receive a buffers swapped notification 751 // switching to software mode or receive a buffers swapped notification
752 // if switching to accelerated mode. 752 // if switching to accelerated mode.
753 // Sometimes (e.g. on a page load) the renderer will spuriously disable then 753 // Sometimes (e.g. on a page load) the renderer will spuriously disable then
754 // re-enable accelerated compositing, causing us to flash. 754 // re-enable accelerated compositing, causing us to flash.
755 // TODO(piman): factor the enable/disable accelerated compositing message into 755 // TODO(piman): factor the enable/disable accelerated compositing message into
756 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have 756 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have
757 // fewer inconsistent temporary states. 757 // fewer inconsistent temporary states.
758 accelerated_compositing_state_changed_ = true; 758 accelerated_compositing_state_changed_ = true;
759 } 759 }
760 760
761 bool RenderWidgetHostViewAura::ShouldSkipFrame(const gfx::Size& size) { 761 bool RenderWidgetHostViewAura::ShouldFastACK(uint64 surface_id) {
762 ui::Texture* container = image_transport_clients_[surface_id];
763 DCHECK(container);
764
762 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || 765 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME ||
763 can_lock_compositor_ == NO_PENDING_COMMIT || 766 can_lock_compositor_ == NO_PENDING_COMMIT ||
764 resize_locks_.empty()) 767 resize_locks_.empty())
765 return false; 768 return false;
766 769
767 gfx::Size container_size = ConvertSizeToDIP(this, size); 770 gfx::Size container_size = ConvertSizeToDIP(this, container->size());
768 ResizeLockList::iterator it = resize_locks_.begin(); 771 ResizeLockList::iterator it = resize_locks_.begin();
769 while (it != resize_locks_.end()) { 772 while (it != resize_locks_.end()) {
770 if ((*it)->expected_size() == container_size) 773 if ((*it)->expected_size() == container_size)
771 break; 774 break;
772 ++it; 775 ++it;
773 } 776 }
774 777
775 // We could be getting an unexpected frame due to an animation 778 // We could be getting an unexpected frame due to an animation
776 // (i.e. we start resizing but we get an old size frame first). 779 // (i.e. we start resizing but we get an old size frame first).
777 return it == resize_locks_.end() || ++it != resize_locks_.end(); 780 return it == resize_locks_.end() || ++it != resize_locks_.end();
778 } 781 }
779 782
780 void RenderWidgetHostViewAura::UpdateExternalTexture() { 783 void RenderWidgetHostViewAura::UpdateExternalTexture() {
781 // Delay processing accelerated compositing state change till here where we 784 // Delay processing accelerated compositing state change till here where we
782 // act upon the state change. (Clear the external texture if switching to 785 // act upon the state change. (Clear the external texture if switching to
783 // software mode or set the external texture if going to accelerated mode). 786 // software mode or set the external texture if going to accelerated mode).
784 if (accelerated_compositing_state_changed_) 787 if (accelerated_compositing_state_changed_)
785 accelerated_compositing_state_changed_ = false; 788 accelerated_compositing_state_changed_ = false;
786 789
787 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) { 790 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) {
788 ui::Texture* container = image_transport_clients_[current_surface_]; 791 ui::Texture* container = image_transport_clients_[current_surface_];
789 window_->SetExternalTexture(container); 792 window_->SetExternalTexture(container);
793 current_surface_in_use_by_compositor_ = true;
790 794
791 if (!container) { 795 if (!container) {
792 resize_locks_.clear(); 796 resize_locks_.clear();
793 } else { 797 } else {
794 ResizeLockList::iterator it = resize_locks_.begin(); 798 ResizeLockList::iterator it = resize_locks_.begin();
795 while (it != resize_locks_.end()) { 799 while (it != resize_locks_.end()) {
796 gfx::Size container_size = ConvertSizeToDIP(this, 800 gfx::Size container_size = ConvertSizeToDIP(this,
797 container->size()); 801 container->size());
798 if ((*it)->expected_size() == container_size) 802 if ((*it)->expected_size() == container_size)
799 break; 803 break;
(...skipping 15 matching lines...) Expand all
815 it2->get()->UnlockCompositor(); 819 it2->get()->UnlockCompositor();
816 } 820 }
817 if (!compositor->HasObserver(this)) 821 if (!compositor->HasObserver(this))
818 compositor->AddObserver(this); 822 compositor->AddObserver(this);
819 } 823 }
820 resize_locks_.erase(resize_locks_.begin(), it); 824 resize_locks_.erase(resize_locks_.begin(), it);
821 } 825 }
822 } 826 }
823 } else { 827 } else {
824 window_->SetExternalTexture(NULL); 828 window_->SetExternalTexture(NULL);
829 if (ShouldReleaseFrontSurface() &&
830 host_->is_accelerated_compositing_active()) {
831 // We need to wait for a commit to clear to guarantee that all we
832 // will not issue any more GL referencing the previous surface.
833 ui::Compositor* compositor = GetCompositor();
834 if (compositor) {
835 can_lock_compositor_ = NO_PENDING_COMMIT;
836 on_compositing_did_commit_callbacks_.push_back(
837 base::Bind(&RenderWidgetHostViewAura::
838 SetSurfaceNotInUseByCompositor,
839 AsWeakPtr()));
840 if (!compositor->HasObserver(this))
841 compositor->AddObserver(this);
842 }
843 }
825 resize_locks_.clear(); 844 resize_locks_.clear();
826 } 845 }
827 } 846 }
828 847
829 bool RenderWidgetHostViewAura::SwapBuffersPrepare(
830 const gfx::Rect& surface_rect,
831 const gfx::Rect& damage_rect,
832 BufferPresentedParams* params) {
833 DCHECK(params->surface_handle);
834 DCHECK(!params->texture_to_produce);
835
836 if (last_swapped_surface_size_ != surface_rect.size()) {
837 // The surface could have shrunk since we skipped an update, in which
838 // case we can expect a full update.
839 DLOG_IF(ERROR, damage_rect != surface_rect) << "Expected full damage rect";
840 skipped_damage_.setEmpty();
841 last_swapped_surface_size_ = surface_rect.size();
842 }
843
844 if (ShouldSkipFrame(surface_rect.size())) {
845 skipped_damage_.op(RectToSkIRect(damage_rect), SkRegion::kUnion_Op);
846 InsertSyncPointAndACK(*params);
847 return false;
848 }
849
850 DCHECK(!current_surface_ || image_transport_clients_.find(current_surface_) !=
851 image_transport_clients_.end());
852 if (current_surface_)
853 params->texture_to_produce = image_transport_clients_[current_surface_];
854
855 std::swap(current_surface_, params->surface_handle);
856
857 DCHECK(image_transport_clients_.find(current_surface_) !=
858 image_transport_clients_.end());
859
860 image_transport_clients_[current_surface_]->Consume(surface_rect.size());
861 released_front_lock_ = NULL;
862 UpdateExternalTexture();
863
864 return true;
865 }
866
867 void RenderWidgetHostViewAura::SwapBuffersCompleted(
868 const BufferPresentedParams& params) {
869 ui::Compositor* compositor = GetCompositor();
870 if (!compositor) {
871 InsertSyncPointAndACK(params);
872 } else {
873 // Add sending an ACK to the list of things to do OnCompositingDidCommit
874 can_lock_compositor_ = NO_PENDING_COMMIT;
875 on_compositing_did_commit_callbacks_.push_back(
876 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, params));
877 if (!compositor->HasObserver(this))
878 compositor->AddObserver(this);
879 }
880 }
881
882 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( 848 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
883 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, 849 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
884 int gpu_host_id) { 850 int gpu_host_id) {
885 const gfx::Rect surface_rect = gfx::Rect(gfx::Point(), params_in_pixel.size); 851 surface_route_id_ = params_in_pixel.route_id;
886 BufferPresentedParams ack_params( 852 // If protection state changed, then this swap is stale. We must still ACK but
887 params_in_pixel.route_id, gpu_host_id, params_in_pixel.surface_handle); 853 // do not update current_surface_ since it may have been discarded.
888 if (!SwapBuffersPrepare(surface_rect, surface_rect, &ack_params)) 854 if (params_in_pixel.protection_state_id &&
855 params_in_pixel.protection_state_id != protection_state_id_) {
856 DCHECK(!current_surface_);
857 if (!params_in_pixel.skip_ack)
858 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL);
889 return; 859 return;
860 }
890 861
891 previous_damage_.setRect(RectToSkIRect(surface_rect)); 862 if (ShouldFastACK(params_in_pixel.surface_handle)) {
892 skipped_damage_.setEmpty(); 863 if (!params_in_pixel.skip_ack)
864 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL);
865 return;
866 }
867
868 current_surface_ = params_in_pixel.surface_handle;
869 // If we don't require an ACK that means the content is not a fresh updated
870 // new frame, rather we are just resetting our handle to some old content
871 // that we still hadn't discarded. Although we could display immediately,
872 // by not resetting the compositor lock here, we give us some time to get
873 // a fresh frame which means fewer content flashes.
874 if (!params_in_pixel.skip_ack)
875 released_front_lock_ = NULL;
876
877 UpdateExternalTexture();
893 878
894 ui::Compositor* compositor = GetCompositor(); 879 ui::Compositor* compositor = GetCompositor();
895 if (compositor) { 880 if (!compositor) {
896 gfx::Size surface_size = ConvertSizeToDIP(this, params_in_pixel.size); 881 if (!params_in_pixel.skip_ack)
882 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, true, NULL);
883 } else {
884 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) !=
885 image_transport_clients_.end());
886 gfx::Size surface_size_in_pixel =
887 image_transport_clients_[params_in_pixel.surface_handle]->size();
888 gfx::Size surface_size = ConvertSizeToDIP(this, surface_size_in_pixel);
897 window_->SchedulePaintInRect(gfx::Rect(surface_size)); 889 window_->SchedulePaintInRect(gfx::Rect(surface_size));
890
891 if (!params_in_pixel.skip_ack) {
892 // Add sending an ACK to the list of things to do OnCompositingDidCommit
893 can_lock_compositor_ = NO_PENDING_COMMIT;
894 on_compositing_did_commit_callbacks_.push_back(
895 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
896 params_in_pixel.route_id,
897 gpu_host_id,
898 true));
899 if (!compositor->HasObserver(this))
900 compositor->AddObserver(this);
901 }
898 } 902 }
899
900 SwapBuffersCompleted(ack_params);
901 } 903 }
902 904
903 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( 905 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
904 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, 906 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
905 int gpu_host_id) { 907 int gpu_host_id) {
906 const gfx::Rect surface_rect = 908 surface_route_id_ = params_in_pixel.route_id;
907 gfx::Rect(gfx::Point(), params_in_pixel.surface_size); 909 // If visible state changed, then this PSB is stale. We must still ACK but
908 gfx::Rect damage_rect(params_in_pixel.x, 910 // do not update current_surface_.
909 params_in_pixel.y, 911 if (params_in_pixel.protection_state_id &&
910 params_in_pixel.width, 912 params_in_pixel.protection_state_id != protection_state_id_) {
911 params_in_pixel.height); 913 DCHECK(!current_surface_);
912 BufferPresentedParams ack_params( 914 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL);
913 params_in_pixel.route_id, gpu_host_id, params_in_pixel.surface_handle);
914 if (!SwapBuffersPrepare(surface_rect, damage_rect, &ack_params))
915 return; 915 return;
916
917 SkRegion damage(RectToSkIRect(damage_rect));
918 if (!skipped_damage_.isEmpty()) {
919 damage.op(skipped_damage_, SkRegion::kUnion_Op);
920 skipped_damage_.setEmpty();
921 } 916 }
922 917
923 DCHECK(surface_rect.Contains(SkIRectToRect(damage.getBounds()))); 918 if (ShouldFastACK(params_in_pixel.surface_handle)) {
924 ui::Texture* current_texture = image_transport_clients_[current_surface_]; 919 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL);
920 return;
921 }
925 922
926 const gfx::Size surface_size_in_pixel = params_in_pixel.surface_size; 923 current_surface_ = params_in_pixel.surface_handle;
927 DLOG_IF(ERROR, ack_params.texture_to_produce && 924 released_front_lock_ = NULL;
928 ack_params.texture_to_produce->size() != current_texture->size() && 925 DCHECK(current_surface_);
929 SkIRectToRect(damage.getBounds()) != surface_rect) << 926 UpdateExternalTexture();
930 "Expected full damage rect after size change";
931 if (ack_params.texture_to_produce && !previous_damage_.isEmpty() &&
932 ack_params.texture_to_produce->size() == current_texture->size()) {
933 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
934 GLHelper* gl_helper = factory->GetGLHelper();
935 gl_helper->CopySubBufferDamage(
936 current_texture->PrepareTexture(),
937 ack_params.texture_to_produce->PrepareTexture(),
938 damage,
939 previous_damage_);
940 }
941 previous_damage_ = damage;
942 927
943 ui::Compositor* compositor = GetCompositor(); 928 ui::Compositor* compositor = GetCompositor();
944 if (compositor) { 929 if (!compositor) {
930 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, true, NULL);
931 } else {
932 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) !=
933 image_transport_clients_.end());
934 gfx::Size surface_size_in_pixel =
935 image_transport_clients_[params_in_pixel.surface_handle]->size();
936
945 // Co-ordinates come in OpenGL co-ordinate space. 937 // Co-ordinates come in OpenGL co-ordinate space.
946 // We need to convert to layer space. 938 // We need to convert to layer space.
947 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect( 939 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect(
948 params_in_pixel.x, 940 params_in_pixel.x,
949 surface_size_in_pixel.height() - params_in_pixel.y - 941 surface_size_in_pixel.height() - params_in_pixel.y -
950 params_in_pixel.height, 942 params_in_pixel.height,
951 params_in_pixel.width, 943 params_in_pixel.width,
952 params_in_pixel.height)); 944 params_in_pixel.height));
953 945
954 // Damage may not have been DIP aligned, so inflate damage to compensate 946 // Damage may not have been DIP aligned, so inflate damage to compensate
955 // for any round-off error. 947 // for any round-off error.
956 rect_to_paint.Inset(-1, -1); 948 rect_to_paint.Inset(-1, -1);
957 rect_to_paint.Intersect(window_->bounds()); 949 rect_to_paint.Intersect(window_->bounds());
958 950
959 window_->SchedulePaintInRect(rect_to_paint); 951 window_->SchedulePaintInRect(rect_to_paint);
952
953 // Add sending an ACK to the list of things to do OnCompositingDidCommit
954 can_lock_compositor_ = NO_PENDING_COMMIT;
955 on_compositing_did_commit_callbacks_.push_back(
956 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
957 params_in_pixel.route_id,
958 gpu_host_id,
959 true));
960 if (!compositor->HasObserver(this))
961 compositor->AddObserver(this);
960 } 962 }
961
962 SwapBuffersCompleted(ack_params);
963 } 963 }
964 964
965 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { 965 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() {
966 } 966 }
967 967
968 bool RenderWidgetHostViewAura::HasAcceleratedSurface( 968 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
969 const gfx::Size& desired_size) { 969 const gfx::Size& desired_size) {
970 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't 970 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't
971 // matter what is returned here as GetBackingStore is the only caller of this 971 // matter what is returned here as GetBackingStore is the only caller of this
972 // method. TODO(jbates) implement this if other Aura code needs it. 972 // method. TODO(jbates) implement this if other Aura code needs it.
973 return false; 973 return false;
974 } 974 }
975 975
976 // TODO(backer): Drop the |shm_handle| once I remove some unused service side 976 // TODO(backer): Drop the |shm_handle| once I remove some unused service side
977 // code. 977 // code.
978 void RenderWidgetHostViewAura::AcceleratedSurfaceNew( 978 void RenderWidgetHostViewAura::AcceleratedSurfaceNew(
979 int32 width_in_pixel, 979 int32 width_in_pixel,
980 int32 height_in_pixel, 980 int32 height_in_pixel,
981 uint64 surface_handle, 981 uint64 surface_handle) {
982 const std::string& mailbox_name) {
983 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 982 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
984 scoped_refptr<ui::Texture> surface(factory->CreateTransportClient( 983 scoped_refptr<ui::Texture> surface(factory->CreateTransportClient(
985 gfx::Size(width_in_pixel, height_in_pixel), device_scale_factor_, 984 gfx::Size(width_in_pixel, height_in_pixel), device_scale_factor_,
986 mailbox_name)); 985 surface_handle));
987 if (!surface) { 986 if (!surface) {
988 LOG(ERROR) << "Failed to create ImageTransport texture"; 987 LOG(ERROR) << "Failed to create ImageTransport texture";
989 return; 988 return;
990 } 989 }
990
991 image_transport_clients_[surface_handle] = surface; 991 image_transport_clients_[surface_handle] = surface;
992 } 992 }
993 993
994 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { 994 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease(
995 // This really tells us to release the frontbuffer. 995 uint64 surface_handle) {
996 if (current_surface_ && ShouldReleaseFrontSurface()) { 996 DCHECK(image_transport_clients_.find(surface_handle) !=
997 ui::Compositor* compositor = GetCompositor(); 997 image_transport_clients_.end());
998 if (compositor) { 998 if (current_surface_ == surface_handle) {
999 // We need to wait for a commit to clear to guarantee that all we
1000 // will not issue any more GL referencing the previous surface.
1001 can_lock_compositor_ = NO_PENDING_COMMIT;
1002 scoped_refptr<ui::Texture> surface_ref =
1003 image_transport_clients_[current_surface_];
1004 on_compositing_did_commit_callbacks_.push_back(
1005 base::Bind(&RenderWidgetHostViewAura::
1006 SetSurfaceNotInUseByCompositor,
1007 AsWeakPtr(),
1008 surface_ref));
1009 if (!compositor->HasObserver(this))
1010 compositor->AddObserver(this);
1011 }
1012 image_transport_clients_.erase(current_surface_);
1013 current_surface_ = 0; 999 current_surface_ = 0;
1014 UpdateExternalTexture(); 1000 UpdateExternalTexture();
1015 } 1001 }
1002 image_transport_clients_.erase(surface_handle);
1016 } 1003 }
1017 1004
1018 void RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor( 1005 void RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor(ui::Compositor*) {
1019 scoped_refptr<ui::Texture>) { 1006 if (current_surface_ || !host_->is_hidden())
1007 return;
1008 current_surface_in_use_by_compositor_ = false;
1009 AdjustSurfaceProtection();
1010 }
1011
1012 void RenderWidgetHostViewAura::AdjustSurfaceProtection() {
1013 // If the current surface is non null, it is protected.
1014 // If we are visible, it is protected.
1015 // Otherwise, change to not proctected once done thumbnailing and compositing.
1016 bool surface_is_protected =
1017 current_surface_ ||
1018 !host_->is_hidden() ||
1019 (current_surface_is_protected_ &&
1020 (pending_thumbnail_tasks_ > 0 ||
1021 current_surface_in_use_by_compositor_));
1022 if (current_surface_is_protected_ == surface_is_protected)
1023 return;
1024 current_surface_is_protected_ = surface_is_protected;
1025 ++protection_state_id_;
1026
1027 if (!surface_route_id_ || !shared_surface_handle_.parent_gpu_process_id)
1028 return;
1029
1030 RenderWidgetHostImpl::SendFrontSurfaceIsProtected(
1031 surface_is_protected,
1032 protection_state_id_,
1033 surface_route_id_,
1034 shared_surface_handle_.parent_gpu_process_id);
1020 } 1035 }
1021 1036
1022 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished( 1037 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished(
1023 base::WeakPtr<RenderWidgetHostViewAura> render_widget_host_view, 1038 base::WeakPtr<RenderWidgetHostViewAura> render_widget_host_view,
1024 const base::Callback<void(bool)>& callback, 1039 const base::Callback<void(bool)>& callback,
1025 bool result) { 1040 bool result) {
1026 callback.Run(result); 1041 callback.Run(result);
1027 1042
1028 if (!render_widget_host_view.get()) 1043 if (!render_widget_host_view.get())
1029 return; 1044 return;
1030 --render_widget_host_view->pending_thumbnail_tasks_; 1045 --render_widget_host_view->pending_thumbnail_tasks_;
1046 render_widget_host_view->AdjustSurfaceProtection();
1031 } 1047 }
1032 1048
1033 void RenderWidgetHostViewAura::SetBackground(const SkBitmap& background) { 1049 void RenderWidgetHostViewAura::SetBackground(const SkBitmap& background) {
1034 RenderWidgetHostViewBase::SetBackground(background); 1050 RenderWidgetHostViewBase::SetBackground(background);
1035 host_->SetBackground(background); 1051 host_->SetBackground(background);
1036 window_->layer()->SetFillsBoundsOpaquely(background.isOpaque()); 1052 window_->layer()->SetFillsBoundsOpaquely(background.isOpaque());
1037 } 1053 }
1038 1054
1039 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) { 1055 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) {
1040 GetScreenInfoForWindow(results, window_); 1056 GetScreenInfoForWindow(results, window_);
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 1756
1741 void RenderWidgetHostViewAura::OnCompositingDidCommit( 1757 void RenderWidgetHostViewAura::OnCompositingDidCommit(
1742 ui::Compositor* compositor) { 1758 ui::Compositor* compositor) {
1743 if (can_lock_compositor_ == NO_PENDING_COMMIT) { 1759 if (can_lock_compositor_ == NO_PENDING_COMMIT) {
1744 can_lock_compositor_ = YES; 1760 can_lock_compositor_ = YES;
1745 for (ResizeLockList::iterator it = resize_locks_.begin(); 1761 for (ResizeLockList::iterator it = resize_locks_.begin();
1746 it != resize_locks_.end(); ++it) 1762 it != resize_locks_.end(); ++it)
1747 if ((*it)->GrabDeferredLock()) 1763 if ((*it)->GrabDeferredLock())
1748 can_lock_compositor_ = YES_DID_LOCK; 1764 can_lock_compositor_ = YES_DID_LOCK;
1749 } 1765 }
1750 RunCompositingDidCommitCallbacks(); 1766 RunCompositingDidCommitCallbacks(compositor);
1751 locks_pending_commit_.clear(); 1767 locks_pending_commit_.clear();
1752 } 1768 }
1753 1769
1754 void RenderWidgetHostViewAura::OnCompositingStarted( 1770 void RenderWidgetHostViewAura::OnCompositingStarted(
1755 ui::Compositor* compositor) { 1771 ui::Compositor* compositor) {
1756 } 1772 }
1757 1773
1758 void RenderWidgetHostViewAura::OnCompositingEnded( 1774 void RenderWidgetHostViewAura::OnCompositingEnded(
1759 ui::Compositor* compositor) { 1775 ui::Compositor* compositor) {
1760 } 1776 }
(...skipping 10 matching lines...) Expand all
1771 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; 1787 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME;
1772 } 1788 }
1773 } 1789 }
1774 1790
1775 //////////////////////////////////////////////////////////////////////////////// 1791 ////////////////////////////////////////////////////////////////////////////////
1776 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: 1792 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation:
1777 1793
1778 void RenderWidgetHostViewAura::OnLostResources() { 1794 void RenderWidgetHostViewAura::OnLostResources() {
1779 image_transport_clients_.clear(); 1795 image_transport_clients_.clear();
1780 current_surface_ = 0; 1796 current_surface_ = 0;
1797 protection_state_id_ = 0;
1798 current_surface_is_protected_ = true;
1799 current_surface_in_use_by_compositor_ = true;
1800 surface_route_id_ = 0;
1781 UpdateExternalTexture(); 1801 UpdateExternalTexture();
1782 locks_pending_commit_.clear(); 1802 locks_pending_commit_.clear();
1783 1803
1784 DCHECK(!shared_surface_handle_.is_null()); 1804 DCHECK(!shared_surface_handle_.is_null());
1785 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1805 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1786 factory->DestroySharedSurfaceHandle(shared_surface_handle_); 1806 factory->DestroySharedSurfaceHandle(shared_surface_handle_);
1787 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); 1807 shared_surface_handle_ = factory->CreateSharedSurfaceHandle();
1788 host_->CompositingSurfaceUpdated(); 1808 host_->CompositingSurfaceUpdated();
1789 host_->ScheduleComposite(); 1809 host_->ScheduleComposite();
1790 } 1810 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 gfx::Rect rect = window_->bounds(); 1932 gfx::Rect rect = window_->bounds();
1913 int border_x = rect.width() * kMouseLockBorderPercentage / 100; 1933 int border_x = rect.width() * kMouseLockBorderPercentage / 100;
1914 int border_y = rect.height() * kMouseLockBorderPercentage / 100; 1934 int border_y = rect.height() * kMouseLockBorderPercentage / 100;
1915 1935
1916 return global_mouse_position_.x() < rect.x() + border_x || 1936 return global_mouse_position_.x() < rect.x() + border_x ||
1917 global_mouse_position_.x() > rect.right() - border_x || 1937 global_mouse_position_.x() > rect.right() - border_x ||
1918 global_mouse_position_.y() < rect.y() + border_y || 1938 global_mouse_position_.y() < rect.y() + border_y ||
1919 global_mouse_position_.y() > rect.bottom() - border_y; 1939 global_mouse_position_.y() > rect.bottom() - border_y;
1920 } 1940 }
1921 1941
1922 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks() { 1942 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks(
1923 for (std::vector<base::Closure>::const_iterator 1943 ui::Compositor* compositor) {
1944 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator
1924 it = on_compositing_did_commit_callbacks_.begin(); 1945 it = on_compositing_did_commit_callbacks_.begin();
1925 it != on_compositing_did_commit_callbacks_.end(); ++it) { 1946 it != on_compositing_did_commit_callbacks_.end(); ++it) {
1926 it->Run(); 1947 it->Run(compositor);
1927 } 1948 }
1928 on_compositing_did_commit_callbacks_.clear(); 1949 on_compositing_did_commit_callbacks_.clear();
1929 } 1950 }
1930 1951
1931 // static 1952 // static
1932 void RenderWidgetHostViewAura::InsertSyncPointAndACK( 1953 void RenderWidgetHostViewAura::InsertSyncPointAndACK(
1933 const BufferPresentedParams& params) { 1954 int32 route_id, int gpu_host_id, bool presented,
1955 ui::Compositor* compositor) {
1934 uint32 sync_point = 0; 1956 uint32 sync_point = 0;
1935 // If we produced a texture, we have to synchronize with the consumer of 1957 // If we have no compositor, so we must still send the ACK. A zero
1936 // that texture. 1958 // sync point will not be waited for in the GPU process.
1937 if (params.texture_to_produce) { 1959 if (compositor) {
1938 params.texture_to_produce->Produce(); 1960 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1939 sync_point = ImageTransportFactory::GetInstance()->InsertSyncPoint(); 1961 sync_point = factory->InsertSyncPoint();
1940 } 1962 }
1941 1963
1942 RenderWidgetHostImpl::AcknowledgeBufferPresent( 1964 RenderWidgetHostImpl::AcknowledgeBufferPresent(
1943 params.route_id, params.gpu_host_id, params.surface_handle, sync_point); 1965 route_id, gpu_host_id, presented, sync_point);
1944 } 1966 }
1945 1967
1946 void RenderWidgetHostViewAura::AddingToRootWindow() { 1968 void RenderWidgetHostViewAura::AddingToRootWindow() {
1947 host_->ParentChanged(GetNativeViewId()); 1969 host_->ParentChanged(GetNativeViewId());
1948 UpdateScreenInfo(window_); 1970 UpdateScreenInfo(window_);
1949 } 1971 }
1950 1972
1951 void RenderWidgetHostViewAura::RemovingFromRootWindow() { 1973 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
1952 host_->ParentChanged(0); 1974 host_->ParentChanged(0);
1953 // We are about to disconnect ourselves from the compositor, we need to issue 1975 // We are about to disconnect ourselves from the compositor, we need to issue
1954 // the callbacks now, because we won't get notified when the frame is done. 1976 // the callbacks now, because we won't get notified when the frame is done.
1955 // TODO(piman): this might in theory cause a race where the GPU process starts 1977 // TODO(piman): this might in theory cause a race where the GPU process starts
1956 // drawing to the buffer we haven't yet displayed. This will only show for 1 1978 // drawing to the buffer we haven't yet displayed. This will only show for 1
1957 // frame though, because we will reissue a new frame right away without that 1979 // frame though, because we will reissue a new frame right away without that
1958 // composited data. 1980 // composited data.
1959 ui::Compositor* compositor = GetCompositor(); 1981 ui::Compositor* compositor = GetCompositor();
1960 RunCompositingDidCommitCallbacks(); 1982 RunCompositingDidCommitCallbacks(compositor);
1961 locks_pending_commit_.clear(); 1983 locks_pending_commit_.clear();
1962 if (compositor && compositor->HasObserver(this)) 1984 if (compositor && compositor->HasObserver(this))
1963 compositor->RemoveObserver(this); 1985 compositor->RemoveObserver(this);
1964 DetachFromInputMethod(); 1986 DetachFromInputMethod();
1965 } 1987 }
1966 1988
1967 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { 1989 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() {
1968 aura::RootWindow* root_window = window_->GetRootWindow(); 1990 aura::RootWindow* root_window = window_->GetRootWindow();
1969 return root_window ? root_window->compositor() : NULL; 1991 return root_window ? root_window->compositor() : NULL;
1970 } 1992 }
(...skipping 12 matching lines...) Expand all
1983 RenderWidgetHost* widget) { 2005 RenderWidgetHost* widget) {
1984 return new RenderWidgetHostViewAura(widget); 2006 return new RenderWidgetHostViewAura(widget);
1985 } 2007 }
1986 2008
1987 // static 2009 // static
1988 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { 2010 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) {
1989 GetScreenInfoForWindow(results, NULL); 2011 GetScreenInfoForWindow(results, NULL);
1990 } 2012 }
1991 2013
1992 } // namespace content 2014 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698