From ede20e5f9cc32d744b39281ba46811c7a41fc028 Mon Sep 17 00:00:00 2001 From: "U. Artie Eoff" Date: Thu, 19 Apr 2012 06:59:19 -0700 Subject: [PATCH] started display and window classes Signed-off-by: U. Artie Eoff --- .gitignore | 21 +++++++++ configure.ac | 3 +- src/Makefile.am | 5 +++ src/display.cpp | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/display.h | 58 ++++++++++++++++++++++++ src/simple.cpp | 10 +++++ src/window.cpp | 23 ++++++++++ src/window.h | 37 ++++++++++++++++ 8 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 src/display.cpp create mode 100644 src/display.h create mode 100644 src/simple.cpp create mode 100644 src/window.cpp create mode 100644 src/window.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7fe7f8e --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +aclocal.m4 +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +depcomp +install-sh +libtool +ltmain.sh +Makefile +Makefile.in +missing +stamp-h1 +autom4te.cache +.deps +*~ +*.o +*.so diff --git a/configure.ac b/configure.ac index b05684d..da7ab8c 100644 --- a/configure.ac +++ b/configure.ac @@ -23,6 +23,5 @@ PKG_CHECK_MODULES(CAIRO, [cairo >= 1.10.0]) PKG_CHECK_MODULES(WAYLAND, [wayland-client wayland-egl]) AC_CONFIG_FILES([Makefile - src/Makefile - src/weston/Makefile]) + src/Makefile]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index 8b13789..6cade67 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1 +1,6 @@ +CXXFLAGS = -std=gnu++0x $(CAIRO_CFLAGS) $(WAYLAND_CFLAGS) +LDFLAGS = $(CAIRO_LIBS) $(WAYLAND_LIBS) + +bin_PROGRAMS = simple +simple_SOURCES = simple.cpp display.cpp diff --git a/src/display.cpp b/src/display.cpp new file mode 100644 index 0000000..ebb6b1d --- /dev/null +++ b/src/display.cpp @@ -0,0 +1,133 @@ +// #include +#include +#include + +#include + +#include "display.h" + +namespace wayland { + +/*static*/ +int Display::evtMaskUpdate(uint32_t mask, void *data) +{ + Display* display = static_cast(data); + display->mask_ = mask; + + return 0; +} + +/*static*/ +void Display::handleGlobal(wl_display* wldisplay, uint32_t id, const char* interface, uint32_t version, void* data) +{ + Display* display = static_cast(data); + if ("wl_compositor" == interface) + { + display->compositor_ = static_cast( + wl_display_bind( + wldisplay, id, &wl_compositor_interface + ) + ); + } + else if ("wl_shell" == interface) + { + display->shell_ = static_cast( + wl_display_bind( + wldisplay, id, &wl_shell_interface + ) + ); + } +} + +Display::Display() + : display_(wl_display_connect(0)) +{ + if (not display_) + { + std::cerr << "Failed to create display!" << std::endl; + exit(1); + } + + wl_display_add_global_listener(display_, handleGlobal, this); + wl_display_iterate(display_, WL_DISPLAY_READABLE); + if (initEGL() < 0) + { + std::cerr << "Failed to initialize egl!" << std::endl; + exit(1); + } +} + +bool Display::initEGL() +{ + EGLint major, minor, n; + + static const EGLint argb_cfg_attribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT, + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_ALPHA_SIZE, 1, + EGL_DEPTH_SIZE, 1, + EGL_RENDERABLE_TYPE, GL_BIT, + EGL_NONE + }; + +#ifdef USE_CAIRO_GLESV2 + static const EGLint context_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + EGLint api = EGL_OPENGL_ES_API; +#else + EGLint *context_attribs = NULL; + EGLint api = EGL_OPENGL_API; +#endif + + eglDisplay_ = eglGetDisplay( (EGLNativeDisplayType)display_); + if (not eglInitialize(eglDisplay_, &major, &minor)) + { +// fprintf(stderr, "failed to initialize display\n"); + return false; + } + + if (not eglBindAPI(api)) + { +// fprintf(stderr, "failed to bind api EGL_OPENGL_API\n"); + return false; + } + + if (not eglChooseConfig(eglDisplay_, argb_cfg_attribs, + &argbConfig_, 1, &n) || n != 1) + { +// fprintf(stderr, "failed to choose argb config\n"); + return false; + } + + argbContext_ = eglCreateContext(eglDisplay_, argbConfig_, + EGL_NO_CONTEXT, context_attribs); + if (not argbContext_) + { +// fprintf(stderr, "failed to create context\n"); + return false; + } + + if (not eglMakeCurrent(eglDisplay_, NULL, NULL, argbContext_)) + { +// fprintf(stderr, "failed to make context current\n"); + return false; + } + +#ifdef HAVE_CAIRO_EGL + argbDevice_ = cairo_egl_device_create(eglDisplay_, argbContext_); + if (cairo_device_status(argbDevice_) != CAIRO_STATUS_SUCCESS) + { +// fprintf(stderr, "failed to get cairo egl argb device\n"); + return false; + } +#endif + + return true; +} + + +} // namespace wayland diff --git a/src/display.h b/src/display.h new file mode 100644 index 0000000..38a1535 --- /dev/null +++ b/src/display.h @@ -0,0 +1,58 @@ +#ifndef __WAYLAND_DISPLAY_H__ +#define __WAYLAND_DISPLAY_H__ + +#include +#include + +#ifdef USE_CAIRO_GLESV2 + #include + #include + + #define GL_BIT EGL_OPENGL_ES2_BIT +#else + #include + #define GL_BIT EGL_OPENGL_BIT +#endif + +#ifdef HAVE_CAIRO_EGL + #include +#endif + + +#include + +struct wl_display; +struct wl_compositor; +struct wl_shell; + +namespace wayland { + +class Display { + +public: + Display(); + + wl_compositor* compositor() { return compositor_; } + wl_display* display() { return display_; } + +private: + wl_display* display_; + uint32_t mask_; + wl_compositor* compositor_; + wl_shell* shell_; + + bool running_; + + EGLDisplay eglDisplay_; + EGLConfig argbConfig_; + EGLContext argbContext_; + + static int evtMaskUpdate(uint32_t, void*); + static void handleGlobal(wl_display*, uint32_t, const char*, uint32_t, void*); + + bool initEGL(); +}; + +} // namespace wayland + +#endif diff --git a/src/simple.cpp b/src/simple.cpp new file mode 100644 index 0000000..4e753b2 --- /dev/null +++ b/src/simple.cpp @@ -0,0 +1,10 @@ +#include +#include + +#include "display.h" + +int main(const int argc, const char** argv) +{ + wayland::Display display; + return 0; +} diff --git a/src/window.cpp b/src/window.cpp new file mode 100644 index 0000000..2ea1960 --- /dev/null +++ b/src/window.cpp @@ -0,0 +1,23 @@ +#include "window.h" + +namespace wayland { + +Window::Window(Display& display) + : display_(display) +{ + EGLBoolean result; + + surface_ = wl_compositor_create_surface(display_.compositor()); + shellSurface_ = wl_shell_get_shell_surface(display_.shell(), surface_); + native_ = wl_egl_window_create(surface_, width_, height_); + eglSurface_ = eglCreateWindowSurface(display_.display(), display_.config(), native_, NULL); + + wl_shell_surface_set_toplevel(shellSurface_); + + assert( + eglMakeCurrent(display_.display(), eglSurface_, eglSurface_, display_.context() + == EGL_TRUE + ); +} + +} // namespace wayland diff --git a/src/window.h b/src/window.h new file mode 100644 index 0000000..f9d11ad --- /dev/null +++ b/src/window.h @@ -0,0 +1,37 @@ +#ifndef __WAYLAND_WINDOW_H__ +#define __WAYLAND_WINDOW_H__ + +#include "display.h" + +namespace wayland { + +class Window +{ + +public: + Window(Display& display); + +private: + Display& display_; + int x_; + int y_; + int width_; + int height_; + + GLuint fbo_; + GLuint colorrbo_; + GLuint program_; + GLuint uniformRotation_; + GLuint pos_; + GLuint col_; + EGLSurface eglSurface_; + + struct wl_egl_window* native_; + struct wl_surface* surface_; + struct wl_shell_surface* shellSurface_; + struct wl_callback* callback_; +}; + +} // namespace wayland + +#endif -- 2.7.4