Skip to content

Commit

Permalink
struct Egl::config
Browse files Browse the repository at this point in the history
-decrease parameter count for function prototypes

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
  • Loading branch information
jwinarske committed May 18, 2024
1 parent edaa1c8 commit 0b71fcc
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 93 deletions.
14 changes: 10 additions & 4 deletions examples/gl-shadertoy/shadertoy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,19 @@ int main(int argc, char **argv) {
}
}

Egl::config egl_config{};
egl_config.context_attribs_size = kEglContextAttribs.size();
egl_config.context_attribs = kEglContextAttribs.data();
egl_config.config_attribs_size = kEglConfigAttribs.size();
egl_config.config_attribs = kEglConfigAttribs.data();
egl_config.buffer_bpp = 32;
egl_config.swap_interval = config.interval;
egl_config.type = Egl::OPENGL_API;

auto top_level = wm.create_top_level(
"simple-egl", "org.freedesktop.gitlab.jwinarske.waypp.simple_egl",
config.width, config.height, 0, 0, config.fullscreen, config.maximized,
config.fullscreen_ratio, config.tearing, draw_frame,
kEglContextAttribs.data(), kEglContextAttribs.size(),
kEglConfigAttribs.data(), kEglConfigAttribs.size(), Egl::OPENGL_API, 32,
config.interval);
config.fullscreen_ratio, config.tearing, draw_frame, &egl_config);

top_level->start_frame_callbacks();

Expand Down
14 changes: 10 additions & 4 deletions examples/simple-egl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,19 @@ int main(int argc, char **argv) {
}
}

Egl::config egl_config{};
egl_config.context_attribs_size = kEglContextAttribs.size();
egl_config.context_attribs = kEglContextAttribs.data();
egl_config.config_attribs_size = kEglConfigAttribs.size();
egl_config.config_attribs = kEglConfigAttribs.data();
egl_config.buffer_bpp = config.buffer_bpp;
egl_config.swap_interval = config.interval;
egl_config.type = Egl::OPENGL_ES_API;

auto top_level = wm.create_top_level(
"simple-egl", "org.freedesktop.gitlab.jwinarske.waypp.simple_egl",
config.width, config.height, 0, 0, config.fullscreen, config.maximized,
config.fullscreen_ratio, config.tearing, draw_frame,
kEglContextAttribs.data(), kEglContextAttribs.size(),
kEglConfigAttribs.data(), kEglConfigAttribs.size(), Egl::OPENGL_ES_API,
config.buffer_bpp, config.interval);
config.fullscreen_ratio, config.tearing, draw_frame, &egl_config);

top_level->start_frame_callbacks();

