OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This file implements the ViewGLContext and PbufferGLContext classes. | 5 // This file implements the ViewGLContext and PbufferGLContext classes. |
6 | 6 |
7 #include "app/gfx/gl/gl_context.h" | 7 #include "app/gfx/gl/gl_context.h" |
8 | 8 |
9 #include <GL/osmesa.h> | 9 #include <GL/osmesa.h> |
10 | 10 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 virtual void* GetHandle(); | 135 virtual void* GetHandle(); |
136 | 136 |
137 private: | 137 private: |
138 GLContextHandle context_; | 138 GLContextHandle context_; |
139 Pixmap pixmap_; | 139 Pixmap pixmap_; |
140 GLXPixmap glx_pixmap_; | 140 GLXPixmap glx_pixmap_; |
141 | 141 |
142 DISALLOW_COPY_AND_ASSIGN(PixmapGLContext); | 142 DISALLOW_COPY_AND_ASSIGN(PixmapGLContext); |
143 }; | 143 }; |
144 | 144 |
145 // scoped_ptr functor for XFree(). Use as follows: | |
146 // scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> foo(...); | |
147 // where "XVisualInfo" is any X type that is freed with XFree. | |
148 class ScopedPtrXFree { | |
149 public: | |
150 void operator()(void* x) const { | |
151 ::XFree(x); | |
152 } | |
153 }; | |
154 | |
155 bool GLContext::InitializeOneOff() { | 145 bool GLContext::InitializeOneOff() { |
156 static bool initialized = false; | 146 static bool initialized = false; |
157 if (initialized) | 147 if (initialized) |
158 return true; | 148 return true; |
159 | 149 |
160 static const GLImplementation kAllowedGLImplementations[] = { | 150 static const GLImplementation kAllowedGLImplementations[] = { |
161 kGLImplementationEGLGLES2, | 151 kGLImplementationEGLGLES2, |
162 kGLImplementationDesktopGL, | 152 kGLImplementationDesktopGL, |
163 kGLImplementationOSMesaGL | 153 kGLImplementationOSMesaGL |
164 }; | 154 }; |
(...skipping 27 matching lines...) Expand all Loading... |
192 if (multisampled) { | 182 if (multisampled) { |
193 LOG(WARNING) << "Multisampling not implemented."; | 183 LOG(WARNING) << "Multisampling not implemented."; |
194 } | 184 } |
195 | 185 |
196 Display* display = x11_util::GetXDisplay(); | 186 Display* display = x11_util::GetXDisplay(); |
197 XWindowAttributes attributes; | 187 XWindowAttributes attributes; |
198 XGetWindowAttributes(display, window_, &attributes); | 188 XGetWindowAttributes(display, window_, &attributes); |
199 XVisualInfo visual_info_template; | 189 XVisualInfo visual_info_template; |
200 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); | 190 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); |
201 int visual_info_count = 0; | 191 int visual_info_count = 0; |
202 scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info_list( | 192 scoped_ptr_malloc<XVisualInfo, FreeFnAdapterIgnoreReturn< ::XFree> > visual_in
fo_list( |
203 XGetVisualInfo(display, VisualIDMask, | 193 XGetVisualInfo(display, VisualIDMask, |
204 &visual_info_template, | 194 &visual_info_template, |
205 &visual_info_count)); | 195 &visual_info_count)); |
206 DCHECK(visual_info_list.get()); | 196 DCHECK(visual_info_list.get()); |
207 DCHECK_GT(visual_info_count, 0); | 197 DCHECK_GT(visual_info_count, 0); |
208 context_ = NULL; | 198 context_ = NULL; |
209 for (int i = 0; i < visual_info_count; ++i) { | 199 for (int i = 0; i < visual_info_count; ++i) { |
210 context_ = glXCreateContext(display, visual_info_list.get() + i, 0, True); | 200 context_ = glXCreateContext(display, visual_info_list.get() + i, 0, True); |
211 if (context_) | 201 if (context_) |
212 break; | 202 break; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 GLX_RGBA_BIT, | 463 GLX_RGBA_BIT, |
474 GLX_DOUBLEBUFFER, | 464 GLX_DOUBLEBUFFER, |
475 0, | 465 0, |
476 0 | 466 0 |
477 }; | 467 }; |
478 | 468 |
479 Display* display = x11_util::GetXDisplay(); | 469 Display* display = x11_util::GetXDisplay(); |
480 | 470 |
481 int nelements = 0; | 471 int nelements = 0; |
482 // TODO(kbr): figure out whether hardcoding screen to 0 is sufficient. | 472 // TODO(kbr): figure out whether hardcoding screen to 0 is sufficient. |
483 scoped_ptr_malloc<GLXFBConfig, ScopedPtrXFree> config( | 473 scoped_ptr_malloc<GLXFBConfig, FreeFnAdapterIgnoreReturn< ::XFree> > config( |
484 glXChooseFBConfig(display, 0, config_attributes, &nelements)); | 474 glXChooseFBConfig(display, 0, config_attributes, &nelements)); |
485 if (!config.get()) { | 475 if (!config.get()) { |
486 LOG(ERROR) << "glXChooseFBConfig failed."; | 476 LOG(ERROR) << "glXChooseFBConfig failed."; |
487 return false; | 477 return false; |
488 } | 478 } |
489 if (!nelements) { | 479 if (!nelements) { |
490 LOG(ERROR) << "glXChooseFBConfig returned 0 elements."; | 480 LOG(ERROR) << "glXChooseFBConfig returned 0 elements."; |
491 return false; | 481 return false; |
492 } | 482 } |
493 | 483 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 LOG(INFO) << "GL context: using pixmaps."; | 582 LOG(INFO) << "GL context: using pixmaps."; |
593 | 583 |
594 static int attributes[] = { | 584 static int attributes[] = { |
595 GLX_RGBA, | 585 GLX_RGBA, |
596 0 | 586 0 |
597 }; | 587 }; |
598 | 588 |
599 Display* display = x11_util::GetXDisplay(); | 589 Display* display = x11_util::GetXDisplay(); |
600 int screen = DefaultScreen(display); | 590 int screen = DefaultScreen(display); |
601 | 591 |
602 scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info( | 592 scoped_ptr_malloc<XVisualInfo, FreeFnAdapterIgnoreReturn< ::XFree> > visual_in
fo( |
603 glXChooseVisual(display, screen, attributes)); | 593 glXChooseVisual(display, screen, attributes)); |
604 | 594 |
605 if (!visual_info.get()) { | 595 if (!visual_info.get()) { |
606 LOG(ERROR) << "glXChooseVisual failed."; | 596 LOG(ERROR) << "glXChooseVisual failed."; |
607 return false; | 597 return false; |
608 } | 598 } |
609 | 599 |
610 GLContextHandle shared_handle = NULL; | 600 GLContextHandle shared_handle = NULL; |
611 if (shared_context) | 601 if (shared_context) |
612 shared_handle = static_cast<GLContextHandle>(shared_context->GetHandle()); | 602 shared_handle = static_cast<GLContextHandle>(shared_context->GetHandle()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 } | 724 } |
735 case kGLImplementationMockGL: | 725 case kGLImplementationMockGL: |
736 return new StubGLContext; | 726 return new StubGLContext; |
737 default: | 727 default: |
738 NOTREACHED(); | 728 NOTREACHED(); |
739 return NULL; | 729 return NULL; |
740 } | 730 } |
741 } | 731 } |
742 | 732 |
743 } // namespace gfx | 733 } // namespace gfx |
OLD | NEW |