OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "content/common/gpu/image_transport_surface_linux.h" | 7 #include "content/common/gpu/image_transport_surface_linux.h" |
8 | 8 |
9 // This conflicts with the defines in Xlib.h and must come first. | 9 // This conflicts with the defines in Xlib.h and must come first. |
10 #include "content/common/gpu/gpu_messages.h" | 10 #include "content/common/gpu/gpu_messages.h" |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <X11/Xlib.h> | 13 #include <X11/Xlib.h> |
14 #include <X11/extensions/Xcomposite.h> | 14 #include <X11/extensions/Xcomposite.h> |
15 | 15 |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "content/common/gpu/gpu_channel.h" | 17 #include "content/common/gpu/gpu_channel.h" |
18 #include "content/common/gpu/gpu_channel_manager.h" | 18 #include "content/common/gpu/gpu_channel_manager.h" |
19 #include "content/common/gpu/gpu_command_buffer_stub.h" | 19 #include "content/common/gpu/gpu_command_buffer_stub.h" |
20 #include "gpu/command_buffer/service/gpu_scheduler.h" | 20 #include "gpu/command_buffer/service/gpu_scheduler.h" |
21 #include "third_party/angle/include/EGL/egl.h" | 21 #include "third_party/angle/include/EGL/egl.h" |
22 #include "third_party/angle/include/EGL/eglext.h" | 22 #include "third_party/angle/include/EGL/eglext.h" |
23 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" | |
23 #include "ui/gfx/gl/gl_context.h" | 24 #include "ui/gfx/gl/gl_context.h" |
24 #include "ui/gfx/gl/gl_bindings.h" | 25 #include "ui/gfx/gl/gl_bindings.h" |
25 #include "ui/gfx/gl/gl_implementation.h" | 26 #include "ui/gfx/gl/gl_implementation.h" |
26 #include "ui/gfx/gl/gl_surface_egl.h" | 27 #include "ui/gfx/gl/gl_surface_egl.h" |
27 #include "ui/gfx/gl/gl_surface_glx.h" | 28 #include "ui/gfx/gl/gl_surface_glx.h" |
29 #include "ui/gfx/gl/gl_surface_osmesa.h" | |
28 #include "ui/gfx/surface/accelerated_surface_linux.h" | 30 #include "ui/gfx/surface/accelerated_surface_linux.h" |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 // We are backed by an Pbuffer offscreen surface for the purposes of creating a | 34 // We are backed by an Pbuffer offscreen surface for the purposes of creating a |
33 // context, but use FBOs to render to X Pixmap backed EGLImages. | 35 // context, but use FBOs to render to X Pixmap backed EGLImages. |
34 class EGLImageTransportSurface : public ImageTransportSurface, | 36 class EGLImageTransportSurface : public ImageTransportSurface, |
35 public gfx::PbufferGLSurfaceEGL { | 37 public gfx::PbufferGLSurfaceEGL { |
36 public: | 38 public: |
37 EGLImageTransportSurface(GpuChannelManager* manager, | 39 EGLImageTransportSurface(GpuChannelManager* manager, |
38 int32 render_view_id, | 40 int32 render_view_id, |
39 int32 renderer_id, | 41 int32 renderer_id, |
40 int32 command_buffer_id); | 42 int32 command_buffer_id); |
41 | 43 |
42 // GLSurface implementation | 44 // GLSurface implementation |
43 virtual bool Initialize() OVERRIDE; | 45 virtual bool Initialize() OVERRIDE; |
44 virtual void Destroy() OVERRIDE; | 46 virtual void Destroy() OVERRIDE; |
45 virtual bool IsOffscreen() OVERRIDE; | 47 virtual bool IsOffscreen() OVERRIDE; |
46 virtual bool SwapBuffers() OVERRIDE; | 48 virtual bool SwapBuffers() OVERRIDE; |
47 virtual gfx::Size GetSize() OVERRIDE; | 49 virtual gfx::Size GetSize() OVERRIDE; |
48 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 50 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
49 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 51 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
50 | 52 |
51 protected: | 53 protected: |
52 // ImageTransportSurface implementation | 54 // ImageTransportSurface implementation |
53 virtual void OnSetSurfaceACK(uint64 surface_id) OVERRIDE; | 55 virtual void OnNewSurfaceACK( |
56 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | |
54 virtual void OnBuffersSwappedACK() OVERRIDE; | 57 virtual void OnBuffersSwappedACK() OVERRIDE; |
55 virtual void OnResize(gfx::Size size) OVERRIDE; | 58 virtual void OnResize(gfx::Size size) OVERRIDE; |
56 | 59 |
57 private: | 60 private: |
58 virtual ~EGLImageTransportSurface() OVERRIDE; | 61 virtual ~EGLImageTransportSurface() OVERRIDE; |
59 void ReleaseSurface(scoped_refptr<AcceleratedSurface>* surface); | 62 void ReleaseSurface(scoped_refptr<AcceleratedSurface>* surface); |
60 | 63 |
61 uint32 fbo_id_; | 64 uint32 fbo_id_; |
62 | 65 |
63 scoped_refptr<AcceleratedSurface> back_surface_; | 66 scoped_refptr<AcceleratedSurface> back_surface_; |
64 scoped_refptr<AcceleratedSurface> front_surface_; | 67 scoped_refptr<AcceleratedSurface> front_surface_; |
65 | 68 |
66 scoped_ptr<ImageTransportHelper> helper_; | 69 scoped_ptr<ImageTransportHelper> helper_; |
67 | 70 |
68 DISALLOW_COPY_AND_ASSIGN(EGLImageTransportSurface); | 71 DISALLOW_COPY_AND_ASSIGN(EGLImageTransportSurface); |
69 }; | 72 }; |
70 | 73 |
71 // We are backed by an Pbuffer offscreen surface for the purposes of creating a | 74 // We render to an off-screen (but mapped) window that the browser process will |
72 // context, but use FBOs to render to X Pixmap backed EGLImages. | 75 // read from via XComposite |
jonathan.backer
2011/09/21 20:27:36
Thanks.
| |
73 class GLXImageTransportSurface : public ImageTransportSurface, | 76 class GLXImageTransportSurface : public ImageTransportSurface, |
74 public gfx::NativeViewGLSurfaceGLX { | 77 public gfx::NativeViewGLSurfaceGLX { |
75 public: | 78 public: |
76 GLXImageTransportSurface(GpuChannelManager* manager, | 79 GLXImageTransportSurface(GpuChannelManager* manager, |
77 int32 render_view_id, | 80 int32 render_view_id, |
78 int32 renderer_id, | 81 int32 renderer_id, |
79 int32 command_buffer_id); | 82 int32 command_buffer_id); |
80 | 83 |
81 // gfx::GLSurface implementation: | 84 // gfx::GLSurface implementation: |
82 virtual bool Initialize() OVERRIDE; | 85 virtual bool Initialize() OVERRIDE; |
83 virtual void Destroy() OVERRIDE; | 86 virtual void Destroy() OVERRIDE; |
84 virtual bool SwapBuffers() OVERRIDE; | 87 virtual bool SwapBuffers() OVERRIDE; |
85 virtual gfx::Size GetSize() OVERRIDE; | 88 virtual gfx::Size GetSize() OVERRIDE; |
86 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 89 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
87 | 90 |
88 protected: | 91 protected: |
89 // ImageTransportSurface implementation: | 92 // ImageTransportSurface implementation: |
90 void OnSetSurfaceACK(uint64 surface_id) OVERRIDE; | 93 virtual void OnNewSurfaceACK( |
91 void OnBuffersSwappedACK() OVERRIDE; | 94 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
92 void OnResize(gfx::Size size) OVERRIDE; | 95 virtual void OnBuffersSwappedACK() OVERRIDE; |
96 virtual void OnResize(gfx::Size size) OVERRIDE; | |
93 | 97 |
94 private: | 98 private: |
95 virtual ~GLXImageTransportSurface(); | 99 virtual ~GLXImageTransportSurface(); |
96 | 100 |
97 // Tell the browser to release the surface. | 101 // Tell the browser to release the surface. |
98 void ReleaseSurface(); | 102 void ReleaseSurface(); |
99 | 103 |
100 XID dummy_parent_; | 104 XID dummy_parent_; |
101 gfx::Size size_; | 105 gfx::Size size_; |
102 | 106 |
103 // Whether or not the image has been bound on the browser side. | 107 // Whether or not the image has been bound on the browser side. |
104 bool bound_; | 108 bool bound_; |
105 | 109 |
106 // Whether or not we've set the swap interval on the associated context. | 110 // Whether or not we've set the swap interval on the associated context. |
107 bool swap_interval_set_; | 111 bool swap_interval_set_; |
108 | 112 |
109 scoped_ptr<ImageTransportHelper> helper_; | 113 scoped_ptr<ImageTransportHelper> helper_; |
110 | 114 |
111 DISALLOW_COPY_AND_ASSIGN(GLXImageTransportSurface); | 115 DISALLOW_COPY_AND_ASSIGN(GLXImageTransportSurface); |
112 }; | 116 }; |
113 | 117 |
118 // We render to a hunk of shared memory that we get from the browser. | |
119 // Swapping buffers simply means telling the browser to read the contents | |
120 // of the memory. | |
121 class OSMesaImageTransportSurface : public ImageTransportSurface, | |
122 public gfx::GLSurfaceOSMesa { | |
123 public: | |
124 OSMesaImageTransportSurface(GpuChannelManager* manager, | |
125 int32 render_view_id, | |
126 int32 renderer_id, | |
127 int32 command_buffer_id); | |
128 | |
129 // gfx::GLSurface implementation: | |
130 virtual bool Initialize() OVERRIDE; | |
131 virtual void Destroy() OVERRIDE; | |
132 virtual bool IsOffscreen() OVERRIDE; | |
133 virtual bool SwapBuffers() OVERRIDE; | |
134 virtual gfx::Size GetSize() OVERRIDE; | |
135 virtual void* GetHandle() OVERRIDE; | |
136 | |
137 protected: | |
138 // ImageTransportSurface implementation: | |
139 virtual void OnNewSurfaceACK( | |
140 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | |
141 virtual void OnBuffersSwappedACK() OVERRIDE; | |
142 virtual void OnResize(gfx::Size size) OVERRIDE; | |
143 | |
144 private: | |
145 virtual ~OSMesaImageTransportSurface(); | |
146 | |
147 // Tell the browser to release the surface. | |
148 void ReleaseSurface(); | |
149 | |
150 scoped_ptr<TransportDIB> shared_mem_; | |
151 uint32 shared_id_; | |
152 gfx::Size size_; | |
153 | |
154 scoped_ptr<ImageTransportHelper> helper_; | |
155 | |
156 DISALLOW_COPY_AND_ASSIGN(OSMesaImageTransportSurface); | |
157 }; | |
158 | |
114 EGLImageTransportSurface::EGLImageTransportSurface( | 159 EGLImageTransportSurface::EGLImageTransportSurface( |
115 GpuChannelManager* manager, | 160 GpuChannelManager* manager, |
116 int32 render_view_id, | 161 int32 render_view_id, |
117 int32 renderer_id, | 162 int32 renderer_id, |
118 int32 command_buffer_id) | 163 int32 command_buffer_id) |
119 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1)), | 164 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1)), |
120 fbo_id_(0) { | 165 fbo_id_(0) { |
121 helper_.reset(new ImageTransportHelper(this, | 166 helper_.reset(new ImageTransportHelper(this, |
122 manager, | 167 manager, |
123 render_view_id, | 168 render_view_id, |
(...skipping 14 matching lines...) Expand all Loading... | |
138 void EGLImageTransportSurface::Destroy() { | 183 void EGLImageTransportSurface::Destroy() { |
139 if (back_surface_.get()) | 184 if (back_surface_.get()) |
140 ReleaseSurface(&back_surface_); | 185 ReleaseSurface(&back_surface_); |
141 if (front_surface_.get()) | 186 if (front_surface_.get()) |
142 ReleaseSurface(&front_surface_); | 187 ReleaseSurface(&front_surface_); |
143 | 188 |
144 helper_->Destroy(); | 189 helper_->Destroy(); |
145 PbufferGLSurfaceEGL::Destroy(); | 190 PbufferGLSurfaceEGL::Destroy(); |
146 } | 191 } |
147 | 192 |
193 // Make sure that buffer swaps occur for the surface, so we can send the data | |
194 // to the actual onscreen surface in the browser | |
148 bool EGLImageTransportSurface::IsOffscreen() { | 195 bool EGLImageTransportSurface::IsOffscreen() { |
149 return false; | 196 return false; |
150 } | 197 } |
151 | 198 |
152 void EGLImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 199 void EGLImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
153 if (fbo_id_) | 200 if (fbo_id_) |
154 return; | 201 return; |
155 | 202 |
156 glGenFramebuffersEXT(1, &fbo_id_); | 203 glGenFramebuffersEXT(1, &fbo_id_); |
157 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_id_); | 204 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_id_); |
(...skipping 24 matching lines...) Expand all Loading... | |
182 ReleaseSurface(&back_surface_); | 229 ReleaseSurface(&back_surface_); |
183 | 230 |
184 back_surface_ = new AcceleratedSurface(size); | 231 back_surface_ = new AcceleratedSurface(size); |
185 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 232 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
186 GL_COLOR_ATTACHMENT0, | 233 GL_COLOR_ATTACHMENT0, |
187 GL_TEXTURE_2D, | 234 GL_TEXTURE_2D, |
188 back_surface_->texture(), | 235 back_surface_->texture(), |
189 0); | 236 0); |
190 glFlush(); | 237 glFlush(); |
191 | 238 |
192 GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params params; | 239 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
193 params.width = size.width(); | 240 params.width = size.width(); |
194 params.height = size.height(); | 241 params.height = size.height(); |
195 params.identifier = back_surface_->pixmap(); | 242 params.identifier = back_surface_->pixmap(); |
196 helper_->SendAcceleratedSurfaceSetIOSurface(params); | 243 helper_->SendAcceleratedSurfaceNew(params); |
197 | 244 |
198 helper_->SetScheduled(false); | 245 helper_->SetScheduled(false); |
199 } | 246 } |
200 | 247 |
201 bool EGLImageTransportSurface::SwapBuffers() { | 248 bool EGLImageTransportSurface::SwapBuffers() { |
202 front_surface_.swap(back_surface_); | 249 front_surface_.swap(back_surface_); |
203 DCHECK_NE(front_surface_.get(), static_cast<AcceleratedSurface*>(NULL)); | 250 DCHECK_NE(front_surface_.get(), static_cast<AcceleratedSurface*>(NULL)); |
204 glFlush(); | 251 glFlush(); |
205 | 252 |
206 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 253 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
(...skipping 11 matching lines...) Expand all Loading... | |
218 0); | 265 0); |
219 } | 266 } |
220 helper_->SetScheduled(false); | 267 helper_->SetScheduled(false); |
221 return true; | 268 return true; |
222 } | 269 } |
223 | 270 |
224 gfx::Size EGLImageTransportSurface::GetSize() { | 271 gfx::Size EGLImageTransportSurface::GetSize() { |
225 return back_surface_->size(); | 272 return back_surface_->size(); |
226 } | 273 } |
227 | 274 |
228 void EGLImageTransportSurface::OnSetSurfaceACK( | 275 void EGLImageTransportSurface::OnNewSurfaceACK( |
229 uint64 surface_id) { | 276 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
jonathan.backer
2011/09/21 20:27:36
Comment out param name? Haven't seen this before.
danakj
2011/09/21 20:58:20
It's in the C++ style guide for params that are no
| |
230 DCHECK_EQ(back_surface_->pixmap(), surface_id); | 277 DCHECK_EQ(back_surface_->pixmap(), surface_id); |
231 helper_->SetScheduled(true); | 278 helper_->SetScheduled(true); |
232 } | 279 } |
233 | 280 |
234 void EGLImageTransportSurface::OnBuffersSwappedACK() { | 281 void EGLImageTransportSurface::OnBuffersSwappedACK() { |
235 helper_->SetScheduled(true); | 282 helper_->SetScheduled(true); |
236 } | 283 } |
237 | 284 |
238 GLXImageTransportSurface::GLXImageTransportSurface( | 285 GLXImageTransportSurface::GLXImageTransportSurface( |
239 GpuChannelManager* manager, | 286 GpuChannelManager* manager, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 size_ = size; | 371 size_ = size; |
325 if (bound_) { | 372 if (bound_) { |
326 ReleaseSurface(); | 373 ReleaseSurface(); |
327 bound_ = false; | 374 bound_ = false; |
328 } | 375 } |
329 | 376 |
330 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); | 377 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); |
331 XResizeWindow(dpy, window_, size_.width(), size_.height()); | 378 XResizeWindow(dpy, window_, size_.width(), size_.height()); |
332 XFlush(dpy); | 379 XFlush(dpy); |
333 | 380 |
334 GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params params; | 381 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
335 params.width = size_.width(); | 382 params.width = size_.width(); |
336 params.height = size_.height(); | 383 params.height = size_.height(); |
337 params.identifier = window_; | 384 params.identifier = window_; |
338 helper_->SendAcceleratedSurfaceSetIOSurface(params); | 385 helper_->SendAcceleratedSurfaceNew(params); |
339 | 386 |
340 helper_->SetScheduled(false); | 387 helper_->SetScheduled(false); |
341 } | 388 } |
342 | 389 |
343 bool GLXImageTransportSurface::SwapBuffers() { | 390 bool GLXImageTransportSurface::SwapBuffers() { |
344 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 391 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
345 glFlush(); | 392 glFlush(); |
346 | 393 |
347 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 394 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
348 params.surface_id = window_; | 395 params.surface_id = window_; |
349 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 396 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
350 | 397 |
351 helper_->SetScheduled(false); | 398 helper_->SetScheduled(false); |
352 return true; | 399 return true; |
353 } | 400 } |
354 | 401 |
355 gfx::Size GLXImageTransportSurface::GetSize() { | 402 gfx::Size GLXImageTransportSurface::GetSize() { |
356 return size_; | 403 return size_; |
357 } | 404 } |
358 | 405 |
359 void GLXImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 406 void GLXImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
360 if (!swap_interval_set_) { | 407 if (!swap_interval_set_) { |
361 context->SetSwapInterval(0); | 408 context->SetSwapInterval(0); |
362 swap_interval_set_ = true; | 409 swap_interval_set_ = true; |
363 } | 410 } |
364 } | 411 } |
365 | 412 |
366 void GLXImageTransportSurface::OnSetSurfaceACK( | 413 void GLXImageTransportSurface::OnNewSurfaceACK( |
367 uint64 surface_id) { | 414 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
368 DCHECK(!bound_); | 415 DCHECK(!bound_); |
369 bound_ = true; | 416 bound_ = true; |
370 helper_->SetScheduled(true); | 417 helper_->SetScheduled(true); |
371 } | 418 } |
372 | 419 |
373 void GLXImageTransportSurface::OnBuffersSwappedACK() { | 420 void GLXImageTransportSurface::OnBuffersSwappedACK() { |
374 helper_->SetScheduled(true); | 421 helper_->SetScheduled(true); |
375 } | 422 } |
376 | 423 |
424 OSMesaImageTransportSurface::OSMesaImageTransportSurface( | |
425 GpuChannelManager* manager, | |
426 int32 render_view_id, | |
427 int32 renderer_id, | |
428 int32 command_buffer_id) | |
429 : gfx::GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)), | |
430 size_(gfx::Size(1, 1)) { | |
431 helper_.reset(new ImageTransportHelper(this, | |
432 manager, | |
433 render_view_id, | |
434 renderer_id, | |
435 command_buffer_id)); | |
436 } | |
437 | |
438 OSMesaImageTransportSurface::~OSMesaImageTransportSurface() { | |
439 Destroy(); | |
440 } | |
441 | |
442 bool OSMesaImageTransportSurface::Initialize() { | |
443 if (!helper_->Initialize()) | |
444 return false; | |
445 return gfx::GLSurfaceOSMesa::Initialize(); | |
446 } | |
447 | |
448 void OSMesaImageTransportSurface::Destroy() { | |
449 if (shared_mem_.get()) | |
450 ReleaseSurface(); | |
451 | |
452 helper_->Destroy(); | |
453 gfx::GLSurfaceOSMesa::Destroy(); | |
454 } | |
455 | |
456 // Make sure that buffer swaps occur for the surface, so we can send the data | |
457 // to the actual onscreen surface in the browser | |
458 bool OSMesaImageTransportSurface::IsOffscreen() { | |
459 return false; | |
460 } | |
461 | |
462 void OSMesaImageTransportSurface::ReleaseSurface() { | |
463 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | |
464 params.identifier = shared_id_; | |
465 helper_->SendAcceleratedSurfaceRelease(params); | |
466 | |
467 shared_mem_.reset(); | |
468 shared_id_ = 0; | |
469 } | |
470 | |
471 void OSMesaImageTransportSurface::OnResize(gfx::Size size) { | |
472 if (shared_mem_.get()) | |
473 ReleaseSurface(); | |
474 | |
475 // Now that the shared memory buffer is gone, we need to change OSMesa to | |
476 // point at something valid, so we'll let it point to the buffer in the super | |
477 // class. This would be really bad since that buffer has a different size, | |
478 // but we don't allow any drawing to take place until we reset the surface | |
479 // back to a new buffer of shared memory. | |
480 helper_->MakeCurrent(); | |
481 | |
482 size_ = size; | |
483 | |
484 GpuHostMsg_AcceleratedSurfaceNew_Params params; | |
485 params.width = size_.width(); | |
486 params.height = size_.height(); | |
487 params.identifier = 0; // id comes from the browser with the shared mem | |
488 helper_->SendAcceleratedSurfaceNew(params); | |
489 | |
490 helper_->SetScheduled(false); | |
491 } | |
492 | |
493 void OSMesaImageTransportSurface::OnNewSurfaceACK( | |
494 uint64 surface_id, TransportDIB::Handle surface_handle) { | |
495 shared_id_ = surface_id; | |
496 shared_mem_.reset(TransportDIB::Map(surface_handle)); | |
497 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | |
498 | |
499 // When we get the shared memory buffer back we can use that for OSMesa to | |
500 // write in, so we give it to OSMesa. | |
501 helper_->MakeCurrent(); | |
502 | |
503 helper_->SetScheduled(true); | |
504 } | |
505 | |
506 bool OSMesaImageTransportSurface::SwapBuffers() { | |
507 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | |
508 | |
509 // Copy the OSMesa buffer to the shared memory | |
510 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); | |
511 | |
512 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
513 params.surface_id = shared_id_; | |
514 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | |
515 | |
516 helper_->SetScheduled(false); | |
517 return true; | |
518 } | |
519 | |
520 void OSMesaImageTransportSurface::OnBuffersSwappedACK() { | |
521 helper_->SetScheduled(true); | |
522 } | |
523 | |
524 gfx::Size OSMesaImageTransportSurface::GetSize() { | |
525 return size_; | |
526 } | |
527 | |
528 void* OSMesaImageTransportSurface::GetHandle() { | |
529 if (shared_mem_.get()) | |
530 return shared_mem_->memory(); | |
531 else | |
532 return GLSurfaceOSMesa::GetHandle(); | |
533 } | |
534 | |
377 } // namespace | 535 } // namespace |
378 | 536 |
379 // static | 537 // static |
380 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 538 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
381 GpuChannelManager* manager, | 539 GpuChannelManager* manager, |
382 int32 render_view_id, | 540 int32 render_view_id, |
383 int32 renderer_id, | 541 int32 renderer_id, |
384 int32 command_buffer_id) { | 542 int32 command_buffer_id) { |
385 scoped_refptr<gfx::GLSurface> surface; | 543 scoped_refptr<gfx::GLSurface> surface; |
386 switch (gfx::GetGLImplementation()) { | 544 switch (gfx::GetGLImplementation()) { |
387 case gfx::kGLImplementationDesktopGL: | 545 case gfx::kGLImplementationDesktopGL: |
388 surface = new GLXImageTransportSurface(manager, | 546 surface = new GLXImageTransportSurface(manager, |
389 render_view_id, | 547 render_view_id, |
390 renderer_id, | 548 renderer_id, |
391 command_buffer_id); | 549 command_buffer_id); |
392 break; | 550 break; |
393 case gfx::kGLImplementationEGLGLES2: | 551 case gfx::kGLImplementationEGLGLES2: |
394 surface = new EGLImageTransportSurface(manager, | 552 surface = new EGLImageTransportSurface(manager, |
395 render_view_id, | 553 render_view_id, |
396 renderer_id, | 554 renderer_id, |
397 command_buffer_id); | 555 command_buffer_id); |
398 break; | 556 break; |
557 case gfx::kGLImplementationOSMesaGL: | |
558 surface = new OSMesaImageTransportSurface(manager, | |
559 render_view_id, | |
560 renderer_id, | |
561 command_buffer_id); | |
562 break; | |
399 default: | 563 default: |
400 NOTREACHED(); | 564 NOTREACHED(); |
401 return NULL; | 565 return NULL; |
402 } | 566 } |
403 if (surface->Initialize()) | 567 if (surface->Initialize()) |
404 return surface; | 568 return surface; |
405 else | 569 else |
406 return NULL; | 570 return NULL; |
407 } | 571 } |
408 | 572 |
(...skipping 25 matching lines...) Expand all Loading... | |
434 | 598 |
435 return true; | 599 return true; |
436 } | 600 } |
437 | 601 |
438 void ImageTransportHelper::Destroy() { | 602 void ImageTransportHelper::Destroy() { |
439 } | 603 } |
440 | 604 |
441 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { | 605 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { |
442 bool handled = true; | 606 bool handled = true; |
443 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) | 607 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) |
444 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_SetSurfaceACK, | 608 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_NewACK, |
445 OnSetSurfaceACK) | 609 OnNewSurfaceACK) |
446 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BuffersSwappedACK, | 610 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BuffersSwappedACK, |
447 OnBuffersSwappedACK) | 611 OnBuffersSwappedACK) |
448 IPC_MESSAGE_UNHANDLED(handled = false) | 612 IPC_MESSAGE_UNHANDLED(handled = false) |
449 IPC_END_MESSAGE_MAP() | 613 IPC_END_MESSAGE_MAP() |
450 return handled; | 614 return handled; |
451 } | 615 } |
452 | 616 |
453 void ImageTransportHelper::SendAcceleratedSurfaceRelease( | 617 void ImageTransportHelper::SendAcceleratedSurfaceRelease( |
454 GpuHostMsg_AcceleratedSurfaceRelease_Params params) { | 618 GpuHostMsg_AcceleratedSurfaceRelease_Params params) { |
455 params.renderer_id = renderer_id_; | 619 params.renderer_id = renderer_id_; |
456 params.render_view_id = render_view_id_; | 620 params.render_view_id = render_view_id_; |
457 params.route_id = route_id_; | 621 params.route_id = route_id_; |
458 manager_->Send(new GpuHostMsg_AcceleratedSurfaceRelease(params)); | 622 manager_->Send(new GpuHostMsg_AcceleratedSurfaceRelease(params)); |
459 } | 623 } |
460 | 624 |
461 void ImageTransportHelper::SendAcceleratedSurfaceSetIOSurface( | 625 void ImageTransportHelper::SendAcceleratedSurfaceNew( |
462 GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params params) { | 626 GpuHostMsg_AcceleratedSurfaceNew_Params params) { |
463 params.renderer_id = renderer_id_; | 627 params.renderer_id = renderer_id_; |
464 params.render_view_id = render_view_id_; | 628 params.render_view_id = render_view_id_; |
465 params.route_id = route_id_; | 629 params.route_id = route_id_; |
466 manager_->Send(new GpuHostMsg_AcceleratedSurfaceSetIOSurface(params)); | 630 manager_->Send(new GpuHostMsg_AcceleratedSurfaceNew(params)); |
467 } | 631 } |
468 | 632 |
469 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( | 633 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( |
470 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { | 634 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { |
471 params.renderer_id = renderer_id_; | 635 params.renderer_id = renderer_id_; |
472 params.render_view_id = render_view_id_; | 636 params.render_view_id = render_view_id_; |
473 params.route_id = route_id_; | 637 params.route_id = route_id_; |
474 manager_->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); | 638 manager_->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); |
475 } | 639 } |
476 | 640 |
477 void ImageTransportHelper::SetScheduled(bool is_scheduled) { | 641 void ImageTransportHelper::SetScheduled(bool is_scheduled) { |
478 gpu::GpuScheduler* scheduler = Scheduler(); | 642 gpu::GpuScheduler* scheduler = Scheduler(); |
479 if (!scheduler) | 643 if (!scheduler) |
480 return; | 644 return; |
481 | 645 |
482 scheduler->SetScheduled(is_scheduled); | 646 scheduler->SetScheduled(is_scheduled); |
483 } | 647 } |
484 | 648 |
485 void ImageTransportHelper::OnSetSurfaceACK(uint64 surface_id) { | 649 void ImageTransportHelper::OnNewSurfaceACK( |
486 surface_->OnSetSurfaceACK(surface_id); | 650 uint64 surface_id, TransportDIB::Handle surface_handle) { |
651 surface_->OnNewSurfaceACK(surface_id, surface_handle); | |
487 } | 652 } |
488 | 653 |
489 void ImageTransportHelper::OnBuffersSwappedACK() { | 654 void ImageTransportHelper::OnBuffersSwappedACK() { |
490 surface_->OnBuffersSwappedACK(); | 655 surface_->OnBuffersSwappedACK(); |
491 } | 656 } |
492 | 657 |
493 void ImageTransportHelper::Resize(gfx::Size size) { | 658 void ImageTransportHelper::Resize(gfx::Size size) { |
494 surface_->OnResize(size); | 659 surface_->OnResize(size); |
495 } | 660 } |
496 | 661 |
662 bool ImageTransportHelper::MakeCurrent() { | |
663 gpu::gles2::GLES2Decoder* decoder = Decoder(); | |
664 if (!decoder) | |
665 return false; | |
666 return decoder->MakeCurrent(); | |
667 } | |
668 | |
497 gpu::GpuScheduler* ImageTransportHelper::Scheduler() { | 669 gpu::GpuScheduler* ImageTransportHelper::Scheduler() { |
498 GpuChannel* channel = manager_->LookupChannel(renderer_id_); | 670 GpuChannel* channel = manager_->LookupChannel(renderer_id_); |
499 if (!channel) | 671 if (!channel) |
500 return NULL; | 672 return NULL; |
501 | 673 |
502 GpuCommandBufferStub* stub = | 674 GpuCommandBufferStub* stub = |
503 channel->LookupCommandBuffer(command_buffer_id_); | 675 channel->LookupCommandBuffer(command_buffer_id_); |
504 if (!stub) | 676 if (!stub) |
505 return NULL; | 677 return NULL; |
506 | 678 |
507 return stub->scheduler(); | 679 return stub->scheduler(); |
508 } | 680 } |
509 | 681 |
510 gpu::gles2::GLES2Decoder* ImageTransportHelper::Decoder() { | 682 gpu::gles2::GLES2Decoder* ImageTransportHelper::Decoder() { |
511 GpuChannel* channel = manager_->LookupChannel(renderer_id_); | 683 GpuChannel* channel = manager_->LookupChannel(renderer_id_); |
512 if (!channel) | 684 if (!channel) |
513 return NULL; | 685 return NULL; |
514 | 686 |
515 GpuCommandBufferStub* stub = | 687 GpuCommandBufferStub* stub = |
516 channel->LookupCommandBuffer(command_buffer_id_); | 688 channel->LookupCommandBuffer(command_buffer_id_); |
517 if (!stub) | 689 if (!stub) |
518 return NULL; | 690 return NULL; |
519 | 691 |
520 return stub->decoder(); | 692 return stub->decoder(); |
521 } | 693 } |
522 | 694 |
523 #endif // defined(USE_GPU) | 695 #endif // defined(USE_GPU) |
OLD | NEW |