Expand Down
21 changes: 8 additions & 13 deletions src/window/egl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ Egl::Egl(struct wl_display *display,
struct wl_surface *wl_surface,
int width,
int height,
const int32_t *context_attribs,
size_t context_attribs_size,
const int32_t *config_attribs,
size_t config_attribs_size,
int buffer_bpp,
enum api type)
struct config *config)
: dpy_(eglGetDisplay(display)),
context_attribs_(context_attribs, context_attribs + context_attribs_size),
config_attribs_(config_attribs, config_attribs + config_attribs_size),
buffer_bpp_(buffer_bpp),
context_attribs_(config->context_attribs, config->context_attribs + config->context_attribs_size),
config_attribs_(config->config_attribs, config->config_attribs + config->config_attribs_size),
buffer_bpp_(config->buffer_bpp),
wl_surface_(wl_surface),
width_(width),
height_(height) {
Expand All @@ -50,7 +45,7 @@ Egl::Egl(struct wl_display *display,
throw std::runtime_error("eglInitialize failed.");
}

ret = eglBindAPI(type);
ret = eglBindAPI(config->type);
if (ret != EGL_TRUE) {
throw std::runtime_error("eglBindAPI failed.");
}
Expand All @@ -71,11 +66,11 @@ Egl::Egl(struct wl_display *display,

EGLint red_size;
for (EGLint i = 0; i < n; i++) {
eglGetConfigAttrib(dpy_, configs[i], EGL_BUFFER_SIZE, &buffer_bpp);
eglGetConfigAttrib(dpy_, configs[i], EGL_BUFFER_SIZE, &config->buffer_bpp);
eglGetConfigAttrib(dpy_, configs[i], EGL_RED_SIZE, &red_size);
SPDLOG_DEBUG("EGL_BUFFER_SIZE: {}", buffer_bpp);
SPDLOG_DEBUG("EGL_BUFFER_SIZE: {}", config->buffer_bpp);
SPDLOG_DEBUG("EGL_RED_SIZE: {}", red_size);
if ((buffer_bpp_ == 0 || buffer_bpp_ == buffer_bpp) && red_size < 10) {
if ((buffer_bpp_ == 0 || buffer_bpp_ == config->buffer_bpp) && red_size < 10) {
config_ = configs[i];
break;
}
Expand Down
23 changes: 14 additions & 9 deletions src/window/egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ class Egl {
OPENGL_API = 0x30A2,
};

struct config {
int buffer_bpp;
int swap_interval;
const int32_t *context_attribs;
size_t context_attribs_size;
const int32_t *config_attribs;
size_t config_attribs_size;
enum Egl::api type;
};

explicit Egl(struct wl_display *display,
struct wl_surface *wl_surface,
int width,
int height,
const int32_t *context_attribs,
size_t context_attribs_size,
const int32_t *config_attribs,
size_t config_attribs_size,
int buffer_bpp,
enum api type = OPENGL_ES_API);
struct config *config);

~Egl();

Expand All @@ -50,14 +55,14 @@ class Egl {

void swap_buffers();

void get_buffer_age(EGLint &age);

bool have_swap_buffers_width_damage() const {
[[nodiscard]] bool have_swap_buffers_with_damage() const {
return pfSwapBufferWithDamage_ != nullptr;
}

void swap_buffers_with_damage(const EGLint *rects, EGLint n_rects);

void get_buffer_age(EGLint &age);

void resize(int width, int height, int dx, int dy);

// Disallow copy and assign.
Expand Down
21 changes: 5 additions & 16 deletions src/window/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ Window::Window(WindowManager *wm,
bool maximized,
bool fullscreen_ratio,
bool tearing,
int buffer_bpp,
int swap_interval,
const int32_t *context_attribs,
size_t context_attribs_size,
const int32_t *config_attribs,
size_t config_attribs_size,
enum Egl::api type)
Egl::config *egl_config)
: wm_(wm),
buffer_transform_(WL_OUTPUT_TRANSFORM_NORMAL),
frame_callback_(frame_callback),
Expand All @@ -49,8 +43,6 @@ Window::Window(WindowManager *wm,
outputs_(wm->get_outputs()),
valid_(true),
logical_size_{.width = width, .height = height},
buffer_bpp_(buffer_bpp),
swap_interval_(swap_interval),
buffer_size_{.width = width, .height = height},
window_size_{.width = buffer_size_.width, .height = buffer_size_.height},
needs_buffer_geometry_update_(false),
Expand Down Expand Up @@ -81,12 +73,9 @@ Window::Window(WindowManager *wm,
}

#if ENABLE_EGL
if (context_attribs_size && config_attribs_size) {
egl_ = std::make_unique<Egl>(wm->get_display(), wl_surface_, width, height,
context_attribs, context_attribs_size,
config_attribs, config_attribs_size,
buffer_bpp, type);
egl_->set_swap_interval(swap_interval);
if (egl_config && egl_config->context_attribs_size && egl_config->config_attribs_size) {
egl_ = std::make_unique<Egl>(wm->get_display(), wl_surface_, width, height, egl_config);
egl_->set_swap_interval(egl_config->swap_interval);
}
#endif

Expand Down Expand Up @@ -428,7 +417,7 @@ void Window::swap_buffers() {
bool Window::have_swap_buffers_width_damage() {
#if ENABLE_EGL
if (egl_) {
return egl_->have_swap_buffers_width_damage();
return egl_->have_swap_buffers_with_damage();
}
#endif
return false;
Expand Down
10 changes: 1 addition & 9 deletions src/window/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ class Window {
bool maximized,
bool fullscreen_ratio,
bool tearing,
int buffer_bpp = 0,
int swap_interval = 0,
const int32_t *context_attribs = nullptr,
size_t context_attribs_size = 0,
const int32_t *config_attribs = nullptr,
size_t config_attribs_size = 0,
enum Egl::api type = Egl::OPENGL_ES_API);
Egl::config *egl_config);

~Window();

Expand Down Expand Up @@ -220,8 +214,6 @@ class Window {
bool resize_{};
bool activated_{};

int buffer_bpp_ = 0;
int swap_interval_ = 1;
int delay_ = 0;

int32_t buffer_scale_ = 1;
Expand Down
16 changes: 2 additions & 14 deletions src/window/xdg_toplevel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ XdgTopLevel::XdgTopLevel(
bool fullscreen_ratio,
bool tearing,
const std::function<void(void *, const uint32_t)> &frame_callback,
int buffer_bpp,
int swap_interval,
const int32_t *context_attribs,
size_t context_attribs_size,
const int32_t *config_attribs,
size_t config_attribs_size,
enum Egl::api type)
Egl::config *egl_config)
: Window(wm,
title,
buffer_count,
Expand All @@ -55,13 +49,7 @@ XdgTopLevel::XdgTopLevel(
maximized,
fullscreen_ratio,
tearing,
buffer_bpp,
swap_interval,
context_attribs,
context_attribs_size,
config_attribs,
config_attribs_size,
type),
egl_config),
wm_(wm),
title_(title),
app_id_(app_id) {
Expand Down
8 changes: 1 addition & 7 deletions src/window/xdg_toplevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ class XdgTopLevel : public Window {
bool fullscreen_ratio,
bool tearing,
const std::function<void(void *, const uint32_t)> &frame_callback,
int buffer_bpp = 0,
int swap_interval = 0,
const int32_t *context_attribs = nullptr,
size_t context_attribs_size = 0,
const int32_t *config_attribs = nullptr,
size_t config_attribs_size = 0,
enum Egl::api type = Egl::OPENGL_ES_API);
Egl::config *egl_config);

~XdgTopLevel();

Expand Down
12 changes: 2 additions & 10 deletions src/window_manager/xdg_window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,11 @@ XdgTopLevel *XdgWindowManager::create_top_level(
bool fullscreen_ratio,
bool tearing,
const std::function<void(void *, const uint32_t)> &frame_callback,
const int32_t *context_attribs,
size_t context_attribs_size,
const int32_t *config_attribs,
size_t config_attribs_size,
enum Egl::api type,
int buffer_bpp,
int swap_interval) {
Egl::config *egl_config) {
auto wm = reinterpret_cast<WindowManager *>(this);

xdg_top_level_ = std::make_unique<XdgTopLevel>(
wm, title, app_id, width, height, buffer_count, buffer_format, fullscreen,
maximized, fullscreen_ratio, tearing, frame_callback, buffer_bpp,
swap_interval, context_attribs, context_attribs_size, config_attribs,
config_attribs_size, type);
maximized, fullscreen_ratio, tearing, frame_callback, egl_config);
return xdg_top_level_.get();
}
8 changes: 1 addition & 7 deletions src/window_manager/xdg_window_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ class XdgWindowManager : public WindowManager {
bool fullscreen_ratio,
bool tearing,
const std::function<void(void *, const uint32_t)> &frame_callback,
const int32_t *context_attribs = nullptr,
size_t context_attribs_size = 0,
const int32_t *config_attribs = nullptr,
size_t config_attribs_size = 0,
enum Egl::api type = Egl::OPENGL_ES_API,
int buffer_bpp = 0,
int swap_interval = 0);
Egl::config *egl_config = nullptr);

// Disallow copy and assign.
XdgWindowManager(const XdgWindowManager &) = delete;
Expand Down

0 comments on commit 0b71fcc

Please sign in to comment.