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_surface.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 and adapted from | |
boliu
2013/08/06 23:38:21
Umm, maybe make GLInProcessContext take a struct o
| |
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 | 206 |
170 namespace { | 207 namespace { |
171 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { | 208 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { |
172 // The system-provided transform translates us from the screen origin to the | 209 // The system-provided transform translates us from the screen origin to the |
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( |
216 scoped_refptr<gfx::GLSurface> surface, | |
179 scoped_refptr<cc::ContextProvider> offscreen_context) { | 217 scoped_refptr<cc::ContextProvider> offscreen_context) { |
180 DCHECK(CalledOnValidThread()); | 218 DCHECK(CalledOnValidThread()); |
181 DCHECK(HasClient()); | 219 DCHECK(HasClient()); |
182 DCHECK(!context3d_); | 220 DCHECK(!context3d_); |
221 DCHECK(surface); | |
183 | 222 |
184 return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(), | 223 return InitializeAndSetContext3D( |
185 offscreen_context); | 224 CreateWebGraphicsContext3D(surface).Pass(), offscreen_context); |
186 } | 225 } |
187 | 226 |
188 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { | 227 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { |
189 cc::OutputSurface::ReleaseGL(); | 228 cc::OutputSurface::ReleaseGL(); |
190 } | 229 } |
191 | 230 |
192 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 231 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
193 gfx::Size surface_size, | 232 gfx::Size surface_size, |
194 const gfx::Transform& transform, | 233 const gfx::Transform& transform, |
195 gfx::Rect clip, | 234 gfx::Rect clip, |
196 bool stencil_enabled) { | 235 bool stencil_enabled) { |
197 DCHECK(CalledOnValidThread()); | 236 DCHECK(CalledOnValidThread()); |
198 DCHECK(HasClient()); | 237 DCHECK(HasClient()); |
199 DCHECK(context3d()); | 238 DCHECK(context3d()); |
200 | 239 |
201 gfx::Transform adjusted_transform = transform; | 240 gfx::Transform adjusted_transform = transform; |
202 AdjustTransformForClip(&adjusted_transform, clip); | 241 AdjustTransformForClip(&adjusted_transform, clip); |
203 surface_size_ = surface_size; | 242 surface_size_ = surface_size; |
204 SetExternalDrawConstraints(adjusted_transform, clip); | 243 SetExternalDrawConstraints(adjusted_transform, clip); |
205 SetExternalStencilTest(stencil_enabled); | 244 SetExternalStencilTest(stencil_enabled); |
206 InvokeComposite(clip.size()); | 245 InvokeComposite(clip.size()); |
207 | 246 |
208 // TODO(boliu): Check if context is lost here. | |
209 | |
210 return did_swap_buffer_; | 247 return did_swap_buffer_; |
211 } | 248 } |
212 | 249 |
213 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 250 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
214 DCHECK(CalledOnValidThread()); | 251 DCHECK(CalledOnValidThread()); |
215 DCHECK(canvas); | 252 DCHECK(canvas); |
216 DCHECK(!current_sw_canvas_); | 253 DCHECK(!current_sw_canvas_); |
217 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 254 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
218 | 255 |
219 SkIRect canvas_clip; | 256 SkIRect canvas_clip; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 295 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
259 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 296 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
260 } | 297 } |
261 | 298 |
262 SynchronousCompositorOutputSurfaceDelegate* | 299 SynchronousCompositorOutputSurfaceDelegate* |
263 SynchronousCompositorOutputSurface::GetDelegate() { | 300 SynchronousCompositorOutputSurface::GetDelegate() { |
264 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 301 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
265 } | 302 } |
266 | 303 |
267 } // namespace content | 304 } // namespace content |
OLD | NEW |