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 "cc/input/input_handler.h" | |
10 #include "cc/input/layer_scroll_offset_delegate.h" | |
9 #include "content/browser/android/in_process/synchronous_input_event_filter.h" | 11 #include "content/browser/android/in_process/synchronous_input_event_filter.h" |
10 #include "content/public/browser/android/synchronous_compositor_client.h" | 12 #include "content/public/browser/android/synchronous_compositor_client.h" |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
14 #include "content/renderer/android/synchronous_compositor_factory.h" | 16 #include "content/renderer/android/synchronous_compositor_factory.h" |
17 #include "content/renderer/gpu/input_handler_manager.h" | |
18 #include "content/renderer/render_thread_impl.h" | |
15 | 19 |
16 namespace content { | 20 namespace content { |
17 | 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 int GetInProcessRendererId() { | 24 int GetInProcessRendererId() { |
21 content::RenderProcessHost::iterator it = | 25 content::RenderProcessHost::iterator it = |
22 content::RenderProcessHost::AllHostsIterator(); | 26 content::RenderProcessHost::AllHostsIterator(); |
23 if (it.IsAtEnd()) { | 27 if (it.IsAtEnd()) { |
24 // There should always be one RPH in single process mode. | 28 // There should always be one RPH in single process mode. |
25 NOTREACHED(); | 29 NOTREACHED(); |
26 return 0; | 30 return 0; |
27 } | 31 } |
28 | 32 |
29 int id = it.GetCurrentValue()->GetID(); | 33 int id = it.GetCurrentValue()->GetID(); |
30 it.Advance(); | 34 it.Advance(); |
31 DCHECK(it.IsAtEnd()); // Not multiprocess compatible. | 35 DCHECK(it.IsAtEnd()); // Not multiprocess compatible. |
32 return id; | 36 return id; |
33 } | 37 } |
34 | 38 |
35 class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { | 39 class SynchronousCompositorFactoryImpl: public SynchronousCompositorFactory { |
joth
2013/06/06 20:19:32
reminder: revert me
mkosiba (inactive)
2013/06/07 16:18:27
Thanks! Done.
| |
36 public: | 40 public: |
37 SynchronousCompositorFactoryImpl() { | 41 SynchronousCompositorFactoryImpl() { |
38 SynchronousCompositorFactory::SetInstance(this); | 42 SynchronousCompositorFactory::SetInstance(this); |
39 } | 43 } |
40 | 44 |
41 // SynchronousCompositorFactory | 45 // SynchronousCompositorFactory |
42 virtual scoped_refptr<base::MessageLoopProxy> | 46 virtual scoped_refptr<base::MessageLoopProxy> |
43 GetCompositorMessageLoop() OVERRIDE { | 47 GetCompositorMessageLoop() OVERRIDE { |
44 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 48 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
45 } | 49 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 bool SynchronousCompositorImpl::DemandDrawHw( | 121 bool SynchronousCompositorImpl::DemandDrawHw( |
118 gfx::Size view_size, | 122 gfx::Size view_size, |
119 const gfx::Transform& transform, | 123 const gfx::Transform& transform, |
120 gfx::Rect damage_area) { | 124 gfx::Rect damage_area) { |
121 DCHECK(CalledOnValidThread()); | 125 DCHECK(CalledOnValidThread()); |
122 DCHECK(output_surface_); | 126 DCHECK(output_surface_); |
123 | 127 |
124 return output_surface_->DemandDrawHw(view_size, transform, damage_area); | 128 return output_surface_->DemandDrawHw(view_size, transform, damage_area); |
125 } | 129 } |
126 | 130 |
131 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { | |
132 if (input_handler_.get()) | |
133 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); | |
134 } | |
135 | |
127 void SynchronousCompositorImpl::DidBindOutputSurface( | 136 void SynchronousCompositorImpl::DidBindOutputSurface( |
128 SynchronousCompositorOutputSurface* output_surface) { | 137 SynchronousCompositorOutputSurface* output_surface) { |
129 DCHECK(CalledOnValidThread()); | 138 DCHECK(CalledOnValidThread()); |
130 output_surface_ = output_surface; | 139 output_surface_ = output_surface; |
131 if (compositor_client_) | 140 if (compositor_client_) |
132 compositor_client_->DidInitializeCompositor(this); | 141 compositor_client_->DidInitializeCompositor(this); |
133 } | 142 } |
134 | 143 |
135 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( | 144 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( |
136 SynchronousCompositorOutputSurface* output_surface) { | 145 SynchronousCompositorOutputSurface* output_surface) { |
137 DCHECK(CalledOnValidThread()); | 146 DCHECK(CalledOnValidThread()); |
147 | |
138 // Allow for transient hand-over when two output surfaces may refer to | 148 // Allow for transient hand-over when two output surfaces may refer to |
139 // a single delegate. | 149 // a single delegate. |
140 if (output_surface_ == output_surface) { | 150 if (output_surface_ == output_surface) { |
141 output_surface_ = NULL; | 151 output_surface_ = NULL; |
142 if (compositor_client_) | 152 if (compositor_client_) |
143 compositor_client_->DidDestroyCompositor(this); | 153 compositor_client_->DidDestroyCompositor(this); |
144 compositor_client_ = NULL; | 154 compositor_client_ = NULL; |
145 } | 155 } |
146 } | 156 } |
147 | 157 |
158 void SynchronousCompositorImpl::SetInputHandler( | |
159 base::WeakPtr<cc::InputHandler> input_handler) { | |
160 DCHECK(CalledOnValidThread()); | |
161 | |
162 if (input_handler_.get()) | |
163 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); | |
164 | |
165 input_handler_ = input_handler; | |
166 | |
167 if (input_handler_.get()) | |
168 input_handler_->SetRootLayerScrollOffsetDelegate(this); | |
169 } | |
170 | |
148 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { | 171 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { |
149 DCHECK(CalledOnValidThread()); | 172 DCHECK(CalledOnValidThread()); |
150 if (compositor_client_) | 173 if (compositor_client_) |
151 compositor_client_->SetContinuousInvalidate(enable); | 174 compositor_client_->SetContinuousInvalidate(enable); |
152 } | 175 } |
153 | 176 |
154 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 177 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
155 const WebKit::WebInputEvent& input_event) { | 178 const WebKit::WebInputEvent& input_event) { |
156 DCHECK(CalledOnValidThread()); | 179 DCHECK(CalledOnValidThread()); |
157 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 180 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
158 routing_id_, input_event); | 181 routing_id_, input_event); |
159 } | 182 } |
160 | 183 |
184 void SynchronousCompositorImpl::SetTotalScrollOffset(gfx::Vector2dF new_value) { | |
185 DCHECK(CalledOnValidThread()); | |
186 if (compositor_client_) | |
187 compositor_client_->SetTotalRootLayerScrollOffset(new_value); | |
188 } | |
189 | |
190 gfx::Vector2dF SynchronousCompositorImpl::GetTotalScrollOffset() { | |
191 DCHECK(CalledOnValidThread()); | |
192 if (compositor_client_) | |
193 return compositor_client_->GetTotalRootLayerScrollOffset(); | |
194 else | |
195 return gfx::Vector2dF(); | |
joth
2013/06/06 20:19:32
use { } (or nix the else caluse)
mkosiba (inactive)
2013/06/07 16:18:27
Done.
| |
196 } | |
197 | |
161 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 198 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
162 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. | 199 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. |
163 bool SynchronousCompositorImpl::CalledOnValidThread() const { | 200 bool SynchronousCompositorImpl::CalledOnValidThread() const { |
164 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 201 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
165 } | 202 } |
166 | 203 |
167 // static | 204 // static |
168 void SynchronousCompositor::SetClientForWebContents( | 205 void SynchronousCompositor::SetClientForWebContents( |
169 WebContents* contents, | 206 WebContents* contents, |
170 SynchronousCompositorClient* client) { | 207 SynchronousCompositorClient* client) { |
171 DCHECK(contents); | 208 DCHECK(contents); |
172 if (client) { | 209 if (client) { |
173 g_factory.Get(); // Ensure it's initialized. | 210 g_factory.Get(); // Ensure it's initialized. |
174 SynchronousCompositorImpl::CreateForWebContents(contents); | 211 SynchronousCompositorImpl::CreateForWebContents(contents); |
175 } | 212 } |
176 if (SynchronousCompositorImpl* instance = | 213 if (SynchronousCompositorImpl* instance = |
177 SynchronousCompositorImpl::FromWebContents(contents)) { | 214 SynchronousCompositorImpl::FromWebContents(contents)) { |
178 instance->SetClient(client); | 215 instance->SetClient(client); |
179 } | 216 } |
180 } | 217 } |
181 | 218 |
182 } // namespace content | 219 } // namespace content |
OLD | NEW |