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" |
11 #include "content/browser/android/synchronous_compositor_host.h" | 11 #include "content/browser/android/synchronous_compositor_host.h" |
12 #include "content/browser/bad_message.h" | 12 #include "content/browser/bad_message.h" |
13 #include "content/common/android/sync_compositor_messages.h" | 13 #include "content/common/android/sync_compositor_messages.h" |
14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
15 #include "ui/android/window_android.h" | 15 #include "ui/android/window_android.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 namespace { | |
20 base::LazyInstance<std::map<int, SynchronousCompositorObserver*>> g_instances; | |
21 } | |
22 | |
23 // static | |
24 SynchronousCompositorObserver* SynchronousCompositorObserver::GetOrCreateFor( | |
25 int process_id) { | |
26 auto itr = g_instances.Get().find(process_id); | |
27 if (itr != g_instances.Get().end()) | |
28 return itr->second; | |
29 return new SynchronousCompositorObserver(process_id); | |
30 } | |
31 | |
32 SynchronousCompositorObserver::SynchronousCompositorObserver(int process_id) | 19 SynchronousCompositorObserver::SynchronousCompositorObserver(int process_id) |
33 : render_process_host_(RenderProcessHost::FromID(process_id)), | 20 : BrowserMessageFilter(SyncCompositorMsgStart), |
21 render_process_host_(RenderProcessHost::FromID(process_id)), | |
34 window_android_in_vsync_(nullptr) { | 22 window_android_in_vsync_(nullptr) { |
35 DCHECK(render_process_host_); | 23 DCHECK(render_process_host_); |
36 DCHECK(!base::ContainsKey(g_instances.Get(), render_process_host_->GetID())); | |
37 g_instances.Get()[render_process_host_->GetID()] = this; | |
38 render_process_host_->AddObserver(this); | |
39 } | 24 } |
40 | 25 |
41 SynchronousCompositorObserver::~SynchronousCompositorObserver() { | 26 SynchronousCompositorObserver::~SynchronousCompositorObserver() { |
42 DCHECK(compositor_host_pending_renderer_state_.empty()); | 27 DCHECK(compositor_host_pending_renderer_state_.empty()); |
43 DCHECK(base::ContainsKey(g_instances.Get(), render_process_host_->GetID())); | 28 // TODO(boliu): signal pending frames. |
44 DCHECK_EQ(this, g_instances.Get()[render_process_host_->GetID()]); | |
45 render_process_host_->RemoveObserver(this); | |
46 g_instances.Get().erase(render_process_host_->GetID()); | |
47 } | |
48 | |
49 void SynchronousCompositorObserver::RenderProcessHostDestroyed( | |
50 RenderProcessHost* host) { | |
51 DCHECK_EQ(render_process_host_, host); | |
52 delete this; | |
53 } | 29 } |
54 | 30 |
55 void SynchronousCompositorObserver::SyncStateAfterVSync( | 31 void SynchronousCompositorObserver::SyncStateAfterVSync( |
56 ui::WindowAndroid* window_android, | 32 ui::WindowAndroid* window_android, |
57 SynchronousCompositorHost* compositor_host) { | 33 SynchronousCompositorHost* compositor_host) { |
58 DCHECK(!window_android_in_vsync_ || | 34 DCHECK(!window_android_in_vsync_ || |
59 window_android_in_vsync_ == window_android) | 35 window_android_in_vsync_ == window_android) |
60 << !!window_android_in_vsync_; | 36 << !!window_android_in_vsync_; |
61 DCHECK(compositor_host); | 37 DCHECK(compositor_host); |
62 DCHECK(!base::ContainsValue(compositor_host_pending_renderer_state_, | 38 DCHECK(!base::ContainsValue(compositor_host_pending_renderer_state_, |
63 compositor_host)); | 39 compositor_host)); |
64 compositor_host_pending_renderer_state_.push_back(compositor_host); | 40 compositor_host_pending_renderer_state_.push_back(compositor_host); |
65 if (window_android_in_vsync_) | 41 if (window_android_in_vsync_) |
66 return; | 42 return; |
67 window_android_in_vsync_ = window_android; | 43 window_android_in_vsync_ = window_android; |
68 window_android_in_vsync_->AddObserver(this); | 44 window_android_in_vsync_->AddObserver(this); |
69 } | 45 } |
70 | 46 |
47 bool SynchronousCompositorObserver::OnMessageReceived( | |
48 const IPC::Message& message) { | |
49 bool handled = true; | |
50 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorObserver, message) | |
51 IPC_MESSAGE_HANDLER_GENERIC(SyncCompositorHostMsg_ReturnFrame, | |
52 ReceiveFrame(message)) | |
53 IPC_MESSAGE_UNHANDLED(handled = false) | |
54 IPC_END_MESSAGE_MAP() | |
55 return handled; | |
56 } | |
57 | |
58 bool SynchronousCompositorObserver::ReceiveFrame(const IPC::Message& message) { | |
59 SyncCompositorHostMsg_ReturnFrame::Param param; | |
60 if (!SyncCompositorHostMsg_ReturnFrame::Read(&message, ¶m)) | |
61 return false; | |
62 | |
63 int routing_id = message.routing_id(); | |
64 scoped_refptr<SynchronousCompositor::FrameFuture> future; | |
65 { | |
66 base::AutoLock lock(future_map_lock_); | |
67 auto itr = future_map_.find(routing_id); | |
68 if (itr == future_map_.end()) { | |
69 bad_message::ReceivedBadMessage(render_process_host_, | |
70 bad_message::SCO_INVALID_ARGUMENT); | |
71 return true; | |
72 } | |
73 future = std::move(itr->second); | |
74 DCHECK(future); | |
75 future_map_.erase(itr); | |
76 } | |
77 | |
78 std::unique_ptr<SynchronousCompositor::Frame> frame_ptr = | |
dcheng
2016/10/21 06:42:56
Note it's generally considered to just abbreviate
boliu
2016/10/21 15:15:32
Done.
| |
79 base::MakeUnique<SynchronousCompositor::Frame>(); | |
80 frame_ptr->compositor_frame_sink_id = std::get<0>(param); | |
81 cc::CompositorFrame& compositor_frame = std::get<1>(param); | |
82 if (compositor_frame.delegated_frame_data) { | |
83 frame_ptr->frame.reset(new cc::CompositorFrame); | |
84 *frame_ptr->frame = std::move(compositor_frame); | |
85 } | |
86 future->setFrame(std::move(frame_ptr)); | |
87 // TODO(boliu): Post metadata back to UI thread. | |
88 return true; | |
89 } | |
90 | |
91 void SynchronousCompositorObserver::SetFrameFuture( | |
92 const int routing_id, | |
93 const scoped_refptr<SynchronousCompositor::FrameFuture>& frame_future) { | |
94 // TODO(boliu): Need a sequenced id, to queue previous frames. | |
95 DCHECK(frame_future); | |
96 base::AutoLock lock(future_map_lock_); | |
97 future_map_[routing_id] = std::move(frame_future); | |
dcheng
2016/10/21 06:42:56
Note that std::move() here doesn't do anything, si
boliu
2016/10/21 15:15:32
changed to pass by value in the function param, so
| |
98 } | |
99 | |
71 void SynchronousCompositorObserver::OnCompositingDidCommit() { | 100 void SynchronousCompositorObserver::OnCompositingDidCommit() { |
72 NOTREACHED(); | 101 NOTREACHED(); |
73 } | 102 } |
74 | 103 |
75 void SynchronousCompositorObserver::OnRootWindowVisibilityChanged( | 104 void SynchronousCompositorObserver::OnRootWindowVisibilityChanged( |
76 bool visible) { | 105 bool visible) { |
77 NOTREACHED(); | 106 NOTREACHED(); |
78 } | 107 } |
79 | 108 |
80 void SynchronousCompositorObserver::OnAttachCompositor() { | 109 void SynchronousCompositorObserver::OnAttachCompositor() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 151 |
123 void SynchronousCompositorObserver::OnActivityStopped() { | 152 void SynchronousCompositorObserver::OnActivityStopped() { |
124 NOTREACHED(); | 153 NOTREACHED(); |
125 } | 154 } |
126 | 155 |
127 void SynchronousCompositorObserver::OnActivityStarted() { | 156 void SynchronousCompositorObserver::OnActivityStarted() { |
128 NOTREACHED(); | 157 NOTREACHED(); |
129 } | 158 } |
130 | 159 |
131 } // namespace content | 160 } // namespace content |
OLD | NEW |