Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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); |
| 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(); |
| 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 27 matching lines...) Expand all Loading... | |
| 194 const std::vector<gfx::Rect>& copy_rects) { | 200 const std::vector<gfx::Rect>& copy_rects) { |
| 195 NOTIMPLEMENTED(); | 201 NOTIMPLEMENTED(); |
| 196 } | 202 } |
| 197 | 203 |
| 198 void RenderWidgetHostViewAndroid::RenderViewGone( | 204 void RenderWidgetHostViewAndroid::RenderViewGone( |
| 199 base::TerminationStatus status, int error_code) { | 205 base::TerminationStatus status, int error_code) { |
| 200 Destroy(); | 206 Destroy(); |
| 201 } | 207 } |
| 202 | 208 |
| 203 void RenderWidgetHostViewAndroid::Destroy() { | 209 void RenderWidgetHostViewAndroid::Destroy() { |
| 210 RenderViewHost* view_host = RenderViewHost::From(host_); | |
| 211 view_host->GetDelegate()->RemoveLayer(texture_layer_); | |
| 212 | |
| 204 content_view_core_ = NULL; | 213 content_view_core_ = NULL; |
| 205 | 214 |
| 206 // The RenderWidgetHost's destruction led here, so don't call it. | 215 // The RenderWidgetHost's destruction led here, so don't call it. |
| 207 host_ = NULL; | 216 host_ = NULL; |
| 208 | 217 |
| 209 delete this; | 218 delete this; |
| 210 } | 219 } |
| 211 | 220 |
| 212 void RenderWidgetHostViewAndroid::SetTooltipText( | 221 void RenderWidgetHostViewAndroid::SetTooltipText( |
| 213 const string16& tooltip_text) { | 222 const string16& tooltip_text) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 NOTIMPLEMENTED(); | 263 NOTIMPLEMENTED(); |
| 255 callback.Run(false); | 264 callback.Run(false); |
| 256 } | 265 } |
| 257 | 266 |
| 258 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { | 267 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { |
| 259 } | 268 } |
| 260 | 269 |
| 261 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( | 270 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( |
| 262 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, | 271 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
| 263 int gpu_host_id) { | 272 int gpu_host_id) { |
| 264 DrawDelegateImpl::GetInstance()->OnSurfaceUpdated( | 273 texture_layer_.setTextureId(params.surface_handle); |
| 265 params.surface_handle, | 274 texture_layer_.invalidate(); |
| 266 this, | 275 // TODO(sievers): The view and layer should get sized proactively. |
| 276 if (((gfx::Size)texture_layer_.bounds()).IsEmpty()) | |
| 277 texture_layer_.setBounds(CompositorImpl::GetInstance()->GetWindowBounds()); | |
| 278 CompositorImpl::GetInstance()->SurfaceUpdated( | |
| 267 base::Bind(&RenderWidgetHostImpl::AcknowledgeBufferPresent, | 279 base::Bind(&RenderWidgetHostImpl::AcknowledgeBufferPresent, |
| 268 params.route_id, gpu_host_id)); | 280 params.route_id, gpu_host_id)); |
| 269 } | 281 } |
| 270 | 282 |
| 271 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( | 283 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( |
| 272 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, | 284 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, |
| 273 int gpu_host_id) { | 285 int gpu_host_id) { |
| 274 NOTREACHED(); | 286 NOTREACHED(); |
| 275 } | 287 } |
| 276 | 288 |
| 277 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { | 289 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { |
| 278 NOTREACHED(); | 290 NOTREACHED(); |
| 279 } | 291 } |
| 280 | 292 |
| 281 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( | 293 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( |
| 282 const gfx::Size& desired_size) { | 294 const gfx::Size& desired_size) { |
| 283 NOTREACHED(); | 295 NOTREACHED(); |
| 284 return false; | 296 return false; |
| 285 } | 297 } |
| 286 | 298 |
| 287 void RenderWidgetHostViewAndroid::StartContentIntent( | 299 void RenderWidgetHostViewAndroid::StartContentIntent( |
| 288 const GURL& content_url) { | 300 const GURL& content_url) { |
| 289 if (content_view_core_) | 301 if (content_view_core_) |
| 290 content_view_core_->StartContentIntent(content_url); | 302 content_view_core_->StartContentIntent(content_url); |
| 291 } | 303 } |
| 292 | 304 |
| 293 gfx::GLSurfaceHandle RenderWidgetHostViewAndroid::GetCompositingSurface() { | 305 gfx::GLSurfaceHandle RenderWidgetHostViewAndroid::GetCompositingSurface() { |
| 294 gfx::GLSurfaceHandle handle = | 306 gfx::GLSurfaceHandle handle = |
|
klobag.chromium
2012/08/22 07:01:19
We don't care about the return any more as it is s
no sievers
2012/08/22 21:17:40
This is actually not the browser-side compositor,
| |
| 295 DrawDelegateImpl::GetInstance()->GetDrawSurface(); | 307 CompositorImpl::GetInstance()->GetCompositorSurface(); |
| 296 if (!handle.is_null()) | 308 if (!handle.is_null()) |
| 297 return handle; | 309 return handle; |
| 298 | 310 |
| 299 // On Android, we cannot generate a window handle that can be passed to the | 311 // On Android, we cannot generate a window handle that can be passed to the |
| 300 // GPU process through the native side. Instead, we send the surface handle | 312 // GPU process through the native side. Instead, we send the surface handle |
| 301 // through Binder after the compositing context has been created. | 313 // through Binder after the compositing context has been created. |
| 302 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, true); | 314 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, true); |
| 303 } | 315 } |
| 304 | 316 |
| 305 void RenderWidgetHostViewAndroid::GetScreenInfo(WebKit::WebScreenInfo* result) { | 317 void RenderWidgetHostViewAndroid::GetScreenInfo(WebKit::WebScreenInfo* result) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 // RenderWidgetHostView, public: | 402 // RenderWidgetHostView, public: |
| 391 | 403 |
| 392 // static | 404 // static |
| 393 RenderWidgetHostView* | 405 RenderWidgetHostView* |
| 394 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 406 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 395 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 407 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 396 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 408 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 397 } | 409 } |
| 398 | 410 |
| 399 } // namespace content | 411 } // namespace content |
| OLD | NEW |