OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/mojo/clients/mojo_android_overlay.h" |
| 6 |
| 7 #include "services/service_manager/public/cpp/connect.h" |
| 8 #include "services/service_manager/public/interfaces/interface_provider.mojom.h" |
| 9 |
| 10 namespace media { |
| 11 |
| 12 MojoAndroidOverlay::MojoAndroidOverlay( |
| 13 service_manager::mojom::InterfaceProvider* interface_provider, |
| 14 const AndroidOverlay::Config& config) |
| 15 : interface_provider_(interface_provider), config_(config) { |
| 16 // Connect to the provider service. |
| 17 mojom::AndroidOverlayProviderPtr provider_ptr; |
| 18 service_manager::GetInterface<mojom::AndroidOverlayProvider>( |
| 19 interface_provider_, &provider_ptr_); |
| 20 |
| 21 // Fill in details of |config| into |mojo_config|. Our caller could do this |
| 22 // too, but since we want to retain |config_| anyway, we do it here. |
| 23 mojom::AndroidOverlayConfigPtr mojo_config = |
| 24 mojom::AndroidOverlayConfig::New(); |
| 25 mojo_config->routing_token = config_.routing_token; |
| 26 mojo_config->rect = config_.rect; |
| 27 |
| 28 mojom::AndroidOverlayClientPtr ptr; |
| 29 binding_ = base::MakeUnique<mojo::Binding<mojom::AndroidOverlayClient>>( |
| 30 this, mojo::MakeRequest(&ptr)); |
| 31 |
| 32 provider_ptr_->CreateOverlay(mojo::MakeRequest(&overlay_ptr_), std::move(ptr), |
| 33 std::move(mojo_config)); |
| 34 } |
| 35 |
| 36 MojoAndroidOverlay::~MojoAndroidOverlay() { |
| 37 // Dropping |overlay_ptr_| will signal to the implementation that we're done |
| 38 // with the surface. If a synchronous destroy is pending, then it can be |
| 39 // allowed to continue. |
| 40 } |
| 41 |
| 42 void MojoAndroidOverlay::ScheduleLayout(const gfx::Rect& rect) { |
| 43 // If we haven't gotten the surface yet, then ignore this. |
| 44 if (!received_surface_) |
| 45 return; |
| 46 |
| 47 overlay_ptr_->ScheduleLayout(rect); |
| 48 } |
| 49 |
| 50 const base::android::JavaRef<jobject>& MojoAndroidOverlay::GetJavaSurface() |
| 51 const { |
| 52 return surface_.j_surface(); |
| 53 } |
| 54 |
| 55 void MojoAndroidOverlay::OnSurfaceReady(uint64_t surface_key) { |
| 56 // TODO(liberato): ask binder for the surface here, and fill in |surface_|. |
| 57 received_surface_ = true; |
| 58 config_.ready_cb.Run(); |
| 59 } |
| 60 |
| 61 void MojoAndroidOverlay::OnDestroyed() { |
| 62 // Note that |overlay_ptr_| might not be bound yet, or we might not have ever |
| 63 // gotten a surface. Regardless, the overlay cannot be used. |
| 64 |
| 65 if (!received_surface_) |
| 66 config_.failed_cb.Run(); |
| 67 else |
| 68 config_.destroyed_cb.Run(); |
| 69 |
| 70 // Note: we do not delete |overlay_ptr_| here. Our client must delete us to |
| 71 // signal that we should do that, since it still might be in use. |
| 72 } |
| 73 |
| 74 } // namespace media |
OLD | NEW |