Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef ForceDiscreteGPUHelperCGL_h_
7 #define ForceDiscreteGPUHelperCGL_h_
9 #include <OpenGL/OpenGL.h>
11 /** This RAII helper guarantees that we're on the discrete GPU during its lifetime.
12 *
13 * As long as any ForceDiscreteGPUHelperCGL object is alive, we're on the discrete GPU.
14 */
15 class ForceDiscreteGPUHelperCGL
16 {
17 CGLPixelFormatObj mPixelFormatObj;
19 public:
20 ForceDiscreteGPUHelperCGL()
21 {
22 // the code in this function is taken from Chromium, src/ui/gfx/gl/gl_context_cgl.cc, r122013
23 // BSD-style license, (c) The Chromium Authors
24 CGLPixelFormatAttribute attribs[1];
25 attribs[0] = static_cast<CGLPixelFormatAttribute>(0);
26 GLint num_pixel_formats = 0;
27 CGLChoosePixelFormat(attribs, &mPixelFormatObj, &num_pixel_formats);
28 }
30 ~ForceDiscreteGPUHelperCGL()
31 {
32 CGLReleasePixelFormat(mPixelFormatObj);
33 }
34 };
36 #endif // ForceDiscreteGPUHelperCGL_h_