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

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

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

Powered by Google App Engine
This is Rietveld 408576698