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

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

Issue 14348029: Android: Throttle render compositor if browser (compositor) is behind. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } // anonymous namespace 70 } // anonymous namespace
71 71
72 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( 72 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
73 RenderWidgetHostImpl* widget_host, 73 RenderWidgetHostImpl* widget_host,
74 ContentViewCoreImpl* content_view_core) 74 ContentViewCoreImpl* content_view_core)
75 : host_(widget_host), 75 : host_(widget_host),
76 is_layer_attached_(true), 76 is_layer_attached_(true),
77 content_view_core_(NULL), 77 content_view_core_(NULL),
78 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 78 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
79 cached_background_color_(SK_ColorWHITE), 79 cached_background_color_(SK_ColorWHITE),
80 texture_id_in_layer_(0) { 80 texture_id_in_layer_(0),
81 consumed_current_texture_(true) {
81 if (CompositorImpl::UsesDirectGL()) { 82 if (CompositorImpl::UsesDirectGL()) {
82 surface_texture_transport_.reset(new SurfaceTextureTransportClient()); 83 surface_texture_transport_.reset(new SurfaceTextureTransportClient());
83 layer_ = surface_texture_transport_->Initialize(); 84 layer_ = surface_texture_transport_->Initialize();
85 layer_->SetIsDrawable(true);
84 } else { 86 } else {
85 texture_layer_ = cc::TextureLayer::Create(NULL); 87 texture_layer_ = cc::TextureLayer::Create(this);
86 layer_ = texture_layer_; 88 layer_ = texture_layer_;
87 } 89 }
88 90
89 layer_->SetContentsOpaque(true); 91 layer_->SetContentsOpaque(true);
90 layer_->SetIsDrawable(true);
91 92
92 host_->SetView(this); 93 host_->SetView(this);
93 SetContentViewCore(content_view_core); 94 SetContentViewCore(content_view_core);
94 } 95 }
95 96
96 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 97 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
97 SetContentViewCore(NULL); 98 SetContentViewCore(NULL);
99 DCHECK(ack_callbacks_.empty());
98 if (texture_id_in_layer_ || !last_mailbox_.IsZero()) { 100 if (texture_id_in_layer_ || !last_mailbox_.IsZero()) {
99 ImageTransportFactoryAndroid* factory = 101 ImageTransportFactoryAndroid* factory =
100 ImageTransportFactoryAndroid::GetInstance(); 102 ImageTransportFactoryAndroid::GetInstance();
101 // TODO: crbug.com/230137 - make workaround obsolete with refcounting. 103 // TODO: crbug.com/230137 - make workaround obsolete with refcounting.
102 // Don't let the last frame we sent leak in the mailbox. 104 // Don't let the last frame we sent leak in the mailbox.
103 if (!last_mailbox_.IsZero()) { 105 if (!last_mailbox_.IsZero()) {
104 if (!texture_id_in_layer_) 106 if (!texture_id_in_layer_)
105 texture_id_in_layer_ = factory->CreateTexture(); 107 texture_id_in_layer_ = factory->CreateTexture();
106 factory->AcquireTexture(texture_id_in_layer_, last_mailbox_.name); 108 factory->AcquireTexture(texture_id_in_layer_, last_mailbox_.name);
107 factory->GetContext3D()->getError(); // Clear error if mailbox was empty. 109 factory->GetContext3D()->getError(); // Clear error if mailbox was empty.
108 } 110 }
109 factory->DeleteTexture(texture_id_in_layer_); 111 factory->DeleteTexture(texture_id_in_layer_);
110 } 112 }
113
114 if (texture_layer_)
115 texture_layer_->ClearClient();
111 } 116 }
112 117
113 118
114 bool RenderWidgetHostViewAndroid::OnMessageReceived( 119 bool RenderWidgetHostViewAndroid::OnMessageReceived(
115 const IPC::Message& message) { 120 const IPC::Message& message) {
116 bool handled = true; 121 bool handled = true;
117 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAndroid, message) 122 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAndroid, message)
118 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeBatchStateChanged_ACK, 123 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeBatchStateChanged_ACK,
119 OnProcessImeBatchStateAck) 124 OnProcessImeBatchStateAck)
120 IPC_MESSAGE_HANDLER(ViewHostMsg_StartContentIntent, OnStartContentIntent) 125 IPC_MESSAGE_HANDLER(ViewHostMsg_StartContentIntent, OnStartContentIntent)
(...skipping 24 matching lines...) Expand all
145 } 150 }
146 151
147 void RenderWidgetHostViewAndroid::WasShown() { 152 void RenderWidgetHostViewAndroid::WasShown() {
148 if (!host_->is_hidden()) 153 if (!host_->is_hidden())
149 return; 154 return;
150 155
151 host_->WasShown(); 156 host_->WasShown();
152 } 157 }
153 158
154 void RenderWidgetHostViewAndroid::WasHidden() { 159 void RenderWidgetHostViewAndroid::WasHidden() {
160 RunAckCallbacks();
161
155 if (host_->is_hidden()) 162 if (host_->is_hidden())
156 return; 163 return;
157 164
158 // Inform the renderer that we are being hidden so it can reduce its resource 165 // Inform the renderer that we are being hidden so it can reduce its resource
159 // utilization. 166 // utilization.
160 host_->WasHidden(); 167 host_->WasHidden();
161 } 168 }
162 169
163 void RenderWidgetHostViewAndroid::WasResized() { 170 void RenderWidgetHostViewAndroid::WasResized() {
164 if (surface_texture_transport_.get() && content_view_core_) 171 if (surface_texture_transport_.get() && content_view_core_)
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 // need to delay the ACK until after commit and use more than a single 595 // need to delay the ACK until after commit and use more than a single
589 // texture. 596 // texture.
590 DCHECK(!CompositorImpl::IsThreadingEnabled()); 597 DCHECK(!CompositorImpl::IsThreadingEnabled());
591 598
592 if (texture_id_in_layer_) { 599 if (texture_id_in_layer_) {
593 DCHECK(!current_mailbox_.IsZero()); 600 DCHECK(!current_mailbox_.IsZero());
594 ImageTransportFactoryAndroid::GetInstance()->ReleaseTexture( 601 ImageTransportFactoryAndroid::GetInstance()->ReleaseTexture(
595 texture_id_in_layer_, current_mailbox_.name); 602 texture_id_in_layer_, current_mailbox_.name);
596 } else { 603 } else {
597 texture_id_in_layer_ = factory->CreateTexture(); 604 texture_id_in_layer_ = factory->CreateTexture();
598 texture_layer_->SetTextureId(texture_id_in_layer_); 605 texture_layer_->SetIsDrawable(true);
599 } 606 }
600 607
601 ImageTransportFactoryAndroid::GetInstance()->AcquireTexture( 608 ImageTransportFactoryAndroid::GetInstance()->AcquireTexture(
602 texture_id_in_layer_, mailbox.name); 609 texture_id_in_layer_, mailbox.name);
603 610
604 texture_layer_->SetNeedsDisplay(); 611 texture_layer_->SetNeedsDisplay();
605 texture_layer_->SetBounds(gfx::Size(content_size.width(), 612 texture_layer_->SetBounds(gfx::Size(content_size.width(),
606 content_size.height())); 613 content_size.height()));
607 614
608 // Calculate the uv_max based on the content size relative to the texture 615 // Calculate the uv_max based on the content size relative to the texture
609 // size. 616 // size.
610 gfx::PointF uv_max; 617 gfx::PointF uv_max;
611 if (texture_size.GetArea() > 0) { 618 if (texture_size.GetArea() > 0) {
612 uv_max.SetPoint(content_size.width() / texture_size.width(), 619 uv_max.SetPoint(content_size.width() / texture_size.width(),
613 content_size.height() / texture_size.height()); 620 content_size.height() / texture_size.height());
614 } 621 }
615 texture_layer_->SetUV(gfx::PointF(0, 0), uv_max); 622 texture_layer_->SetUV(gfx::PointF(0, 0), uv_max);
616 texture_size_in_layer_ = texture_size; 623 texture_size_in_layer_ = texture_size;
617 current_mailbox_ = mailbox; 624 current_mailbox_ = mailbox;
618 ack_callback.Run(); 625
626 if (consumed_current_texture_ || host_->is_hidden())
627 ack_callback.Run();
628 else
629 ack_callbacks_.push(ack_callback);
630
631 consumed_current_texture_ = false;
619 } 632 }
620 633
621 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( 634 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer(
622 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 635 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
623 int gpu_host_id) { 636 int gpu_host_id) {
624 NOTREACHED(); 637 NOTREACHED();
625 } 638 }
626 639
627 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { 640 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() {
628 NOTREACHED(); 641 NOTREACHED();
629 } 642 }
630 643
631 void RenderWidgetHostViewAndroid::AcceleratedSurfaceRelease() { 644 void RenderWidgetHostViewAndroid::AcceleratedSurfaceRelease() {
632 // This tells us we should free the frontbuffer. 645 // This tells us we should free the frontbuffer.
633 if (texture_id_in_layer_) { 646 if (texture_id_in_layer_) {
634 texture_layer_->SetTextureId(0); 647 texture_layer_->SetTextureId(0);
648 texture_layer_->SetIsDrawable(false);
635 ImageTransportFactoryAndroid::GetInstance()->DeleteTexture( 649 ImageTransportFactoryAndroid::GetInstance()->DeleteTexture(
636 texture_id_in_layer_); 650 texture_id_in_layer_);
637 texture_id_in_layer_ = 0; 651 texture_id_in_layer_ = 0;
638 current_mailbox_ = gpu::Mailbox(); 652 current_mailbox_ = gpu::Mailbox();
639 } 653 }
640 } 654 }
641 655
642 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( 656 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface(
643 const gfx::Size& desired_size) { 657 const gfx::Size& desired_size) {
644 NOTREACHED(); 658 NOTREACHED();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 if (host_) 764 if (host_)
751 host_->MoveCaret(point); 765 host_->MoveCaret(point);
752 } 766 }
753 767
754 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { 768 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const {
755 return cached_background_color_; 769 return cached_background_color_;
756 } 770 }
757 771
758 void RenderWidgetHostViewAndroid::SetContentViewCore( 772 void RenderWidgetHostViewAndroid::SetContentViewCore(
759 ContentViewCoreImpl* content_view_core) { 773 ContentViewCoreImpl* content_view_core) {
774 RunAckCallbacks();
775
760 if (content_view_core_ && is_layer_attached_) 776 if (content_view_core_ && is_layer_attached_)
761 content_view_core_->RemoveLayer(layer_); 777 content_view_core_->RemoveLayer(layer_);
762 778
763 content_view_core_ = content_view_core; 779 content_view_core_ = content_view_core;
764 if (content_view_core_ && is_layer_attached_) 780 if (content_view_core_ && is_layer_attached_)
765 content_view_core_->AttachLayer(layer_); 781 content_view_core_->AttachLayer(layer_);
766 } 782 }
767 783
784 void RenderWidgetHostViewAndroid::RunAckCallbacks() {
785 while (!ack_callbacks_.empty()) {
786 ack_callbacks_.front().Run();
787 ack_callbacks_.pop();
788 }
789 }
790
768 void RenderWidgetHostViewAndroid::HasTouchEventHandlers( 791 void RenderWidgetHostViewAndroid::HasTouchEventHandlers(
769 bool need_touch_events) { 792 bool need_touch_events) {
770 if (content_view_core_) 793 if (content_view_core_)
771 content_view_core_->HasTouchEventHandlers(need_touch_events); 794 content_view_core_->HasTouchEventHandlers(need_touch_events);
772 } 795 }
773 796
797 unsigned RenderWidgetHostViewAndroid::PrepareTexture(
798 cc::ResourceUpdateQueue* queue) {
799 RunAckCallbacks();
800 consumed_current_texture_ = true;
801 return texture_id_in_layer_;
802 }
803
804 WebKit::WebGraphicsContext3D* RenderWidgetHostViewAndroid::Context3d() {
805 return ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
806 }
807
808 bool RenderWidgetHostViewAndroid::PrepareTextureMailbox(
809 cc::TextureMailbox* mailbox) {
810 return false;
811 }
812
774 // static 813 // static
775 void RenderWidgetHostViewPort::GetDefaultScreenInfo( 814 void RenderWidgetHostViewPort::GetDefaultScreenInfo(
776 WebKit::WebScreenInfo* results) { 815 WebKit::WebScreenInfo* results) {
777 const gfx::Display& display = 816 const gfx::Display& display =
778 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 817 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
779 results->rect = display.bounds(); 818 results->rect = display.bounds();
780 // TODO(husky): Remove any system controls from availableRect. 819 // TODO(husky): Remove any system controls from availableRect.
781 results->availableRect = display.work_area(); 820 results->availableRect = display.work_area();
782 results->deviceScaleFactor = display.device_scale_factor(); 821 results->deviceScaleFactor = display.device_scale_factor();
783 gfx::DeviceDisplayInfo info; 822 gfx::DeviceDisplayInfo info;
784 results->depth = info.GetBitsPerPixel(); 823 results->depth = info.GetBitsPerPixel();
785 results->depthPerComponent = info.GetBitsPerComponent(); 824 results->depthPerComponent = info.GetBitsPerComponent();
786 results->isMonochrome = (results->depthPerComponent == 0); 825 results->isMonochrome = (results->depthPerComponent == 0);
787 } 826 }
788 827
789 //////////////////////////////////////////////////////////////////////////////// 828 ////////////////////////////////////////////////////////////////////////////////
790 // RenderWidgetHostView, public: 829 // RenderWidgetHostView, public:
791 830
792 // static 831 // static
793 RenderWidgetHostView* 832 RenderWidgetHostView*
794 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 833 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
795 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 834 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
796 return new RenderWidgetHostViewAndroid(rwhi, NULL); 835 return new RenderWidgetHostViewAndroid(rwhi, NULL);
797 } 836 }
798 837
799 } // namespace content 838 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698