blob: 4af014ae965526dcb52cbc10a8b682e00ab56317 [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
53GLSurface* GLSurface::CreateViewGLSurface(gfx::PluginWindowHandle window) {
54 switch (GetGLImplementation()) {
55 case kGLImplementationOSMesaGL: {
56 scoped_ptr<NativeViewGLSurfaceOSMesa> surface(
57 new NativeViewGLSurfaceOSMesa(window));
58 if (!surface->Initialize())
59 return NULL;
60
61 return surface.release();
62 }
63 case kGLImplementationDesktopGL: {
64 scoped_ptr<NativeViewGLSurfaceCGL> surface(new NativeViewGLSurfaceCGL(
65 window));
66 if (!surface->Initialize())
67 return NULL;
68
69 return surface.release();
70 }
71 case kGLImplementationMockGL:
72 return new GLSurfaceStub;
73 default:
74 NOTREACHED();
75 return NULL;
76 }
77}
78#endif
79
80GLSurface* GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) {
81 switch (GetGLImplementation()) {
82 case kGLImplementationOSMesaGL: {
83 scoped_ptr<GLSurfaceOSMesa> surface(new GLSurfaceOSMesa(size));
84 if (!surface->Initialize())
85 return NULL;
86
87 return surface.release();
88 }
89 case kGLImplementationDesktopGL: {
90 scoped_ptr<PbufferGLSurfaceCGL> surface(new PbufferGLSurfaceCGL(size));
91 if (!surface->Initialize())
92 return NULL;
93
94 return surface.release();
95 }
96 case kGLImplementationMockGL:
97 return new GLSurfaceStub;
98 default:
99 NOTREACHED();
100 return NULL;
101 }
102}
103
104} // namespace gfx