Commit fe2f3d63 by Corentin Wallez

Add a basic support for Linux for utils/

* Timer and path utils are done. * Window only implements initialize and setVisible BUG=angleproject:892 Change-Id: I3f49b68ef9ec5be324b25e211199bac2953ae11e Reviewed-on: https://chromium-review.googlesource.com/269520Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 0e7ee498
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
#include "OSWindow.h" #include "OSWindow.h"
#ifdef _WIN32 #ifdef _WIN32
#include "win32/Win32Timer.h" #elif __linux__
#include "win32/Win32Window.h"
#else #else
#error unsupported OS. #error unsupported OS.
#endif #endif
......
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// LinuxTimer.cpp: Implementation of a high precision timer class on Linux
#include "linux/LinuxTimer.h"
LinuxTimer::LinuxTimer()
: mRunning(false)
{
}
void LinuxTimer::start()
{
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mStartTime);
mRunning = true;
}
void LinuxTimer::stop()
{
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mStopTime);
mRunning = false;
}
double LinuxTimer::getElapsedTime() const
{
struct timespec endTime;
if (mRunning)
{
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &endTime);
}
else
{
endTime = mStopTime;
}
return endTime.tv_sec + (1.0 / 1000000000) * endTime.tv_nsec;
}
Timer *CreateTimer()
{
return new LinuxTimer();
}
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// LinuxTimer.h: Definition of a high precision timer class on Linux
#ifndef UTIL_LINUX_TIMER_H
#define UTIL_LINUX_TIMER_H
#include <time.h>
#include "Timer.h"
class LinuxTimer : public Timer
{
public:
LinuxTimer();
void start() override;
void stop() override;
double getElapsedTime() const override;
private:
bool mRunning;
struct timespec mStartTime;
struct timespec mStopTime;
};
#endif // UTIL_LINUX_TIMER_H
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Linux_path_utils.cpp: Implementation of OS-specific path functions for Linux
#include "path_utils.h"
#include <array>
#include <sys/stat.h>
#include <unistd.h>
std::string GetExecutablePath()
{
struct stat sb;
if (lstat("/proc/self/exe", &sb) == -1)
{
return "";
}
char *path = static_cast<char*>(malloc(sb.st_size + 1));
if (!path)
{
return "";
}
ssize_t result = readlink("/proc/self/exe", path, sb.st_size);
if (result != sb.st_size)
{
free(path);
return "";
}
path[sb.st_size] = '\0';
std::string strPath(path);
free(path);
return strPath;
}
std::string GetExecutableDirectory()
{
std::string executablePath = GetExecutablePath();
size_t lastPathSepLoc = executablePath.find_last_of("/");
return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : "";
}
...@@ -3,10 +3,43 @@ ...@@ -3,10 +3,43 @@
# found in the LICENSE file. # found in the LICENSE file.
{ {
'conditions': 'variables':
[
['OS=="win"',
{ {
'util_sources':
[
'com_utils.h',
'keyboard.h',
'mouse.h',
'path_utils.h',
'random_utils.cpp',
'random_utils.h',
'shader_utils.cpp',
'shader_utils.h',
'testfixturetypes.h',
'EGLWindow.cpp',
'EGLWindow.h',
'Event.h',
'OSWindow.cpp',
'OSWindow.h',
'Timer.h',
],
'util_win32_sources':
[
'win32/Win32_path_utils.cpp',
'win32/Win32Timer.cpp',
'win32/Win32Timer.h',
'win32/Win32Window.cpp',
'win32/Win32Window.h',
],
'util_linux_sources':
[
'linux/Linux_path_utils.cpp',
'linux/LinuxTimer.cpp',
'linux/LinuxTimer.h',
'x11/X11Window.cpp',
'x11/X11Window.h',
]
},
'targets': 'targets':
[ [
{ {
...@@ -30,28 +63,8 @@ ...@@ -30,28 +63,8 @@
], ],
'sources': 'sources':
[ [
'com_utils.h', '<@(util_sources)',
'keyboard.h',
'mouse.h',
'path_utils.h',
'random_utils.cpp',
'random_utils.h',
'shader_utils.cpp',
'shader_utils.h',
'testfixturetypes.h',
'EGLWindow.cpp',
'EGLWindow.h',
'Event.h',
'OSWindow.cpp',
'OSWindow.h',
'Timer.h',
'win32/Win32_path_utils.cpp',
'win32/Win32Timer.cpp',
'win32/Win32Timer.h',
'win32/Win32Window.cpp',
'win32/Win32Window.h',
], ],
'msvs_disabled_warnings': [ 4201 ],
'direct_dependent_settings': 'direct_dependent_settings':
{ {
'include_dirs': 'include_dirs':
...@@ -60,8 +73,32 @@ ...@@ -60,8 +73,32 @@
'<(angle_path)/util', '<(angle_path)/util',
], ],
}, },
}, 'conditions':
[
['OS=="win"',
{
'msvs_disabled_warnings': [ 4201 ],
'sources':
[
'<@(util_win32_sources)',
], ],
}], }],
['OS=="linux"',
{
'sources':
[
'<@(util_linux_sources)',
],
'link_settings': {
'ldflags': [
'<!@(pkg-config --libs-only-L --libs-only-other x11 xi)',
],
'libraries': [
'<!@(pkg-config --libs-only-l x11 xi)',
],
},
}],
],
},
], ],
} }
...@@ -43,4 +43,4 @@ class Win32Window : public OSWindow ...@@ -43,4 +43,4 @@ class Win32Window : public OSWindow
EGLNativeDisplayType mNativeDisplay; EGLNativeDisplayType mNativeDisplay;
}; };
#endif // SAMPLE_UTIL_WINDOW_H #endif // SAMPLE_UTIL_WIN32_WINDOW_H
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// X11Window.cpp: Implementation of OSWindow for X11
#include "x11/X11Window.h"
X11Window::X11Window()
: mDisplay(nullptr),
mWindow(0)
{
}
X11Window::~X11Window()
{
destroy();
}
bool X11Window::initialize(const std::string &name, size_t width, size_t height)
{
destroy();
mDisplay = XOpenDisplay(NULL);
if (!mDisplay)
{
return false;
}
int screen = DefaultScreen(mDisplay);
Window root = RootWindow(mDisplay, screen);
Colormap colormap = XCreateColormap(mDisplay, root, DefaultVisual(mDisplay, screen), AllocNone);
int depth = DefaultDepth(mDisplay, screen);
Visual *visual = DefaultVisual(mDisplay, screen);
XSetWindowAttributes attributes;
unsigned long attributeMask = CWBorderPixel | CWColormap | CWEventMask;
// TODO(cwallez) change when input is implemented
attributes.event_mask = 0;
attributes.border_pixel = 0;
attributes.colormap = colormap;
mWindow = XCreateWindow(mDisplay, root, 0, 0, width, height, 0, depth, InputOutput,
visual, attributeMask, &attributes);
if (!mWindow)
{
XFreeColormap(mDisplay, colormap);
return false;
}
XFlush(mDisplay);
mX = 0;
mY = 0;
mWidth = width;
mHeight = height;
return true;
}
void X11Window::destroy()
{
if (mWindow)
{
XDestroyWindow(mDisplay, mWindow);
mWindow = 0;
}
if (mDisplay)
{
XCloseDisplay(mDisplay);
mDisplay = nullptr;
}
}
EGLNativeWindowType X11Window::getNativeWindow() const
{
return mWindow;
}
EGLNativeDisplayType X11Window::getNativeDisplay() const
{
return mDisplay;
}
void X11Window::messageLoop()
{
//TODO
}
void X11Window::setMousePosition(int x, int y)
{
//TODO
}
OSWindow *CreateOSWindow()
{
return new X11Window();
}
bool X11Window::setPosition(int x, int y)
{
//TODO
return true;
}
bool X11Window::resize(int width, int height)
{
//TODO
return true;
}
void X11Window::setVisible(bool isVisible)
{
if (isVisible)
{
XMapWindow(mDisplay, mWindow);
}
else
{
XUnmapWindow(mDisplay, mWindow);
}
XFlush(mDisplay);
}
void X11Window::pushEvent(Event event)
{
//TODO
}
void X11Window::signalTestEvent()
{
//TODO
}
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// X11Window.h: Definition of the implementation of OSWindow for X11
#ifndef UTIL_X11_WINDOW_H
#define UTIL_X11_WINDOW_H
#include <string>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#include "OSWindow.h"
class X11Window : public OSWindow
{
public:
X11Window();
~X11Window();
bool initialize(const std::string &name, size_t width, size_t height) override;
void destroy() override;
EGLNativeWindowType getNativeWindow() const override;
EGLNativeDisplayType getNativeDisplay() const override;
void messageLoop() override;
void pushEvent(Event event) override;
void setMousePosition(int x, int y) override;
bool setPosition(int x, int y) override;
bool resize(int width, int height) override;
void setVisible(bool isVisible) override;
void signalTestEvent() override;
private:
Display *mDisplay;
Window mWindow;
};
#endif // UTIL_X11_WINDOW_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment