EME test page application.
[chromium-blink-merge.git] / ui / gl / gl_surface_cgl.cc
blob6c35693bdccdc2d4e6f1a5988735b0a47ef58264
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
3 // found in the LICENSE file.
5 #include "ui/gl/gl_surface_cgl.h"
7 #include <OpenGL/CGLRenderers.h>
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11 #include "base/mac/mac_util.h"
12 #include "ui/gl/gl_bindings.h"
13 #include "ui/gl/gl_context.h"
14 #include "ui/gl/gl_implementation.h"
15 #include "ui/gl/gpu_switching_manager.h"
17 namespace gfx {
19 namespace {
20 CGLPixelFormatObj g_pixel_format;
23 GLSurfaceCGL::GLSurfaceCGL() {}
25 bool GLSurfaceCGL::InitializeOneOff() {
26 static bool initialized = false;
27 if (initialized)
28 return true;
30 // This is called from the sandbox warmup code on Mac OS X.
31 // GPU-related stuff is very slow without this, probably because
32 // the sandbox prevents loading graphics drivers or some such.
33 std::vector<CGLPixelFormatAttribute> attribs;
34 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
35 // Avoid switching to the discrete GPU just for this pixel
36 // format selection.
37 attribs.push_back(kCGLPFAAllowOfflineRenderers);
39 if (GetGLImplementation() == kGLImplementationAppleGL) {
40 attribs.push_back(kCGLPFARendererID);
41 attribs.push_back(static_cast<CGLPixelFormatAttribute>(
42 kCGLRendererGenericFloatID));
44 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0));
46 CGLPixelFormatObj format;
47 GLint num_pixel_formats;
48 if (CGLChoosePixelFormat(&attribs.front(),
49 &format,
50 &num_pixel_formats) != kCGLNoError) {
51 LOG(ERROR) << "Error choosing pixel format.";
52 return false;
54 if (!format) {
55 LOG(ERROR) << "format == 0.";
56 return false;
58 CGLReleasePixelFormat(format);
59 DCHECK_NE(num_pixel_formats, 0);
60 initialized = true;
61 return true;
64 void* GLSurfaceCGL::GetPixelFormat() {
65 return g_pixel_format;
68 GLSurfaceCGL::~GLSurfaceCGL() {}
70 NoOpGLSurfaceCGL::NoOpGLSurfaceCGL(const gfx::Size& size)
71 : size_(size) {
74 bool NoOpGLSurfaceCGL::Initialize() {
75 return true;
78 void NoOpGLSurfaceCGL::Destroy() {
81 bool NoOpGLSurfaceCGL::IsOffscreen() {
82 return true;
85 bool NoOpGLSurfaceCGL::SwapBuffers() {
86 NOTREACHED() << "Cannot call SwapBuffers on a NoOpGLSurfaceCGL.";
87 return false;
90 gfx::Size NoOpGLSurfaceCGL::GetSize() {
91 return size_;
94 void* NoOpGLSurfaceCGL::GetHandle() {
95 return NULL;
98 void* NoOpGLSurfaceCGL::GetDisplay() {
99 return NULL;
102 NoOpGLSurfaceCGL::~NoOpGLSurfaceCGL() {
103 Destroy();
106 } // namespace gfx