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

Side by Side Diff: media/mojo/clients/mojo_android_overlay.cc

Issue 2688193002: Mojo framework for AndroidOverlay. (Closed)
Patch Set: cl comments, refactored MojoAndroidOverlay to inherit from mojom:... Created 3 years, 10 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
OLDNEW
(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 int render_frame_id,
15 int renderer_pid,
16 const AndroidOverlay::Config& config)
17 : interface_provider_(interface_provider) {
18 // Connect to the provider service.
19 mojom::AndroidOverlayProviderPtr provider_ptr;
20 service_manager::GetInterface<mojom::AndroidOverlayProvider>(
21 interface_provider_, &provider_ptr);
22
23 Setup(std::move(provider_ptr), render_frame_id, renderer_pid, config);
24 }
25
26 MojoAndroidOverlay::MojoAndroidOverlay(
27 mojom::AndroidOverlayProviderPtr provider_ptr,
28 int render_frame_id,
29 int renderer_pid,
30 const AndroidOverlay::Config& config) {
31 Setup(std::move(provider_ptr), render_frame_id, renderer_pid, config);
32 }
33
34 MojoAndroidOverlay::~MojoAndroidOverlay() {
35 // Dropping |overlay_ptr_| will signal to the implementation that we're done
36 // with the surface. If a synchronous destroy is pending, then it can be
37 // allowed to continue.
38 }
39
40 void MojoAndroidOverlay::Setup(mojom::AndroidOverlayProviderPtr provider_ptr,
41 int render_frame_id,
42 int renderer_pid,
43 const AndroidOverlay::Config& config) {
44 config_ = config;
45 provider_ptr_ = std::move(provider_ptr);
46
47 // Construct the config. While our caller could provide this, we also want to
48 // get (and retain) |config_|.
49 mojom::AndroidOverlayConfigPtr mojo_config =
50 mojom::AndroidOverlayConfig::New();
51 mojo_config->render_frame_id = render_frame_id;
52 mojo_config->renderer_pid = renderer_pid;
53 mojo_config->rect = config_.rect;
54
55 mojom::AndroidOverlayClientPtr ptr;
56 binding_ = base::MakeUnique<mojo::Binding<mojom::AndroidOverlayClient>>(
57 this, mojo::MakeRequest(&ptr));
58 provider_ptr_->CreateOverlay(std::move(ptr), std::move(mojo_config));
59 }
60
61 void MojoAndroidOverlay::ScheduleLayout(const gfx::Rect& rect) {
62 // If we haven't gotten the overlay yet, then ignore this.
63 if (!overlay_ptr_.is_bound())
64 return;
65
66 if (!received_surface_)
67 return;
68
69 overlay_ptr_->ScheduleLayout(rect);
70 }
71
72 void MojoAndroidOverlay::OnInitialized(mojom::AndroidOverlayPtr ptr) {
73 overlay_ptr_ = std::move(ptr);
74 }
75
76 void MojoAndroidOverlay::OnSurfaceReady(uint64_t surface_key) {
77 gl::ScopedJavaSurface surface;
78 // TODO(liberato): ask binder for the surface here.
79 SetJavaSurface(std::move(surface));
80 received_surface_ = true;
81 config_.ready_cb.Run();
82 }
83
84 void MojoAndroidOverlay::OnDestroyed() {
85 // Note that |overlay_ptr_| might not be bound yet, or we might not have ever
86 // gotten a surface. Regardless, the overlay cannot be used.
87 config_.destroyed_cb.Run();
88
89 // Note: we do not delete |overlay_ptr_| here. Our client must delete us to
90 // signal that we should do that, since it still might be in use.
91 }
92
93 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698