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

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

Issue 2688193002: Mojo framework for AndroidOverlay. (Closed)
Patch Set: BUILD.gn fixes 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 "mojo/public/cpp/bindings/associated_binding.h"
8 #include "mojo/public/cpp/bindings/binding.h"
9 #include "services/service_manager/public/cpp/connect.h"
10 #include "services/service_manager/public/interfaces/interface_provider.mojom.h"
11
12 namespace media {
13
14 // Callback that we send to the provider impl. It just notifies the overlay.
15 // Will be deleted before the MojoAndroidOverlay that owns it is.
16 class MojoAndroidOverlayClient : public mojom::AndroidOverlayClient {
17 public:
18 MojoAndroidOverlayClient(mojom::AndroidOverlayClientRequest request,
19 MojoAndroidOverlay* overlay)
20 : overlay_(overlay), binding_(this, std::move(request)) {}
21
22 void OnInitialized(mojom::AndroidOverlayPtr ptr) override {
23 overlay_->OnInitialized(std::move(ptr));
24 }
25
26 void OnSurfaceReady(uint64_t surface_key) override {
27 overlay_->OnSurfaceReady(surface_key);
28 }
29
30 void OnDestroyed() override { overlay_->OnDestroyed(); }
31
32 private:
33 MojoAndroidOverlay* overlay_;
34 mojo::Binding<mojom::AndroidOverlayClient> binding_;
35
36 DISALLOW_COPY_AND_ASSIGN(MojoAndroidOverlayClient);
37 };
38
39 MojoAndroidOverlay::MojoAndroidOverlay(
40 service_manager::mojom::InterfaceProvider* interface_provider,
41 int render_frame_id,
42 int renderer_pid,
43 const AndroidOverlay::Config& config)
44 : interface_provider_(interface_provider) {
45 // Connect to the provider service.
46 mojom::AndroidOverlayProviderPtr provider_ptr;
47 service_manager::GetInterface<mojom::AndroidOverlayProvider>(
48 interface_provider_, &provider_ptr);
49
50 Setup(std::move(provider_ptr), render_frame_id, renderer_pid, config);
51 }
52
53 MojoAndroidOverlay::MojoAndroidOverlay(
54 mojom::AndroidOverlayProviderPtr provider_ptr,
55 int render_frame_id,
56 int renderer_pid,
57 const AndroidOverlay::Config& config) {
58 Setup(std::move(provider_ptr), render_frame_id, renderer_pid, config);
59 }
60
61 MojoAndroidOverlay::~MojoAndroidOverlay() {
62 // Dropping |overlay_ptr_| will signal to the implementation that we're done
63 // with the surface. If a synchronous destroy is pending, then it can be
64 // allowed to continue.
65
66 // We don't want any callbacks once destruction starts.
67 client_ = nullptr;
68 }
69
70 void MojoAndroidOverlay::Setup(mojom::AndroidOverlayProviderPtr provider_ptr,
71 int render_frame_id,
72 int renderer_pid,
73 const AndroidOverlay::Config& config) {
74 config_ = config;
75 provider_ptr_ = std::move(provider_ptr);
76
77 // Create the overlay client that will notify us.
78 mojom::AndroidOverlayClientPtr ptr;
79 client_ = base::MakeUnique<MojoAndroidOverlayClient>(MakeRequest(&ptr), this);
80
81 // Construct the config. While our caller could provide this, we also want to
82 // get (and retain) |config_|.
83 mojom::AndroidOverlayConfigPtr mojo_config =
84 mojom::AndroidOverlayConfig::New();
85 mojo_config->render_frame_id = render_frame_id;
86 mojo_config->renderer_pid = renderer_pid;
87 mojo_config->rect = config_.rect;
88 provider_ptr_->CreateOverlay(std::move(ptr), std::move(mojo_config));
89 }
90
91 void MojoAndroidOverlay::ScheduleLayout(const gfx::Rect& rect) {
92 // If we haven't gotten the overlay yet, then ignore this.
93 if (!overlay_ptr_.is_bound())
94 return;
95
96 if (!received_surface_)
97 return;
98
99 overlay_ptr_->ScheduleLayout(rect);
100 }
101
102 void MojoAndroidOverlay::OnInitialized(mojom::AndroidOverlayPtr ptr) {
103 overlay_ptr_ = std::move(ptr);
104 }
105
106 void MojoAndroidOverlay::OnSurfaceReady(uint32_t surface_key) {
107 // 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
108 gl::ScopedJavaSurface surface;
109 received_surface_ = true;
110 config_.ready_cb.Run(std::move(surface));
111 }
112
113 void MojoAndroidOverlay::OnDestroyed() {
114 // Note that |overlay_ptr_| might not be bound yet, or we might not have ever
115 // gotten a surface. Regardless, the overlay cannot be used.
116 config_.destroyed_cb.Run();
117
118 // Note: we do not delete |overlay_ptr_| here. Our client must delete us to
119 // signal that we should do that, since it still might be in use.
120 }
121
122 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698