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_output_surfa
ce.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 65 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
66 int routing_id, | 66 int routing_id, |
67 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) | 67 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) |
68 : cc::OutputSurface( | 68 : cc::OutputSurface( |
69 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 69 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
70 routing_id_(routing_id), | 70 routing_id_(routing_id), |
71 registered_(false), | 71 registered_(false), |
72 current_sw_canvas_(nullptr), | 72 current_sw_canvas_(nullptr), |
73 memory_policy_(0), | 73 memory_policy_(0), |
74 frame_swap_message_queue_(frame_swap_message_queue) { | 74 output_surface_client_(nullptr), |
| 75 frame_swap_message_queue_(frame_swap_message_queue), |
| 76 begin_frame_source_(nullptr) { |
75 capabilities_.deferred_gl_initialization = true; | 77 capabilities_.deferred_gl_initialization = true; |
76 capabilities_.draw_and_swap_full_viewport_every_frame = true; | 78 capabilities_.draw_and_swap_full_viewport_every_frame = true; |
77 capabilities_.adjust_deadline_for_parent = false; | 79 capabilities_.adjust_deadline_for_parent = false; |
78 capabilities_.delegated_rendering = true; | 80 capabilities_.delegated_rendering = true; |
79 capabilities_.max_frames_pending = 1; | 81 capabilities_.max_frames_pending = 1; |
80 memory_policy_.priority_cutoff_when_visible = | 82 memory_policy_.priority_cutoff_when_visible = |
81 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 83 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
82 } | 84 } |
83 | 85 |
84 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 86 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
85 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
86 if (registered_) { | 88 if (registered_) { |
87 SynchronousCompositorRegistry::GetInstance()->UnregisterOutputSurface( | 89 SynchronousCompositorRegistry::GetInstance()->UnregisterOutputSurface( |
88 routing_id_, this); | 90 routing_id_, this); |
89 } | 91 } |
| 92 DCHECK(!begin_frame_source_); |
90 } | 93 } |
91 | 94 |
92 bool SynchronousCompositorOutputSurface::BindToClient( | 95 bool SynchronousCompositorOutputSurface::BindToClient( |
93 cc::OutputSurfaceClient* surface_client) { | 96 cc::OutputSurfaceClient* surface_client) { |
94 DCHECK(CalledOnValidThread()); | 97 DCHECK(CalledOnValidThread()); |
95 if (!cc::OutputSurface::BindToClient(surface_client)) | 98 if (!cc::OutputSurface::BindToClient(surface_client)) |
96 return false; | 99 return false; |
97 | 100 |
98 client_->SetMemoryPolicy(memory_policy_); | 101 output_surface_client_ = surface_client; |
| 102 output_surface_client_->SetMemoryPolicy(memory_policy_); |
99 | 103 |
100 SynchronousCompositorRegistry::GetInstance()->RegisterOutputSurface( | 104 SynchronousCompositorRegistry::GetInstance()->RegisterOutputSurface( |
101 routing_id_, this); | 105 routing_id_, this); |
102 registered_ = true; | 106 registered_ = true; |
103 | 107 |
104 return true; | 108 return true; |
105 } | 109 } |
106 | 110 |
107 void SynchronousCompositorOutputSurface::SetCompositor( | |
108 SynchronousCompositorImpl* compositor) { | |
109 DCHECK(CalledOnValidThread()); | |
110 compositor_ = compositor; | |
111 } | |
112 | |
113 void SynchronousCompositorOutputSurface::Reshape( | 111 void SynchronousCompositorOutputSurface::Reshape( |
114 const gfx::Size& size, float scale_factor) { | 112 const gfx::Size& size, float scale_factor) { |
115 // Intentional no-op: surface size is controlled by the embedder. | 113 // Intentional no-op: surface size is controlled by the embedder. |
116 } | 114 } |
117 | 115 |
118 void SynchronousCompositorOutputSurface::SwapBuffers( | 116 void SynchronousCompositorOutputSurface::SwapBuffers( |
119 cc::CompositorFrame* frame) { | 117 cc::CompositorFrame* frame) { |
120 DCHECK(CalledOnValidThread()); | 118 DCHECK(CalledOnValidThread()); |
121 | 119 |
122 frame_holder_.reset(new cc::CompositorFrame); | 120 frame_holder_.reset(new cc::CompositorFrame); |
123 frame->AssignTo(frame_holder_.get()); | 121 frame->AssignTo(frame_holder_.get()); |
124 | 122 |
125 client_->DidSwapBuffers(); | 123 client_->DidSwapBuffers(); |
126 } | 124 } |
127 | 125 |
128 void SynchronousCompositorOutputSurface::Invalidate() { | 126 void SynchronousCompositorOutputSurface::SetBeginFrameSource( |
129 DCHECK(CalledOnValidThread()); | 127 SynchronousCompositorExternalBeginFrameSource* begin_frame_source) { |
130 compositor_->PostInvalidate(); | 128 begin_frame_source_ = begin_frame_source; |
131 } | 129 } |
132 | 130 |
133 namespace { | 131 namespace { |
134 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { | 132 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { |
135 // CC's draw origin starts at the viewport. | 133 // CC's draw origin starts at the viewport. |
136 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0); | 134 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0); |
137 } | 135 } |
138 } // namespace | 136 } // namespace |
139 | 137 |
140 bool SynchronousCompositorOutputSurface::InitializeHwDraw( | 138 bool SynchronousCompositorOutputSurface::InitializeHwDraw( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 true); | 172 true); |
175 | 173 |
176 return frame_holder_.Pass(); | 174 return frame_holder_.Pass(); |
177 } | 175 } |
178 | 176 |
179 scoped_ptr<cc::CompositorFrame> | 177 scoped_ptr<cc::CompositorFrame> |
180 SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 178 SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
181 DCHECK(CalledOnValidThread()); | 179 DCHECK(CalledOnValidThread()); |
182 DCHECK(canvas); | 180 DCHECK(canvas); |
183 DCHECK(!current_sw_canvas_); | 181 DCHECK(!current_sw_canvas_); |
184 | |
185 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 182 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
186 | 183 |
187 SkIRect canvas_clip; | 184 SkIRect canvas_clip; |
188 canvas->getClipDeviceBounds(&canvas_clip); | 185 canvas->getClipDeviceBounds(&canvas_clip); |
189 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); | 186 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
190 | 187 |
191 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 188 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
192 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 189 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
193 | 190 |
194 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), | 191 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), |
(...skipping 13 matching lines...) Expand all Loading... |
208 } | 205 } |
209 | 206 |
210 void SynchronousCompositorOutputSurface::InvokeComposite( | 207 void SynchronousCompositorOutputSurface::InvokeComposite( |
211 const gfx::Transform& transform, | 208 const gfx::Transform& transform, |
212 gfx::Rect viewport, | 209 gfx::Rect viewport, |
213 gfx::Rect clip, | 210 gfx::Rect clip, |
214 gfx::Rect viewport_rect_for_tile_priority, | 211 gfx::Rect viewport_rect_for_tile_priority, |
215 gfx::Transform transform_for_tile_priority, | 212 gfx::Transform transform_for_tile_priority, |
216 bool hardware_draw) { | 213 bool hardware_draw) { |
217 DCHECK(!frame_holder_.get()); | 214 DCHECK(!frame_holder_.get()); |
| 215 DCHECK(begin_frame_source_); |
218 | 216 |
219 gfx::Transform adjusted_transform = transform; | 217 gfx::Transform adjusted_transform = transform; |
220 AdjustTransform(&adjusted_transform, viewport); | 218 AdjustTransform(&adjusted_transform, viewport); |
221 SetExternalDrawConstraints(adjusted_transform, | 219 SetExternalDrawConstraints(adjusted_transform, |
222 viewport, | 220 viewport, |
223 clip, | 221 clip, |
224 viewport_rect_for_tile_priority, | 222 viewport_rect_for_tile_priority, |
225 transform_for_tile_priority, | 223 transform_for_tile_priority, |
226 !hardware_draw); | 224 !hardware_draw); |
227 SetNeedsRedrawRect(gfx::Rect(viewport.size())); | 225 SetNeedsRedrawRect(gfx::Rect(viewport.size())); |
228 | 226 |
229 client_->OnDraw(); | 227 begin_frame_source_->BeginFrame(); |
230 | 228 |
231 // After software draws (which might move the viewport arbitrarily), restore | 229 // After software draws (which might move the viewport arbitrarily), restore |
232 // the previous hardware viewport to allow CC's tile manager to prioritize | 230 // the previous hardware viewport to allow CC's tile manager to prioritize |
233 // properly. | 231 // properly. |
234 if (hardware_draw) { | 232 if (hardware_draw) { |
235 cached_hw_transform_ = adjusted_transform; | 233 cached_hw_transform_ = adjusted_transform; |
236 cached_hw_viewport_ = viewport; | 234 cached_hw_viewport_ = viewport; |
237 cached_hw_clip_ = clip; | 235 cached_hw_clip_ = clip; |
238 cached_hw_viewport_rect_for_tile_priority_ = | 236 cached_hw_viewport_rect_for_tile_priority_ = |
239 viewport_rect_for_tile_priority; | 237 viewport_rect_for_tile_priority; |
(...skipping 15 matching lines...) Expand all Loading... |
255 void SynchronousCompositorOutputSurface::ReturnResources( | 253 void SynchronousCompositorOutputSurface::ReturnResources( |
256 const cc::CompositorFrameAck& frame_ack) { | 254 const cc::CompositorFrameAck& frame_ack) { |
257 ReclaimResources(&frame_ack); | 255 ReclaimResources(&frame_ack); |
258 } | 256 } |
259 | 257 |
260 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { | 258 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { |
261 DCHECK(CalledOnValidThread()); | 259 DCHECK(CalledOnValidThread()); |
262 memory_policy_.bytes_limit_when_visible = bytes_limit; | 260 memory_policy_.bytes_limit_when_visible = bytes_limit; |
263 memory_policy_.num_resources_limit = kNumResourcesLimit; | 261 memory_policy_.num_resources_limit = kNumResourcesLimit; |
264 | 262 |
265 if (client_) | 263 if (output_surface_client_) |
266 client_->SetMemoryPolicy(memory_policy_); | 264 output_surface_client_->SetMemoryPolicy(memory_policy_); |
267 } | 265 } |
268 | 266 |
269 void SynchronousCompositorOutputSurface::SetTreeActivationCallback( | 267 void SynchronousCompositorOutputSurface::SetTreeActivationCallback( |
270 const base::Closure& callback) { | 268 const base::Closure& callback) { |
271 DCHECK(client_); | 269 DCHECK(client_); |
272 client_->SetTreeActivationCallback(callback); | 270 client_->SetTreeActivationCallback(callback); |
273 } | 271 } |
274 | 272 |
275 void SynchronousCompositorOutputSurface::GetMessagesToDeliver( | 273 void SynchronousCompositorOutputSurface::GetMessagesToDeliver( |
276 ScopedVector<IPC::Message>* messages) { | 274 ScopedVector<IPC::Message>* messages) { |
277 DCHECK(CalledOnValidThread()); | 275 DCHECK(CalledOnValidThread()); |
278 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = | 276 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
279 frame_swap_message_queue_->AcquireSendMessageScope(); | 277 frame_swap_message_queue_->AcquireSendMessageScope(); |
280 frame_swap_message_queue_->DrainMessages(messages); | 278 frame_swap_message_queue_->DrainMessages(messages); |
281 } | 279 } |
282 | 280 |
283 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 281 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
284 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 282 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
285 // thread. | 283 // thread. |
286 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 284 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
287 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 285 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
288 } | 286 } |
289 | 287 |
290 } // namespace content | 288 } // namespace content |
OLD | NEW |