Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ui / gl / gl_surface_mac.cc
blobdf542a152636f9510980944deeec9587b07296ff
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/MesaLib/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"
17 #if defined(USE_AURA)
18 #include "ui/gl/gl_surface_nsview.h"
19 #endif
21 namespace gfx {
23 bool GLSurface::InitializeOneOffInternal() {
24 switch (GetGLImplementation()) {
25 case kGLImplementationDesktopGL:
26 case kGLImplementationAppleGL:
27 if (!GLSurfaceCGL::InitializeOneOff()) {
28 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
29 return false;
31 break;
32 default:
33 break;
35 return true;
38 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
39 bool software,
40 gfx::AcceleratedWidget window) {
41 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface");
42 #if defined(USE_AURA)
43 if (software)
44 return NULL;
46 switch (GetGLImplementation()) {
47 case kGLImplementationDesktopGL:
48 case kGLImplementationAppleGL: {
49 scoped_refptr<GLSurface> surface(new GLSurfaceNSView(window));
50 if (!surface->Initialize())
51 return NULL;
53 return surface;
55 case kGLImplementationMockGL:
56 return new GLSurfaceStub;
57 default:
58 NOTREACHED();
59 return NULL;
61 #else
62 return CreateOffscreenGLSurface(software, gfx::Size(1,1));
63 #endif
66 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
67 bool software,
68 const gfx::Size& size) {
69 TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface");
70 if (software)
71 return NULL;
73 switch (GetGLImplementation()) {
74 case kGLImplementationOSMesaGL: {
75 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
76 size));
77 if (!surface->Initialize())
78 return NULL;
80 return surface;
82 case kGLImplementationDesktopGL:
83 case kGLImplementationAppleGL: {
84 scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size));
85 if (!surface->Initialize())
86 return NULL;
88 return surface;
90 case kGLImplementationMockGL:
91 return new GLSurfaceStub;
92 default:
93 NOTREACHED();
94 return NULL;
98 } // namespace gfx