Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: ui/gl/gl_image_glx.cc

Issue 807853005: Refactor Vaapi video decoder/encoder in preparation of Freon support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove whitespace changes Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« content/content_tests.gypi ('K') | « ui/gl/gl_image_glx.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 }
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_image_glx.h"
13 #include "ui/gl/gl_surface_glx.h"
14
15 namespace gfx {
16
17 namespace {
18
19 // scoped_ptr functor for XFree(). Use as follows:
20 // scoped_ptr<XVisualInfo, ScopedPtrXFree> foo(...);
21 // where "XVisualInfo" is any X type that is freed with XFree.
22 struct ScopedPtrXFree {
23 void operator()(void* x) const { ::XFree(x); }
24 };
25
26 bool ValidFormat(unsigned internalformat) {
27 switch (internalformat) {
28 case GL_RGB:
29 case GL_RGBA:
30 return true;
31 default:
32 return false;
33 }
34 }
35
36 int TextureFormat(unsigned internalformat) {
37 switch (internalformat) {
38 case GL_RGB:
39 return GLX_TEXTURE_FORMAT_RGB_EXT;
40 case GL_RGBA:
41 return GLX_TEXTURE_FORMAT_RGBA_EXT;
42 default:
43 NOTREACHED();
44 return 0;
45 }
46 }
47
48 int BindToTextureFormat(unsigned internalformat) {
49 switch (internalformat) {
50 case GL_RGB:
51 return GLX_BIND_TO_TEXTURE_RGB_EXT;
52 case GL_RGBA:
53 return GLX_BIND_TO_TEXTURE_RGBA_EXT;
54 default:
55 NOTREACHED();
56 return 0;
57 }
58 }
59
60 unsigned PixmapDepth(unsigned internalformat) {
61 switch (internalformat) {
62 case GL_RGBA:
piman 2014/12/17 18:57:06 what about GL_RGB? It's handled in all other funct
llandwerlin-old 2014/12/17 21:24:59 Thanks, adding that.
63 return 32u;
64 default:
65 NOTREACHED();
66 return 0u;
67 }
68 }
69
70 bool ActualPixmapGeometry(XID pixmap, gfx::Size* size, unsigned* depth) {
71 XID root_return;
72 int x_return;
73 int y_return;
74 unsigned width_return;
75 unsigned height_return;
76 unsigned border_width_return;
77 unsigned depth_return;
78 if (!XGetGeometry(gfx::GetXDisplay(),
79 pixmap,
80 &root_return,
81 &x_return,
82 &y_return,
83 &width_return,
84 &height_return,
85 &border_width_return,
86 &depth_return))
87 return false;
88
89 if (size)
90 *size = gfx::Size(width_return, height_return);
91 if (depth)
92 *depth = depth_return;
93 return true;
94 }
95
96 unsigned ActualPixmapDepth(XID pixmap) {
97 unsigned depth;
98 if (!ActualPixmapGeometry(pixmap, NULL, &depth))
99 return -1;
100
101 return depth;
102 }
103
104 gfx::Size ActualPixmapSize(XID pixmap) {
105 gfx::Size size;
106 if (!ActualPixmapGeometry(pixmap, &size, NULL))
107 return gfx::Size();
108
109 return size;
110 }
111
112 } // namespace anonymous
113
114 GLImageGLX::GLImageGLX(const gfx::Size& size, unsigned internalformat)
115 : glx_pixmap_(0), size_(size), internalformat_(internalformat) {
116 }
117
118 GLImageGLX::~GLImageGLX() {
119 DCHECK_EQ(0u, glx_pixmap_);
120 }
121
122 bool GLImageGLX::Initialize(XID pixmap) {
123 if (!GLSurfaceGLX::IsTextureFromPixmapSupported()) {
124 DVLOG(0) << "GLX_EXT_texture_from_pixmap not supported.";
125 return false;
126 }
127
128 if (!ValidFormat(internalformat_)) {
129 DVLOG(0) << "Invalid format: " << internalformat_;
130 return false;
131 }
132
133 DCHECK_EQ(PixmapDepth(internalformat_), ActualPixmapDepth(pixmap));
134 DCHECK_EQ(size_.ToString(), ActualPixmapSize(pixmap).ToString());
135
136 int config_attribs[] = {
137 GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
138 GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_EXT,
139 BindToTextureFormat(internalformat_), GL_TRUE,
140 0};
141 int num_elements = 0;
142 scoped_ptr<GLXFBConfig, ScopedPtrXFree> config(
143 glXChooseFBConfig(gfx::GetXDisplay(),
144 DefaultScreen(gfx::GetXDisplay()),
145 config_attribs,
146 &num_elements));
147 if (!config.get()) {
148 DVLOG(0) << "glXChooseFBConfig failed.";
149 return false;
150 }
151 if (!num_elements) {
152 DVLOG(0) << "glXChooseFBConfig returned 0 elements.";
153 return false;
154 }
155
156 int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
157 GLX_TEXTURE_FORMAT_EXT,
158 TextureFormat(internalformat_), 0};
159 glx_pixmap_ = glXCreatePixmap(
160 gfx::GetXDisplay(), *config.get(), pixmap, pixmap_attribs);
161 if (!glx_pixmap_) {
162 DVLOG(0) << "glXCreatePixmap failed.";
163 return false;
164 }
165
166 return true;
167 }
168
169 void GLImageGLX::Destroy(bool have_context) {
170 if (glx_pixmap_) {
171 glXDestroyGLXPixmap(gfx::GetXDisplay(), glx_pixmap_);
172 glx_pixmap_ = 0;
173 }
174 }
175
176 gfx::Size GLImageGLX::GetSize() { return size_; }
177
178 bool GLImageGLX::BindTexImage(unsigned target) {
179 if (!glx_pixmap_)
180 return false;
181
182 // Requires TEXTURE_2D target.
183 if (target != GL_TEXTURE_2D)
184 return false;
185
186 glXBindTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0);
187 return true;
188 }
189
190 void GLImageGLX::ReleaseTexImage(unsigned target) {
191 DCHECK_NE(0u, glx_pixmap_);
192 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target);
193
194 glXReleaseTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT);
195 }
196
197 bool GLImageGLX::CopyTexImage(unsigned target) {
198 return false;
199 }
200
201 bool GLImageGLX::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
202 int z_order,
203 OverlayTransform transform,
204 const Rect& bounds_rect,
205 const RectF& crop_rect) {
206 return false;
207 }
208
209 } // namespace gfx
OLDNEW
« content/content_tests.gypi ('K') | « ui/gl/gl_image_glx.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698