blob: 2367679ba6e49732009567e721080c66099a4344 [file] [log] [blame]
[email protected]ffae4022011-05-12 22:54:291// Copyright (c) 2011 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/gfx/gl/gl_surface.h"
6
7#include "base/logging.h"
8#include "base/memory/scoped_ptr.h"
9#include "third_party/mesa/MesaLib/include/GL/osmesa.h"
10#include "ui/gfx/gl/gl_bindings.h"
11#include "ui/gfx/gl/gl_implementation.h"
12#include "ui/gfx/gl/gl_surface_cgl.h"
13#include "ui/gfx/gl/gl_surface_osmesa.h"
14#include "ui/gfx/gl/gl_surface_stub.h"
15
16namespace gfx {
17
18bool GLSurface::InitializeOneOff() {
19 static bool initialized = false;
20 if (initialized)
21 return true;
22
23 static const GLImplementation kAllowedGLImplementations[] = {
24 kGLImplementationDesktopGL,
25 kGLImplementationOSMesaGL
26 };
27
28 if (!InitializeRequestedGLBindings(
29 kAllowedGLImplementations,
30 kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
31 kGLImplementationDesktopGL)) {
32 LOG(ERROR) << "InitializeRequestedGLBindings failed.";
33 return false;
34 }
35
36 switch (GetGLImplementation()) {
37 case kGLImplementationDesktopGL:
38 if (!GLSurfaceCGL::InitializeOneOff()) {
39 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
40 return false;
41 }
42 break;
43 default:
44 break;
45 }
46
47 initialized = true;
48 return true;
49}
50
51// TODO(apatrick): support ViewGLSurface on mac.
52#if 0
[email protected]fbe20372011-06-01 01:46:3853scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
54 gfx::PluginWindowHandle window) {
[email protected]ffae4022011-05-12 22:54:2955 switch (GetGLImplementation()) {
56 case kGLImplementationOSMesaGL: {
[email protected]fbe20372011-06-01 01:46:3857 scoped_refptr<GLSurface> surface(
[email protected]ffae4022011-05-12 22:54:2958 new NativeViewGLSurfaceOSMesa(window));
59 if (!surface->Initialize())
60 return NULL;
61
[email protected]fbe20372011-06-01 01:46:3862 return surface;
[email protected]ffae4022011-05-12 22:54:2963 }
64 case kGLImplementationDesktopGL: {
[email protected]fbe20372011-06-01 01:46:3865 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceCGL(
[email protected]ffae4022011-05-12 22:54:2966 window));
67 if (!surface->Initialize())
68 return NULL;
69
[email protected]fbe20372011-06-01 01:46:3870 return surface;
[email protected]ffae4022011-05-12 22:54:2971 }
72 case kGLImplementationMockGL:
73 return new GLSurfaceStub;
74 default:
75 NOTREACHED();
76 return NULL;
77 }
78}
79#endif
80
[email protected]fbe20372011-06-01 01:46:3881scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
82 const gfx::Size& size) {
[email protected]ffae4022011-05-12 22:54:2983 switch (GetGLImplementation()) {
84 case kGLImplementationOSMesaGL: {
[email protected]fbe20372011-06-01 01:46:3885 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
86 size));
[email protected]ffae4022011-05-12 22:54:2987 if (!surface->Initialize())
88 return NULL;
89
[email protected]fbe20372011-06-01 01:46:3890 return surface;
[email protected]ffae4022011-05-12 22:54:2991 }
92 case kGLImplementationDesktopGL: {
[email protected]fbe20372011-06-01 01:46:3893 scoped_refptr<GLSurface> surface(new PbufferGLSurfaceCGL(size));
[email protected]ffae4022011-05-12 22:54:2994 if (!surface->Initialize())
95 return NULL;
96
[email protected]fbe20372011-06-01 01:46:3897 return surface;
[email protected]ffae4022011-05-12 22:54:2998 }
99 case kGLImplementationMockGL:
100 return new GLSurfaceStub;
101 default:
102 NOTREACHED();
103 return NULL;
104 }
105}
106
107} // namespace gfx