Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / gl / gl_surface_mac.cc
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
17 namespace gfx {
18
19 bool GLSurface::InitializeOneOffInternal() {
20   switch (GetGLImplementation()) {
21     case kGLImplementationDesktopGL:
22     case kGLImplementationAppleGL:
23       if (!GLSurfaceCGL::InitializeOneOff()) {
24         LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
25         return false;
26       }
27       break;
28     default:
29       break;
30   }
31   return true;
32 }
33
34 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
35     gfx::AcceleratedWidget window) {
36   TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface");
37   switch (GetGLImplementation()) {
38     case kGLImplementationDesktopGL:
39     case kGLImplementationAppleGL: {
40       NOTIMPLEMENTED() << "No onscreen support on Mac.";
41       return NULL;
42     }
43     case kGLImplementationMockGL:
44       return new GLSurfaceStub;
45     default:
46       NOTREACHED();
47       return NULL;
48   }
49 }
50
51 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
52     const gfx::Size& size) {
53   TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface");
54   switch (GetGLImplementation()) {
55     case kGLImplementationOSMesaGL: {
56       scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
57                                                            size));
58       if (!surface->Initialize())
59         return NULL;
60
61       return surface;
62     }
63     case kGLImplementationDesktopGL:
64     case kGLImplementationAppleGL: {
65       scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size));
66       if (!surface->Initialize())
67         return NULL;
68
69       return surface;
70     }
71     case kGLImplementationMockGL:
72       return new GLSurfaceStub;
73     default:
74       NOTREACHED();
75       return NULL;
76   }
77 }
78
79 }  // namespace gfx