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

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

Issue 12389061: Android: Add support for CompositorFrame swaps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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"
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) {
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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) { 469 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) {
436 if (!content_view_core_) 470 if (!content_view_core_)
437 return; 471 return;
438 472
439 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap); 473 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap);
440 } 474 }
441 475
442 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { 476 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() {
443 } 477 }
444 478
479 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
480 const cc::CompositorFrame& frame) {
481 if (!frame.gl_frame_data || frame.gl_frame_data->mailbox.IsZero())
482 return;
483
484 base::Closure callback = base::Bind(&InsertSyncPointAndAckForCompositor,
485 host_->GetProcess()->GetID(),
486 host_->GetRoutingID(),
487 current_mailbox_,
488 texture_size_in_layer_);
489 ImageTransportFactoryAndroid::GetInstance()->WaitSyncPoint(
490 frame.gl_frame_data->sync_point);
491 BuffersSwapped(
492 frame.gl_frame_data->mailbox, frame.gl_frame_data->size, callback);
493
494 }
495
445 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( 496 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped(
446 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, 497 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
447 int gpu_host_id) { 498 int gpu_host_id) {
499 if (params.mailbox_name.empty())
500 return;
501
502 std::string return_mailbox;
503 if (!current_mailbox_.IsZero()) {
504 return_mailbox.assign(
505 reinterpret_cast<const char*>(current_mailbox_.name),
506 sizeof(current_mailbox_.name));
507 }
508
509 base::Closure callback = base::Bind(&InsertSyncPointAndAckForGpu,
510 gpu_host_id, params.route_id,
511 return_mailbox);
512
513 gpu::Mailbox mailbox;
514 std::copy(params.mailbox_name.data(),
515 params.mailbox_name.data() + params.mailbox_name.length(),
516 reinterpret_cast<char*>(mailbox.name));
517
518 BuffersSwapped(mailbox, params.size, callback);
519 }
520
521 void RenderWidgetHostViewAndroid::BuffersSwapped(
522 const gpu::Mailbox& mailbox,
523 const gfx::Size size,
524 const base::Closure& ack_callback) {
448 ImageTransportFactoryAndroid* factory = 525 ImageTransportFactoryAndroid* factory =
449 ImageTransportFactoryAndroid::GetInstance(); 526 ImageTransportFactoryAndroid::GetInstance();
450 527
451 if (params.mailbox_name.empty())
452 return;
453
454 // TODO(sievers): When running the impl thread in the browser we 528 // TODO(sievers): When running the impl thread in the browser we
455 // need to delay the ACK until after commit and use more than a single 529 // need to delay the ACK until after commit and use more than a single
456 // texture. 530 // texture.
457 DCHECK(!CompositorImpl::IsThreadingEnabled()); 531 DCHECK(!CompositorImpl::IsThreadingEnabled());
458 532
459 if (texture_id_in_layer_) { 533 if (texture_id_in_layer_) {
460 DCHECK(!current_mailbox_name_.empty()); 534 DCHECK(!current_mailbox_.IsZero());
461 ImageTransportFactoryAndroid::GetInstance()->ReleaseTexture( 535 ImageTransportFactoryAndroid::GetInstance()->ReleaseTexture(
462 texture_id_in_layer_, 536 texture_id_in_layer_, current_mailbox_.name);
463 reinterpret_cast<const signed char*>(
464 current_mailbox_name_.data()));
465 } else { 537 } else {
466 texture_id_in_layer_ = factory->CreateTexture(); 538 texture_id_in_layer_ = factory->CreateTexture();
467 texture_layer_->setTextureId(texture_id_in_layer_); 539 texture_layer_->setTextureId(texture_id_in_layer_);
468 } 540 }
469 541
470 ImageTransportFactoryAndroid::GetInstance()->AcquireTexture( 542 ImageTransportFactoryAndroid::GetInstance()->AcquireTexture(
471 texture_id_in_layer_, 543 texture_id_in_layer_, mailbox.name);
472 reinterpret_cast<const signed char*>(
473 params.mailbox_name.data()));
474 544
475 // We need to tell ContentViewCore about the new frame before calling 545 // We need to tell ContentViewCore about the new frame before calling
476 // setNeedsDisplay() below so that it has the needed information schedule the 546 // setNeedsDisplay() below so that it has the needed information schedule the
477 // next compositor frame. 547 // next compositor frame.
478 if (content_view_core_) 548 if (content_view_core_)
479 content_view_core_->DidProduceRendererFrame(); 549 content_view_core_->DidProduceRendererFrame();
480 550
481 texture_layer_->setNeedsDisplay(); 551 texture_layer_->setNeedsDisplay();
482 texture_layer_->setBounds(params.size); 552 texture_layer_->setBounds(size);
483 texture_size_in_layer_ = params.size; 553 texture_size_in_layer_ = size;
484 554 current_mailbox_ = mailbox;
485 uint32 sync_point = 555 ack_callback.Run();
486 ImageTransportFactoryAndroid::GetInstance()->InsertSyncPoint();
487
488 AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
489 ack_params.mailbox_name = current_mailbox_name_;
490 ack_params.sync_point = sync_point;
491 RenderWidgetHostImpl::AcknowledgeBufferPresent(
492 params.route_id, gpu_host_id, ack_params);
493 current_mailbox_name_ = params.mailbox_name;
494 } 556 }
495 557
496 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( 558 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer(
497 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 559 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
498 int gpu_host_id) { 560 int gpu_host_id) {
499 NOTREACHED(); 561 NOTREACHED();
500 } 562 }
501 563
502 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { 564 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() {
503 NOTREACHED(); 565 NOTREACHED();
504 } 566 }
505 567
506 void RenderWidgetHostViewAndroid::AcceleratedSurfaceRelease() { 568 void RenderWidgetHostViewAndroid::AcceleratedSurfaceRelease() {
507 // This tells us we should free the frontbuffer. 569 // This tells us we should free the frontbuffer.
508 if (texture_id_in_layer_) { 570 if (texture_id_in_layer_) {
509 texture_layer_->setTextureId(0); 571 texture_layer_->setTextureId(0);
510 ImageTransportFactoryAndroid::GetInstance()->DeleteTexture( 572 ImageTransportFactoryAndroid::GetInstance()->DeleteTexture(
511 texture_id_in_layer_); 573 texture_id_in_layer_);
512 texture_id_in_layer_ = 0; 574 texture_id_in_layer_ = 0;
513 current_mailbox_name_.clear(); 575 current_mailbox_ = gpu::Mailbox();
514 } 576 }
515 } 577 }
516 578
517 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( 579 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface(
518 const gfx::Size& desired_size) { 580 const gfx::Size& desired_size) {
519 NOTREACHED(); 581 NOTREACHED();
520 return false; 582 return false;
521 } 583 }
522 584
523 void RenderWidgetHostViewAndroid::GetScreenInfo(WebKit::WebScreenInfo* result) { 585 void RenderWidgetHostViewAndroid::GetScreenInfo(WebKit::WebScreenInfo* result) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 // RenderWidgetHostView, public: 740 // RenderWidgetHostView, public:
679 741
680 // static 742 // static
681 RenderWidgetHostView* 743 RenderWidgetHostView*
682 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 744 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
683 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 745 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
684 return new RenderWidgetHostViewAndroid(rwhi, NULL); 746 return new RenderWidgetHostViewAndroid(rwhi, NULL);
685 } 747 }
686 748
687 } // namespace content 749 } // 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