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. 4 5 #include "ui/gl/gl_surface.h" 6 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" 17 18 namespace gfx { 19 20 bool GLSurface::InitializeOneOffInternal() { 21 switch (GetGLImplementation()) { 22 case kGLImplementationDesktopGL: 23 case kGLImplementationAppleGL: 24 if (!GLSurfaceCGL::InitializeOneOff()) { 25 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; 26 return false; 27 } 28 break; 29 default: 30 break; 31 } 32 return true; 33 } 34 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()) 43 return NULL; 44 45 return surface; 46 } 47 case kGLImplementationMockGL: 48 return new GLSurfaceStub; 49 default: 50 NOTREACHED(); 51 return NULL; 52 } 53 } 54 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, 61 size)); 62 if (!surface->Initialize()) 63 return NULL; 64 65 return surface; 66 } 67 case kGLImplementationDesktopGL: 68 case kGLImplementationAppleGL: { 69 scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size)); 70 if (!surface->Initialize()) 71 return NULL; 72 73 return surface; 74 } 75 case kGLImplementationMockGL: 76 return new GLSurfaceStub; 77 default: 78 NOTREACHED(); 79 return NULL; 80 } 81 } 82 83 } // namespace gfx 84