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

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: send SurfaceRel from Destroy(), hold GLContext ref for cleanup so surface is compatible 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "ui/gfx/canvas.h" 50 #include "ui/gfx/canvas.h"
51 #include "ui/gfx/display.h" 51 #include "ui/gfx/display.h"
52 #include "ui/gfx/rect_conversions.h" 52 #include "ui/gfx/rect_conversions.h"
53 #include "ui/gfx/screen.h" 53 #include "ui/gfx/screen.h"
54 #include "ui/gfx/skia_util.h" 54 #include "ui/gfx/skia_util.h"
55 55
56 #if defined(OS_WIN) 56 #if defined(OS_WIN)
57 #include "ui/base/win/hidden_window.h" 57 #include "ui/base/win/hidden_window.h"
58 #endif 58 #endif
59 59
60 using gfx::RectToSkIRect;
61 using gfx::SkIRectToRect;
62
60 using WebKit::WebScreenInfo; 63 using WebKit::WebScreenInfo;
61 using WebKit::WebTouchEvent; 64 using WebKit::WebTouchEvent;
62 65
63 namespace content { 66 namespace content {
64 namespace { 67 namespace {
65 68
66 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting 69 // 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, 70 // 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 71 // 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 72 // doesn't work well. It reduces the frequency of useful mouse move messages
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 in_shutdown_(false), 275 in_shutdown_(false),
273 is_fullscreen_(false), 276 is_fullscreen_(false),
274 popup_parent_host_view_(NULL), 277 popup_parent_host_view_(NULL),
275 popup_child_host_view_(NULL), 278 popup_child_host_view_(NULL),
276 is_loading_(false), 279 is_loading_(false),
277 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 280 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
278 can_compose_inline_(true), 281 can_compose_inline_(true),
279 has_composition_text_(false), 282 has_composition_text_(false),
280 device_scale_factor_(1.0f), 283 device_scale_factor_(1.0f),
281 current_surface_(0), 284 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), 285 paint_canvas_(NULL),
287 synthetic_move_sent_(false), 286 synthetic_move_sent_(false),
288 accelerated_compositing_state_changed_(false), 287 accelerated_compositing_state_changed_(false),
289 can_lock_compositor_(YES) { 288 can_lock_compositor_(YES) {
290 host_->SetView(this); 289 host_->SetView(this);
291 window_observer_.reset(new WindowObserver(this)); 290 window_observer_.reset(new WindowObserver(this));
292 window_->AddObserver(window_observer_.get()); 291 window_->AddObserver(window_observer_.get());
293 aura::client::SetTooltipText(window_, &tooltip_); 292 aura::client::SetTooltipText(window_, &tooltip_);
294 aura::client::SetActivationDelegate(window_, this); 293 aura::client::SetActivationDelegate(window_, this);
295 gfx::Screen::GetScreenFor(window_)->AddObserver(this); 294 gfx::Screen::GetScreenFor(window_)->AddObserver(this);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 void RenderWidgetHostViewAura::WasShown() { 374 void RenderWidgetHostViewAura::WasShown() {
376 if (!host_->is_hidden()) 375 if (!host_->is_hidden())
377 return; 376 return;
378 host_->WasShown(); 377 host_->WasShown();
379 378
380 if (!current_surface_ && host_->is_accelerated_compositing_active() && 379 if (!current_surface_ && host_->is_accelerated_compositing_active() &&
381 !released_front_lock_.get()) { 380 !released_front_lock_.get()) {
382 released_front_lock_ = GetCompositor()->GetCompositorLock(); 381 released_front_lock_ = GetCompositor()->GetCompositorLock();
383 } 382 }
384 383
385 AdjustSurfaceProtection();
386
387 #if defined(OS_WIN) 384 #if defined(OS_WIN)
388 LPARAM lparam = reinterpret_cast<LPARAM>(this); 385 LPARAM lparam = reinterpret_cast<LPARAM>(this);
389 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); 386 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam);
390 #endif 387 #endif
391 } 388 }
392 389
393 void RenderWidgetHostViewAura::WasHidden() { 390 void RenderWidgetHostViewAura::WasHidden() {
394 if (host_->is_hidden()) 391 if (host_->is_hidden())
395 return; 392 return;
396 host_->WasHidden(); 393 host_->WasHidden();
397 394
398 released_front_lock_ = NULL; 395 released_front_lock_ = NULL;
399 396
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) 397 #if defined(OS_WIN)
409 aura::RootWindow* root_window = window_->GetRootWindow(); 398 aura::RootWindow* root_window = window_->GetRootWindow();
410 if (root_window) { 399 if (root_window) {
411 HWND parent = root_window->GetAcceleratedWidget(); 400 HWND parent = root_window->GetAcceleratedWidget();
412 LPARAM lparam = reinterpret_cast<LPARAM>(this); 401 LPARAM lparam = reinterpret_cast<LPARAM>(this);
413 402
414 EnumChildWindows(parent, HideWindowsCallback, lparam); 403 EnumChildWindows(parent, HideWindowsCallback, lparam);
415 } 404 }
416 #endif 405 #endif
417 } 406 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 693
705 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 694 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
706 GLHelper* gl_helper = factory->GetGLHelper(); 695 GLHelper* gl_helper = factory->GetGLHelper();
707 if (!gl_helper) 696 if (!gl_helper)
708 return; 697 return;
709 698
710 unsigned char* addr = static_cast<unsigned char*>( 699 unsigned char* addr = static_cast<unsigned char*>(
711 output->GetBitmap().getPixels()); 700 output->GetBitmap().getPixels());
712 scoped_callback_runner.Release(); 701 scoped_callback_runner.Release();
713 // Wrap the callback with an internal handler so that we can inject our 702 // Wrap the callback with an internal handler so that we can inject our
714 // own completion handlers (where we can call AdjustSurfaceProtection). 703 // own completion handlers (where we can try to free the frontbuffer).
715 base::Callback<void(bool)> wrapper_callback = base::Bind( 704 base::Callback<void(bool)> wrapper_callback = base::Bind(
716 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished, 705 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished,
717 AsWeakPtr(), 706 AsWeakPtr(),
718 callback); 707 callback);
719 ++pending_thumbnail_tasks_; 708 ++pending_thumbnail_tasks_;
720 709
721 // Convert |src_subrect| from the views coordinate (upper-left origin) into 710 // Convert |src_subrect| from the views coordinate (upper-left origin) into
722 // the OpenGL coordinate (lower-left origin). 711 // the OpenGL coordinate (lower-left origin).
723 gfx::Rect src_subrect_in_gl = src_subrect; 712 gfx::Rect src_subrect_in_gl = src_subrect;
724 src_subrect_in_gl.set_y(GetViewBounds().height() - src_subrect.bottom()); 713 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 726 // switching to software mode or receive a buffers swapped notification
738 // if switching to accelerated mode. 727 // if switching to accelerated mode.
739 // Sometimes (e.g. on a page load) the renderer will spuriously disable then 728 // Sometimes (e.g. on a page load) the renderer will spuriously disable then
740 // re-enable accelerated compositing, causing us to flash. 729 // re-enable accelerated compositing, causing us to flash.
741 // TODO(piman): factor the enable/disable accelerated compositing message into 730 // TODO(piman): factor the enable/disable accelerated compositing message into
742 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have 731 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have
743 // fewer inconsistent temporary states. 732 // fewer inconsistent temporary states.
744 accelerated_compositing_state_changed_ = true; 733 accelerated_compositing_state_changed_ = true;
745 } 734 }
746 735
747 bool RenderWidgetHostViewAura::ShouldFastACK(uint64 surface_id) { 736 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 || 737 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME ||
752 can_lock_compositor_ == NO_PENDING_COMMIT || 738 can_lock_compositor_ == NO_PENDING_COMMIT ||
753 resize_locks_.empty()) 739 resize_locks_.empty())
754 return false; 740 return false;
755 741
756 gfx::Size container_size = ConvertSizeToDIP(this, container->size()); 742 gfx::Size container_size = ConvertSizeToDIP(this, size);
757 ResizeLockList::iterator it = resize_locks_.begin(); 743 ResizeLockList::iterator it = resize_locks_.begin();
758 while (it != resize_locks_.end()) { 744 while (it != resize_locks_.end()) {
759 if ((*it)->expected_size() == container_size) 745 if ((*it)->expected_size() == container_size)
760 break; 746 break;
761 ++it; 747 ++it;
762 } 748 }
763 749
764 // We could be getting an unexpected frame due to an animation 750 // 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). 751 // (i.e. we start resizing but we get an old size frame first).
766 return it == resize_locks_.end() || ++it != resize_locks_.end(); 752 return it == resize_locks_.end() || ++it != resize_locks_.end();
767 } 753 }
768 754
769 void RenderWidgetHostViewAura::UpdateExternalTexture() { 755 void RenderWidgetHostViewAura::UpdateExternalTexture() {
770 // Delay processing accelerated compositing state change till here where we 756 // Delay processing accelerated compositing state change till here where we
771 // act upon the state change. (Clear the external texture if switching to 757 // 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). 758 // software mode or set the external texture if going to accelerated mode).
773 if (accelerated_compositing_state_changed_) 759 if (accelerated_compositing_state_changed_)
774 accelerated_compositing_state_changed_ = false; 760 accelerated_compositing_state_changed_ = false;
775 761
776 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) { 762 if (current_surface_ != 0 && host_->is_accelerated_compositing_active()) {
777 ui::Texture* container = image_transport_clients_[current_surface_]; 763 ui::Texture* container = image_transport_clients_[current_surface_];
778 window_->SetExternalTexture(container); 764 window_->SetExternalTexture(container);
779 current_surface_in_use_by_compositor_ = true;
780 765
781 if (!container) { 766 if (!container) {
782 resize_locks_.clear(); 767 resize_locks_.clear();
783 } else { 768 } else {
784 ResizeLockList::iterator it = resize_locks_.begin(); 769 ResizeLockList::iterator it = resize_locks_.begin();
785 while (it != resize_locks_.end()) { 770 while (it != resize_locks_.end()) {
786 gfx::Size container_size = ConvertSizeToDIP(this, 771 gfx::Size container_size = ConvertSizeToDIP(this,
787 container->size()); 772 container->size());
788 if ((*it)->expected_size() == container_size) 773 if ((*it)->expected_size() == container_size)
789 break; 774 break;
(...skipping 15 matching lines...) Expand all
805 it2->get()->UnlockCompositor(); 790 it2->get()->UnlockCompositor();
806 } 791 }
807 if (!compositor->HasObserver(this)) 792 if (!compositor->HasObserver(this))
808 compositor->AddObserver(this); 793 compositor->AddObserver(this);
809 } 794 }
810 resize_locks_.erase(resize_locks_.begin(), it); 795 resize_locks_.erase(resize_locks_.begin(), it);
811 } 796 }
812 } 797 }
813 } else { 798 } else {
814 window_->SetExternalTexture(NULL); 799 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(); 800 resize_locks_.clear();
831 } 801 }
832 } 802 }
833 803
804 bool RenderWidgetHostViewAura::SwapBuffersPrepare(
805 const gfx::Rect& surface_rect,
806 const gfx::Rect& damage_rect,
807 BufferPresentedParams& params) {
808 DCHECK(params.surface_handle);
809 DCHECK(!params.texture_to_produce);
810
811 if (previous_surface_size_ != surface_rect.size()) {
812 // The surface could have shrunk since we skipped an update, in which
813 // case we can expect a full update.
814 DLOG_IF(ERROR, damage_rect != surface_rect) << "Expected full damage rect";
815 skipped_damage_.setEmpty();
816 previous_surface_size_ = surface_rect.size();
817 }
818
819 if (ShouldSkipFrame(surface_rect.size()) || !GetCompositor()) {
820 skipped_damage_.op(RectToSkIRect(damage_rect), SkRegion::kUnion_Op);
821 InsertSyncPointAndACK(params);
822 return false;
823 }
824
825 const uint64 previous_surface = current_surface_;
826 DCHECK(!previous_surface || image_transport_clients_.find(previous_surface) !=
827 image_transport_clients_.end());
828 if (previous_surface)
829 params.texture_to_produce = image_transport_clients_[previous_surface];
830
831 current_surface_ = params.surface_handle;
832 params.surface_handle = previous_surface;
833
834 DCHECK(image_transport_clients_.find(current_surface_) !=
835 image_transport_clients_.end());
836
837 image_transport_clients_[current_surface_]->Consume(surface_rect.size());
838 released_front_lock_ = NULL;
839 UpdateExternalTexture();
840
841 return true;
842 }
843
844 void RenderWidgetHostViewAura::SwapBuffersCompleted(
845 const BufferPresentedParams& params) {
846 ui::Compositor* compositor = GetCompositor();
847 if (!compositor) {
848 InsertSyncPointAndACK(params);
849 } else {
850 // Add sending an ACK to the list of things to do OnCompositingDidCommit
851 can_lock_compositor_ = NO_PENDING_COMMIT;
852 on_compositing_did_commit_callbacks_.push_back(
853 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, params));
854 if (!compositor->HasObserver(this))
855 compositor->AddObserver(this);
856 }
857 }
858
834 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( 859 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
835 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, 860 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
836 int gpu_host_id) { 861 int gpu_host_id) {
837 surface_route_id_ = params_in_pixel.route_id; 862 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 863 BufferPresentedParams ack_params(
839 // do not update current_surface_ since it may have been discarded. 864 params_in_pixel.route_id, gpu_host_id, params_in_pixel.surface_handle);
840 if (params_in_pixel.protection_state_id && 865 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; 866 return;
867
868 previous_damage_.setRect(RectToSkIRect(surface_rect));
869 skipped_damage_.setEmpty();
870
871 ui::Compositor* compositor = GetCompositor();
872 if (compositor) {
873 gfx::Size surface_size = ConvertSizeToDIP(this, params_in_pixel.size);
874 window_->SchedulePaintInRect(gfx::Rect(surface_size));
846 } 875 }
847 876
848 if (ShouldFastACK(params_in_pixel.surface_handle)) { 877 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 } 878 }
890 879
891 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( 880 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
892 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, 881 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
893 int gpu_host_id) { 882 int gpu_host_id) {
894 surface_route_id_ = params_in_pixel.route_id; 883 const gfx::Rect surface_rect =
895 // If visible state changed, then this PSB is stale. We must still ACK but 884 gfx::Rect(gfx::Point(), params_in_pixel.surface_size);
896 // do not update current_surface_. 885 gfx::Rect damage_rect(params_in_pixel.x,
897 if (params_in_pixel.protection_state_id && 886 params_in_pixel.y,
898 params_in_pixel.protection_state_id != protection_state_id_) { 887 params_in_pixel.width,
899 DCHECK(!current_surface_); 888 params_in_pixel.height);
900 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); 889 BufferPresentedParams ack_params(
890 params_in_pixel.route_id, gpu_host_id, params_in_pixel.surface_handle);
891 if (!SwapBuffersPrepare(surface_rect, damage_rect, ack_params))
901 return; 892 return;
893
894 SkRegion damage(RectToSkIRect(damage_rect));
895 if (!skipped_damage_.isEmpty()) {
896 damage.op(skipped_damage_, SkRegion::kUnion_Op);
897 damage_rect = gfx::SkIRectToRect(damage.getBounds());
898 skipped_damage_.setEmpty();
902 } 899 }
903 900
904 if (ShouldFastACK(params_in_pixel.surface_handle)) { 901 DCHECK(surface_rect.Contains(damage_rect));
905 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, false, NULL); 902 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 903
914 ui::Compositor* compositor = GetCompositor(); 904 ui::Compositor* compositor = GetCompositor();
915 if (!compositor) { 905 if (compositor) {
916 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, true, NULL); 906 const gfx::Size surface_size_in_pixel = params_in_pixel.surface_size;
917 } else { 907 DLOG_IF(ERROR, ack_params.texture_to_produce &&
918 DCHECK(image_transport_clients_.find(params_in_pixel.surface_handle) != 908 ack_params.texture_to_produce->size() != current_texture->size() &&
919 image_transport_clients_.end()); 909 damage_rect != surface_rect) <<
920 gfx::Size surface_size_in_pixel = 910 "Expected full damage rect after size change";
921 image_transport_clients_[params_in_pixel.surface_handle]->size(); 911 if (ack_params.texture_to_produce && !previous_damage_.isEmpty() &&
912 ack_params.texture_to_produce->size() == current_texture->size()) {
913 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
914 GLHelper* gl_helper = factory->GetGLHelper();
915 gl_helper->CopySubBufferDamage(
916 current_texture->PrepareTexture(),
917 ack_params.texture_to_produce->PrepareTexture(),
918 damage,
919 previous_damage_);
920 }
921 previous_damage_ = damage;
922 922
923 // Co-ordinates come in OpenGL co-ordinate space. 923 // Co-ordinates come in OpenGL co-ordinate space.
924 // We need to convert to layer space. 924 // We need to convert to layer space.
925 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect( 925 gfx::Rect rect_to_paint = ConvertRectToDIP(this, gfx::Rect(
926 params_in_pixel.x, 926 params_in_pixel.x,
927 surface_size_in_pixel.height() - params_in_pixel.y - 927 surface_size_in_pixel.height() - params_in_pixel.y -
928 params_in_pixel.height, 928 params_in_pixel.height,
929 params_in_pixel.width, 929 params_in_pixel.width,
930 params_in_pixel.height)); 930 params_in_pixel.height));
931 931
932 // Damage may not have been DIP aligned, so inflate damage to compensate 932 // Damage may not have been DIP aligned, so inflate damage to compensate
933 // for any round-off error. 933 // for any round-off error.
934 rect_to_paint.Inset(-1, -1); 934 rect_to_paint.Inset(-1, -1);
935 rect_to_paint.Intersect(window_->bounds()); 935 rect_to_paint.Intersect(window_->bounds());
936 936
937 window_->SchedulePaintInRect(rect_to_paint); 937 window_->SchedulePaintInRect(rect_to_paint);
938 }
938 939
939 // Add sending an ACK to the list of things to do OnCompositingDidCommit 940 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 } 941 }
950 942
951 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { 943 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() {
952 } 944 }
953 945
954 bool RenderWidgetHostViewAura::HasAcceleratedSurface( 946 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
955 const gfx::Size& desired_size) { 947 const gfx::Size& desired_size) {
956 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't 948 // 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 949 // 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. 950 // method. TODO(jbates) implement this if other Aura code needs it.
959 return false; 951 return false;
960 } 952 }
961 953
962 // TODO(backer): Drop the |shm_handle| once I remove some unused service side 954 // TODO(backer): Drop the |shm_handle| once I remove some unused service side
963 // code. 955 // code.
964 void RenderWidgetHostViewAura::AcceleratedSurfaceNew( 956 void RenderWidgetHostViewAura::AcceleratedSurfaceNew(
965 int32 width_in_pixel, 957 int32 width_in_pixel,
966 int32 height_in_pixel, 958 int32 height_in_pixel,
967 uint64 surface_handle) { 959 uint64 surface_handle,
960 const std::string& mailbox_name) {
968 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 961 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
969 scoped_refptr<ui::Texture> surface(factory->CreateTransportClient( 962 scoped_refptr<ui::Texture> surface(factory->CreateTransportClient(
970 gfx::Size(width_in_pixel, height_in_pixel), device_scale_factor_, 963 gfx::Size(width_in_pixel, height_in_pixel), device_scale_factor_,
971 surface_handle)); 964 mailbox_name));
972 if (!surface) { 965 if (!surface) {
973 LOG(ERROR) << "Failed to create ImageTransport texture"; 966 LOG(ERROR) << "Failed to create ImageTransport texture";
974 return; 967 return;
975 } 968 }
976
977 image_transport_clients_[surface_handle] = surface; 969 image_transport_clients_[surface_handle] = surface;
978 } 970 }
979 971
980 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease( 972 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease(
981 uint64 surface_handle) { 973 uint64 surface_handle) {
982 DCHECK(image_transport_clients_.find(surface_handle) != 974 // This really tells us to release the frontbuffer.
983 image_transport_clients_.end()); 975 if (current_surface_ && ShouldReleaseFrontSurface()) {
984 if (current_surface_ == surface_handle) { 976 ui::Compositor* compositor = GetCompositor();
977 if (compositor) {
978 // We need to wait for a commit to clear to guarantee that all we
979 // will not issue any more GL referencing the previous surface.
980 can_lock_compositor_ = NO_PENDING_COMMIT;
981 scoped_refptr<ui::Texture> surface_ref =
982 image_transport_clients_[surface_handle];
983 on_compositing_did_commit_callbacks_.push_back(
984 base::Bind(&RenderWidgetHostViewAura::
985 SetSurfaceNotInUseByCompositor,
986 AsWeakPtr(),
987 surface_ref));
988 if (!compositor->HasObserver(this))
989 compositor->AddObserver(this);
990 }
991 image_transport_clients_.erase(current_surface_);
985 current_surface_ = 0; 992 current_surface_ = 0;
986 UpdateExternalTexture(); 993 UpdateExternalTexture();
987 } 994 }
988 image_transport_clients_.erase(surface_handle);
989 } 995 }
990 996
991 void RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor(ui::Compositor*) { 997 void RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor(
992 if (current_surface_ || !host_->is_hidden()) 998 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 } 999 }
1022 1000
1023 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished( 1001 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished(
1024 base::WeakPtr<RenderWidgetHostViewAura> render_widget_host_view, 1002 base::WeakPtr<RenderWidgetHostViewAura> render_widget_host_view,
1025 const base::Callback<void(bool)>& callback, 1003 const base::Callback<void(bool)>& callback,
1026 bool result) { 1004 bool result) {
1027 callback.Run(result); 1005 callback.Run(result);
1028 1006
1029 if (!render_widget_host_view.get()) 1007 if (!render_widget_host_view.get())
1030 return; 1008 return;
1031 --render_widget_host_view->pending_thumbnail_tasks_; 1009 --render_widget_host_view->pending_thumbnail_tasks_;
1032 render_widget_host_view->AdjustSurfaceProtection();
1033 } 1010 }
1034 1011
1035 void RenderWidgetHostViewAura::SetBackground(const SkBitmap& background) { 1012 void RenderWidgetHostViewAura::SetBackground(const SkBitmap& background) {
1036 RenderWidgetHostViewBase::SetBackground(background); 1013 RenderWidgetHostViewBase::SetBackground(background);
1037 host_->SetBackground(background); 1014 host_->SetBackground(background);
1038 window_->layer()->SetFillsBoundsOpaquely(background.isOpaque()); 1015 window_->layer()->SetFillsBoundsOpaquely(background.isOpaque());
1039 } 1016 }
1040 1017
1041 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) { 1018 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) {
1042 GetScreenInfoForWindow(results, window_); 1019 GetScreenInfoForWindow(results, window_);
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 1707
1731 void RenderWidgetHostViewAura::OnCompositingDidCommit( 1708 void RenderWidgetHostViewAura::OnCompositingDidCommit(
1732 ui::Compositor* compositor) { 1709 ui::Compositor* compositor) {
1733 if (can_lock_compositor_ == NO_PENDING_COMMIT) { 1710 if (can_lock_compositor_ == NO_PENDING_COMMIT) {
1734 can_lock_compositor_ = YES; 1711 can_lock_compositor_ = YES;
1735 for (ResizeLockList::iterator it = resize_locks_.begin(); 1712 for (ResizeLockList::iterator it = resize_locks_.begin();
1736 it != resize_locks_.end(); ++it) 1713 it != resize_locks_.end(); ++it)
1737 if ((*it)->GrabDeferredLock()) 1714 if ((*it)->GrabDeferredLock())
1738 can_lock_compositor_ = YES_DID_LOCK; 1715 can_lock_compositor_ = YES_DID_LOCK;
1739 } 1716 }
1740 RunCompositingDidCommitCallbacks(compositor); 1717 RunCompositingDidCommitCallbacks();
1741 locks_pending_commit_.clear(); 1718 locks_pending_commit_.clear();
1742 } 1719 }
1743 1720
1744 void RenderWidgetHostViewAura::OnCompositingStarted( 1721 void RenderWidgetHostViewAura::OnCompositingStarted(
1745 ui::Compositor* compositor) { 1722 ui::Compositor* compositor) {
1746 } 1723 }
1747 1724
1748 void RenderWidgetHostViewAura::OnCompositingEnded( 1725 void RenderWidgetHostViewAura::OnCompositingEnded(
1749 ui::Compositor* compositor) { 1726 ui::Compositor* compositor) {
1750 } 1727 }
1751 1728
1752 void RenderWidgetHostViewAura::OnCompositingAborted( 1729 void RenderWidgetHostViewAura::OnCompositingAborted(
1753 ui::Compositor* compositor) { 1730 ui::Compositor* compositor) {
1754 } 1731 }
1755 1732
1756 void RenderWidgetHostViewAura::OnCompositingLockStateChanged( 1733 void RenderWidgetHostViewAura::OnCompositingLockStateChanged(
1757 ui::Compositor* compositor) { 1734 ui::Compositor* compositor) {
1758 // A compositor lock that is part of a resize lock timed out. We 1735 // A compositor lock that is part of a resize lock timed out. We
1759 // should display a renderer frame. 1736 // should display a renderer frame.
1760 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { 1737 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) {
1761 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; 1738 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME;
1762 } 1739 }
1763 } 1740 }
1764 1741
1765 //////////////////////////////////////////////////////////////////////////////// 1742 ////////////////////////////////////////////////////////////////////////////////
1766 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: 1743 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation:
1767 1744
1768 void RenderWidgetHostViewAura::OnLostResources() { 1745 void RenderWidgetHostViewAura::OnLostResources() {
1769 image_transport_clients_.clear(); 1746 image_transport_clients_.clear();
no sievers 2012/11/20 00:03:03 This is a problem if we lose the UI/helper context
1770 current_surface_ = 0; 1747 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(); 1748 UpdateExternalTexture();
1776 locks_pending_commit_.clear(); 1749 locks_pending_commit_.clear();
1777 1750
1778 DCHECK(!shared_surface_handle_.is_null()); 1751 DCHECK(!shared_surface_handle_.is_null());
1779 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1752 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1780 factory->DestroySharedSurfaceHandle(shared_surface_handle_); 1753 factory->DestroySharedSurfaceHandle(shared_surface_handle_);
1781 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); 1754 shared_surface_handle_ = factory->CreateSharedSurfaceHandle();
1782 host_->CompositingSurfaceUpdated(); 1755 host_->CompositingSurfaceUpdated();
1783 host_->ScheduleComposite(); 1756 host_->ScheduleComposite();
1784 } 1757 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 gfx::Rect rect = window_->bounds(); 1879 gfx::Rect rect = window_->bounds();
1907 int border_x = rect.width() * kMouseLockBorderPercentage / 100; 1880 int border_x = rect.width() * kMouseLockBorderPercentage / 100;
1908 int border_y = rect.height() * kMouseLockBorderPercentage / 100; 1881 int border_y = rect.height() * kMouseLockBorderPercentage / 100;
1909 1882
1910 return global_mouse_position_.x() < rect.x() + border_x || 1883 return global_mouse_position_.x() < rect.x() + border_x ||
1911 global_mouse_position_.x() > rect.right() - border_x || 1884 global_mouse_position_.x() > rect.right() - border_x ||
1912 global_mouse_position_.y() < rect.y() + border_y || 1885 global_mouse_position_.y() < rect.y() + border_y ||
1913 global_mouse_position_.y() > rect.bottom() - border_y; 1886 global_mouse_position_.y() > rect.bottom() - border_y;
1914 } 1887 }
1915 1888
1916 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks( 1889 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks() {
1917 ui::Compositor* compositor) { 1890 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(); 1891 it = on_compositing_did_commit_callbacks_.begin();
1920 it != on_compositing_did_commit_callbacks_.end(); ++it) { 1892 it != on_compositing_did_commit_callbacks_.end(); ++it) {
1921 it->Run(compositor); 1893 it->Run();
1922 } 1894 }
1923 on_compositing_did_commit_callbacks_.clear(); 1895 on_compositing_did_commit_callbacks_.clear();
1924 } 1896 }
1925 1897
1926 // static 1898 // static
1927 void RenderWidgetHostViewAura::InsertSyncPointAndACK( 1899 void RenderWidgetHostViewAura::InsertSyncPointAndACK(
1928 int32 route_id, int gpu_host_id, bool presented, 1900 const BufferPresentedParams& params) {
1929 ui::Compositor* compositor) { 1901 if (params.texture_to_produce)
1902 params.texture_to_produce->Produce();
1903
1904 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1905
1930 uint32 sync_point = 0; 1906 uint32 sync_point = 0;
1931 // If we have no compositor, so we must still send the ACK. A zero 1907 // 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. 1908 // that texture.
1933 if (compositor) { 1909 if (params.texture_to_produce)
1934 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1910 sync_point = factory->InsertSyncPoint();
1935 sync_point = factory->InsertSyncPoint();
1936 }
1937 1911
1938 RenderWidgetHostImpl::AcknowledgeBufferPresent( 1912 RenderWidgetHostImpl::AcknowledgeBufferPresent(
1939 route_id, gpu_host_id, presented, sync_point); 1913 params.route_id, params.gpu_host_id, params.surface_handle, sync_point);
1940 } 1914 }
1941 1915
1942 void RenderWidgetHostViewAura::AddingToRootWindow() { 1916 void RenderWidgetHostViewAura::AddingToRootWindow() {
1943 host_->ParentChanged(GetNativeViewId()); 1917 host_->ParentChanged(GetNativeViewId());
1944 UpdateScreenInfo(window_); 1918 UpdateScreenInfo(window_);
1945 } 1919 }
1946 1920
1947 void RenderWidgetHostViewAura::RemovingFromRootWindow() { 1921 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
1948 host_->ParentChanged(0); 1922 host_->ParentChanged(0);
1949 // We are about to disconnect ourselves from the compositor, we need to issue 1923 // 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. 1924 // 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 1925 // 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 1926 // 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 1927 // frame though, because we will reissue a new frame right away without that
1954 // composited data. 1928 // composited data.
1955 ui::Compositor* compositor = GetCompositor(); 1929 ui::Compositor* compositor = GetCompositor();
1956 RunCompositingDidCommitCallbacks(compositor); 1930 RunCompositingDidCommitCallbacks();
1957 locks_pending_commit_.clear(); 1931 locks_pending_commit_.clear();
1958 if (compositor && compositor->HasObserver(this)) 1932 if (compositor && compositor->HasObserver(this))
1959 compositor->RemoveObserver(this); 1933 compositor->RemoveObserver(this);
1960 DetachFromInputMethod(); 1934 DetachFromInputMethod();
1961 } 1935 }
1962 1936
1963 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { 1937 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() {
1964 aura::RootWindow* root_window = window_->GetRootWindow(); 1938 aura::RootWindow* root_window = window_->GetRootWindow();
1965 return root_window ? root_window->compositor() : NULL; 1939 return root_window ? root_window->compositor() : NULL;
1966 } 1940 }
(...skipping 12 matching lines...) Expand all
1979 RenderWidgetHost* widget) { 1953 RenderWidgetHost* widget) {
1980 return new RenderWidgetHostViewAura(widget); 1954 return new RenderWidgetHostViewAura(widget);
1981 } 1955 }
1982 1956
1983 // static 1957 // static
1984 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { 1958 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) {
1985 GetScreenInfoForWindow(results, NULL); 1959 GetScreenInfoForWindow(results, NULL);
1986 } 1960 }
1987 1961
1988 } // namespace content 1962 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698