Chromium Code Reviews| Index: media/mojo/clients/mojo_android_overlay.cc |
| diff --git a/media/mojo/clients/mojo_android_overlay.cc b/media/mojo/clients/mojo_android_overlay.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2bacaf323671a4d6ba66f982583955032a15e1a1 |
| --- /dev/null |
| +++ b/media/mojo/clients/mojo_android_overlay.cc |
| @@ -0,0 +1,122 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/mojo/clients/mojo_android_overlay.h" |
| + |
| +#include "mojo/public/cpp/bindings/associated_binding.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "services/service_manager/public/cpp/connect.h" |
| +#include "services/service_manager/public/interfaces/interface_provider.mojom.h" |
| + |
| +namespace media { |
| + |
| +// Callback that we send to the provider impl. It just notifies the overlay. |
| +// Will be deleted before the MojoAndroidOverlay that owns it is. |
| +class MojoAndroidOverlayClient : public mojom::AndroidOverlayClient { |
| + public: |
| + MojoAndroidOverlayClient(mojom::AndroidOverlayClientRequest request, |
| + MojoAndroidOverlay* overlay) |
| + : overlay_(overlay), binding_(this, std::move(request)) {} |
| + |
| + void OnInitialized(mojom::AndroidOverlayPtr ptr) override { |
| + overlay_->OnInitialized(std::move(ptr)); |
| + } |
| + |
| + void OnSurfaceReady(uint64_t surface_key) override { |
| + overlay_->OnSurfaceReady(surface_key); |
| + } |
| + |
| + void OnDestroyed() override { overlay_->OnDestroyed(); } |
| + |
| + private: |
| + MojoAndroidOverlay* overlay_; |
| + mojo::Binding<mojom::AndroidOverlayClient> binding_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MojoAndroidOverlayClient); |
| +}; |
| + |
| +MojoAndroidOverlay::MojoAndroidOverlay( |
| + service_manager::mojom::InterfaceProvider* interface_provider, |
| + int render_frame_id, |
| + int renderer_pid, |
| + const AndroidOverlay::Config& config) |
| + : interface_provider_(interface_provider) { |
| + // Connect to the provider service. |
| + mojom::AndroidOverlayProviderPtr provider_ptr; |
| + service_manager::GetInterface<mojom::AndroidOverlayProvider>( |
| + interface_provider_, &provider_ptr); |
| + |
| + Setup(std::move(provider_ptr), render_frame_id, renderer_pid, config); |
| +} |
| + |
| +MojoAndroidOverlay::MojoAndroidOverlay( |
| + mojom::AndroidOverlayProviderPtr provider_ptr, |
| + int render_frame_id, |
| + int renderer_pid, |
| + const AndroidOverlay::Config& config) { |
| + Setup(std::move(provider_ptr), render_frame_id, renderer_pid, config); |
| +} |
| + |
| +MojoAndroidOverlay::~MojoAndroidOverlay() { |
| + // Dropping |overlay_ptr_| will signal to the implementation that we're done |
| + // with the surface. If a synchronous destroy is pending, then it can be |
| + // allowed to continue. |
| + |
| + // We don't want any callbacks once destruction starts. |
| + client_ = nullptr; |
| +} |
| + |
| +void MojoAndroidOverlay::Setup(mojom::AndroidOverlayProviderPtr provider_ptr, |
| + int render_frame_id, |
| + int renderer_pid, |
| + const AndroidOverlay::Config& config) { |
| + config_ = config; |
| + provider_ptr_ = std::move(provider_ptr); |
| + |
| + // Create the overlay client that will notify us. |
| + mojom::AndroidOverlayClientPtr ptr; |
| + client_ = base::MakeUnique<MojoAndroidOverlayClient>(MakeRequest(&ptr), this); |
| + |
| + // Construct the config. While our caller could provide this, we also want to |
| + // get (and retain) |config_|. |
| + mojom::AndroidOverlayConfigPtr mojo_config = |
| + mojom::AndroidOverlayConfig::New(); |
| + mojo_config->render_frame_id = render_frame_id; |
| + mojo_config->renderer_pid = renderer_pid; |
| + mojo_config->rect = config_.rect; |
| + provider_ptr_->CreateOverlay(std::move(ptr), std::move(mojo_config)); |
| +} |
| + |
| +void MojoAndroidOverlay::ScheduleLayout(const gfx::Rect& rect) { |
| + // If we haven't gotten the overlay yet, then ignore this. |
| + if (!overlay_ptr_.is_bound()) |
| + return; |
| + |
| + if (!received_surface_) |
| + return; |
| + |
| + overlay_ptr_->ScheduleLayout(rect); |
| +} |
| + |
| +void MojoAndroidOverlay::OnInitialized(mojom::AndroidOverlayPtr ptr) { |
| + overlay_ptr_ = std::move(ptr); |
| +} |
| + |
| +void MojoAndroidOverlay::OnSurfaceReady(uint32_t surface_key) { |
| + // TODO(liberato): ask binder for the surface. |
|
Ken Rockot(use gerrit already)
2017/02/17 06:29:56
Side note in case this is interesting: we're activ
liberato (no reviews please)
2017/02/17 17:47:12
that is very exciting news!
is there a design doc
|
| + gl::ScopedJavaSurface surface; |
| + received_surface_ = true; |
| + config_.ready_cb.Run(std::move(surface)); |
| +} |
| + |
| +void MojoAndroidOverlay::OnDestroyed() { |
| + // Note that |overlay_ptr_| might not be bound yet, or we might not have ever |
| + // gotten a surface. Regardless, the overlay cannot be used. |
| + config_.destroyed_cb.Run(); |
| + |
| + // Note: we do not delete |overlay_ptr_| here. Our client must delete us to |
| + // signal that we should do that, since it still might be in use. |
| +} |
| + |
| +} // namespace media |