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 #include "content/browser/renderer_host/image_transport_client.h" | 5 #include "content/browser/renderer_host/image_transport_client.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/extensions/Xcomposite.h> | 8 #include <X11/extensions/Xcomposite.h> |
9 | 9 |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 virtual ~ImageTransportClientEGL() { | 49 virtual ~ImageTransportClientEGL() { |
50 if (image_) { | 50 if (image_) { |
51 scoped_ptr<gfx::ScopedMakeCurrent> bind( | 51 scoped_ptr<gfx::ScopedMakeCurrent> bind( |
52 resources_->GetScopedMakeCurrent()); | 52 resources_->GetScopedMakeCurrent()); |
53 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); | 53 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); |
54 glFlush(); | 54 glFlush(); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 virtual unsigned int Initialize(uint64* surface_id) { | 58 virtual unsigned int Initialize(uint64* surface_handle) { |
59 scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); | 59 scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); |
60 image_ = eglCreateImageKHR( | 60 image_ = eglCreateImageKHR( |
61 gfx::GLSurfaceEGL::GetHardwareDisplay(), EGL_NO_CONTEXT, | 61 gfx::GLSurfaceEGL::GetHardwareDisplay(), EGL_NO_CONTEXT, |
62 EGL_NATIVE_PIXMAP_KHR, reinterpret_cast<void*>(*surface_id), NULL); | 62 EGL_NATIVE_PIXMAP_KHR, reinterpret_cast<void*>(*surface_handle), NULL); |
63 if (!image_) | 63 if (!image_) |
64 return 0; | 64 return 0; |
65 GLuint texture = CreateTexture(); | 65 GLuint texture = CreateTexture(); |
66 glBindTexture(GL_TEXTURE_2D, texture); | 66 glBindTexture(GL_TEXTURE_2D, texture); |
67 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_); | 67 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_); |
68 glFlush(); | 68 glFlush(); |
69 return texture; | 69 return texture; |
70 } | 70 } |
71 | 71 |
72 virtual void Acquire() { } | 72 virtual void Acquire() { } |
(...skipping 20 matching lines...) Expand all Loading... |
93 } | 93 } |
94 | 94 |
95 virtual ~ImageTransportClientGLX() { | 95 virtual ~ImageTransportClientGLX() { |
96 Display* dpy = static_cast<Display*>(resources_->GetDisplay()); | 96 Display* dpy = static_cast<Display*>(resources_->GetDisplay()); |
97 if (glx_pixmap_) | 97 if (glx_pixmap_) |
98 glXDestroyGLXPixmap(dpy, glx_pixmap_); | 98 glXDestroyGLXPixmap(dpy, glx_pixmap_); |
99 if (pixmap_) | 99 if (pixmap_) |
100 XFreePixmap(dpy, pixmap_); | 100 XFreePixmap(dpy, pixmap_); |
101 } | 101 } |
102 | 102 |
103 virtual unsigned int Initialize(uint64* surface_id) { | 103 virtual unsigned int Initialize(uint64* surface_handle) { |
104 TRACE_EVENT0("renderer_host", "ImageTransportClientGLX::Initialize"); | 104 TRACE_EVENT0("renderer_host", "ImageTransportClientGLX::Initialize"); |
105 Display* dpy = static_cast<Display*>(resources_->GetDisplay()); | 105 Display* dpy = static_cast<Display*>(resources_->GetDisplay()); |
106 | 106 |
107 scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); | 107 scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); |
108 if (!InitializeOneOff(dpy)) | 108 if (!InitializeOneOff(dpy)) |
109 return 0; | 109 return 0; |
110 | 110 |
111 // Create pixmap from window. | 111 // Create pixmap from window. |
112 // We receive a window here rather than a pixmap directly because drivers | 112 // We receive a window here rather than a pixmap directly because drivers |
113 // require (or required) that the pixmap used to create the GL texture be | 113 // require (or required) that the pixmap used to create the GL texture be |
114 // created in the same process as the texture. | 114 // created in the same process as the texture. |
115 pixmap_ = XCompositeNameWindowPixmap(dpy, *surface_id); | 115 pixmap_ = XCompositeNameWindowPixmap(dpy, *surface_handle); |
116 | 116 |
117 const int pixmapAttribs[] = { | 117 const int pixmapAttribs[] = { |
118 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, | 118 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, |
119 GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, | 119 GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, |
120 0 | 120 0 |
121 }; | 121 }; |
122 | 122 |
123 glx_pixmap_ = glXCreatePixmap(dpy, fbconfig_.Get(), pixmap_, pixmapAttribs); | 123 glx_pixmap_ = glXCreatePixmap(dpy, fbconfig_.Get(), pixmap_, pixmapAttribs); |
124 | 124 |
125 texture_ = CreateTexture(); | 125 texture_ = CreateTexture(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 ImageTransportClientOSMesa(ui::SharedResources* resources, | 226 ImageTransportClientOSMesa(ui::SharedResources* resources, |
227 const gfx::Size& size) | 227 const gfx::Size& size) |
228 : resources_(resources), | 228 : resources_(resources), |
229 size_(size), | 229 size_(size), |
230 texture_(0) { | 230 texture_(0) { |
231 } | 231 } |
232 | 232 |
233 virtual ~ImageTransportClientOSMesa() { | 233 virtual ~ImageTransportClientOSMesa() { |
234 } | 234 } |
235 | 235 |
236 virtual unsigned int Initialize(uint64* surface_id) { | 236 virtual unsigned int Initialize(uint64* surface_handle) { |
237 // We expect to make the id here, so don't want the other end giving us one | 237 // We expect to make the handle here, so don't want the other end giving us |
238 DCHECK_EQ(*surface_id, static_cast<uint64>(0)); | 238 // one. |
| 239 DCHECK_EQ(*surface_handle, static_cast<uint64>(0)); |
239 | 240 |
240 // It's possible that this ID gneration could clash with IDs from other | 241 // It's possible that this ID gneration could clash with IDs from other |
241 // AcceleratedSurfaceContainerTouch* objects, however we should never have | 242 // AcceleratedSurfaceContainerTouch* objects, however we should never have |
242 // ids active from more than one type at the same time, so we have free | 243 // ids active from more than one type at the same time, so we have free |
243 // reign of the id namespace. | 244 // reign of the id namespace. |
244 *surface_id = next_id_++; | 245 *surface_handle = next_handle_++; |
245 | 246 |
246 shared_mem_.reset( | 247 shared_mem_.reset( |
247 TransportDIB::Create(size_.GetArea() * 4, // GL_RGBA=4 B/px | 248 TransportDIB::Create(size_.GetArea() * 4, // GL_RGBA=4 B/px |
248 *surface_id)); | 249 *surface_handle)); |
249 if (!shared_mem_.get()) | 250 if (!shared_mem_.get()) |
250 return 0; | 251 return 0; |
251 | 252 |
252 scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); | 253 scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); |
253 texture_ = CreateTexture(); | 254 texture_ = CreateTexture(); |
254 return texture_; | 255 return texture_; |
255 } | 256 } |
256 | 257 |
257 virtual void Acquire() { | 258 virtual void Acquire() { |
258 glBindTexture(GL_TEXTURE_2D, texture_); | 259 glBindTexture(GL_TEXTURE_2D, texture_); |
259 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, | 260 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, |
260 size_.width(), size_.height(), 0, | 261 size_.width(), size_.height(), 0, |
261 GL_RGBA, GL_UNSIGNED_BYTE, shared_mem_->memory()); | 262 GL_RGBA, GL_UNSIGNED_BYTE, shared_mem_->memory()); |
262 } | 263 } |
263 | 264 |
264 virtual void Release() { } | 265 virtual void Release() { } |
265 virtual bool Flipped() { return false; } | 266 virtual bool Flipped() { return false; } |
266 virtual TransportDIB::Handle Handle() const { return shared_mem_->handle(); } | 267 virtual TransportDIB::Handle Handle() const { return shared_mem_->handle(); } |
267 | 268 |
268 private: | 269 private: |
269 ui::SharedResources* resources_; | 270 ui::SharedResources* resources_; |
270 gfx::Size size_; | 271 gfx::Size size_; |
271 scoped_ptr<TransportDIB> shared_mem_; | 272 scoped_ptr<TransportDIB> shared_mem_; |
272 GLuint texture_; | 273 GLuint texture_; |
273 static uint32 next_id_; | 274 static uint32 next_handle_; |
274 }; | 275 }; |
275 uint32 ImageTransportClientOSMesa::next_id_ = 0; | 276 uint32 ImageTransportClientOSMesa::next_handle_ = 0; |
276 | 277 |
277 #endif // !USE_WAYLAND | 278 #endif // !USE_WAYLAND |
278 | 279 |
279 } // anonymous namespace | 280 } // anonymous namespace |
280 | 281 |
281 ImageTransportClient* ImageTransportClient::Create( | 282 ImageTransportClient* ImageTransportClient::Create( |
282 ui::SharedResources* resources, | 283 ui::SharedResources* resources, |
283 const gfx::Size& size) { | 284 const gfx::Size& size) { |
284 switch (gfx::GetGLImplementation()) { | 285 switch (gfx::GetGLImplementation()) { |
285 #if !defined(USE_WAYLAND) | 286 #if !defined(USE_WAYLAND) |
286 case gfx::kGLImplementationOSMesaGL: | 287 case gfx::kGLImplementationOSMesaGL: |
287 return new ImageTransportClientOSMesa(resources, size); | 288 return new ImageTransportClientOSMesa(resources, size); |
288 case gfx::kGLImplementationDesktopGL: | 289 case gfx::kGLImplementationDesktopGL: |
289 return new ImageTransportClientGLX(resources); | 290 return new ImageTransportClientGLX(resources); |
290 #endif | 291 #endif |
291 case gfx::kGLImplementationEGLGLES2: | 292 case gfx::kGLImplementationEGLGLES2: |
292 return new ImageTransportClientEGL(resources); | 293 return new ImageTransportClientEGL(resources); |
293 default: | 294 default: |
294 NOTREACHED(); | 295 NOTREACHED(); |
295 return NULL; | 296 return NULL; |
296 } | 297 } |
297 } | 298 } |
OLD | NEW |