OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #include "ui/gl/init/gl_initializer.h" |
| 6 |
| 7 #include <OpenGL/CGLRenderers.h> |
| 8 |
| 9 #include <vector> |
| 10 |
| 11 #include "base/logging.h" |
| 12 #include "ui/gl/gl_bindings.h" |
| 13 #include "ui/gl/gl_implementation.h" |
| 14 #include "ui/gl/gl_surface.h" |
| 15 #include "ui/gl/gpu_switching_manager.h" |
| 16 |
| 17 namespace gl { |
| 18 namespace init { |
| 19 |
| 20 namespace { |
| 21 |
| 22 bool InitializeOneOffForSandbox() { |
| 23 static bool initialized = false; |
| 24 if (initialized) |
| 25 return true; |
| 26 |
| 27 // This is called from the sandbox warmup code on Mac OS X. |
| 28 // GPU-related stuff is very slow without this, probably because |
| 29 // the sandbox prevents loading graphics drivers or some such. |
| 30 std::vector<CGLPixelFormatAttribute> attribs; |
| 31 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { |
| 32 // Avoid switching to the discrete GPU just for this pixel |
| 33 // format selection. |
| 34 attribs.push_back(kCGLPFAAllowOfflineRenderers); |
| 35 } |
| 36 if (GetGLImplementation() == kGLImplementationAppleGL) { |
| 37 attribs.push_back(kCGLPFARendererID); |
| 38 attribs.push_back( |
| 39 static_cast<CGLPixelFormatAttribute>(kCGLRendererGenericFloatID)); |
| 40 } |
| 41 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0)); |
| 42 |
| 43 CGLPixelFormatObj format; |
| 44 GLint num_pixel_formats; |
| 45 if (CGLChoosePixelFormat(&attribs.front(), &format, &num_pixel_formats) != |
| 46 kCGLNoError) { |
| 47 LOG(ERROR) << "Error choosing pixel format."; |
| 48 return false; |
| 49 } |
| 50 if (!format) { |
| 51 LOG(ERROR) << "format == 0."; |
| 52 return false; |
| 53 } |
| 54 CGLReleasePixelFormat(format); |
| 55 DCHECK_NE(num_pixel_formats, 0); |
| 56 initialized = true; |
| 57 return true; |
| 58 } |
| 59 |
| 60 } // namespace |
| 61 |
| 62 bool InitializeGLOneOffPlatform() { |
| 63 switch (GetGLImplementation()) { |
| 64 case kGLImplementationDesktopGL: |
| 65 case kGLImplementationDesktopGLCoreProfile: |
| 66 case kGLImplementationAppleGL: |
| 67 if (!InitializeOneOffForSandbox()) { |
| 68 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; |
| 69 return false; |
| 70 } |
| 71 return true; |
| 72 default: |
| 73 return true; |
| 74 } |
| 75 } |
| 76 |
| 77 } // namespace init |
| 78 } // namespace gl |
OLD | NEW |