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

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

Issue 10828356: Very basic Android browser-side compositing support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments, rebase Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "content/browser/android/content_view_core_impl.h" 11 #include "content/browser/android/content_view_core_impl.h"
12 #include "content/browser/android/draw_delegate_impl.h"
13 #include "content/browser/gpu/gpu_surface_tracker.h" 12 #include "content/browser/gpu/gpu_surface_tracker.h"
13 #include "content/browser/renderer_host/compositor_impl_android.h"
14 #include "content/browser/renderer_host/render_widget_host_impl.h" 14 #include "content/browser/renderer_host/render_widget_host_impl.h"
15 #include "content/common/android/device_info.h" 15 #include "content/common/android/device_info.h"
16 #include "content/common/gpu/gpu_messages.h" 16 #include "content/common/gpu/gpu_messages.h"
17 #include "content/common/view_messages.h" 17 #include "content/common/view_messages.h"
18 #include "content/public/browser/render_view_host.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( 22 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
22 RenderWidgetHostImpl* widget_host, 23 RenderWidgetHostImpl* widget_host,
23 ContentViewCoreImpl* content_view_core) 24 ContentViewCoreImpl* content_view_core)
24 : host_(widget_host), 25 : host_(widget_host),
25 // ContentViewCoreImpl represents the native side of the Java 26 // ContentViewCoreImpl represents the native side of the Java
26 // ContentViewCore. It being NULL means that it is not attached to the 27 // ContentViewCore. It being NULL means that it is not attached to the
27 // View system yet, so we treat it as hidden. 28 // View system yet, so we treat it as hidden.
28 is_hidden_(!content_view_core), 29 is_hidden_(!content_view_core),
29 content_view_core_(content_view_core) { 30 content_view_core_(content_view_core),
31 texture_layer_(WebKit::WebExternalTextureLayer::create()) {
30 host_->SetView(this); 32 host_->SetView(this);
31 // RenderWidgetHost is initialized as visible. If is_hidden_ is true, tell 33 // RenderWidgetHost is initialized as visible. If is_hidden_ is true, tell
32 // RenderWidgetHost to hide. 34 // RenderWidgetHost to hide.
33 if (is_hidden_) 35 if (is_hidden_)
34 host_->WasHidden(); 36 host_->WasHidden();
37 texture_layer_.setDrawsContent(!is_hidden_);
38 RenderViewHost* view_host = RenderViewHost::From(host_);
39 view_host->GetDelegate()->AttachLayer(texture_layer_);
35 } 40 }
36 41
37 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 42 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
38 } 43 }
39 44
40 void RenderWidgetHostViewAndroid::InitAsChild(gfx::NativeView parent_view) { 45 void RenderWidgetHostViewAndroid::InitAsChild(gfx::NativeView parent_view) {
41 NOTIMPLEMENTED(); 46 NOTIMPLEMENTED();
42 } 47 }
43 48
44 void RenderWidgetHostViewAndroid::InitAsPopup( 49 void RenderWidgetHostViewAndroid::InitAsPopup(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 host_->WasHidden(); 83 host_->WasHidden();
79 } 84 }
80 85
81 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { 86 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) {
82 // Update the size of the RWH. 87 // Update the size of the RWH.
83 if (requested_size_.width() != size.width() || 88 if (requested_size_.width() != size.width() ||
84 requested_size_.height() != size.height()) { 89 requested_size_.height() != size.height()) {
85 requested_size_ = gfx::Size(size.width(), size.height()); 90 requested_size_ = gfx::Size(size.width(), size.height());
86 host_->WasResized(); 91 host_->WasResized();
87 } 92 }
93 texture_layer_.setBounds(size);
88 } 94 }
89 95
90 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { 96 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
91 if (rect.origin().x() || rect.origin().y()) { 97 if (rect.origin().x() || rect.origin().y()) {
92 VLOG(0) << "SetBounds not implemented for (x,y)!=(0,0)"; 98 VLOG(0) << "SetBounds not implemented for (x,y)!=(0,0)";
93 } 99 }
94 SetSize(rect.size()); 100 SetSize(rect.size());
95 } 101 }
96 102
97 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { 103 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 140
135 return content_view_core_->HasFocus(); 141 return content_view_core_->HasFocus();
136 } 142 }
137 143
138 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { 144 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const {
139 NOTIMPLEMENTED(); 145 NOTIMPLEMENTED();
140 return false; 146 return false;
141 } 147 }
142 148
143 void RenderWidgetHostViewAndroid::Show() { 149 void RenderWidgetHostViewAndroid::Show() {
144 // nothing to do 150 texture_layer_.setDrawsContent(true);
klobag.chromium 2012/08/23 02:08:12 If we always call Show after the constructor, shou
no sievers 2012/08/27 18:07:02 Eventually we should do that. But it would break C
klobag.chromium 2012/08/27 23:44:55 Hmm, this can break instance where it doesn't have
145 } 151 }
146 152
147 void RenderWidgetHostViewAndroid::Hide() { 153 void RenderWidgetHostViewAndroid::Hide() {
148 // nothing to do 154 texture_layer_.setDrawsContent(false);
149 } 155 }
150 156
151 bool RenderWidgetHostViewAndroid::IsShowing() { 157 bool RenderWidgetHostViewAndroid::IsShowing() {
152 return !is_hidden_; 158 return !is_hidden_;
153 } 159 }
154 160
155 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { 161 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const {
156 gfx::Size bounds = DrawDelegateImpl::GetInstance()->GetBounds(); 162 gfx::Size bounds = CompositorImpl::GetInstance()->GetWindowBounds();
klobag.chromium 2012/08/23 02:08:12 I am not convinced that compositor should provides
no sievers 2012/08/27 18:07:02 Done.
157 if (!bounds.IsEmpty()) 163 if (!bounds.IsEmpty())
158 return gfx::Rect(bounds); 164 return gfx::Rect(bounds);
159 165
160 if (content_view_core_) { 166 if (content_view_core_) {
161 return content_view_core_->GetBounds(); 167 return content_view_core_->GetBounds();
162 } else { 168 } else {
163 // The ContentViewCore has not been created yet. This only happens when 169 // The ContentViewCore has not been created yet. This only happens when
164 // renderer asks for creating new window, for example, 170 // renderer asks for creating new window, for example,
165 // javascript window.open(). 171 // javascript window.open().
166 return gfx::Rect(0, 0, 0, 0); 172 return gfx::Rect(0, 0, 0, 0);
(...skipping 22 matching lines...) Expand all
189 const std::vector<gfx::Rect>& copy_rects) { 195 const std::vector<gfx::Rect>& copy_rects) {
190 NOTIMPLEMENTED(); 196 NOTIMPLEMENTED();
191 } 197 }
192 198
193 void RenderWidgetHostViewAndroid::RenderViewGone( 199 void RenderWidgetHostViewAndroid::RenderViewGone(
194 base::TerminationStatus status, int error_code) { 200 base::TerminationStatus status, int error_code) {
195 Destroy(); 201 Destroy();
196 } 202 }
197 203
198 void RenderWidgetHostViewAndroid::Destroy() { 204 void RenderWidgetHostViewAndroid::Destroy() {
205 RenderViewHost* view_host = RenderViewHost::From(host_);
206 view_host->GetDelegate()->RemoveLayer(texture_layer_);
207
199 content_view_core_ = NULL; 208 content_view_core_ = NULL;
200 209
201 // The RenderWidgetHost's destruction led here, so don't call it. 210 // The RenderWidgetHost's destruction led here, so don't call it.
202 host_ = NULL; 211 host_ = NULL;
203 212
204 delete this; 213 delete this;
205 } 214 }
206 215
207 void RenderWidgetHostViewAndroid::SetTooltipText( 216 void RenderWidgetHostViewAndroid::SetTooltipText(
208 const string16& tooltip_text) { 217 const string16& tooltip_text) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 NOTIMPLEMENTED(); 258 NOTIMPLEMENTED();
250 callback.Run(false); 259 callback.Run(false);
251 } 260 }
252 261
253 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { 262 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() {
254 } 263 }
255 264
256 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( 265 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped(
257 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, 266 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
258 int gpu_host_id) { 267 int gpu_host_id) {
259 DrawDelegateImpl::GetInstance()->OnSurfaceUpdated( 268 texture_layer_.setTextureId(params.surface_handle);
260 params.surface_handle, 269 texture_layer_.invalidate();
261 this, 270 // TODO(sievers): The view and layer should get sized proactively.
271 if (((gfx::Size)texture_layer_.bounds()).IsEmpty())
272 texture_layer_.setBounds(CompositorImpl::GetInstance()->GetWindowBounds());
273 CompositorImpl::GetInstance()->SurfaceUpdated(
262 base::Bind(&RenderWidgetHostImpl::AcknowledgeBufferPresent, 274 base::Bind(&RenderWidgetHostImpl::AcknowledgeBufferPresent,
263 params.route_id, gpu_host_id)); 275 params.route_id, gpu_host_id));
264 } 276 }
265 277
266 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( 278 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer(
267 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 279 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
268 int gpu_host_id) { 280 int gpu_host_id) {
269 NOTREACHED(); 281 NOTREACHED();
270 } 282 }
271 283
272 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { 284 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() {
273 NOTREACHED(); 285 NOTREACHED();
274 } 286 }
275 287
276 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( 288 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface(
277 const gfx::Size& desired_size) { 289 const gfx::Size& desired_size) {
278 NOTREACHED(); 290 NOTREACHED();
279 return false; 291 return false;
280 } 292 }
281 293
282 void RenderWidgetHostViewAndroid::StartContentIntent( 294 void RenderWidgetHostViewAndroid::StartContentIntent(
283 const GURL& content_url) { 295 const GURL& content_url) {
284 if (content_view_core_) 296 if (content_view_core_)
285 content_view_core_->StartContentIntent(content_url); 297 content_view_core_->StartContentIntent(content_url);
286 } 298 }
287 299
288 gfx::GLSurfaceHandle RenderWidgetHostViewAndroid::GetCompositingSurface() { 300 gfx::GLSurfaceHandle RenderWidgetHostViewAndroid::GetCompositingSurface() {
289 gfx::GLSurfaceHandle handle = 301 gfx::GLSurfaceHandle handle =
klobag.chromium 2012/08/23 02:08:12 Still not clear for this. You are using the browse
no sievers 2012/08/27 18:07:02 The handle is for the renderer-side compositor. Bu
klobag.chromium 2012/08/27 23:44:55 I think this deserves a comment. On 2012/08/27 18
290 DrawDelegateImpl::GetInstance()->GetDrawSurface(); 302 CompositorImpl::GetInstance()->GetCompositorSurface();
291 if (!handle.is_null()) 303 if (!handle.is_null())
292 return handle; 304 return handle;
293 305
294 // On Android, we cannot generate a window handle that can be passed to the 306 // On Android, we cannot generate a window handle that can be passed to the
295 // GPU process through the native side. Instead, we send the surface handle 307 // GPU process through the native side. Instead, we send the surface handle
296 // through Binder after the compositing context has been created. 308 // through Binder after the compositing context has been created.
297 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, true); 309 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, true);
298 } 310 }
299 311
300 void RenderWidgetHostViewAndroid::GetScreenInfo(WebKit::WebScreenInfo* result) { 312 void RenderWidgetHostViewAndroid::GetScreenInfo(WebKit::WebScreenInfo* result) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 // RenderWidgetHostView, public: 397 // RenderWidgetHostView, public:
386 398
387 // static 399 // static
388 RenderWidgetHostView* 400 RenderWidgetHostView*
389 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 401 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
390 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 402 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
391 return new RenderWidgetHostViewAndroid(rwhi, NULL); 403 return new RenderWidgetHostViewAndroid(rwhi, NULL);
392 } 404 }
393 405
394 } // namespace content 406 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698