| 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/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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 192 } |
| 193 | 193 |
| 194 private: | 194 private: |
| 195 RenderWidgetHostViewAura* view_; | 195 RenderWidgetHostViewAura* view_; |
| 196 | 196 |
| 197 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 197 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 class RenderWidgetHostViewAura::ResizeLock { | 200 class RenderWidgetHostViewAura::ResizeLock { |
| 201 public: | 201 public: |
| 202 ResizeLock(aura::RootWindow* root_window, const gfx::Size new_size) | 202 ResizeLock(aura::RootWindow* root_window, |
| 203 const gfx::Size new_size, |
| 204 bool defer_compositor_lock) |
| 203 : root_window_(root_window), | 205 : root_window_(root_window), |
| 204 new_size_(new_size), | 206 new_size_(new_size), |
| 205 compositor_lock_(root_window_->GetCompositorLock()), | 207 compositor_lock_(defer_compositor_lock ? |
| 206 weak_ptr_factory_(this) { | 208 NULL : |
| 209 root_window_->compositor()->GetCompositorLock()), |
| 210 weak_ptr_factory_(this), |
| 211 defer_compositor_lock_(defer_compositor_lock) { |
| 207 root_window_->HoldMouseMoves(); | 212 root_window_->HoldMouseMoves(); |
| 208 | 213 |
| 209 BrowserThread::PostDelayedTask( | 214 BrowserThread::PostDelayedTask( |
| 210 BrowserThread::UI, FROM_HERE, | 215 BrowserThread::UI, FROM_HERE, |
| 211 base::Bind(&RenderWidgetHostViewAura::ResizeLock::CancelLock, | 216 base::Bind(&RenderWidgetHostViewAura::ResizeLock::CancelLock, |
| 212 weak_ptr_factory_.GetWeakPtr()), | 217 weak_ptr_factory_.GetWeakPtr()), |
| 213 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs)); | 218 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs)); |
| 214 } | 219 } |
| 215 | 220 |
| 216 ~ResizeLock() { | 221 ~ResizeLock() { |
| 217 CancelLock(); | 222 CancelLock(); |
| 218 } | 223 } |
| 219 | 224 |
| 220 void UnlockCompositor() { | 225 void UnlockCompositor() { |
| 226 defer_compositor_lock_ = false; |
| 221 compositor_lock_ = NULL; | 227 compositor_lock_ = NULL; |
| 222 } | 228 } |
| 223 | 229 |
| 224 void CancelLock() { | 230 void CancelLock() { |
| 225 if (!root_window_) | 231 if (!root_window_) |
| 226 return; | 232 return; |
| 227 UnlockCompositor(); | 233 UnlockCompositor(); |
| 228 root_window_->ReleaseMouseMoves(); | 234 root_window_->ReleaseMouseMoves(); |
| 229 root_window_ = NULL; | 235 root_window_ = NULL; |
| 230 } | 236 } |
| 231 | 237 |
| 232 const gfx::Size& expected_size() const { | 238 const gfx::Size& expected_size() const { |
| 233 return new_size_; | 239 return new_size_; |
| 234 } | 240 } |
| 235 | 241 |
| 242 bool GrabDeferredLock() { |
| 243 if (root_window_ && defer_compositor_lock_) { |
| 244 compositor_lock_ = root_window_->compositor()->GetCompositorLock(); |
| 245 defer_compositor_lock_ = false; |
| 246 return true; |
| 247 } |
| 248 return false; |
| 249 } |
| 250 |
| 236 private: | 251 private: |
| 237 aura::RootWindow* root_window_; | 252 aura::RootWindow* root_window_; |
| 238 gfx::Size new_size_; | 253 gfx::Size new_size_; |
| 239 scoped_refptr<aura::CompositorLock> compositor_lock_; | 254 scoped_refptr<ui::CompositorLock> compositor_lock_; |
| 240 base::WeakPtrFactory<ResizeLock> weak_ptr_factory_; | 255 base::WeakPtrFactory<ResizeLock> weak_ptr_factory_; |
| 256 bool defer_compositor_lock_; |
| 241 | 257 |
| 242 DISALLOW_COPY_AND_ASSIGN(ResizeLock); | 258 DISALLOW_COPY_AND_ASSIGN(ResizeLock); |
| 243 }; | 259 }; |
| 244 | 260 |
| 245 //////////////////////////////////////////////////////////////////////////////// | 261 //////////////////////////////////////////////////////////////////////////////// |
| 246 // RenderWidgetHostViewAura, public: | 262 // RenderWidgetHostViewAura, public: |
| 247 | 263 |
| 248 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) | 264 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) |
| 249 : host_(RenderWidgetHostImpl::From(host)), | 265 : host_(RenderWidgetHostImpl::From(host)), |
| 250 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | 266 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), |
| 251 in_shutdown_(false), | 267 in_shutdown_(false), |
| 252 is_fullscreen_(false), | 268 is_fullscreen_(false), |
| 253 popup_parent_host_view_(NULL), | 269 popup_parent_host_view_(NULL), |
| 254 popup_child_host_view_(NULL), | 270 popup_child_host_view_(NULL), |
| 255 is_loading_(false), | 271 is_loading_(false), |
| 256 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 272 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 257 can_compose_inline_(true), | 273 can_compose_inline_(true), |
| 258 has_composition_text_(false), | 274 has_composition_text_(false), |
| 259 device_scale_factor_(1.0f), | 275 device_scale_factor_(1.0f), |
| 260 current_surface_(0), | 276 current_surface_(0), |
| 261 current_surface_is_protected_(true), | 277 current_surface_is_protected_(true), |
| 262 current_surface_in_use_by_compositor_(true), | 278 current_surface_in_use_by_compositor_(true), |
| 263 protection_state_id_(0), | 279 protection_state_id_(0), |
| 264 surface_route_id_(0), | 280 surface_route_id_(0), |
| 265 paint_canvas_(NULL), | 281 paint_canvas_(NULL), |
| 266 synthetic_move_sent_(false), | 282 synthetic_move_sent_(false), |
| 267 accelerated_compositing_state_changed_(false) { | 283 accelerated_compositing_state_changed_(false), |
| 284 can_lock_compositor_(YES) { |
| 268 host_->SetView(this); | 285 host_->SetView(this); |
| 269 window_observer_.reset(new WindowObserver(this)); | 286 window_observer_.reset(new WindowObserver(this)); |
| 270 window_->AddObserver(window_observer_.get()); | 287 window_->AddObserver(window_observer_.get()); |
| 271 aura::client::SetTooltipText(window_, &tooltip_); | 288 aura::client::SetTooltipText(window_, &tooltip_); |
| 272 aura::client::SetActivationDelegate(window_, this); | 289 aura::client::SetActivationDelegate(window_, this); |
| 273 } | 290 } |
| 274 | 291 |
| 275 //////////////////////////////////////////////////////////////////////////////// | 292 //////////////////////////////////////////////////////////////////////////////// |
| 276 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: | 293 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: |
| 277 | 294 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 return host_; | 354 return host_; |
| 338 } | 355 } |
| 339 | 356 |
| 340 void RenderWidgetHostViewAura::WasShown() { | 357 void RenderWidgetHostViewAura::WasShown() { |
| 341 if (!host_->is_hidden()) | 358 if (!host_->is_hidden()) |
| 342 return; | 359 return; |
| 343 host_->WasShown(); | 360 host_->WasShown(); |
| 344 | 361 |
| 345 if (!current_surface_ && host_->is_accelerated_compositing_active() && | 362 if (!current_surface_ && host_->is_accelerated_compositing_active() && |
| 346 !released_front_lock_.get()) { | 363 !released_front_lock_.get()) { |
| 347 released_front_lock_ = window_->GetRootWindow()->GetCompositorLock(); | 364 released_front_lock_ = GetCompositor()->GetCompositorLock(); |
| 348 } | 365 } |
| 349 | 366 |
| 350 AdjustSurfaceProtection(); | 367 AdjustSurfaceProtection(); |
| 351 | 368 |
| 352 #if defined(OS_WIN) | 369 #if defined(OS_WIN) |
| 353 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 370 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
| 354 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); | 371 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); |
| 355 #endif | 372 #endif |
| 356 } | 373 } |
| 357 | 374 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 382 } | 399 } |
| 383 | 400 |
| 384 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { | 401 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { |
| 385 SetBounds(gfx::Rect(window_->bounds().origin(), size)); | 402 SetBounds(gfx::Rect(window_->bounds().origin(), size)); |
| 386 } | 403 } |
| 387 | 404 |
| 388 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { | 405 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { |
| 389 if (window_->bounds().size() != rect.size() && | 406 if (window_->bounds().size() != rect.size() && |
| 390 host_->is_accelerated_compositing_active()) { | 407 host_->is_accelerated_compositing_active()) { |
| 391 aura::RootWindow* root_window = window_->GetRootWindow(); | 408 aura::RootWindow* root_window = window_->GetRootWindow(); |
| 392 if (root_window) { | 409 ui::Compositor* compositor = root_window ? |
| 410 root_window->compositor() : NULL; |
| 411 if (root_window && compositor) { |
| 412 // Listen to changes in the compositor lock state. |
| 413 if (!compositor->HasObserver(this)) |
| 414 compositor->AddObserver(this); |
| 415 |
| 416 bool defer_compositor_lock = |
| 417 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || |
| 418 can_lock_compositor_ == NO_PENDING_COMMIT; |
| 419 |
| 420 if (can_lock_compositor_ == YES) |
| 421 can_lock_compositor_ = YES_DID_LOCK; |
| 422 |
| 393 resize_locks_.push_back(make_linked_ptr( | 423 resize_locks_.push_back(make_linked_ptr( |
| 394 new ResizeLock(root_window, rect.size()))); | 424 new ResizeLock(root_window, rect.size(), defer_compositor_lock))); |
| 395 } | 425 } |
| 396 } | 426 } |
| 397 window_->SetBounds(rect); | 427 window_->SetBounds(rect); |
| 398 host_->WasResized(); | 428 host_->WasResized(); |
| 399 } | 429 } |
| 400 | 430 |
| 401 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { | 431 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { |
| 402 return window_; | 432 return window_; |
| 403 } | 433 } |
| 404 | 434 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 // switching to software mode or receive a buffers swapped notification | 718 // switching to software mode or receive a buffers swapped notification |
| 689 // if switching to accelerated mode. | 719 // if switching to accelerated mode. |
| 690 // Sometimes (e.g. on a page load) the renderer will spuriously disable then | 720 // Sometimes (e.g. on a page load) the renderer will spuriously disable then |
| 691 // re-enable accelerated compositing, causing us to flash. | 721 // re-enable accelerated compositing, causing us to flash. |
| 692 // TODO(piman): factor the enable/disable accelerated compositing message into | 722 // TODO(piman): factor the enable/disable accelerated compositing message into |
| 693 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have | 723 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have |
| 694 // fewer inconsistent temporary states. | 724 // fewer inconsistent temporary states. |
| 695 accelerated_compositing_state_changed_ = true; | 725 accelerated_compositing_state_changed_ = true; |
| 696 } | 726 } |
| 697 | 727 |
| 728 bool RenderWidgetHostViewAura::ShouldFastACK(uint64 surface_id) { |
| 729 ui::Texture* container = image_transport_clients_[surface_id]; |
| 730 DCHECK(container); |
| 731 |
| 732 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || |
| 733 can_lock_compositor_ == NO_PENDING_COMMIT || |
| 734 resize_locks_.empty()) |
| 735 return false; |
| 736 |
| 737 gfx::Size container_size = ConvertSizeToDIP(this, container->size()); |
| 738 ResizeLockList::iterator it = resize_locks_.begin(); |
| 739 while (it != resize_locks_.end()) { |
| 740 if ((*it)->expected_size() == container_size) |
| 741 break; |
| 742 ++it; |
| 743 } |
| 744 |
| 745 // We could be getting an unexpected frame due to an animation |
| 746 // (i.e. we start resizing but we get an old size frame first). |
| 747 return it == resize_locks_.end() || ++it != resize_locks_.end(); |
| 748 } |
| 749 |
| 698 void RenderWidgetHostViewAura::UpdateExternalTexture() { | 750 void RenderWidgetHostViewAura::UpdateExternalTexture() { |
| 699 // Delay processing accelerated compositing state change till here where we | 751 // Delay processing accelerated compositing state change till here where we |
| 700 // act upon the state change. (Clear the external texture if switching to | 752 // act upon the state change. (Clear the external texture if switching to |
| 701 // software mode or set the external texture if going to accelerated mode). | 753 // software mode or set the external texture if going to accelerated mode). |
| 702 if (accelerated_compositing_state_changed_) | 754 if (accelerated_compositing_state_changed_) |
| 703 accelerated_compositing_state_changed_ = false; | 755 accelerated_compositing_state_changed_ = false; |
| 704 | 756 |
| 705 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) { | 757 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) { |
| 706 ui::Texture* container = image_transport_clients_[current_surface_]; | 758 ui::Texture* container = image_transport_clients_[current_surface_]; |
| 707 window_->SetExternalTexture(container); | 759 window_->SetExternalTexture(container); |
| 708 current_surface_in_use_by_compositor_ = true; | 760 current_surface_in_use_by_compositor_ = true; |
| 709 | 761 |
| 710 if (!container) { | 762 if (!container) { |
| 711 resize_locks_.clear(); | 763 resize_locks_.clear(); |
| 712 } else { | 764 } else { |
| 713 typedef std::vector<linked_ptr<ResizeLock> > ResizeLockList; | |
| 714 ResizeLockList::iterator it = resize_locks_.begin(); | 765 ResizeLockList::iterator it = resize_locks_.begin(); |
| 715 while (it != resize_locks_.end()) { | 766 while (it != resize_locks_.end()) { |
| 716 gfx::Size container_size = ConvertSizeToDIP(this, | 767 gfx::Size container_size = ConvertSizeToDIP(this, |
| 717 container->size()); | 768 container->size()); |
| 718 if ((*it)->expected_size() == container_size) | 769 if ((*it)->expected_size() == container_size) |
| 719 break; | 770 break; |
| 720 ++it; | 771 ++it; |
| 721 } | 772 } |
| 722 if (it != resize_locks_.end()) { | 773 if (it != resize_locks_.end()) { |
| 723 ++it; | 774 ++it; |
| 724 ui::Compositor* compositor = GetCompositor(); | 775 ui::Compositor* compositor = GetCompositor(); |
| 725 if (compositor) { | 776 if (compositor) { |
| 726 // Delay the release of the lock until we've kicked a frame with the | 777 // Delay the release of the lock until we've kicked a frame with the |
| 727 // new texture, to avoid resizing the UI before we have a chance to | 778 // new texture, to avoid resizing the UI before we have a chance to |
| 728 // draw a "good" frame. | 779 // draw a "good" frame. |
| 729 locks_pending_draw_.insert( | 780 locks_pending_commit_.insert( |
| 730 locks_pending_draw_.begin(), resize_locks_.begin(), it); | 781 locks_pending_commit_.begin(), resize_locks_.begin(), it); |
| 731 // However since we got the size we were looking for, unlock the | 782 // However since we got the size we were looking for, unlock the |
| 732 // compositor. | 783 // compositor. |
| 733 for (ResizeLockList::iterator it2 = resize_locks_.begin(); | 784 for (ResizeLockList::iterator it2 = resize_locks_.begin(); |
| 734 it2 !=it; ++it2) { | 785 it2 !=it; ++it2) { |
| 735 it2->get()->UnlockCompositor(); | 786 it2->get()->UnlockCompositor(); |
| 736 } | 787 } |
| 737 if (!compositor->HasObserver(this)) | 788 if (!compositor->HasObserver(this)) |
| 738 compositor->AddObserver(this); | 789 compositor->AddObserver(this); |
| 739 } | 790 } |
| 740 resize_locks_.erase(resize_locks_.begin(), it); | 791 resize_locks_.erase(resize_locks_.begin(), it); |
| 741 } | 792 } |
| 742 } | 793 } |
| 743 } else { | 794 } else { |
| 744 window_->SetExternalTexture(NULL); | 795 window_->SetExternalTexture(NULL); |
| 745 if (ShouldReleaseFrontSurface() && | 796 if (ShouldReleaseFrontSurface() && |
| 746 host_->is_accelerated_compositing_active()) { | 797 host_->is_accelerated_compositing_active()) { |
| 747 // The current surface may have pipelined gl commands, so always wait for | 798 // We need to wait for a commit to clear to guarantee that all we |
| 748 // the next composite to start. If the current surface is still null, | 799 // will not issue any more GL referencing the previous surface. |
| 749 // then we really know its no longer in use. | |
| 750 ui::Compositor* compositor = GetCompositor(); | 800 ui::Compositor* compositor = GetCompositor(); |
| 751 if (compositor) { | 801 if (compositor) { |
| 752 on_compositing_will_start_callbacks_.push_back( | 802 can_lock_compositor_ = NO_PENDING_COMMIT; |
| 803 on_compositing_did_commit_callbacks_.push_back( |
| 753 base::Bind(&RenderWidgetHostViewAura:: | 804 base::Bind(&RenderWidgetHostViewAura:: |
| 754 SetSurfaceNotInUseByCompositor, | 805 SetSurfaceNotInUseByCompositor, |
| 755 AsWeakPtr())); | 806 AsWeakPtr())); |
| 756 if (!compositor->HasObserver(this)) | 807 if (!compositor->HasObserver(this)) |
| 757 compositor->AddObserver(this); | 808 compositor->AddObserver(this); |
| 758 } | 809 } |
| 759 } | 810 } |
| 760 resize_locks_.clear(); | 811 resize_locks_.clear(); |
| 761 } | 812 } |
| 762 } | 813 } |
| 763 | 814 |
| 764 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( | 815 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( |
| 765 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, | 816 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, |
| 766 int gpu_host_id) { | 817 int gpu_host_id) { |
| 767 surface_route_id_ = params_in_pixel.route_id; | 818 surface_route_id_ = params_in_pixel.route_id; |
| 768 // If protection state changed, then this swap is stale. We must still ACK but | 819 // If protection state changed, then this swap is stale. We must still ACK but |
| 769 // do not update current_surface_ since it may have been discarded. | 820 // do not update current_surface_ since it may have been discarded. |
| 770 if (params_in_pixel.protection_state_id && | 821 if (params_in_pixel.protection_state_id && |
| 771 params_in_pixel.protection_state_id != protection_state_id_) { | 822 params_in_pixel.protection_state_id != protection_state_id_) { |
| 772 DCHECK(!current_surface_); | 823 DCHECK(!current_surface_); |
| 773 if (!params_in_pixel.skip_ack) | 824 if (!params_in_pixel.skip_ack) |
| 774 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL); | 825 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); |
| 775 return; | 826 return; |
| 776 } | 827 } |
| 828 |
| 829 if (ShouldFastACK(params_in_pixel.surface_handle)) { |
| 830 if (!params_in_pixel.skip_ack) |
| 831 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); |
| 832 return; |
| 833 } |
| 834 |
| 777 current_surface_ = params_in_pixel.surface_handle; | 835 current_surface_ = params_in_pixel.surface_handle; |
| 778 // If we don't require an ACK that means the content is not a fresh updated | 836 // If we don't require an ACK that means the content is not a fresh updated |
| 779 // new frame, rather we are just resetting our handle to some old content that | 837 // new frame, rather we are just resetting our handle to some old content |
| 780 // we still hadn't discarded. Although we could display immediately, by not | 838 // that we still hadn't discarded. Although we could display immediately, |
| 781 // resetting the compositor lock here, we give us some time to get a fresh | 839 // by not resetting the compositor lock here, we give us some time to get |
| 782 // frame which means fewer content flashes. | 840 // a fresh frame which means fewer content flashes. |
| 783 if (!params_in_pixel.skip_ack) | 841 if (!params_in_pixel.skip_ack) |
| 784 released_front_lock_ = NULL; | 842 released_front_lock_ = NULL; |
| 785 | 843 |
| 786 UpdateExternalTexture(); | 844 UpdateExternalTexture(); |
| 787 | 845 |
| 788 ui::Compositor* compositor = GetCompositor(); | 846 ui::Compositor* compositor = GetCompositor(); |
| 789 if (!compositor) { | 847 if (!compositor) { |
| 790 // We have no compositor, so we have no way to display the surface. | |
| 791 // Must still send the ACK. | |
| 792 if (!params_in_pixel.skip_ack) | 848 if (!params_in_pixel.skip_ack) |
| 793 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL); | 849 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); |
| 794 } else { | 850 } else { |
| 795 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) != | 851 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) != |
| 796 image_transport_clients_.end()); | 852 image_transport_clients_.end()); |
| 797 gfx::Size surface_size_in_pixel = | 853 gfx::Size surface_size_in_pixel = |
| 798 image_transport_clients_[params_in_pixel.surface_handle]->size(); | 854 image_transport_clients_[params_in_pixel.surface_handle]->size(); |
| 799 gfx::Size surface_size = ConvertSizeToDIP(this, | 855 gfx::Size surface_size = ConvertSizeToDIP(this, surface_size_in_pixel); |
| 800 surface_size_in_pixel); | |
| 801 window_->SchedulePaintInRect(gfx::Rect(surface_size)); | 856 window_->SchedulePaintInRect(gfx::Rect(surface_size)); |
| 802 | 857 |
| 803 if (!params_in_pixel.skip_ack) { | 858 if (!params_in_pixel.skip_ack) { |
| 804 if (!resize_locks_.empty()) { | 859 // Add sending an ACK to the list of things to do OnCompositingDidCommit |
| 805 // If we are waiting for the resize, fast-track the ACK. | 860 can_lock_compositor_ = NO_PENDING_COMMIT; |
| 806 if (compositor->IsThreaded()) { | 861 on_compositing_did_commit_callbacks_.push_back( |
| 807 // We need the compositor thread to pick up the active buffer before | 862 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, |
| 808 // ACKing. | 863 params_in_pixel.route_id, |
| 809 on_compositing_did_commit_callbacks_.push_back( | 864 gpu_host_id, |
| 810 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, | 865 true)); |
| 811 params_in_pixel.route_id, | 866 if (!compositor->HasObserver(this)) |
| 812 gpu_host_id)); | 867 compositor->AddObserver(this); |
| 813 if (!compositor->HasObserver(this)) | |
| 814 compositor->AddObserver(this); | |
| 815 } else { | |
| 816 // The compositor will pickup the active buffer during a draw, so we | |
| 817 // can ACK immediately. | |
| 818 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, | |
| 819 compositor); | |
| 820 } | |
| 821 } else { | |
| 822 // Add sending an ACK to the list of things to do OnCompositingWillStart | |
| 823 on_compositing_will_start_callbacks_.push_back( | |
| 824 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, | |
| 825 params_in_pixel.route_id, | |
| 826 gpu_host_id)); | |
| 827 if (!compositor->HasObserver(this)) | |
| 828 compositor->AddObserver(this); | |
| 829 } | |
| 830 } | 868 } |
| 831 } | 869 } |
| 832 } | 870 } |
| 833 | 871 |
| 834 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( | 872 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( |
| 835 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, | 873 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, |
| 836 int gpu_host_id) { | 874 int gpu_host_id) { |
| 837 surface_route_id_ = params_in_pixel.route_id; | 875 surface_route_id_ = params_in_pixel.route_id; |
| 838 // If visible state changed, then this PSB is stale. We must still ACK but | 876 // If visible state changed, then this PSB is stale. We must still ACK but |
| 839 // do not update current_surface_. | 877 // do not update current_surface_. |
| 840 if (params_in_pixel.protection_state_id && | 878 if (params_in_pixel.protection_state_id && |
| 841 params_in_pixel.protection_state_id != protection_state_id_) { | 879 params_in_pixel.protection_state_id != protection_state_id_) { |
| 842 DCHECK(!current_surface_); | 880 DCHECK(!current_surface_); |
| 843 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL); | 881 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); |
| 844 return; | 882 return; |
| 845 } | 883 } |
| 884 |
| 885 if (ShouldFastACK(params_in_pixel.surface_handle)) { |
| 886 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); |
| 887 return; |
| 888 } |
| 889 |
| 846 current_surface_ = params_in_pixel.surface_handle; | 890 current_surface_ = params_in_pixel.surface_handle; |
| 847 released_front_lock_ = NULL; | 891 released_front_lock_ = NULL; |
| 848 DCHECK(current_surface_); | 892 DCHECK(current_surface_); |
| 849 UpdateExternalTexture(); | 893 UpdateExternalTexture(); |
| 850 | 894 |
| 851 ui::Compositor* compositor = GetCompositor(); | 895 ui::Compositor* compositor = GetCompositor(); |
| 852 if (!compositor) { | 896 if (!compositor) { |
| 853 // We have no compositor, so we have no way to display the surface | 897 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); |
| 854 // Must still send the ACK | |
| 855 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL); | |
| 856 } else { | 898 } else { |
| 857 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) != | 899 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) != |
| 858 image_transport_clients_.end()); | 900 image_transport_clients_.end()); |
| 859 gfx::Size surface_size_in_pixel = | 901 gfx::Size surface_size_in_pixel = |
| 860 image_transport_clients_[params_in_pixel.surface_handle]->size(); | 902 image_transport_clients_[params_in_pixel.surface_handle]->size(); |
| 861 | 903 |
| 862 // Co-ordinates come in OpenGL co-ordinate space. | 904 // Co-ordinates come in OpenGL co-ordinate space. |
| 863 // We need to convert to layer space. | 905 // We need to convert to layer space. |
| 864 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect( | 906 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect( |
| 865 params_in_pixel.x, | 907 params_in_pixel.x, |
| 866 surface_size_in_pixel.height() - params_in_pixel.y - | 908 surface_size_in_pixel.height() - params_in_pixel.y - |
| 867 params_in_pixel.height, | 909 params_in_pixel.height, |
| 868 params_in_pixel.width, | 910 params_in_pixel.width, |
| 869 params_in_pixel.height)); | 911 params_in_pixel.height)); |
| 870 | 912 |
| 871 // Damage may not have been DIP aligned, so inflate damage to compensate | 913 // Damage may not have been DIP aligned, so inflate damage to compensate |
| 872 // for any round-off error. | 914 // for any round-off error. |
| 873 rect_to_paint.Inset(-1, -1); | 915 rect_to_paint.Inset(-1, -1); |
| 874 rect_to_paint = rect_to_paint.Intersect(window_->bounds()); | 916 rect_to_paint = rect_to_paint.Intersect(window_->bounds()); |
| 875 | 917 |
| 876 window_->SchedulePaintInRect(rect_to_paint); | 918 window_->SchedulePaintInRect(rect_to_paint); |
| 877 | 919 |
| 878 if (!resize_locks_.empty()) { | 920 // Add sending an ACK to the list of things to do OnCompositingDidCommit |
| 879 // If we are waiting for the resize, fast-track the ACK. | 921 can_lock_compositor_ = NO_PENDING_COMMIT; |
| 880 if (compositor->IsThreaded()) { | 922 on_compositing_did_commit_callbacks_.push_back( |
| 881 // We need the compositor thread to pick up the active buffer before | 923 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, |
| 882 // ACKing. | 924 params_in_pixel.route_id, |
| 883 on_compositing_did_commit_callbacks_.push_back( | 925 gpu_host_id, |
| 884 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, | 926 true)); |
| 885 params_in_pixel.route_id, | 927 if (!compositor->HasObserver(this)) |
| 886 gpu_host_id)); | 928 compositor->AddObserver(this); |
| 887 if (!compositor->HasObserver(this)) | |
| 888 compositor->AddObserver(this); | |
| 889 } else { | |
| 890 // The compositor will pickup the active buffer during a draw, so we | |
| 891 // can ACK immediately. | |
| 892 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, | |
| 893 compositor); | |
| 894 } | |
| 895 } else { | |
| 896 // Add sending an ACK to the list of things to do OnCompositingWillStart | |
| 897 on_compositing_will_start_callbacks_.push_back( | |
| 898 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, | |
| 899 params_in_pixel.route_id, | |
| 900 gpu_host_id)); | |
| 901 if (!compositor->HasObserver(this)) | |
| 902 compositor->AddObserver(this); | |
| 903 } | |
| 904 } | 929 } |
| 905 } | 930 } |
| 906 | 931 |
| 907 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { | 932 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { |
| 908 } | 933 } |
| 909 | 934 |
| 910 bool RenderWidgetHostViewAura::HasAcceleratedSurface( | 935 bool RenderWidgetHostViewAura::HasAcceleratedSurface( |
| 911 const gfx::Size& desired_size) { | 936 const gfx::Size& desired_size) { |
| 912 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't | 937 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't |
| 913 // matter what is returned here as GetBackingStore is the only caller of this | 938 // matter what is returned here as GetBackingStore is the only caller of this |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 } | 1665 } |
| 1641 | 1666 |
| 1642 void RenderWidgetHostViewAura::OnLostActive() { | 1667 void RenderWidgetHostViewAura::OnLostActive() { |
| 1643 } | 1668 } |
| 1644 | 1669 |
| 1645 //////////////////////////////////////////////////////////////////////////////// | 1670 //////////////////////////////////////////////////////////////////////////////// |
| 1646 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: | 1671 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: |
| 1647 | 1672 |
| 1648 void RenderWidgetHostViewAura::OnCompositingDidCommit( | 1673 void RenderWidgetHostViewAura::OnCompositingDidCommit( |
| 1649 ui::Compositor* compositor) { | 1674 ui::Compositor* compositor) { |
| 1675 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
| 1676 can_lock_compositor_ = YES; |
| 1677 for (ResizeLockList::iterator it = resize_locks_.begin(); |
| 1678 it != resize_locks_.end(); ++it) |
| 1679 if ((*it)->GrabDeferredLock()) |
| 1680 can_lock_compositor_ = YES_DID_LOCK; |
| 1681 } |
| 1650 RunCompositingDidCommitCallbacks(compositor); | 1682 RunCompositingDidCommitCallbacks(compositor); |
| 1651 } | 1683 locks_pending_commit_.clear(); |
| 1652 | |
| 1653 void RenderWidgetHostViewAura::OnCompositingWillStart( | |
| 1654 ui::Compositor* compositor) { | |
| 1655 RunCompositingWillStartCallbacks(compositor); | |
| 1656 } | 1684 } |
| 1657 | 1685 |
| 1658 void RenderWidgetHostViewAura::OnCompositingStarted( | 1686 void RenderWidgetHostViewAura::OnCompositingStarted( |
| 1659 ui::Compositor* compositor) { | 1687 ui::Compositor* compositor) { |
| 1660 locks_pending_draw_.clear(); | |
| 1661 } | 1688 } |
| 1662 | 1689 |
| 1663 void RenderWidgetHostViewAura::OnCompositingEnded( | 1690 void RenderWidgetHostViewAura::OnCompositingEnded( |
| 1664 ui::Compositor* compositor) { | 1691 ui::Compositor* compositor) { |
| 1665 } | 1692 } |
| 1666 | 1693 |
| 1667 void RenderWidgetHostViewAura::OnCompositingAborted( | 1694 void RenderWidgetHostViewAura::OnCompositingAborted( |
| 1668 ui::Compositor* compositor) { | 1695 ui::Compositor* compositor) { |
| 1669 } | 1696 } |
| 1670 | 1697 |
| 1698 void RenderWidgetHostViewAura::OnCompositingLockStateChanged( |
| 1699 ui::Compositor* compositor) { |
| 1700 // A compositor lock that is part of a resize lock timed out. We |
| 1701 // should display a renderer frame. |
| 1702 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { |
| 1703 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; |
| 1704 } |
| 1705 } |
| 1706 |
| 1671 //////////////////////////////////////////////////////////////////////////////// | 1707 //////////////////////////////////////////////////////////////////////////////// |
| 1672 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: | 1708 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: |
| 1673 | 1709 |
| 1674 void RenderWidgetHostViewAura::OnLostResources() { | 1710 void RenderWidgetHostViewAura::OnLostResources() { |
| 1675 image_transport_clients_.clear(); | 1711 image_transport_clients_.clear(); |
| 1676 current_surface_ = 0; | 1712 current_surface_ = 0; |
| 1677 protection_state_id_ = 0; | 1713 protection_state_id_ = 0; |
| 1678 current_surface_is_protected_ = true; | 1714 current_surface_is_protected_ = true; |
| 1679 current_surface_in_use_by_compositor_ = true; | 1715 current_surface_in_use_by_compositor_ = true; |
| 1680 surface_route_id_ = 0; | 1716 surface_route_id_ = 0; |
| 1681 UpdateExternalTexture(); | 1717 UpdateExternalTexture(); |
| 1682 locks_pending_draw_.clear(); | 1718 locks_pending_commit_.clear(); |
| 1683 | 1719 |
| 1684 DCHECK(!shared_surface_handle_.is_null()); | 1720 DCHECK(!shared_surface_handle_.is_null()); |
| 1685 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1721 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 1686 factory->DestroySharedSurfaceHandle(shared_surface_handle_); | 1722 factory->DestroySharedSurfaceHandle(shared_surface_handle_); |
| 1687 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); | 1723 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); |
| 1688 host_->CompositingSurfaceUpdated(); | 1724 host_->CompositingSurfaceUpdated(); |
| 1689 host_->ScheduleComposite(); | 1725 host_->ScheduleComposite(); |
| 1690 } | 1726 } |
| 1691 | 1727 |
| 1692 //////////////////////////////////////////////////////////////////////////////// | 1728 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks( | 1854 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks( |
| 1819 ui::Compositor* compositor) { | 1855 ui::Compositor* compositor) { |
| 1820 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator | 1856 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator |
| 1821 it = on_compositing_did_commit_callbacks_.begin(); | 1857 it = on_compositing_did_commit_callbacks_.begin(); |
| 1822 it != on_compositing_did_commit_callbacks_.end(); ++it) { | 1858 it != on_compositing_did_commit_callbacks_.end(); ++it) { |
| 1823 it->Run(compositor); | 1859 it->Run(compositor); |
| 1824 } | 1860 } |
| 1825 on_compositing_did_commit_callbacks_.clear(); | 1861 on_compositing_did_commit_callbacks_.clear(); |
| 1826 } | 1862 } |
| 1827 | 1863 |
| 1828 void RenderWidgetHostViewAura::RunCompositingWillStartCallbacks( | |
| 1829 ui::Compositor* compositor) { | |
| 1830 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator | |
| 1831 it = on_compositing_will_start_callbacks_.begin(); | |
| 1832 it != on_compositing_will_start_callbacks_.end(); ++it) { | |
| 1833 it->Run(compositor); | |
| 1834 } | |
| 1835 on_compositing_will_start_callbacks_.clear(); | |
| 1836 } | |
| 1837 | |
| 1838 // static | 1864 // static |
| 1839 void RenderWidgetHostViewAura::InsertSyncPointAndACK( | 1865 void RenderWidgetHostViewAura::InsertSyncPointAndACK( |
| 1840 int32 route_id, int gpu_host_id, ui::Compositor* compositor) { | 1866 int32 route_id, int gpu_host_id, bool presented, |
| 1867 ui::Compositor* compositor) { |
| 1841 uint32 sync_point = 0; | 1868 uint32 sync_point = 0; |
| 1842 // If we have no compositor, so we must still send the ACK. A zero | 1869 // If we have no compositor, so we must still send the ACK. A zero |
| 1843 // sync point will not be waited for in the GPU process. | 1870 // sync point will not be waited for in the GPU process. |
| 1844 if (compositor) { | 1871 if (compositor) { |
| 1845 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1872 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 1846 sync_point = factory->InsertSyncPoint(); | 1873 sync_point = factory->InsertSyncPoint(); |
| 1847 } | 1874 } |
| 1848 | 1875 |
| 1849 RenderWidgetHostImpl::AcknowledgeBufferPresent( | 1876 RenderWidgetHostImpl::AcknowledgeBufferPresent( |
| 1850 route_id, gpu_host_id, sync_point); | 1877 route_id, gpu_host_id, presented, sync_point); |
| 1851 } | 1878 } |
| 1852 | 1879 |
| 1853 void RenderWidgetHostViewAura::RemovingFromRootWindow() { | 1880 void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
| 1854 // We are about to disconnect ourselves from the compositor, we need to issue | 1881 // We are about to disconnect ourselves from the compositor, we need to issue |
| 1855 // the callbacks now, because we won't get notified when the frame is done. | 1882 // the callbacks now, because we won't get notified when the frame is done. |
| 1856 // TODO(piman): this might in theory cause a race where the GPU process starts | 1883 // TODO(piman): this might in theory cause a race where the GPU process starts |
| 1857 // drawing to the buffer we haven't yet displayed. This will only show for 1 | 1884 // drawing to the buffer we haven't yet displayed. This will only show for 1 |
| 1858 // frame though, because we will reissue a new frame right away without that | 1885 // frame though, because we will reissue a new frame right away without that |
| 1859 // composited data. | 1886 // composited data. |
| 1860 ui::Compositor* compositor = GetCompositor(); | 1887 ui::Compositor* compositor = GetCompositor(); |
| 1861 RunCompositingDidCommitCallbacks(compositor); | 1888 RunCompositingDidCommitCallbacks(compositor); |
| 1862 RunCompositingWillStartCallbacks(compositor); | 1889 locks_pending_commit_.clear(); |
| 1863 locks_pending_draw_.clear(); | |
| 1864 if (compositor && compositor->HasObserver(this)) | 1890 if (compositor && compositor->HasObserver(this)) |
| 1865 compositor->RemoveObserver(this); | 1891 compositor->RemoveObserver(this); |
| 1866 DetachFromInputMethod(); | 1892 DetachFromInputMethod(); |
| 1867 } | 1893 } |
| 1868 | 1894 |
| 1869 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { | 1895 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { |
| 1870 aura::RootWindow* root_window = window_->GetRootWindow(); | 1896 aura::RootWindow* root_window = window_->GetRootWindow(); |
| 1871 return root_window ? root_window->compositor() : NULL; | 1897 return root_window ? root_window->compositor() : NULL; |
| 1872 } | 1898 } |
| 1873 | 1899 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1885 RenderWidgetHost* widget) { | 1911 RenderWidgetHost* widget) { |
| 1886 return new RenderWidgetHostViewAura(widget); | 1912 return new RenderWidgetHostViewAura(widget); |
| 1887 } | 1913 } |
| 1888 | 1914 |
| 1889 // static | 1915 // static |
| 1890 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 1916 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 1891 GetScreenInfoForWindow(results, NULL); | 1917 GetScreenInfoForWindow(results, NULL); |
| 1892 } | 1918 } |
| 1893 | 1919 |
| 1894 } // namespace content | 1920 } // namespace content |
| OLD | NEW |