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

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

Issue 11194042: Implement TextureImageTransportSurface using texture mailbox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 27 matching lines...) Expand all
38 #include "ui/aura/root_window.h" 38 #include "ui/aura/root_window.h"
39 #include "ui/aura/window.h" 39 #include "ui/aura/window.h"
40 #include "ui/aura/window_observer.h" 40 #include "ui/aura/window_observer.h"
41 #include "ui/aura/window_tracker.h" 41 #include "ui/aura/window_tracker.h"
42 #include "ui/base/clipboard/scoped_clipboard_writer.h" 42 #include "ui/base/clipboard/scoped_clipboard_writer.h"
43 #include "ui/base/events/event.h" 43 #include "ui/base/events/event.h"
44 #include "ui/base/gestures/gesture_recognizer.h" 44 #include "ui/base/gestures/gesture_recognizer.h"
45 #include "ui/base/hit_test.h" 45 #include "ui/base/hit_test.h"
46 #include "ui/base/ime/input_method.h" 46 #include "ui/base/ime/input_method.h"
47 #include "ui/base/ui_base_types.h" 47 #include "ui/base/ui_base_types.h"
48 #include "ui/compositor/compositor.h"
49 #include "ui/compositor/layer.h" 48 #include "ui/compositor/layer.h"
50 #include "ui/gfx/canvas.h" 49 #include "ui/gfx/canvas.h"
51 #include "ui/gfx/display.h" 50 #include "ui/gfx/display.h"
52 #include "ui/gfx/rect_conversions.h" 51 #include "ui/gfx/rect_conversions.h"
53 #include "ui/gfx/screen.h" 52 #include "ui/gfx/screen.h"
54 #include "ui/gfx/skia_util.h" 53 #include "ui/gfx/skia_util.h"
55 54
56 #if defined(OS_WIN) 55 #if defined(OS_WIN)
57 #include "ui/base/win/hidden_window.h" 56 #include "ui/base/win/hidden_window.h"
58 #endif 57 #endif
59 58
59 using gfx::RectToSkIRect;
60 using gfx::SkIRectToRect;
61
60 using WebKit::WebScreenInfo; 62 using WebKit::WebScreenInfo;
61 using WebKit::WebTouchEvent; 63 using WebKit::WebTouchEvent;
62 64
63 namespace content { 65 namespace content {
64 namespace { 66 namespace {
65 67
66 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting 68 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting
67 // the border of the view, in order to get valid movement information. However, 69 // the border of the view, in order to get valid movement information. However,
68 // forcing the cursor back to the center of the view after each mouse move 70 // forcing the cursor back to the center of the view after each mouse move
69 // doesn't work well. It reduces the frequency of useful mouse move messages 71 // doesn't work well. It reduces the frequency of useful mouse move messages
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 private: 258 private:
257 aura::RootWindow* root_window_; 259 aura::RootWindow* root_window_;
258 gfx::Size new_size_; 260 gfx::Size new_size_;
259 scoped_refptr<ui::CompositorLock> compositor_lock_; 261 scoped_refptr<ui::CompositorLock> compositor_lock_;
260 base::WeakPtrFactory<ResizeLock> weak_ptr_factory_; 262 base::WeakPtrFactory<ResizeLock> weak_ptr_factory_;
261 bool defer_compositor_lock_; 263 bool defer_compositor_lock_;
262 264
263 DISALLOW_COPY_AND_ASSIGN(ResizeLock); 265 DISALLOW_COPY_AND_ASSIGN(ResizeLock);
264 }; 266 };
265 267
268 RenderWidgetHostViewAura::BufferPresentedParams::BufferPresentedParams(
269 int route_id,
270 int gpu_host_id,
271 uint64 surface_handle)
272 : route_id(route_id),
273 gpu_host_id(gpu_host_id),
274 surface_handle(surface_handle) {
275 }
276
277 RenderWidgetHostViewAura::BufferPresentedParams::~BufferPresentedParams() {
278 }
279
266 //////////////////////////////////////////////////////////////////////////////// 280 ////////////////////////////////////////////////////////////////////////////////
267 // RenderWidgetHostViewAura, public: 281 // RenderWidgetHostViewAura, public:
268 282
269 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) 283 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
270 : host_(RenderWidgetHostImpl::From(host)), 284 : host_(RenderWidgetHostImpl::From(host)),
271 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), 285 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
272 in_shutdown_(false), 286 in_shutdown_(false),
273 is_fullscreen_(false), 287 is_fullscreen_(false),
274 popup_parent_host_view_(NULL), 288 popup_parent_host_view_(NULL),
275 popup_child_host_view_(NULL), 289 popup_child_host_view_(NULL),
276 is_loading_(false), 290 is_loading_(false),
277 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 291 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
278 can_compose_inline_(true), 292 can_compose_inline_(true),
279 has_composition_text_(false), 293 has_composition_text_(false),
280 device_scale_factor_(1.0f), 294 device_scale_factor_(1.0f),
281 current_surface_(0), 295 current_surface_(0),
282 current_surface_is_protected_(true),
283 current_surface_in_use_by_compositor_(true),
284 protection_state_id_(0),
285 surface_route_id_(0),
286 paint_canvas_(NULL), 296 paint_canvas_(NULL),
287 synthetic_move_sent_(false), 297 synthetic_move_sent_(false),
288 accelerated_compositing_state_changed_(false), 298 accelerated_compositing_state_changed_(false),
289 can_lock_compositor_(YES) { 299 can_lock_compositor_(YES) {
290 host_->SetView(this); 300 host_->SetView(this);
291 window_observer_.reset(new WindowObserver(this)); 301 window_observer_.reset(new WindowObserver(this));
292 window_->AddObserver(window_observer_.get()); 302 window_->AddObserver(window_observer_.get());
293 aura::client::SetTooltipText(window_, &tooltip_); 303 aura::client::SetTooltipText(window_, &tooltip_);
294 aura::client::SetActivationDelegate(window_, this); 304 aura::client::SetActivationDelegate(window_, this);
295 gfx::Screen::GetScreenFor(window_)->AddObserver(this); 305 gfx::Screen::GetScreenFor(window_)->AddObserver(this);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 void RenderWidgetHostViewAura::WasShown() { 385 void RenderWidgetHostViewAura::WasShown() {
376 if (!host_->is_hidden()) 386 if (!host_->is_hidden())
377 return; 387 return;
378 host_->WasShown(); 388 host_->WasShown();
379 389
380 if (!current_surface_ && host_->is_accelerated_compositing_active() && 390 if (!current_surface_ && host_->is_accelerated_compositing_active() &&
381 !released_front_lock_.get()) { 391 !released_front_lock_.get()) {
382 released_front_lock_ = GetCompositor()->GetCompositorLock(); 392 released_front_lock_ = GetCompositor()->GetCompositorLock();
383 } 393 }
384 394
385 AdjustSurfaceProtection();
386
387 #if defined(OS_WIN) 395 #if defined(OS_WIN)
388 LPARAM lparam = reinterpret_cast<LPARAM>(this); 396 LPARAM lparam = reinterpret_cast<LPARAM>(this);
389 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); 397 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam);
390 #endif 398 #endif
391 } 399 }
392 400
393 void RenderWidgetHostViewAura::WasHidden() { 401 void RenderWidgetHostViewAura::WasHidden() {
394 if (host_->is_hidden()) 402 if (host_->is_hidden())
395 return; 403 return;
396 host_->WasHidden(); 404 host_->WasHidden();
397 405
398 released_front_lock_ = NULL; 406 released_front_lock_ = NULL;
399 407
400 if (ShouldReleaseFrontSurface() &&
401 host_->is_accelerated_compositing_active()) {
402 current_surface_ = 0;
403 UpdateExternalTexture();
404 }
405
406 AdjustSurfaceProtection();
407
408 #if defined(OS_WIN) 408 #if defined(OS_WIN)
409 aura::RootWindow* root_window = window_->GetRootWindow(); 409 aura::RootWindow* root_window = window_->GetRootWindow();
410 if (root_window) { 410 if (root_window) {
411 HWND parent = root_window->GetAcceleratedWidget(); 411 HWND parent = root_window->GetAcceleratedWidget();
412 LPARAM lparam = reinterpret_cast<LPARAM>(this); 412 LPARAM lparam = reinterpret_cast<LPARAM>(this);
413 413
414 EnumChildWindows(parent, HideWindowsCallback, lparam); 414 EnumChildWindows(parent, HideWindowsCallback, lparam);
415 } 415 }
416 #endif 416 #endif
417 } 417 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 704
705 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 705 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
706 GLHelper* gl_helper = factory->GetGLHelper(); 706 GLHelper* gl_helper = factory->GetGLHelper();
707 if (!gl_helper) 707 if (!gl_helper)
708 return; 708 return;
709 709
710 unsigned char* addr = static_cast<unsigned char*>( 710 unsigned char* addr = static_cast<unsigned char*>(
711 output->GetBitmap().getPixels()); 711 output->GetBitmap().getPixels());
712 scoped_callback_runner.Release(); 712 scoped_callback_runner.Release();
713 // Wrap the callback with an internal handler so that we can inject our 713 // Wrap the callback with an internal handler so that we can inject our
714 // own completion handlers (where we can call AdjustSurfaceProtection). 714 // own completion handlers (where we can try to free the frontbuffer).
715 base::Callback<void(bool)> wrapper_callback = base::Bind( 715 base::Callback<void(bool)> wrapper_callback = base::Bind(
716 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished, 716 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished,
717 AsWeakPtr(), 717 AsWeakPtr(),
718 callback); 718 callback);
719 ++pending_thumbnail_tasks_; 719 ++pending_thumbnail_tasks_;
720 720
721 // Convert |src_subrect| from the views coordinate (upper-left origin) into 721 // Convert |src_subrect| from the views coordinate (upper-left origin) into
722 // the OpenGL coordinate (lower-left origin). 722 // the OpenGL coordinate (lower-left origin).
723 gfx::Rect src_subrect_in_gl = src_subrect; 723 gfx::Rect src_subrect_in_gl = src_subrect;
724 src_subrect_in_gl.set_y(GetViewBounds().height() - src_subrect.bottom()); 724 src_subrect_in_gl.set_y(GetViewBounds().height() - src_subrect.bottom());
(...skipping 12 matching lines...) Expand all
737 // switching to software mode or receive a buffers swapped notification 737 // switching to software mode or receive a buffers swapped notification
738 // if switching to accelerated mode. 738 // if switching to accelerated mode.
739 // Sometimes (e.g. on a page load) the renderer will spuriously disable then 739 // Sometimes (e.g. on a page load) the renderer will spuriously disable then
740 // re-enable accelerated compositing, causing us to flash. 740 // re-enable accelerated compositing, causing us to flash.
741 // TODO(piman): factor the enable/disable accelerated compositing message into 741 // TODO(piman): factor the enable/disable accelerated compositing message into
742 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have 742 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have
743 // fewer inconsistent temporary states. 743 // fewer inconsistent temporary states.
744 accelerated_compositing_state_changed_ = true; 744 accelerated_compositing_state_changed_ = true;
745 } 745 }
746 746
747 bool RenderWidgetHostViewAura::ShouldFastACK(uint64 surface_id) { 747 bool RenderWidgetHostViewAura::ShouldSkipFrame(const gfx::Size& size) {
748 ui::Texture* container = image_transport_clients_[surface_id];
749 DCHECK(container);
750
751 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || 748 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME ||
752 can_lock_compositor_ == NO_PENDING_COMMIT || 749 can_lock_compositor_ == NO_PENDING_COMMIT ||
753 resize_locks_.empty()) 750 resize_locks_.empty())
754 return false; 751 return false;
755 752
756 gfx::Size container_size = ConvertSizeToDIP(this, container->size()); 753 gfx::Size container_size = ConvertSizeToDIP(this, size);
757 ResizeLockList::iterator it = resize_locks_.begin(); 754 ResizeLockList::iterator it = resize_locks_.begin();
758 while (it != resize_locks_.end()) { 755 while (it != resize_locks_.end()) {
759 if ((*it)->expected_size() == container_size) 756 if ((*it)->expected_size() == container_size)
760 break; 757 break;
761 ++it; 758 ++it;
762 } 759 }
763 760
764 // We could be getting an unexpected frame due to an animation 761 // We could be getting an unexpected frame due to an animation
765 // (i.e. we start resizing but we get an old size frame first). 762 // (i.e. we start resizing but we get an old size frame first).
766 return it == resize_locks_.end() || ++it != resize_locks_.end(); 763 return it == resize_locks_.end() || ++it != resize_locks_.end();
767 } 764 }
768 765
769 void RenderWidgetHostViewAura::UpdateExternalTexture() { 766 void RenderWidgetHostViewAura::UpdateExternalTexture() {
770 // Delay processing accelerated compositing state change till here where we 767 // Delay processing accelerated compositing state change till here where we
771 // act upon the state change. (Clear the external texture if switching to 768 // act upon the state change. (Clear the external texture if switching to
772 // software mode or set the external texture if going to accelerated mode). 769 // software mode or set the external texture if going to accelerated mode).
773 if (accelerated_compositing_state_changed_) 770 if (accelerated_compositing_state_changed_)
774 accelerated_compositing_state_changed_ = false; 771 accelerated_compositing_state_changed_ = false;
775 772
776 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) { 773 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) {
777 ui::Texture* container = image_transport_clients_[current_surface_]; 774 ui::Texture* container = image_transport_clients_[current_surface_];
778 window_->SetExternalTexture(container); 775 window_->SetExternalTexture(container);
779 current_surface_in_use_by_compositor_ = true;
780 776
781 if (!container) { 777 if (!container) {
782 resize_locks_.clear(); 778 resize_locks_.clear();
783 } else { 779 } else {
784 ResizeLockList::iterator it = resize_locks_.begin(); 780 ResizeLockList::iterator it = resize_locks_.begin();
785 while (it != resize_locks_.end()) { 781 while (it != resize_locks_.end()) {
786 gfx::Size container_size = ConvertSizeToDIP(this, 782 gfx::Size container_size = ConvertSizeToDIP(this,
787 container->size()); 783 container->size());
788 if ((*it)->expected_size() == container_size) 784 if ((*it)->expected_size() == container_size)
789 break; 785 break;
(...skipping 15 matching lines...) Expand all
805 it2->get()->UnlockCompositor(); 801 it2->get()->UnlockCompositor();
806 } 802 }
807 if (!compositor->HasObserver(this)) 803 if (!compositor->HasObserver(this))
808 compositor->AddObserver(this); 804 compositor->AddObserver(this);
809 } 805 }
810 resize_locks_.erase(resize_locks_.begin(), it); 806 resize_locks_.erase(resize_locks_.begin(), it);
811 } 807 }
812 } 808 }
813 } else { 809 } else {
814 window_->SetExternalTexture(NULL); 810 window_->SetExternalTexture(NULL);
815 if (ShouldReleaseFrontSurface() &&
816 host_->is_accelerated_compositing_active()) {
817 // We need to wait for a commit to clear to guarantee that all we
818 // will not issue any more GL referencing the previous surface.
819 ui::Compositor* compositor = GetCompositor();
820 if (compositor) {
821 can_lock_compositor_ = NO_PENDING_COMMIT;
822 on_compositing_did_commit_callbacks_.push_back(
823 base::Bind(&RenderWidgetHostViewAura::
824 SetSurfaceNotInUseByCompositor,
825 AsWeakPtr()));
826 if (!compositor->HasObserver(this))
827 compositor->AddObserver(this);
828 }
829 }
830 resize_locks_.clear(); 811 resize_locks_.clear();
831 } 812 }
832 } 813 }
833 814
815 bool RenderWidgetHostViewAura::SwapBuffersPrepare(
816 const gfx::Rect& surface_rect,
817 const gfx::Rect& damage_rect,
818 BufferPresentedParams& params) {
piman 2012/11/30 03:54:32 nit: style says no non-const reference as paramete
819 DCHECK(params.surface_handle);
820 DCHECK(!params.texture_to_produce);
821
822 if (previous_surface_size_ != surface_rect.size()) {
823 // The surface could have shrunk since we skipped an update, in which
824 // case we can expect a full update.
825 DLOG_IF(ERROR, damage_rect != surface_rect) << "Expected full damage rect";
826 skipped_damage_.setEmpty();
jonathan.backer 2012/11/20 21:21:11 I like the idea of the sanity check, but we're not
no sievers 2012/12/01 00:58:38 But I do want to reset the skipped_damage_ here. T
827 previous_surface_size_ = surface_rect.size();
828 }
829
830 if (ShouldSkipFrame(surface_rect.size()) || !GetCompositor()) {
piman 2012/11/30 03:54:32 As mentioned before, even if we don't have a compo
no sievers 2012/12/01 00:58:38 Ok, so I've changed it to *not* do the fast ack he
piman 2012/12/03 21:08:43 Yep, great.
831 skipped_damage_.op(RectToSkIRect(damage_rect), SkRegion::kUnion_Op);
832 InsertSyncPointAndACK(params);
833 return false;
834 }
835
836 const uint64 previous_surface = current_surface_;
837 DCHECK(!previous_surface || image_transport_clients_.find(previous_surface) !=
838 image_transport_clients_.end());
839 if (previous_surface)
840 params.texture_to_produce = image_transport_clients_[previous_surface];
841
842 current_surface_ = params.surface_handle;
843 params.surface_handle = previous_surface;
piman 2012/11/30 03:54:32 nit: how about std::swap?
844
845 DCHECK(image_transport_clients_.find(current_surface_) !=
846 image_transport_clients_.end());
847
848 image_transport_clients_[current_surface_]->Consume(surface_rect.size());
849 released_front_lock_ = NULL;
850 UpdateExternalTexture();
851
852 return true;
853 }
854
855 void RenderWidgetHostViewAura::SwapBuffersCompleted(
856 const BufferPresentedParams& params) {
857 ui::Compositor* compositor = GetCompositor();
858 if (!compositor) {
859 InsertSyncPointAndACK(params);
860 } else {
861 // Add sending an ACK to the list of things to do OnCompositingDidCommit
862 can_lock_compositor_ = NO_PENDING_COMMIT;
863 on_compositing_did_commit_callbacks_.push_back(
864 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, params));
865 if (!compositor->HasObserver(this))
866 compositor->AddObserver(this);
867 }
868 }
869
834 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( 870 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
835 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, 871 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
836 int gpu_host_id) { 872 int gpu_host_id) {
837 surface_route_id_ = params_in_pixel.route_id; 873 const gfx::Rect surface_rect = gfx::Rect(gfx::Point(), params_in_pixel.size);
838 // If protection state changed, then this swap is stale. We must still ACK but 874 BufferPresentedParams ack_params(
839 // do not update current_surface_ since it may have been discarded. 875 params_in_pixel.route_id, gpu_host_id, params_in_pixel.surface_handle);
840 if (params_in_pixel.protection_state_id && 876 if (!SwapBuffersPrepare(surface_rect, surface_rect, ack_params))
841 params_in_pixel.protection_state_id != protection_state_id_) {
842 DCHECK(!current_surface_);
843 if (!params_in_pixel.skip_ack)
844 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL);
845 return; 877 return;
878
879 previous_damage_.setRect(RectToSkIRect(surface_rect));
880 skipped_damage_.setEmpty();
881
882 ui::Compositor* compositor = GetCompositor();
jonathan.backer 2012/11/20 21:21:11 Don't we know we have a compositor here? If not |S
no sievers 2012/12/01 00:58:38 Since I changed it in the latest patch to copy the
883 if (compositor) {
884 gfx::Size surface_size = ConvertSizeToDIP(this, params_in_pixel.size);
885 window_->SchedulePaintInRect(gfx::Rect(surface_size));
846 } 886 }
847 887
848 if (ShouldFastACK(params_in_pixel.surface_handle)) { 888 SwapBuffersCompleted(ack_params);
849 if (!params_in_pixel.skip_ack)
850 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL);
851 return;
852 }
853
854 current_surface_ = params_in_pixel.surface_handle;
855 // If we don't require an ACK that means the content is not a fresh updated
856 // new frame, rather we are just resetting our handle to some old content
857 // that we still hadn't discarded. Although we could display immediately,
858 // by not resetting the compositor lock here, we give us some time to get
859 // a fresh frame which means fewer content flashes.
860 if (!params_in_pixel.skip_ack)
861 released_front_lock_ = NULL;
862
863 UpdateExternalTexture();
864
865 ui::Compositor* compositor = GetCompositor();
866 if (!compositor) {
867 if (!params_in_pixel.skip_ack)
868 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, true, NULL);
869 } else {
870 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) !=
871 image_transport_clients_.end());
872 gfx::Size surface_size_in_pixel =
873 image_transport_clients_[params_in_pixel.surface_handle]->size();
874 gfx::Size surface_size = ConvertSizeToDIP(this, surface_size_in_pixel);
875 window_->SchedulePaintInRect(gfx::Rect(surface_size));
876
877 if (!params_in_pixel.skip_ack) {
878 // Add sending an ACK to the list of things to do OnCompositingDidCommit
879 can_lock_compositor_ = NO_PENDING_COMMIT;
880 on_compositing_did_commit_callbacks_.push_back(
881 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
882 params_in_pixel.route_id,
883 gpu_host_id,
884 true));
885 if (!compositor->HasObserver(this))
886 compositor->AddObserver(this);
887 }
888 }
889 } 889 }
890 890
891 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( 891 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
892 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, 892 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
893 int gpu_host_id) { 893 int gpu_host_id) {
894 surface_route_id_ = params_in_pixel.route_id; 894 const gfx::Rect surface_rect =
895 // If visible state changed, then this PSB is stale. We must still ACK but 895 gfx::Rect(gfx::Point(), params_in_pixel.surface_size);
896 // do not update current_surface_. 896 gfx::Rect damage_rect(params_in_pixel.x,
897 if (params_in_pixel.protection_state_id && 897 params_in_pixel.y,
898 params_in_pixel.protection_state_id != protection_state_id_) { 898 params_in_pixel.width,
899 DCHECK(!current_surface_); 899 params_in_pixel.height);
900 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); 900 BufferPresentedParams ack_params(
901 params_in_pixel.route_id, gpu_host_id, params_in_pixel.surface_handle);
902 if (!SwapBuffersPrepare(surface_rect, damage_rect, ack_params))
901 return; 903 return;
904
905 SkRegion damage(RectToSkIRect(damage_rect));
906 if (!skipped_damage_.isEmpty()) {
907 damage.op(skipped_damage_, SkRegion::kUnion_Op);
908 damage_rect = gfx::SkIRectToRect(damage.getBounds());
jonathan.backer 2012/11/20 21:21:11 Why reset |damage_rect|? Just for the following DC
909 skipped_damage_.setEmpty();
902 } 910 }
903 911
904 if (ShouldFastACK(params_in_pixel.surface_handle)) { 912 DCHECK(surface_rect.Contains(damage_rect));
905 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); 913 ui::Texture* current_texture = image_transport_clients_[current_surface_];
906 return;
907 }
908
909 current_surface_ = params_in_pixel.surface_handle;
910 released_front_lock_ = NULL;
911 DCHECK(current_surface_);
912 UpdateExternalTexture();
913 914
914 ui::Compositor* compositor = GetCompositor(); 915 ui::Compositor* compositor = GetCompositor();
jonathan.backer 2012/11/20 21:21:11 Same as above. We know that we have a compositor h
915 if (!compositor) { 916 if (compositor) {
916 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, true, NULL); 917 const gfx::Size surface_size_in_pixel = params_in_pixel.surface_size;
917 } else { 918 DLOG_IF(ERROR, ack_params.texture_to_produce &&
918 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) != 919 ack_params.texture_to_produce->size() != current_texture->size() &&
919 image_transport_clients_.end()); 920 damage_rect != surface_rect) <<
920 gfx::Size surface_size_in_pixel = 921 "Expected full damage rect after size change";
921 image_transport_clients_[params_in_pixel.surface_handle]->size(); 922 if (ack_params.texture_to_produce && !previous_damage_.isEmpty() &&
923 ack_params.texture_to_produce->size() == current_texture->size()) {
924 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
925 GLHelper* gl_helper = factory->GetGLHelper();
926 gl_helper->CopySubBufferDamage(
927 current_texture->PrepareTexture(),
928 ack_params.texture_to_produce->PrepareTexture(),
929 damage,
930 previous_damage_);
931 }
932 previous_damage_ = damage;
jonathan.backer 2012/11/20 21:21:11 This seems like too much damage! We're flipping an
jonathan.backer 2012/11/21 05:47:05 Please ignore this comment.
922 933
923 // Co-ordinates come in OpenGL co-ordinate space. 934 // Co-ordinates come in OpenGL co-ordinate space.
924 // We need to convert to layer space. 935 // We need to convert to layer space.
925 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect( 936 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect(
926 params_in_pixel.x, 937 params_in_pixel.x,
927 surface_size_in_pixel.height() - params_in_pixel.y - 938 surface_size_in_pixel.height() - params_in_pixel.y -
928 params_in_pixel.height, 939 params_in_pixel.height,
929 params_in_pixel.width, 940 params_in_pixel.width,
930 params_in_pixel.height)); 941 params_in_pixel.height));
931 942
932 // Damage may not have been DIP aligned, so inflate damage to compensate 943 // Damage may not have been DIP aligned, so inflate damage to compensate
933 // for any round-off error. 944 // for any round-off error.
934 rect_to_paint.Inset(-1, -1); 945 rect_to_paint.Inset(-1, -1);
935 rect_to_paint.Intersect(window_->bounds()); 946 rect_to_paint.Intersect(window_->bounds());
936 947
937 window_->SchedulePaintInRect(rect_to_paint); 948 window_->SchedulePaintInRect(rect_to_paint);
949 }
938 950
939 // Add sending an ACK to the list of things to do OnCompositingDidCommit 951 SwapBuffersCompleted(ack_params);
940 can_lock_compositor_ = NO_PENDING_COMMIT;
941 on_compositing_did_commit_callbacks_.push_back(
942 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
943 params_in_pixel.route_id,
944 gpu_host_id,
945 true));
946 if (!compositor->HasObserver(this))
947 compositor->AddObserver(this);
948 }
949 } 952 }
950 953
951 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { 954 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() {
952 } 955 }
953 956
954 bool RenderWidgetHostViewAura::HasAcceleratedSurface( 957 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
955 const gfx::Size& desired_size) { 958 const gfx::Size& desired_size) {
956 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't 959 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't
957 // matter what is returned here as GetBackingStore is the only caller of this 960 // matter what is returned here as GetBackingStore is the only caller of this
958 // method. TODO(jbates) implement this if other Aura code needs it. 961 // method. TODO(jbates) implement this if other Aura code needs it.
959 return false; 962 return false;
960 } 963 }
961 964
962 // TODO(backer): Drop the |shm_handle| once I remove some unused service side 965 // TODO(backer): Drop the |shm_handle| once I remove some unused service side
963 // code. 966 // code.
964 void RenderWidgetHostViewAura::AcceleratedSurfaceNew( 967 void RenderWidgetHostViewAura::AcceleratedSurfaceNew(
965 int32 width_in_pixel, 968 int32 width_in_pixel,
966 int32 height_in_pixel, 969 int32 height_in_pixel,
967 uint64 surface_handle) { 970 uint64 surface_handle,
971 const std::string& mailbox_name) {
968 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 972 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
969 scoped_refptr<ui::Texture> surface(factory->CreateTransportClient( 973 scoped_refptr<ui::Texture> surface(factory->CreateTransportClient(
970 gfx::Size(width_in_pixel, height_in_pixel), device_scale_factor_, 974 gfx::Size(width_in_pixel, height_in_pixel), device_scale_factor_,
971 surface_handle)); 975 mailbox_name));
972 if (!surface) { 976 if (!surface) {
973 LOG(ERROR) << "Failed to create ImageTransport texture"; 977 LOG(ERROR) << "Failed to create ImageTransport texture";
974 return; 978 return;
975 } 979 }
976
977 image_transport_clients_[surface_handle] = surface; 980 image_transport_clients_[surface_handle] = surface;
978 } 981 }
979 982
980 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease( 983 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease(
981 uint64 surface_handle) { 984 uint64 surface_handle) {
982 DCHECK(image_transport_clients_.find(surface_handle) != 985 // This really tells us to release the frontbuffer.
983 image_transport_clients_.end()); 986 if (current_surface_ && ShouldReleaseFrontSurface()) {
984 if (current_surface_ == surface_handle) { 987 ui::Compositor* compositor = GetCompositor();
988 if (compositor) {
989 // We need to wait for a commit to clear to guarantee that all we
990 // will not issue any more GL referencing the previous surface.
991 can_lock_compositor_ = NO_PENDING_COMMIT;
992 scoped_refptr<ui::Texture> surface_ref =
993 image_transport_clients_[surface_handle];
994 on_compositing_did_commit_callbacks_.push_back(
995 base::Bind(&RenderWidgetHostViewAura::
996 SetSurfaceNotInUseByCompositor,
997 AsWeakPtr(),
998 surface_ref));
jonathan.backer 2012/11/20 21:21:11 Isn't this a no-op now?
piman 2012/11/30 03:54:32 My understanding is that it's just there to keep a
no sievers 2012/12/01 00:58:38 Yes, it's there to make sure we don't delete the t
999 if (!compositor->HasObserver(this))
1000 compositor->AddObserver(this);
1001 }
1002 image_transport_clients_.erase(current_surface_);
985 current_surface_ = 0; 1003 current_surface_ = 0;
986 UpdateExternalTexture(); 1004 UpdateExternalTexture();
987 } 1005 }
988 image_transport_clients_.erase(surface_handle);
989 } 1006 }
990 1007
991 void RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor(ui::Compositor*) { 1008 void RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor(
992 if (current_surface_ || !host_->is_hidden()) 1009 scoped_refptr<ui::Texture>) {
993 return;
994 current_surface_in_use_by_compositor_ = false;
995 AdjustSurfaceProtection();
996 }
997
998 void RenderWidgetHostViewAura::AdjustSurfaceProtection() {
999 // If the current surface is non null, it is protected.
1000 // If we are visible, it is protected.
1001 // Otherwise, change to not proctected once done thumbnailing and compositing.
1002 bool surface_is_protected =
1003 current_surface_ ||
1004 !host_->is_hidden() ||
1005 (current_surface_is_protected_ &&
1006 (pending_thumbnail_tasks_ > 0 ||
1007 current_surface_in_use_by_compositor_));
1008 if (current_surface_is_protected_ == surface_is_protected)
1009 return;
1010 current_surface_is_protected_ = surface_is_protected;
1011 ++protection_state_id_;
1012
1013 if (!surface_route_id_ || !shared_surface_handle_.parent_gpu_process_id)
1014 return;
1015
1016 RenderWidgetHostImpl::SendFrontSurfaceIsProtected(
1017 surface_is_protected,
1018 protection_state_id_,
1019 surface_route_id_,
1020 shared_surface_handle_.parent_gpu_process_id);
1021 } 1010 }
1022 1011
1023 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished( 1012 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished(
1024 base::WeakPtr<RenderWidgetHostViewAura> render_widget_host_view, 1013 base::WeakPtr<RenderWidgetHostViewAura> render_widget_host_view,
1025 const base::Callback<void(bool)>& callback, 1014 const base::Callback<void(bool)>& callback,
1026 bool result) { 1015 bool result) {
1027 callback.Run(result); 1016 callback.Run(result);
1028 1017
1029 if (!render_widget_host_view.get()) 1018 if (!render_widget_host_view.get())
1030 return; 1019 return;
1031 --render_widget_host_view->pending_thumbnail_tasks_; 1020 --render_widget_host_view->pending_thumbnail_tasks_;
1032 render_widget_host_view->AdjustSurfaceProtection();
1033 } 1021 }
1034 1022
1035 void RenderWidgetHostViewAura::SetBackground(const SkBitmap& background) { 1023 void RenderWidgetHostViewAura::SetBackground(const SkBitmap& background) {
1036 RenderWidgetHostViewBase::SetBackground(background); 1024 RenderWidgetHostViewBase::SetBackground(background);
1037 host_->SetBackground(background); 1025 host_->SetBackground(background);
1038 window_->layer()->SetFillsBoundsOpaquely(background.isOpaque()); 1026 window_->layer()->SetFillsBoundsOpaquely(background.isOpaque());
1039 } 1027 }
1040 1028
1041 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) { 1029 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) {
1042 GetScreenInfoForWindow(results, window_); 1030 GetScreenInfoForWindow(results, window_);
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 1718
1731 void RenderWidgetHostViewAura::OnCompositingDidCommit( 1719 void RenderWidgetHostViewAura::OnCompositingDidCommit(
1732 ui::Compositor* compositor) { 1720 ui::Compositor* compositor) {
1733 if (can_lock_compositor_ == NO_PENDING_COMMIT) { 1721 if (can_lock_compositor_ == NO_PENDING_COMMIT) {
1734 can_lock_compositor_ = YES; 1722 can_lock_compositor_ = YES;
1735 for (ResizeLockList::iterator it = resize_locks_.begin(); 1723 for (ResizeLockList::iterator it = resize_locks_.begin();
1736 it != resize_locks_.end(); ++it) 1724 it != resize_locks_.end(); ++it)
1737 if ((*it)->GrabDeferredLock()) 1725 if ((*it)->GrabDeferredLock())
1738 can_lock_compositor_ = YES_DID_LOCK; 1726 can_lock_compositor_ = YES_DID_LOCK;
1739 } 1727 }
1740 RunCompositingDidCommitCallbacks(compositor); 1728 RunCompositingDidCommitCallbacks();
1741 locks_pending_commit_.clear(); 1729 locks_pending_commit_.clear();
1742 } 1730 }
1743 1731
1744 void RenderWidgetHostViewAura::OnCompositingStarted( 1732 void RenderWidgetHostViewAura::OnCompositingStarted(
1745 ui::Compositor* compositor) { 1733 ui::Compositor* compositor) {
1746 } 1734 }
1747 1735
1748 void RenderWidgetHostViewAura::OnCompositingEnded( 1736 void RenderWidgetHostViewAura::OnCompositingEnded(
1749 ui::Compositor* compositor) { 1737 ui::Compositor* compositor) {
1750 } 1738 }
(...skipping 10 matching lines...) Expand all
1761 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; 1749 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME;
1762 } 1750 }
1763 } 1751 }
1764 1752
1765 //////////////////////////////////////////////////////////////////////////////// 1753 ////////////////////////////////////////////////////////////////////////////////
1766 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: 1754 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation:
1767 1755
1768 void RenderWidgetHostViewAura::OnLostResources() { 1756 void RenderWidgetHostViewAura::OnLostResources() {
1769 image_transport_clients_.clear(); 1757 image_transport_clients_.clear();
1770 current_surface_ = 0; 1758 current_surface_ = 0;
1771 protection_state_id_ = 0;
1772 current_surface_is_protected_ = true;
1773 current_surface_in_use_by_compositor_ = true;
1774 surface_route_id_ = 0;
1775 UpdateExternalTexture(); 1759 UpdateExternalTexture();
1776 locks_pending_commit_.clear(); 1760 locks_pending_commit_.clear();
1777 1761
1778 DCHECK(!shared_surface_handle_.is_null()); 1762 DCHECK(!shared_surface_handle_.is_null());
1779 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1763 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1780 factory->DestroySharedSurfaceHandle(shared_surface_handle_); 1764 factory->DestroySharedSurfaceHandle(shared_surface_handle_);
1781 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); 1765 shared_surface_handle_ = factory->CreateSharedSurfaceHandle();
1782 host_->CompositingSurfaceUpdated(); 1766 host_->CompositingSurfaceUpdated();
1783 host_->ScheduleComposite(); 1767 host_->ScheduleComposite();
1784 } 1768 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 gfx::Rect rect = window_->bounds(); 1890 gfx::Rect rect = window_->bounds();
1907 int border_x = rect.width() * kMouseLockBorderPercentage / 100; 1891 int border_x = rect.width() * kMouseLockBorderPercentage / 100;
1908 int border_y = rect.height() * kMouseLockBorderPercentage / 100; 1892 int border_y = rect.height() * kMouseLockBorderPercentage / 100;
1909 1893
1910 return global_mouse_position_.x() < rect.x() + border_x || 1894 return global_mouse_position_.x() < rect.x() + border_x ||
1911 global_mouse_position_.x() > rect.right() - border_x || 1895 global_mouse_position_.x() > rect.right() - border_x ||
1912 global_mouse_position_.y() < rect.y() + border_y || 1896 global_mouse_position_.y() < rect.y() + border_y ||
1913 global_mouse_position_.y() > rect.bottom() - border_y; 1897 global_mouse_position_.y() > rect.bottom() - border_y;
1914 } 1898 }
1915 1899
1916 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks( 1900 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks() {
1917 ui::Compositor* compositor) { 1901 for (std::vector<base::Closure>::const_iterator
1918 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator
1919 it = on_compositing_did_commit_callbacks_.begin(); 1902 it = on_compositing_did_commit_callbacks_.begin();
1920 it != on_compositing_did_commit_callbacks_.end(); ++it) { 1903 it != on_compositing_did_commit_callbacks_.end(); ++it) {
1921 it->Run(compositor); 1904 it->Run();
1922 } 1905 }
1923 on_compositing_did_commit_callbacks_.clear(); 1906 on_compositing_did_commit_callbacks_.clear();
1924 } 1907 }
1925 1908
1926 // static 1909 // static
1927 void RenderWidgetHostViewAura::InsertSyncPointAndACK( 1910 void RenderWidgetHostViewAura::InsertSyncPointAndACK(
1928 int32 route_id, int gpu_host_id, bool presented, 1911 const BufferPresentedParams& params) {
1929 ui::Compositor* compositor) { 1912 if (params.texture_to_produce)
1913 params.texture_to_produce->Produce();
1914
1915 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
jonathan.backer 2012/11/20 21:21:11 nit: put this in the scope with the call to Insert
piman 2012/11/30 03:54:32 Agreed, and you can combine the bodies of the 2 if
1916
1930 uint32 sync_point = 0; 1917 uint32 sync_point = 0;
1931 // If we have no compositor, so we must still send the ACK. A zero 1918 // If we produced a texture, we have to synchronize with the consumer of
1932 // sync point will not be waited for in the GPU process. 1919 // that texture.
1933 if (compositor) { 1920 if (params.texture_to_produce)
1934 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1921 sync_point = factory->InsertSyncPoint();
piman 2012/11/30 03:54:32 nit: indent
1935 sync_point = factory->InsertSyncPoint();
1936 }
1937 1922
1938 RenderWidgetHostImpl::AcknowledgeBufferPresent( 1923 RenderWidgetHostImpl::AcknowledgeBufferPresent(
1939 route_id, gpu_host_id, presented, sync_point); 1924 params.route_id, params.gpu_host_id, params.surface_handle, sync_point);
1940 } 1925 }
1941 1926
1942 void RenderWidgetHostViewAura::AddingToRootWindow() { 1927 void RenderWidgetHostViewAura::AddingToRootWindow() {
1943 host_->ParentChanged(GetNativeViewId()); 1928 host_->ParentChanged(GetNativeViewId());
1944 UpdateScreenInfo(window_); 1929 UpdateScreenInfo(window_);
1945 } 1930 }
1946 1931
1947 void RenderWidgetHostViewAura::RemovingFromRootWindow() { 1932 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
1948 host_->ParentChanged(0); 1933 host_->ParentChanged(0);
1949 // We are about to disconnect ourselves from the compositor, we need to issue 1934 // We are about to disconnect ourselves from the compositor, we need to issue
1950 // the callbacks now, because we won't get notified when the frame is done. 1935 // the callbacks now, because we won't get notified when the frame is done.
1951 // TODO(piman): this might in theory cause a race where the GPU process starts 1936 // TODO(piman): this might in theory cause a race where the GPU process starts
1952 // drawing to the buffer we haven't yet displayed. This will only show for 1 1937 // drawing to the buffer we haven't yet displayed. This will only show for 1
1953 // frame though, because we will reissue a new frame right away without that 1938 // frame though, because we will reissue a new frame right away without that
1954 // composited data. 1939 // composited data.
1955 ui::Compositor* compositor = GetCompositor(); 1940 ui::Compositor* compositor = GetCompositor();
1956 RunCompositingDidCommitCallbacks(compositor); 1941 RunCompositingDidCommitCallbacks();
1957 locks_pending_commit_.clear(); 1942 locks_pending_commit_.clear();
1958 if (compositor && compositor->HasObserver(this)) 1943 if (compositor && compositor->HasObserver(this))
1959 compositor->RemoveObserver(this); 1944 compositor->RemoveObserver(this);
1960 DetachFromInputMethod(); 1945 DetachFromInputMethod();
1961 } 1946 }
1962 1947
1963 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { 1948 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() {
1964 aura::RootWindow* root_window = window_->GetRootWindow(); 1949 aura::RootWindow* root_window = window_->GetRootWindow();
1965 return root_window ? root_window->compositor() : NULL; 1950 return root_window ? root_window->compositor() : NULL;
1966 } 1951 }
(...skipping 12 matching lines...) Expand all
1979 RenderWidgetHost* widget) { 1964 RenderWidgetHost* widget) {
1980 return new RenderWidgetHostViewAura(widget); 1965 return new RenderWidgetHostViewAura(widget);
1981 } 1966 }
1982 1967
1983 // static 1968 // static
1984 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { 1969 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) {
1985 GetScreenInfoForWindow(results, NULL); 1970 GetScreenInfoForWindow(results, NULL);
1986 } 1971 }
1987 1972
1988 } // namespace content 1973 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698