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

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

Issue 10690168: Aura: Resize locks with --ui-enable-threaded-compositing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New approach. Created 8 years, 4 months 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 161 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
162 }; 162 };
163 163
164 class RenderWidgetHostViewAura::ResizeLock 164 class RenderWidgetHostViewAura::ResizeLock
165 : public base::SupportsWeakPtr<RenderWidgetHostViewAura::ResizeLock> { 165 : public base::SupportsWeakPtr<RenderWidgetHostViewAura::ResizeLock> {
166 public: 166 public:
167 ResizeLock(aura::RootWindow* root_window, const gfx::Size new_size) 167 ResizeLock(aura::RootWindow* root_window, const gfx::Size new_size)
168 : root_window_(root_window), 168 : root_window_(root_window),
169 new_size_(new_size), 169 new_size_(new_size),
170 compositor_lock_(root_window_->GetCompositorLock()) { 170 compositor_lock_(root_window_->compositor()->GetCompositorLock()) {
171 root_window_->HoldMouseMoves(); 171 root_window_->HoldMouseMoves();
172 172
173 BrowserThread::PostDelayedTask( 173 BrowserThread::PostDelayedTask(
174 BrowserThread::UI, FROM_HERE, 174 BrowserThread::UI, FROM_HERE,
175 base::Bind(&RenderWidgetHostViewAura::ResizeLock::CancelLock, 175 base::Bind(&RenderWidgetHostViewAura::ResizeLock::CancelLock,
176 AsWeakPtr()), 176 AsWeakPtr()),
177 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs)); 177 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs));
178 } 178 }
179 179
180 ~ResizeLock() { 180 ~ResizeLock() {
181 CancelLock(); 181 CancelLock();
182 } 182 }
183 183
184 bool IsLocked() {
185 return root_window_ != NULL;
186 }
187
184 void UnlockCompositor() { 188 void UnlockCompositor() {
185 compositor_lock_ = NULL; 189 compositor_lock_ = NULL;
186 } 190 }
187 191
188 void CancelLock() { 192 void CancelLock() {
189 if (!root_window_) 193 if (!root_window_)
190 return; 194 return;
191 UnlockCompositor(); 195 UnlockCompositor();
192 root_window_->ReleaseMouseMoves(); 196 root_window_->ReleaseMouseMoves();
193 root_window_ = NULL; 197 root_window_ = NULL;
194 } 198 }
195 199
196 const gfx::Size& expected_size() const { 200 const gfx::Size& expected_size() const {
197 return new_size_; 201 return new_size_;
198 } 202 }
199 203
200 private: 204 private:
201 aura::RootWindow* root_window_; 205 aura::RootWindow* root_window_;
202 gfx::Size new_size_; 206 gfx::Size new_size_;
203 scoped_refptr<aura::CompositorLock> compositor_lock_; 207 scoped_refptr<ui::CompositorLock> compositor_lock_;
204 208
205 DISALLOW_COPY_AND_ASSIGN(ResizeLock); 209 DISALLOW_COPY_AND_ASSIGN(ResizeLock);
206 }; 210 };
207 211
208 //////////////////////////////////////////////////////////////////////////////// 212 ////////////////////////////////////////////////////////////////////////////////
209 // RenderWidgetHostViewAura, public: 213 // RenderWidgetHostViewAura, public:
210 214
211 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) 215 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
212 : host_(RenderWidgetHostImpl::From(host)), 216 : host_(RenderWidgetHostImpl::From(host)),
213 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), 217 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 return host_; 278 return host_;
275 } 279 }
276 280
277 void RenderWidgetHostViewAura::WasShown() { 281 void RenderWidgetHostViewAura::WasShown() {
278 if (!host_->is_hidden()) 282 if (!host_->is_hidden())
279 return; 283 return;
280 host_->WasShown(); 284 host_->WasShown();
281 285
282 if (!current_surface_ && host_->is_accelerated_compositing_active() && 286 if (!current_surface_ && host_->is_accelerated_compositing_active() &&
283 !released_front_lock_.get()) { 287 !released_front_lock_.get()) {
284 released_front_lock_ = window_->GetRootWindow()->GetCompositorLock(); 288 released_front_lock_ = GetCompositor()->GetCompositorLock();
285 } 289 }
286 290
287 AdjustSurfaceProtection(); 291 AdjustSurfaceProtection();
288 } 292 }
289 293
290 void RenderWidgetHostViewAura::WasHidden() { 294 void RenderWidgetHostViewAura::WasHidden() {
291 if (host_->is_hidden()) 295 if (host_->is_hidden())
292 return; 296 return;
293 host_->WasHidden(); 297 host_->WasHidden();
294 298
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 555 }
552 556
553 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) { 557 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) {
554 ui::Texture* container = image_transport_clients_[current_surface_]; 558 ui::Texture* container = image_transport_clients_[current_surface_];
555 window_->SetExternalTexture(container); 559 window_->SetExternalTexture(container);
556 current_surface_in_use_by_compositor_ = true; 560 current_surface_in_use_by_compositor_ = true;
557 561
558 if (!container) { 562 if (!container) {
559 resize_locks_.clear(); 563 resize_locks_.clear();
560 } else { 564 } else {
561 typedef std::vector<linked_ptr<ResizeLock> > ResizeLockList; 565 UpdateResizeLocks(ConvertSizeToDIP(this, container->size()));
562 ResizeLockList::iterator it = resize_locks_.begin();
563 while (it != resize_locks_.end()) {
564 gfx::Size container_size = ConvertSizeToDIP(this,
565 container->size());
566 if ((*it)->expected_size() == container_size)
567 break;
568 ++it;
569 }
570 if (it != resize_locks_.end()) {
571 ++it;
572 ui::Compositor* compositor = GetCompositor();
573 if (compositor) {
574 // Delay the release of the lock until we've kicked a frame with the
575 // new texture, to avoid resizing the UI before we have a chance to
576 // draw a "good" frame.
577 locks_pending_draw_.insert(
578 locks_pending_draw_.begin(), resize_locks_.begin(), it);
579 // However since we got the size we were looking for, unlock the
580 // compositor.
581 for (ResizeLockList::iterator it2 = resize_locks_.begin();
582 it2 !=it; ++it2) {
583 it2->get()->UnlockCompositor();
584 }
585 if (!compositor->HasObserver(this))
586 compositor->AddObserver(this);
587 }
588 resize_locks_.erase(resize_locks_.begin(), it);
589 }
590 } 566 }
591 } else { 567 } else {
592 window_->SetExternalTexture(NULL); 568 window_->SetExternalTexture(NULL);
593 if (ShouldReleaseFrontSurface() && 569 if (ShouldReleaseFrontSurface() &&
594 host_->is_accelerated_compositing_active()) { 570 host_->is_accelerated_compositing_active()) {
595 // The current surface may have pipelined gl commands, so always wait for 571 // The current surface may have pipelined gl commands, so always wait for
596 // the next composite to start. If the current surface is still null, 572 // the next composite to start. If the current surface is still null,
597 // then we really know its no longer in use. 573 // then we really know its no longer in use.
598 ui::Compositor* compositor = GetCompositor(); 574 ui::Compositor* compositor = GetCompositor();
599 if (compositor) { 575 if (compositor) {
600 on_compositing_will_start_callbacks_.push_back( 576 AddCompositingStartedCallback(
601 base::Bind(&RenderWidgetHostViewAura:: 577 base::Bind(&RenderWidgetHostViewAura::
602 SetSurfaceNotInUseByCompositor, 578 SetSurfaceNotInUseByCompositor,
603 AsWeakPtr())); 579 AsWeakPtr()));
604 if (!compositor->HasObserver(this)) 580 if (!compositor->HasObserver(this))
605 compositor->AddObserver(this); 581 compositor->AddObserver(this);
606 } 582 }
607 } 583 }
608 resize_locks_.clear(); 584 resize_locks_.clear();
609 } 585 }
610 } 586 }
611 587
588 void RenderWidgetHostViewAura::UpdateResizeLocks(
589 const gfx::Size& surface_size_in_dip) {
590 typedef std::vector<linked_ptr<ResizeLock> > ResizeLockList;
591
592 // Remove locks that timed out.
593 ResizeLockList::iterator it = resize_locks_.begin();
594 while (it != resize_locks_.end()) {
595 if ((*it)->IsLocked())
596 break;
597 ++it;
598 }
599 resize_locks_.erase(resize_locks_.begin(), it);
600
601 // Remove locks if we've got got the right size.
piman 2012/07/31 23:42:17 typo: got got
jonathan.backer 2012/08/01 17:22:43 Done.
602 it = resize_locks_.begin();
603 while (it != resize_locks_.end()) {
604 if ((*it)->expected_size() == surface_size_in_dip)
605 break;
606 ++it;
607 }
608
609 if (it != resize_locks_.end()) {
610 ++it;
611 ui::Compositor* compositor = GetCompositor();
612 if (compositor) {
613 // Delay the release of the lock until we've kicked a frame with the
614 // new texture, to avoid resizing the UI before we have a chance to
615 // draw a "good" frame.
616 locks_pending_draw_.insert(
617 locks_pending_draw_.begin(), resize_locks_.begin(), it);
618 // However since we got the size we were looking for, unlock the
619 // compositor.
620 for (ResizeLockList::iterator it2 = resize_locks_.begin();
621 it2 != it; ++it2) {
622 it2->get()->UnlockCompositor();
623 }
624 if (!compositor->HasObserver(this))
625 compositor->AddObserver(this);
626 }
627 resize_locks_.erase(resize_locks_.begin(), it);
628 }
629 }
630
631 bool RenderWidgetHostViewAura::CanFastTrackACK(
632 const gfx::Size& surface_size_in_dip) {
633 std::vector<linked_ptr<ResizeLock> >::iterator it = resize_locks_.begin();
634 if (it == resize_locks_.end())
635 return false;
636
637 if (!(*it)->IsLocked())
638 return false;
639
640 UpdateResizeLocks(surface_size_in_dip);
641 return !resize_locks_.empty();
642 }
643
612 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( 644 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
613 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, 645 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
614 int gpu_host_id) { 646 int gpu_host_id) {
615 surface_route_id_ = params_in_pixel.route_id; 647 surface_route_id_ = params_in_pixel.route_id;
616 // If protection state changed, then this swap is stale. We must still ACK but 648 // If protection state changed, then this swap is stale. We must still ACK but
617 // do not update current_surface_ since it may have been discarded. 649 // do not update current_surface_ since it may have been discarded.
618 if (host_->is_hidden() || 650 if (host_->is_hidden() ||
619 (params_in_pixel.protection_state_id && 651 (params_in_pixel.protection_state_id &&
620 params_in_pixel.protection_state_id != protection_state_id_)) { 652 params_in_pixel.protection_state_id != protection_state_id_)) {
621 DCHECK(!current_surface_); 653 DCHECK(!current_surface_);
622 if (!params_in_pixel.skip_ack) 654 if (!params_in_pixel.skip_ack)
623 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL); 655 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
624 return; 656 return;
625 } 657 }
626 current_surface_ = params_in_pixel.surface_handle;
627 // If we don't require an ACK that means the content is not a fresh updated 658 // If we don't require an ACK that means the content is not a fresh updated
628 // new frame, rather we are just resetting our handle to some old content that 659 // new frame, rather we are just resetting our handle to some old content that
629 // we still hadn't discarded. Although we could display immediately, by not 660 // we still hadn't discarded. Although we could display immediately, by not
630 // resetting the compositor lock here, we give us some time to get a fresh 661 // resetting the compositor lock here, we give us some time to get a fresh
631 // frame which means fewer content flashes. 662 // frame which means fewer content flashes.
632 if (!params_in_pixel.skip_ack) 663 if (!params_in_pixel.skip_ack)
633 released_front_lock_ = NULL; 664 released_front_lock_ = NULL;
634 665
635 UpdateExternalTexture();
636
637 ui::Compositor* compositor = GetCompositor(); 666 ui::Compositor* compositor = GetCompositor();
638 if (!compositor) { 667 if (!compositor) {
639 // We have no compositor, so we have no way to display the surface. 668 // We have no compositor, so we have no way to display the surface.
640 // Must still send the ACK. 669 // Must still send the ACK.
641 if (!params_in_pixel.skip_ack) 670 if (!params_in_pixel.skip_ack)
642 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL); 671 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
643 } else { 672 } else {
644 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) != 673 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) !=
645 image_transport_clients_.end()); 674 image_transport_clients_.end());
646 gfx::Size surface_size_in_pixel = 675 gfx::Size surface_size_in_pixel =
647 image_transport_clients_[params_in_pixel.surface_handle]->size(); 676 image_transport_clients_[params_in_pixel.surface_handle]->size();
648 gfx::Size surface_size = ConvertSizeToDIP(this, 677 gfx::Size surface_size = ConvertSizeToDIP(this, surface_size_in_pixel);
649 surface_size_in_pixel);
650 window_->SchedulePaintInRect(gfx::Rect(surface_size)); 678 window_->SchedulePaintInRect(gfx::Rect(surface_size));
651 679
652 if (!params_in_pixel.skip_ack) { 680 if (params_in_pixel.skip_ack) {
653 if (!resize_locks_.empty()) { 681 current_surface_ = params_in_pixel.surface_handle;
654 // If we are waiting for the resize, fast-track the ACK. 682 UpdateExternalTexture();
655 if (compositor->IsThreaded()) { 683 } else {
656 // We need the compositor thread to pick up the active buffer before 684 if (CanFastTrackACK(surface_size)) {
657 // ACKing. 685 // Skip the flip.
658 on_compositing_did_commit_callbacks_.push_back( 686 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
659 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
660 params_in_pixel.route_id,
661 gpu_host_id));
662 if (!compositor->HasObserver(this))
663 compositor->AddObserver(this);
664 } else {
665 // The compositor will pickup the active buffer during a draw, so we
666 // can ACK immediately.
667 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id,
668 compositor);
669 }
670 } else { 687 } else {
671 // Add sending an ACK to the list of things to do OnCompositingWillStart 688 current_surface_ = params_in_pixel.surface_handle;
672 on_compositing_will_start_callbacks_.push_back( 689 UpdateExternalTexture();
690
691 AddCompositingStartedCallback(
673 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, 692 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
674 params_in_pixel.route_id, 693 params_in_pixel.route_id,
675 gpu_host_id)); 694 gpu_host_id));
676 if (!compositor->HasObserver(this))
677 compositor->AddObserver(this);
678 } 695 }
679 } 696 }
680 } 697 }
681 } 698 }
682 699
683 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( 700 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
684 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, 701 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
685 int gpu_host_id) { 702 int gpu_host_id) {
686 surface_route_id_ = params_in_pixel.route_id; 703 surface_route_id_ = params_in_pixel.route_id;
687 // If visible state changed, then this PSB is stale. We must still ACK but 704 // If visible state changed, then this PSB is stale. We must still ACK but
688 // do not update current_surface_. 705 // do not update current_surface_.
689 if (host_->is_hidden() || 706 if (host_->is_hidden() ||
690 (params_in_pixel.protection_state_id && 707 (params_in_pixel.protection_state_id &&
691 params_in_pixel.protection_state_id != protection_state_id_)) { 708 params_in_pixel.protection_state_id != protection_state_id_)) {
692 DCHECK(!current_surface_); 709 DCHECK(!current_surface_);
693 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL); 710 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
694 return; 711 return;
695 } 712 }
696 current_surface_ = params_in_pixel.surface_handle;
697 released_front_lock_ = NULL;
698 DCHECK(current_surface_);
699 UpdateExternalTexture();
700 713
701 ui::Compositor* compositor = GetCompositor(); 714 ui::Compositor* compositor = GetCompositor();
702 if (!compositor) { 715 if (!compositor) {
703 // We have no compositor, so we have no way to display the surface 716 // We have no compositor, so we have no way to display the surface
704 // Must still send the ACK 717 // Must still send the ACK
705 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL); 718 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
706 } else { 719 } else {
707 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) != 720 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) !=
708 image_transport_clients_.end()); 721 image_transport_clients_.end());
709 gfx::Size surface_size_in_pixel = 722 gfx::Size surface_size_in_pixel =
710 image_transport_clients_[params_in_pixel.surface_handle]->size(); 723 image_transport_clients_[params_in_pixel.surface_handle]->size();
711 724
712 // Co-ordinates come in OpenGL co-ordinate space. 725 // Co-ordinates come in OpenGL co-ordinate space.
713 // We need to convert to layer space. 726 // We need to convert to layer space.
714 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect( 727 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect(
715 params_in_pixel.x, 728 params_in_pixel.x,
716 surface_size_in_pixel.height() - params_in_pixel.y - 729 surface_size_in_pixel.height() - params_in_pixel.y -
717 params_in_pixel.height, 730 params_in_pixel.height,
718 params_in_pixel.width, 731 params_in_pixel.width,
719 params_in_pixel.height)); 732 params_in_pixel.height));
720 733
721 // Damage may not have been DIP aligned, so inflate damage to compensate 734 // Damage may not have been DIP aligned, so inflate damage to compensate
722 // for any round-off error. 735 // for any round-off error.
723 rect_to_paint.Inset(-1, -1); 736 rect_to_paint.Inset(-1, -1);
724 rect_to_paint.Intersect(window_->bounds()); 737 rect_to_paint.Intersect(window_->bounds());
725 738
726 window_->SchedulePaintInRect(rect_to_paint); 739 window_->SchedulePaintInRect(rect_to_paint);
727 740
728 if (!resize_locks_.empty()) { 741 if (CanFastTrackACK(ConvertSizeToDIP(this, surface_size_in_pixel))) {
729 // If we are waiting for the resize, fast-track the ACK. 742 // Skip the flip.
730 if (compositor->IsThreaded()) { 743 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
731 // We need the compositor thread to pick up the active buffer before
732 // ACKing.
733 on_compositing_did_commit_callbacks_.push_back(
734 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
735 params_in_pixel.route_id,
736 gpu_host_id));
737 if (!compositor->HasObserver(this))
738 compositor->AddObserver(this);
739 } else {
740 // The compositor will pickup the active buffer during a draw, so we
741 // can ACK immediately.
742 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id,
743 compositor);
744 }
745 } else { 744 } else {
746 // Add sending an ACK to the list of things to do OnCompositingWillStart 745 current_surface_ = params_in_pixel.surface_handle;
747 on_compositing_will_start_callbacks_.push_back( 746 released_front_lock_ = NULL;
747 DCHECK(current_surface_);
748 UpdateExternalTexture();
749
750 AddCompositingStartedCallback(
piman 2012/07/31 23:42:17 So, in the single-thread case, we're moving the sy
jonathan.backer 2012/08/01 17:22:43 Done.
748 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, 751 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
749 params_in_pixel.route_id, 752 params_in_pixel.route_id,
750 gpu_host_id)); 753 gpu_host_id));
751 if (!compositor->HasObserver(this))
752 compositor->AddObserver(this);
753 } 754 }
754 } 755 }
755 } 756 }
756 757
757 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { 758 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() {
758 } 759 }
759 760
760 bool RenderWidgetHostViewAura::HasAcceleratedSurface( 761 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
761 const gfx::Size& desired_size) { 762 const gfx::Size& desired_size) {
762 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't 763 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 1416
1416 void RenderWidgetHostViewAura::OnActivated() { 1417 void RenderWidgetHostViewAura::OnActivated() {
1417 } 1418 }
1418 1419
1419 void RenderWidgetHostViewAura::OnLostActive() { 1420 void RenderWidgetHostViewAura::OnLostActive() {
1420 } 1421 }
1421 1422
1422 //////////////////////////////////////////////////////////////////////////////// 1423 ////////////////////////////////////////////////////////////////////////////////
1423 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: 1424 // RenderWidgetHostViewAura, ui::CompositorObserver implementation:
1424 1425
1425 void RenderWidgetHostViewAura::OnCompositingDidCommit(
1426 ui::Compositor* compositor) {
1427 RunCompositingDidCommitCallbacks(compositor);
1428 }
1429
1430 void RenderWidgetHostViewAura::OnCompositingWillStart(
1431 ui::Compositor* compositor) {
1432 RunCompositingWillStartCallbacks(compositor);
1433 }
1434
1435 void RenderWidgetHostViewAura::OnCompositingStarted( 1426 void RenderWidgetHostViewAura::OnCompositingStarted(
1436 ui::Compositor* compositor) { 1427 ui::Compositor* compositor) {
1428 RunCompositingStartedCallbacks(compositor);
1437 locks_pending_draw_.clear(); 1429 locks_pending_draw_.clear();
1438 } 1430 }
1439 1431
1440 void RenderWidgetHostViewAura::OnCompositingEnded( 1432 void RenderWidgetHostViewAura::OnCompositingEnded(
1441 ui::Compositor* compositor) { 1433 ui::Compositor* compositor) {
1442 } 1434 }
1443 1435
1444 void RenderWidgetHostViewAura::OnCompositingAborted( 1436 void RenderWidgetHostViewAura::OnCompositingAborted(
1445 ui::Compositor* compositor) { 1437 ui::Compositor* compositor) {
1446 } 1438 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 gfx::Rect rect = window_->bounds(); 1569 gfx::Rect rect = window_->bounds();
1578 int border_x = rect.width() * kMouseLockBorderPercentage / 100; 1570 int border_x = rect.width() * kMouseLockBorderPercentage / 100;
1579 int border_y = rect.height() * kMouseLockBorderPercentage / 100; 1571 int border_y = rect.height() * kMouseLockBorderPercentage / 100;
1580 1572
1581 return global_mouse_position_.x() < rect.x() + border_x || 1573 return global_mouse_position_.x() < rect.x() + border_x ||
1582 global_mouse_position_.x() > rect.right() - border_x || 1574 global_mouse_position_.x() > rect.right() - border_x ||
1583 global_mouse_position_.y() < rect.y() + border_y || 1575 global_mouse_position_.y() < rect.y() + border_y ||
1584 global_mouse_position_.y() > rect.bottom() - border_y; 1576 global_mouse_position_.y() > rect.bottom() - border_y;
1585 } 1577 }
1586 1578
1587 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks( 1579 void RenderWidgetHostViewAura::RunCompositingStartedCallbacks(
1588 ui::Compositor* compositor) { 1580 ui::Compositor* compositor) {
1589 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator 1581 std::vector<CommitIdAndCallback> uncalled;
1590 it = on_compositing_did_commit_callbacks_.begin(); 1582 for (std::vector<CommitIdAndCallback>::const_iterator
1591 it != on_compositing_did_commit_callbacks_.end(); ++it) { 1583 it = on_compositing_started_callbacks_.begin();
1592 it->Run(compositor); 1584 it != on_compositing_started_callbacks_.end(); ++it) {
1585 if (it->first <= compositor->last_commit_id()) {
1586 it->second.Run(compositor);
1587 } else {
1588 uncalled.push_back(*it);
1589 }
1593 } 1590 }
1594 on_compositing_did_commit_callbacks_.clear(); 1591 on_compositing_started_callbacks_.swap(uncalled);
1595 } 1592 }
1596 1593
1597 void RenderWidgetHostViewAura::RunCompositingWillStartCallbacks( 1594 void RenderWidgetHostViewAura::AddCompositingStartedCallback(
1598 ui::Compositor* compositor) { 1595 base::Callback<void(ui::Compositor*)> callback) {
1599 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator 1596 ui::Compositor* compositor = GetCompositor();
1600 it = on_compositing_will_start_callbacks_.begin(); 1597 DCHECK(compositor);
1601 it != on_compositing_will_start_callbacks_.end(); ++it) { 1598 on_compositing_started_callbacks_.push_back(
1602 it->Run(compositor); 1599 CommitIdAndCallback(compositor->last_commit_id() + 1, callback));
1603 } 1600 if (!compositor->HasObserver(this))
1604 on_compositing_will_start_callbacks_.clear(); 1601 compositor->AddObserver(this);
1605 } 1602 }
1606 1603
1607 // static 1604 // static
1608 void RenderWidgetHostViewAura::InsertSyncPointAndACK( 1605 void RenderWidgetHostViewAura::InsertSyncPointAndACK(
1609 int32 route_id, int gpu_host_id, ui::Compositor* compositor) { 1606 int32 route_id, int gpu_host_id, ui::Compositor* compositor) {
1610 uint32 sync_point = 0; 1607 uint32 sync_point = 0;
1611 // If we have no compositor, so we must still send the ACK. A zero 1608 // If we have no compositor, so we must still send the ACK. A zero
1612 // sync point will not be waited for in the GPU process. 1609 // sync point will not be waited for in the GPU process.
1613 if (compositor) { 1610 if (compositor) {
1614 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1611 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1615 sync_point = factory->InsertSyncPoint(compositor); 1612 sync_point = factory->InsertSyncPoint(compositor);
1616 } 1613 }
1617 1614
1618 RenderWidgetHostImpl::AcknowledgeBufferPresent( 1615 RenderWidgetHostImpl::AcknowledgeBufferPresent(
1619 route_id, gpu_host_id, sync_point); 1616 route_id, gpu_host_id, sync_point);
1620 } 1617 }
1621 1618
1622 void RenderWidgetHostViewAura::RemovingFromRootWindow() { 1619 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
1623 // We are about to disconnect ourselves from the compositor, we need to issue 1620 // We are about to disconnect ourselves from the compositor, we need to issue
1624 // the callbacks now, because we won't get notified when the frame is done. 1621 // the callbacks now, because we won't get notified when the frame is done.
1625 // TODO(piman): this might in theory cause a race where the GPU process starts 1622 // TODO(piman): this might in theory cause a race where the GPU process starts
1626 // drawing to the buffer we haven't yet displayed. This will only show for 1 1623 // drawing to the buffer we haven't yet displayed. This will only show for 1
1627 // frame though, because we will reissue a new frame right away without that 1624 // frame though, because we will reissue a new frame right away without that
1628 // composited data. 1625 // composited data.
1629 ui::Compositor* compositor = GetCompositor(); 1626 ui::Compositor* compositor = GetCompositor();
1630 RunCompositingDidCommitCallbacks(compositor); 1627 RunCompositingStartedCallbacks(compositor);
1631 RunCompositingWillStartCallbacks(compositor);
1632 locks_pending_draw_.clear(); 1628 locks_pending_draw_.clear();
1633 if (compositor && compositor->HasObserver(this)) 1629 if (compositor && compositor->HasObserver(this))
1634 compositor->RemoveObserver(this); 1630 compositor->RemoveObserver(this);
1635 DetachFromInputMethod(); 1631 DetachFromInputMethod();
1636 } 1632 }
1637 1633
1638 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { 1634 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() {
1639 aura::RootWindow* root_window = window_->GetRootWindow(); 1635 aura::RootWindow* root_window = window_->GetRootWindow();
1640 return root_window ? root_window->compositor() : NULL; 1636 return root_window ? root_window->compositor() : NULL;
1641 } 1637 }
(...skipping 12 matching lines...) Expand all
1654 RenderWidgetHost* widget) { 1650 RenderWidgetHost* widget) {
1655 return new RenderWidgetHostViewAura(widget); 1651 return new RenderWidgetHostViewAura(widget);
1656 } 1652 }
1657 1653
1658 // static 1654 // static
1659 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { 1655 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) {
1660 GetScreenInfoForWindow(results, NULL); 1656 GetScreenInfoForWindow(results, NULL);
1661 } 1657 }
1662 1658
1663 } // namespace content 1659 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698