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 "ui/gl/gl_surface_glx.h" | 9 #include "ui/gl/gl_surface_glx.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "ui/gfx/x/x11_connection.h" | 26 #include "ui/gfx/x/x11_connection.h" |
27 #include "ui/gfx/x/x11_types.h" | 27 #include "ui/gfx/x/x11_types.h" |
28 #include "ui/gl/gl_bindings.h" | 28 #include "ui/gl/gl_bindings.h" |
29 #include "ui/gl/gl_implementation.h" | 29 #include "ui/gl/gl_implementation.h" |
30 #include "ui/gl/sync_control_vsync_provider.h" | 30 #include "ui/gl/sync_control_vsync_provider.h" |
31 | 31 |
32 namespace gfx { | 32 namespace gfx { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 // scoped_ptr functor for XFree(). Use as follows: | |
37 // scoped_ptr<XVisualInfo, ScopedPtrXFree> foo(...); | |
38 // where "XVisualInfo" is any X type that is freed with XFree. | |
39 struct ScopedPtrXFree { | |
40 void operator()(void* x) const { | |
41 ::XFree(x); | |
42 } | |
43 }; | |
44 | |
45 Display* g_display = NULL; | 36 Display* g_display = NULL; |
46 const char* g_glx_extensions = NULL; | 37 const char* g_glx_extensions = NULL; |
47 bool g_glx_context_create = false; | 38 bool g_glx_context_create = false; |
48 bool g_glx_create_context_robustness_supported = false; | 39 bool g_glx_create_context_robustness_supported = false; |
49 bool g_glx_texture_from_pixmap_supported = false; | 40 bool g_glx_texture_from_pixmap_supported = false; |
50 bool g_glx_oml_sync_control_supported = false; | 41 bool g_glx_oml_sync_control_supported = false; |
51 | 42 |
52 // Track support of glXGetMscRateOML separately from GLX_OML_sync_control as a | 43 // Track support of glXGetMscRateOML separately from GLX_OML_sync_control as a |
53 // whole since on some platforms (e.g. crosbug.com/34585), glXGetMscRateOML | 44 // whole since on some platforms (e.g. crosbug.com/34585), glXGetMscRateOML |
54 // always fails even though GLX_OML_sync_control is reported as being supported. | 45 // always fails even though GLX_OML_sync_control is reported as being supported. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 if (!XGetWindowAttributes(display_, window_, &attributes)) { | 164 if (!XGetWindowAttributes(display_, window_, &attributes)) { |
174 LOG(ERROR) << "XGetWindowAttributes failed for window " << | 165 LOG(ERROR) << "XGetWindowAttributes failed for window " << |
175 window_ << "."; | 166 window_ << "."; |
176 return; | 167 return; |
177 } | 168 } |
178 | 169 |
179 XVisualInfo visual_info_template; | 170 XVisualInfo visual_info_template; |
180 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); | 171 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); |
181 | 172 |
182 int visual_info_count = 0; | 173 int visual_info_count = 0; |
183 scoped_ptr<XVisualInfo, ScopedPtrXFree> visual_info_list( | 174 gfx::XScopedPtr<XVisualInfo> visual_info_list(XGetVisualInfo( |
184 XGetVisualInfo(display_, VisualIDMask, | 175 display_, VisualIDMask, &visual_info_template, &visual_info_count)); |
185 &visual_info_template, &visual_info_count)); | |
186 | 176 |
187 DCHECK(visual_info_list.get()); | 177 DCHECK(visual_info_list.get()); |
188 if (visual_info_count == 0) { | 178 if (visual_info_count == 0) { |
189 LOG(ERROR) << "No visual info for visual ID."; | 179 LOG(ERROR) << "No visual info for visual ID."; |
190 return; | 180 return; |
191 } | 181 } |
192 | 182 |
193 context_ = glXCreateContext(display_, visual_info_list.get(), NULL, True); | 183 context_ = glXCreateContext(display_, visual_info_list.get(), NULL, True); |
194 | 184 |
195 DCHECK(NULL != context_); | 185 DCHECK(NULL != context_); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 window_, | 536 window_, |
547 &attributes)) { | 537 &attributes)) { |
548 LOG(ERROR) << "XGetWindowAttributes failed for window " << | 538 LOG(ERROR) << "XGetWindowAttributes failed for window " << |
549 window_ << "."; | 539 window_ << "."; |
550 return NULL; | 540 return NULL; |
551 } | 541 } |
552 | 542 |
553 int visual_id = XVisualIDFromVisual(attributes.visual); | 543 int visual_id = XVisualIDFromVisual(attributes.visual); |
554 | 544 |
555 int num_elements = 0; | 545 int num_elements = 0; |
556 scoped_ptr<GLXFBConfig, ScopedPtrXFree> configs( | 546 gfx::XScopedPtr<GLXFBConfig> configs( |
557 glXGetFBConfigs(g_display, | 547 glXGetFBConfigs(g_display, DefaultScreen(g_display), &num_elements)); |
558 DefaultScreen(g_display), | |
559 &num_elements)); | |
560 if (!configs.get()) { | 548 if (!configs.get()) { |
561 LOG(ERROR) << "glXGetFBConfigs failed."; | 549 LOG(ERROR) << "glXGetFBConfigs failed."; |
562 return NULL; | 550 return NULL; |
563 } | 551 } |
564 if (!num_elements) { | 552 if (!num_elements) { |
565 LOG(ERROR) << "glXGetFBConfigs returned 0 elements."; | 553 LOG(ERROR) << "glXGetFBConfigs returned 0 elements."; |
566 return NULL; | 554 return NULL; |
567 } | 555 } |
568 bool found = false; | 556 bool found = false; |
569 int i; | 557 int i; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 GLX_BLUE_SIZE, 8, | 609 GLX_BLUE_SIZE, 8, |
622 GLX_GREEN_SIZE, 8, | 610 GLX_GREEN_SIZE, 8, |
623 GLX_RED_SIZE, 8, | 611 GLX_RED_SIZE, 8, |
624 GLX_RENDER_TYPE, GLX_RGBA_BIT, | 612 GLX_RENDER_TYPE, GLX_RGBA_BIT, |
625 GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, | 613 GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, |
626 GLX_DOUBLEBUFFER, False, | 614 GLX_DOUBLEBUFFER, False, |
627 0 | 615 0 |
628 }; | 616 }; |
629 | 617 |
630 int num_elements = 0; | 618 int num_elements = 0; |
631 scoped_ptr<GLXFBConfig, ScopedPtrXFree> configs( | 619 gfx::XScopedPtr<GLXFBConfig> configs(glXChooseFBConfig( |
632 glXChooseFBConfig(g_display, | 620 g_display, DefaultScreen(g_display), config_attributes, &num_elements)); |
633 DefaultScreen(g_display), | |
634 config_attributes, | |
635 &num_elements)); | |
636 if (!configs.get()) { | 621 if (!configs.get()) { |
637 LOG(ERROR) << "glXChooseFBConfig failed."; | 622 LOG(ERROR) << "glXChooseFBConfig failed."; |
638 return false; | 623 return false; |
639 } | 624 } |
640 if (!num_elements) { | 625 if (!num_elements) { |
641 LOG(ERROR) << "glXChooseFBConfig returned 0 elements."; | 626 LOG(ERROR) << "glXChooseFBConfig returned 0 elements."; |
642 return false; | 627 return false; |
643 } | 628 } |
644 | 629 |
645 config_ = configs.get()[0]; | 630 config_ = configs.get()[0]; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 | 674 |
690 void* PbufferGLSurfaceGLX::GetConfig() { | 675 void* PbufferGLSurfaceGLX::GetConfig() { |
691 return config_; | 676 return config_; |
692 } | 677 } |
693 | 678 |
694 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { | 679 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { |
695 Destroy(); | 680 Destroy(); |
696 } | 681 } |
697 | 682 |
698 } // namespace gfx | 683 } // namespace gfx |
OLD | NEW |