[email protected] | 52dd2f84 | 2012-02-01 00:07:21 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 5 | #include "ui/gl/gl_surface.h" |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 6 | |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 7 | #include "base/debug/trace_event.h" |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 8 | #include "base/logging.h" |
9 | #include "base/memory/scoped_ptr.h" | ||||
[email protected] | 0843156 | 2013-06-08 05:34:19 | [diff] [blame] | 10 | #include "third_party/mesa/src/include/GL/osmesa.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 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" | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 16 | |
[email protected] | 2f47fc45 | 2011-11-21 03:12:17 | [diff] [blame] | 17 | #if defined(USE_AURA) |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 18 | #include "ui/gl/gl_surface_nsview.h" |
[email protected] | 2f47fc45 | 2011-11-21 03:12:17 | [diff] [blame] | 19 | #endif |
20 | |||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 21 | namespace gfx { |
22 | |||||
[email protected] | 0f5e888 | 2011-11-08 22:29:38 | [diff] [blame] | 23 | bool GLSurface::InitializeOneOffInternal() { |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 24 | switch (GetGLImplementation()) { |
25 | case kGLImplementationDesktopGL: | ||||
[email protected] | 020d047e | 2011-12-07 19:15:42 | [diff] [blame] | 26 | case kGLImplementationAppleGL: |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 27 | if (!GLSurfaceCGL::InitializeOneOff()) { |
28 | LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; | ||||
29 | return false; | ||||
30 | } | ||||
31 | break; | ||||
32 | default: | ||||
33 | break; | ||||
34 | } | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 35 | return true; |
36 | } | ||||
37 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 38 | scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
[email protected] | 52dd2f84 | 2012-02-01 00:07:21 | [diff] [blame] | 39 | gfx::AcceleratedWidget window) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 40 | TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); |
[email protected] | 2f47fc45 | 2011-11-21 03:12:17 | [diff] [blame] | 41 | #if defined(USE_AURA) |
[email protected] | 2f47fc45 | 2011-11-21 03:12:17 | [diff] [blame] | 42 | switch (GetGLImplementation()) { |
[email protected] | 020d047e | 2011-12-07 19:15:42 | [diff] [blame] | 43 | case kGLImplementationDesktopGL: |
44 | case kGLImplementationAppleGL: { | ||||
[email protected] | 2f47fc45 | 2011-11-21 03:12:17 | [diff] [blame] | 45 | scoped_refptr<GLSurface> surface(new GLSurfaceNSView(window)); |
46 | if (!surface->Initialize()) | ||||
47 | return NULL; | ||||
48 | |||||
49 | return surface; | ||||
50 | } | ||||
51 | case kGLImplementationMockGL: | ||||
52 | return new GLSurfaceStub; | ||||
53 | default: | ||||
54 | NOTREACHED(); | ||||
55 | return NULL; | ||||
56 | } | ||||
57 | #else | ||||
[email protected] | 658f03f | 2013-06-17 18:28:09 | [diff] [blame] | 58 | return CreateOffscreenGLSurface(gfx::Size(1, 1)); |
[email protected] | 2f47fc45 | 2011-11-21 03:12:17 | [diff] [blame] | 59 | #endif |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 60 | } |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 61 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 62 | scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
63 | const gfx::Size& size) { | ||||
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 64 | TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface"); |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 65 | switch (GetGLImplementation()) { |
66 | case kGLImplementationOSMesaGL: { | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 67 | scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA, |
68 | size)); | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 69 | if (!surface->Initialize()) |
70 | return NULL; | ||||
71 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 72 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 73 | } |
[email protected] | 020d047e | 2011-12-07 19:15:42 | [diff] [blame] | 74 | case kGLImplementationDesktopGL: |
75 | case kGLImplementationAppleGL: { | ||||
[email protected] | 51e6f6a7 | 2011-12-21 19:42:55 | [diff] [blame] | 76 | scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size)); |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 77 | if (!surface->Initialize()) |
78 | return NULL; | ||||
79 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 80 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 81 | } |
82 | case kGLImplementationMockGL: | ||||
83 | return new GLSurfaceStub; | ||||
84 | default: | ||||
85 | NOTREACHED(); | ||||
86 | return NULL; | ||||
87 | } | ||||
88 | } | ||||
89 | |||||
90 | } // namespace gfx |