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" |
15 #include "webkit/common/gpu/context_provider_in_process.h" | 17 #include "webkit/common/gpu/context_provider_in_process.h" |
16 | 18 |
17 namespace content { | 19 namespace content { |
18 | 20 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 106 } |
105 | 107 |
106 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( | 108 SynchronousCompositorImpl* SynchronousCompositorImpl::FromRoutingID( |
107 int routing_id) { | 109 int routing_id) { |
108 return FromID(GetInProcessRendererId(), routing_id); | 110 return FromID(GetInProcessRendererId(), routing_id); |
109 } | 111 } |
110 | 112 |
111 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) | 113 SynchronousCompositorImpl::SynchronousCompositorImpl(WebContents* contents) |
112 : compositor_client_(NULL), | 114 : compositor_client_(NULL), |
113 output_surface_(NULL), | 115 output_surface_(NULL), |
114 contents_(contents) { | 116 contents_(contents), |
| 117 input_handler_(NULL) { |
115 DCHECK(contents); | 118 DCHECK(contents); |
116 } | 119 } |
117 | 120 |
118 SynchronousCompositorImpl::~SynchronousCompositorImpl() { | 121 SynchronousCompositorImpl::~SynchronousCompositorImpl() { |
119 if (compositor_client_) | 122 if (compositor_client_) |
120 compositor_client_->DidDestroyCompositor(this); | 123 compositor_client_->DidDestroyCompositor(this); |
121 } | 124 } |
122 | 125 |
123 void SynchronousCompositorImpl::SetClient( | 126 void SynchronousCompositorImpl::SetClient( |
124 SynchronousCompositorClient* compositor_client) { | 127 SynchronousCompositorClient* compositor_client) { |
(...skipping 17 matching lines...) Expand all Loading... |
142 return output_surface_->DemandDrawHw(view_size, transform, damage_area); | 145 return output_surface_->DemandDrawHw(view_size, transform, damage_area); |
143 } | 146 } |
144 | 147 |
145 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { | 148 bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { |
146 DCHECK(CalledOnValidThread()); | 149 DCHECK(CalledOnValidThread()); |
147 DCHECK(output_surface_); | 150 DCHECK(output_surface_); |
148 | 151 |
149 return output_surface_->DemandDrawSw(canvas); | 152 return output_surface_->DemandDrawSw(canvas); |
150 } | 153 } |
151 | 154 |
| 155 void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { |
| 156 if (input_handler_) |
| 157 input_handler_->OnRootLayerDelegatedScrollOffsetChanged(); |
| 158 } |
| 159 |
152 void SynchronousCompositorImpl::DidBindOutputSurface( | 160 void SynchronousCompositorImpl::DidBindOutputSurface( |
153 SynchronousCompositorOutputSurface* output_surface) { | 161 SynchronousCompositorOutputSurface* output_surface) { |
154 DCHECK(CalledOnValidThread()); | 162 DCHECK(CalledOnValidThread()); |
155 output_surface_ = output_surface; | 163 output_surface_ = output_surface; |
156 if (compositor_client_) | 164 if (compositor_client_) |
157 compositor_client_->DidInitializeCompositor(this); | 165 compositor_client_->DidInitializeCompositor(this); |
158 } | 166 } |
159 | 167 |
160 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( | 168 void SynchronousCompositorImpl::DidDestroySynchronousOutputSurface( |
161 SynchronousCompositorOutputSurface* output_surface) { | 169 SynchronousCompositorOutputSurface* output_surface) { |
162 DCHECK(CalledOnValidThread()); | 170 DCHECK(CalledOnValidThread()); |
| 171 |
163 // Allow for transient hand-over when two output surfaces may refer to | 172 // Allow for transient hand-over when two output surfaces may refer to |
164 // a single delegate. | 173 // a single delegate. |
165 if (output_surface_ == output_surface) { | 174 if (output_surface_ == output_surface) { |
166 output_surface_ = NULL; | 175 output_surface_ = NULL; |
167 if (compositor_client_) | 176 if (compositor_client_) |
168 compositor_client_->DidDestroyCompositor(this); | 177 compositor_client_->DidDestroyCompositor(this); |
169 compositor_client_ = NULL; | 178 compositor_client_ = NULL; |
170 } | 179 } |
171 } | 180 } |
172 | 181 |
| 182 void SynchronousCompositorImpl::SetInputHandler( |
| 183 cc::InputHandler* input_handler) { |
| 184 DCHECK(CalledOnValidThread()); |
| 185 |
| 186 if (input_handler_) |
| 187 input_handler_->SetRootLayerScrollOffsetDelegate(NULL); |
| 188 |
| 189 input_handler_ = input_handler; |
| 190 |
| 191 if (input_handler_) |
| 192 input_handler_->SetRootLayerScrollOffsetDelegate(this); |
| 193 } |
| 194 |
173 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { | 195 void SynchronousCompositorImpl::SetContinuousInvalidate(bool enable) { |
174 DCHECK(CalledOnValidThread()); | 196 DCHECK(CalledOnValidThread()); |
175 if (compositor_client_) | 197 if (compositor_client_) |
176 compositor_client_->SetContinuousInvalidate(enable); | 198 compositor_client_->SetContinuousInvalidate(enable); |
177 } | 199 } |
178 | 200 |
179 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( | 201 InputEventAckState SynchronousCompositorImpl::HandleInputEvent( |
180 const WebKit::WebInputEvent& input_event) { | 202 const WebKit::WebInputEvent& input_event) { |
181 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
182 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( | 204 return g_factory.Get().synchronous_input_event_filter()->HandleInputEvent( |
183 contents_->GetRoutingID(), input_event); | 205 contents_->GetRoutingID(), input_event); |
184 } | 206 } |
185 | 207 |
| 208 void SynchronousCompositorImpl::SetTotalScrollOffset(gfx::Vector2dF new_value) { |
| 209 DCHECK(CalledOnValidThread()); |
| 210 if (compositor_client_) |
| 211 compositor_client_->SetTotalRootLayerScrollOffset(new_value); |
| 212 } |
| 213 |
| 214 gfx::Vector2dF SynchronousCompositorImpl::GetTotalScrollOffset() { |
| 215 DCHECK(CalledOnValidThread()); |
| 216 if (compositor_client_) |
| 217 return compositor_client_->GetTotalRootLayerScrollOffset(); |
| 218 return gfx::Vector2dF(); |
| 219 } |
| 220 |
186 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 221 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
187 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. | 222 // requirement: SynchronousCompositorImpl() must only be used on the UI thread. |
188 bool SynchronousCompositorImpl::CalledOnValidThread() const { | 223 bool SynchronousCompositorImpl::CalledOnValidThread() const { |
189 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 224 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
190 } | 225 } |
191 | 226 |
192 // static | 227 // static |
193 void SynchronousCompositor::SetClientForWebContents( | 228 void SynchronousCompositor::SetClientForWebContents( |
194 WebContents* contents, | 229 WebContents* contents, |
195 SynchronousCompositorClient* client) { | 230 SynchronousCompositorClient* client) { |
196 DCHECK(contents); | 231 DCHECK(contents); |
197 if (client) { | 232 if (client) { |
198 g_factory.Get(); // Ensure it's initialized. | 233 g_factory.Get(); // Ensure it's initialized. |
199 SynchronousCompositorImpl::CreateForWebContents(contents); | 234 SynchronousCompositorImpl::CreateForWebContents(contents); |
200 } | 235 } |
201 if (SynchronousCompositorImpl* instance = | 236 if (SynchronousCompositorImpl* instance = |
202 SynchronousCompositorImpl::FromWebContents(contents)) { | 237 SynchronousCompositorImpl::FromWebContents(contents)) { |
203 instance->SetClient(client); | 238 instance->SetClient(client); |
204 } | 239 } |
205 } | 240 } |
206 | 241 |
207 } // namespace content | 242 } // namespace content |
OLD | NEW |