blob: 7cd54618669365158cbc37b3a19acdad81a34ba4 [file] [log] [blame]
[email protected]52dd2f842012-02-01 00:07:211// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ffae4022011-05-12 22:54:292// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]c9e2cbbb2012-05-12 21:17:275#include "ui/gl/gl_surface.h"
[email protected]ffae4022011-05-12 22:54:296
[email protected]3551cb202012-05-24 10:55:327#include "base/debug/trace_event.h"
[email protected]ffae4022011-05-12 22:54:298#include "base/logging.h"
9#include "base/memory/scoped_ptr.h"
[email protected]08431562013-06-08 05:34:1910#include "third_party/mesa/src/include/GL/osmesa.h"
[email protected]c9e2cbbb2012-05-12 21:17:2711#include "ui/gl/gl_bindings.h"
12#include "ui/gl/gl_implementation.h"
13#include "ui/gl/gl_surface_cgl.h"
14#include "ui/gl/gl_surface_osmesa.h"
15#include "ui/gl/gl_surface_stub.h"
[email protected]ffae4022011-05-12 22:54:2916
[email protected]2f47fc452011-11-21 03:12:1717#if defined(USE_AURA)
[email protected]c9e2cbbb2012-05-12 21:17:2718#include "ui/gl/gl_surface_nsview.h"
[email protected]2f47fc452011-11-21 03:12:1719#endif
20
[email protected]ffae4022011-05-12 22:54:2921namespace gfx {
22
[email protected]0f5e8882011-11-08 22:29:3823bool GLSurface::InitializeOneOffInternal() {
[email protected]ffae4022011-05-12 22:54:2924 switch (GetGLImplementation()) {
25 case kGLImplementationDesktopGL:
[email protected]020d047e2011-12-07 19:15:4226 case kGLImplementationAppleGL:
[email protected]ffae4022011-05-12 22:54:2927 if (!GLSurfaceCGL::InitializeOneOff()) {
28 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
29 return false;
30 }
31 break;
32 default:
33 break;
34 }
[email protected]ffae4022011-05-12 22:54:2935 return true;
36}
37
[email protected]fbe20372011-06-01 01:46:3838scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
[email protected]52dd2f842012-02-01 00:07:2139 gfx::AcceleratedWidget window) {
[email protected]3551cb202012-05-24 10:55:3240 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface");
[email protected]2f47fc452011-11-21 03:12:1741#if defined(USE_AURA)
[email protected]2f47fc452011-11-21 03:12:1742 switch (GetGLImplementation()) {
[email protected]020d047e2011-12-07 19:15:4243 case kGLImplementationDesktopGL:
44 case kGLImplementationAppleGL: {
[email protected]2f47fc452011-11-21 03:12:1745 scoped_refptr<GLSurface> surface(new GLSurfaceNSView(window));
46 if (!surface->Initialize())
47 return NULL;
48
49 return surface;
50 }
51 case kGLImplementationMockGL:
52 return new GLSurfaceStub;
53 default:
54 NOTREACHED();
55 return NULL;
56 }
57#else
[email protected]658f03f2013-06-17 18:28:0958 return CreateOffscreenGLSurface(gfx::Size(1, 1));
[email protected]2f47fc452011-11-21 03:12:1759#endif
[email protected]ffae4022011-05-12 22:54:2960}
[email protected]ffae4022011-05-12 22:54:2961
[email protected]fbe20372011-06-01 01:46:3862scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
63 const gfx::Size& size) {
[email protected]3551cb202012-05-24 10:55:3264 TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface");
[email protected]ffae4022011-05-12 22:54:2965 switch (GetGLImplementation()) {
66 case kGLImplementationOSMesaGL: {
[email protected]fbe20372011-06-01 01:46:3867 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
68 size));
[email protected]ffae4022011-05-12 22:54:2969 if (!surface->Initialize())
70 return NULL;
71
[email protected]fbe20372011-06-01 01:46:3872 return surface;
[email protected]ffae4022011-05-12 22:54:2973 }
[email protected]020d047e2011-12-07 19:15:4274 case kGLImplementationDesktopGL:
75 case kGLImplementationAppleGL: {
[email protected]51e6f6a72011-12-21 19:42:5576 scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size));
[email protected]ffae4022011-05-12 22:54:2977 if (!surface->Initialize())
78 return NULL;
79
[email protected]fbe20372011-06-01 01:46:3880 return surface;
[email protected]ffae4022011-05-12 22:54:2981 }
82 case kGLImplementationMockGL:
83 return new GLSurfaceStub;
84 default:
85 NOTREACHED();
86 return NULL;
87 }
88}
89
90} // namespace gfx