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" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "third_party/angle/include/EGL/egl.h" | 13 #include "third_party/angle/include/EGL/egl.h" |
14 #include "third_party/angle/include/EGL/eglext.h" | 14 #include "third_party/angle/include/EGL/eglext.h" |
15 #include "ui/gfx/gl/gl_bindings.h" | 15 #include "ui/gfx/gl/gl_bindings.h" |
16 #include "ui/gfx/gl/gl_implementation.h" | 16 #include "ui/gfx/gl/gl_implementation.h" |
17 #include "ui/gfx/gl/gl_surface_egl.h" | 17 #include "ui/gfx/gl/gl_surface_egl.h" |
18 #include "ui/gfx/gl/gl_surface_glx.h" | 18 #include "ui/gfx/gl/gl_surface_glx.h" |
| 19 #include "ui/gfx/gl/scoped_make_current.h" |
19 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 class ScopedPtrXFree { | 24 class ScopedPtrXFree { |
24 public: | 25 public: |
25 void operator()(void* x) const { | 26 void operator()(void* x) const { |
26 ::XFree(x); | 27 ::XFree(x); |
27 } | 28 } |
28 }; | 29 }; |
(...skipping 11 matching lines...) Expand all Loading... |
40 | 41 |
41 class ImageTransportClientEGL : public ImageTransportClient { | 42 class ImageTransportClientEGL : public ImageTransportClient { |
42 public: | 43 public: |
43 explicit ImageTransportClientEGL(ui::SharedResources* resources) | 44 explicit ImageTransportClientEGL(ui::SharedResources* resources) |
44 : resources_(resources), | 45 : resources_(resources), |
45 image_(NULL) { | 46 image_(NULL) { |
46 } | 47 } |
47 | 48 |
48 virtual ~ImageTransportClientEGL() { | 49 virtual ~ImageTransportClientEGL() { |
49 if (image_) { | 50 if (image_) { |
50 resources_->MakeSharedContextCurrent(); | 51 scoped_ptr<gfx::ScopedMakeCurrent> bind( |
| 52 resources_->GetScopedMakeCurrent()); |
51 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); | 53 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); |
52 glFlush(); | 54 glFlush(); |
53 } | 55 } |
54 } | 56 } |
55 | 57 |
56 virtual unsigned int Initialize(uint64* surface_id) { | 58 virtual unsigned int Initialize(uint64* surface_id) { |
57 resources_->MakeSharedContextCurrent(); | 59 scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); |
58 image_ = eglCreateImageKHR( | 60 image_ = eglCreateImageKHR( |
59 gfx::GLSurfaceEGL::GetHardwareDisplay(), EGL_NO_CONTEXT, | 61 gfx::GLSurfaceEGL::GetHardwareDisplay(), EGL_NO_CONTEXT, |
60 EGL_NATIVE_PIXMAP_KHR, reinterpret_cast<void*>(*surface_id), NULL); | 62 EGL_NATIVE_PIXMAP_KHR, reinterpret_cast<void*>(*surface_id), NULL); |
61 if (!image_) | 63 if (!image_) |
62 return 0; | 64 return 0; |
63 GLuint texture = CreateTexture(); | 65 GLuint texture = CreateTexture(); |
64 glBindTexture(GL_TEXTURE_2D, texture); | 66 glBindTexture(GL_TEXTURE_2D, texture); |
65 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_); | 67 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_); |
66 glFlush(); | 68 glFlush(); |
67 return texture; | 69 return texture; |
(...skipping 25 matching lines...) Expand all Loading... |
93 if (glx_pixmap_) | 95 if (glx_pixmap_) |
94 glXDestroyGLXPixmap(dpy, glx_pixmap_); | 96 glXDestroyGLXPixmap(dpy, glx_pixmap_); |
95 if (pixmap_) | 97 if (pixmap_) |
96 XFreePixmap(dpy, pixmap_); | 98 XFreePixmap(dpy, pixmap_); |
97 } | 99 } |
98 | 100 |
99 virtual unsigned int Initialize(uint64* surface_id) { | 101 virtual unsigned int Initialize(uint64* surface_id) { |
100 TRACE_EVENT0("renderer_host", "ImageTransportClientGLX::Initialize"); | 102 TRACE_EVENT0("renderer_host", "ImageTransportClientGLX::Initialize"); |
101 Display* dpy = static_cast<Display*>(resources_->GetDisplay()); | 103 Display* dpy = static_cast<Display*>(resources_->GetDisplay()); |
102 | 104 |
103 resources_->MakeSharedContextCurrent(); | 105 scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); |
104 if (!InitializeOneOff(dpy)) | 106 if (!InitializeOneOff(dpy)) |
105 return 0; | 107 return 0; |
106 | 108 |
107 // Create pixmap from window. | 109 // Create pixmap from window. |
108 // We receive a window here rather than a pixmap directly because drivers | 110 // We receive a window here rather than a pixmap directly because drivers |
109 // require (or required) that the pixmap used to create the GL texture be | 111 // require (or required) that the pixmap used to create the GL texture be |
110 // created in the same process as the texture. | 112 // created in the same process as the texture. |
111 pixmap_ = XCompositeNameWindowPixmap(dpy, *surface_id); | 113 pixmap_ = XCompositeNameWindowPixmap(dpy, *surface_id); |
112 | 114 |
113 const int pixmapAttribs[] = { | 115 const int pixmapAttribs[] = { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // ids active from more than one type at the same time, so we have free | 240 // ids active from more than one type at the same time, so we have free |
239 // reign of the id namespace. | 241 // reign of the id namespace. |
240 *surface_id = next_id_++; | 242 *surface_id = next_id_++; |
241 | 243 |
242 shared_mem_.reset( | 244 shared_mem_.reset( |
243 TransportDIB::Create(size_.GetArea() * 4, // GL_RGBA=4 B/px | 245 TransportDIB::Create(size_.GetArea() * 4, // GL_RGBA=4 B/px |
244 *surface_id)); | 246 *surface_id)); |
245 if (!shared_mem_.get()) | 247 if (!shared_mem_.get()) |
246 return 0; | 248 return 0; |
247 | 249 |
248 resources_->MakeSharedContextCurrent(); | 250 scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); |
249 texture_ = CreateTexture(); | 251 texture_ = CreateTexture(); |
250 return texture_; | 252 return texture_; |
251 } | 253 } |
252 | 254 |
253 virtual void Acquire() { | 255 virtual void Acquire() { |
254 glBindTexture(GL_TEXTURE_2D, texture_); | 256 glBindTexture(GL_TEXTURE_2D, texture_); |
255 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, | 257 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, |
256 size_.width(), size_.height(), 0, | 258 size_.width(), size_.height(), 0, |
257 GL_RGBA, GL_UNSIGNED_BYTE, shared_mem_->memory()); | 259 GL_RGBA, GL_UNSIGNED_BYTE, shared_mem_->memory()); |
258 } | 260 } |
(...skipping 21 matching lines...) Expand all Loading... |
280 return new ImageTransportClientGLX(resources); | 282 return new ImageTransportClientGLX(resources); |
281 case gfx::kGLImplementationEGLGLES2: | 283 case gfx::kGLImplementationEGLGLES2: |
282 return new ImageTransportClientEGL(resources); | 284 return new ImageTransportClientEGL(resources); |
283 case gfx::kGLImplementationOSMesaGL: | 285 case gfx::kGLImplementationOSMesaGL: |
284 return new ImageTransportClientOSMesa(resources, size); | 286 return new ImageTransportClientOSMesa(resources, size); |
285 default: | 287 default: |
286 NOTREACHED(); | 288 NOTREACHED(); |
287 return NULL; | 289 return NULL; |
288 } | 290 } |
289 } | 291 } |
OLD | NEW |