Skip to content

Commit

Permalink
internal/glfw: reduce TLS usages at swapInterval*
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Oct 12, 2024
1 parent 18d3d91 commit 09c027b
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/glfw/context_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ GLFWAPI void glfwSwapInterval(GLFWwindow* handle, int interval)

_GLFW_REQUIRE_INIT();

window->context.swapInterval(interval);
window->context.swapInterval(window, interval);
}

GLFWAPI int glfwExtensionSupported(GLFWwindow* handle, const char* extension)
Expand Down
2 changes: 1 addition & 1 deletion internal/glfw/context_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (w *Window) SwapInterval(interval int) error {
return NotInitialized
}

if err := w.context.swapInterval(interval); err != nil {
if err := w.context.swapInterval(w, interval); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/glfw/egl_context_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static void swapBuffersEGL(_GLFWwindow* window)
eglSwapBuffers(_glfw.egl.display, window->context.egl.surface);
}

static void swapIntervalEGL(int interval)
static void swapIntervalEGL(_GLFWwindow* window, int interval)
{
eglSwapInterval(_glfw.egl.display, interval);
}
Expand Down
5 changes: 1 addition & 4 deletions internal/glfw/glx_context_linbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,8 @@ static void swapBuffersGLX(_GLFWwindow* window)
glXSwapBuffers(_glfw.x11.display, window->context.glx.window);
}

static void swapIntervalGLX(int interval)
static void swapIntervalGLX(_GLFWwindow* window, int interval)
{
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
assert(window != NULL);

if (_glfw.glx.EXT_swap_control)
{
_glfw.glx.SwapIntervalEXT(_glfw.x11.display,
Expand Down
2 changes: 1 addition & 1 deletion internal/glfw/internal_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef struct _GLFWmutex _GLFWmutex;

typedef void (* _GLFWmakecontextcurrentfun)(_GLFWwindow*);
typedef void (* _GLFWswapbuffersfun)(_GLFWwindow*);
typedef void (* _GLFWswapintervalfun)(int);
typedef void (* _GLFWswapintervalfun)(_GLFWwindow*, int);
typedef int (* _GLFWextensionsupportedfun)(const char*);
typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*);
typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
Expand Down
2 changes: 1 addition & 1 deletion internal/glfw/internal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type context struct {
// TODO: Put these functions in an interface type.
makeCurrent func(*Window) error
swapBuffers func(*Window) error
swapInterval func(int) error
swapInterval func(*Window, int) error
extensionSupported func(string) bool
getProcAddress func(string) uintptr
destroy func(*Window) error
Expand Down
5 changes: 1 addition & 4 deletions internal/glfw/nsgl_context_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ static void swapBuffersNSGL(_GLFWwindow* window)
} // autoreleasepool
}

static void swapIntervalNSGL(int interval)
static void swapIntervalNSGL(_GLFWwindow* window, int interval)
{
@autoreleasepool {

_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
assert(window != NULL);

[window->context.nsgl.object setValues:&interval
forParameter:NSOpenGLContextParameterSwapInterval];

Expand Down
2 changes: 1 addition & 1 deletion internal/glfw/osmesa_context_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void swapBuffersOSMesa(_GLFWwindow* window)
// No double buffering on OSMesa
}

static void swapIntervalOSMesa(int interval)
static void swapIntervalOSMesa(_GLFWwindow* window, int interval)
{
// No swap interval on OSMesa
}
Expand Down
8 changes: 1 addition & 7 deletions internal/glfw/wgl_context_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,7 @@ func swapBuffersWGL(window *Window) error {
return nil
}

func swapIntervalWGL(interval int) error {
ptr, err := _glfw.contextSlot.get()
if err != nil {
return err
}
window := (*Window)(unsafe.Pointer(ptr))

func swapIntervalWGL(window *Window, interval int) error {
window.context.platform.interval = interval

if window.monitor == nil && winver.IsWindowsVistaOrGreater() {
Expand Down

0 comments on commit 09c027b

Please sign in to comment.