| 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..debd9e371bc6640b7c66a5216a664f3144f365ff
|
| --- /dev/null
|
| +++ b/media/mojo/clients/mojo_android_overlay.cc
|
| @@ -0,0 +1,123 @@
|
| +// 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) {
|
| + gl::ScopedJavaSurface surface;
|
| + // TODO(liberato): ask binder for the surface here.
|
| + SetJavaSurface(std::move(surface));
|
| + received_surface_ = true;
|
| + config_.ready_cb.Run();
|
| +}
|
| +
|
| +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
|
|
|