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.
6 #include "ui/gl/gl_bindings.h"
7 #include "ui/gl/gl_context_stub_with_extensions.h"
8 #include "ui/gl/gl_egl_api_implementation.h"
9 #include "ui/gl/gl_gl_api_implementation.h"
10 #include "ui/gl/gl_implementation.h"
11 #include "ui/gl/gl_implementation_osmesa.h"
12 #include "ui/gl/gl_osmesa_api_implementation.h"
13 #include "ui/ozone/public/ozone_platform.h"
14 #include "ui/ozone/public/surface_factory_ozone.h"
20 void GL_BINDING_CALL
MarshalClearDepthToClearDepthf(GLclampd depth
) {
21 glClearDepthf(static_cast<GLclampf
>(depth
));
24 void GL_BINDING_CALL
MarshalDepthRangeToDepthRangef(GLclampd z_near
,
26 glDepthRangef(static_cast<GLclampf
>(z_near
), static_cast<GLclampf
>(z_far
));
31 void GetAllowedGLImplementations(std::vector
<GLImplementation
>* impls
) {
32 impls
->push_back(kGLImplementationEGLGLES2
);
33 impls
->push_back(kGLImplementationOSMesaGL
);
36 bool InitializeStaticGLBindings(GLImplementation implementation
) {
37 // Prevent reinitialization with a different implementation. Once the gpu
38 // unit tests have initialized with kGLImplementationMock, we don't want to
39 // later switch to another GL implementation.
40 DCHECK_EQ(kGLImplementationNone
, GetGLImplementation());
41 ui::OzonePlatform::InitializeForGPU();
43 switch (implementation
) {
44 case kGLImplementationOSMesaGL
:
45 return InitializeStaticGLBindingsOSMesaGL();
46 case kGLImplementationEGLGLES2
:
47 if (!ui::OzonePlatform::GetInstance()
48 ->GetSurfaceFactoryOzone()
49 ->LoadEGLGLES2Bindings(base::Bind(&AddGLNativeLibrary
),
50 base::Bind(&SetGLGetProcAddressProc
)))
52 SetGLImplementation(kGLImplementationEGLGLES2
);
53 InitializeStaticGLBindingsGL();
54 InitializeStaticGLBindingsEGL();
56 // These two functions take single precision float rather than double
57 // precision float parameters in GLES.
58 ::gfx::g_driver_gl
.fn
.glClearDepthFn
= MarshalClearDepthToClearDepthf
;
59 ::gfx::g_driver_gl
.fn
.glDepthRangeFn
= MarshalDepthRangeToDepthRangef
;
61 case kGLImplementationMockGL
: {
62 SetGLImplementation(kGLImplementationMockGL
);
63 InitializeStaticGLBindingsGL();
68 << "Unsupported GL type for Ozone surface implementation";
75 bool InitializeDynamicGLBindings(GLImplementation implementation
,
77 switch (implementation
) {
78 case kGLImplementationOSMesaGL
:
79 case kGLImplementationEGLGLES2
:
80 InitializeDynamicGLBindingsGL(context
);
82 case kGLImplementationMockGL
:
84 scoped_refptr
<GLContextStubWithExtensions
> mock_context(
85 new GLContextStubWithExtensions());
86 mock_context
->SetGLVersionString("3.0");
87 InitializeDynamicGLBindingsGL(mock_context
.get());
89 InitializeDynamicGLBindingsGL(context
);
98 void InitializeDebugGLBindings() {
101 void ClearGLBindings() {
102 ClearGLBindingsEGL();
104 SetGLImplementation(kGLImplementationNone
);
105 UnloadGLNativeLibraries();
108 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo
* info
) {
109 switch (GetGLImplementation()) {
110 case kGLImplementationEGLGLES2
:
111 return GetGLWindowSystemBindingInfoEGL(info
);