OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 extern "C" { | 5 extern "C" { |
6 #include <X11/Xlib.h> | 6 #include <X11/Xlib.h> |
7 } | 7 } |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
12 #include "ui/gl/gl_image_glx.h" | 12 #include "ui/gl/gl_image_glx.h" |
13 #include "ui/gl/gl_surface_glx.h" | 13 #include "ui/gl/gl_surface_glx.h" |
14 | 14 |
15 namespace gfx { | 15 namespace gfx { |
16 | |
17 namespace { | 16 namespace { |
18 | 17 |
19 bool ValidFormat(unsigned internalformat) { | 18 bool ValidFormat(unsigned internalformat) { |
20 switch (internalformat) { | 19 switch (internalformat) { |
21 case GL_RGB: | 20 case GL_RGB: |
22 case GL_RGBA: | 21 case GL_RGBA: |
23 return true; | 22 return true; |
24 default: | 23 default: |
25 return false; | 24 return false; |
26 } | 25 } |
(...skipping 28 matching lines...) Expand all Loading... |
55 case GL_RGBA: | 54 case GL_RGBA: |
56 return 32u; | 55 return 32u; |
57 case GL_RGB: | 56 case GL_RGB: |
58 return 24u; | 57 return 24u; |
59 default: | 58 default: |
60 NOTREACHED(); | 59 NOTREACHED(); |
61 return 0u; | 60 return 0u; |
62 } | 61 } |
63 } | 62 } |
64 | 63 |
65 bool ActualPixmapGeometry(XID pixmap, gfx::Size* size, unsigned* depth) { | 64 bool ActualPixmapGeometry(XID pixmap, Size* size, unsigned* depth) { |
66 XID root_return; | 65 XID root_return; |
67 int x_return; | 66 int x_return; |
68 int y_return; | 67 int y_return; |
69 unsigned width_return; | 68 unsigned width_return; |
70 unsigned height_return; | 69 unsigned height_return; |
71 unsigned border_width_return; | 70 unsigned border_width_return; |
72 unsigned depth_return; | 71 unsigned depth_return; |
73 if (!XGetGeometry(gfx::GetXDisplay(), | 72 if (!XGetGeometry(GetXDisplay(), pixmap, &root_return, &x_return, &y_return, |
74 pixmap, | 73 &width_return, &height_return, &border_width_return, |
75 &root_return, | |
76 &x_return, | |
77 &y_return, | |
78 &width_return, | |
79 &height_return, | |
80 &border_width_return, | |
81 &depth_return)) | 74 &depth_return)) |
82 return false; | 75 return false; |
83 | 76 |
84 if (size) | 77 if (size) |
85 *size = gfx::Size(width_return, height_return); | 78 *size = Size(width_return, height_return); |
86 if (depth) | 79 if (depth) |
87 *depth = depth_return; | 80 *depth = depth_return; |
88 return true; | 81 return true; |
89 } | 82 } |
90 | 83 |
91 unsigned ActualPixmapDepth(XID pixmap) { | 84 unsigned ActualPixmapDepth(XID pixmap) { |
92 unsigned depth; | 85 unsigned depth; |
93 if (!ActualPixmapGeometry(pixmap, NULL, &depth)) | 86 if (!ActualPixmapGeometry(pixmap, NULL, &depth)) |
94 return -1; | 87 return -1; |
95 | 88 |
96 return depth; | 89 return depth; |
97 } | 90 } |
98 | 91 |
99 gfx::Size ActualPixmapSize(XID pixmap) { | 92 Size ActualPixmapSize(XID pixmap) { |
100 gfx::Size size; | 93 Size size; |
101 if (!ActualPixmapGeometry(pixmap, &size, NULL)) | 94 if (!ActualPixmapGeometry(pixmap, &size, NULL)) |
102 return gfx::Size(); | 95 return Size(); |
103 | 96 |
104 return size; | 97 return size; |
105 } | 98 } |
106 | 99 |
107 } // namespace anonymous | 100 } // namespace |
108 | 101 |
109 GLImageGLX::GLImageGLX(const gfx::Size& size, unsigned internalformat) | 102 GLImageGLX::GLImageGLX(const Size& size, unsigned internalformat) |
110 : glx_pixmap_(0), size_(size), internalformat_(internalformat) { | 103 : glx_pixmap_(0), size_(size), internalformat_(internalformat) {} |
111 } | |
112 | 104 |
113 GLImageGLX::~GLImageGLX() { | 105 GLImageGLX::~GLImageGLX() { |
114 DCHECK_EQ(0u, glx_pixmap_); | 106 DCHECK_EQ(0u, glx_pixmap_); |
115 } | 107 } |
116 | 108 |
117 bool GLImageGLX::Initialize(XID pixmap) { | 109 bool GLImageGLX::Initialize(XID pixmap) { |
118 if (!GLSurfaceGLX::IsTextureFromPixmapSupported()) { | 110 if (!GLSurfaceGLX::IsTextureFromPixmapSupported()) { |
119 DVLOG(0) << "GLX_EXT_texture_from_pixmap not supported."; | 111 DVLOG(0) << "GLX_EXT_texture_from_pixmap not supported."; |
120 return false; | 112 return false; |
121 } | 113 } |
122 | 114 |
123 if (!ValidFormat(internalformat_)) { | 115 if (!ValidFormat(internalformat_)) { |
124 DVLOG(0) << "Invalid format: " << internalformat_; | 116 DVLOG(0) << "Invalid format: " << internalformat_; |
125 return false; | 117 return false; |
126 } | 118 } |
127 | 119 |
128 DCHECK_EQ(PixmapDepth(internalformat_), ActualPixmapDepth(pixmap)); | 120 DCHECK_EQ(PixmapDepth(internalformat_), ActualPixmapDepth(pixmap)); |
129 DCHECK_EQ(size_.ToString(), ActualPixmapSize(pixmap).ToString()); | 121 DCHECK_EQ(size_.ToString(), ActualPixmapSize(pixmap).ToString()); |
130 | 122 |
131 int config_attribs[] = { | 123 int config_attribs[] = { |
132 GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, | 124 GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, |
133 GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_EXT, | 125 GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_EXT, |
134 BindToTextureFormat(internalformat_), GL_TRUE, | 126 BindToTextureFormat(internalformat_), GL_TRUE, |
135 0}; | 127 0}; |
136 int num_elements = 0; | 128 int num_elements = 0; |
137 gfx::XScopedPtr<GLXFBConfig> config( | 129 XScopedPtr<GLXFBConfig> config( |
138 glXChooseFBConfig(gfx::GetXDisplay(), DefaultScreen(gfx::GetXDisplay()), | 130 glXChooseFBConfig(GetXDisplay(), DefaultScreen(GetXDisplay()), |
139 config_attribs, &num_elements)); | 131 config_attribs, &num_elements)); |
140 if (!config.get()) { | 132 if (!config.get()) { |
141 DVLOG(0) << "glXChooseFBConfig failed."; | 133 DVLOG(0) << "glXChooseFBConfig failed."; |
142 return false; | 134 return false; |
143 } | 135 } |
144 if (!num_elements) { | 136 if (!num_elements) { |
145 DVLOG(0) << "glXChooseFBConfig returned 0 elements."; | 137 DVLOG(0) << "glXChooseFBConfig returned 0 elements."; |
146 return false; | 138 return false; |
147 } | 139 } |
148 | 140 |
149 int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, | 141 int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, |
150 GLX_TEXTURE_FORMAT_EXT, | 142 GLX_TEXTURE_FORMAT_EXT, |
151 TextureFormat(internalformat_), 0}; | 143 TextureFormat(internalformat_), 0}; |
152 glx_pixmap_ = glXCreatePixmap( | 144 glx_pixmap_ = |
153 gfx::GetXDisplay(), *config.get(), pixmap, pixmap_attribs); | 145 glXCreatePixmap(GetXDisplay(), *config.get(), pixmap, pixmap_attribs); |
154 if (!glx_pixmap_) { | 146 if (!glx_pixmap_) { |
155 DVLOG(0) << "glXCreatePixmap failed."; | 147 DVLOG(0) << "glXCreatePixmap failed."; |
156 return false; | 148 return false; |
157 } | 149 } |
158 | 150 |
159 return true; | 151 return true; |
160 } | 152 } |
161 | 153 |
162 void GLImageGLX::Destroy(bool have_context) { | 154 void GLImageGLX::Destroy(bool have_context) { |
163 if (glx_pixmap_) { | 155 if (glx_pixmap_) { |
164 glXDestroyGLXPixmap(gfx::GetXDisplay(), glx_pixmap_); | 156 glXDestroyGLXPixmap(GetXDisplay(), glx_pixmap_); |
165 glx_pixmap_ = 0; | 157 glx_pixmap_ = 0; |
166 } | 158 } |
167 } | 159 } |
168 | 160 |
169 gfx::Size GLImageGLX::GetSize() { return size_; } | 161 Size GLImageGLX::GetSize() { |
| 162 return size_; |
| 163 } |
170 | 164 |
171 unsigned GLImageGLX::GetInternalFormat() { return internalformat_; } | 165 unsigned GLImageGLX::GetInternalFormat() { return internalformat_; } |
172 | 166 |
173 bool GLImageGLX::BindTexImage(unsigned target) { | 167 bool GLImageGLX::BindTexImage(unsigned target) { |
174 if (!glx_pixmap_) | 168 if (!glx_pixmap_) |
175 return false; | 169 return false; |
176 | 170 |
177 // Requires TEXTURE_2D target. | 171 // Requires TEXTURE_2D target. |
178 if (target != GL_TEXTURE_2D) | 172 if (target != GL_TEXTURE_2D) |
179 return false; | 173 return false; |
180 | 174 |
181 glXBindTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0); | 175 glXBindTexImageEXT(GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0); |
182 return true; | 176 return true; |
183 } | 177 } |
184 | 178 |
185 void GLImageGLX::ReleaseTexImage(unsigned target) { | 179 void GLImageGLX::ReleaseTexImage(unsigned target) { |
186 DCHECK_NE(0u, glx_pixmap_); | 180 DCHECK_NE(0u, glx_pixmap_); |
187 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target); | 181 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target); |
188 | 182 |
189 glXReleaseTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT); | 183 glXReleaseTexImageEXT(GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT); |
| 184 } |
| 185 |
| 186 bool GLImageGLX::CopyTexImage(unsigned target) { |
| 187 return false; |
190 } | 188 } |
191 | 189 |
192 bool GLImageGLX::CopyTexSubImage(unsigned target, | 190 bool GLImageGLX::CopyTexSubImage(unsigned target, |
193 const Point& offset, | 191 const Point& offset, |
194 const Rect& rect) { | 192 const Rect& rect) { |
195 return false; | 193 return false; |
196 } | 194 } |
197 | 195 |
198 bool GLImageGLX::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 196 bool GLImageGLX::ScheduleOverlayPlane(AcceleratedWidget widget, |
199 int z_order, | 197 int z_order, |
200 OverlayTransform transform, | 198 OverlayTransform transform, |
201 const Rect& bounds_rect, | 199 const Rect& bounds_rect, |
202 const RectF& crop_rect) { | 200 const RectF& crop_rect) { |
203 return false; | 201 return false; |
204 } | 202 } |
205 | 203 |
206 void GLImageGLX::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 204 void GLImageGLX::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
207 uint64_t process_tracing_id, | 205 uint64_t process_tracing_id, |
208 const std::string& dump_name) { | 206 const std::string& dump_name) { |
209 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 | 207 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 |
210 } | 208 } |
211 | 209 |
212 } // namespace gfx | 210 } // namespace gfx |
OLD | NEW |