Skip to content

Commit

Permalink
Move static GL binding initialization to //ui/gl/init.
Browse files Browse the repository at this point in the history
Static GL binding initialization needs to call out to the Ozone
platform. Move this initialization code from //ui/gl to //ui/gl/init as
part of larger effort to break //ui/gl dep on //ui/ozone. Also move
InitializationDebugGLBindings() and ClearGLBindings() in a similar
fashion as they are closely linked to static initialization.

Unfortunately, dynamic GL binding initialization can't be moved
//ui/gl/init. It would be nice to have all the initialization code in
one target but dynamic GL binding initialization is used by GLContext.

The existing InitializationStaticGLBindings() functions had grown to be
very large for some platforms. Where appropriate the code for each
implementation has been extracted into it's own method to improve
readability.

The PRESUBMIT.py script is modified slightly here. The existing static
GL initialization uses ScopedAllowIO on some platforms. This function is
banned so moving the code triggers presubmit errors. The GPU main thread
can't continue until initialization is finished anyways so moving
blocking code to a different thread isn't helpful. Add new exemptions to
PRESUBMIT.py.

This is a resubmission of r402259. The original patch was reverted after
it broke the win Chrome branded build. The include directory for
swiftshader was missing, this CL now modifies BUILD.gn and *.gyp files
appropriately.

BUG=611142
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel;tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2103123002
Cr-Commit-Position: refs/heads/master@{#403714}
  • Loading branch information
kylechar authored and Commit bot committed Jul 4, 2016
1 parent 3f28275 commit 1666624
Show file tree
Hide file tree
Showing 34 changed files with 812 additions and 800 deletions.
7 changes: 5 additions & 2 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,13 @@
r"^net[\\\/]url_request[\\\/]test_url_fetcher_factory\.cc$",
r"^remoting[\\\/]host[\\\/]security_key[\\\/]"
"gnubby_auth_handler_linux\.cc$",
r"^ui[\\\/]ozone[\\\/]platform[\\\/]drm[\\\/]host[\\\/]"
"drm_display_host_manager\.cc$",
r"^ui[\\\/]base[\\\/]material_design[\\\/]"
"material_design_controller\.cc$",
r"^ui[\\\/]gl[\\\/]init[\\\/]gl_initializer_mac\.cc$",
r"^ui[\\\/]gl[\\\/]init[\\\/]gl_initializer_win\.cc$",
r"^ui[\\\/]gl[\\\/]init[\\\/]gl_initializer_x11\.cc$",
r"^ui[\\\/]ozone[\\\/]platform[\\\/]drm[\\\/]host[\\\/]"
"drm_display_host_manager\.cc$",
),
),
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_mock.h"
#include "ui/gl/init/gl_factory.h"
#include "ui/gl/test/gl_surface_test_support.h"

using ::gl::MockGLInterface;
Expand Down Expand Up @@ -573,7 +574,7 @@ void GLES2DecoderTestBase::ResetDecoder() {
engine_.reset();
::gl::MockGLInterface::SetGLInterface(NULL);
gl_.reset();
gl::ClearGLBindings();
gl::init::ClearGLBindings();
}

