blob: aeb33666b29d53d4bd4f004c9bb460362592fccb [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
[email protected]2f47fc452011-11-21 03:12:1716#if defined(USE_AURA)
17#include "ui/gfx/gl/gl_surface_nsview.h"
18#endif
19
[email protected]ffae4022011-05-12 22:54:2920namespace gfx {
21
[email protected]0f5e8882011-11-08 22:29:3822bool GLSurface::InitializeOneOffInternal() {
[email protected]ffae4022011-05-12 22:54:2923 switch (GetGLImplementation()) {
24 case kGLImplementationDesktopGL:
[email protected]020d047e2011-12-07 19:15:4225 case kGLImplementationAppleGL:
[email protected]ffae4022011-05-12 22:54:2926 if (!GLSurfaceCGL::InitializeOneOff()) {
27 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
28 return false;
29 }
30 break;
31 default:
32 break;
33 }
[email protected]ffae4022011-05-12 22:54:2934 return true;
35}
36
[email protected]fbe20372011-06-01 01:46:3837scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
[email protected]79311e82011-09-20 00:40:5038 bool software,
[email protected]fbe20372011-06-01 01:46:3839 gfx::PluginWindowHandle window) {
[email protected]2f47fc452011-11-21 03:12:1740#if defined(USE_AURA)
41 if (software)
42 return NULL;
43
44 switch (GetGLImplementation()) {
[email protected]020d047e2011-12-07 19:15:4245 case kGLImplementationDesktopGL:
46 case kGLImplementationAppleGL: {
[email protected]2f47fc452011-11-21 03:12:1747 scoped_refptr<GLSurface> surface(new GLSurfaceNSView(window));
48 if (!surface->Initialize())
49 return NULL;
50
51 return surface;
52 }
53 case kGLImplementationMockGL:
54 return new GLSurfaceStub;
55 default:
56 NOTREACHED();
57 return NULL;
58 }
59#else
60 return CreateOffscreenGLSurface(software, gfx::Size(1,1));
61#endif
[email protected]ffae4022011-05-12 22:54:2962}
[email protected]ffae4022011-05-12 22:54:2963
[email protected]fbe20372011-06-01 01:46:3864scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
[email protected]f81f5952011-07-21 18:52:4765 bool software,
[email protected]fbe20372011-06-01 01:46:3866 const gfx::Size& size) {
[email protected]f81f5952011-07-21 18:52:4767 if (software)
68 return NULL;
69
[email protected]ffae4022011-05-12 22:54:2970 switch (GetGLImplementation()) {
71 case kGLImplementationOSMesaGL: {
[email protected]fbe20372011-06-01 01:46:3872 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
73 size));
[email protected]ffae4022011-05-12 22:54:2974 if (!surface->Initialize())
75 return NULL;
76
[email protected]fbe20372011-06-01 01:46:3877 return surface;
[email protected]ffae4022011-05-12 22:54:2978 }
[email protected]020d047e2011-12-07 19:15:4279 case kGLImplementationDesktopGL:
80 case kGLImplementationAppleGL: {
[email protected]51e6f6a72011-12-21 19:42:5581 scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size));
[email protected]ffae4022011-05-12 22:54:2982 if (!surface->Initialize())
83 return NULL;
84
[email protected]fbe20372011-06-01 01:46:3885 return surface;
[email protected]ffae4022011-05-12 22:54:2986 }
87 case kGLImplementationMockGL:
88 return new GLSurfaceStub;
89 default:
90 NOTREACHED();
91 return NULL;
92 }
93}
94
95} // namespace gfx