| 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 SynchronousCompositorOutputSurfaceDelegate* 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 needs_begin_frame_(false), | 95 needs_begin_frame_(false), |
| 97 did_swap_buffer_(false), | 96 did_swap_buffer_(false), |
| 98 current_sw_canvas_(NULL) { | 97 current_sw_canvas_(NULL) { |
| 99 capabilities_.deferred_gl_initialization = true; | 98 capabilities_.deferred_gl_initialization = true; |
| 100 } | 99 } |
| 101 | 100 |
| 102 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 101 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
| 103 DCHECK(CalledOnValidThread()); | 102 DCHECK(CalledOnValidThread()); |
| 104 if (compositor_client_) | 103 delegate_->DidDestroyCompositor(); |
| 105 compositor_client_->DidDestroyCompositor(this); | |
| 106 } | 104 } |
| 107 | 105 |
| 108 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { | 106 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { |
| 109 return current_sw_canvas_ != NULL; | 107 return current_sw_canvas_ != NULL; |
| 110 } | 108 } |
| 111 | 109 |
| 112 bool SynchronousCompositorOutputSurface::BindToClient( | 110 bool SynchronousCompositorOutputSurface::BindToClient( |
| 113 cc::OutputSurfaceClient* surface_client) { | 111 cc::OutputSurfaceClient* surface_client) { |
| 114 DCHECK(CalledOnValidThread()); | 112 DCHECK(CalledOnValidThread()); |
| 115 if (!cc::OutputSurface::BindToClient(surface_client)) | 113 if (!cc::OutputSurface::BindToClient(surface_client)) |
| 116 return false; | 114 return false; |
| 117 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_, | 115 delegate_->DidCreateSynchronousCompositor(); |
| 118 this); | |
| 119 return true; | 116 return true; |
| 120 } | 117 } |
| 121 | 118 |
| 122 void SynchronousCompositorOutputSurface::Reshape(gfx::Size size) { | 119 void SynchronousCompositorOutputSurface::Reshape(gfx::Size size) { |
| 123 // Intentional no-op: surface size is controlled by the embedder. | 120 // Intentional no-op: surface size is controlled by the embedder. |
| 124 } | 121 } |
| 125 | 122 |
| 126 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( | 123 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( |
| 127 cc::CompositorFrame* frame) { | 124 cc::CompositorFrame* frame) { |
| 128 NOTREACHED(); | 125 NOTREACHED(); |
| 129 // TODO(joth): Route page scale to the client, see http://crbug.com/237006 | 126 // TODO(joth): Route page scale to the client, see http://crbug.com/237006 |
| 130 } | 127 } |
| 131 | 128 |
| 132 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( | 129 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( |
| 133 bool enable) { | 130 bool enable) { |
| 134 DCHECK(CalledOnValidThread()); | 131 DCHECK(CalledOnValidThread()); |
| 135 needs_begin_frame_ = enable; | 132 needs_begin_frame_ = enable; |
| 136 UpdateCompositorClientSettings(); | 133 delegate_->SetContinuousInvalidate(needs_begin_frame_); |
| 137 } | 134 } |
| 138 | 135 |
| 139 void SynchronousCompositorOutputSurface::SwapBuffers( | 136 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 140 const cc::LatencyInfo& info) { | 137 const cc::LatencyInfo& info) { |
| 141 context3d()->shallowFlushCHROMIUM(); | 138 context3d()->shallowFlushCHROMIUM(); |
| 142 did_swap_buffer_ = true; | 139 did_swap_buffer_ = true; |
| 143 } | 140 } |
| 144 | 141 |
| 145 void SynchronousCompositorOutputSurface::SetClient( | |
| 146 SynchronousCompositorClient* compositor_client) { | |
| 147 DCHECK(CalledOnValidThread()); | |
| 148 compositor_client_ = compositor_client; | |
| 149 UpdateCompositorClientSettings(); | |
| 150 } | |
| 151 | |
| 152 bool SynchronousCompositorOutputSurface::IsHwReady() { | 142 bool SynchronousCompositorOutputSurface::IsHwReady() { |
| 153 return context3d() != NULL; | 143 return context3d() != NULL; |
| 154 } | 144 } |
| 155 | 145 |
| 156 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 146 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 157 DCHECK(CalledOnValidThread()); | 147 DCHECK(CalledOnValidThread()); |
| 158 DCHECK(canvas); | 148 DCHECK(canvas); |
| 159 DCHECK(!current_sw_canvas_); | 149 DCHECK(!current_sw_canvas_); |
| 160 current_sw_canvas_ = canvas; | 150 current_sw_canvas_ = canvas; |
| 161 | 151 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 void SynchronousCompositorOutputSurface::InvokeComposite( | 184 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 195 const gfx::Transform& transform, | 185 const gfx::Transform& transform, |
| 196 gfx::Rect damage_area) { | 186 gfx::Rect damage_area) { |
| 197 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the | 187 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the |
| 198 // whole view. Tracking bug to implement this: crbug.com/230463. | 188 // whole view. Tracking bug to implement this: crbug.com/230463. |
| 199 client_->SetNeedsRedrawRect(damage_area); | 189 client_->SetNeedsRedrawRect(damage_area); |
| 200 if (needs_begin_frame_) | 190 if (needs_begin_frame_) |
| 201 client_->BeginFrame(base::TimeTicks::Now()); | 191 client_->BeginFrame(base::TimeTicks::Now()); |
| 202 } | 192 } |
| 203 | 193 |
| 204 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() { | |
| 205 if (compositor_client_) { | |
| 206 compositor_client_->SetContinuousInvalidate(needs_begin_frame_); | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 194 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 211 // requirement: SynchronousCompositorOutputSurface() must only be used by | 195 // requirement: SynchronousCompositorOutputSurface() must only be used by |
| 212 // embedders that supply their own compositor loop via | 196 // embedders that supply their own compositor loop via |
| 213 // OverrideCompositorMessageLoop(). | 197 // OverrideCompositorMessageLoop(). |
| 214 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 198 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 215 return base::MessageLoop::current() && (base::MessageLoop::current() == | 199 return base::MessageLoop::current() && (base::MessageLoop::current() == |
| 216 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); | 200 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); |
| 217 } | 201 } |
| 218 | 202 |
| 219 } // namespace content | 203 } // namespace content |
| OLD | NEW |