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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 | 192 |
193 private: | 193 private: |
194 RenderWidgetHostViewAura* view_; | 194 RenderWidgetHostViewAura* view_; |
195 | 195 |
196 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 196 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
197 }; | 197 }; |
198 | 198 |
199 class RenderWidgetHostViewAura::ResizeLock { | 199 class RenderWidgetHostViewAura::ResizeLock { |
200 public: | 200 public: |
201 ResizeLock(aura::RootWindow* root_window, const gfx::Size new_size) | 201 ResizeLock(aura::RootWindow* root_window, |
| 202 const gfx::Size new_size, |
| 203 bool defer_compositor_lock) |
202 : root_window_(root_window), | 204 : root_window_(root_window), |
203 new_size_(new_size), | 205 new_size_(new_size), |
204 compositor_lock_(root_window_->GetCompositorLock()), | 206 compositor_lock_(defer_compositor_lock ? |
205 weak_ptr_factory_(this) { | 207 NULL : |
| 208 root_window_->compositor()->GetCompositorLock()), |
| 209 weak_ptr_factory_(this), |
| 210 defer_compositor_lock_(defer_compositor_lock) { |
206 root_window_->HoldMouseMoves(); | 211 root_window_->HoldMouseMoves(); |
207 | 212 |
208 BrowserThread::PostDelayedTask( | 213 BrowserThread::PostDelayedTask( |
209 BrowserThread::UI, FROM_HERE, | 214 BrowserThread::UI, FROM_HERE, |
210 base::Bind(&RenderWidgetHostViewAura::ResizeLock::CancelLock, | 215 base::Bind(&RenderWidgetHostViewAura::ResizeLock::CancelLock, |
211 weak_ptr_factory_.GetWeakPtr()), | 216 weak_ptr_factory_.GetWeakPtr()), |
212 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs)); | 217 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs)); |
213 } | 218 } |
214 | 219 |
215 ~ResizeLock() { | 220 ~ResizeLock() { |
216 CancelLock(); | 221 CancelLock(); |
217 } | 222 } |
218 | 223 |
219 void UnlockCompositor() { | 224 void UnlockCompositor() { |
| 225 defer_compositor_lock_ = false; |
220 compositor_lock_ = NULL; | 226 compositor_lock_ = NULL; |
221 } | 227 } |
222 | 228 |
223 void CancelLock() { | 229 void CancelLock() { |
224 if (!root_window_) | 230 if (!root_window_) |
225 return; | 231 return; |
226 UnlockCompositor(); | 232 UnlockCompositor(); |
227 root_window_->ReleaseMouseMoves(); | 233 root_window_->ReleaseMouseMoves(); |
228 root_window_ = NULL; | 234 root_window_ = NULL; |
229 } | 235 } |
230 | 236 |
231 const gfx::Size& expected_size() const { | 237 const gfx::Size& expected_size() const { |
232 return new_size_; | 238 return new_size_; |
233 } | 239 } |
234 | 240 |
| 241 bool GrabDeferredLock() { |
| 242 if (root_window_ && defer_compositor_lock_) { |
| 243 compositor_lock_ = root_window_->compositor()->GetCompositorLock(); |
| 244 defer_compositor_lock_ = false; |
| 245 return true; |
| 246 } |
| 247 return false; |
| 248 } |
| 249 |
235 private: | 250 private: |
236 aura::RootWindow* root_window_; | 251 aura::RootWindow* root_window_; |
237 gfx::Size new_size_; | 252 gfx::Size new_size_; |
238 scoped_refptr<aura::CompositorLock> compositor_lock_; | 253 scoped_refptr<ui::CompositorLock> compositor_lock_; |
239 base::WeakPtrFactory<ResizeLock> weak_ptr_factory_; | 254 base::WeakPtrFactory<ResizeLock> weak_ptr_factory_; |
| 255 bool defer_compositor_lock_; |
240 | 256 |
241 DISALLOW_COPY_AND_ASSIGN(ResizeLock); | 257 DISALLOW_COPY_AND_ASSIGN(ResizeLock); |
242 }; | 258 }; |
243 | 259 |
244 //////////////////////////////////////////////////////////////////////////////// | 260 //////////////////////////////////////////////////////////////////////////////// |
245 // RenderWidgetHostViewAura, public: | 261 // RenderWidgetHostViewAura, public: |
246 | 262 |
247 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) | 263 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) |
248 : host_(RenderWidgetHostImpl::From(host)), | 264 : host_(RenderWidgetHostImpl::From(host)), |
249 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | 265 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), |
250 in_shutdown_(false), | 266 in_shutdown_(false), |
251 is_fullscreen_(false), | 267 is_fullscreen_(false), |
252 popup_parent_host_view_(NULL), | 268 popup_parent_host_view_(NULL), |
253 popup_child_host_view_(NULL), | 269 popup_child_host_view_(NULL), |
254 is_loading_(false), | 270 is_loading_(false), |
255 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 271 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
256 can_compose_inline_(true), | 272 can_compose_inline_(true), |
257 has_composition_text_(false), | 273 has_composition_text_(false), |
258 device_scale_factor_(1.0f), | 274 device_scale_factor_(1.0f), |
259 current_surface_(0), | 275 current_surface_(0), |
260 current_surface_is_protected_(true), | 276 current_surface_is_protected_(true), |
261 current_surface_in_use_by_compositor_(true), | 277 current_surface_in_use_by_compositor_(true), |
262 protection_state_id_(0), | 278 protection_state_id_(0), |
263 surface_route_id_(0), | 279 surface_route_id_(0), |
264 paint_canvas_(NULL), | 280 paint_canvas_(NULL), |
265 synthetic_move_sent_(false), | 281 synthetic_move_sent_(false), |
266 accelerated_compositing_state_changed_(false) { | 282 accelerated_compositing_state_changed_(false), |
| 283 can_lock_compositor_(YES) { |
267 host_->SetView(this); | 284 host_->SetView(this); |
268 window_observer_.reset(new WindowObserver(this)); | 285 window_observer_.reset(new WindowObserver(this)); |
269 window_->AddObserver(window_observer_.get()); | 286 window_->AddObserver(window_observer_.get()); |
270 aura::client::SetTooltipText(window_, &tooltip_); | 287 aura::client::SetTooltipText(window_, &tooltip_); |
271 aura::client::SetActivationDelegate(window_, this); | 288 aura::client::SetActivationDelegate(window_, this); |
272 } | 289 } |
273 | 290 |
274 //////////////////////////////////////////////////////////////////////////////// | 291 //////////////////////////////////////////////////////////////////////////////// |
275 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: | 292 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: |
276 | 293 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 return host_; | 353 return host_; |
337 } | 354 } |
338 | 355 |
339 void RenderWidgetHostViewAura::WasShown() { | 356 void RenderWidgetHostViewAura::WasShown() { |
340 if (!host_->is_hidden()) | 357 if (!host_->is_hidden()) |
341 return; | 358 return; |
342 host_->WasShown(); | 359 host_->WasShown(); |
343 | 360 |
344 if (!current_surface_ && host_->is_accelerated_compositing_active() && | 361 if (!current_surface_ && host_->is_accelerated_compositing_active() && |
345 !released_front_lock_.get()) { | 362 !released_front_lock_.get()) { |
346 released_front_lock_ = window_->GetRootWindow()->GetCompositorLock(); | 363 released_front_lock_ = GetCompositor()->GetCompositorLock(); |
347 } | 364 } |
348 | 365 |
349 AdjustSurfaceProtection(); | 366 AdjustSurfaceProtection(); |
350 | 367 |
351 #if defined(OS_WIN) | 368 #if defined(OS_WIN) |
352 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 369 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
353 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); | 370 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); |
354 #endif | 371 #endif |
355 } | 372 } |
356 | 373 |
(...skipping 24 matching lines...) Expand all Loading... |
381 } | 398 } |
382 | 399 |
383 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { | 400 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { |
384 SetBounds(gfx::Rect(window_->bounds().origin(), size)); | 401 SetBounds(gfx::Rect(window_->bounds().origin(), size)); |
385 } | 402 } |
386 | 403 |
387 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { | 404 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { |
388 if (window_->bounds().size() != rect.size() && | 405 if (window_->bounds().size() != rect.size() && |
389 host_->is_accelerated_compositing_active()) { | 406 host_->is_accelerated_compositing_active()) { |
390 aura::RootWindow* root_window = window_->GetRootWindow(); | 407 aura::RootWindow* root_window = window_->GetRootWindow(); |
391 if (root_window) { | 408 ui::Compositor* compositor = root_window ? |
| 409 root_window->compositor() : NULL; |
| 410 if (root_window && compositor) { |
| 411 // Listen to changes in the compositor lock state. |
| 412 if (!compositor->HasObserver(this)) |
| 413 compositor->AddObserver(this); |
| 414 |
| 415 bool defer_compositor_lock = |
| 416 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || |
| 417 can_lock_compositor_ == NO_PENDING_COMMIT; |
| 418 |
| 419 if (can_lock_compositor_ == YES) |
| 420 can_lock_compositor_ = YES_DID_LOCK; |
| 421 |
392 resize_locks_.push_back(make_linked_ptr( | 422 resize_locks_.push_back(make_linked_ptr( |
393 new ResizeLock(root_window, rect.size()))); | 423 new ResizeLock(root_window, rect.size(), defer_compositor_lock))); |
394 } | 424 } |
395 } | 425 } |
396 window_->SetBounds(rect); | 426 window_->SetBounds(rect); |
397 host_->WasResized(); | 427 host_->WasResized(); |
398 } | 428 } |
399 | 429 |
400 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { | 430 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { |
401 return window_; | 431 return window_; |
402 } | 432 } |
403 | 433 |
(...skipping 284 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.Intersect(window_->bounds()); | 916 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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 } | 1671 } |
1647 | 1672 |
1648 void RenderWidgetHostViewAura::OnLostActive() { | 1673 void RenderWidgetHostViewAura::OnLostActive() { |
1649 } | 1674 } |
1650 | 1675 |
1651 //////////////////////////////////////////////////////////////////////////////// | 1676 //////////////////////////////////////////////////////////////////////////////// |
1652 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: | 1677 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: |
1653 | 1678 |
1654 void RenderWidgetHostViewAura::OnCompositingDidCommit( | 1679 void RenderWidgetHostViewAura::OnCompositingDidCommit( |
1655 ui::Compositor* compositor) { | 1680 ui::Compositor* compositor) { |
| 1681 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
| 1682 can_lock_compositor_ = YES; |
| 1683 for (ResizeLockList::iterator it = resize_locks_.begin(); |
| 1684 it != resize_locks_.end(); ++it) |
| 1685 if ((*it)->GrabDeferredLock()) |
| 1686 can_lock_compositor_ = YES_DID_LOCK; |
| 1687 } |
1656 RunCompositingDidCommitCallbacks(compositor); | 1688 RunCompositingDidCommitCallbacks(compositor); |
1657 } | 1689 locks_pending_commit_.clear(); |
1658 | |
1659 void RenderWidgetHostViewAura::OnCompositingWillStart( | |
1660 ui::Compositor* compositor) { | |
1661 RunCompositingWillStartCallbacks(compositor); | |
1662 } | 1690 } |
1663 | 1691 |
1664 void RenderWidgetHostViewAura::OnCompositingStarted( | 1692 void RenderWidgetHostViewAura::OnCompositingStarted( |
1665 ui::Compositor* compositor) { | 1693 ui::Compositor* compositor) { |
1666 locks_pending_draw_.clear(); | |
1667 } | 1694 } |
1668 | 1695 |
1669 void RenderWidgetHostViewAura::OnCompositingEnded( | 1696 void RenderWidgetHostViewAura::OnCompositingEnded( |
1670 ui::Compositor* compositor) { | 1697 ui::Compositor* compositor) { |
1671 } | 1698 } |
1672 | 1699 |
1673 void RenderWidgetHostViewAura::OnCompositingAborted( | 1700 void RenderWidgetHostViewAura::OnCompositingAborted( |
1674 ui::Compositor* compositor) { | 1701 ui::Compositor* compositor) { |
1675 } | 1702 } |
1676 | 1703 |
| 1704 void RenderWidgetHostViewAura::OnCompositingLockStateChanged( |
| 1705 ui::Compositor* compositor) { |
| 1706 // A compositor lock that is part of a resize lock timed out. We |
| 1707 // should display a renderer frame. |
| 1708 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { |
| 1709 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; |
| 1710 } |
| 1711 } |
| 1712 |
1677 //////////////////////////////////////////////////////////////////////////////// | 1713 //////////////////////////////////////////////////////////////////////////////// |
1678 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: | 1714 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: |
1679 | 1715 |
1680 void RenderWidgetHostViewAura::OnLostResources() { | 1716 void RenderWidgetHostViewAura::OnLostResources() { |
1681 image_transport_clients_.clear(); | 1717 image_transport_clients_.clear(); |
1682 current_surface_ = 0; | 1718 current_surface_ = 0; |
1683 protection_state_id_ = 0; | 1719 protection_state_id_ = 0; |
1684 current_surface_is_protected_ = true; | 1720 current_surface_is_protected_ = true; |
1685 current_surface_in_use_by_compositor_ = true; | 1721 current_surface_in_use_by_compositor_ = true; |
1686 surface_route_id_ = 0; | 1722 surface_route_id_ = 0; |
1687 UpdateExternalTexture(); | 1723 UpdateExternalTexture(); |
1688 locks_pending_draw_.clear(); | 1724 locks_pending_commit_.clear(); |
1689 | 1725 |
1690 DCHECK(!shared_surface_handle_.is_null()); | 1726 DCHECK(!shared_surface_handle_.is_null()); |
1691 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1727 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
1692 factory->DestroySharedSurfaceHandle(shared_surface_handle_); | 1728 factory->DestroySharedSurfaceHandle(shared_surface_handle_); |
1693 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); | 1729 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); |
1694 host_->CompositingSurfaceUpdated(); | 1730 host_->CompositingSurfaceUpdated(); |
1695 host_->ScheduleComposite(); | 1731 host_->ScheduleComposite(); |
1696 } | 1732 } |
1697 | 1733 |
1698 //////////////////////////////////////////////////////////////////////////////// | 1734 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1825 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks( | 1861 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks( |
1826 ui::Compositor* compositor) { | 1862 ui::Compositor* compositor) { |
1827 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator | 1863 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator |
1828 it = on_compositing_did_commit_callbacks_.begin(); | 1864 it = on_compositing_did_commit_callbacks_.begin(); |
1829 it != on_compositing_did_commit_callbacks_.end(); ++it) { | 1865 it != on_compositing_did_commit_callbacks_.end(); ++it) { |
1830 it->Run(compositor); | 1866 it->Run(compositor); |
1831 } | 1867 } |
1832 on_compositing_did_commit_callbacks_.clear(); | 1868 on_compositing_did_commit_callbacks_.clear(); |
1833 } | 1869 } |
1834 | 1870 |
1835 void RenderWidgetHostViewAura::RunCompositingWillStartCallbacks( | |
1836 ui::Compositor* compositor) { | |
1837 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator | |
1838 it = on_compositing_will_start_callbacks_.begin(); | |
1839 it != on_compositing_will_start_callbacks_.end(); ++it) { | |
1840 it->Run(compositor); | |
1841 } | |
1842 on_compositing_will_start_callbacks_.clear(); | |
1843 } | |
1844 | |
1845 // static | 1871 // static |
1846 void RenderWidgetHostViewAura::InsertSyncPointAndACK( | 1872 void RenderWidgetHostViewAura::InsertSyncPointAndACK( |
1847 int32 route_id, int gpu_host_id, ui::Compositor* compositor) { | 1873 int32 route_id, int gpu_host_id, bool presented, |
| 1874 ui::Compositor* compositor) { |
1848 uint32 sync_point = 0; | 1875 uint32 sync_point = 0; |
1849 // If we have no compositor, so we must still send the ACK. A zero | 1876 // If we have no compositor, so we must still send the ACK. A zero |
1850 // sync point will not be waited for in the GPU process. | 1877 // sync point will not be waited for in the GPU process. |
1851 if (compositor) { | 1878 if (compositor) { |
1852 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1879 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
1853 sync_point = factory->InsertSyncPoint(); | 1880 sync_point = factory->InsertSyncPoint(); |
1854 } | 1881 } |
1855 | 1882 |
1856 RenderWidgetHostImpl::AcknowledgeBufferPresent( | 1883 RenderWidgetHostImpl::AcknowledgeBufferPresent( |
1857 route_id, gpu_host_id, sync_point); | 1884 route_id, gpu_host_id, presented, sync_point); |
1858 } | 1885 } |
1859 | 1886 |
1860 void RenderWidgetHostViewAura::RemovingFromRootWindow() { | 1887 void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
1861 // We are about to disconnect ourselves from the compositor, we need to issue | 1888 // We are about to disconnect ourselves from the compositor, we need to issue |
1862 // the callbacks now, because we won't get notified when the frame is done. | 1889 // the callbacks now, because we won't get notified when the frame is done. |
1863 // TODO(piman): this might in theory cause a race where the GPU process starts | 1890 // TODO(piman): this might in theory cause a race where the GPU process starts |
1864 // drawing to the buffer we haven't yet displayed. This will only show for 1 | 1891 // drawing to the buffer we haven't yet displayed. This will only show for 1 |
1865 // frame though, because we will reissue a new frame right away without that | 1892 // frame though, because we will reissue a new frame right away without that |
1866 // composited data. | 1893 // composited data. |
1867 ui::Compositor* compositor = GetCompositor(); | 1894 ui::Compositor* compositor = GetCompositor(); |
1868 RunCompositingDidCommitCallbacks(compositor); | 1895 RunCompositingDidCommitCallbacks(compositor); |
1869 RunCompositingWillStartCallbacks(compositor); | 1896 locks_pending_commit_.clear(); |
1870 locks_pending_draw_.clear(); | |
1871 if (compositor && compositor->HasObserver(this)) | 1897 if (compositor && compositor->HasObserver(this)) |
1872 compositor->RemoveObserver(this); | 1898 compositor->RemoveObserver(this); |
1873 DetachFromInputMethod(); | 1899 DetachFromInputMethod(); |
1874 } | 1900 } |
1875 | 1901 |
1876 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { | 1902 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { |
1877 aura::RootWindow* root_window = window_->GetRootWindow(); | 1903 aura::RootWindow* root_window = window_->GetRootWindow(); |
1878 return root_window ? root_window->compositor() : NULL; | 1904 return root_window ? root_window->compositor() : NULL; |
1879 } | 1905 } |
1880 | 1906 |
(...skipping 11 matching lines...) Expand all Loading... |
1892 RenderWidgetHost* widget) { | 1918 RenderWidgetHost* widget) { |
1893 return new RenderWidgetHostViewAura(widget); | 1919 return new RenderWidgetHostViewAura(widget); |
1894 } | 1920 } |
1895 | 1921 |
1896 // static | 1922 // static |
1897 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 1923 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
1898 GetScreenInfoForWindow(results, NULL); | 1924 GetScreenInfoForWindow(results, NULL); |
1899 } | 1925 } |
1900 | 1926 |
1901 } // namespace content | 1927 } // namespace content |
OLD | NEW |