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.h"
7 #include "base/debug/trace_event.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "third_party/mesa/src/include/GL/osmesa.h"
11 #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"
16 #include "ui/gl/gl_surface_nsview.h"
20 bool GLSurface::InitializeOneOffInternal() {
21 switch (GetGLImplementation()) {
22 case kGLImplementationDesktopGL
:
23 case kGLImplementationAppleGL
:
24 if (!GLSurfaceCGL::InitializeOneOff()) {
25 LOG(ERROR
) << "GLSurfaceCGL::InitializeOneOff failed.";
35 scoped_refptr
<GLSurface
> GLSurface::CreateViewGLSurface(
36 gfx::AcceleratedWidget window
) {
37 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface");
38 switch (GetGLImplementation()) {
39 case kGLImplementationDesktopGL
:
40 case kGLImplementationAppleGL
: {
41 scoped_refptr
<GLSurface
> surface(new GLSurfaceNSView(window
));
42 if (!surface
->Initialize())
47 case kGLImplementationMockGL
:
48 return new GLSurfaceStub
;
55 scoped_refptr
<GLSurface
> GLSurface::CreateOffscreenGLSurface(
56 const gfx::Size
& size
) {
57 TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface");
58 switch (GetGLImplementation()) {
59 case kGLImplementationOSMesaGL
: {
60 scoped_refptr
<GLSurface
> surface(new GLSurfaceOSMesa(OSMESA_RGBA
,
62 if (!surface
->Initialize())
67 case kGLImplementationDesktopGL
:
68 case kGLImplementationAppleGL
: {
69 scoped_refptr
<GLSurface
> surface(new NoOpGLSurfaceCGL(size
));
70 if (!surface
->Initialize())
75 case kGLImplementationMockGL
:
76 return new GLSurfaceStub
;