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"
18 #include "ui/gl/gl_surface_nsview.h"
23 bool GLSurface::InitializeOneOffInternal() {
24 switch (GetGLImplementation()) {
25 case kGLImplementationDesktopGL:
26 case kGLImplementationAppleGL:
27 if (!GLSurfaceCGL::InitializeOneOff()) {
28 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
38 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
39 gfx::AcceleratedWidget window) {
40 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface");
42 switch (GetGLImplementation()) {
43 case kGLImplementationDesktopGL:
44 case kGLImplementationAppleGL: {
45 scoped_refptr<GLSurface> surface(new GLSurfaceNSView(window));
46 if (!surface->Initialize())
51 case kGLImplementationMockGL:
52 return new GLSurfaceStub;
58 return CreateOffscreenGLSurface(gfx::Size(1, 1));
62 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
63 const gfx::Size& size) {
64 TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface");
65 switch (GetGLImplementation()) {
66 case kGLImplementationOSMesaGL: {
67 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
69 if (!surface->Initialize())
74 case kGLImplementationDesktopGL:
75 case kGLImplementationAppleGL: {
76 scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size));
77 if (!surface->Initialize())
82 case kGLImplementationMockGL:
83 return new GLSurfaceStub;