void GLES2DecoderTestBase::TearDown() {
Expand Down
3 changes: 2 additions & 1 deletion gpu/command_buffer/service/gpu_service_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_mock.h"
#include "ui/gl/gl_surface_stub.h"
#include "ui/gl/init/gl_factory.h"
#include "ui/gl/test/gl_surface_test_support.h"

namespace gpu {
Expand Down Expand Up @@ -50,7 +51,7 @@ void GpuServiceTest::TearDown() {
surface_ = nullptr;
::gl::MockGLInterface::SetGLInterface(NULL);
gl_.reset();
gl::ClearGLBindings();
gl::init::ClearGLBindings();
ran_teardown_ = true;

testing::Test::TearDown();
Expand Down
3 changes: 2 additions & 1 deletion gpu/config/gpu_info_collector_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_mock.h"
#include "ui/gl/init/gl_factory.h"
#include "ui/gl/test/gl_surface_test_support.h"

using ::gl::MockGLInterface;
Expand Down Expand Up @@ -167,7 +168,7 @@ class GPUInfoCollectorTest
void TearDown() override {
::gl::MockGLInterface::SetGLInterface(NULL);
gl_.reset();
gl::ClearGLBindings();
gl::init::ClearGLBindings();

testing::Test::TearDown();
}
Expand Down
3 changes: 2 additions & 1 deletion gpu/ipc/service/gpu_channel_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ui/gl/gl_context_stub_with_extensions.h"
#include "ui/gl/gl_mock.h"
#include "ui/gl/gl_surface_stub.h"
#include "ui/gl/init/gl_factory.h"
#include "ui/gl/test/gl_surface_test_support.h"

namespace gpu {
Expand Down Expand Up @@ -135,7 +136,7 @@ class GpuChannelTest : public GpuChannelTestCommon {
stub_context_ = nullptr;
stub_surface_ = nullptr;
gl::MockGLInterface::SetGLInterface(nullptr);
gl::ClearGLBindings();
gl::init::ClearGLBindings();
gl_interface_ = nullptr;
}

Expand Down
5 changes: 1 addition & 4 deletions ui/gl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ component("gl") {
configs += [ "//build/config:precompiled_headers" ]
defines = [ "GL_IMPLEMENTATION" ]

include_dirs = [
"//third_party/swiftshader/include",
"//third_party/mesa/src/include",
]
include_dirs = [ "//third_party/mesa/src/include" ]

all_dependent_configs = [ ":gl_config" ]

Expand Down
4 changes: 3 additions & 1 deletion ui/gl/angle_platform_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
// Implements the ANGLE platform interface, for functionality like
// histograms and trace profiling.

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "third_party/angle/include/platform/Platform.h"
#include "ui/gl/gl_export.h"

namespace gl {

// Derives the base ANGLE platform and provides implementations
class ANGLEPlatformImpl : public angle::Platform {
class GL_EXPORT ANGLEPlatformImpl : NON_EXPORTED_BASE(public angle::Platform) {
public:
ANGLEPlatformImpl();
~ANGLEPlatformImpl() override;
Expand Down
1 change: 0 additions & 1 deletion ui/gl/gl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
'GL_IMPLEMENTATION',
],
'include_dirs': [
'<(DEPTH)/third_party/swiftshader/include',
'<(DEPTH)/third_party/khronos',
],
'export_dependent_settings': [
Expand Down
18 changes: 18 additions & 0 deletions ui/gl/gl_egl_api_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@

namespace gl {

namespace {

void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) {
glClearDepthf(static_cast<GLclampf>(depth));
}

void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near,
GLclampd z_far) {
glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far));
}

} // namespace

RealEGLApi* g_real_egl;

void InitializeStaticGLBindingsEGL() {
Expand All @@ -22,6 +35,11 @@ void InitializeStaticGLBindingsEGL() {
g_real_egl->Initialize(&g_driver_egl);
g_current_egl_context = g_real_egl;
g_driver_egl.InitializeExtensionBindings();

// These two functions take single precision float rather than double
// precision float parameters in GLES.
::gl::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf;
::gl::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef;
}

void InitializeDebugGLBindingsEGL() {
Expand Down
6 changes: 3 additions & 3 deletions ui/gl/gl_egl_api_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace gl {
class GLContext;
struct GLWindowSystemBindingInfo;

void InitializeStaticGLBindingsEGL();
void InitializeDebugGLBindingsEGL();
void ClearGLBindingsEGL();
GL_EXPORT void InitializeStaticGLBindingsEGL();
GL_EXPORT void InitializeDebugGLBindingsEGL();
GL_EXPORT void ClearGLBindingsEGL();
bool GetGLWindowSystemBindingInfoEGL(GLWindowSystemBindingInfo* info);

class GL_EXPORT EGLApiBase : public EGLApi {
Expand Down
6 changes: 3 additions & 3 deletions ui/gl/gl_gl_api_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class GLContext;
class GLSurface;
struct GLVersionInfo;

void InitializeStaticGLBindingsGL();
GL_EXPORT void InitializeStaticGLBindingsGL();
void InitializeDynamicGLBindingsGL(GLContext* context);
void InitializeDebugGLBindingsGL();
GL_EXPORT void InitializeDebugGLBindingsGL();
void InitializeNullDrawGLBindingsGL();
// TODO(danakj): Remove this when all test suites are using null-draw.
bool HasInitializedNullDrawGLBindingsGL();
bool SetNullDrawGLBindingsEnabledGL(bool enabled);
void ClearGLBindingsGL();
GL_EXPORT void ClearGLBindingsGL();
void SetGLToRealGLApi();
void SetGLApi(GLApi* api);
void SetGLApiToNoContext();
Expand Down
6 changes: 3 additions & 3 deletions ui/gl/gl_glx_api_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace gl {
class GLContext;
struct GLWindowSystemBindingInfo;

void InitializeStaticGLBindingsGLX();
void InitializeDebugGLBindingsGLX();
void ClearGLBindingsGLX();
GL_EXPORT void InitializeStaticGLBindingsGLX();
GL_EXPORT void InitializeDebugGLBindingsGLX();
GL_EXPORT void ClearGLBindingsGLX();
bool GetGLWindowSystemBindingInfoGLX(GLWindowSystemBindingInfo* info);

class GL_EXPORT GLXApiBase : public GLXApi {
Expand Down
19 changes: 6 additions & 13 deletions ui/gl/gl_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,11 @@ typedef void* (WINAPI *GLGetProcAddressProc)(const char* name);
typedef void* (*GLGetProcAddressProc)(const char* name);
#endif

// Initialize a particular GL implementation.
GL_EXPORT bool InitializeStaticGLBindings(GLImplementation implementation);

// Initialize function bindings that depend on the context for a GL
// implementation.
GL_EXPORT bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context);

// Initialize Debug logging wrappers for GL bindings.
GL_EXPORT void InitializeDebugGLBindings();

// Initialize stub methods for drawing operations in the GL bindings. The
// null draw bindings default to enabled, so that draw operations do nothing.
GL_EXPORT void InitializeNullDrawGLBindings();
Expand All @@ -82,8 +76,6 @@ class GL_EXPORT DisableNullDrawGLBindings {
bool initial_enabled_;
};

GL_EXPORT void ClearGLBindings();

// Set the current GL implementation.
GL_EXPORT void SetGLImplementation(GLImplementation implementation);

Expand All @@ -101,10 +93,10 @@ GL_EXPORT GLImplementation GetNamedGLImplementation(const std::string& name);
GL_EXPORT const char* GetGLImplementationName(GLImplementation implementation);

// Add a native library to those searched for GL entry points.
void AddGLNativeLibrary(base::NativeLibrary library);
GL_EXPORT void AddGLNativeLibrary(base::NativeLibrary library);

// Unloads all native libraries.
void UnloadGLNativeLibraries();
GL_EXPORT void UnloadGLNativeLibraries();

// Set an additional function that will be called to find GL entry points.
// Exported so that tests may set the function used in the mock implementation.
Expand All @@ -117,7 +109,7 @@ GL_EXPORT void SetGLGetProcAddressProc(GLGetProcAddressProc proc);
// and when querying functions from the EGL library supplied by Android, it may
// return a function that prints a log message about the function being
// unsupported.
void* GetGLProcAddress(const char* name);
GL_EXPORT void* GetGLProcAddress(const char* name);

// Return information about the GL window system binding implementation (e.g.,
// EGL, GLX, WGL). Returns true if the information was retrieved successfully.
Expand All @@ -137,9 +129,10 @@ GL_EXPORT std::string GetGLExtensionsFromCurrentContext();
GL_EXPORT bool WillUseGLGetStringForExtensions();

// Helpers to load a library and log error on failure.
base::NativeLibrary LoadLibraryAndPrintError(
GL_EXPORT base::NativeLibrary LoadLibraryAndPrintError(
const base::FilePath::CharType* filename);
base::NativeLibrary LoadLibraryAndPrintError(const base::FilePath& filename);
GL_EXPORT base::NativeLibrary LoadLibraryAndPrintError(
const base::FilePath& filename);

} // namespace gl

Expand Down
98 changes: 4 additions & 94 deletions ui/gl/gl_implementation_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "ui/gl/gl_implementation.h"

#include "base/logging.h"
#include "base/native_library.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context_stub_with_extensions.h"
#include "ui/gl/gl_egl_api_implementation.h"
#include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_implementation_osmesa.h"
#include "ui/gl/gl_osmesa_api_implementation.h"

namespace gl {

namespace {

void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) {
glClearDepthf(static_cast<GLclampf>(depth));
}

void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near,
GLclampd z_far) {
glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far));
}

} // namespace

void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
impls->push_back(kGLImplementationEGLGLES2);
impls->push_back(kGLImplementationOSMesaGL);
}

bool InitializeStaticGLBindings(GLImplementation implementation) {
// Prevent reinitialization with a different implementation. Once the gpu
// unit tests have initialized with kGLImplementationMock, we don't want to
// later switch to another GL implementation.
DCHECK_EQ(kGLImplementationNone, GetGLImplementation());

switch (implementation) {
case kGLImplementationEGLGLES2: {
base::NativeLibrary gles_library =
LoadLibraryAndPrintError("libGLESv2.so");
if (!gles_library)
return false;
base::NativeLibrary egl_library = LoadLibraryAndPrintError("libEGL.so");
if (!egl_library) {
base::UnloadNativeLibrary(gles_library);
return false;
}

GLGetProcAddressProc get_proc_address =
reinterpret_cast<GLGetProcAddressProc>(
base::GetFunctionPointerFromNativeLibrary(
egl_library, "eglGetProcAddress"));
if (!get_proc_address) {
LOG(ERROR) << "eglGetProcAddress not found.";
base::UnloadNativeLibrary(egl_library);
base::UnloadNativeLibrary(gles_library);
return false;
}

SetGLGetProcAddressProc(get_proc_address);
AddGLNativeLibrary(egl_library);
AddGLNativeLibrary(gles_library);
SetGLImplementation(kGLImplementationEGLGLES2);

InitializeStaticGLBindingsGL();
InitializeStaticGLBindingsEGL();

// These two functions take single precision float rather than double
// precision float parameters in GLES.
::gl::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf;
::gl::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef;
break;
}
case kGLImplementationOSMesaGL:
InitializeStaticGLBindingsOSMesaGL();
break;
case kGLImplementationMockGL: {
SetGLImplementation(kGLImplementationMockGL);
InitializeStaticGLBindingsGL();
break;
}
default:
NOTIMPLEMENTED() << "InitializeStaticGLBindings on Android";
return false;
}

return true;
}

bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context) {
switch (implementation) {
Expand All @@ -107,8 +31,9 @@ bool InitializeDynamicGLBindings(GLImplementation implementation,
new GLContextStubWithExtensions());
mock_context->SetGLVersionString("opengl es 3.0");
InitializeDynamicGLBindingsGL(mock_context.get());
} else
} else {
InitializeDynamicGLBindingsGL(context);
}
break;
default:
NOTREACHED() << "InitializeDynamicGLBindings on Android";
Expand All @@ -118,21 +43,6 @@ bool InitializeDynamicGLBindings(GLImplementation implementation,
return true;
}

void InitializeDebugGLBindings() {
InitializeDebugGLBindingsEGL();
InitializeDebugGLBindingsGL();
InitializeDebugGLBindingsOSMESA();
}

void ClearGLBindings() {
ClearGLBindingsEGL();
ClearGLBindingsGL();
ClearGLBindingsOSMESA();
SetGLImplementation(kGLImplementationNone);

UnloadGLNativeLibraries();
}

bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
switch (GetGLImplementation()) {
case kGLImplementationEGLGLES2:
Expand Down
Loading

0 comments on commit 1666624

Please sign in to comment.