Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
environment_script: "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
- name: "Ubuntu Latest GCC"
os: ubuntu-latest
cc: "gcc-9"
cxx: "g++-9"
cc: "gcc"
cxx: "g++"
- name: "macOS Latest Clang"
os: macos-latest
cc: "clang"
Expand Down
51 changes: 47 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,50 @@ project(examples)
if (UNIX AND NOT APPLE)
find_package(OpenGL REQUIRED COMPONENTS OpenGL)
find_package(PkgConfig REQUIRED)
pkg_check_modules(gtk3 REQUIRED IMPORTED_TARGET gtk+-3.0)

option(X_Win "Use x11 window" ON)

set(SRC host/linux/skia_app.cpp
host/linux/skia_context.cpp)

if (X_Win)
pkg_check_modules(depend REQUIRED IMPORTED_TARGET
x11 glx
)
set(SRC ${SRC}
host/linux/x11/application.cpp
)

else()
pkg_check_modules(depend REQUIRED IMPORTED_TARGET
wayland-client wayland-cursor wayland-egl xkbcommon egl
)

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(WaylandScanner REQUIRED)

set(WORK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/host/linux/wayland")

wayland_add_protocol_client(SRC_GEN ${WORK_DIR}
"${WaylandScanner_DATADIR}/stable/xdg-shell/xdg-shell.xml")
wayland_add_protocol_client(SRC_GEN ${WORK_DIR}
"${WaylandScanner_DATADIR}/unstable/tablet/tablet-unstable-v2.xml")
wayland_add_protocol_client(SRC_GEN ${WORK_DIR}
"${WaylandScanner_DATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml")
wayland_add_protocol_client(SRC_GEN ${WORK_DIR}
"${WaylandScanner_DATADIR}/staging/fractional-scale/fractional-scale-v1.xml")
wayland_add_protocol_client(SRC_GEN ${WORK_DIR}
"${WaylandScanner_DATADIR}/stable/viewporter/viewporter.xml")

set(SRC ${SRC} ${SRC_GEN}
host/linux/wayland/core.cpp
host/linux/wayland/display.cpp
host/linux/wayland/xdgshell.cpp
host/linux/wayland/contextegl.cpp
host/linux/wayland/application.cpp
)
endif()

endif()

file(
Expand Down Expand Up @@ -78,17 +121,17 @@ function(add_example name)
)

elseif (UNIX)

add_executable(
${name}
${name}.cpp
host/linux/skia_app.cpp
${SRC}
print_elapsed.cpp
)

target_link_libraries(
${name}
PkgConfig::gtk3
PkgConfig::depend
OpenGL::GL
)

Expand Down
60 changes: 60 additions & 0 deletions examples/cmake/FindWaylandScanner.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Finds the Wayland client libraries
# Also supports components "protocols" and "scanner"

find_package(PkgConfig QUIET)

pkg_check_modules(PKG_Wayland QUIET wayland-protocols wayland-scanner)

set(WaylandScanner_VERSION ${PKG_Wayland_VERSION})
set(WaylandScanner_DEFINITIONS ${PKG_Wayland_CFLAGS})
mark_as_advanced(WaylandScanner_DEFINITIONS)

pkg_get_variable(Wayland_PROTOCOLS_DATADIR wayland-protocols pkgdatadir)
mark_as_advanced(Wayland_PROTOCOLS_DATADIR)

if (NOT Wayland_PROTOCOLS_DATADIR)
message(FATAL "The wayland-protocols data directory has not been found on your system.")
endif()

pkg_get_variable(WaylandScanner_EXECUTABLE_DIR wayland-scanner bindir)
find_program(WaylandScanner_EXECUTABLE NAMES wayland-scanner HINTS ${WaylandScanner_EXECUTABLE_DIR})
mark_as_advanced(WaylandScanner_EXECUTABLE WaylandScanner_EXECUTABLE_DIR)

set(WaylandScanner_DATADIR ${Wayland_PROTOCOLS_DATADIR})

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(WaylandScanner
FOUND_VAR WaylandScanner_FOUND
VERSION_VAR WaylandScanner_VERSION
REQUIRED_VARS WaylandScanner_EXECUTABLE ) #Wayland_LIBRARIES)

if (NOT TARGET Wayland::Scanner AND WaylandScanner_FOUND)
add_executable(Wayland::Scanner IMPORTED)
set_target_properties(Wayland::Scanner PROPERTIES
IMPORTED_LOCATION "${WaylandScanner_EXECUTABLE}")
endif()

function(wayland_add_protocol_client _sources _workdir _protocol)
if (NOT TARGET Wayland::Scanner)
message(FATAL "The wayland-scanner executable has not been found on your system.")
endif()

get_filename_component(_basename ${_protocol} NAME_WLE)

set(_source_file "${_protocol}")
set(_client_header "${_workdir}/${_basename}-client-protocol.h")
set(_private_code "${_workdir}/${_basename}-protocol.c")

add_custom_command(OUTPUT ${_client_header}
COMMAND Wayland::Scanner client-header ${_source_file} ${_client_header}
DEPENDS ${_source_file} VERBATIM)

add_custom_command(OUTPUT ${_private_code}
COMMAND Wayland::Scanner private-code ${_source_file} ${_private_code}
DEPENDS ${_source_file} ${_client_header} VERBATIM)

list(APPEND ${_sources} ${_client_header} ${_private_code})
set(${_sources} ${${_sources}} PARENT_SCOPE)

endfunction()
51 changes: 51 additions & 0 deletions examples/host/linux/application.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef APP_H
#define APP_H

#include "SkSurface.h"

class Application
{
public:
void run();
void stop(){isRuning = false;}

class DisplayImpl;

private:
bool isRuning{false};
};

enum SurfaceState
{
resizing = 1 << 0,
maximized = 1 << 1,
activated = 1 << 2,
fullscreen = 1 << 3
};

class Surface
{
public:
Surface(int width, int height);
~Surface();

void setTitle(const char* txt);

protected:
/*
* Draw frame. Returns true if the next frame needs to be drawn
*/
virtual bool draw(float /*scale*/) = 0;
virtual void configure(unsigned /*w*/, unsigned /*h*/, unsigned /*state*/) = 0;
virtual void closed() = 0;

sk_sp<SkSurface> skia_surf;

private:
struct Impl;
std::unique_ptr<Impl> impl;

friend class Application;
};

#endif // APP_H
43 changes: 43 additions & 0 deletions examples/host/linux/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef LOG_H
#define LOG_H

#include <syslog.h>

class Logger final
{
public:
explicit Logger(const char* app_id)
{
openlog(app_id, LOG_PERROR | LOG_PID, LOG_USER);
}

~Logger()
{
closelog();
}

template<typename ...Arg>
static void message(const char *msg, Arg&& ...args) noexcept
{
syslog(LOG_INFO, msg, args...);
}

template<typename ...Arg>
static void error(const char *msg, Arg&& ...args) noexcept
{
syslog(LOG_ERR, msg, args...);
}

template<typename ...Arg>
static void debug(const char *msg, Arg&& ...args) noexcept
{
#ifndef NDEBUG
syslog(LOG_DEBUG, msg, args...);
#endif
}

private:
Logger() = default;
};

#endif // LOG_H
Loading
Loading