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

Side by Side Diff: ui/gl/init/gl_initializer_mac.cc

Issue 2024953002: Move GL one-off initialization code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split_x11
Patch Set: Delete GLInitializer class. Created 4 years, 6 months 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
« no previous file with comments | « ui/gl/init/gl_initializer_android.cc ('k') | ui/gl/init/gl_initializer_ozone.cc » ('j') | 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 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
OLDNEW
« no previous file with comments | « ui/gl/init/gl_initializer_android.cc ('k') | ui/gl/init/gl_initializer_ozone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698