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

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

Issue 2017623002: Create core profile contexts with WGL when --enable-unsafe-es3-apis is used. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/gl_bindings_autogen_wgl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This file implements the GLContextWGL and PbufferGLContext classes. 5 // This file implements the GLContextWGL and PbufferGLContext classes.
6 6
7 #include "ui/gl/gl_context_wgl.h" 7 #include "ui/gl/gl_context_wgl.h"
8 8
9 #include "base/command_line.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
11 #include "ui/gl/gl_bindings.h" 12 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_implementation.h" 13 #include "ui/gl/gl_implementation.h"
13 #include "ui/gl/gl_surface_wgl.h" 14 #include "ui/gl/gl_surface_wgl.h"
14 15
15 namespace gl { 16 namespace gl {
16 17
17 GLContextWGL::GLContextWGL(GLShareGroup* share_group) 18 GLContextWGL::GLContextWGL(GLShareGroup* share_group)
18 : GLContextReal(share_group), context_(nullptr) { 19 : GLContextReal(share_group), context_(nullptr) {
19 } 20 }
20 21
21 bool GLContextWGL::Initialize( 22 bool GLContextWGL::Initialize(
22 GLSurface* compatible_surface, GpuPreference gpu_preference) { 23 GLSurface* compatible_surface, GpuPreference gpu_preference) {
23 // Get the handle of another initialized context in the share group _before_ 24 // Get the handle of another initialized context in the share group _before_
24 // setting context_. Otherwise this context will be considered initialized 25 // setting context_. Otherwise this context will be considered initialized
25 // and could potentially be returned by GetHandle. 26 // and could potentially be returned by GetHandle.
26 HGLRC share_handle = static_cast<HGLRC>(share_group()->GetHandle()); 27 HGLRC share_handle = static_cast<HGLRC>(share_group()->GetHandle());
27 28
28 context_ = wglCreateContext( 29 HDC device_context = static_cast<HDC>(compatible_surface->GetHandle());
29 static_cast<HDC>(compatible_surface->GetHandle())); 30 bool has_wgl_create_context_arb =
31 strstr(wglGetExtensionsStringARB(device_context),
32 "WGL_ARB_create_context") != nullptr;
33 bool create_core_profile = has_wgl_create_context_arb &&
34 base::CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kEnableUnsafeES3APIs);
36
37 if (create_core_profile) {
38 std::pair<int, int> attempt_versions[] = {
39 {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2},
40 };
41
42 for (const auto& version : attempt_versions) {
43 const int attribs[] = {
44 WGL_CONTEXT_MAJOR_VERSION_ARB,
45 version.first,
46 WGL_CONTEXT_MINOR_VERSION_ARB,
47 version.second,
48 WGL_CONTEXT_PROFILE_MASK_ARB,
49 WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
50 0,
51 0,
52 };
53
54 context_ =
55 wglCreateContextAttribsARB(device_context, share_handle, attribs);
56 if (context_) {
57 break;
58 }
59 }
60 }
61
62 if (!context_) {
63 context_ = wglCreateContext(device_context);
64 }
30 if (!context_) { 65 if (!context_) {
31 LOG(ERROR) << "Failed to create GL context."; 66 LOG(ERROR) << "Failed to create GL context.";
32 Destroy(); 67 Destroy();
33 return false; 68 return false;
34 } 69 }
35 70
36 if (share_handle) { 71 if (share_handle) {
37 if (!wglShareLists(share_handle, context_)) { 72 if (!wglShareLists(share_handle, context_)) {
38 LOG(ERROR) << "Could not share GL contexts."; 73 LOG(ERROR) << "Could not share GL contexts.";
39 Destroy(); 74 Destroy();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 return GLContext::GetExtensions() + " " + extensions; 170 return GLContext::GetExtensions() + " " + extensions;
136 171
137 return GLContext::GetExtensions(); 172 return GLContext::GetExtensions();
138 } 173 }
139 174
140 GLContextWGL::~GLContextWGL() { 175 GLContextWGL::~GLContextWGL() {
141 Destroy(); 176 Destroy();
142 } 177 }
143 178
144 } // namespace gl 179 } // namespace gl
OLDNEW
« no previous file with comments | « ui/gl/gl_bindings_autogen_wgl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698