| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/renderer/android/synchronous_compositor_output_surface.h" | 5 #include "content/renderer/android/synchronous_compositor_output_surface.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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 SynchronousCompositorOutputSurface* surface_; | 82 SynchronousCompositorOutputSurface* surface_; |
| 83 SkDevice null_device_; | 83 SkDevice null_device_; |
| 84 SkCanvas null_canvas_; | 84 SkCanvas null_canvas_; |
| 85 | 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); | 86 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 89 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 90 int32 routing_id) | 90 Delegate* delegate) |
| 91 : cc::OutputSurface(CreateWebGraphicsContext3D(), | 91 : cc::OutputSurface( |
| 92 scoped_ptr<cc::SoftwareOutputDevice>( | 92 CreateWebGraphicsContext3D(), |
| 93 new SoftwareDevice(this))), | 93 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
| 94 compositor_client_(NULL), | 94 delegate_(delegate), |
| 95 routing_id_(routing_id), | |
| 96 vsync_enabled_(false), | 95 vsync_enabled_(false), |
| 97 did_swap_buffer_(false), | 96 did_swap_buffer_(false), |
| 98 current_sw_canvas_(NULL) { | 97 current_sw_canvas_(NULL) {} |
| 99 } | |
| 100 | 98 |
| 101 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 99 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
| 102 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
| 103 if (compositor_client_) | 101 delegate_->DidDestroyCompositor(); |
| 104 compositor_client_->DidDestroyCompositor(this); | |
| 105 } | 102 } |
| 106 | 103 |
| 107 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { | 104 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { |
| 108 return current_sw_canvas_ != NULL; | 105 return current_sw_canvas_ != NULL; |
| 109 } | 106 } |
| 110 | 107 |
| 111 bool SynchronousCompositorOutputSurface::BindToClient( | 108 bool SynchronousCompositorOutputSurface::BindToClient( |
| 112 cc::OutputSurfaceClient* surface_client) { | 109 cc::OutputSurfaceClient* surface_client) { |
| 113 DCHECK(CalledOnValidThread()); | 110 DCHECK(CalledOnValidThread()); |
| 114 if (!cc::OutputSurface::BindToClient(surface_client)) | 111 if (!cc::OutputSurface::BindToClient(surface_client)) |
| 115 return false; | 112 return false; |
| 116 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_, | 113 delegate_->DidCreateSynchronousCompositor(); |
| 117 this); | |
| 118 return true; | 114 return true; |
| 119 } | 115 } |
| 120 | 116 |
| 121 void SynchronousCompositorOutputSurface::Reshape(gfx::Size size) { | 117 void SynchronousCompositorOutputSurface::Reshape(gfx::Size size) { |
| 122 // Intentional no-op: surface size is controlled by the embedder. | 118 // Intentional no-op: surface size is controlled by the embedder. |
| 123 } | 119 } |
| 124 | 120 |
| 125 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( | 121 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( |
| 126 cc::CompositorFrame* frame) { | 122 cc::CompositorFrame* frame) { |
| 127 NOTREACHED(); | 123 NOTREACHED(); |
| 128 // TODO(joth): Route page scale to the client, see http://crbug.com/237006 | 124 // TODO(joth): Route page scale to the client, see http://crbug.com/237006 |
| 129 } | 125 } |
| 130 | 126 |
| 131 void SynchronousCompositorOutputSurface::EnableVSyncNotification( | 127 void SynchronousCompositorOutputSurface::EnableVSyncNotification( |
| 132 bool enable_vsync) { | 128 bool enable_vsync) { |
| 133 DCHECK(CalledOnValidThread()); | 129 DCHECK(CalledOnValidThread()); |
| 134 vsync_enabled_ = enable_vsync; | 130 vsync_enabled_ = enable_vsync; |
| 135 UpdateCompositorClientSettings(); | 131 delegate_->SetContinuousInvalidate(enable_vsync); |
| 136 } | 132 } |
| 137 | 133 |
| 138 void SynchronousCompositorOutputSurface::SwapBuffers( | 134 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 139 const cc::LatencyInfo& info) { | 135 const cc::LatencyInfo& info) { |
| 140 context3d()->finish(); | 136 context3d()->finish(); |
| 141 did_swap_buffer_ = true; | 137 did_swap_buffer_ = true; |
| 142 } | 138 } |
| 143 | 139 |
| 144 void SynchronousCompositorOutputSurface::SetClient( | |
| 145 SynchronousCompositorClient* compositor_client) { | |
| 146 DCHECK(CalledOnValidThread()); | |
| 147 compositor_client_ = compositor_client; | |
| 148 UpdateCompositorClientSettings(); | |
| 149 } | |
| 150 | |
| 151 bool SynchronousCompositorOutputSurface::IsHwReady() { | 140 bool SynchronousCompositorOutputSurface::IsHwReady() { |
| 152 return context3d() != NULL; | 141 return context3d() != NULL; |
| 153 } | 142 } |
| 154 | 143 |
| 155 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 144 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 156 DCHECK(CalledOnValidThread()); | 145 DCHECK(CalledOnValidThread()); |
| 157 DCHECK(canvas); | 146 DCHECK(canvas); |
| 158 DCHECK(!current_sw_canvas_); | 147 DCHECK(!current_sw_canvas_); |
| 159 current_sw_canvas_ = canvas; | 148 current_sw_canvas_ = canvas; |
| 160 | 149 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 void SynchronousCompositorOutputSurface::InvokeComposite( | 182 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 194 const gfx::Transform& transform, | 183 const gfx::Transform& transform, |
| 195 gfx::Rect damage_area) { | 184 gfx::Rect damage_area) { |
| 196 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the | 185 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the |
| 197 // whole view. Tracking bug to implement this: crbug.com/230463. | 186 // whole view. Tracking bug to implement this: crbug.com/230463. |
| 198 client_->SetNeedsRedrawRect(damage_area); | 187 client_->SetNeedsRedrawRect(damage_area); |
| 199 if (vsync_enabled_) | 188 if (vsync_enabled_) |
| 200 client_->DidVSync(base::TimeTicks::Now()); | 189 client_->DidVSync(base::TimeTicks::Now()); |
| 201 } | 190 } |
| 202 | 191 |
| 203 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() { | |
| 204 if (compositor_client_) { | |
| 205 compositor_client_->SetContinuousInvalidate(vsync_enabled_); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 192 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 210 // requirement: SynchronousCompositorOutputSurface() must only be used by | 193 // requirement: SynchronousCompositorOutputSurface() must only be used by |
| 211 // embedders that supply their own compositor loop via | 194 // embedders that supply their own compositor loop via |
| 212 // OverrideCompositorMessageLoop(). | 195 // OverrideCompositorMessageLoop(). |
| 213 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 196 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 214 return base::MessageLoop::current() && (base::MessageLoop::current() == | 197 return base::MessageLoop::current() && (base::MessageLoop::current() == |
| 215 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); | 198 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); |
| 216 } | 199 } |
| 217 | 200 |
| 218 } // namespace content | 201 } // namespace content |
| OLD | NEW |