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 <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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "cc/compositor_frame.h" | |
| 14 #include "cc/compositor_frame_ack.h" | |
| 13 #include "cc/layer.h" | 15 #include "cc/layer.h" |
| 14 #include "cc/texture_layer.h" | 16 #include "cc/texture_layer.h" |
| 15 #include "content/browser/android/content_view_core_impl.h" | 17 #include "content/browser/android/content_view_core_impl.h" |
| 16 #include "content/browser/gpu/gpu_surface_tracker.h" | 18 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 17 #include "content/browser/renderer_host/compositor_impl_android.h" | 19 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 18 #include "content/browser/renderer_host/image_transport_factory_android.h" | 20 #include "content/browser/renderer_host/image_transport_factory_android.h" |
| 19 #include "content/browser/renderer_host/render_widget_host_impl.h" | 21 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 20 #include "content/browser/renderer_host/surface_texture_transport_client_android .h" | 22 #include "content/browser/renderer_host/surface_texture_transport_client_android .h" |
| 21 #include "content/common/gpu/client/gl_helper.h" | 23 #include "content/common/gpu/client/gl_helper.h" |
| 22 #include "content/common/gpu/gpu_messages.h" | 24 #include "content/common/gpu/gpu_messages.h" |
| 23 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
| 24 #include "third_party/khronos/GLES2/gl2.h" | 26 #include "third_party/khronos/GLES2/gl2.h" |
| 25 #include "third_party/khronos/GLES2/gl2ext.h" | 27 #include "third_party/khronos/GLES2/gl2ext.h" |
| 26 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" | 28 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" |
| 27 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL ayer.h" | 29 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL ayer.h" |
| 28 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 29 #include "ui/gfx/android/device_display_info.h" | 31 #include "ui/gfx/android/device_display_info.h" |
| 30 #include "ui/gfx/android/java_bitmap.h" | 32 #include "ui/gfx/android/java_bitmap.h" |
| 31 #include "ui/gfx/display.h" | 33 #include "ui/gfx/display.h" |
| 32 #include "ui/gfx/screen.h" | 34 #include "ui/gfx/screen.h" |
| 33 #include "ui/gfx/size_conversions.h" | 35 #include "ui/gfx/size_conversions.h" |
| 34 #include "webkit/compositor_bindings/web_compositor_support_impl.h" | 36 #include "webkit/compositor_bindings/web_compositor_support_impl.h" |
| 35 | 37 |
| 36 namespace content { | 38 namespace content { |
| 37 | 39 |
| 40 namespace { | |
| 41 | |
| 42 void InsertSyncPointAndAckForGpu( | |
| 43 int gpu_host_id, int route_id, const std::string& return_mailbox) { | |
| 44 uint32 sync_point = | |
| 45 ImageTransportFactoryAndroid::GetInstance()->InsertSyncPoint(); | |
| 46 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | |
| 47 ack_params.mailbox_name = return_mailbox; | |
| 48 ack_params.sync_point = sync_point; | |
| 49 RenderWidgetHostImpl::AcknowledgeBufferPresent( | |
| 50 route_id, gpu_host_id, ack_params); | |
| 51 } | |
| 52 | |
| 53 void InsertSyncPointAndAckForCompositor( | |
| 54 int renderer_host_id, | |
| 55 int route_id, | |
| 56 const gpu::Mailbox& return_mailbox, | |
| 57 const gfx::Size& return_size) { | |
|
Sami
2013/03/05 17:44:42
Nit: size by value.
no sievers
2013/03/05 21:58:05
Done.
| |
| 58 cc::CompositorFrameAck ack; | |
| 59 ack.gl_frame_data.reset(new cc::GLFrameData()); | |
| 60 if (!return_mailbox.IsZero()) { | |
| 61 ack.gl_frame_data->mailbox = return_mailbox; | |
| 62 ack.gl_frame_data->size = return_size; | |
| 63 ack.gl_frame_data->sync_point = | |
| 64 ImageTransportFactoryAndroid::GetInstance()->InsertSyncPoint(); | |
| 65 } | |
| 66 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | |
| 67 route_id, renderer_host_id, ack); | |
| 68 } | |
| 69 | |
| 70 } // anonymous namespace | |
| 71 | |
| 38 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( | 72 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
| 39 RenderWidgetHostImpl* widget_host, | 73 RenderWidgetHostImpl* widget_host, |
| 40 ContentViewCoreImpl* content_view_core) | 74 ContentViewCoreImpl* content_view_core) |
| 41 : host_(widget_host), | 75 : host_(widget_host), |
| 42 is_layer_attached_(true), | 76 is_layer_attached_(true), |
| 43 content_view_core_(NULL), | 77 content_view_core_(NULL), |
| 44 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 78 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 45 cached_background_color_(SK_ColorWHITE), | 79 cached_background_color_(SK_ColorWHITE), |
| 46 texture_id_in_layer_(0) { | 80 texture_id_in_layer_(0) { |
| 47 if (CompositorImpl::UsesDirectGL()) { | 81 if (CompositorImpl::UsesDirectGL()) { |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) { | 472 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) { |
| 439 if (!content_view_core_) | 473 if (!content_view_core_) |
| 440 return; | 474 return; |
| 441 | 475 |
| 442 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap); | 476 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap); |
| 443 } | 477 } |
| 444 | 478 |
| 445 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { | 479 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { |
| 446 } | 480 } |
| 447 | 481 |
| 482 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | |
| 483 const cc::CompositorFrame& frame) { | |
| 484 if (!frame.gl_frame_data || frame.gl_frame_data->mailbox.IsZero()) | |
| 485 return; | |
| 486 | |
| 487 base::Closure callback = base::Bind(&InsertSyncPointAndAckForCompositor, | |
| 488 host_->GetProcess()->GetID(), | |
| 489 host_->GetRoutingID(), | |
| 490 current_mailbox_, | |
| 491 texture_size_in_layer_); | |
| 492 ImageTransportFactoryAndroid::GetInstance()->WaitSyncPoint( | |
| 493 frame.gl_frame_data->sync_point); | |
| 494 BuffersSwapped( | |
| 495 frame.gl_frame_data->mailbox, frame.gl_frame_data->size, callback); | |
| 496 | |
|
Sami
2013/03/05 17:44:42
Maybe I'm missing something but why not call Inser
| |
| 497 } | |
| 498 | |
| 448 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( | 499 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( |
| 449 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, | 500 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
| 450 int gpu_host_id) { | 501 int gpu_host_id) { |
| 502 if (params.mailbox_name.empty()) | |
| 503 return; | |
| 504 | |
| 505 std::string return_mailbox; | |
| 506 if (!current_mailbox_.IsZero()) { | |
| 507 return_mailbox.assign( | |
| 508 reinterpret_cast<const char*>(current_mailbox_.name), | |
| 509 sizeof(current_mailbox_.name)); | |
| 510 } | |
| 511 | |
| 512 base::Closure callback = base::Bind(&InsertSyncPointAndAckForGpu, | |
| 513 gpu_host_id, params.route_id, | |
| 514 return_mailbox); | |
| 515 | |
| 516 gpu::Mailbox mailbox; | |
| 517 std::copy(params.mailbox_name.data(), | |
| 518 params.mailbox_name.data() + params.mailbox_name.length(), | |
| 519 reinterpret_cast<char*>(mailbox.name)); | |
| 520 | |
| 521 BuffersSwapped(mailbox, params.size, callback); | |
|
Sami
2013/03/05 17:44:42
Same Q about closure usage.
| |
| 522 } | |
| 523 | |
| 524 void RenderWidgetHostViewAndroid::BuffersSwapped( | |
| 525 const gpu::Mailbox& mailbox, | |
| 526 const gfx::Size& size, | |
| 527 const base::Closure& ack_callback) { | |
| 451 ImageTransportFactoryAndroid* factory = | 528 ImageTransportFactoryAndroid* factory = |
| 452 ImageTransportFactoryAndroid::GetInstance(); | 529 ImageTransportFactoryAndroid::GetInstance(); |
| 453 | 530 |
| 454 if (params.mailbox_name.empty()) | |
| 455 return; | |
| 456 | |
| 457 // TODO(sievers): When running the impl thread in the browser we | 531 // TODO(sievers): When running the impl thread in the browser we |
| 458 // need to delay the ACK until after commit and use more than a single | 532 // need to delay the ACK until after commit and use more than a single |
| 459 // texture. | 533 // texture. |
| 460 DCHECK(!CompositorImpl::IsThreadingEnabled()); | 534 DCHECK(!CompositorImpl::IsThreadingEnabled()); |
| 461 | 535 |
| 462 if (texture_id_in_layer_) { | 536 if (texture_id_in_layer_) { |
| 463 DCHECK(!current_mailbox_name_.empty()); | 537 DCHECK(!current_mailbox_.IsZero()); |
| 464 ImageTransportFactoryAndroid::GetInstance()->ReleaseTexture( | 538 ImageTransportFactoryAndroid::GetInstance()->ReleaseTexture( |
| 465 texture_id_in_layer_, | 539 texture_id_in_layer_, current_mailbox_.name); |
| 466 reinterpret_cast<const signed char*>( | |
| 467 current_mailbox_name_.data())); | |
| 468 } else { | 540 } else { |
| 469 texture_id_in_layer_ = factory->CreateTexture(); | 541 texture_id_in_layer_ = factory->CreateTexture(); |
| 470 texture_layer_->setTextureId(texture_id_in_layer_); | 542 texture_layer_->setTextureId(texture_id_in_layer_); |
| 471 } | 543 } |
| 472 | 544 |
| 473 ImageTransportFactoryAndroid::GetInstance()->AcquireTexture( | 545 ImageTransportFactoryAndroid::GetInstance()->AcquireTexture( |
| 474 texture_id_in_layer_, | 546 texture_id_in_layer_, mailbox.name); |
| 475 reinterpret_cast<const signed char*>( | |
| 476 params.mailbox_name.data())); | |
| 477 | 547 |
| 478 // We need to tell ContentViewCore about the new frame before calling | 548 // We need to tell ContentViewCore about the new frame before calling |
| 479 // setNeedsDisplay() below so that it has the needed information schedule the | 549 // setNeedsDisplay() below so that it has the needed information schedule the |
| 480 // next compositor frame. | 550 // next compositor frame. |
| 481 if (content_view_core_) | 551 if (content_view_core_) |
| 482 content_view_core_->DidProduceRendererFrame(); | 552 content_view_core_->DidProduceRendererFrame(); |
| 483 | 553 |
| 484 texture_layer_->setNeedsDisplay(); | 554 texture_layer_->setNeedsDisplay(); |
| 485 texture_layer_->setBounds(params.size); | 555 texture_layer_->setBounds(size); |
| 486 texture_size_in_layer_ = params.size; | 556 texture_size_in_layer_ = size; |
| 487 | 557 current_mailbox_ = mailbox; |
| 488 uint32 sync_point = | 558 ack_callback.Run(); |
| 489 ImageTransportFactoryAndroid::GetInstance()->InsertSyncPoint(); | |
| 490 | |
| 491 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | |
| 492 ack_params.mailbox_name = current_mailbox_name_; | |
| 493 ack_params.sync_point = sync_point; | |
| 494 RenderWidgetHostImpl::AcknowledgeBufferPresent( | |
| 495 params.route_id, gpu_host_id, ack_params); | |
| 496 current_mailbox_name_ = params.mailbox_name; | |
| 497 } | 559 } |
| 498 | 560 |
| 499 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( | 561 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( |
| 500 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, | 562 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, |
| 501 int gpu_host_id) { | 563 int gpu_host_id) { |
| 502 NOTREACHED(); | 564 NOTREACHED(); |
| 503 } | 565 } |
| 504 | 566 |
| 505 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { | 567 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { |
| 506 NOTREACHED(); | 568 NOTREACHED(); |
| 507 } | 569 } |
| 508 | 570 |
| 509 void RenderWidgetHostViewAndroid::AcceleratedSurfaceRelease() { | 571 void RenderWidgetHostViewAndroid::AcceleratedSurfaceRelease() { |
| 510 // This tells us we should free the frontbuffer. | 572 // This tells us we should free the frontbuffer. |
| 511 if (texture_id_in_layer_) { | 573 if (texture_id_in_layer_) { |
| 512 texture_layer_->setTextureId(0); | 574 texture_layer_->setTextureId(0); |
| 513 ImageTransportFactoryAndroid::GetInstance()->DeleteTexture( | 575 ImageTransportFactoryAndroid::GetInstance()->DeleteTexture( |
| 514 texture_id_in_layer_); | 576 texture_id_in_layer_); |
| 515 texture_id_in_layer_ = 0; | 577 texture_id_in_layer_ = 0; |
| 516 current_mailbox_name_.clear(); | 578 current_mailbox_ = gpu::Mailbox(); |
| 517 } | 579 } |
| 518 } | 580 } |
| 519 | 581 |
| 520 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( | 582 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( |
| 521 const gfx::Size& desired_size) { | 583 const gfx::Size& desired_size) { |
| 522 NOTREACHED(); | 584 NOTREACHED(); |
| 523 return false; | 585 return false; |
| 524 } | 586 } |
| 525 | 587 |
| 526 void RenderWidgetHostViewAndroid::GetScreenInfo(WebKit::WebScreenInfo* result) { | 588 void RenderWidgetHostViewAndroid::GetScreenInfo(WebKit::WebScreenInfo* result) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 // RenderWidgetHostView, public: | 743 // RenderWidgetHostView, public: |
| 682 | 744 |
| 683 // static | 745 // static |
| 684 RenderWidgetHostView* | 746 RenderWidgetHostView* |
| 685 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 747 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 686 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 748 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 687 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 749 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 688 } | 750 } |
| 689 | 751 |
| 690 } // namespace content | 752 } // namespace content |
| OLD | NEW |