OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/in_process/synchronous_compositor_impl.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "content/browser/android/in_process/synchronous_input_event_filter.h" |
9 #include "content/public/browser/android/synchronous_compositor_client.h" | 10 #include "content/public/browser/android/synchronous_compositor_client.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
13 #include "content/renderer/android/synchronous_compositor_factory.h" | 14 #include "content/renderer/android/synchronous_compositor_factory.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
(...skipping 23 matching lines...) Expand all Loading... |
42 GetCompositorMessageLoop() OVERRIDE { | 43 GetCompositorMessageLoop() OVERRIDE { |
43 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 44 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
44 } | 45 } |
45 | 46 |
46 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface( | 47 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface( |
47 int routing_id) OVERRIDE { | 48 int routing_id) OVERRIDE { |
48 scoped_ptr<SynchronousCompositorOutputSurface> output_surface( | 49 scoped_ptr<SynchronousCompositorOutputSurface> output_surface( |
49 new SynchronousCompositorOutputSurface(routing_id)); | 50 new SynchronousCompositorOutputSurface(routing_id)); |
50 return output_surface.PassAs<cc::OutputSurface>(); | 51 return output_surface.PassAs<cc::OutputSurface>(); |
51 } | 52 } |
| 53 |
| 54 virtual InputHandlerManagerClient* GetInputHandlerManagerClient() OVERRIDE { |
| 55 return synchronous_input_event_filter(); |
| 56 } |
| 57 |
| 58 SynchronousInputEventFilter* synchronous_input_event_filter() { |
| 59 return &synchronous_input_event_filter_; |
| 60 } |
| 61 |
| 62 private: |
| 63 SynchronousInputEventFilter synchronous_input_event_filter_; |
52 }; | 64 }; |
53 | 65 |
54 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory = | 66 base::LazyInstance<SynchronousCompositorFactoryImpl>::Leaky g_factory = |
55 LAZY_INSTANCE_INITIALIZER; | 67 LAZY_INSTANCE_INITIALIZER; |
56 | 68 |
57 } // namespace | 69 } // namespace |
58 | 70 |
59 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl); | 71 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SynchronousCompositorImpl); |
60 | 72 |
61 // static | 73 // static |
62 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( | 74 SynchronousCompositorImpl* SynchronousCompositorImpl::FromID(int process_id, |
63 int routing_id) { | 75 int routing_id) { |
64 RenderViewHost* rvh = RenderViewHost::FromID(GetInProcessRendererId(), | 76 if (g_factory == NULL) |
65 routing_id); | 77 return NULL; |
| 78 RenderViewHost* rvh = RenderViewHost::FromID(process_id, routing_id); |
66 if (!rvh) | 79 if (!rvh) |
67 return NULL; | 80 return NULL; |
68 WebContents* contents = WebContents::FromRenderViewHost(rvh); | 81 WebContents* contents = WebContents::FromRenderViewHost(rvh); |
69 if (!contents) | 82 if (!contents) |
70 return NULL; | 83 return NULL; |
71 return FromWebContents(contents); | 84 return FromWebContents(contents); |
72 } | 85 } |
73 | 86 |
| 87 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( |
| 88 int routing_id) { |
| 89 return FromID(GetInProcessRendererId(), routing_id); |
| 90 } |
| 91 |
74 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 92 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) |
75 : compositor_client_(NULL), | 93 : compositor_client_(NULL), |
76 output_surface_(NULL), | 94 output_surface_(NULL), |
77 contents_(contents) { | 95 contents_(contents) { |
78 } | 96 } |
79 | 97 |
80 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 98 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
81 if (compositor_client_) | 99 if (compositor_client_) |
82 compositor_client_->DidDestroyCompositor(this); | 100 compositor_client_->DidDestroyCompositor(this); |
83 } | 101 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 compositor_client_ = NULL; | 150 compositor_client_ = NULL; |
133 } | 151 } |
134 } | 152 } |
135 | 153 |
136 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { | 154 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { |
137 DCHECK(CalledOnValidThread()); | 155 DCHECK(CalledOnValidThread()); |
138 if (compositor_client_) | 156 if (compositor_client_) |
139 compositor_client_->SetContinuousInvalidate(enable); | 157 compositor_client_->SetContinuousInvalidate(enable); |
140 } | 158 } |
141 | 159 |
| 160 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
| 161 const WebKit::WebInputEvent& input_event) { |
| 162 DCHECK(CalledOnValidThread()); |
| 163 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
| 164 routing_id_, input_event); |
| 165 } |
| 166 |
142 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 167 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
143 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. | 168 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. |
144 bool SynchronousCompositorImpl::CalledOnValidThread() const { | 169 bool SynchronousCompositorImpl::CalledOnValidThread() const { |
145 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 170 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
146 } | 171 } |
147 | 172 |
148 // static | 173 // static |
149 void SynchronousCompositor::SetClientForWebContents( | 174 void SynchronousCompositor::SetClientForWebContents( |
150 WebContents* contents, | 175 WebContents* contents, |
151 SynchronousCompositorClient* client) { | 176 SynchronousCompositorClient* client) { |
152 DCHECK(contents); | 177 DCHECK(contents); |
153 if (client) { | 178 if (client) { |
154 g_factory.Get(); // Ensure it's initialized. | 179 g_factory.Get(); // Ensure it's initialized. |
155 SynchronousCompositorImpl::CreateForWebContents(contents); | 180 SynchronousCompositorImpl::CreateForWebContents(contents); |
156 } | 181 } |
157 if (SynchronousCompositorImpl* instance = | 182 if (SynchronousCompositorImpl* instance = |
158 SynchronousCompositorImpl::FromWebContents(contents)) { | 183 SynchronousCompositorImpl::FromWebContents(contents)) { |
159 instance->SetClient(client); | 184 instance->SetClient(client); |
160 } | 185 } |
161 } | 186 } |
162 | 187 |
163 } // namespace content | 188 } // namespace content |
OLD | NEW |