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" |
| 11 #include "cc/output/compositor_frame_ack.h" | 11 #include "cc/output/compositor_frame_ack.h" |
| 12 #include "cc/output/context_provider.h" | |
| 12 #include "cc/output/output_surface_client.h" | 13 #include "cc/output/output_surface_client.h" |
| 13 #include "cc/output/software_output_device.h" | 14 #include "cc/output/software_output_device.h" |
| 14 #include "content/browser/android/in_process/synchronous_compositor_impl.h" | 15 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
| 15 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 16 #include "content/public/browser/android/synchronous_compositor_client.h" | 17 #include "content/public/browser/android/synchronous_compositor_client.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 19 #include "skia/ext/refptr.h" | 20 #include "skia/ext/refptr.h" |
| 20 #include "third_party/skia/include/core/SkCanvas.h" | 21 #include "third_party/skia/include/core/SkCanvas.h" |
| 21 #include "third_party/skia/include/core/SkDevice.h" | 22 #include "third_party/skia/include/core/SkDevice.h" |
| 22 #include "third_party/skia/include/core/SkPicture.h" | 23 #include "third_party/skia/include/core/SkPicture.h" |
| 23 #include "ui/gfx/rect_conversions.h" | 24 #include "ui/gfx/rect_conversions.h" |
| 24 #include "ui/gfx/skia_util.h" | 25 #include "ui/gfx/skia_util.h" |
| 25 #include "ui/gfx/transform.h" | 26 #include "ui/gfx/transform.h" |
| 26 #include "ui/gl/gl_context.h" | 27 #include "ui/gl/gl_context.h" |
| 27 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" | 28 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" |
| 28 | 29 |
| 29 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | 30 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // TODO(boliu): RenderThreadImpl should create in process contexts as well. | 36 // TODO(boliu): RenderThreadImpl should create in process contexts as well. |
| 36 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() { | 37 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() { |
| 37 if (!CommandLine::ForCurrentProcess()->HasSwitch("testing-webview-gl-mode")) | |
| 38 return scoped_ptr<WebKit::WebGraphicsContext3D>(); | |
| 39 | |
| 40 WebKit::WebGraphicsContext3D::Attributes attributes; | 38 WebKit::WebGraphicsContext3D::Attributes attributes; |
| 41 attributes.antialias = false; | 39 attributes.antialias = false; |
| 42 attributes.shareResources = true; | 40 attributes.shareResources = true; |
| 43 attributes.noAutomaticFlushes = true; | 41 attributes.noAutomaticFlushes = true; |
| 44 | 42 |
| 45 return scoped_ptr<WebKit::WebGraphicsContext3D>( | 43 return scoped_ptr<WebKit::WebGraphicsContext3D>( |
| 46 WebGraphicsContext3DInProcessCommandBufferImpl | 44 WebGraphicsContext3DInProcessCommandBufferImpl |
| 47 ::CreateViewContext(attributes, NULL)); | 45 ::CreateViewContext(attributes, NULL)); |
| 48 } | 46 } |
| 49 | 47 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 SynchronousCompositorOutputSurface* surface_; | 82 SynchronousCompositorOutputSurface* surface_; |
| 85 SkDevice null_device_; | 83 SkDevice null_device_; |
| 86 SkCanvas null_canvas_; | 84 SkCanvas null_canvas_; |
| 87 | 85 |
| 88 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); | 86 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); |
| 89 }; | 87 }; |
| 90 | 88 |
| 91 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 89 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 92 int routing_id) | 90 int routing_id) |
| 93 : cc::OutputSurface( | 91 : cc::OutputSurface( |
| 94 CreateWebGraphicsContext3D(), | |
| 95 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 92 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
| 96 routing_id_(routing_id), | 93 routing_id_(routing_id), |
| 97 needs_begin_frame_(false), | 94 needs_begin_frame_(false), |
| 98 did_swap_buffer_(false), | 95 did_swap_buffer_(false), |
| 99 current_sw_canvas_(NULL) { | 96 current_sw_canvas_(NULL) { |
| 100 capabilities_.deferred_gl_initialization = true; | 97 capabilities_.deferred_gl_initialization = true; |
| 101 // Cannot call out to GetDelegate() here as the output surface is not | 98 // Cannot call out to GetDelegate() here as the output surface is not |
| 102 // constructed on the correct thread. | 99 // constructed on the correct thread. |
| 103 } | 100 } |
| 104 | 101 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 if (delegate) | 140 if (delegate) |
| 144 delegate->SetContinuousInvalidate(needs_begin_frame_); | 141 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 145 } | 142 } |
| 146 | 143 |
| 147 void SynchronousCompositorOutputSurface::SwapBuffers( | 144 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 148 const ui::LatencyInfo& info) { | 145 const ui::LatencyInfo& info) { |
| 149 context3d()->shallowFlushCHROMIUM(); | 146 context3d()->shallowFlushCHROMIUM(); |
| 150 did_swap_buffer_ = true; | 147 did_swap_buffer_ = true; |
| 151 } | 148 } |
| 152 | 149 |
| 153 bool SynchronousCompositorOutputSurface::IsHwReady() { | |
| 154 return context3d() != NULL; | |
| 155 } | |
| 156 | |
| 157 namespace { | 150 namespace { |
| 158 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { | 151 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { |
| 159 // The system-provided transform translates us from the screen origin to the | 152 // The system-provided transform translates us from the screen origin to the |
| 160 // origin of the clip rect, but CC's draw origin starts at the clip. | 153 // origin of the clip rect, but CC's draw origin starts at the clip. |
| 161 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); | 154 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); |
| 162 } | 155 } |
| 163 } // namespace | 156 } // namespace |
| 164 | 157 |
| 165 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 158 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 166 DCHECK(CalledOnValidThread()); | 159 DCHECK(CalledOnValidThread()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 180 canvas->getDeviceSize().height()); | 173 canvas->getDeviceSize().height()); |
| 181 client_->SetExternalDrawConstraints(transform, clip); | 174 client_->SetExternalDrawConstraints(transform, clip); |
| 182 | 175 |
| 183 InvokeComposite(clip.size()); | 176 InvokeComposite(clip.size()); |
| 184 | 177 |
| 185 bool finished_draw = current_sw_canvas_ == NULL; | 178 bool finished_draw = current_sw_canvas_ == NULL; |
| 186 current_sw_canvas_ = NULL; | 179 current_sw_canvas_ = NULL; |
| 187 return finished_draw; | 180 return finished_draw; |
| 188 } | 181 } |
| 189 | 182 |
| 183 bool SynchronousCompositorOutputSurface::InitializeHwDraw() { | |
| 184 DCHECK(CalledOnValidThread()); | |
| 185 DCHECK(client_); | |
| 186 DCHECK(!context3d_); | |
| 187 | |
| 188 // TODO(boliu): Get a context provider in constructor and pass here. | |
| 189 bool success = | |
| 190 InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(), | |
| 191 scoped_refptr<cc::ContextProvider>()); | |
| 192 if (!success) | |
| 193 client_->DidLoseOutputSurface(); | |
|
joth
2013/06/07 01:08:03
could base class InitializeAndSetContext3D() handl
boliu
2013/06/07 18:46:18
With the new contract in OutputSurface, we can jus
| |
| 194 | |
| 195 return success; | |
| 196 } | |
| 197 | |
| 190 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 198 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
| 191 gfx::Size surface_size, | 199 gfx::Size surface_size, |
| 192 const gfx::Transform& transform, | 200 const gfx::Transform& transform, |
| 193 gfx::Rect clip) { | 201 gfx::Rect clip) { |
| 194 DCHECK(CalledOnValidThread()); | 202 DCHECK(CalledOnValidThread()); |
| 195 DCHECK(client_); | 203 DCHECK(client_); |
| 196 DCHECK(context3d()); | 204 DCHECK(context3d()); |
| 197 | 205 |
| 198 // Force a GL state restore next time a GLContextVirtual is made current. | 206 // 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 | 207 // 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 | 208 // all cases of MakeCurrent calls outside of draws. Tracked in |
| 201 // crbug.com/239856. | 209 // crbug.com/239856. |
| 202 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); | 210 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); |
| 203 if (current_context) | 211 if (current_context) |
| 204 current_context->ReleaseCurrent(NULL); | 212 current_context->ReleaseCurrent(NULL); |
| 205 | 213 |
| 206 did_swap_buffer_ = false; | 214 did_swap_buffer_ = false; |
| 207 | 215 |
| 208 gfx::Transform adjusted_transform = transform; | 216 gfx::Transform adjusted_transform = transform; |
| 209 AdjustTransformForClip(&adjusted_transform, clip); | 217 AdjustTransformForClip(&adjusted_transform, clip); |
| 210 surface_size_ = surface_size; | 218 surface_size_ = surface_size; |
| 211 client_->SetExternalDrawConstraints(adjusted_transform, clip); | 219 client_->SetExternalDrawConstraints(adjusted_transform, clip); |
| 212 InvokeComposite(clip.size()); | 220 InvokeComposite(clip.size()); |
| 213 | 221 |
| 222 // TODO(boliu): Check if context is lost here. | |
| 223 | |
| 214 return did_swap_buffer_; | 224 return did_swap_buffer_; |
| 215 } | 225 } |
| 216 | 226 |
| 217 void SynchronousCompositorOutputSurface::InvokeComposite( | 227 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 218 gfx::Size damage_size) { | 228 gfx::Size damage_size) { |
| 219 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); | 229 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); |
| 220 if (needs_begin_frame_) | 230 if (needs_begin_frame_) |
| 221 client_->BeginFrame(base::TimeTicks::Now()); | 231 client_->BeginFrame(base::TimeTicks::Now()); |
| 222 } | 232 } |
| 223 | 233 |
| 224 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 234 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 225 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 235 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 226 // thread. | 236 // thread. |
| 227 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 237 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 228 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 238 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 229 } | 239 } |
| 230 | 240 |
| 231 SynchronousCompositorOutputSurfaceDelegate* | 241 SynchronousCompositorOutputSurfaceDelegate* |
| 232 SynchronousCompositorOutputSurface::GetDelegate() { | 242 SynchronousCompositorOutputSurface::GetDelegate() { |
| 233 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 243 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 234 } | 244 } |
| 235 | 245 |
| 236 } // namespace content | 246 } // namespace content |
| OLD | NEW |