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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 SoftwareDevice(SynchronousCompositorOutputSurface* surface) | 55 SoftwareDevice(SynchronousCompositorOutputSurface* surface) |
56 : surface_(surface), | 56 : surface_(surface), |
57 null_device_(SkBitmap::kARGB_8888_Config, 1, 1), | 57 null_device_(SkBitmap::kARGB_8888_Config, 1, 1), |
58 null_canvas_(&null_device_) { | 58 null_canvas_(&null_device_) { |
59 } | 59 } |
60 virtual void Resize(gfx::Size size) OVERRIDE { | 60 virtual void Resize(gfx::Size size) OVERRIDE { |
61 // Intentional no-op: canvas size is controlled by the embedder. | 61 // Intentional no-op: canvas size is controlled by the embedder. |
62 } | 62 } |
63 virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE { | 63 virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE { |
64 DCHECK(surface_->current_sw_canvas_); | 64 DCHECK(surface_->current_sw_canvas_); |
65 if (surface_->current_sw_canvas_) | 65 if (!surface_->current_sw_canvas_) { |
66 return surface_->current_sw_canvas_; | 66 LOG(WARNING) << "BeginPaint with no canvas set"; |
67 return &null_canvas_; | 67 return &null_canvas_; |
68 } | |
69 LOG_IF(WARNING, surface_->did_swap_buffer_) | |
70 << "Mutliple calls to BeginPaint per frame"; | |
71 return surface_->current_sw_canvas_; | |
68 } | 72 } |
69 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE { | 73 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE { |
70 surface_->current_sw_canvas_ = NULL; | 74 surface_->did_swap_buffer_ = true; |
71 } | 75 } |
72 virtual void CopyToBitmap(gfx::Rect rect, SkBitmap* output) OVERRIDE { | 76 virtual void CopyToBitmap(gfx::Rect rect, SkBitmap* output) OVERRIDE { |
73 NOTIMPLEMENTED(); | 77 NOTIMPLEMENTED(); |
74 } | 78 } |
75 virtual void Scroll(gfx::Vector2d delta, | 79 virtual void Scroll(gfx::Vector2d delta, |
76 gfx::Rect clip_rect) OVERRIDE { | 80 gfx::Rect clip_rect) OVERRIDE { |
77 NOTIMPLEMENTED(); | 81 NOTIMPLEMENTED(); |
78 } | 82 } |
79 virtual void ReclaimDIB(const TransportDIB::Id& id) OVERRIDE { | 83 virtual void ReclaimDIB(const TransportDIB::Id& id) OVERRIDE { |
80 NOTIMPLEMENTED(); | 84 NOTIMPLEMENTED(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 damage_area = gfx::ToEnclosedRect(gfx::SkRectToRectF(canvas_clip)); | 170 damage_area = gfx::ToEnclosedRect(gfx::SkRectToRectF(canvas_clip)); |
167 } else { | 171 } else { |
168 damage_area = gfx::Rect(kint16max, kint16max); | 172 damage_area = gfx::Rect(kint16max, kint16max); |
169 } | 173 } |
170 | 174 |
171 gfx::Transform transform; | 175 gfx::Transform transform; |
172 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 176 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
173 | 177 |
174 InvokeComposite(transform, damage_area); | 178 InvokeComposite(transform, damage_area); |
175 | 179 |
176 bool finished_draw = current_sw_canvas_ == NULL; | |
177 current_sw_canvas_ = NULL; | 180 current_sw_canvas_ = NULL; |
178 return finished_draw; | 181 return did_swap_buffer_; |
179 } | 182 } |
180 | 183 |
181 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 184 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
182 gfx::Size view_size, | 185 gfx::Size view_size, |
183 const gfx::Transform& transform, | 186 const gfx::Transform& transform, |
184 gfx::Rect damage_area) { | 187 gfx::Rect damage_area) { |
185 DCHECK(CalledOnValidThread()); | 188 DCHECK(CalledOnValidThread()); |
186 DCHECK(client_); | 189 DCHECK(client_); |
187 DCHECK(context3d()); | 190 DCHECK(context3d()); |
188 | 191 |
189 // Force a GL state restore next time a GLContextVirtual is made current. | 192 // Force a GL state restore next time a GLContextVirtual is made current. |
190 // TODO(boliu): Move this to the end of this function after we have fixed | 193 // TODO(boliu): Move this to the end of this function after we have fixed |
191 // all cases of MakeCurrent calls outside of draws. Tracked in | 194 // all cases of MakeCurrent calls outside of draws. Tracked in |
192 // crbug.com/239856. | 195 // crbug.com/239856. |
193 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); | 196 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); |
194 if (current_context) | 197 if (current_context) |
195 current_context->ReleaseCurrent(NULL); | 198 current_context->ReleaseCurrent(NULL); |
196 | 199 |
197 did_swap_buffer_ = false; | |
198 | 200 |
199 InvokeComposite(transform, damage_area); | 201 InvokeComposite(transform, damage_area); |
200 | 202 |
201 return did_swap_buffer_; | 203 return did_swap_buffer_; |
202 } | 204 } |
203 | 205 |
204 void SynchronousCompositorOutputSurface::InvokeComposite( | 206 void SynchronousCompositorOutputSurface::InvokeComposite( |
205 const gfx::Transform& transform, | 207 const gfx::Transform& transform, |
206 gfx::Rect damage_area) { | 208 gfx::Rect damage_area) { |
209 did_swap_buffer_ = false; | |
207 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the | 210 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the |
208 // whole view. Tracking bug to implement this: crbug.com/230463. | 211 // whole view. Tracking bug to implement this: crbug.com/230463. |
209 client_->SetNeedsRedrawRect(damage_area); | 212 client_->SetNeedsRedrawRect(damage_area); |
210 if (needs_begin_frame_) | 213 if (needs_begin_frame_) |
211 client_->BeginFrame(base::TimeTicks::Now()); | 214 client_->BeginFrame(base::TimeTicks::Now()); |
215 | |
216 if (did_swap_buffer_) | |
217 client_->OnSwapBuffersComplete(); | |
no sievers
2013/06/05 21:08:05
Is it even more straightforward to call this from
joth
2013/06/05 21:26:40
SwapBuffers() isn't called in the SW draw case.
| |
212 } | 218 } |
213 | 219 |
214 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 220 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
215 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 221 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
216 // thread. | 222 // thread. |
217 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 223 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
218 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 224 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
219 } | 225 } |
220 | 226 |
221 SynchronousCompositorOutputSurfaceDelegate* | 227 SynchronousCompositorOutputSurfaceDelegate* |
222 SynchronousCompositorOutputSurface::GetDelegate() { | 228 SynchronousCompositorOutputSurface::GetDelegate() { |
223 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 229 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
224 } | 230 } |
225 | 231 |
226 } // namespace content | 232 } // namespace content |
OLD | NEW |