| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( | 42 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
| 43 RenderWidgetHostImpl* widget_host, | 43 RenderWidgetHostImpl* widget_host, |
| 44 ContentViewCoreImpl* content_view_core) | 44 ContentViewCoreImpl* content_view_core) |
| 45 : host_(widget_host), | 45 : host_(widget_host), |
| 46 // ContentViewCoreImpl represents the native side of the Java | 46 // ContentViewCoreImpl represents the native side of the Java |
| 47 // ContentViewCore. It being NULL means that it is not attached to the | 47 // ContentViewCore. It being NULL means that it is not attached to the |
| 48 // View system yet, so we treat it as hidden. | 48 // View system yet, so we treat it as hidden. |
| 49 is_hidden_(!content_view_core), | 49 is_hidden_(!content_view_core), |
| 50 content_view_core_(content_view_core), | 50 content_view_core_(content_view_core), |
| 51 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 51 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 52 texture_layer_(WebKit::WebExternalTextureLayer::create()) { | 52 texture_layer_(WebKit::WebExternalTextureLayer::create()), |
| 53 current_buffer_id_(0) { |
| 53 host_->SetView(this); | 54 host_->SetView(this); |
| 54 // RenderWidgetHost is initialized as visible. If is_hidden_ is true, tell | 55 // RenderWidgetHost is initialized as visible. If is_hidden_ is true, tell |
| 55 // RenderWidgetHost to hide. | 56 // RenderWidgetHost to hide. |
| 56 if (is_hidden_) | 57 if (is_hidden_) |
| 57 host_->WasHidden(); | 58 host_->WasHidden(); |
| 58 texture_layer_->layer()->setDrawsContent(!is_hidden_); | 59 texture_layer_->layer()->setDrawsContent(!is_hidden_); |
| 59 host_->AttachLayer(texture_layer_->layer()); | 60 host_->AttachLayer(texture_layer_->layer()); |
| 60 } | 61 } |
| 61 | 62 |
| 62 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { | 63 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 NOTIMPLEMENTED(); | 303 NOTIMPLEMENTED(); |
| 303 callback.Run(false); | 304 callback.Run(false); |
| 304 } | 305 } |
| 305 | 306 |
| 306 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { | 307 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { |
| 307 } | 308 } |
| 308 | 309 |
| 309 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( | 310 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( |
| 310 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, | 311 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
| 311 int gpu_host_id) { | 312 int gpu_host_id) { |
| 312 texture_layer_->setTextureId(params.surface_handle); | 313 DCHECK(id_to_texture_map_.find(params.surface_handle) != |
| 314 id_to_texture_map_.end()); |
| 315 // TODO(sievers): The compositor should do this on the impl thread. |
| 316 // And the release should happen after the next commit. |
| 317 |
| 318 if (current_buffer_id_) { |
| 319 TextureMap::const_iterator it = id_to_texture_map_.find( |
| 320 current_buffer_id_); |
| 321 DCHECK(it != id_to_texture_map_.end()); |
| 322 ImageTransportFactoryAndroid::GetInstance()->ReleaseTexture( |
| 323 it->second->id, it->second->mailbox_name.get()); |
| 324 } |
| 325 |
| 326 TextureMap::const_iterator it = |
| 327 id_to_texture_map_.find(params.surface_handle); |
| 328 DCHECK(it != id_to_texture_map_.end()); |
| 329 const TextureInfo* texture = it->second; |
| 330 current_buffer_id_ = params.surface_handle; |
| 331 ImageTransportFactoryAndroid::GetInstance()->AcquireTexture( |
| 332 texture->id, texture->mailbox_name.get()); |
| 333 texture_layer_->setTextureId(texture->id); |
| 313 texture_layer_->layer()->invalidate(); | 334 texture_layer_->layer()->invalidate(); |
| 335 |
| 314 // TODO(sievers): The view and layer should get sized proactively. | 336 // TODO(sievers): The view and layer should get sized proactively. |
| 315 if (((gfx::Size)texture_layer_->layer()->bounds()).IsEmpty()) | 337 if (((gfx::Size)texture_layer_->layer()->bounds()).IsEmpty()) |
| 316 texture_layer_->layer()->setBounds( | 338 texture_layer_->layer()->setBounds( |
| 317 DrawDelegateImpl::GetInstance()->GetBounds()); | 339 DrawDelegateImpl::GetInstance()->GetBounds()); |
| 318 | 340 |
| 319 // TODO(sievers): When running the impl thread in the browser we | 341 // TODO(sievers): When running the impl thread in the browser we |
| 320 // need to delay the ACK until after commit. | 342 // need to delay the ACK until after commit. |
| 321 DCHECK(!WebKit::Platform::current()->compositorSupport()-> | 343 DCHECK(!WebKit::Platform::current()->compositorSupport()-> |
| 322 isThreadingEnabled()); | 344 isThreadingEnabled()); |
| 323 uint32 sync_point = | 345 uint32 sync_point = |
| 324 ImageTransportFactoryAndroid::GetInstance()->InsertSyncPoint(); | 346 ImageTransportFactoryAndroid::GetInstance()->InsertSyncPoint(); |
| 325 RenderWidgetHostImpl::AcknowledgeBufferPresent( | 347 RenderWidgetHostImpl::AcknowledgeBufferPresent( |
| 326 params.route_id, gpu_host_id, sync_point); | 348 params.route_id, gpu_host_id, sync_point); |
| 327 } | 349 } |
| 328 | 350 |
| 329 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( | 351 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( |
| 330 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, | 352 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, |
| 331 int gpu_host_id) { | 353 int gpu_host_id) { |
| 332 NOTREACHED(); | 354 NOTREACHED(); |
| 333 } | 355 } |
| 334 | 356 |
| 335 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { | 357 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { |
| 336 NOTREACHED(); | 358 NOTREACHED(); |
| 337 } | 359 } |
| 338 | 360 |
| 361 void RenderWidgetHostViewAndroid::AcceleratedSurfaceNew( |
| 362 int32 width_in_pixel, int32 height_in_pixel, uint64 surface_id, |
| 363 const std::string& mailbox_name) { |
| 364 LOG(INFO) << "RenderWidgetHostViewAndroid::AcceleratedSurfaceNew " << |
| 365 surface_id; |
| 366 DCHECK(surface_id); |
| 367 if (id_to_texture_map_.find(surface_id) != id_to_texture_map_.end()) { |
| 368 // TODO: Should this really happen? (It does during Resize and such) |
| 369 TextureInfo* texture = id_to_texture_map_[surface_id]; |
| 370 memcpy(texture->mailbox_name.get(), |
| 371 mailbox_name.c_str(), |
| 372 mailbox_name.length()); |
| 373 } else { |
| 374 scoped_ptr<TextureInfo> texture(new TextureInfo); |
| 375 texture->id = ImageTransportFactoryAndroid::GetInstance()->CreateTexture(); |
| 376 texture->mailbox_name.reset(new signed char[mailbox_name.length()]); |
| 377 memcpy(texture->mailbox_name.get(), |
| 378 mailbox_name.c_str(), |
| 379 mailbox_name.length()); |
| 380 id_to_texture_map_[surface_id] = texture.release(); |
| 381 } |
| 382 |
| 383 // There should only ever be a front- and backbuffer. |
| 384 DCHECK(id_to_texture_map_.size() <= 2); |
| 385 } |
| 386 |
| 387 void RenderWidgetHostViewAndroid::AcceleratedSurfaceRelease(uint64 surface_id) { |
| 388 LOG(INFO) << "RenderWidgetHostViewAndroid::AcceleratedSurfaceRelease " << |
| 389 surface_id; |
| 390 DCHECK(surface_id); |
| 391 TextureMap::iterator it = id_to_texture_map_.find(surface_id); |
| 392 DCHECK(it != id_to_texture_map_.end()); |
| 393 ImageTransportFactoryAndroid::GetInstance()->DeleteTexture(it->second->id); |
| 394 delete it->second; |
| 395 id_to_texture_map_.erase(it); |
| 396 } |
| 397 |
| 339 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( | 398 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( |
| 340 const gfx::Size& desired_size) { | 399 const gfx::Size& desired_size) { |
| 341 NOTREACHED(); | 400 NOTREACHED(); |
| 342 return false; | 401 return false; |
| 343 } | 402 } |
| 344 | 403 |
| 345 void RenderWidgetHostViewAndroid::StartContentIntent( | 404 void RenderWidgetHostViewAndroid::StartContentIntent( |
| 346 const GURL& content_url) { | 405 const GURL& content_url) { |
| 347 if (content_view_core_) | 406 if (content_view_core_) |
| 348 content_view_core_->StartContentIntent(content_url); | 407 content_view_core_->StartContentIntent(content_url); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 // RenderWidgetHostView, public: | 566 // RenderWidgetHostView, public: |
| 508 | 567 |
| 509 // static | 568 // static |
| 510 RenderWidgetHostView* | 569 RenderWidgetHostView* |
| 511 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 570 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 512 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 571 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 513 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 572 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 514 } | 573 } |
| 515 | 574 |
| 516 } // namespace content | 575 } // namespace content |
| OLD | NEW |