| 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/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" |
| 11 #include "cc/output/compositor_frame_ack.h" | 11 #include "cc/output/compositor_frame_ack.h" |
| 12 #include "cc/output/output_surface_client.h" | 12 #include "cc/output/output_surface_client.h" |
| 13 #include "cc/output/software_output_device.h" | 13 #include "cc/output/software_output_device.h" |
| 14 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
| 14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 15 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 16 #include "content/public/renderer/android/synchronous_compositor_client.h" | 18 #include "content/public/renderer/android/synchronous_compositor_client.h" |
| 17 #include "content/public/renderer/content_renderer_client.h" | |
| 18 #include "skia/ext/refptr.h" | 19 #include "skia/ext/refptr.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "third_party/skia/include/core/SkDevice.h" | 21 #include "third_party/skia/include/core/SkDevice.h" |
| 21 #include "third_party/skia/include/core/SkPicture.h" | 22 #include "third_party/skia/include/core/SkPicture.h" |
| 22 #include "ui/gfx/rect_conversions.h" | 23 #include "ui/gfx/rect_conversions.h" |
| 23 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| 24 #include "ui/gfx/transform.h" | 25 #include "ui/gfx/transform.h" |
| 25 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | 26 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" |
| 26 | 27 |
| 27 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | 28 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 81 |
| 81 private: | 82 private: |
| 82 SynchronousCompositorOutputSurface* surface_; | 83 SynchronousCompositorOutputSurface* surface_; |
| 83 SkDevice null_device_; | 84 SkDevice null_device_; |
| 84 SkCanvas null_canvas_; | 85 SkCanvas null_canvas_; |
| 85 | 86 |
| 86 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); | 87 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 90 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 90 int32 routing_id) | 91 int routing_id) |
| 91 : cc::OutputSurface(CreateWebGraphicsContext3D(), | 92 : cc::OutputSurface( |
| 92 scoped_ptr<cc::SoftwareOutputDevice>( | 93 CreateWebGraphicsContext3D(), |
| 93 new SoftwareDevice(this))), | 94 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
| 94 compositor_client_(NULL), | |
| 95 routing_id_(routing_id), | 95 routing_id_(routing_id), |
| 96 needs_begin_frame_(false), | 96 needs_begin_frame_(false), |
| 97 did_swap_buffer_(false), | 97 did_swap_buffer_(false), |
| 98 current_sw_canvas_(NULL) { | 98 current_sw_canvas_(NULL) { |
| 99 capabilities_.deferred_gl_initialization = true; | 99 capabilities_.deferred_gl_initialization = true; |
| 100 // Cannot call out to GetDelegate() here as the output surface is not |
| 101 // constructed on the correct thread. |
| 100 } | 102 } |
| 101 | 103 |
| 102 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 104 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
| 103 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
| 104 if (compositor_client_) | 106 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 105 compositor_client_->DidDestroyCompositor(this); | 107 if (delegate) |
| 108 delegate->DidDestroySynchronousOutputSurface(this); |
| 106 } | 109 } |
| 107 | 110 |
| 108 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { | 111 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { |
| 109 return current_sw_canvas_ != NULL; | 112 return current_sw_canvas_ != NULL; |
| 110 } | 113 } |
| 111 | 114 |
| 112 bool SynchronousCompositorOutputSurface::BindToClient( | 115 bool SynchronousCompositorOutputSurface::BindToClient( |
| 113 cc::OutputSurfaceClient* surface_client) { | 116 cc::OutputSurfaceClient* surface_client) { |
| 114 DCHECK(CalledOnValidThread()); | 117 DCHECK(CalledOnValidThread()); |
| 115 if (!cc::OutputSurface::BindToClient(surface_client)) | 118 if (!cc::OutputSurface::BindToClient(surface_client)) |
| 116 return false; | 119 return false; |
| 117 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_, | 120 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 118 this); | 121 if (delegate) |
| 122 delegate->DidBindOutputSurface(this); |
| 119 return true; | 123 return true; |
| 120 } | 124 } |
| 121 | 125 |
| 122 void SynchronousCompositorOutputSurface::Reshape( | 126 void SynchronousCompositorOutputSurface::Reshape( |
| 123 gfx::Size size, float scale_factor) { | 127 gfx::Size size, float scale_factor) { |
| 124 // Intentional no-op: surface size is controlled by the embedder. | 128 // Intentional no-op: surface size is controlled by the embedder. |
| 125 } | 129 } |
| 126 | 130 |
| 127 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( | 131 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( |
| 128 cc::CompositorFrame* frame) { | 132 cc::CompositorFrame* frame) { |
| 129 NOTREACHED(); | 133 NOTREACHED(); |
| 130 // TODO(joth): Route page scale to the client, see http://crbug.com/237006 | 134 // TODO(joth): Route page scale to the client, see http://crbug.com/237006 |
| 131 } | 135 } |
| 132 | 136 |
| 133 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( | 137 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( |
| 134 bool enable) { | 138 bool enable) { |
| 135 DCHECK(CalledOnValidThread()); | 139 DCHECK(CalledOnValidThread()); |
| 136 needs_begin_frame_ = enable; | 140 needs_begin_frame_ = enable; |
| 137 UpdateCompositorClientSettings(); | 141 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 142 if (delegate) |
| 143 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 138 } | 144 } |
| 139 | 145 |
| 140 void SynchronousCompositorOutputSurface::SwapBuffers( | 146 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 141 const ui::LatencyInfo& info) { | 147 const ui::LatencyInfo& info) { |
| 142 context3d()->shallowFlushCHROMIUM(); | 148 context3d()->shallowFlushCHROMIUM(); |
| 143 did_swap_buffer_ = true; | 149 did_swap_buffer_ = true; |
| 144 } | 150 } |
| 145 | 151 |
| 146 void SynchronousCompositorOutputSurface::SetClient( | |
| 147 SynchronousCompositorClient* compositor_client) { | |
| 148 DCHECK(CalledOnValidThread()); | |
| 149 compositor_client_ = compositor_client; | |
| 150 UpdateCompositorClientSettings(); | |
| 151 } | |
| 152 | |
| 153 bool SynchronousCompositorOutputSurface::IsHwReady() { | 152 bool SynchronousCompositorOutputSurface::IsHwReady() { |
| 154 return context3d() != NULL; | 153 return context3d() != NULL; |
| 155 } | 154 } |
| 156 | 155 |
| 157 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 156 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 158 DCHECK(CalledOnValidThread()); | 157 DCHECK(CalledOnValidThread()); |
| 159 DCHECK(canvas); | 158 DCHECK(canvas); |
| 160 DCHECK(!current_sw_canvas_); | 159 DCHECK(!current_sw_canvas_); |
| 161 current_sw_canvas_ = canvas; | 160 current_sw_canvas_ = canvas; |
| 162 | 161 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 void SynchronousCompositorOutputSurface::InvokeComposite( | 194 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 196 const gfx::Transform& transform, | 195 const gfx::Transform& transform, |
| 197 gfx::Rect damage_area) { | 196 gfx::Rect damage_area) { |
| 198 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the | 197 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the |
| 199 // whole view. Tracking bug to implement this: crbug.com/230463. | 198 // whole view. Tracking bug to implement this: crbug.com/230463. |
| 200 client_->SetNeedsRedrawRect(damage_area); | 199 client_->SetNeedsRedrawRect(damage_area); |
| 201 if (needs_begin_frame_) | 200 if (needs_begin_frame_) |
| 202 client_->BeginFrame(base::TimeTicks::Now()); | 201 client_->BeginFrame(base::TimeTicks::Now()); |
| 203 } | 202 } |
| 204 | 203 |
| 205 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() { | 204 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 206 if (compositor_client_) { | 205 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 207 compositor_client_->SetContinuousInvalidate(needs_begin_frame_); | 206 // thread. |
| 208 } | 207 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 208 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 209 } | 209 } |
| 210 | 210 |
| 211 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 211 SynchronousCompositorOutputSurfaceDelegate* |
| 212 // requirement: SynchronousCompositorOutputSurface() must only be used by | 212 SynchronousCompositorOutputSurface::GetDelegate() { |
| 213 // embedders that supply their own compositor loop via | 213 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 214 // OverrideCompositorMessageLoop(). | |
| 215 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | |
| 216 return base::MessageLoop::current() && (base::MessageLoop::current() == | |
| 217 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); | |
| 218 } | 214 } |
| 219 | 215 |
| 220 } // namespace content | 216 } // namespace content |
| OLD | NEW |