OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/android/synchronous_compositor_observer.h" | 5 #include "content/browser/android/synchronous_compositor_observer.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // static | 23 // static |
24 SynchronousCompositorObserver* SynchronousCompositorObserver::GetOrCreateFor( | 24 SynchronousCompositorObserver* SynchronousCompositorObserver::GetOrCreateFor( |
25 int process_id) { | 25 int process_id) { |
26 auto itr = g_instances.Get().find(process_id); | 26 auto itr = g_instances.Get().find(process_id); |
27 if (itr != g_instances.Get().end()) | 27 if (itr != g_instances.Get().end()) |
28 return itr->second; | 28 return itr->second; |
29 return new SynchronousCompositorObserver(process_id); | 29 return new SynchronousCompositorObserver(process_id); |
30 } | 30 } |
31 | 31 |
32 SynchronousCompositorObserver::SynchronousCompositorObserver(int process_id) | 32 SynchronousCompositorObserver::SynchronousCompositorObserver(int process_id) |
33 : render_process_host_(RenderProcessHost::FromID(process_id)), | 33 : BrowserMessageFilter(SyncCompositorMsgStart), |
| 34 render_process_host_(RenderProcessHost::FromID(process_id)), |
34 window_android_in_vsync_(nullptr) { | 35 window_android_in_vsync_(nullptr) { |
35 DCHECK(render_process_host_); | 36 DCHECK(render_process_host_); |
36 DCHECK(!base::ContainsKey(g_instances.Get(), render_process_host_->GetID())); | 37 DCHECK(!base::ContainsKey(g_instances.Get(), render_process_host_->GetID())); |
37 g_instances.Get()[render_process_host_->GetID()] = this; | 38 g_instances.Get()[render_process_host_->GetID()] = this; |
38 render_process_host_->AddObserver(this); | 39 render_process_host_->AddObserver(this); |
39 } | 40 } |
40 | 41 |
41 SynchronousCompositorObserver::~SynchronousCompositorObserver() { | 42 SynchronousCompositorObserver::~SynchronousCompositorObserver() { |
42 DCHECK(compositor_host_pending_renderer_state_.empty()); | 43 DCHECK(compositor_host_pending_renderer_state_.empty()); |
43 DCHECK(base::ContainsKey(g_instances.Get(), render_process_host_->GetID())); | 44 DCHECK(base::ContainsKey(g_instances.Get(), render_process_host_->GetID())); |
(...skipping 17 matching lines...) Expand all Loading... |
61 DCHECK(compositor_host); | 62 DCHECK(compositor_host); |
62 DCHECK(!base::ContainsValue(compositor_host_pending_renderer_state_, | 63 DCHECK(!base::ContainsValue(compositor_host_pending_renderer_state_, |
63 compositor_host)); | 64 compositor_host)); |
64 compositor_host_pending_renderer_state_.push_back(compositor_host); | 65 compositor_host_pending_renderer_state_.push_back(compositor_host); |
65 if (window_android_in_vsync_) | 66 if (window_android_in_vsync_) |
66 return; | 67 return; |
67 window_android_in_vsync_ = window_android; | 68 window_android_in_vsync_ = window_android; |
68 window_android_in_vsync_->AddObserver(this); | 69 window_android_in_vsync_->AddObserver(this); |
69 } | 70 } |
70 | 71 |
| 72 bool SynchronousCompositorObserver::OnMessageReceived( |
| 73 const IPC::Message& message) { |
| 74 bool handled = true; |
| 75 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorObserver, message) |
| 76 IPC_MESSAGE_HANDLER_GENERIC(SyncCompositorHostMsg_ReturnFrame, |
| 77 ReceiveFrame(message)) |
| 78 IPC_MESSAGE_UNHANDLED(handled = false) |
| 79 IPC_END_MESSAGE_MAP() |
| 80 return handled; |
| 81 } |
| 82 |
| 83 bool SynchronousCompositorObserver::ReceiveFrame(const IPC::Message& message) { |
| 84 SyncCompositorHostMsg_ReturnFrame::Param param; |
| 85 if (!SyncCompositorHostMsg_ReturnFrame::Read(&message, ¶m)) |
| 86 return false; |
| 87 uint32_t compositor_frame_sink_id = std::get<0>(param); |
| 88 cc::CompositorFrame compositor_frame = std::move(std::get<1>(param)); |
| 89 |
| 90 content::SynchronousCompositor::Frame frame; |
| 91 frame.frame.reset(new cc::CompositorFrame); |
| 92 frame.compositor_frame_sink_id = compositor_frame_sink_id; |
| 93 *frame.frame = std::move(compositor_frame); |
| 94 |
| 95 if (!frame.frame->delegated_frame_data) { |
| 96 frame.frame.reset(); |
| 97 } |
| 98 |
| 99 std::unique_ptr<SynchronousCompositor::Frame> frame_ptr = |
| 100 base::MakeUnique<SynchronousCompositor::Frame>(); |
| 101 frame_ptr->frame = std::move(frame.frame); |
| 102 frame_ptr->compositor_frame_sink_id = frame.compositor_frame_sink_id; |
| 103 |
| 104 int routing_id = message.routing_id(); |
| 105 |
| 106 future_map_[routing_id]->setFrame(std::move(frame_ptr)); |
| 107 |
| 108 return true; |
| 109 } |
| 110 |
| 111 void SynchronousCompositorObserver::SetFrameFuture( |
| 112 const int routing_id, |
| 113 const scoped_refptr<content::SynchronousCompositor::FrameFuture>& |
| 114 frame_future) { |
| 115 future_map_[routing_id] = std::move(frame_future); |
| 116 } |
| 117 |
71 void SynchronousCompositorObserver::OnCompositingDidCommit() { | 118 void SynchronousCompositorObserver::OnCompositingDidCommit() { |
72 NOTREACHED(); | 119 NOTREACHED(); |
73 } | 120 } |
74 | 121 |
75 void SynchronousCompositorObserver::OnRootWindowVisibilityChanged( | 122 void SynchronousCompositorObserver::OnRootWindowVisibilityChanged( |
76 bool visible) { | 123 bool visible) { |
77 NOTREACHED(); | 124 NOTREACHED(); |
78 } | 125 } |
79 | 126 |
80 void SynchronousCompositorObserver::OnAttachCompositor() { | 127 void SynchronousCompositorObserver::OnAttachCompositor() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 169 |
123 void SynchronousCompositorObserver::OnActivityStopped() { | 170 void SynchronousCompositorObserver::OnActivityStopped() { |
124 NOTREACHED(); | 171 NOTREACHED(); |
125 } | 172 } |
126 | 173 |
127 void SynchronousCompositorObserver::OnActivityStarted() { | 174 void SynchronousCompositorObserver::OnActivityStarted() { |
128 NOTREACHED(); | 175 NOTREACHED(); |
129 } | 176 } |
130 | 177 |
131 } // namespace content | 178 } // namespace content |
OLD | NEW |