Add locking control to user flows, disallow screen locking during user creation.
[chromium-blink-merge.git] / ui / gl / gl_implementation_ozone.cc
blob3659a0235125868ba03a857841d817bce10453e3
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 "base/bind.h"
6 #include "ui/gfx/ozone/surface_factory_ozone.h"
7 #include "ui/gl/gl_bindings.h"
8 #include "ui/gl/gl_context_stub_with_extensions.h"
9 #include "ui/gl/gl_egl_api_implementation.h"
10 #include "ui/gl/gl_gl_api_implementation.h"
11 #include "ui/gl/gl_implementation.h"
12 #include "ui/gl/gl_implementation_linux.h"
13 #include "ui/gl/gl_osmesa_api_implementation.h"
14 #include "ui/ozone/ozone_platform.h"
16 namespace gfx {
18 namespace {
20 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) {
21 glClearDepthf(static_cast<GLclampf>(depth));
24 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near,
25 GLclampd z_far) {
26 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far));
29 } // namespace
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 if (GetGLImplementation() != kGLImplementationNone)
41 return true;
43 switch (implementation) {
44 case kGLImplementationOSMesaGL:
45 return InitializeStaticGLBindingsOSMesaGL();
46 case kGLImplementationEGLGLES2:
47 ui::OzonePlatform::Initialize();
48 if (!gfx::SurfaceFactoryOzone::GetInstance()->LoadEGLGLES2Bindings(
49 base::Bind(&AddGLNativeLibrary),
50 base::Bind(&SetGLGetProcAddressProc)))
51 return false;
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;
60 break;
61 case kGLImplementationMockGL: {
62 SetGLImplementation(kGLImplementationMockGL);
63 InitializeStaticGLBindingsGL();
64 break;
66 default:
67 NOTIMPLEMENTED()
68 << "Unsupported GL type for Ozone surface implementation";
69 return false;
72 return true;
75 bool InitializeDynamicGLBindings(GLImplementation implementation,
76 GLContext* context) {
77 switch (implementation) {
78 case kGLImplementationOSMesaGL:
79 InitializeDynamicGLBindingsGL(context);
80 InitializeDynamicGLBindingsOSMESA(context);
81 break;
82 case kGLImplementationEGLGLES2:
83 InitializeDynamicGLBindingsGL(context);
84 InitializeDynamicGLBindingsEGL(context);
85 break;
86 case kGLImplementationMockGL:
87 if (!context) {
88 scoped_refptr<GLContextStubWithExtensions> mock_context(
89 new GLContextStubWithExtensions());
90 mock_context->SetGLVersionString("3.0");
91 InitializeDynamicGLBindingsGL(mock_context.get());
92 } else
93 InitializeDynamicGLBindingsGL(context);
94 break;
95 default:
96 return false;
99 return true;
102 void InitializeDebugGLBindings() {
105 void ClearGLBindings() {
106 ClearGLBindingsEGL();
107 ClearGLBindingsGL();
108 SetGLImplementation(kGLImplementationNone);
109 UnloadGLNativeLibraries();
112 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
113 switch (GetGLImplementation()) {
114 case kGLImplementationEGLGLES2:
115 return GetGLWindowSystemBindingInfoEGL(info);
116 default:
117 return false;
119 return false;
122 } // namespace gfx