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/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "cc/output/begin_frame_args.h" | 9 #include "cc/output/begin_frame_args.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
11 #include "cc/output/context_provider.h" | 11 #include "cc/output/context_provider.h" |
12 #include "cc/output/managed_memory_policy.h" | 12 #include "cc/output/managed_memory_policy.h" |
13 #include "cc/output/output_surface_client.h" | 13 #include "cc/output/output_surface_client.h" |
14 #include "cc/output/software_output_device.h" | 14 #include "cc/output/software_output_device.h" |
15 #include "content/browser/android/in_process/synchronous_compositor_impl.h" | 15 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "gpu/command_buffer/client/gl_in_process_context.h" |
18 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
19 #include "third_party/skia/include/core/SkDevice.h" | 20 #include "third_party/skia/include/core/SkDevice.h" |
20 #include "ui/gfx/rect_conversions.h" | 21 #include "ui/gfx/rect_conversions.h" |
21 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
22 #include "ui/gfx/transform.h" | 23 #include "ui/gfx/transform.h" |
23 #include "ui/gl/gl_context.h" | 24 #include "ui/gl/gl_context.h" |
24 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | 25 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" |
25 | 26 |
26 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // TODO(boliu): RenderThreadImpl should create in process contexts as well. | 32 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D( |
33 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() { | 33 scoped_refptr<gfx::GLSurface> surface) { |
| 34 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
| 35 if (!gfx::GLSurface::InitializeOneOff()) |
| 36 scoped_ptr<WebKit::WebGraphicsContext3D>(); |
| 37 |
| 38 // TODO(boliu): Much of this code is copied or adapted from |
| 39 // WebGraphicsContext3DInProcessCommandBufferImpl. Refactor and reduce |
| 40 // code duplication. |
| 41 const bool offscreen = false; |
| 42 const gfx::Size size(1, 1); |
| 43 const char* allowed_extensions = "*"; |
| 44 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 45 |
34 WebKit::WebGraphicsContext3D::Attributes attributes; | 46 WebKit::WebGraphicsContext3D::Attributes attributes; |
35 attributes.antialias = false; | 47 attributes.antialias = false; |
36 attributes.shareResources = true; | 48 attributes.shareResources = true; |
37 attributes.noAutomaticFlushes = true; | 49 attributes.noAutomaticFlushes = true; |
| 50 const int alpha_size = attributes.alpha ? 8 : 0; |
| 51 const int depth_size = attributes.depth ? 24 : 0; |
| 52 const int stencil_size = attributes.stencil ? 8 : 0; |
| 53 const int samples = attributes.antialias ? 4 : 0; |
| 54 const int sample_buffers = attributes.antialias ? 1 : 0; |
| 55 const int32 attribs[] = { |
| 56 gpu::GLInProcessContext::ALPHA_SIZE, alpha_size, |
| 57 gpu::GLInProcessContext::DEPTH_SIZE, depth_size, |
| 58 gpu::GLInProcessContext::STENCIL_SIZE, stencil_size, |
| 59 gpu::GLInProcessContext::SAMPLES, samples, |
| 60 gpu::GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, |
| 61 gpu::GLInProcessContext::NONE, |
| 62 }; |
| 63 |
| 64 scoped_ptr<gpu::GLInProcessContext> context( |
| 65 gpu::GLInProcessContext::CreateWithSurface(surface, |
| 66 offscreen, |
| 67 size, |
| 68 attributes.shareResources, |
| 69 allowed_extensions, |
| 70 attribs, |
| 71 gpu_preference)); |
| 72 |
| 73 if (!context.get()) |
| 74 scoped_ptr<WebKit::WebGraphicsContext3D>(); |
38 | 75 |
39 return scoped_ptr<WebKit::WebGraphicsContext3D>( | 76 return scoped_ptr<WebKit::WebGraphicsContext3D>( |
40 WebGraphicsContext3DInProcessCommandBufferImpl | 77 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( |
41 ::CreateViewContext(attributes, NULL)); | 78 context.Pass(), attributes)); |
42 } | 79 } |
43 | 80 |
44 void DidActivatePendingTree(int routing_id) { | 81 void DidActivatePendingTree(int routing_id) { |
45 SynchronousCompositorOutputSurfaceDelegate* delegate = | 82 SynchronousCompositorOutputSurfaceDelegate* delegate = |
46 SynchronousCompositorImpl::FromRoutingID(routing_id); | 83 SynchronousCompositorImpl::FromRoutingID(routing_id); |
47 if (delegate) | 84 if (delegate) |
48 delegate->DidActivatePendingTree(); | 85 delegate->DidActivatePendingTree(); |
49 } | 86 } |
50 | 87 |
51 } // namespace | 88 } // namespace |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // origin of the clip rect, but CC's draw origin starts at the clip. | 210 // origin of the clip rect, but CC's draw origin starts at the clip. |
174 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); | 211 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); |
175 } | 212 } |
176 } // namespace | 213 } // namespace |
177 | 214 |
178 bool SynchronousCompositorOutputSurface::InitializeHwDraw( | 215 bool SynchronousCompositorOutputSurface::InitializeHwDraw( |
179 scoped_refptr<cc::ContextProvider> offscreen_context) { | 216 scoped_refptr<cc::ContextProvider> offscreen_context) { |
180 DCHECK(CalledOnValidThread()); | 217 DCHECK(CalledOnValidThread()); |
181 DCHECK(HasClient()); | 218 DCHECK(HasClient()); |
182 DCHECK(!context3d_); | 219 DCHECK(!context3d_); |
| 220 DCHECK(!surface_); |
183 | 221 |
184 return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(), | 222 surface_ = new gfx::GLSurfaceStub; |
185 offscreen_context); | 223 bool success = InitializeAndSetContext3D( |
| 224 CreateWebGraphicsContext3D(surface_).Pass(), offscreen_context); |
| 225 if (!success) |
| 226 surface_ = NULL; |
| 227 |
| 228 return success; |
186 } | 229 } |
187 | 230 |
188 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { | 231 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { |
| 232 DCHECK(surface_); |
189 cc::OutputSurface::ReleaseGL(); | 233 cc::OutputSurface::ReleaseGL(); |
| 234 surface_ = NULL; |
190 } | 235 } |
191 | 236 |
192 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 237 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
193 gfx::Size surface_size, | 238 gfx::Size surface_size, |
194 const gfx::Transform& transform, | 239 const gfx::Transform& transform, |
195 gfx::Rect clip, | 240 gfx::Rect clip, |
196 bool stencil_enabled) { | 241 bool stencil_enabled) { |
197 DCHECK(CalledOnValidThread()); | 242 DCHECK(CalledOnValidThread()); |
198 DCHECK(HasClient()); | 243 DCHECK(HasClient()); |
199 DCHECK(context3d()); | 244 DCHECK(context3d()); |
| 245 DCHECK(surface_); |
| 246 |
| 247 surface_->SaveCurrentFBO(); |
200 | 248 |
201 gfx::Transform adjusted_transform = transform; | 249 gfx::Transform adjusted_transform = transform; |
202 AdjustTransformForClip(&adjusted_transform, clip); | 250 AdjustTransformForClip(&adjusted_transform, clip); |
203 surface_size_ = surface_size; | 251 surface_size_ = surface_size; |
204 SetExternalDrawConstraints(adjusted_transform, clip); | 252 SetExternalDrawConstraints(adjusted_transform, clip); |
205 SetExternalStencilTest(stencil_enabled); | 253 SetExternalStencilTest(stencil_enabled); |
206 InvokeComposite(clip.size()); | 254 InvokeComposite(clip.size()); |
207 | 255 |
208 // TODO(boliu): Check if context is lost here. | |
209 | |
210 return did_swap_buffer_; | 256 return did_swap_buffer_; |
211 } | 257 } |
212 | 258 |
213 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 259 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
214 DCHECK(CalledOnValidThread()); | 260 DCHECK(CalledOnValidThread()); |
215 DCHECK(canvas); | 261 DCHECK(canvas); |
216 DCHECK(!current_sw_canvas_); | 262 DCHECK(!current_sw_canvas_); |
217 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 263 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
218 | 264 |
219 SkIRect canvas_clip; | 265 SkIRect canvas_clip; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 304 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
259 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 305 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
260 } | 306 } |
261 | 307 |
262 SynchronousCompositorOutputSurfaceDelegate* | 308 SynchronousCompositorOutputSurfaceDelegate* |
263 SynchronousCompositorOutputSurface::GetDelegate() { | 309 SynchronousCompositorOutputSurface::GetDelegate() { |
264 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 310 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
265 } | 311 } |
266 | 312 |
267 } // namespace content | 313 } // namespace content |
OLD | NEW |