Chromium Code Reviews| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 179 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 176 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 180 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 177 AdjustTransformForClip(&transform, clip); | 181 AdjustTransformForClip(&transform, clip); |
| 178 | 182 |
| 179 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), | 183 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), |
| 180 canvas->getDeviceSize().height()); | 184 canvas->getDeviceSize().height()); |
| 181 client_->SetExternalDrawConstraints(transform, clip); | 185 client_->SetExternalDrawConstraints(transform, clip); |
| 182 | 186 |
| 183 InvokeComposite(clip.size()); | 187 InvokeComposite(clip.size()); |
| 184 | 188 |
| 185 bool finished_draw = current_sw_canvas_ == NULL; | |
| 186 current_sw_canvas_ = NULL; | 189 current_sw_canvas_ = NULL; |
| 187 return finished_draw; | 190 return did_swap_buffer_; |
| 188 } | 191 } |
| 189 | 192 |
| 190 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 193 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
| 191 gfx::Size surface_size, | 194 gfx::Size surface_size, |
| 192 const gfx::Transform& transform, | 195 const gfx::Transform& transform, |
| 193 gfx::Rect clip) { | 196 gfx::Rect clip) { |
| 194 DCHECK(CalledOnValidThread()); | 197 DCHECK(CalledOnValidThread()); |
| 195 DCHECK(client_); | 198 DCHECK(client_); |
| 196 DCHECK(context3d()); | 199 DCHECK(context3d()); |
| 197 | 200 |
| 198 // Force a GL state restore next time a GLContextVirtual is made current. | 201 // Force a GL state restore next time a GLContextVirtual is made current. |
| 199 // TODO(boliu): Move this to the end of this function after we have fixed | 202 // TODO(boliu): Move this to the end of this function after we have fixed |
| 200 // all cases of MakeCurrent calls outside of draws. Tracked in | 203 // all cases of MakeCurrent calls outside of draws. Tracked in |
| 201 // crbug.com/239856. | 204 // crbug.com/239856. |
| 202 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); | 205 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); |
| 203 if (current_context) | 206 if (current_context) |
| 204 current_context->ReleaseCurrent(NULL); | 207 current_context->ReleaseCurrent(NULL); |
| 205 | 208 |
| 206 did_swap_buffer_ = false; | 209 InvokeComposite(transform, damage_area); |
| 207 | |
| 208 gfx::Transform adjusted_transform = transform; | |
| 209 AdjustTransformForClip(&adjusted_transform, clip); | |
| 210 surface_size_ = surface_size; | |
| 211 client_->SetExternalDrawConstraints(adjusted_transform, clip); | |
| 212 InvokeComposite(clip.size()); | |
| 213 | 210 |
| 214 return did_swap_buffer_; | 211 return did_swap_buffer_; |
| 215 } | 212 } |
| 216 | 213 |
| 217 void SynchronousCompositorOutputSurface::InvokeComposite( | 214 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 218 gfx::Size damage_size) { | 215 const gfx::Transform& transform, |
| 219 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); | 216 gfx::Rect damage_area) { |
| 217 did_swap_buffer_ = false; | |
| 218 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the | |
| 219 // whole view. Tracking bug to implement this: crbug.com/230463. | |
|
joth
2013/06/07 04:02:51
BUG: rebase resolve error.
joth
2013/06/07 04:28:48
fixed in PS5
| |
| 220 client_->SetNeedsRedrawRect(damage_area); | |
| 220 if (needs_begin_frame_) | 221 if (needs_begin_frame_) |
| 221 client_->BeginFrame(base::TimeTicks::Now()); | 222 client_->BeginFrame(base::TimeTicks::Now()); |
| 223 | |
| 224 if (did_swap_buffer_) | |
| 225 client_->OnSwapBuffersComplete(); | |
|
joth
2013/06/07 04:02:05
BUG: I need to call this back async, as per FakeOu
joth
2013/06/07 04:28:48
Actually, not a bug at all. By the point we get he
| |
| 222 } | 226 } |
| 223 | 227 |
| 224 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 228 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 225 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 229 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 226 // thread. | 230 // thread. |
| 227 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 231 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 228 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 232 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 229 } | 233 } |
| 230 | 234 |
| 231 SynchronousCompositorOutputSurfaceDelegate* | 235 SynchronousCompositorOutputSurfaceDelegate* |
| 232 SynchronousCompositorOutputSurface::GetDelegate() { | 236 SynchronousCompositorOutputSurface::GetDelegate() { |
| 233 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 237 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 234 } | 238 } |
| 235 | 239 |
| 236 } // namespace content | 240 } // namespace content |
| OLD | NEW |