提交 a68209fe 编写于 作者: A Adam Barth

Merge pull request #2549 from abarth/glfw_32

Update to GLFW 3.2
......@@ -5,6 +5,8 @@
[DartPackage="sky_services"]
module pointer;
// See https://github.com/flutter/engine/blob/master/sky/specs/pointer.md
enum PointerType {
DOWN,
UP,
......
......@@ -417,6 +417,8 @@ if (is_android) {
sources += [
"//sky/shell/platform/glfw/init_glfw.cc",
"//sky/shell/platform/glfw/init_glfw.h",
"//sky/shell/platform/glfw/message_pump_glfw.cc",
"//sky/shell/platform/glfw/message_pump_glfw.h",
"//sky/shell/platform/glfw/platform_view_glfw.cc",
"//sky/shell/platform/glfw/platform_view_glfw.h",
"//sky/shell/platform/glfw/window_impl.cc",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/shell/platform/glfw/message_pump_glfw.h"
#include <GLFW/glfw3.h>
#include "base/auto_reset.h"
#include "base/logging.h"
#include "base/time/time.h"
namespace sky {
namespace shell {
MessagePumpGLFW::MessagePumpGLFW() : in_run_(false), should_quit_(false) {
}
MessagePumpGLFW::~MessagePumpGLFW() {
}
// static
scoped_ptr<base::MessagePump> MessagePumpGLFW::Create() {
return scoped_ptr<MessagePump>(new MessagePumpGLFW());
}
void MessagePumpGLFW::Run(Delegate* delegate) {
base::AutoReset<bool> auto_reset_keep_running(&should_quit_, false);
base::AutoReset<bool> auto_reset_in_run(&in_run_, true);
for (;;) {
bool did_work = delegate->DoWork();
if (should_quit_)
break;
did_work |= delegate->DoDelayedWork(&delayed_work_time_);
if (should_quit_)
break;
if (did_work)
continue;
did_work = delegate->DoIdleWork();
if (should_quit_)
break;
if (did_work)
continue;
if (delayed_work_time_.is_null()) {
glfwPollEvents();
} else {
base::TimeDelta delay = delayed_work_time_ - base::TimeTicks::Now();
if (delay > base::TimeDelta()) {
glfwWaitEventsTimeout(delay.InSecondsF());
} else {
// It looks like delayed_work_time_ indicates a time in the past, so we
// need to call DoDelayedWork now.
delayed_work_time_ = base::TimeTicks();
}
}
if (should_quit_)
break;
}
}
void MessagePumpGLFW::Quit() {
DCHECK(in_run_) << "Quit was called outside of Run!";
should_quit_ = true;
ScheduleWork();
}
void MessagePumpGLFW::ScheduleWork() {
glfwPostEmptyEvent();
}
void MessagePumpGLFW::ScheduleDelayedWork(
const base::TimeTicks& delayed_work_time) {
// We know that we can't be blocked on Wait right now since this method can
// only be called on the same thread as Run, so we only need to update our
// record of how long to sleep when we do sleep.
delayed_work_time_ = delayed_work_time;
}
} // namespace shell
} // namespace sky
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_SHELL_PLATFORM_GLFW_MESSAGE_PUMP_GLFW_H_
#define SKY_SHELL_PLATFORM_GLFW_MESSAGE_PUMP_GLFW_H_
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_pump.h"
#include "base/time/time.h"
namespace sky {
namespace shell {
class MessagePumpGLFW : public base::MessagePump {
public:
MessagePumpGLFW();
~MessagePumpGLFW() override;
static scoped_ptr<base::MessagePump> Create();
// MessagePump methods:
void Run(Delegate* delegate) override;
void Quit() override;
void ScheduleWork() override;
void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override;
private:
bool in_run_;
bool should_quit_;
base::TimeTicks delayed_work_time_;
DISALLOW_COPY_AND_ASSIGN(MessagePumpGLFW);
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_PLATFORM_GLFW_MESSAGE_PUMP_GLFW_H_
......@@ -21,11 +21,20 @@ void OnWindowSizeChanged(GLFWwindow* window, int width, int height) {
ToImpl(window)->UpdateViewportMetrics(width, height);
}
void OnMouseButtonChanged(GLFWwindow* window, int button, int action, int mods) {
ToImpl(window)->DispatchMouseButtonEvent(button, action, mods);
}
void OnCursorPosChanged(GLFWwindow* window, double x, double y) {
ToImpl(window)->DispatchMouseMoveEvent(x, y);
}
} // namespace
WindowImpl::WindowImpl(GLFWwindow* window)
: window_(window),
shell_view_(new ShellView(Shell::Shared())) {
shell_view_(new ShellView(Shell::Shared())),
buttons_(0) {
glfwSetWindowUserPointer(window_, this);
auto platform_view =
static_cast<sky::shell::PlatformViewGLFW*>(shell_view_->view());
......@@ -38,6 +47,7 @@ WindowImpl::WindowImpl(GLFWwindow* window)
UpdateViewportMetrics(width, height);
glfwSetWindowSizeCallback(window_, OnWindowSizeChanged);
glfwSetMouseButtonCallback(window_, OnMouseButtonChanged);
}
WindowImpl::~WindowImpl() {
......@@ -61,5 +71,69 @@ void WindowImpl::UpdateViewportMetrics(int width, int height) {
engine_->OnViewportMetricsChanged(metrics.Pass());
}
void WindowImpl::DispatchMouseButtonEvent(int button, int action, int mods) {
pointer::PointerType type;
if (action == GLFW_PRESS) {
if (!buttons_) {
type = pointer::PointerType::DOWN;
glfwSetCursorPosCallback(window_, OnCursorPosChanged);
} else {
type = pointer::PointerType::MOVE;
}
// GLFW's button order matches what we want:
// https://github.com/flutter/engine/blob/master/sky/specs/pointer.md
// http://www.glfw.org/docs/3.2/group__buttons.html
buttons_ |= 1 << button;
} else if (action == GLFW_RELEASE) {
buttons_ &= ~(1 << button);
if (!buttons_) {
type = pointer::PointerType::UP;
glfwSetCursorPosCallback(window_, nullptr);
} else {
type = pointer::PointerType::MOVE;
}
} else {
DLOG(INFO) << "Unknown mouse action: " << action;
return;
}
double x = 0.f, y = 0.f;
glfwGetCursorPos(window_, &x, &y);
base::TimeDelta time_stamp = base::TimeTicks::Now() - base::TimeTicks();
auto pointer_data = pointer::Pointer::New();
pointer_data->time_stamp = time_stamp.InMicroseconds();
pointer_data->type = type;
pointer_data->kind = pointer::PointerKind::MOUSE;
pointer_data->x = x;
pointer_data->y = y;
pointer_data->buttons = buttons_;
pointer_data->pressure = 1.0;
pointer_data->pressure_max = 1.0;
auto pointer_packet = pointer::PointerPacket::New();
pointer_packet->pointers.push_back(pointer_data.Pass());
engine_->OnPointerPacket(pointer_packet.Pass());
}
void WindowImpl::DispatchMouseMoveEvent(double x, double y) {
base::TimeDelta time_stamp = base::TimeTicks::Now() - base::TimeTicks();
auto pointer_data = pointer::Pointer::New();
pointer_data->time_stamp = time_stamp.InMicroseconds();
pointer_data->type = pointer::PointerType::MOVE;
pointer_data->kind = pointer::PointerKind::MOUSE;
pointer_data->x = x;
pointer_data->y = y;
pointer_data->buttons = buttons_;
pointer_data->pressure = 1.0;
pointer_data->pressure_max = 1.0;
auto pointer_packet = pointer::PointerPacket::New();
pointer_packet->pointers.push_back(pointer_data.Pass());
engine_->OnPointerPacket(pointer_packet.Pass());
}
} // namespace shell
} // namespace sky
......@@ -24,11 +24,14 @@ class WindowImpl {
const std::string& bundle_path);
void UpdateViewportMetrics(int width, int height);
void DispatchMouseButtonEvent(int button, int action, int mods);
void DispatchMouseMoveEvent(double x, double y);
private:
GLFWwindow* window_;
std::unique_ptr<ShellView> shell_view_;
sky::SkyEnginePtr engine_;
int buttons_;
DISALLOW_COPY_AND_ASSIGN(WindowImpl);
};
......
......@@ -16,8 +16,43 @@
#if defined(USE_GLFW)
#include "sky/shell/platform/glfw/init_glfw.h"
#include "sky/shell/platform/glfw/message_pump_glfw.h"
#endif
namespace {
int RunNonInteractive() {
base::MessageLoop message_loop;
mojo::embedder::Init(mojo::embedder::CreateSimplePlatformSupport());
sky::shell::Shell::InitStandalone();
if (!sky::shell::InitForTesting()) {
sky::shell::switches::PrintUsage("sky_shell");
return 1;
}
message_loop.Run();
return 0;
}
#if defined(USE_GLFW)
int RunInteractive() {
base::MessageLoop message_loop(sky::shell::MessagePumpGLFW::Create());
mojo::embedder::Init(mojo::embedder::CreateSimplePlatformSupport());
sky::shell::Shell::InitStandalone();
if (!sky::shell::InitInteractive())
return 1;
message_loop.Run();
return 0;
}
#endif // defined(USE_GLFW)
} // namespace
int main(int argc, const char* argv[]) {
base::AtExitManager exit_manager;
base::CommandLine::Init(argc, argv);
......@@ -29,21 +64,11 @@ int main(int argc, const char* argv[]) {
return 0;
}
base::MessageLoop message_loop;
mojo::embedder::Init(mojo::embedder::CreateSimplePlatformSupport());
sky::shell::Shell::InitStandalone();
bool running = false;
#if defined(USE_GLFW)
if (!command_line.HasSwitch(sky::shell::switches::kNonInteractive))
running = sky::shell::InitInteractive();
if (command_line.HasSwitch(sky::shell::switches::kNonInteractive))
return RunNonInteractive();
return RunInteractive();
#endif
if (!running && !sky::shell::InitForTesting()) {
sky::shell::switches::PrintUsage("sky_shell");
return 1;
}
message_loop.Run();
return 0;
return RunNonInteractive();
}
......@@ -21,6 +21,7 @@ source_set("glfw") {
"src/posix_time.h",
"src/posix_tls.c",
"src/posix_tls.h",
"src/vulkan.c",
"src/window.c",
"src/x11_init.c",
"src/x11_monitor.c",
......
glfw 3.1.2
glfw 3.2
==========
Imported from https://github.com/glfw/glfw.git@30306e54705c3adae9fe082c816a3be71963485c
Imported from https://github.com/glfw/glfw.git@3503cba5d9df2976fa94eeaf852e15f987a00fa0
/*************************************************************************
* GLFW 3.1 - www.glfw.org
* GLFW 3.2 - www.glfw.org
* A library for OpenGL, window and input
*------------------------------------------------------------------------
* Copyright (c) 2002-2006 Marcus Geelnard
......@@ -38,20 +38,30 @@ extern "C" {
* Doxygen documentation
*************************************************************************/
/*! @file glfw3native.h
* @brief The header of the native access functions.
*
* This is the header file of the native access functions. See @ref native for
* more information.
*/
/*! @defgroup native Native access
*
* **By using the native access functions you assert that you know what you're
* doing and how to fix problems caused by using them. If you don't, you
* shouldn't be using them.**
*
* Before the inclusion of @ref glfw3native.h, you must define exactly one
* window system API macro and exactly one context creation API macro. Failure
* to do this will cause a compile-time error.
* Before the inclusion of @ref glfw3native.h, you may define exactly one
* window system API macro and zero or more context creation API macros.
*
* The chosen backends must match those the library was compiled for. Failure
* to do this will cause a link-time error.
*
* The available window API macros are:
* * `GLFW_EXPOSE_NATIVE_WIN32`
* * `GLFW_EXPOSE_NATIVE_COCOA`
* * `GLFW_EXPOSE_NATIVE_X11`
* * `GLFW_EXPOSE_NATIVE_WAYLAND`
* * `GLFW_EXPOSE_NATIVE_MIR`
*
* The available context API macros are:
* * `GLFW_EXPOSE_NATIVE_WGL`
......@@ -86,20 +96,23 @@ extern "C" {
#elif defined(GLFW_EXPOSE_NATIVE_X11)
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#else
#error "No window API selected"
#elif defined(GLFW_EXPOSE_NATIVE_WAYLAND)
#include <wayland-client.h>
#elif defined(GLFW_EXPOSE_NATIVE_MIR)
#include <mir_toolkit/mir_client_library.h>
#endif
#if defined(GLFW_EXPOSE_NATIVE_WGL)
/* WGL is declared by windows.h */
#elif defined(GLFW_EXPOSE_NATIVE_NSGL)
#endif
#if defined(GLFW_EXPOSE_NATIVE_NSGL)
/* NSGL is declared by Cocoa.h */
#elif defined(GLFW_EXPOSE_NATIVE_GLX)
#endif
#if defined(GLFW_EXPOSE_NATIVE_GLX)
#include <GL/glx.h>
#elif defined(GLFW_EXPOSE_NATIVE_EGL)
#endif
#if defined(GLFW_EXPOSE_NATIVE_EGL)
#include <EGL/egl.h>
#else
#error "No context API selected"
#endif
......@@ -114,11 +127,10 @@ extern "C" {
* of the specified monitor, or `NULL` if an [error](@ref error_handling)
* occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
......@@ -130,11 +142,10 @@ GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
* `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
......@@ -145,11 +156,10 @@ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
* @return The `HWND` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
......@@ -162,11 +172,10 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window);
* @return The `HGLRC` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
......@@ -179,11 +188,10 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
* @return The `CGDirectDisplayID` of the specified monitor, or
* `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
......@@ -194,11 +202,10 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
* @return The `NSWindow` of the specified window, or `nil` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
......@@ -211,11 +218,10 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
* @return The `NSOpenGLContext` of the specified window, or `nil` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
......@@ -228,11 +234,10 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* window);
* @return The `Display` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
......@@ -243,11 +248,10 @@ GLFWAPI Display* glfwGetX11Display(void);
* @return The `RRCrtc` of the specified monitor, or `None` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
......@@ -258,11 +262,10 @@ GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
* @return The `RROutput` of the specified monitor, or `None` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.1.
* @since Added in version 3.1.
*
* @ingroup native
*/
......@@ -273,11 +276,10 @@ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
* @return The `Window` of the specified window, or `None` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
......@@ -290,15 +292,116 @@ GLFWAPI Window glfwGetX11Window(GLFWwindow* window);
* @return The `GLXContext` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
/*! @brief Returns the `GLXWindow` of the specified window.
*
* @return The `GLXWindow` of the specified window, or `None` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window);
#endif
#if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
/*! @brief Returns the `struct wl_display*` used by GLFW.
*
* @return The `struct wl_display*` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI struct wl_display* glfwGetWaylandDisplay(void);
/*! @brief Returns the `struct wl_output*` of the specified monitor.
*
* @return The `struct wl_output*` of the specified monitor, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor);
/*! @brief Returns the main `struct wl_surface*` of the specified window.
*
* @return The main `struct wl_surface*` of the specified window, or `NULL` if
* an [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window);
#endif
#if defined(GLFW_EXPOSE_NATIVE_MIR)
/*! @brief Returns the `MirConnection*` used by GLFW.
*
* @return The `MirConnection*` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI MirConnection* glfwGetMirDisplay(void);
/*! @brief Returns the Mir output ID of the specified monitor.
*
* @return The Mir output ID of the specified monitor, or zero if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor);
/*! @brief Returns the `MirSurface*` of the specified window.
*
* @return The `MirSurface*` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.2.
*
* @ingroup native
*/
GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* window);
#endif
#if defined(GLFW_EXPOSE_NATIVE_EGL)
......@@ -307,11 +410,10 @@ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
* @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
......@@ -322,11 +424,10 @@ GLFWAPI EGLDisplay glfwGetEGLDisplay(void);
* @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
......@@ -337,11 +438,10 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window);
* @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an
* [error](@ref error_handling) occurred.
*
* @par Thread Safety
* This function may be called from any thread. Access is not synchronized.
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @par History
* Added in GLFW 3.0.
* @since Added in version 3.0.
*
* @ingroup native
*/
......
include_directories("${GLFW_SOURCE_DIR}/src"
"${GLFW_BINARY_DIR}/src"
${glfw_INCLUDE_DIRS})
add_definitions(-D_GLFW_USE_CONFIG_H)
set(common_HEADERS internal.h
"${GLFW_BINARY_DIR}/src/glfw_config.h"
"${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h"
"${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h")
set(common_SOURCES context.c init.c input.c monitor.c window.c)
set(common_SOURCES context.c init.c input.c monitor.c vulkan.c window.c)
if (_GLFW_COCOA)
set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h iokit_joystick.h
set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h cocoa_joystick.h
posix_tls.h)
set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_monitor.m
cocoa_window.m iokit_joystick.m mach_time.c posix_tls.c)
set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_joystick.m
cocoa_monitor.m cocoa_window.m cocoa_time.c posix_tls.c)
elseif (_GLFW_WIN32)
set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_tls.h
winmm_joystick.h)
set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_monitor.c win32_time.c
win32_tls.c win32_window.c winmm_joystick.c)
set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_joystick.h)
set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_joystick.c
win32_monitor.c win32_time.c win32_tls.c win32_window.c)
elseif (_GLFW_X11)
set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h
linux_joystick.h posix_time.h posix_tls.h)
......@@ -31,6 +24,15 @@ elseif (_GLFW_WAYLAND)
posix_time.h posix_tls.h xkb_unicode.h)
set(glfw_SOURCES ${common_SOURCES} wl_init.c wl_monitor.c wl_window.c
linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c)
ecm_add_wayland_client_protocol(glfw_SOURCES
PROTOCOL
${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml
BASENAME relative-pointer-unstable-v1)
ecm_add_wayland_client_protocol(glfw_SOURCES
PROTOCOL
${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml
BASENAME pointer-constraints-unstable-v1)
elseif (_GLFW_MIR)
set(glfw_HEADERS ${common_HEADERS} mir_platform.h linux_joystick.h
posix_time.h posix_tls.h xkb_unicode.h)
......@@ -59,35 +61,64 @@ endif()
add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS})
set_target_properties(glfw PROPERTIES
OUTPUT_NAME "${GLFW_LIB_NAME}"
OUTPUT_NAME ${GLFW_LIB_NAME}
VERSION ${GLFW_VERSION}
SOVERSION ${GLFW_VERSION_MAJOR}
POSITION_INDEPENDENT_CODE ON
FOLDER "GLFW3")
target_compile_definitions(glfw PRIVATE -D_GLFW_USE_CONFIG_H)
target_include_directories(glfw PUBLIC
$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
target_include_directories(glfw PRIVATE
"${GLFW_SOURCE_DIR}/src"
"${GLFW_BINARY_DIR}/src"
${glfw_INCLUDE_DIRS})
# HACK: When building on MinGW, WINVER and UNICODE need to be defined before
# the inclusion of stddef.h (by glfw3.h), which is itself included before
# win32_platform.h. We define them here until a saner solution can be found
# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack.
target_compile_definitions(glfw PRIVATE
"$<$<BOOL:${MINGW}>:UNICODE;WINVER=0x0501>")
# Enable a reasonable set of warnings (no, -Wextra is not reasonable)
target_compile_options(glfw PRIVATE
"$<$<C_COMPILER_ID:Clang>:-Wall>"
"$<$<C_COMPILER_ID:GNU>:-Wall>")
if (BUILD_SHARED_LIBS)
if (WIN32)
# The GLFW DLL needs a special compile-time macro and import library name
set_target_properties(glfw PROPERTIES PREFIX "" IMPORT_PREFIX "")
if (MINGW)
# Remove the lib prefix on the DLL (but not the import library
set_target_properties(glfw PROPERTIES PREFIX "")
# Add a suffix to the import library to avoid naming conflicts
set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a")
else()
# Add a suffix to the import library to avoid naming conflicts
set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib")
endif()
elseif (APPLE)
# Append -fno-common to the compile flags to work around a bug in
# Apple's GCC
get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS)
if (NOT glfw_CFLAGS)
set(glfw_CFLAGS "")
endif()
# Add -fno-common to work around a bug in Apple's GCC
target_compile_options(glfw PRIVATE "-fno-common")
set_target_properties(glfw PROPERTIES
COMPILE_FLAGS "${glfw_CFLAGS} -fno-common"
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
INSTALL_NAME_DIR "lib${LIB_SUFFIX}")
elseif (UNIX)
# Hide symbols not explicitly tagged for export from the shared library
target_compile_options(glfw PRIVATE "-fvisibility=hidden")
endif()
target_link_libraries(glfw ${glfw_LIBRARIES})
target_compile_definitions(glfw INTERFACE -DGLFW_DLL)
target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES})
else()
target_link_libraries(glfw INTERFACE ${glfw_LIBRARIES})
endif()
if (MSVC)
target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
if (GLFW_INSTALL)
......
//========================================================================
// GLFW 3.1 OS X - www.glfw.org
// GLFW 3.2 OS X - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2009-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
......@@ -72,7 +72,10 @@ static void changeToResourcesDirectory(void)
//
static void createKeyTables(void)
{
int scancode;
memset(_glfw.ns.publicKeys, -1, sizeof(_glfw.ns.publicKeys));
memset(_glfw.ns.nativeKeys, -1, sizeof(_glfw.ns.nativeKeys));
_glfw.ns.publicKeys[0x1D] = GLFW_KEY_0;
_glfw.ns.publicKeys[0x12] = GLFW_KEY_1;
......@@ -188,6 +191,13 @@ static void createKeyTables(void)
_glfw.ns.publicKeys[0x51] = GLFW_KEY_KP_EQUAL;
_glfw.ns.publicKeys[0x43] = GLFW_KEY_KP_MULTIPLY;
_glfw.ns.publicKeys[0x4E] = GLFW_KEY_KP_SUBTRACT;
for (scancode = 0; scancode < 256; scancode++)
{
// Store the reverse translation for faster key name lookup
if (_glfw.ns.publicKeys[scancode] >= 0)
_glfw.ns.nativeKeys[_glfw.ns.publicKeys[scancode]] = scancode;
}
}
......@@ -207,21 +217,41 @@ int _glfwPlatformInit(void)
_glfw.ns.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
if (!_glfw.ns.eventSource)
return GL_FALSE;
return GLFW_FALSE;
CGEventSourceSetLocalEventsSuppressionInterval(_glfw.ns.eventSource, 0.0);
if (!_glfwInitContextAPI())
return GL_FALSE;
// TODO: Catch kTISNotifySelectedKeyboardInputSourceChanged and update
_glfw.ns.inputSource = TISCopyCurrentKeyboardLayoutInputSource();
if (!_glfw.ns.inputSource)
return GLFW_FALSE;
_glfwInitTimer();
_glfwInitJoysticks();
_glfw.ns.unicodeData = TISGetInputSourceProperty(_glfw.ns.inputSource,
kTISPropertyUnicodeKeyLayoutData);
if (!_glfw.ns.unicodeData)
return GLFW_FALSE;
return GL_TRUE;
if (!_glfwInitThreadLocalStoragePOSIX())
return GLFW_FALSE;
if (!_glfwInitNSGL())
return GLFW_FALSE;
_glfwInitTimerNS();
_glfwInitJoysticksNS();
return GLFW_TRUE;
}
void _glfwPlatformTerminate(void)
{
if (_glfw.ns.inputSource)
{
CFRelease(_glfw.ns.inputSource);
_glfw.ns.inputSource = NULL;
}
if (_glfw.ns.eventSource)
{
CFRelease(_glfw.ns.eventSource);
......@@ -235,16 +265,17 @@ void _glfwPlatformTerminate(void)
_glfw.ns.delegate = nil;
}
[_glfw.ns.autoreleasePool release];
_glfw.ns.autoreleasePool = nil;
[_glfw.ns.cursor release];
_glfw.ns.cursor = nil;
free(_glfw.ns.clipboardString);
_glfwTerminateJoysticks();
_glfwTerminateContextAPI();
_glfwTerminateNSGL();
_glfwTerminateJoysticksNS();
_glfwTerminateThreadLocalStoragePOSIX();
[_glfw.ns.autoreleasePool release];
_glfw.ns.autoreleasePool = nil;
}
const char* _glfwPlatformGetVersionString(void)
......
//========================================================================
// GLFW 3.1 IOKit - www.glfw.org
// GLFW 3.2 Cocoa - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2006-2014 Camilla Berglund <elmindreda@elmindreda.org>
//
......@@ -24,23 +24,22 @@
//
//========================================================================
#ifndef _glfw3_iokit_joystick_h_
#define _glfw3_iokit_joystick_h_
#ifndef _glfw3_cocoa_joystick_h_
#define _glfw3_cocoa_joystick_h_
#include <IOKit/IOKitLib.h>
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/hid/IOHIDLib.h>
#include <IOKit/hid/IOHIDKeys.h>
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \
_GLFWjoystickIOKit iokit_js
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWjoystickNS ns_js
// IOKit-specific per-joystick data
// Cocoa-specific per-joystick data
//
typedef struct _GLFWjoydevice
typedef struct _GLFWjoydeviceNS
{
int present;
GLFWbool present;
char name[256];
IOHIDDeviceRef deviceRef;
......@@ -51,18 +50,18 @@ typedef struct _GLFWjoydevice
float* axes;
unsigned char* buttons;
} _GLFWjoydevice;
} _GLFWjoydeviceNS;
// IOKit-specific joystick API data
// Cocoa-specific joystick API data
//
typedef struct _GLFWjoystickIOKit
typedef struct _GLFWjoystickNS
{
_GLFWjoydevice devices[GLFW_JOYSTICK_LAST + 1];
_GLFWjoydeviceNS devices[GLFW_JOYSTICK_LAST + 1];
IOHIDManagerRef managerRef;
} _GLFWjoystickIOKit;
} _GLFWjoystickNS;
void _glfwInitJoysticks(void);
void _glfwTerminateJoysticks(void);
void _glfwInitJoysticksNS(void);
void _glfwTerminateJoysticksNS(void);
#endif // _glfw3_iokit_joystick_h_
#endif // _glfw3_cocoa_joystick_h_
//========================================================================
// GLFW 3.1 IOKit - www.glfw.org
// GLFW 3.2 Cocoa - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2009-2010 Camilla Berglund <elmindreda@elmindreda.org>
// Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net>
......@@ -29,6 +29,7 @@
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
......@@ -40,7 +41,7 @@
//------------------------------------------------------------------------
// Joystick element information
//------------------------------------------------------------------------
typedef struct
typedef struct _GLFWjoyelementNS
{
IOHIDElementRef elementRef;
......@@ -50,14 +51,14 @@ typedef struct
long minReport;
long maxReport;
} _GLFWjoyelement;
} _GLFWjoyelementNS;
static void getElementsCFArrayHandler(const void* value, void* parameter);
// Adds an element to the specified joystick
//
static void addJoystickElement(_GLFWjoydevice* joystick,
static void addJoystickElement(_GLFWjoydeviceNS* joystick,
IOHIDElementRef elementRef)
{
IOHIDElementType elementType;
......@@ -109,7 +110,7 @@ static void addJoystickElement(_GLFWjoydevice* joystick,
if (elementsArray)
{
_GLFWjoyelement* element = calloc(1, sizeof(_GLFWjoyelement));
_GLFWjoyelementNS* element = calloc(1, sizeof(_GLFWjoyelementNS));
CFArrayAppendValue(elementsArray, element);
......@@ -126,14 +127,14 @@ static void getElementsCFArrayHandler(const void* value, void* parameter)
{
if (CFGetTypeID(value) == IOHIDElementGetTypeID())
{
addJoystickElement((_GLFWjoydevice*) parameter,
addJoystickElement((_GLFWjoydeviceNS*) parameter,
(IOHIDElementRef) value);
}
}
// Returns the value of the specified element of the specified joystick
//
static long getElementValue(_GLFWjoydevice* joystick, _GLFWjoyelement* element)
static long getElementValue(_GLFWjoydeviceNS* joystick, _GLFWjoyelementNS* element)
{
IOReturn result = kIOReturnSuccess;
IOHIDValueRef valueRef;
......@@ -163,7 +164,7 @@ static long getElementValue(_GLFWjoydevice* joystick, _GLFWjoyelement* element)
// Removes the specified joystick
//
static void removeJoystick(_GLFWjoydevice* joystick)
static void removeJoystick(_GLFWjoydeviceNS* joystick)
{
int i;
......@@ -188,70 +189,66 @@ static void removeJoystick(_GLFWjoydevice* joystick)
free(joystick->axes);
free(joystick->buttons);
memset(joystick, 0, sizeof(_GLFWjoydevice));
memset(joystick, 0, sizeof(_GLFWjoydeviceNS));
}
// Polls for joystick events and updates GLFW state
//
static void pollJoystickEvents(void)
static GLFWbool pollJoystickEvents(_GLFWjoydeviceNS* joystick)
{
int joy;
for (joy = 0; joy <= GLFW_JOYSTICK_LAST; joy++)
{
CFIndex i;
int buttonIndex = 0;
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy;
CFIndex i;
int buttonIndex = 0;
if (!joystick->present)
continue;
if (!joystick->present)
return GLFW_FALSE;
for (i = 0; i < CFArrayGetCount(joystick->buttonElements); i++)
{
_GLFWjoyelement* button = (_GLFWjoyelement*)
CFArrayGetValueAtIndex(joystick->buttonElements, i);
for (i = 0; i < CFArrayGetCount(joystick->buttonElements); i++)
{
_GLFWjoyelementNS* button = (_GLFWjoyelementNS*)
CFArrayGetValueAtIndex(joystick->buttonElements, i);
if (getElementValue(joystick, button))
joystick->buttons[buttonIndex++] = GLFW_PRESS;
else
joystick->buttons[buttonIndex++] = GLFW_RELEASE;
}
if (getElementValue(joystick, button))
joystick->buttons[buttonIndex++] = GLFW_PRESS;
else
joystick->buttons[buttonIndex++] = GLFW_RELEASE;
}
for (i = 0; i < CFArrayGetCount(joystick->axisElements); i++)
{
_GLFWjoyelement* axis = (_GLFWjoyelement*)
CFArrayGetValueAtIndex(joystick->axisElements, i);
for (i = 0; i < CFArrayGetCount(joystick->axisElements); i++)
{
_GLFWjoyelementNS* axis = (_GLFWjoyelementNS*)
CFArrayGetValueAtIndex(joystick->axisElements, i);
long value = getElementValue(joystick, axis);
long readScale = axis->maxReport - axis->minReport;
long value = getElementValue(joystick, axis);
long readScale = axis->maxReport - axis->minReport;
if (readScale == 0)
joystick->axes[i] = value;
else
joystick->axes[i] = (2.f * (value - axis->minReport) / readScale) - 1.f;
}
if (readScale == 0)
joystick->axes[i] = value;
else
joystick->axes[i] = (2.f * (value - axis->minReport) / readScale) - 1.f;
}
for (i = 0; i < CFArrayGetCount(joystick->hatElements); i++)
{
_GLFWjoyelement* hat = (_GLFWjoyelement*)
CFArrayGetValueAtIndex(joystick->hatElements, i);
for (i = 0; i < CFArrayGetCount(joystick->hatElements); i++)
{
_GLFWjoyelementNS* hat = (_GLFWjoyelementNS*)
CFArrayGetValueAtIndex(joystick->hatElements, i);
// Bit fields of button presses for each direction, including nil
const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 };
// Bit fields of button presses for each direction, including nil
const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 };
long j, value = getElementValue(joystick, hat);
if (value < 0 || value > 8)
value = 8;
long j, value = getElementValue(joystick, hat);
if (value < 0 || value > 8)
value = 8;
for (j = 0; j < 4; j++)
{
if (directions[value] & (1 << j))
joystick->buttons[buttonIndex++] = GLFW_PRESS;
else
joystick->buttons[buttonIndex++] = GLFW_RELEASE;
}
for (j = 0; j < 4; j++)
{
if (directions[value] & (1 << j))
joystick->buttons[buttonIndex++] = GLFW_PRESS;
else
joystick->buttons[buttonIndex++] = GLFW_RELEASE;
}
}
return GLFW_TRUE;
}
// Callback for user-initiated joystick addition
......@@ -261,12 +258,12 @@ static void matchCallback(void* context,
void* sender,
IOHIDDeviceRef deviceRef)
{
_GLFWjoydevice* joystick;
_GLFWjoydeviceNS* joystick;
int joy;
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
{
joystick = _glfw.iokit_js.devices + joy;
joystick = _glfw.ns_js.devices + joy;
if (!joystick->present)
continue;
......@@ -277,7 +274,7 @@ static void matchCallback(void* context,
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
{
joystick = _glfw.iokit_js.devices + joy;
joystick = _glfw.ns_js.devices + joy;
if (!joystick->present)
break;
......@@ -286,15 +283,20 @@ static void matchCallback(void* context,
if (joy > GLFW_JOYSTICK_LAST)
return;
joystick->present = GL_TRUE;
joystick->present = GLFW_TRUE;
joystick->deviceRef = deviceRef;
CFStringRef name = IOHIDDeviceGetProperty(deviceRef,
CFSTR(kIOHIDProductKey));
CFStringGetCString(name,
joystick->name,
sizeof(joystick->name),
kCFStringEncodingUTF8);
if (name)
{
CFStringGetCString(name,
joystick->name,
sizeof(joystick->name),
kCFStringEncodingUTF8);
}
else
strncpy(joystick->name, "Unknown", sizeof(joystick->name));
joystick->axisElements = CFArrayCreateMutable(NULL, 0, NULL);
joystick->buttonElements = CFArrayCreateMutable(NULL, 0, NULL);
......@@ -328,7 +330,7 @@ static void removeCallback(void* context,
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
{
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy;
_GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
if (joystick->deviceRef == deviceRef)
{
removeJoystick(joystick);
......@@ -384,12 +386,12 @@ static CFMutableDictionaryRef createMatchingDictionary(long usagePage,
// Initialize joystick interface
//
void _glfwInitJoysticks(void)
void _glfwInitJoysticksNS(void)
{
CFMutableArrayRef matchingCFArrayRef;
_glfw.iokit_js.managerRef = IOHIDManagerCreate(kCFAllocatorDefault,
kIOHIDOptionsTypeNone);
_glfw.ns_js.managerRef = IOHIDManagerCreate(kCFAllocatorDefault,
kIOHIDOptionsTypeNone);
matchingCFArrayRef = CFArrayCreateMutable(kCFAllocatorDefault,
0,
......@@ -422,21 +424,21 @@ void _glfwInitJoysticks(void)
CFRelease(matchingCFDictRef);
}
IOHIDManagerSetDeviceMatchingMultiple(_glfw.iokit_js.managerRef,
IOHIDManagerSetDeviceMatchingMultiple(_glfw.ns_js.managerRef,
matchingCFArrayRef);
CFRelease(matchingCFArrayRef);
}
IOHIDManagerRegisterDeviceMatchingCallback(_glfw.iokit_js.managerRef,
IOHIDManagerRegisterDeviceMatchingCallback(_glfw.ns_js.managerRef,
&matchCallback, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(_glfw.iokit_js.managerRef,
IOHIDManagerRegisterDeviceRemovalCallback(_glfw.ns_js.managerRef,
&removeCallback, NULL);
IOHIDManagerScheduleWithRunLoop(_glfw.iokit_js.managerRef,
IOHIDManagerScheduleWithRunLoop(_glfw.ns_js.managerRef,
CFRunLoopGetMain(),
kCFRunLoopDefaultMode);
IOHIDManagerOpen(_glfw.iokit_js.managerRef, kIOHIDOptionsTypeNone);
IOHIDManagerOpen(_glfw.ns_js.managerRef, kIOHIDOptionsTypeNone);
// Execute the run loop once in order to register any initially-attached
// joysticks
......@@ -445,18 +447,18 @@ void _glfwInitJoysticks(void)
// Close all opened joystick handles
//
void _glfwTerminateJoysticks(void)
void _glfwTerminateJoysticksNS(void)
{
int joy;
for (joy = 0; joy <= GLFW_JOYSTICK_LAST; joy++)
{
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy;
_GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
removeJoystick(joystick);
}
CFRelease(_glfw.iokit_js.managerRef);
_glfw.iokit_js.managerRef = NULL;
CFRelease(_glfw.ns_js.managerRef);
_glfw.ns_js.managerRef = NULL;
}
......@@ -466,18 +468,14 @@ void _glfwTerminateJoysticks(void)
int _glfwPlatformJoystickPresent(int joy)
{
pollJoystickEvents();
return _glfw.iokit_js.devices[joy].present;
_GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
return pollJoystickEvents(joystick);
}
const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
{
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy;
pollJoystickEvents();
if (!joystick->present)
_GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
if (!pollJoystickEvents(joystick))
return NULL;
*count = (int) CFArrayGetCount(joystick->axisElements);
......@@ -486,11 +484,8 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
{
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy;
pollJoystickEvents();
if (!joystick->present)
_GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
if (!pollJoystickEvents(joystick))
return NULL;
*count = (int) CFArrayGetCount(joystick->buttonElements) +
......@@ -500,8 +495,10 @@ const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
const char* _glfwPlatformGetJoystickName(int joy)
{
pollJoystickEvents();
_GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
if (!pollJoystickEvents(joystick))
return NULL;
return _glfw.iokit_js.devices[joy].name;
return joystick->name;
}
//========================================================================
// GLFW 3.1 OS X - www.glfw.org
// GLFW 3.2 OS X - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
......@@ -76,28 +76,28 @@ static char* getDisplayName(CGDirectDisplayID displayID)
// Check whether the display mode should be included in enumeration
//
static GLboolean modeIsGood(CGDisplayModeRef mode)
static GLFWbool modeIsGood(CGDisplayModeRef mode)
{
uint32_t flags = CGDisplayModeGetIOFlags(mode);
if (!(flags & kDisplayModeValidFlag) || !(flags & kDisplayModeSafeFlag))
return GL_FALSE;
return GLFW_FALSE;
if (flags & kDisplayModeInterlacedFlag)
return GL_FALSE;
return GLFW_FALSE;
if (flags & kDisplayModeStretchedFlag)
return GL_FALSE;
return GLFW_FALSE;
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) &&
CFStringCompare(format, CFSTR(IO32BitDirectPixels), 0))
{
CFRelease(format);
return GL_FALSE;
return GLFW_FALSE;
}
CFRelease(format);
return GL_TRUE;
return GLFW_TRUE;
}
// Convert Core Graphics display mode to GLFW video mode
......@@ -166,7 +166,7 @@ static void endFadeReservation(CGDisplayFadeReservationToken token)
// Change the current video mode
//
GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{
CFArrayRef modes;
CFIndex count, i;
......@@ -178,7 +178,7 @@ GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
best = _glfwChooseVideoMode(monitor, desired);
_glfwPlatformGetVideoMode(monitor, &current);
if (_glfwCompareVideoModes(&current, best) == 0)
return GL_TRUE;
return GLFW_TRUE;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
......@@ -216,15 +216,15 @@ GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Cocoa: Monitor mode list changed");
return GL_FALSE;
return GLFW_FALSE;
}
return GL_TRUE;
return GLFW_TRUE;
}
// Restore the previously saved (original) video mode
//
void _glfwRestoreVideoMode(_GLFWmonitor* monitor)
void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor)
{
if (monitor->ns.previousMode)
{
......@@ -283,7 +283,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
return monitors;
}
GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second)
GLFWbool _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second)
{
// HACK: Compare unit numbers instead of display IDs to work around display
// replacement on machines with automatic graphics switching
......
//========================================================================
// GLFW 3.1 OS X - www.glfw.org
// GLFW 3.2 OS X - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2009-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
......@@ -28,16 +28,19 @@
#define _glfw3_cocoa_platform_h_
#include <stdint.h>
#include <dlfcn.h>
#if defined(__OBJC__)
#import <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
#else
#include <Carbon/Carbon.h>
#include <ApplicationServices/ApplicationServices.h>
typedef void* id;
#endif
#include "posix_tls.h"
#include "iokit_joystick.h"
#include "cocoa_joystick.h"
#if defined(_GLFW_NSGL)
#include "nsgl_context.h"
......@@ -45,6 +48,10 @@ typedef void* id;
#error "The Cocoa backend depends on NSGL platform support"
#endif
#define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
#define _glfw_dlclose(handle) dlclose(handle)
#define _glfw_dlsym(handle, name) dlsym(handle, name)
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns
#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeNS ns_time
......@@ -59,7 +66,6 @@ typedef struct _GLFWwindowNS
id object;
id delegate;
id view;
unsigned int modifierFlags;
// The total sum of the distances the cursor has been warped
// since the last cursor motion event was processed
......@@ -73,13 +79,17 @@ typedef struct _GLFWwindowNS
//
typedef struct _GLFWlibraryNS
{
CGEventSourceRef eventSource;
id delegate;
id autoreleasePool;
id cursor;
short int publicKeys[256];
char* clipboardString;
CGEventSourceRef eventSource;
id delegate;
id autoreleasePool;
id cursor;
TISInputSourceRef inputSource;
id unicodeData;
char keyName[64];
short int publicKeys[256];
short int nativeKeys[GLFW_KEY_LAST + 1];
char* clipboardString;
} _GLFWlibraryNS;
......@@ -108,15 +118,14 @@ typedef struct _GLFWcursorNS
//
typedef struct _GLFWtimeNS
{
double base;
double resolution;
GLFWuint64 frequency;
} _GLFWtimeNS;
void _glfwInitTimer(void);
void _glfwInitTimerNS(void);
GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoMode(_GLFWmonitor* monitor);
GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
#endif // _glfw3_cocoa_platform_h_
//========================================================================
// GLFW 3.1 OS X - www.glfw.org
// GLFW 3.2 OS X - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2009-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
......@@ -29,27 +29,18 @@
#include <mach/mach_time.h>
// Return raw time
//
static uint64_t getRawTime(void)
{
return mach_absolute_time();
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
// Initialise timer
//
void _glfwInitTimer(void)
void _glfwInitTimerNS(void)
{
mach_timebase_info_data_t info;
mach_timebase_info(&info);
_glfw.ns_time.resolution = (double) info.numer / (info.denom * 1.0e9);
_glfw.ns_time.base = getRawTime();
_glfw.ns_time.frequency = (info.denom * 1e9) / info.numer;
}
......@@ -57,15 +48,13 @@ void _glfwInitTimer(void)
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
double _glfwPlatformGetTime(void)
GLFWuint64 _glfwPlatformGetTimerValue(void)
{
return (double) (getRawTime() - _glfw.ns_time.base) *
_glfw.ns_time.resolution;
return mach_absolute_time();
}
void _glfwPlatformSetTime(double time)
GLFWuint64 _glfwPlatformGetTimerFrequency(void)
{
_glfw.ns_time.base = getRawTime() -
(uint64_t) (time / _glfw.ns_time.resolution);
return _glfw.ns_time.frequency;
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
//========================================================================
// GLFW 3.1 EGL - www.glfw.org
// GLFW 3.2 EGL - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
......@@ -28,23 +28,92 @@
#ifndef _glfw3_egl_context_h_
#define _glfw3_egl_context_h_
#if defined(_GLFW_WIN32)
#define _glfw_dlopen(name) LoadLibraryA(name)
#define _glfw_dlclose(handle) FreeLibrary((HMODULE) handle)
#define _glfw_dlsym(handle, name) GetProcAddress((HMODULE) handle, name)
#if defined(_GLFW_USE_EGLPLATFORM_H)
#include <EGL/eglplatform.h>
#elif defined(_GLFW_WIN32)
#define EGLAPIENTRY __stdcall
typedef HDC EGLNativeDisplayType;
typedef HWND EGLNativeWindowType;
#elif defined(_GLFW_X11)
#define EGLAPIENTRY
typedef Display* EGLNativeDisplayType;
typedef Window EGLNativeWindowType;
#elif defined(_GLFW_WAYLAND)
#define EGLAPIENTRY
typedef struct wl_display* EGLNativeDisplayType;
typedef struct wl_egl_window* EGLNativeWindowType;
#elif defined(_GLFW_MIR)
#define EGLAPIENTRY
typedef MirEGLNativeDisplayType EGLNativeDisplayType;
typedef MirEGLNativeWindowType EGLNativeWindowType;
#else
#include <dlfcn.h>
#define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
#define _glfw_dlclose(handle) dlclose(handle)
#define _glfw_dlsym(handle, name) dlsym(handle, name)
#error "No supported EGL platform selected"
#endif
#include <EGL/egl.h>
// This path may need to be changed if you build GLFW using your own setup
// We ship and use our own copy of eglext.h since GLFW uses fairly new
// extensions and not all operating systems come with an up-to-date version
#include "../deps/EGL/eglext.h"
#define EGL_SUCCESS 0x3000
#define EGL_NOT_INITIALIZED 0x3001
#define EGL_BAD_ACCESS 0x3002
#define EGL_BAD_ALLOC 0x3003
#define EGL_BAD_ATTRIBUTE 0x3004
#define EGL_BAD_CONFIG 0x3005
#define EGL_BAD_CONTEXT 0x3006
#define EGL_BAD_CURRENT_SURFACE 0x3007
#define EGL_BAD_DISPLAY 0x3008
#define EGL_BAD_MATCH 0x3009
#define EGL_BAD_NATIVE_PIXMAP 0x300a
#define EGL_BAD_NATIVE_WINDOW 0x300b
#define EGL_BAD_PARAMETER 0x300c
#define EGL_BAD_SURFACE 0x300d
#define EGL_CONTEXT_LOST 0x300e
#define EGL_COLOR_BUFFER_TYPE 0x303f
#define EGL_RGB_BUFFER 0x308e
#define EGL_SURFACE_TYPE 0x3033
#define EGL_WINDOW_BIT 0x0004
#define EGL_RENDERABLE_TYPE 0x3040
#define EGL_OPENGL_ES_BIT 0x0001
#define EGL_OPENGL_ES2_BIT 0x0004
#define EGL_OPENGL_BIT 0x0008
#define EGL_ALPHA_SIZE 0x3021
#define EGL_BLUE_SIZE 0x3022
#define EGL_GREEN_SIZE 0x3023
#define EGL_RED_SIZE 0x3024
#define EGL_DEPTH_SIZE 0x3025
#define EGL_STENCIL_SIZE 0x3026
#define EGL_SAMPLES 0x3031
#define EGL_OPENGL_ES_API 0x30a0
#define EGL_OPENGL_API 0x30a2
#define EGL_NONE 0x3038
#define EGL_EXTENSIONS 0x3055
#define EGL_CONTEXT_CLIENT_VERSION 0x3098
#define EGL_NATIVE_VISUAL_ID 0x302e
#define EGL_NO_SURFACE ((EGLSurface) 0)
#define EGL_NO_DISPLAY ((EGLDisplay) 0)
#define EGL_NO_CONTEXT ((EGLContext) 0)
#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType) 0)
#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002
#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001
#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002
#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001
#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31bd
#define EGL_NO_RESET_NOTIFICATION_KHR 0x31be
#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31bf
#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004
#define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098
#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30fb
#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30fd
#define EGL_CONTEXT_FLAGS_KHR 0x30fc
#define EGL_CONTEXT_OPENGL_NO_ERROR_KHR 0x31b3
#define EGL_GL_COLORSPACE_KHR 0x309d
#define EGL_GL_COLORSPACE_SRGB_KHR 0x3089
typedef int EGLint;
typedef unsigned int EGLBoolean;
typedef unsigned int EGLenum;
typedef void* EGLConfig;
typedef void* EGLContext;
typedef void* EGLDisplay;
typedef void* EGLSurface;
// EGL function pointer typedefs
typedef EGLBoolean (EGLAPIENTRY * PFNEGLGETCONFIGATTRIBPROC)(EGLDisplay,EGLConfig,EGLint,EGLint*);
......@@ -63,22 +132,22 @@ typedef EGLBoolean (EGLAPIENTRY * PFNEGLSWAPBUFFERSPROC)(EGLDisplay,EGLSurface);
typedef EGLBoolean (EGLAPIENTRY * PFNEGLSWAPINTERVALPROC)(EGLDisplay,EGLint);
typedef const char* (EGLAPIENTRY * PFNEGLQUERYSTRINGPROC)(EGLDisplay,EGLint);
typedef GLFWglproc (EGLAPIENTRY * PFNEGLGETPROCADDRESSPROC)(const char*);
#define _glfw_eglGetConfigAttrib _glfw.egl.GetConfigAttrib
#define _glfw_eglGetConfigs _glfw.egl.GetConfigs
#define _glfw_eglGetDisplay _glfw.egl.GetDisplay
#define _glfw_eglGetError _glfw.egl.GetError
#define _glfw_eglInitialize _glfw.egl.Initialize
#define _glfw_eglTerminate _glfw.egl.Terminate
#define _glfw_eglBindAPI _glfw.egl.BindAPI
#define _glfw_eglCreateContext _glfw.egl.CreateContext
#define _glfw_eglDestroySurface _glfw.egl.DestroySurface
#define _glfw_eglDestroyContext _glfw.egl.DestroyContext
#define _glfw_eglCreateWindowSurface _glfw.egl.CreateWindowSurface
#define _glfw_eglMakeCurrent _glfw.egl.MakeCurrent
#define _glfw_eglSwapBuffers _glfw.egl.SwapBuffers
#define _glfw_eglSwapInterval _glfw.egl.SwapInterval
#define _glfw_eglQueryString _glfw.egl.QueryString
#define _glfw_eglGetProcAddress _glfw.egl.GetProcAddress
#define eglGetConfigAttrib _glfw.egl.GetConfigAttrib
#define eglGetConfigs _glfw.egl.GetConfigs
#define eglGetDisplay _glfw.egl.GetDisplay
#define eglGetError _glfw.egl.GetError
#define eglInitialize _glfw.egl.Initialize
#define eglTerminate _glfw.egl.Terminate
#define eglBindAPI _glfw.egl.BindAPI
#define eglCreateContext _glfw.egl.CreateContext
#define eglDestroySurface _glfw.egl.DestroySurface
#define eglDestroyContext _glfw.egl.DestroyContext
#define eglCreateWindowSurface _glfw.egl.CreateWindowSurface
#define eglMakeCurrent _glfw.egl.MakeCurrent
#define eglSwapBuffers _glfw.egl.SwapBuffers
#define eglSwapInterval _glfw.egl.SwapInterval
#define eglQueryString _glfw.egl.QueryString
#define eglGetProcAddress _glfw.egl.GetProcAddress
#define _GLFW_PLATFORM_FBCONFIG EGLConfig egl
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL egl
......@@ -90,13 +159,9 @@ typedef GLFWglproc (EGLAPIENTRY * PFNEGLGETPROCADDRESSPROC)(const char*);
typedef struct _GLFWcontextEGL
{
EGLConfig config;
EGLContext context;
EGLContext handle;
EGLSurface surface;
#if defined(_GLFW_X11)
XVisualInfo* visual;
#endif
void* client;
} _GLFWcontextEGL;
......@@ -109,7 +174,9 @@ typedef struct _GLFWlibraryEGL
EGLDisplay display;
EGLint major, minor;
GLboolean KHR_create_context;
GLFWbool KHR_create_context;
GLFWbool KHR_create_context_no_error;
GLFWbool KHR_gl_colorspace;
void* handle;
......@@ -133,14 +200,16 @@ typedef struct _GLFWlibraryEGL
} _GLFWlibraryEGL;
int _glfwInitContextAPI(void);
void _glfwTerminateContextAPI(void);
int _glfwCreateContext(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
void _glfwDestroyContext(_GLFWwindow* window);
int _glfwAnalyzeContext(const _GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
GLFWbool _glfwInitEGL(void);
void _glfwTerminateEGL(void);
GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
void _glfwDestroyContextEGL(_GLFWwindow* window);
#if defined(_GLFW_X11)
GLFWbool _glfwChooseVisualEGL(const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig,
Visual** visual, int* depth);
#endif /*_GLFW_X11*/
#endif // _glfw3_egl_context_h_
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
//========================================================================
// GLFW 3.1 Linux - www.glfw.org
// GLFW 3.2 Linux - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2014 Jonas Ådahl <jadahl@gmail.com>
//
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册