./ 0000755 0000041 0000041 00000000000 13115234677 011254 5 ustar www-data www-data ./CMakeLists.txt 0000644 0000041 0000041 00000031014 13115234664 014007 0 ustar www-data www-data # Copyright © 2012 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# Authored by: Thomas Voss ,
# Alan Griffiths
set(CMAKE_GCOV gcov)
project(Mir)
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0015 NEW)
cmake_policy(SET CMP0022 NEW)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(MIR_VERSION_MAJOR 0)
set(MIR_VERSION_MINOR 26)
set(MIR_VERSION_PATCH 3)
add_definitions(-DMIR_VERSION_MAJOR=${MIR_VERSION_MAJOR})
add_definitions(-DMIR_VERSION_MINOR=${MIR_VERSION_MINOR})
add_definitions(-DMIR_VERSION_MICRO=${MIR_VERSION_PATCH})
add_definitions(-D_GNU_SOURCE)
add_definitions(-D_FILE_OFFSET_BITS=64)
set(MIR_VERSION ${MIR_VERSION_MAJOR}.${MIR_VERSION_MINOR}.${MIR_VERSION_PATCH})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
OUTPUT_VARIABLE TARGET_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
option(use_debflags "Use build flags from dpkg-buildflags." OFF)
if(use_debflags)
include (cmake/Debian.cmake)
endif()
include (cmake/EnableCoverageReport.cmake)
include (cmake/MirCommon.cmake)
include (GNUInstallDirs)
set(build_types "None;Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;AddressSanitizer;ThreadSanitizer;UBSanitizer")
# Change informational string for CMAKE_BUILD_TYPE
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "${build_types}" FORCE)
# Enable cmake-gui to display a drop down list for CMAKE_BUILD_TYPE
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${build_types}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -g -Werror -Wall -pedantic -Wextra -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g -std=c++14 -Werror -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--as-needed")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wmismatched-tags HAS_W_MISMATCHED_TAGS)
if(HAS_W_MISMATCHED_TAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-mismatched-tags")
endif()
option(MIR_USE_LD_GOLD "Enables the \"gold\" linker." OFF)
if(MIR_USE_LD_GOLD)
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=gold")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
endif()
# Link time optimization allows leaner, cleaner libraries
message(STATUS "CMAKE_C_COMPILER: " ${CMAKE_C_COMPILER})
option(MIR_LINK_TIME_OPTIMIZATION "Enables the linker to optimize binaries." OFF)
if(MIR_LINK_TIME_OPTIMIZATION)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto -ffat-lto-objects")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -ffat-lto-objects")
if(${CMAKE_COMPILER_IS_GNUCXX})
set(CMAKE_NM "gcc-nm")
set(CMAKE_AR "gcc-ar")
set(CMAKE_RANLIB "gcc-ranlib")
endif()
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower)
#####################################################################
# Enable code coverage calculation with gcov/gcovr/lcov
# Usage:
# * Switch build type to coverage (use ccmake or cmake-gui)
# * Invoke make, make test, make coverage
# * Find html report in subdir coveragereport
# * Find xml report feasible for jenkins in coverage.xml
#####################################################################
if(cmake_build_type_lower MATCHES "coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -ftest-coverage -fprofile-arcs")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ftest-coverage -fprofile-arcs")
endif()
if(cmake_build_type_lower MATCHES "addresssanitizer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
elseif(cmake_build_type_lower MATCHES "threadsanitizer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=thread")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=thread")
link_libraries(tsan) # Workaround for LP:1413474
elseif(cmake_build_type_lower MATCHES "ubsanitizer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-omit-frame-pointer")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=undefined")
# "Symbol already defined" errors occur with pre-compiled headers
SET(MIR_USE_PRECOMPILED_HEADERS OFF CACHE BOOL "Use precompiled headers" FORCE)
else()
# AddressSanitizer builds fail if we disallow undefined symbols
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
endif()
# Define LOG_NDEBUG=1 to ensure Android ALOGV calls are not compiled in to
# consume CPU time...
add_definitions(-DLOG_NDEBUG=1)
enable_testing()
include_directories(include/core)
include_directories(include/common)
include_directories(include/cookie)
# Check for boost
find_package(Boost 1.48.0 COMPONENTS date_time system program_options filesystem REQUIRED)
include_directories (SYSTEM
${Boost_INCLUDE_DIRS}
)
option(
MIR_DISABLE_EPOLL_REACTOR
"Disable boost::asio's epoll implementation and switch to a select-based reactor to account for ancient kernels on ppa builders."
OFF
)
if(MIR_DISABLE_EPOLL_REACTOR)
add_definitions(
-DBOOST_ASIO_DISABLE_EPOLL -DBOOST_ASIO_DISABLE_KQUEUE -DBOOST_ASIO_DISABLE_DEV_POLL
)
endif(MIR_DISABLE_EPOLL_REACTOR)
add_definitions(-DMESA_EGL_NO_X11_HEADERS)
# Default to KMS backend, but build all of them
set(
MIR_PLATFORM
mesa-kms;android;mesa-x11;eglstream-kms
CACHE
STRING
"a list of graphics backends to build (options are 'mesa-kms', 'android', 'mesa-x11', or 'eglstream-kms')"
)
list(GET MIR_PLATFORM 0 MIR_TEST_PLATFORM)
option(MIR_ENABLE_TESTS "Build tests" ON)
foreach(platform IN LISTS MIR_PLATFORM)
if (platform STREQUAL "mesa-kms")
set(MIR_BUILD_PLATFORM_MESA_KMS TRUE)
endif()
if (platform STREQUAL "android")
set(MIR_BUILD_PLATFORM_ANDROID TRUE)
endif()
if (platform STREQUAL "mesa-x11")
set(MIR_BUILD_PLATFORM_MESA_X11 TRUE)
endif()
if (platform STREQUAL "eglstream-kms")
set(MIR_BUILD_PLATFORM_EGLSTREAM_KMS TRUE)
endif()
endforeach(platform)
find_package(EGL REQUIRED)
find_package(GLESv2 REQUIRED)
find_package(GLM REQUIRED)
find_package(Protobuf REQUIRED )
find_package(CapnProto REQUIRED)
find_package(GLog REQUIRED)
find_package(GFlags REQUIRED)
find_package(LTTngUST REQUIRED)
pkg_check_modules(UDEV REQUIRED libudev)
pkg_check_modules(GLIB REQUIRED glib-2.0)
include_directories (SYSTEM ${GLESv2_INCLUDE_DIRS})
include_directories (SYSTEM ${EGL_INCLUDE_DIRS})
include_directories (SYSTEM ${GLM_INCLUDE_DIRS})
#
# Full OpenGL support is possibly complete but not yet perfect. So is
# presently disabled by default due to:
# 1. Black windows bug: https://bugs.freedesktop.org/show_bug.cgi?id=92265
# 2. Use of glEGLImageTargetTexture2DOES in:
# src/platform/graphics/egl_extensions.cpp
# possibly shouldn't work even though it does. Or should it?
#
#if (TARGET_ARCH STREQUAL "x86_64-linux-gnu" OR
# TARGET_ARCH STREQUAL "i386-linux-gnu")
# set(DEFAULT_LIBGL "libGL")
#else()
set(DEFAULT_LIBGL "libGLESv2")
#endif()
set(MIR_SERVER_LIBGL ${DEFAULT_LIBGL} CACHE STRING "OpenGL library to use in Mir servers {libGL,libGLESv2}")
if (MIR_SERVER_LIBGL STREQUAL "libGL")
pkg_check_modules(GL REQUIRED gl)
add_definitions(
-DGL_GLEXT_PROTOTYPES
-DMIR_SERVER_GL_H=
-DMIR_SERVER_GLEXT_H=
-DMIR_SERVER_EGL_OPENGL_BIT=EGL_OPENGL_BIT
-DMIR_SERVER_EGL_OPENGL_API=EGL_OPENGL_API
)
elseif (MIR_SERVER_LIBGL STREQUAL "libGLESv2")
pkg_check_modules(GL REQUIRED glesv2)
add_definitions(
-DMIR_SERVER_GL_H=
-DMIR_SERVER_GLEXT_H=
-DMIR_SERVER_EGL_OPENGL_BIT=EGL_OPENGL_ES2_BIT
-DMIR_SERVER_EGL_OPENGL_API=EGL_OPENGL_ES_API
)
else()
message(FATAL_ERROR "Invalid MIR_SERVER_LIBGL value ${MIR_SERVER_LIBGL}")
endif()
if (MIR_BUILD_PLATFORM_ANDROID)
find_package(AndroidProperties REQUIRED)
find_package(LibHardware REQUIRED)
endif()
if (MIR_BUILD_PLATFORM_MESA_KMS OR MIR_BUILD_PLATFORM_MESA_X11)
find_package( PkgConfig )
pkg_check_modules( GBM REQUIRED gbm>=9.0.0)
pkg_check_modules( DRM REQUIRED libdrm )
endif()
if (MIR_BUILD_PLATFORM_EGLSTREAM_KMS)
pkg_check_modules(EPOXY REQUIRED epoxy)
endif()
set(MIR_ANDROID_INCLUDE_DIRECTORIES) # to be filled by android-input
set(MIR_ANDROID_INPUT_COMPILE_FLAGS) # to be filled by android-input
set(MIR_3RD_PARTY_INCLUDE_DIRECTORIES)
add_subdirectory(3rd_party/)
set(MIR_TRACEPOINT_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/mir/tools)
set(MIR_GENERATED_INCLUDE_DIRECTORIES)
macro(uses_android_input _target_name)
set_property(TARGET ${_target_name} APPEND_STRING PROPERTY COMPILE_FLAGS "${MIR_ANDROID_INPUT_COMPILE_FLAGS}")
endmacro()
add_subdirectory(src/)
include_directories(${MIR_GENERATED_INCLUDE_DIRECTORIES})
# This copy is used by users of mirplatforminputevdev
if ("${LIBINPUT_VERSION}" VERSION_LESS "1.1")
add_definitions(-DMIR_LIBINPUT_HAS_ACCEL_PROFILE=0)
else ()
add_definitions(-DMIR_LIBINPUT_HAS_ACCEL_PROFILE=1)
endif ()
add_subdirectory(benchmarks/)
add_subdirectory(examples/)
add_subdirectory(playground/)
add_subdirectory(guides/)
add_subdirectory(cmake/)
if (MIR_ENABLE_TESTS)
find_package(GtestGmock REQUIRED)
pkg_check_modules(LIBEVDEV REQUIRED libevdev)
include_directories(${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR})
add_subdirectory(tests/)
# There's no nice way to format this. Thanks CMake.
mir_add_test(NAME LGPL-required
COMMAND /bin/sh -c "! grep -rl 'GNU General' ${PROJECT_SOURCE_DIR}/src/client ${PROJECT_SOURCE_DIR}/include/client ${PROJECT_SOURCE_DIR}/src/common ${PROJECT_SOURCE_DIR}/include/common ${PROJECT_SOURCE_DIR}/src/include/common ${PROJECT_SOURCE_DIR}/src/platform ${PROJECT_SOURCE_DIR}/include/platform ${PROJECT_SOURCE_DIR}/src/include/platform ${PROJECT_SOURCE_DIR}/src/capnproto"
)
mir_add_test(NAME GPL-required
COMMAND /bin/sh -c "! grep -rl 'GNU Lesser' ${PROJECT_SOURCE_DIR}/src/server ${PROJECT_SOURCE_DIR}/include/server ${PROJECT_SOURCE_DIR}/src/include/server ${PROJECT_SOURCE_DIR}/tests ${PROJECT_SOURCE_DIR}/examples"
)
mir_add_test(NAME package-abis
COMMAND /bin/sh -c "cd ${PROJECT_SOURCE_DIR} && tools/update_package_abis.sh --check --verbose")
endif ()
enable_coverage_report(mirserver)
include (cmake/Doxygen.cmake)
include (cmake/ABICheck.cmake)
add_custom_target(ptest
COMMAND "${CMAKE_SOURCE_DIR}/tools/run_ctests.sh" "--cost-file" "${CMAKE_BINARY_DIR}/ptest_ctest_cost_data.txt" "sh ${CMAKE_BINARY_DIR}/discover_all_tests.sh" "--" "$$ARGS"
)
add_custom_target(release-checks)
mir_check_no_unreleased_symbols(mirclient release-checks)
mir_check_no_unreleased_symbols(mircommon release-checks)
mir_check_no_unreleased_symbols(mircookie release-checks)
mir_check_no_unreleased_symbols(mirplatform release-checks)
mir_check_no_unreleased_symbols(mirprotobuf release-checks)
mir_check_no_unreleased_symbols(mirserver release-checks)
if (TARGET doc)
add_custom_target(doc-show
xdg-open ${CMAKE_BINARY_DIR}/doc/html/index.html
DEPENDS doc)
endif()
./playground/ 0000755 0000041 0000041 00000000000 13115234677 013440 5 ustar www-data www-data ./playground/render_surface.cpp 0000644 0000041 0000041 00000015230 13115234664 017130 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Author: Christopher James Halse Rogers
* Cemil Azizoglu
*/
#include
#include
#include
#include
#include
#include
#include "mir_toolkit/mir_client_library.h"
#include "mir_toolkit/rs/mir_render_surface.h"
#include "client_helpers.h"
namespace me = mir::examples;
class Pixel
{
public:
Pixel(void* addr, MirPixelFormat format)
: addr{addr},
format{format}
{
}
void write(int r, int g, int b, int a)
{
switch (format)
{
case mir_pixel_format_abgr_8888:
*((uint32_t*) addr) =
(uint32_t) a << 24 |
(uint32_t) b << 16 |
(uint32_t) g << 8 |
(uint32_t) r;
break;
case mir_pixel_format_xbgr_8888:
*((uint32_t*) addr) =
/* Not filling in the X byte is correct but buggy (LP: #1423462) */
(uint32_t) b << 16 |
(uint32_t) g << 8 |
(uint32_t) r;
break;
case mir_pixel_format_argb_8888:
*((uint32_t*) addr) =
(uint32_t) a << 24 |
(uint32_t) r << 16 |
(uint32_t) g << 8 |
(uint32_t) b;
break;
case mir_pixel_format_xrgb_8888:
*((uint32_t*) addr) =
/* Not filling in the X byte is correct but buggy (LP: #1423462) */
(uint32_t) r << 16 |
(uint32_t) g << 8 |
(uint32_t) b;
break;
case mir_pixel_format_rgb_888:
*((uint8_t*) addr) = r;
*((uint8_t*) addr + 1) = g;
*((uint8_t*) addr + 2) = b;
break;
case mir_pixel_format_bgr_888:
*((uint8_t*) addr) = b;
*((uint8_t*) addr + 1) = g;
*((uint8_t*) addr + 2) = r;
break;
default:
throw std::runtime_error{"Pixel format unsupported by Pixel::write!"};
}
}
public:
void* const addr;
MirPixelFormat const format;
};
class pixel_iterator : std::iterator
{
public:
pixel_iterator(MirGraphicsRegion const& region, int x, int y)
: x{x},
y{y},
buffer(region)
{
}
pixel_iterator(MirGraphicsRegion const& region)
: pixel_iterator(region, 0, 0)
{
}
pixel_iterator& operator++()
{
x++;
if (x == buffer.width)
{
x = 0;
y++;
}
return *this;
}
pixel_iterator operator++(int)
{
auto old = *this;
++(*this);
return old;
}
Pixel operator*() const
{
return Pixel{
buffer.vaddr + (x * MIR_BYTES_PER_PIXEL(buffer.pixel_format))
+ (y * buffer.stride), buffer.pixel_format};
}
bool operator==(pixel_iterator const& rhs)
{
return rhs.buffer.vaddr == buffer.vaddr &&
rhs.x == x &&
rhs.y == y;
}
bool operator!=(pixel_iterator const& rhs)
{
return !(*this == rhs);
}
private:
int x, y;
MirGraphicsRegion const buffer;
};
pixel_iterator begin(MirGraphicsRegion const& region)
{
return pixel_iterator(region);
}
pixel_iterator end(MirGraphicsRegion const& region)
{
return pixel_iterator{region, 0, region.height};
}
void fill_stream_with(MirBufferStream* stream, int r, int g, int b, int a)
{
MirGraphicsRegion buffer;
mir_buffer_stream_get_graphics_region(stream, &buffer);
for (auto pixel : buffer)
{
pixel.write(r, g, b, a);
}
}
void bounce_position(int& position, int& delta, int min, int max)
{
if (position <= min || position >= max)
{
delta = -delta;
}
position += delta;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
int main(int /*argc*/, char* /*argv*/[])
{
char const* socket = nullptr;
int const width = 200;
int const height = 200;
int baseColour = 255, dbase = 1;
unsigned int nformats{0};
MirPixelFormat pixel_format;
me::Connection connection{socket, "MirRenderSurface example"};
auto render_surface = mir_connection_create_render_surface_sync(connection, width, height);
if (!mir_render_surface_is_valid(render_surface))
throw std::runtime_error(
std::string(mir_render_surface_get_error_message(render_surface)));
auto spec = mir_create_normal_window_spec(connection, width, height);
mir_window_spec_set_name(spec, "Stream");
mir_window_spec_add_render_surface(spec, render_surface, width, height, 0, 0);
mir_connection_get_available_surface_formats(connection, &pixel_format, 1, &nformats);
if (nformats == 0)
throw std::runtime_error("no pixel formats for buffer stream");
printf("Software Driver selected pixel format %d\n", pixel_format);
auto buffer_stream = mir_render_surface_get_buffer_stream(
render_surface, width, height, pixel_format);
auto window = mir_create_window_sync(spec);
mir_window_spec_release(spec);
fill_stream_with(buffer_stream, 255, 0, 0, 128);
mir_buffer_stream_swap_buffers_sync(buffer_stream);
sigset_t halt_signals;
sigemptyset(&halt_signals);
sigaddset(&halt_signals, SIGTERM);
sigaddset(&halt_signals, SIGQUIT);
sigaddset(&halt_signals, SIGINT);
sigprocmask(SIG_BLOCK, &halt_signals, nullptr);
int const signal_watch{signalfd(-1, &halt_signals, SFD_CLOEXEC)};
pollfd signal_poll{
signal_watch,
POLLIN | POLLERR,
0
};
while (poll(&signal_poll, 1, 0) <= 0)
{
bounce_position(baseColour, dbase, 128, 255);
fill_stream_with(buffer_stream, baseColour, 0, 0, 128);
mir_buffer_stream_swap_buffers_sync(buffer_stream);
}
mir_render_surface_release(render_surface);
mir_window_release_sync(window);
close(signal_watch);
return 0;
}
#pragma GCC diagnostic pop
./playground/demo-shell/ 0000755 0000041 0000041 00000000000 13115234677 015471 5 ustar www-data www-data ./playground/demo-shell/CMakeLists.txt 0000644 0000041 0000041 00000000524 13115234664 020226 0 ustar www-data www-data add_library(demo-shell STATIC
demo_compositor.cpp
demo_renderer.cpp
window_manager.cpp
)
add_subdirectory(typo)
target_link_libraries(demo-shell typo)
mir_add_wrapped_executable(mir_proving_server
demo_shell.cpp
)
target_link_libraries(mir_proving_server
demo-shell
mirserver
playgroundserverconfig
exampleserverconfig
)
./playground/demo-shell/demo_renderer.cpp 0000644 0000041 0000041 00000034247 13115234664 021015 0 ustar www-data www-data /*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#define MIR_LOG_COMPONENT "DemoRenderer"
#include "typo_stub_renderer.h"
#ifdef TYPO_SUPPORTS_FREETYPE
#include "typo_freetype_renderer.h"
#endif
#include "demo_renderer.h"
#include
#include
#include
using namespace mir;
using namespace mir::examples;
using namespace mir::geometry;
using namespace mir::compositor;
using namespace mir::renderer;
namespace
{
struct Color
{
GLubyte r, g, b, a;
};
float penumbra_curve(float x)
{
return 1.0f - std::sin(x * M_PI / 2.0f);
}
GLuint generate_shadow_corner_texture(float opacity)
{
struct Texel
{
GLubyte luminance;
GLubyte alpha;
};
int const width = 256;
Texel image[width][width];
int const max = width - 1;
for (int y = 0; y < width; ++y)
{
float curve_y = opacity * 255.0f *
penumbra_curve(static_cast(y) / max);
for (int x = 0; x < width; ++x)
{
Texel *t = &image[y][x];
t->luminance = 0;
t->alpha = curve_y * penumbra_curve(static_cast(x) / max);
}
}
GLuint corner;
glGenTextures(1, &corner);
glBindTexture(GL_TEXTURE_2D, corner);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA,
width, width, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
image);
return corner;
}
GLuint generate_frame_corner_texture(float corner_radius,
Color const& color,
GLubyte highlight)
{
int const height = 256;
/*
* GCC 4.9 with optimizations enabled will generate armhf NEON/VFP instructions
* here that are not understood/implemented by Valgrind (but are by hardware),
* causing Valgrind to crash:
* eebe 0acc vcvt.s32.f32 s0, s0, #8
* So this clumsy expression below tricks the compiler into not using those
* optimized ARM instructions that Valgrind doesn't support yet:
*/
int const width = height / (1.0f / corner_radius);
Color image[height * height]; // Worst case still much faster than the heap
int const cx = width;
int const cy = cx;
int const radius_sqr = cx * cy;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
Color col = color;
// Set gradient
if (y < cy)
{
float brighten = (1.0f - (static_cast(y) / cy)) *
std::sin(x * M_PI / (2 * (width - 1)));
col.r += (highlight - col.r) * brighten;
col.g += (highlight - col.g) * brighten;
col.b += (highlight - col.b) * brighten;
}
// Cut out the corner in a circular shape.
if (x < cx && y < cy)
{
int dx = cx - x;
int dy = cy - y;
if (dx * dx + dy * dy >= radius_sqr)
col = {0, 0, 0, 0};
}
image[y * width + x] = col;
}
}
GLuint corner;
glGenTextures(1, &corner);
glBindTexture(GL_TEXTURE_2D, corner);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
image);
glGenerateMipmap(GL_TEXTURE_2D); // Antialiasing please
return corner;
}
static const GLchar inverse_fshader[] =
{
"#ifdef GL_ES\n"
"precision mediump float;\n"
"#endif\n"
"uniform sampler2D tex;\n"
"uniform float alpha;\n"
"varying vec2 v_texcoord;\n"
"void main() {\n"
" vec4 f = texture2D(tex, v_texcoord);\n"
" vec3 inverted = (vec3(1.0) - (f.rgb / f.a)) * f.a;\n"
" gl_FragColor = alpha*vec4(inverted, f.a);\n"
"}\n"
};
static const GLchar contrast_fshader[] =
{
"#ifdef GL_ES\n"
"precision mediump float;\n"
"#endif\n"
"uniform sampler2D tex;\n"
"uniform float alpha;\n"
"varying vec2 v_texcoord;\n"
"void main() {\n"
" vec4 raw = texture2D(tex, v_texcoord);\n"
" vec3 bent = (1.0 - cos(raw.rgb * 3.141592654)) / 2.0;\n"
" gl_FragColor = alpha * vec4(bent, raw.a);\n"
"}\n"
};
} // namespace
DemoRenderer::DemoRenderer(
graphics::DisplayBuffer& display_buffer,
float const titlebar_height,
float const shadow_radius) :
renderer::gl::Renderer(display_buffer),
titlebar_height{titlebar_height},
shadow_radius{shadow_radius},
corner_radius{0.5f},
colour_effect{none},
inverse_program(family.add_program(vshader, inverse_fshader)),
contrast_program(family.add_program(vshader, contrast_fshader)),
title_cache(std::make_shared())
{
shadow_corner_tex = generate_shadow_corner_texture(0.4f);
titlebar_corner_tex = generate_frame_corner_texture(corner_radius,
{128,128,128,255},
255);
clear_color[0] = clear_color[1] = clear_color[2] = 0.2f;
clear_color[3] = 1.0f;
#ifdef TYPO_SUPPORTS_FREETYPE
const char title_font_path[] = "/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf";
auto ftrenderer = std::make_shared();
if (ftrenderer->load(title_font_path, 128))
title_cache.change_renderer(ftrenderer);
else
mir::log_error("Failed to load titlebar font: %s", title_font_path);
#endif
}
DemoRenderer::~DemoRenderer()
{
glDeleteTextures(1, &shadow_corner_tex);
glDeleteTextures(1, &titlebar_corner_tex);
}
void DemoRenderer::begin(DecorMap&& d) const
{
decor_map = std::move(d);
title_cache.drop_unused();
title_cache.mark_all_unused();
}
void DemoRenderer::tessellate(std::vector& primitives,
graphics::Renderable const& renderable) const
{
renderer::gl::Renderer::tessellate(primitives, renderable);
auto d = decor_map.find(renderable.id());
if (d != decor_map.end())
{
auto& decor = d->second;
if (decor->type != Decoration::Type::none)
{
tessellate_shadow(primitives, renderable, shadow_radius);
tessellate_frame(primitives, renderable, titlebar_height,
decor->name.c_str());
}
}
}
void DemoRenderer::tessellate_shadow(std::vector& primitives,
graphics::Renderable const& renderable,
float radius) const
{
auto const& rect = renderable.screen_position();
GLfloat left = rect.top_left.x.as_int();
GLfloat right = left + rect.size.width.as_int();
GLfloat top = rect.top_left.y.as_int();
GLfloat bottom = top + rect.size.height.as_int();
auto n = primitives.size();
primitives.resize(n + 8);
GLfloat rightr = right + radius;
GLfloat leftr = left - radius;
GLfloat topr = top - radius;
GLfloat bottomr = bottom + radius;
auto& right_shadow = primitives[n++];
right_shadow.tex_id = shadow_corner_tex;
right_shadow.vertices[0] = {{right, top, 0.0f}, {0.0f, 0.0f}};
right_shadow.vertices[1] = {{rightr, top, 0.0f}, {1.0f, 0.0f}};
right_shadow.vertices[2] = {{rightr, bottom, 0.0f}, {1.0f, 0.0f}};
right_shadow.vertices[3] = {{right, bottom, 0.0f}, {0.0f, 0.0f}};
auto& left_shadow = primitives[n++];
left_shadow.tex_id = shadow_corner_tex;
left_shadow.vertices[0] = {{leftr, top, 0.0f}, {1.0f, 0.0f}};
left_shadow.vertices[1] = {{left, top, 0.0f}, {0.0f, 0.0f}};
left_shadow.vertices[2] = {{left, bottom, 0.0f}, {0.0f, 0.0f}};
left_shadow.vertices[3] = {{leftr, bottom, 0.0f}, {1.0f, 0.0f}};
auto& top_shadow = primitives[n++];
top_shadow.tex_id = shadow_corner_tex;
top_shadow.vertices[0] = {{left, topr, 0.0f}, {1.0f, 0.0f}};
top_shadow.vertices[1] = {{right, topr, 0.0f}, {1.0f, 0.0f}};
top_shadow.vertices[2] = {{right, top, 0.0f}, {0.0f, 0.0f}};
top_shadow.vertices[3] = {{left, top, 0.0f}, {0.0f, 0.0f}};
auto& bottom_shadow = primitives[n++];
bottom_shadow.tex_id = shadow_corner_tex;
bottom_shadow.vertices[0] = {{left, bottom, 0.0f}, {0.0f, 0.0f}};
bottom_shadow.vertices[1] = {{right, bottom, 0.0f}, {0.0f, 0.0f}};
bottom_shadow.vertices[2] = {{right, bottomr, 0.0f}, {1.0f, 0.0f}};
bottom_shadow.vertices[3] = {{left, bottomr, 0.0f}, {1.0f, 0.0f}};
auto& tr_shadow = primitives[n++];
tr_shadow.tex_id = shadow_corner_tex;
tr_shadow.vertices[0] = {{right, top, 0.0f}, {0.0f, 0.0f}};
tr_shadow.vertices[1] = {{right, topr, 0.0f}, {1.0f, 0.0f}};
tr_shadow.vertices[2] = {{rightr, topr, 0.0f}, {1.0f, 1.0f}};
tr_shadow.vertices[3] = {{rightr, top, 0.0f}, {0.0f, 1.0f}};
auto& br_shadow = primitives[n++];
br_shadow.tex_id = shadow_corner_tex;
br_shadow.vertices[0] = {{right, bottom, 0.0f}, {0.0f, 0.0f}};
br_shadow.vertices[1] = {{rightr, bottom, 0.0f}, {1.0f, 0.0f}};
br_shadow.vertices[2] = {{rightr, bottomr, 0.0f}, {1.0f, 1.0f}};
br_shadow.vertices[3] = {{right, bottomr, 0.0f}, {0.0f, 1.0f}};
auto& bl_shadow = primitives[n++];
bl_shadow.tex_id = shadow_corner_tex;
bl_shadow.vertices[0] = {{left, bottom, 0.0f}, {0.0f, 0.0f}};
bl_shadow.vertices[1] = {{left, bottomr, 0.0f}, {1.0f, 0.0f}};
bl_shadow.vertices[2] = {{leftr, bottomr, 0.0f}, {1.0f, 1.0f}};
bl_shadow.vertices[3] = {{leftr, bottom, 0.0f}, {0.0f, 1.0f}};
auto& tl_shadow = primitives[n++];
tl_shadow.tex_id = shadow_corner_tex;
tl_shadow.vertices[0] = {{left, top, 0.0f}, {0.0f, 0.0f}};
tl_shadow.vertices[1] = {{leftr, top, 0.0f}, {1.0f, 0.0f}};
tl_shadow.vertices[2] = {{leftr, topr, 0.0f}, {1.0f, 1.0f}};
tl_shadow.vertices[3] = {{left, topr, 0.0f}, {0.0f, 1.0f}};
}
void DemoRenderer::tessellate_frame(std::vector& primitives,
graphics::Renderable const& renderable,
float titlebar_height,
char const* name) const
{
auto const& rect = renderable.screen_position();
GLfloat left = rect.top_left.x.as_int();
GLfloat right = left + rect.size.width.as_int();
GLfloat top = rect.top_left.y.as_int();
auto n = primitives.size();
primitives.resize(n + 4);
GLfloat htop = top - titlebar_height;
GLfloat in = titlebar_height * corner_radius;
GLfloat inleft = left + in;
GLfloat inright = right - in;
GLfloat mid = (left + right) / 2.0f;
if (inleft > mid) inleft = mid;
if (inright < mid) inright = mid;
auto& top_left_corner = primitives[n++];
top_left_corner.tex_id = titlebar_corner_tex;
top_left_corner.vertices[0] = {{left, htop, 0.0f}, {0.0f, 0.0f}};
top_left_corner.vertices[1] = {{inleft, htop, 0.0f}, {1.0f, 0.0f}};
top_left_corner.vertices[2] = {{inleft, top, 0.0f}, {1.0f, 1.0f}};
top_left_corner.vertices[3] = {{left, top, 0.0f}, {0.0f, 1.0f}};
auto& top_right_corner = primitives[n++];
top_right_corner.tex_id = titlebar_corner_tex;
top_right_corner.vertices[0] = {{inright, htop, 0.0f}, {1.0f, 0.0f}};
top_right_corner.vertices[1] = {{right, htop, 0.0f}, {0.0f, 0.0f}};
top_right_corner.vertices[2] = {{right, top, 0.0f}, {0.0f, 1.0f}};
top_right_corner.vertices[3] = {{inright, top, 0.0f}, {1.0f, 1.0f}};
auto& titlebar = primitives[n++];
titlebar.tex_id = titlebar_corner_tex;
titlebar.vertices[0] = {{inleft, htop, 0.0f}, {1.0f, 0.0f}};
titlebar.vertices[1] = {{inright, htop, 0.0f}, {1.0f, 0.0f}};
titlebar.vertices[2] = {{inright, top, 0.0f}, {1.0f, 1.0f}};
titlebar.vertices[3] = {{inleft, top, 0.0f}, {1.0f, 1.0f}};
auto str = title_cache.get(name);
GLfloat text_vin = titlebar_height / 5;
GLfloat text_top = htop + text_vin;
GLfloat text_bot = top - text_vin;
GLfloat text_height = text_bot - text_top;
GLfloat text_scale = text_height / str.height;
GLfloat text_left = inleft;
GLfloat text_right = text_left + text_scale * str.width;
GLfloat text_u = 1.0f;
if (text_right > inright) // Title too long for window
{
text_u = (inright - text_left) / (text_right - text_left);
text_right = inright;
}
auto& text_prim = primitives[n++];
text_prim.tex_id = str.tex;
text_prim.vertices[0] = {{text_left, text_top, 0.0f}, {0.0f, 0.0f}};
text_prim.vertices[1] = {{text_right, text_top, 0.0f}, {text_u, 0.0f}};
text_prim.vertices[2] = {{text_right, text_bot, 0.0f}, {text_u, 1.0f}};
text_prim.vertices[3] = {{text_left, text_bot, 0.0f}, {0.0f, 1.0f}};
}
void DemoRenderer::set_colour_effect(ColourEffect e)
{
colour_effect = e;
}
void DemoRenderer::draw(graphics::Renderable const& renderable,
renderer::gl::Renderer::Program const& current_program) const
{
const renderer::gl::Renderer::Program* const programs[ColourEffect::neffects] =
{
¤t_program,
&inverse_program,
&contrast_program
};
renderer::gl::Renderer::draw(renderable, *programs[colour_effect]);
}
./playground/demo-shell/demo_compositor.cpp 0000644 0000041 0000041 00000015176 13115234664 021405 0 ustar www-data www-data /*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Kevin DuBois
*/
#include "mir/graphics/display_buffer.h"
#include "mir/compositor/compositor_report.h"
#include "mir/compositor/scene_element.h"
#include "demo_compositor.h"
namespace me = mir::examples;
namespace mg = mir::graphics;
namespace mc = mir::compositor;
namespace geom = mir::geometry;
std::mutex me::DemoCompositor::instances_mutex;
std::unordered_set me::DemoCompositor::instances;
me::DemoCompositor::DemoCompositor(
mg::DisplayBuffer& display_buffer,
std::shared_ptr const& report) :
display_buffer(display_buffer),
report(report),
viewport(display_buffer.view_area()),
zoom_mag{1.0f},
renderer(
display_buffer,
30.0f, //titlebar_height
80.0f) //shadow_radius
{
std::lock_guard lock(instances_mutex);
instances.insert(this);
}
me::DemoCompositor::~DemoCompositor()
{
std::lock_guard lock(instances_mutex);
instances.erase(this);
}
void me::DemoCompositor::for_each(std::function f)
{
std::lock_guard lock(instances_mutex);
for (auto& i : instances)
f(*i);
}
void me::DemoCompositor::composite(mc::SceneElementSequence&& elements)
{
report->began_frame(this);
//a simple filtering out of renderables that shouldn't be drawn
//the elements should be notified if they are rendered or not
bool nonrenderlist_elements{false};
mg::RenderableList renderable_list;
DecorMap decorated;
for(auto const& it : elements)
{
auto const& renderable = it->renderable();
bool embellished = false;
if (auto decor = it->decoration())
{
embellished = decor->type != mc::Decoration::Type::none;
decorated[renderable->id()] = std::move(decor);
}
if (embellished || viewport.overlaps(renderable->screen_position()))
{
renderable_list.push_back(renderable);
/*
* TODO: This logic could be replaced more cleanly in future by
* the surface stack logic setting decoration status more
* accurately for fullscreen surfaces.
*/
// Fullscreen and opaque? Definitely no embellishment
if (renderable->screen_position() == viewport &&
renderable->alpha() == 1.0f &&
!renderable->shaped() &&
renderable->transformation() == glm::mat4())
{
embellished = false;
nonrenderlist_elements = false; // Don't care what's underneath
}
it->rendered();
}
else
{
it->occluded();
}
nonrenderlist_elements |= embellished;
}
/*
* Note: Buffer lifetimes are ensured by the two objects holding
* references to them; elements and renderable_list.
* So no buffer is going to be released back to the client till
* both of those containers get destroyed (end of the function).
* Actually, there's a third reference held by the texture cache
* in GLRenderer, but that gets released earlier in render().
*/
elements.clear(); // Release those that didn't make it to renderable_list
if (!nonrenderlist_elements &&
viewport == display_buffer.view_area() && // no bypass while zoomed
display_buffer.overlay(renderable_list))
{
report->renderables_in_frame(this, renderable_list);
renderer.suspend();
}
else
{
renderer.set_output_transform(display_buffer.orientation(), display_buffer.mirror_mode());
renderer.set_viewport(viewport);
renderer.begin(std::move(decorated));
renderer.render(renderable_list);
report->renderables_in_frame(this, renderable_list);
report->rendered_frame(this);
// Release buffers back to the clients now that the swap has returned.
// It's important to do this before starting on the potentially slow
// flip() ...
// FIXME: This clear() call is blocking a little (LP: #1395421)
renderable_list.clear();
}
report->finished_frame(this);
}
void me::DemoCompositor::on_cursor_movement(
geometry::Point const& p)
{
cursor_pos = p;
if (zoom_mag != 1.0f)
update_viewport();
}
void me::DemoCompositor::zoom(float mag)
{
zoom_mag = mag;
update_viewport();
}
void me::DemoCompositor::set_colour_effect(me::ColourEffect e)
{
renderer.set_colour_effect(e);
}
void me::DemoCompositor::update_viewport()
{
auto const& view_area = display_buffer.view_area();
if (zoom_mag == 1.0f)
{
// The below calculations should yield the same result as this, but
// just in case there are any floating point precision errors,
// set it precisely:
viewport = view_area;
}
else
{
int db_width = view_area.size.width.as_int();
int db_height = view_area.size.height.as_int();
int db_x = view_area.top_left.x.as_int();
int db_y = view_area.top_left.y.as_int();
float zoom_width = db_width / zoom_mag;
float zoom_height = db_height / zoom_mag;
// Note the 0.5f. This is because cursors (and all input in general)
// measures coordinates at the centre of a pixel. But GL measures to
// the top-left corner of a pixel.
float screen_x = cursor_pos.x.as_int() + 0.5f - db_x;
float screen_y = cursor_pos.y.as_int() + 0.5f - db_y;
float normal_x = screen_x / db_width;
float normal_y = screen_y / db_height;
// Position the viewport so the cursor location matches up.
// This assumes the hardware cursor still traverses the physical
// screen and isn't being warped.
int zoom_x = db_x + (db_width - zoom_width) * normal_x;
int zoom_y = db_y + (db_height - zoom_height) * normal_y;
viewport = {{zoom_x, zoom_y}, {zoom_width, zoom_height}};
}
}
./playground/demo-shell/demo_compositor.h 0000644 0000041 0000041 00000004052 13115234416 021034 0 ustar www-data www-data /*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Kevin DuBois
*/
#ifndef MIR_EXAMPLES_DEMO_COMPOSITOR_H_
#define MIR_EXAMPLES_DEMO_COMPOSITOR_H_
#include "mir/compositor/display_buffer_compositor.h"
#include "mir/compositor/scene.h"
#include "mir/geometry/rectangle.h"
#include "mir/graphics/renderable.h"
#include "demo_renderer.h"
#include
#include
namespace mir
{
namespace compositor
{
class Scene;
class CompositorReport;
}
namespace graphics
{
class DisplayBuffer;
}
namespace examples
{
class DemoCompositor : public compositor::DisplayBufferCompositor
{
public:
DemoCompositor(
graphics::DisplayBuffer& display_buffer,
std::shared_ptr const& report);
~DemoCompositor();
void composite(compositor::SceneElementSequence&& elements) override;
void zoom(float mag);
void on_cursor_movement(geometry::Point const& p);
void set_colour_effect(ColourEffect);
static void for_each(std::function f);
private:
void update_viewport();
graphics::DisplayBuffer& display_buffer;
std::shared_ptr const report;
geometry::Rectangle viewport;
geometry::Point cursor_pos;
float zoom_mag;
DemoRenderer renderer;
static std::mutex instances_mutex;
static std::unordered_set instances;
};
} // namespace examples
} // namespace mir
#endif // MIR_EXAMPLES_DEMO_COMPOSITOR_H_
./playground/demo-shell/demo_renderer.h 0000644 0000041 0000041 00000004620 13115234416 020445 0 ustar www-data www-data /*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#ifndef MIR_EXAMPLES_DEMO_RENDERER_H_
#define MIR_EXAMPLES_DEMO_RENDERER_H_
#include "gl/renderer.h"
#include "mir/compositor/decoration.h"
#include "typo_glcache.h"
#include
namespace mir
{
namespace examples
{
enum ColourEffect
{
none,
inverse,
contrast,
neffects
};
typedef std::unordered_map> DecorMap;
class DemoRenderer : public renderer::gl::Renderer
{
public:
DemoRenderer(
graphics::DisplayBuffer& display_buffer,
float const titlebar_height,
float const shadow_radius);
~DemoRenderer();
void begin(DecorMap&&) const;
void set_colour_effect(ColourEffect);
protected:
void tessellate(std::vector& primitives,
graphics::Renderable const& renderable) const override;
void draw(graphics::Renderable const& renderable,
Renderer::Program const& prog) const override;
private:
void tessellate_shadow(
std::vector& primitives,
graphics::Renderable const& renderable,
float radius) const;
void tessellate_frame(
std::vector& primitives,
graphics::Renderable const& renderable,
float titlebar_height,
char const* name) const;
float const titlebar_height;
float const shadow_radius;
float const corner_radius;
GLuint shadow_corner_tex;
GLuint titlebar_corner_tex;
ColourEffect colour_effect;
Program inverse_program, contrast_program;
mutable DecorMap decor_map;
mutable typo::GLCache title_cache;
};
} // namespace examples
} // namespace mir
#endif // MIR_EXAMPLES_DEMO_RENDERER_H_
./playground/demo-shell/typo/ 0000755 0000041 0000041 00000000000 13115234677 016464 5 ustar www-data www-data ./playground/demo-shell/typo/CMakeLists.txt 0000644 0000041 0000041 00000001104 13115234664 021214 0 ustar www-data www-data find_package(PkgConfig)
pkg_search_module(FREETYPE freetype2)
if (FREETYPE_FOUND)
set(OPTIONAL_SRCS typo_freetype_renderer.cpp)
endif ()
add_library(typo STATIC
typo_renderer.cpp
typo_stub_renderer.cpp
typo_glcache.cpp
${OPTIONAL_SRCS}
)
target_link_libraries(typo ${GL_LIBRARIES})
target_include_directories(typo PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
if (FREETYPE_FOUND)
target_compile_definitions(typo PUBLIC -DTYPO_SUPPORTS_FREETYPE)
target_link_libraries(typo ${FREETYPE_LIBRARIES})
target_include_directories(typo PUBLIC ${FREETYPE_INCLUDE_DIRS})
endif ()
./playground/demo-shell/typo/typo_renderer.cpp 0000644 0000041 0000041 00000002773 13115234664 022056 0 ustar www-data www-data /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#include "typo_renderer.h"
#include
using namespace mir::typo;
Renderer::Image::Image()
: buf(nullptr), width_(0), stride_(0), height_(0), align_(4),
format_(alpha8)
{
}
Renderer::Image::~Image()
{
delete[] buf;
}
void Renderer::Image::reserve(int w, int h, Format f)
{
width_ = w;
height_ = h;
format_ = f;
int const bpp = 1; // format is always alpha8
stride_ = (((width_ * bpp) + align_ - 1) / align_) * align_;
delete[] buf;
auto size = stride_ * height_;
buf = new unsigned char[size];
memset(buf, 0, size);
}
Renderer::~Renderer()
{
}
unsigned long Renderer::unicode_from_utf8(char const** utf8)
{
int char_len = 1; // TODO: Add support for non-ASCII UTF-8
unsigned long unicode = **utf8;
if (unicode)
*utf8 += char_len;
return unicode;
}
./playground/demo-shell/typo/typo_stub_renderer.cpp 0000644 0000041 0000041 00000002721 13115234664 023104 0 ustar www-data www-data /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#include "typo_stub_renderer.h"
#include
using namespace mir::typo;
void StubRenderer::render(char const* str, Image& img)
{
int const char_width = 8;
int const char_height = 16;
int const char_space = 2;
int const tex_height = 20;
int const len = strlen(str);
int const top = (tex_height - char_height) / 2;
img.reserve(len*(char_width+char_space) - char_space, tex_height,
Image::alpha8);
char const* s = str;
for (int n = 0; unicode_from_utf8(&s); ++n)
{
unsigned char* row = img.data() + top*img.stride() +
n*(char_width+char_space);
for (int y = 0; y < char_height; ++y)
{
memset(row, 255, char_width);
row += img.stride();
}
}
}
./playground/demo-shell/typo/typo_freetype_renderer.h 0000644 0000041 0000041 00000002323 13115234664 023415 0 ustar www-data www-data /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#ifndef MIR_TYPO_FREETYPE_RENDERER_H_
#define MIR_TYPO_FREETYPE_RENDERER_H_
#include "typo_renderer.h"
#include
#include FT_FREETYPE_H
namespace mir { namespace typo {
class FreetypeRenderer : public Renderer
{
public:
FreetypeRenderer();
~FreetypeRenderer();
bool load(char const* font_path, int pref_height);
void render(char const* str, Image& img) override;
private:
FT_Library lib;
FT_Face face;
int preferred_height;
};
} } // namespace mir::typo
#endif // MIR_TYPO_FREETYPE_RENDERER_H_
./playground/demo-shell/typo/typo_stub_renderer.h 0000644 0000041 0000041 00000001744 13115234664 022555 0 ustar www-data www-data /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#ifndef MIR_TYPO_STUB_RENDERER_H_
#define MIR_TYPO_STUB_RENDERER_H_
#include "typo_renderer.h"
namespace mir { namespace typo {
class StubRenderer : public Renderer
{
public:
void render(char const* str, Image& img) override;
};
} } // namespace mir::typo
#endif // MIR_TYPO_STUB_RENDERER_H_
./playground/demo-shell/typo/typo_freetype_renderer.cpp 0000644 0000041 0000041 00000007103 13115234664 023751 0 ustar www-data www-data /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#include "typo_freetype_renderer.h"
#include
#include
using namespace mir::typo;
FreetypeRenderer::FreetypeRenderer()
: lib(nullptr), face(nullptr), preferred_height(16)
{
if (FT_Init_FreeType(&lib))
throw std::runtime_error("FreeType init failed");
}
FreetypeRenderer::~FreetypeRenderer()
{
if (face) FT_Done_Face(face);
if (lib) FT_Done_FreeType(lib);
}
bool FreetypeRenderer::load(char const* font_path, int pref_height)
{
preferred_height = pref_height;
if (face)
{
FT_Done_Face(face);
face = nullptr;
}
if (FT_New_Face(lib, font_path, 0, &face))
return false;
FT_Set_Pixel_Sizes(face, 0, preferred_height);
return true;
}
void FreetypeRenderer::render(char const* str, Image& img)
{
int minx = 0, maxx = 0, miny = 0, maxy = 0;
int penx = 0, peny = 0;
FT_GlyphSlot slot = face->glyph;
char const* s = str;
while (unsigned long u = unicode_from_utf8(&s))
{
auto glyph = FT_Get_Char_Index(face, u);
FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT);
FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
int left = penx + slot->bitmap_left;
if (left < minx) minx = left;
int right = left + slot->bitmap.width;
if (right > maxx) maxx = right;
int top = peny - slot->bitmap_top;
if (top < miny) miny = top;
int bottom = top + slot->bitmap.rows;
if (bottom > maxy) maxy = bottom;
penx += slot->advance.x >> 6;
peny += slot->advance.y >> 6;
}
int const padding = preferred_height / 8; // Allow mipmapping to smear
int width = maxx - minx + 1 + 2*padding;
int height = maxy - miny + 1;
if (height < preferred_height) // e.g. str has no descenders, but make
height = preferred_height; // room so we get a consistent height
height += 2*padding;
penx = -minx + padding;
peny = -miny + padding;
img.reserve(width, height, Image::alpha8);
s = str;
while (unsigned long u = unicode_from_utf8(&s))
{
auto glyph = FT_Get_Char_Index(face, u);
FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT);
FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
auto& bitmap = slot->bitmap;
int x = penx + slot->bitmap_left;
int y = peny - slot->bitmap_top;
int right = x + bitmap.width;
int bottom = y + bitmap.rows;
if (x >= 0 && right <= width && y >= 0 && bottom <= height)
{
unsigned char* src = bitmap.buffer;
unsigned char* dest = img.data() + y*img.stride() + x;
int ylimit = y + bitmap.rows;
for (; y < ylimit; ++y)
{
memcpy(dest, src, bitmap.width);
src += bitmap.pitch;
dest += img.stride();
}
}
penx += slot->advance.x >> 6;
peny += slot->advance.y >> 6;
}
}
./playground/demo-shell/typo/typo_renderer.h 0000644 0000041 0000041 00000003276 13115234664 021522 0 ustar www-data www-data /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#ifndef MIR_TYPO_RENDERER_H_
#define MIR_TYPO_RENDERER_H_
namespace mir { namespace typo {
class Renderer
{
public:
class Image
{
public:
Image();
Image(Image const&) = delete;
Image(Image const&&) = delete;
Image& operator=(Image const&) = delete;
~Image();
typedef enum {alpha8} Format;
void reserve(int w, int h, Format f);
unsigned char* data() const { return buf; };
int width() const { return width_; }
int height() const { return height_; }
int stride() const { return stride_; }
int alignment() const { return align_; }
Format format() const { return format_; }
private:
unsigned char* buf;
int width_, stride_, height_, align_;
Format format_;
};
virtual ~Renderer();
virtual void render(char const* str, Image& img) = 0;
protected:
static unsigned long unicode_from_utf8(char const** utf8);
};
} } // namespace mir::typo
#endif // MIR_TYPO_RENDERER_H_
./playground/demo-shell/typo/typo_glcache.cpp 0000644 0000041 0000041 00000005145 13115234664 021632 0 ustar www-data www-data /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#include "typo_glcache.h"
#include MIR_SERVER_GL_H
using namespace mir::typo;
GLCache::GLCache(std::shared_ptr const& r)
: renderer(r)
{
}
GLCache::~GLCache()
{
clear();
}
void GLCache::change_renderer(std::shared_ptr const& r)
{
clear();
renderer = r;
}
void GLCache::clear()
{
for (auto& e : map)
glDeleteTextures(1, &e.second.tex);
map.clear();
}
void GLCache::mark_all_unused()
{
for (auto& e : map)
e.second.used = false;
}
void GLCache::drop_unused()
{
for (auto e = map.begin(); e != map.end();)
{
if (!e->second.used)
{
glDeleteTextures(1, &e->second.tex);
e = map.erase(e);
}
else
e++;
}
}
bool GLCache::Entry::valid() const
{
return width > 0 && height > 0;
}
GLCache::Entry const& GLCache::get(char const* str)
{
Entry& entry = map[str];
if (!entry.valid())
{
Renderer::Image img;
renderer->render(str, img);
if (img.data())
{
entry.width = img.width();
entry.height = img.height();
glGenTextures(1, &entry.tex);
glBindTexture(GL_TEXTURE_2D, entry.tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glPixelStorei(GL_UNPACK_ALIGNMENT, img.alignment());
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
img.width(), img.height(), 0, GL_ALPHA,
GL_UNSIGNED_BYTE, img.data());
glGenerateMipmap(GL_TEXTURE_2D); // Antialiasing shrinkage please
}
}
entry.used = true;
return entry;
}
./playground/demo-shell/typo/typo_glcache.h 0000644 0000041 0000041 00000002700 13115234664 021271 0 ustar www-data www-data /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#ifndef MIR_TYPO_GLCACHE_H_
#define MIR_TYPO_GLCACHE_H_
#include "typo_renderer.h"
#include
#include
#include
namespace mir { namespace typo {
class GLCache
{
public:
struct Entry
{
bool valid() const;
unsigned int tex = 0;
int width = 0, height = 0;
bool used = false;
};
explicit GLCache(std::shared_ptr const&);
~GLCache();
void change_renderer(std::shared_ptr const&);
Entry const& get(char const* str);
void clear();
void mark_all_unused();
void drop_unused();
private:
typedef std::unordered_map Map;
Map map;
std::shared_ptr renderer;
};
} } // namespace mir::typo
#endif // MIR_TYPO_GLCACHE_H_
./playground/demo-shell/demo_shell.cpp 0000644 0000041 0000041 00000006741 13115234664 020314 0 ustar www-data www-data /*
* Copyright © 2013-2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Robert Carr
*/
/// \example demo_shell.cpp A simple mir shell
#include "demo_compositor.h"
#include "window_manager.h"
#include "../server_configuration.h"
#include "mir/run_mir.h"
#include "mir/report_exception.h"
#include "mir/graphics/display.h"
#include "mir/input/composite_event_filter.h"
#include "mir/compositor/display_buffer_compositor_factory.h"
#include "mir/renderer/renderer_factory.h"
#include "mir/options/option.h"
#include "server_example_host_lifecycle_event_listener.h"
#include
namespace me = mir::examples;
namespace ms = mir::scene;
namespace mg = mir::graphics;
namespace mf = mir::frontend;
namespace mi = mir::input;
namespace mc = mir::compositor;
namespace msh = mir::shell;
namespace mir
{
namespace examples
{
class DisplayBufferCompositorFactory : public mc::DisplayBufferCompositorFactory
{
public:
DisplayBufferCompositorFactory(
std::shared_ptr const& report) :
report(report)
{
}
std::unique_ptr create_compositor_for(
mg::DisplayBuffer& display_buffer) override
{
return std::unique_ptr(
new me::DemoCompositor{display_buffer, report});
}
private:
std::shared_ptr const report;
};
class DemoServerConfiguration : public mir::examples::ServerConfiguration
{
public:
using mir::examples::ServerConfiguration::ServerConfiguration;
std::shared_ptr the_display_buffer_compositor_factory() override
{
return display_buffer_compositor_factory(
[this]()
{
return std::make_shared(
the_compositor_report());
});
}
std::shared_ptr the_host_lifecycle_event_listener() override
{
return host_lifecycle_event_listener(
[this]()
{
return std::make_shared(the_logger());
});
}
};
}
}
int main(int argc, char const* argv[])
try
{
me::DemoServerConfiguration config(argc, argv);
auto wm = std::make_shared();
mir::run_mir(config, [&config, &wm](mir::DisplayServer&)
{
// We use this strange two stage initialization to avoid a circular dependency between the EventFilters
// and the SessionStore
wm->set_focus_controller(config.the_focus_controller());
wm->set_display(config.the_display());
wm->set_compositor(config.the_compositor());
wm->set_input_scene(config.the_input_scene());
config.the_composite_event_filter()->prepend(wm);
});
return 0;
}
catch (...)
{
mir::report_exception(std::cerr);
return 1;
}
./playground/demo-shell/window_manager.h 0000644 0000041 0000041 00000005425 13115234664 020645 0 ustar www-data www-data /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Robert Carr
*/
#ifndef MIR_EXAMPLES_WINDOW_MANAGER_H_
#define MIR_EXAMPLES_WINDOW_MANAGER_H_
#include "mir/input/event_filter.h"
#include "mir/input/scene.h"
#include "mir/geometry/displacement.h"
#include "mir/geometry/size.h"
#include "demo_renderer.h"
#include
namespace mir
{
namespace shell
{
class FocusController;
}
namespace graphics
{
class Display;
}
namespace compositor
{
class Compositor;
}
namespace scene { class Surface; }
namespace examples
{
class WindowManager : public input::EventFilter
{
public:
WindowManager();
~WindowManager() = default;
void set_focus_controller(std::shared_ptr const& focus_controller);
void set_display(std::shared_ptr const& display);
void set_compositor(std::shared_ptr const& compositor);
void set_input_scene(std::shared_ptr const& scene);
void force_redraw();
bool handle(MirEvent const& event) override;
protected:
WindowManager(const WindowManager&) = delete;
WindowManager& operator=(const WindowManager&) = delete;
private:
std::shared_ptr focus_controller;
std::shared_ptr display;
std::shared_ptr compositor;
std::shared_ptr input_scene;
geometry::Point click;
geometry::Point old_pos;
geometry::Point old_cursor;
geometry::Size old_size;
float old_pinch_diam;
int max_fingers; // Maximum number of fingers touched during gesture
float zoom_exponent = 0.0f;
ColourEffect colour_effect = none;
void toggle(ColourEffect);
enum {left_edge, hmiddle, right_edge} xedge = hmiddle;
enum {top_edge, vmiddle, bottom_edge} yedge = vmiddle;
void save_edges(scene::Surface& surf, geometry::Point const& p);
void resize(scene::Surface& surf, geometry::Point const& cursor) const;
bool handle_key_event(MirKeyboardEvent const* event);
bool handle_touch_event(MirTouchEvent const* event);
bool handle_pointer_event(MirPointerEvent const* event);
};
}
} // namespace mir
#endif // MIR_EXAMPLES_WINDOW_MANAGER_H_
./playground/demo-shell/window_manager.cpp 0000644 0000041 0000041 00000044131 13115234664 021175 0 ustar www-data www-data /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Robert Carr
* Daniel van Vugt
*/
#include "window_manager.h"
#include "demo_compositor.h"
#include "mir/shell/focus_controller.h"
#include "mir/scene/session.h"
#include "mir/scene/surface.h"
#include "mir/graphics/display.h"
#include "mir/graphics/display_configuration.h"
#include "mir/compositor/compositor.h"
#include
#include
#include
#include
namespace me = mir::examples;
namespace msh = mir::shell;
namespace mg = mir::graphics;
namespace mc = mir::compositor;
namespace mi = mir::input;
namespace
{
const int min_swipe_distance = 100; // How long must a swipe be to act on?
}
me::WindowManager::WindowManager()
: old_pinch_diam(0.0f), max_fingers(0)
{
}
void me::WindowManager::set_focus_controller(std::shared_ptr const& controller)
{
focus_controller = controller;
}
void me::WindowManager::set_display(std::shared_ptr const& dpy)
{
display = dpy;
}
void me::WindowManager::set_compositor(std::shared_ptr const& cptor)
{
compositor = cptor;
}
void me::WindowManager::set_input_scene(std::shared_ptr const& s)
{
input_scene = s;
}
void me::WindowManager::force_redraw()
{
// This is clumsy, but the only option our architecture allows us for now
// Same hack as used in TouchspotController...
input_scene->emit_scene_changed();
}
namespace
{
mir::geometry::Point average_pointer(MirTouchEvent const* tev)
{
using namespace mir;
using namespace geometry;
int x = 0, y = 0;
int count = mir_touch_event_point_count(tev);
for (int i = 0; i < count; i++)
{
x += mir_touch_event_axis_value(tev, i, mir_touch_axis_x);
y += mir_touch_event_axis_value(tev, i, mir_touch_axis_y);
}
x /= count;
y /= count;
return Point{x, y};
}
float measure_pinch(MirTouchEvent const* tev,
mir::geometry::Displacement& dir)
{
int count = mir_touch_event_point_count(tev);
int max = 0;
for (int i = 0; i < count; i++)
{
for (int j = 0; j < i; j++)
{
int dx = mir_touch_event_axis_value(tev, i, mir_touch_axis_x) -
mir_touch_event_axis_value(tev, j, mir_touch_axis_x);
int dy = mir_touch_event_axis_value(tev, i, mir_touch_axis_y) -
mir_touch_event_axis_value(tev, j, mir_touch_axis_y);
int sqr = dx*dx + dy*dy;
if (sqr > max)
{
max = sqr;
dir = mir::geometry::Displacement{dx, dy};
}
}
}
return sqrtf(max); // return pinch diameter
}
} // namespace
void me::WindowManager::toggle(ColourEffect which)
{
colour_effect = (colour_effect == which) ? none : which;
me::DemoCompositor::for_each([this](me::DemoCompositor& c)
{
c.set_colour_effect(colour_effect);
});
force_redraw();
}
void me::WindowManager::save_edges(scene::Surface& surf,
geometry::Point const& p)
{
int width = surf.size().width.as_int();
int height = surf.size().height.as_int();
int left = surf.top_left().x.as_int();
int right = left + width;
int top = surf.top_left().y.as_int();
int bottom = top + height;
int leftish = left + width/3;
int rightish = right - width/3;
int topish = top + height/3;
int bottomish = bottom - height/3;
int click_x = p.x.as_int();
xedge = (click_x <= leftish) ? left_edge :
(click_x >= rightish) ? right_edge :
hmiddle;
int click_y = p.y.as_int();
yedge = (click_y <= topish) ? top_edge :
(click_y >= bottomish) ? bottom_edge :
vmiddle;
}
void me::WindowManager::resize(scene::Surface& surf,
geometry::Point const& cursor) const
{
int width = surf.size().width.as_int();
int height = surf.size().height.as_int();
int left = surf.top_left().x.as_int();
int right = left + width;
int top = surf.top_left().y.as_int();
int bottom = top + height;
geometry::Displacement drag = cursor - old_cursor;
int dx = drag.dx.as_int();
int dy = drag.dy.as_int();
if (xedge == left_edge && dx < width)
left = old_pos.x.as_int() + dx;
else if (xedge == right_edge)
right = old_pos.x.as_int() + old_size.width.as_int() + dx;
if (yedge == top_edge && dy < height)
top = old_pos.y.as_int() + dy;
else if (yedge == bottom_edge)
bottom = old_pos.y.as_int() + old_size.height.as_int() + dy;
surf.move_to({left, top});
surf.resize({right-left, bottom-top});
}
bool me::WindowManager::handle_key_event(MirKeyboardEvent const* kev)
{
// TODO: Fix android configuration and remove static hack ~racarr
static bool display_off = false;
if (mir_keyboard_event_action(kev) != mir_keyboard_action_down)
return false;
auto modifiers = mir_keyboard_event_modifiers(kev);
auto scan_code = mir_keyboard_event_scan_code(kev);
if (modifiers & mir_input_event_modifier_alt &&
scan_code == KEY_TAB) // TODO: Use keycode once we support keymapping on the server side
{
focus_controller->focus_next_session();
if (auto const surface = focus_controller->focused_surface())
focus_controller->raise({surface});
return true;
}
else if (modifiers & mir_input_event_modifier_alt &&
scan_code == KEY_GRAVE)
{
if (auto const prev = focus_controller->focused_surface())
{
auto const app = focus_controller->focused_session();
auto const next = app->surface_after(prev);
focus_controller->set_focus_to(app, next);
focus_controller->raise({next});
}
return true;
}
else if (modifiers & mir_input_event_modifier_alt &&
scan_code == KEY_F4)
{
auto const surf = focus_controller->focused_surface();
if (surf)
surf->request_client_surface_close();
return true;
}
else if ((modifiers & mir_input_event_modifier_alt &&
scan_code == KEY_P) ||
(scan_code == KEY_POWER))
{
compositor->stop();
auto conf = display->configuration();
MirPowerMode new_power_mode = display_off ?
mir_power_mode_on : mir_power_mode_off;
conf->for_each_output(
[&](mg::UserDisplayConfigurationOutput& output) -> void
{
output.power_mode = new_power_mode;
});
display_off = !display_off;
display->configure(*conf.get());
if (!display_off)
compositor->start();
return true;
}
else if ((modifiers & mir_input_event_modifier_alt) &&
(modifiers & mir_input_event_modifier_ctrl) &&
(scan_code == KEY_ESC))
{
std::abort();
return true;
}
else if ((modifiers & mir_input_event_modifier_alt) &&
(modifiers & mir_input_event_modifier_ctrl) &&
(scan_code == KEY_L) &&
focus_controller)
{
auto const app = focus_controller->focused_session();
if (app)
{
app->set_lifecycle_state(mir_lifecycle_state_will_suspend);
}
}
else if ((modifiers & mir_input_event_modifier_alt) &&
(modifiers & mir_input_event_modifier_ctrl))
{
MirOrientation orientation = mir_orientation_normal;
bool rotating = true;
int mode_change = 0;
bool preferred_mode = false;
switch (scan_code)
{
case KEY_UP: orientation = mir_orientation_normal; break;
case KEY_DOWN: orientation = mir_orientation_inverted; break;
case KEY_LEFT: orientation = mir_orientation_left; break;
case KEY_RIGHT: orientation = mir_orientation_right; break;
default: rotating = false; break;
}
switch (scan_code)
{
case KEY_MINUS: mode_change = -1; break;
case KEY_EQUAL: mode_change = +1; break;
case KEY_0: preferred_mode = true; break;
default: break;
}
if (rotating || mode_change || preferred_mode)
{
compositor->stop();
auto conf = display->configuration();
conf->for_each_output(
[&](mg::UserDisplayConfigurationOutput& output) -> void
{
// Only apply changes to the monitor the cursor is on
if (!output.extents().contains(old_cursor))
return;
if (rotating)
output.orientation = orientation;
if (preferred_mode)
{
output.current_mode_index =
output.preferred_mode_index;
}
else if (mode_change)
{
size_t nmodes = output.modes.size();
if (nmodes)
output.current_mode_index =
(output.current_mode_index + nmodes +
mode_change) % nmodes;
}
});
display->configure(*conf);
compositor->start();
return true;
}
}
else if ((scan_code == KEY_VOLUMEDOWN ||
scan_code == KEY_VOLUMEUP) &&
max_fingers == 1)
{
int delta = (scan_code == KEY_VOLUMEDOWN) ? -1 : +1;
static const MirOrientation order[4] =
{
mir_orientation_normal,
mir_orientation_right,
mir_orientation_inverted,
mir_orientation_left
};
compositor->stop();
auto conf = display->configuration();
conf->for_each_output(
[&](mg::UserDisplayConfigurationOutput& output)
{
int i = 0;
for (; i < 4; ++i)
{
if (output.orientation == order[i])
break;
}
output.orientation = order[(i+4+delta) % 4];
});
display->configure(*conf.get());
compositor->start();
return true;
}
else if (modifiers & mir_input_event_modifier_meta &&
scan_code == KEY_N)
{
toggle(inverse);
return true;
}
else if (modifiers & mir_input_event_modifier_meta &&
scan_code == KEY_C)
{
toggle(contrast);
return true;
}
return false;
}
bool me::WindowManager::handle_pointer_event(MirPointerEvent const* pev)
{
bool handled = false;
geometry::Point cursor{mir_pointer_event_axis_value(pev, mir_pointer_axis_x),
mir_pointer_event_axis_value(pev, mir_pointer_axis_y)};
auto action = mir_pointer_event_action(pev);
auto modifiers = mir_pointer_event_modifiers(pev);
auto vscroll = mir_pointer_event_axis_value(pev, mir_pointer_axis_vscroll);
auto primary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_primary);
auto tertiary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_tertiary);
float new_zoom_mag = 0.0f; // zero means unchanged
if (modifiers & mir_input_event_modifier_meta &&
action == mir_pointer_action_motion &&
vscroll != 0.0f)
{
zoom_exponent += vscroll;
// Negative exponents do work too, but disable them until
// there's a clear edge to the desktop.
if (zoom_exponent < 0)
zoom_exponent = 0;
new_zoom_mag = powf(1.2f, zoom_exponent);
handled = true;
}
me::DemoCompositor::for_each(
[new_zoom_mag,&cursor](me::DemoCompositor& c)
{
if (new_zoom_mag > 0.0f)
c.zoom(new_zoom_mag);
c.on_cursor_movement(cursor);
});
if (zoom_exponent || new_zoom_mag)
force_redraw();
auto const surf = focus_controller->focused_surface();
if (surf &&
(modifiers & mir_input_event_modifier_alt) && (primary_button_pressed || tertiary_button_pressed))
{
// Start of a gesture: When the latest finger/button goes down
if (action == mir_pointer_action_button_down)
{
click = cursor;
save_edges(*surf, click);
handled = true;
}
else if (action == mir_pointer_action_motion)
{
geometry::Displacement drag = cursor - old_cursor;
if (tertiary_button_pressed)
{ // Resize by mouse middle button
resize(*surf, cursor);
}
else
{
surf->move_to(old_pos + drag);
}
handled = true;
}
old_pos = surf->top_left();
old_size = surf->size();
}
if (surf &&
(modifiers & mir_input_event_modifier_alt) &&
action == mir_pointer_action_motion &&
vscroll)
{
float alpha = surf->alpha();
alpha += vscroll > 0.0f ? 0.1f : -0.1f;
if (alpha < 0.0f)
alpha = 0.0f;
else if (alpha > 1.0f)
alpha = 1.0f;
surf->set_alpha(alpha);
handled = true;
}
old_cursor = cursor;
return handled;
}
namespace
{
bool any_touches_went_down(MirTouchEvent const* tev)
{
auto count = mir_touch_event_point_count(tev);
for (unsigned i = 0; i < count; i++)
{
if (mir_touch_event_action(tev, i) == mir_touch_action_down)
return true;
}
return false;
}
bool last_touch_released(MirTouchEvent const* tev)
{
auto count = mir_touch_event_point_count(tev);
if (count > 1)
return false;
return mir_touch_event_action(tev, 0) == mir_touch_action_up;
}
}
bool me::WindowManager::handle_touch_event(MirTouchEvent const* tev)
{
bool handled = false;
geometry::Point cursor = average_pointer(tev);
auto const& modifiers = mir_touch_event_modifiers(tev);
int fingers = mir_touch_event_point_count(tev);
if (fingers > max_fingers)
max_fingers = fingers;
auto const surf = focus_controller->focused_surface();
if (surf &&
(modifiers & mir_input_event_modifier_alt ||
fingers >= 3))
{
geometry::Displacement pinch_dir;
auto pinch_diam =
measure_pinch(tev, pinch_dir);
// Start of a gesture: When the latest finger/button goes down
if (any_touches_went_down(tev))
{
click = cursor;
save_edges(*surf, click);
handled = true;
}
else if(max_fingers <= 3) // Avoid accidental movement
{
geometry::Displacement drag = cursor - old_cursor;
surf->move_to(old_pos + drag);
if (fingers == 3)
{ // Resize by pinch/zoom
float diam_delta = pinch_diam - old_pinch_diam;
/*
* Resize vector (dx,dy) has length=diam_delta and
* direction=pinch_dir, so solve for (dx,dy)...
*/
float lenlen = diam_delta * diam_delta;
int x = pinch_dir.dx.as_int();
int y = pinch_dir.dy.as_int();
int xx = x * x;
int yy = y * y;
int xxyy = xx + yy;
int dx = sqrtf(lenlen * xx / xxyy);
int dy = sqrtf(lenlen * yy / xxyy);
if (diam_delta < 0.0f)
{
dx = -dx;
dy = -dy;
}
int width = old_size.width.as_int() + dx;
int height = old_size.height.as_int() + dy;
surf->resize({width, height});
}
handled = true;
}
old_pos = surf->top_left();
old_size = surf->size();
old_pinch_diam = pinch_diam;
}
auto gesture_ended = last_touch_released(tev);
if (max_fingers == 4 && gesture_ended)
{ // Four fingers released
geometry::Displacement dir = cursor - click;
if (abs(dir.dx.as_int()) >= min_swipe_distance)
{
focus_controller->focus_next_session();
if (auto const surface = focus_controller->focused_surface())
focus_controller->raise({surface});
handled = true;
}
}
if (fingers == 1 && gesture_ended)
max_fingers = 0;
old_cursor = cursor;
/*
* For now we reserve all 3 or 4 finger gestures for window manipulation.
* Make sure clients don't receive spurious events in the process...
*/
handled |= (max_fingers == 3 || max_fingers == 4);
return handled;
}
bool me::WindowManager::handle(MirEvent const& event)
{
assert(focus_controller);
assert(display);
assert(compositor);
if (mir_event_get_type(&event) != mir_event_type_input)
return false;
auto iev = mir_event_get_input_event(&event);
auto input_type = mir_input_event_get_type(iev);
if (input_type == mir_input_event_type_key)
{
return handle_key_event(mir_input_event_get_keyboard_event(iev));
}
else if (input_type == mir_input_event_type_pointer &&
focus_controller)
{
return handle_pointer_event(mir_input_event_get_pointer_event(iev));
}
else if (input_type == mir_input_event_type_touch &&
focus_controller)
{
return handle_touch_event(mir_input_event_get_touch_event(iev));
}
return false;
}
./playground/diamond.c 0000644 0000041 0000041 00000013351 13115234664 015216 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Author: Kevin DuBois
*/
#include "diamond.h"
#include "mir_egl_platform_shim.h"
#include
#include
#include
int const num_vertices = 4;
GLfloat const vertices[] =
{
1.0f, 0.0f,
0.0f, 1.0f,
0.0f, -1.0f,
-1.0f, 0.0f,
};
GLfloat const texcoords[] =
{
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
};
static GLuint load_shader(const char *src, GLenum type)
{
GLuint shader = glCreateShader(type);
assert(shader);
GLint compiled;
glShaderSource(shader, 1, &src, NULL);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if (!compiled)
{
GLchar log[1024];
glGetShaderInfoLog(shader, sizeof log - 1, NULL, log);
log[sizeof log - 1] = '\0';
printf("load_shader compile failed: %s\n", log);
glDeleteShader(shader);
shader = 0;
assert(-1);
}
return shader;
}
void render_diamond(Diamond* info, int width, int height)
{
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, width, height);
glDrawArrays(GL_TRIANGLE_STRIP, 0, info->num_vertices);
}
Diamond setup_diamond_common()
{
glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
char const vertex_shader_src[] =
"attribute vec2 pos; \n"
"attribute vec2 texcoord; \n"
"varying vec2 v_texcoord; \n"
"void main() \n"
"{ \n"
" gl_Position = vec4(pos.x, pos.y, 0.0, 1.0); \n"
" v_texcoord = texcoord; \n"
"} \n";
char const fragment_shader_src[] =
"precision mediump float; \n"
"varying vec2 v_texcoord; \n"
"uniform sampler2D tex; \n"
"void main() \n"
"{ \n"
" gl_FragColor = texture2D(tex, v_texcoord); \n"
"} \n";
GLint linked = 0;
Diamond info;
info.vertex_shader = load_shader(vertex_shader_src, GL_VERTEX_SHADER);
info.fragment_shader = load_shader(fragment_shader_src, GL_FRAGMENT_SHADER);
info.program = glCreateProgram();
assert(info.program);
glAttachShader(info.program, info.vertex_shader);
glAttachShader(info.program, info.fragment_shader);
glLinkProgram(info.program);
glGetProgramiv(info.program, GL_LINK_STATUS, &linked);
if (!linked)
{
GLchar log[1024];
glGetProgramInfoLog(info.program, sizeof log - 1, NULL, log);
log[sizeof log - 1] = '\0';
printf("Link failed: %s\n", log);
assert(-1);
}
glUseProgram(info.program);
info.pos = glGetAttribLocation(info.program, "pos");
info.texuniform = glGetUniformLocation(info.program, "tex");
info.texcoord = glGetAttribLocation(info.program, "texcoord");
info.num_vertices = num_vertices;
glUniform1i(info.pos, 0);
glUniform1i(info.texuniform, 0);
glVertexAttribPointer(info.pos, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(info.texcoord, 2, GL_FLOAT, GL_FALSE, 0, texcoords);
glEnableVertexAttribArray(info.pos);
glEnableVertexAttribArray(info.texcoord);
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &info.texid);
glBindTexture(GL_TEXTURE_2D, info.texid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
return info;
}
Diamond setup_diamond_import(EGLImageKHR img, int use_shim)
{
Diamond diamond = setup_diamond_common();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (use_shim)
{
future_driver_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, img);
}
else
{
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES =
(PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress("glEGLImageTargetTexture2DOES");
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, img);
}
return diamond;
}
Diamond setup_diamond()
{
Diamond diamond = setup_diamond_common();
static unsigned char data[] = {
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
};
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA,
2, 2, 0,
GL_RGBA, GL_UNSIGNED_BYTE,
data);
return diamond;
}
void destroy_diamond(Diamond* info)
{
glDeleteTextures(1, &info->texid);
glDisableVertexAttribArray(info->pos);
glDisableVertexAttribArray(info->texcoord);
glDeleteShader(info->vertex_shader);
glDeleteShader(info->fragment_shader);
glDeleteProgram(info->program);
}
./playground/CMakeLists.txt 0000644 0000041 0000041 00000002704 13115234664 016177 0 ustar www-data www-data
include_directories(
${PROJECT_SOURCE_DIR}/src/include/server
${PROJECT_SOURCE_DIR}/src/include/platform
${PROJECT_SOURCE_DIR}/src/include/common
${PROJECT_SOURCE_DIR}/src/include/gl
${PROJECT_SOURCE_DIR}/src/include/client
${PROJECT_SOURCE_DIR}/src/renderers
${PROJECT_SOURCE_DIR}/include/client
${PROJECT_SOURCE_DIR}/include/server
${PROJECT_SOURCE_DIR}/include/platform
${PROJECT_SOURCE_DIR}/include/renderer
${PROJECT_SOURCE_DIR}/include/renderers/gl
${PROJECT_SOURCE_DIR}/examples/
)
add_library(playgroundserverconfig STATIC
server_configuration.cpp
)
add_subdirectory(demo-shell/)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
mir_add_wrapped_executable(mir_demo_client_prerendered_frames
mir_demo_client_prerendered_frames.c
)
target_link_libraries(mir_demo_client_prerendered_frames
mirclient
m
)
mir_add_wrapped_executable(mir_demo_client_chain_jumping_buffers
mir_demo_client_chain_jumping_buffers.c
)
target_link_libraries(mir_demo_client_chain_jumping_buffers
mirclient
)
mir_add_wrapped_executable(mir_demo_client_render_surface
render_surface.cpp
)
target_link_libraries(mir_demo_client_render_surface
mirclient
eglapp
)
mir_add_wrapped_executable(mir_demo_client_egldiamond_render_surface
egldiamond_render_surface.c
mir_egl_platform_shim.c
diamond.c
)
target_link_libraries(mir_demo_client_egldiamond_render_surface
mirclient
${EGL_LIBRARIES}
${GLESv2_LIBRARIES}
)
./playground/mir_demo_client_chain_jumping_buffers.c 0000644 0000041 0000041 00000021207 13115234664 023342 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Kevin DuBois
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PALETTE_SIZE 5
void fill_buffer_diagonal_stripes(
MirBuffer* buffer, unsigned int fg, unsigned int bg)
{
MirBufferLayout layout = mir_buffer_layout_unknown;
MirGraphicsRegion region;
mir_buffer_map(buffer, ®ion, &layout);
if ((!region.vaddr) || (region.pixel_format != mir_pixel_format_abgr_8888) || layout != mir_buffer_layout_linear)
return;
unsigned char* vaddr = (unsigned char*) region.vaddr;
int const num_stripes = 10;
int const stripes_thickness = region.width / num_stripes;
for(int i = 0; i < region.height; i++)
{
unsigned int* pixel = (unsigned int*) vaddr;
for(int j = 0; j < region.width ; j++)
{
if ((((i + j) / stripes_thickness) % stripes_thickness) % 2)
pixel[j] = bg;
else
pixel[j] = fg;
}
vaddr += region.stride;
}
mir_buffer_unmap(buffer);
}
typedef struct SubmissionInfo
{
int available;
MirBuffer* buffer;
pthread_mutex_t lock;
pthread_cond_t cv;
} SubmissionInfo;
static void available_callback(MirBuffer* buffer, void* client_context)
{
SubmissionInfo* info = (SubmissionInfo*) client_context;
pthread_mutex_lock(&info->lock);
info->available = 1;
info->buffer = buffer;
pthread_cond_broadcast(&info->cv);
pthread_mutex_unlock(&info->lock);
}
volatile sig_atomic_t rendering = 1;
static void shutdown(int signum)
{
if ((signum == SIGTERM) || (signum == SIGINT))
rendering = 0;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
int main(int argc, char** argv)
{
static char const *socket_file = NULL;
int arg = -1;
int width = 400;
int height = 400;
while ((arg = getopt (argc, argv, "m:s:h:")) != -1)
{
switch (arg)
{
case 'm':
socket_file = optarg;
break;
case 's':
{
unsigned int w, h;
if (sscanf(optarg, "%ux%u", &w, &h) == 2)
{
width = w;
height = h;
}
else
{
printf("Invalid size: %s, using default size\n", optarg);
}
break;
}
case 'h':
case '?':
default:
puts(argv[0]);
printf("Usage:\n");
printf(" -m \n");
printf(" -s WIDTHxHEIGHT of window\n");
printf(" -h help dialog\n");
return -1;
}
}
int const chain_width = width / 2;
int const chain_height = height / 2;
sigset_t signal_set;
sigemptyset(&signal_set);
sigaddset(&signal_set, SIGALRM);
sigprocmask(SIG_BLOCK, &signal_set, NULL);
struct sigaction action;
action.sa_handler = shutdown;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
sigaction(SIGINT, &action, NULL);
sigaction(SIGTERM, &action, NULL);
int displacement_x = 0;
int displacement_y = 0;
MirPixelFormat format = mir_pixel_format_abgr_8888;
MirConnection* connection = mir_connect_sync(socket_file, "prerendered_frames");
if (!mir_connection_is_valid(connection))
{
printf("could not connect to server file at: %s\n", socket_file);
return -1;
}
unsigned int const num_chains = 4;
unsigned int const num_buffers = num_chains + 1;
unsigned int const fg[PALETTE_SIZE] = {
0xFF14BEA0,
0xFF000000,
0xFF1111FF,
0xFFAAAAAA,
0xFFB00076
};
unsigned int const bg[PALETTE_SIZE] = {
0xFFDF2111,
0xFFFFFFFF,
0xFF11DDDD,
0xFF404040,
0xFFFFFF00
};
unsigned int spare_buffer = 0;
MirPresentationChain* chain[num_chains];
MirRenderSurface* render_surface[num_chains];
for(unsigned int i = 0u; i < num_chains; i++)
{
render_surface[i] = mir_connection_create_render_surface_sync(connection, chain_width, chain_height);
if (!mir_render_surface_is_valid(render_surface[i]))
{
printf("could not create render surface\n");
return -1;
}
chain[i] = mir_render_surface_get_presentation_chain(render_surface[i]);
if (!mir_presentation_chain_is_valid(chain[i]))
{
printf("could not create MirPresentationChain\n");
// TODO this is a frig to pass smoke tests until we support NBS by default
#if (MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 3, 0))
printf("This is currently an unreleased API - likely server support is switched off\n");
return 0;
#else
return -1;
#endif
}
}
//Arrange a 2x2 grid of chains within window
MirWindowSpec* spec = mir_create_normal_window_spec(connection, width, height);
mir_window_spec_set_pixel_format(spec, format);
mir_window_spec_add_render_surface(
spec, render_surface[0], chain_width, chain_height, displacement_x, displacement_y);
mir_window_spec_add_render_surface(
spec, render_surface[1], chain_width, chain_height, chain_width, displacement_y);
mir_window_spec_add_render_surface(
spec, render_surface[2], chain_width, chain_height, displacement_x, chain_height);
mir_window_spec_add_render_surface(
spec, render_surface[3], chain_width, chain_height, chain_width, chain_height);
MirWindow* window = mir_create_window_sync(spec);
mir_window_spec_release(spec);
SubmissionInfo buffer_available[num_buffers];
//prerender the frames
for (unsigned int i = 0u; i < num_buffers; i++)
{
pthread_cond_init(&buffer_available[i].cv, NULL);
pthread_mutex_init(&buffer_available[i].lock, NULL);
buffer_available[i].available = 0;
buffer_available[i].buffer = NULL;
mir_connection_allocate_buffer(
connection, width, height, format, available_callback, &buffer_available[i]);
pthread_mutex_lock(&buffer_available[i].lock);
while(!buffer_available[i].buffer)
pthread_cond_wait(&buffer_available[i].cv, &buffer_available[i].lock);
fill_buffer_diagonal_stripes(buffer_available[i].buffer,
fg[i % PALETTE_SIZE], bg[i % PALETTE_SIZE]);
pthread_mutex_unlock(&buffer_available[i].lock);
}
while (rendering)
{
for(unsigned int i = 0u; i < num_chains; i++)
{
MirBuffer* b;
pthread_mutex_lock(&buffer_available[spare_buffer].lock);
while(!buffer_available[spare_buffer].available)
pthread_cond_wait(&buffer_available[spare_buffer].cv, &buffer_available[spare_buffer].lock);
buffer_available[spare_buffer].available = 0;
b = buffer_available[spare_buffer].buffer;
pthread_mutex_unlock(&buffer_available[spare_buffer].lock);
mir_presentation_chain_submit_buffer(
chain[i], b, available_callback, &buffer_available[spare_buffer]);
//just looks like a blur if we don't slow things down
ualarm(500000, 0);
int sig;
sigwait(&signal_set, &sig);
if (!rendering) break;
if (++spare_buffer > num_chains)
spare_buffer = 0;
}
}
for (unsigned int i = 0u; i < num_buffers; i++)
mir_buffer_release(buffer_available[i].buffer);
for (unsigned int i = 0u; i < num_chains; i++)
mir_render_surface_release(render_surface[i]);
mir_window_release_sync(window);
mir_connection_release(connection);
return 0;
}
#pragma GCC diagnostic pop
./playground/README 0000644 0000041 0000041 00000000321 13115234664 014310 0 ustar www-data www-data The Playground
These are mir demos that exercise private, in-flux mir functionality. As such
functionality matures, related headers become public and the relevant playground
code may be moved to 'examples/'.
./playground/diamond.h 0000644 0000041 0000041 00000002511 13115234664 015217 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Author: Kevin DuBois
*/
#ifndef PLAYGROUND_DIAMOND_H_
#define PLAYGROUND_DIAMOND_H_
#include
#include
#include
#include
#include "mir_toolkit/mir_buffer.h"
typedef struct
{
GLuint vertex_shader;
GLuint fragment_shader;
GLuint program;
GLuint pos;
GLuint texuniform;
GLuint texcoord;
GLuint texid;
GLfloat const* vertices;
GLfloat const* colors;
int num_vertices;
} Diamond;
Diamond setup_diamond();
Diamond setup_diamond_import(EGLImageKHR img, int use_shim);
void destroy_diamond(Diamond* info);
void render_diamond(Diamond* info, int width, int height);
#endif /* PLAYGROUND_DIAMOND_H_ */
./playground/server_configuration.h 0000644 0000041 0000041 00000002715 13115234664 020047 0 ustar www-data www-data /*
* Copyright © 2013-2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef MIR_EXAMPLES_SERVER_CONFIGURATION_H_
#define MIR_EXAMPLES_SERVER_CONFIGURATION_H_
#include "mir/default_server_configuration.h"
namespace mir
{
namespace options
{
class DefaultConfiguration;
}
namespace examples
{
class ServerConfiguration : public DefaultServerConfiguration
{
public:
ServerConfiguration(int argc, char const** argv);
explicit ServerConfiguration(std::shared_ptr const& configuration_options);
std::shared_ptr the_display_configuration_policy() override;
std::shared_ptr the_composite_event_filter() override;
private:
std::shared_ptr quit_filter;
};
}
}
#endif /* MIR_EXAMPLES_SERVER_CONFIGURATION_H_ */
./playground/mir_egl_platform_shim.h 0000644 0000041 0000041 00000003525 13115234664 020154 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Author: Kevin DuBois
*/
#ifndef MIR_PLAYGROUND_MIR_EGL_PLATFORM_SHIM_H_
#define MIR_PLAYGROUND_MIR_EGL_PLATFORM_SHIM_H_
#include
#include
#include
#include
#include "mir_toolkit/rs/mir_render_surface.h"
//Note that these have the same signatures as the proper EGL functions,
//and use our intended EGLNativeDisplayType and EGLNativeWindowType.
EGLDisplay future_driver_eglGetDisplay(MirConnection*);
EGLBoolean future_driver_eglTerminate(EGLDisplay);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
EGLSurface future_driver_eglCreateWindowSurface(
EGLDisplay display, EGLConfig config, MirRenderSurface* surface, const EGLint *);
#pragma GCC diagnostic pop
EGLBoolean future_driver_eglSwapBuffers(EGLDisplay display, EGLSurface surface);
EGLImageKHR future_driver_eglCreateImageKHR(
EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
EGLBoolean future_driver_eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image);
void future_driver_glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image);
#endif /* MIR_PLAYGROUND_MIR_EGL_PLATFORM_SHIM_H_*/
./playground/mir_demo_client_prerendered_frames.c 0000644 0000041 0000041 00000016717 13115234664 022661 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Kevin DuBois
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
float distance(int x0, int y0, int x1, int y1)
{
float dx = x1 - x0;
float dy = y1 - y0;
return sqrt((dx * dx + dy * dy));
}
void fill_buffer_with_centered_circle_abgr(
MirBuffer* buffer, float radius, unsigned int fg, unsigned int bg)
{
MirBufferLayout layout = mir_buffer_layout_unknown;
MirGraphicsRegion region;
mir_buffer_map(buffer, ®ion, &layout);
if ((!region.vaddr) || (region.pixel_format != mir_pixel_format_abgr_8888) || layout != mir_buffer_layout_linear)
return;
int const center_x = region.width / 2;
int const center_y = region.height / 2;
unsigned char* vaddr = (unsigned char*) region.vaddr;
for(int i = 0; i < region.height; i++)
{
unsigned int* pixel = (unsigned int*) vaddr;
for(int j = 0; j < region.width ; j++)
{
int const centered_i = i - center_y;
int const centered_j = j - center_x;
if (distance(0,0, centered_i, centered_j) > radius)
pixel[j] = bg;
else
pixel[j] = fg;
}
vaddr += region.stride;
}
mir_buffer_unmap(buffer);
}
typedef struct SubmissionInfo
{
int available;
MirBuffer* buffer;
pthread_mutex_t lock;
pthread_cond_t cv;
} SubmissionInfo;
static void available_callback(MirBuffer* buffer, void* client_context)
{
SubmissionInfo* info = (SubmissionInfo*) client_context;
pthread_mutex_lock(&info->lock);
info->available = 1;
info->buffer = buffer;
pthread_cond_broadcast(&info->cv);
pthread_mutex_unlock(&info->lock);
}
volatile int rendering = 1;
static void shutdown(int signum)
{
if ((signum == SIGTERM) || (signum == SIGINT))
rendering = 0;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
int main(int argc, char** argv)
{
static char const *socket_file = NULL;
int arg = -1;
int width = 400;
int height = 400;
while ((arg = getopt (argc, argv, "m:s:h:")) != -1)
{
switch (arg)
{
case 'm':
socket_file = optarg;
break;
case 's':
{
unsigned int w, h;
if (sscanf(optarg, "%ux%u", &w, &h) == 2)
{
width = w;
height = h;
}
else
{
printf("Invalid size: %s, using default size\n", optarg);
}
break;
}
case 'h':
case '?':
default:
puts(argv[0]);
printf("Usage:\n");
printf(" -m \n");
printf(" -s WIDTHxHEIGHT of window\n");
printf(" -h help dialog\n");
return -1;
}
}
signal(SIGTERM, shutdown);
signal(SIGINT, shutdown);
int displacement_x = 0;
int displacement_y = 0;
unsigned int fg = 0xFF1448DD;
unsigned int bg = 0xFF6F2177;
MirPixelFormat format = mir_pixel_format_abgr_8888;
MirConnection* connection = mir_connect_sync(socket_file, "prerendered_frames");
if (!mir_connection_is_valid(connection))
{
printf("could not connect to server file at: %s\n", socket_file);
return -1;
}
MirRenderSurface* render_surface = mir_connection_create_render_surface_sync(connection, width, height);
if (!mir_render_surface_is_valid(render_surface))
{
printf("could not create a render surface\n");
return -1;
}
MirPresentationChain* chain = mir_render_surface_get_presentation_chain(render_surface);
if (!mir_presentation_chain_is_valid(chain))
{
printf("could not create MirPresentationChain\n");
// TODO this is a frig to pass smoke tests until we support NBS by default
#if (MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 3, 0))
printf("This is currently an unreleased API - likely server support is switched off\n");
return 0;
#else
return -1;
#endif
}
MirWindowSpec* spec = mir_create_normal_window_spec(connection, width, height);
mir_window_spec_set_pixel_format(spec, format);
mir_window_spec_add_render_surface(
spec, render_surface, width, height, displacement_x, displacement_y);
MirWindow* window = mir_create_window_sync(spec);
if (!mir_window_is_valid(window))
{
printf("could not create a window\n");
return -1;
}
mir_window_spec_release(spec);
int num_prerendered_frames = 20;
SubmissionInfo buffer_available[num_prerendered_frames];
for (int i = 0u; i < num_prerendered_frames; i++)
{
pthread_cond_init(&buffer_available[i].cv, NULL);
pthread_mutex_init(&buffer_available[i].lock, NULL);
buffer_available[i].available = 0;
buffer_available[i].buffer = NULL;
mir_connection_allocate_buffer(
connection, width, height, format, available_callback, &buffer_available[i]);
pthread_mutex_lock(&buffer_available[i].lock);
while(!buffer_available[i].buffer)
pthread_cond_wait(&buffer_available[i].cv, &buffer_available[i].lock);
if (!mir_buffer_is_valid(buffer_available[i].buffer))
{
printf("could not create MirBuffer\n");
return -1;
}
float max_radius = distance(0, 0, width, height) / 2.0f;
float radius_i = ((float) i + 1) / num_prerendered_frames * max_radius;
fill_buffer_with_centered_circle_abgr(buffer_available[i].buffer, radius_i, fg, bg);
pthread_mutex_unlock(&buffer_available[i].lock);
}
int i = 0;
int inc = -1;
while (rendering)
{
MirBuffer* b;
pthread_mutex_lock(&buffer_available[i].lock);
while(!buffer_available[i].available)
pthread_cond_wait(&buffer_available[i].cv, &buffer_available[i].lock);
buffer_available[i].available = 0;
b = buffer_available[i].buffer;
pthread_mutex_unlock(&buffer_available[i].lock);
mir_presentation_chain_submit_buffer(chain, b, available_callback, &buffer_available[i]);
if ((i == num_prerendered_frames - 1) || (i == 0))
inc *= -1;
i = i + inc;
}
for (i = 0u; i < num_prerendered_frames; i++)
mir_buffer_release(buffer_available[i].buffer);
mir_render_surface_release(render_surface);
mir_window_release_sync(window);
mir_connection_release(connection);
return 0;
}
#pragma GCC diagnostic pop
./playground/mir_egl_platform_shim.c 0000644 0000041 0000041 00000014622 13115234664 020147 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Author: Kevin DuBois
*/
#include "mir_egl_platform_shim.h"
#include "mir_toolkit/mir_client_library.h"
#include "mir_toolkit/mir_extension_core.h"
#include "mir_toolkit/extensions/android_egl.h"
#include "mir_toolkit/extensions/hardware_buffer_stream.h"
#include
#include
#include
#include
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
//Information the driver will have to maintain
typedef struct
{
MirConnection* connection; //EGLNativeDisplayType
MirRenderSurface* surface; //EGLNativeWindowType
MirBufferStream* stream; //the internal semantics a driver might want to use...
//could be MirPresentationChain as well
int current_physical_width; //The driver is in charge of the physical width
int current_physical_height; //The driver is in charge of the physical height
MirExtensionAndroidEGLV1 const* ext;
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
} DriverInfo;
static DriverInfo* info = NULL;
typedef struct
{
struct ANativeWindowBuffer *buffer;
EGLImageKHR img;
} ShimEGLImageKHR;
EGLSurface future_driver_eglCreateWindowSurface(
EGLDisplay display, EGLConfig config, MirRenderSurface* surface, const EGLint* attr)
{
MirExtensionHardwareBufferStreamV1 const * ext = mir_extension_hardware_buffer_stream_v1(info->connection);
if (info->surface || !ext)
{
printf("shim only supports one surface at the moment");
return EGL_NO_SURFACE;
}
info->surface = surface;
mir_render_surface_get_size(surface,
&info->current_physical_width, &info->current_physical_height);
//TODO: the driver needs to be selecting a pixel format that's acceptable based on
// the EGLConfig. mir_connection_get_egl_pixel_format
// needs to be deprecated once the drivers support the Mir EGL platform.
MirPixelFormat pixel_format = mir_connection_get_egl_pixel_format(info->connection, display, config);
//this particular [silly] driver has chosen the buffer stream as the way it wants to post
//its hardware content. I'd think most drivers would want MirPresentationChain for flexibility
info->stream = ext->get_hardware_buffer_stream(surface,
info->current_physical_width,
info->current_physical_height,
pixel_format);
printf("The driver chose pixel format %d.\n", pixel_format);
return eglCreateWindowSurface(display, config, (EGLNativeWindowType) surface, attr);
}
EGLBoolean future_driver_eglSwapBuffers(EGLDisplay display, EGLSurface surface)
{
int width = -1;
int height = -1;
mir_render_surface_get_size(info->surface, &width, &height);
if (width != info->current_physical_width || height != info->current_physical_height)
{
//note that this affects the next buffer that we get after swapbuffers.
mir_buffer_stream_set_size(info->stream, width, height);
info->current_physical_width = width;
info->current_physical_height = height;
}
return eglSwapBuffers(display, surface);
}
#pragma GCC diagnostic pop
EGLDisplay future_driver_eglGetDisplay(MirConnection* connection)
{
if (info)
{
printf("shim only supports one display connection at the moment");
return EGL_NO_DISPLAY;
}
info = malloc(sizeof(DriverInfo));
memset(info, 0, sizeof(*info));
info->connection = connection;
info->ext = mir_extension_android_egl_v1(info->connection);
info->eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR");
info->eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR");
info->glEGLImageTargetTexture2DOES =
(PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress("glEGLImageTargetTexture2DOES");
return eglGetDisplay(mir_connection_get_egl_native_display(connection));
}
EGLBoolean future_driver_eglTerminate(EGLDisplay display)
{
if (info)
free(info);
return eglTerminate(display);
}
EGLImageKHR future_driver_eglCreateImageKHR(
EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
{
//bit pedantic, but we should validate the parameters we require from the extension
if ( (target != EGL_NATIVE_PIXMAP_KHR) || (ctx != EGL_NO_CONTEXT) || !info || !info->ext )
return EGL_NO_IMAGE_KHR;
//check we have subloaded extension available.
if(!strstr(eglQueryString(dpy, EGL_EXTENSIONS), "EGL_ANDROID_image_native_buffer"))
return EGL_NO_IMAGE_KHR;
static EGLint const expected_attrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE };
int i = 0;
while ( (attrib_list[i] != EGL_NONE) && (expected_attrs[i] != EGL_NONE) )
{
if (attrib_list[i] != expected_attrs[i])
return EGL_NO_IMAGE_KHR;
i++;
}
ShimEGLImageKHR* img = (ShimEGLImageKHR*) malloc(sizeof(ShimEGLImageKHR));
img->buffer = info->ext->create_buffer(buffer);
img->img = info->eglCreateImageKHR(dpy, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
img->buffer, attrib_list);
return (EGLImageKHR) img;
}
EGLBoolean future_driver_eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image)
{
if (!info)
return EGL_FALSE;
ShimEGLImageKHR* img = (ShimEGLImageKHR*) image;
EGLBoolean rc = info->eglDestroyImageKHR(dpy, image);
info->ext->destroy_buffer(img->buffer);
free(img);
return rc;
}
void future_driver_glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image)
{
if (!info)
return;
ShimEGLImageKHR* img = (ShimEGLImageKHR*) image;
info->glEGLImageTargetTexture2DOES(target, img->img);
}
./playground/server_configuration.cpp 0000644 0000041 0000041 00000006073 13115234664 020403 0 ustar www-data www-data /*
* Copyright © 2013-2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "server_configuration.h"
#include "mir/options/default_configuration.h"
#include "mir/input/composite_event_filter.h"
#include "mir/graphics/default_display_configuration_policy.h"
#include "mir/main_loop.h"
#include "server_example_display_configuration_policy.h"
#include "server_example_input_event_filter.h"
namespace me = mir::examples;
namespace mg = mir::graphics;
namespace
{
std::shared_ptr const& customize(
std::shared_ptr const& opt)
{
opt->add_options()(me::display_config_opt,
boost::program_options::value()->
default_value(me::clone_opt_val),
me::display_config_descr);
return opt;
}
}
me::ServerConfiguration::ServerConfiguration(std::shared_ptr const& configuration_options) :
DefaultServerConfiguration(customize(configuration_options))
{
}
me::ServerConfiguration::ServerConfiguration(int argc, char const** argv) :
ServerConfiguration(std::make_shared(argc, argv))
{
}
std::shared_ptr
me::ServerConfiguration::the_display_configuration_policy()
{
return display_configuration_policy(
[this]() -> std::shared_ptr
{
auto display_config = the_options()->get(me::display_config_opt);
if (display_config == me::sidebyside_opt_val)
return std::make_shared();
else if (display_config == me::single_opt_val)
return std::make_shared();
else
return DefaultServerConfiguration::the_display_configuration_policy();
});
}
std::shared_ptr
me::ServerConfiguration::the_composite_event_filter()
{
return composite_event_filter(
[this]() -> std::shared_ptr
{
if (!quit_filter)
quit_filter = std::make_shared([this] { the_main_loop()->stop(); });
auto composite_filter = DefaultServerConfiguration::the_composite_event_filter();
composite_filter->append(quit_filter);
return composite_filter;
});
}
./playground/egldiamond_render_surface.c 0000644 0000041 0000041 00000024074 13115234664 020761 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Author: Daniel van Vugt
* Cemil Azizoglu
* Kevin DuBois
*/
#include "mir_toolkit/mir_client_library.h"
#include "mir_toolkit/rs/mir_render_surface.h"
#include "mir_toolkit/mir_buffer.h"
#include "mir_toolkit/mir_presentation_chain.h"
#include "mir_egl_platform_shim.h"
#include "diamond.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
static volatile sig_atomic_t running = 0;
static void shutdown(int signum)
{
if (running)
{
running = 0;
printf("Signal %d received. Good night.\n", signum);
}
}
#define CHECK(_cond, _err) \
if (!(_cond)) \
{ \
printf("%s\n", (_err)); \
return -1; \
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
//The client arranges the scene in the subscene
void resize_callback(MirWindow* window, MirEvent const* event, void* context)
{
(void) window;
MirEventType type = mir_event_get_type(event);
if (type == mir_event_type_resize)
{
MirResizeEvent const* resize_event = mir_event_get_resize_event(event);
int width = mir_resize_event_get_width(resize_event);
int height = mir_resize_event_get_height(resize_event);
MirRenderSurface* rs = (MirRenderSurface*) context;
mir_render_surface_set_size(rs, width, height);
}
}
typedef struct
{
pthread_mutex_t* mut;
pthread_cond_t* cond;
MirBuffer** buffer;
} BufferWait;
void wait_buffer(MirBuffer* b, void* context)
{
BufferWait* w = (BufferWait*) context;
pthread_mutex_lock(w->mut);
*w->buffer = b;
pthread_cond_broadcast(w->cond);
pthread_mutex_unlock(w->mut);
}
bool fill_buffer(MirBuffer* buffer)
{
MirBufferLayout layout = mir_buffer_layout_unknown;
MirGraphicsRegion region;
bool rc = mir_buffer_map(buffer, ®ion, &layout);
if (!rc || layout == mir_buffer_layout_unknown)
return false;
unsigned int *data = (unsigned int*) region.vaddr;
for (int i = 0; i < region.width; i++)
{
for (int j = 0; j < region.height; j++)
{
int idx = (i * (region.stride/4)) + j;
if (idx % 32 > 16)
data[ idx ] = 0xFF00FFFF;
else
data[ idx ] = 0xFFFF0000;
}
}
mir_buffer_unmap(buffer);
return true;
}
int main(int argc, char *argv[])
{
//once full transition to Mir platform has been made, internal shim will be removed,
//and the examples/ will use MirConnection/MirRenderSurface/MirBuffer as their egl types.
int use_shim = 1;
int swapinterval = 1;
char* socket = NULL;
int c;
while ((c = getopt(argc, argv, "ehnm:")) != -1)
{
switch (c)
{
case 'm':
socket = optarg;
break;
case 'e':
use_shim = 0;
break;
case 'n':
swapinterval = 0;
break;
case 'h':
default:
printf(
"Usage:\n"
"\t-m mir_socket\n"
"\t-e use egl library directly, instead of using shim\n"
"\t-n use swapinterval 0\n"
"\t-h this message\n");
return -1;
}
}
const char* appname = "EGL Render Surface Demo";
int width = 300;
int height = 300;
EGLDisplay egldisplay;
EGLSurface eglsurface;
EGLint ctxattribs[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
EGLContext eglctx;
EGLConfig eglconfig;
EGLint neglconfigs;
EGLBoolean ok;
MirConnection* connection = NULL;
MirWindow* window = NULL;
MirRenderSurface* render_surface = NULL;
signal(SIGINT, shutdown);
signal(SIGTERM, shutdown);
signal(SIGHUP, shutdown);
if (use_shim)
printf("internal EGL driver shim in use\n");
else
printf("using EGL driver directly\n");
connection = mir_connect_sync(socket, appname);
CHECK(mir_connection_is_valid(connection), "Can't get connection");
BufferWait w;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
MirBuffer* buffer = NULL;
w.mut = &mutex;
w.cond = &cond;
w.buffer = &buffer;
mir_connection_allocate_buffer(
connection, 256, 256, mir_pixel_format_abgr_8888, wait_buffer, &w);
pthread_mutex_lock(&mutex);
while (buffer == NULL)
pthread_cond_wait(&cond, &mutex);
pthread_mutex_unlock(&mutex);
bool const filled = fill_buffer(buffer);
if (use_shim)
egldisplay = future_driver_eglGetDisplay(connection);
else
egldisplay = eglGetDisplay(connection);
CHECK(egldisplay != EGL_NO_DISPLAY, "Can't eglGetDisplay");
int maj =0;
int min = 0;
ok = eglInitialize(egldisplay, &maj, &min);
CHECK(ok, "Can't eglInitialize");
printf("EGL version %i.%i\n", maj, min);
const EGLint attribs[] =
{
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_NONE
};
ok = eglChooseConfig(egldisplay, attribs, &eglconfig, 1, &neglconfigs);
CHECK(ok, "Could not eglChooseConfig");
CHECK(neglconfigs > 0, "No EGL config available");
render_surface = mir_connection_create_render_surface_sync(connection, width, height);
CHECK(mir_render_surface_is_valid(render_surface), "could not create render surface");
CHECK(mir_render_surface_get_error_message(render_surface), "");
if (use_shim)
eglsurface = future_driver_eglCreateWindowSurface(egldisplay, eglconfig, render_surface, NULL);
else
eglsurface = eglCreateWindowSurface(egldisplay, eglconfig, (EGLNativeWindowType) render_surface, NULL);
if (eglsurface == EGL_NO_SURFACE)
{
printf("eglCreateWindowSurface failed. "
"This is likely because the egl driver does not support the usage of MirRenderSurface\n");
mir_render_surface_release(render_surface);
mir_connection_release(connection);
eglTerminate(egldisplay);
return 0;
}
//The format field is only used for default-created streams.
//width and height are the logical width the user wants the window to be
MirWindowSpec *spec =
mir_create_normal_window_spec(connection, width, height);
CHECK(spec, "Can't create a window spec");
mir_window_spec_set_name(spec, appname);
mir_window_spec_add_render_surface(spec, render_surface, width, height, 0, 0);
mir_window_spec_set_event_handler(spec, resize_callback, render_surface);
window = mir_create_window_sync(spec);
mir_window_spec_release(spec);
eglctx = eglCreateContext(egldisplay, eglconfig, EGL_NO_CONTEXT,
ctxattribs);
CHECK(eglctx != EGL_NO_CONTEXT, "eglCreateContext failed");
ok = eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglctx);
CHECK(ok, "Can't eglMakeCurrent");
eglSwapInterval(egldisplay, swapinterval);
EGLImageKHR image = EGL_NO_IMAGE_KHR;
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = NULL;
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR = NULL;
char const* extensions = eglQueryString(egldisplay, EGL_EXTENSIONS);
printf("EGL extensions %s\n", extensions);
if (strstr(extensions, "EGL_KHR_image_pixmap"))
{
static EGLint const image_attrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE };
if (use_shim)
{
eglCreateImageKHR = future_driver_eglCreateImageKHR;
eglDestroyImageKHR = future_driver_eglDestroyImageKHR;
}
else
{
eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR");
eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR");
}
if (filled)
image = eglCreateImageKHR(egldisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, buffer, image_attrs);
}
Diamond diamond;
if (image == EGL_NO_IMAGE_KHR)
{
printf("MirBuffer import not supported by driver. Should see red/white checker\n");
diamond = setup_diamond();
}
else
{
printf("MirBuffer import supported by driver. Should see yellow/blue stripes\n");
diamond = setup_diamond_import(image, use_shim);
}
EGLint viewport_width = -1;
EGLint viewport_height = -1;
running = 1;
while (running)
{
eglQuerySurface(egldisplay, eglsurface, EGL_WIDTH, &viewport_width);
eglQuerySurface(egldisplay, eglsurface, EGL_HEIGHT, &viewport_height);
render_diamond(&diamond, viewport_width, viewport_height);
if (use_shim)
future_driver_eglSwapBuffers(egldisplay, eglsurface);
else
eglSwapBuffers(egldisplay, eglsurface);
}
destroy_diamond(&diamond);
eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (image)
eglDestroyImageKHR(egldisplay, image);
if (use_shim)
future_driver_eglTerminate(egldisplay);
else
eglTerminate(egldisplay);
mir_render_surface_release(render_surface);
mir_window_release_sync(window);
mir_connection_release(connection);
return 0;
}
#pragma GCC diagnostic pop
./COPYING.GPL 0000644 0000041 0000041 00000104374 13115234416 012730 0 ustar www-data www-data
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
./.clang-format 0000644 0000041 0000041 00000002615 13115234416 013622 0 ustar www-data www-data Language: Cpp
AccessModifierOffset: -4
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BinPackParameters: false
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerBinding: true
ExperimentalAutoDetectBinPacking: true
IndentCaseLabels: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerBindsToType: true
SpacesBeforeTrailingComments: 2
Cpp11BracedListStyle: true
Standard: Cpp11
IndentWidth: 4
TabWidth: 8
UseTab: Never
BreakBeforeBraces: Allman
IndentFunctionDeclarationAfterType: true
SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
SpaceBeforeParens: ControlStatements
./include/ 0000755 0000041 0000041 00000000000 13115234677 012677 5 ustar www-data www-data ./include/platform/ 0000755 0000041 0000041 00000000000 13115234413 014507 5 ustar www-data www-data ./include/platform/mir/ 0000755 0000041 0000041 00000000000 13115234417 015302 5 ustar www-data www-data ./include/platform/mir/abnormal_exit.h 0000644 0000041 0000041 00000001737 13115234416 020306 0 ustar www-data www-data /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Alan Griffiths
*/
#ifndef MIR_ABNORMAL_EXIT_H_
#define MIR_ABNORMAL_EXIT_H_
#include
namespace mir
{
class AbnormalExit : public std::runtime_error
{
public:
AbnormalExit(std::string const& what) :
std::runtime_error(what)
{
}
};
}
#endif /* MIR_ABNORMAL_EXIT_H_ */
./include/platform/mir/options/ 0000755 0000041 0000041 00000000000 13115234417 016775 5 ustar www-data www-data ./include/platform/mir/options/option.h 0000644 0000041 0000041 00000003205 13115234416 020455 0 ustar www-data www-data /*
* Copyright © 2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Alan Griffiths
*/
#ifndef MIR_OPTIONS_OPTION_H_
#define MIR_OPTIONS_OPTION_H_
#include
#include
namespace mir
{
/// System options. Interface for extracting configuration options from wherever
/// they may be (e.g. program arguments, config files or environment variables).
namespace options
{
class Option
{
public:
virtual bool is_set(char const* name) const = 0;
virtual bool get(char const* name, bool default_) const = 0;
virtual std::string get(char const* name, char const* default_) const = 0;
virtual int get(char const* name, int default_) const = 0;
virtual boost::any const& get(char const* name) const = 0;
template
Type get(char const* name) const
{ return boost::any_cast(get(name)); }
protected:
Option() = default;
virtual ~Option() = default;
Option(Option const&) = delete;
Option& operator=(Option const&) = delete;
};
}
}
#endif /* MIR_OPTIONS_OPTION_H_ */
./include/platform/mir/module_properties.h 0000644 0000041 0000041 00000002465 13115234416 021222 0 ustar www-data www-data /*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Christopher James Halse Rogers
*/
#ifndef MIR_PLATFORM_MODULE_PROPERTIES_H_
#define MIR_PLATFORM_MODULE_PROPERTIES_H_
namespace mir
{
/**
* Describes a platform module. Mir provides the following graphics platforms:
* "mir:mesa-kms", "mir:mesa-x11" and "mir:android".
* Mir provides "mir:evdev-input" input platform.
*
* Third party platforms should be named according to the vendor and platform:
* ":"
*/
struct ModuleProperties
{
char const* name;
int major_version;
int minor_version;
int micro_version;
char const* file;
};
}
#endif /* MIR_PLATFORM_MODULE_PROPERTIES_H_ */
./include/platform/mir/graphics/ 0000755 0000041 0000041 00000000000 13115234677 017112 5 ustar www-data www-data ./include/platform/mir/graphics/platform_ipc_package.h 0000644 0000041 0000041 00000002507 13115234416 023410 0 ustar www-data www-data /*
* Copyright © 2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef MIR_GRAPHICS_PLATFORM_IPC_PACKAGE_H_
#define MIR_GRAPHICS_PLATFORM_IPC_PACKAGE_H_
#include
#include
namespace mir
{
struct ModuleProperties;
namespace graphics
{
/**
* Platform data to be sent to the clients over IPC.
*/
struct PlatformIPCPackage
{
PlatformIPCPackage() : graphics_module(nullptr) {}
explicit PlatformIPCPackage(ModuleProperties const* graphics_module) : graphics_module(graphics_module) {}
std::vector ipc_data;
std::vector ipc_fds;
ModuleProperties const* graphics_module;
};
}
}
#endif /* MIR_GRAPHICS_PLATFORM_IPC_PACKAGE_H_ */
./include/platform/mir/graphics/platform_operation_message.h 0000644 0000041 0000041 00000001771 13115234416 024670 0 ustar www-data www-data /*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef MIR_GRAPHICS_PLATFORM_OPERATION_MESSAGE_H_
#define MIR_GRAPHICS_PLATFORM_OPERATION_MESSAGE_H_
#include
#include
namespace mir
{
namespace graphics
{
struct PlatformOperationMessage
{
std::vector data;
std::vector fds;
};
}
}
#endif
./include/platform/mir/graphics/platform_ipc_operations.h 0000644 0000041 0000041 00000006332 13115234664 024205 0 ustar www-data www-data /*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Kevin DuBois
*/
#ifndef MIR_GRAPHICS_PLATFORM_IPC_OPERATIONS_H_
#define MIR_GRAPHICS_PLATFORM_IPC_OPERATIONS_H_
#include "platform_ipc_package.h"
#include
namespace mir
{
namespace graphics
{
enum class BufferIpcMsgType
{
full_msg, //pack the full ipc representation of the buffer
update_msg //assume the client has a full representation, and pack only updates to the buffer
};
class Buffer;
class BufferIpcMessage;
struct PlatformOperationMessage;
class PlatformIpcOperations
{
public:
virtual ~PlatformIpcOperations() = default;
/**
* Arranges the IPC package for a buffer that is to be sent through
* the frontend from server to client. This should be called every
* time a buffer is to be sent cross-process.
*
* Pack the platform specific contents of Buffer into BufferIpcMessage for sending to the client
*
* \param [in] message the message that will be sent
* \param [in] buffer the buffer to be put in the message
* \param [in] msg_type what sort of ipc message is needed
*/
virtual void pack_buffer(BufferIpcMessage& message, Buffer const& buffer, BufferIpcMsgType msg_type) const = 0;
/**
* Arranges the IPC package for a buffer that was sent over IPC
* client to server. This must be called every time a buffer is
* received, as some platform specific processing has to be done on
* the incoming buffer.
* \param [in] message the message that was sent to the server
* \param [in] buffer the buffer associated with the message
*/
virtual void unpack_buffer(BufferIpcMessage& message, Buffer const& buffer) const = 0;
/**
* Gets the connection package for the platform.
*
* The IPC package will be sent to clients when they connect.
*/
virtual std::shared_ptr connection_ipc_package() = 0;
/**
* Arranges a platform specific operation triggered by an IPC call
* \returns the response that will be sent to the client
* \param [in] opcode the opcode that indicates the action to be performed
* \param [in] message the message that was sent to the server
*/
virtual PlatformOperationMessage platform_operation(
unsigned int const opcode, PlatformOperationMessage const& message) = 0;
protected:
PlatformIpcOperations() = default;
PlatformIpcOperations(PlatformIpcOperations const&) = delete;
PlatformIpcOperations& operator=(PlatformIpcOperations const&) = delete;
};
}
}
#endif /* MIR_GRAPHICS_BUFFER_IPC_PACKER_H_ */
./include/platform/mir/graphics/display_configuration_policy.h 0000644 0000041 0000041 00000002477 13115234416 025237 0 ustar www-data www-data /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef MIR_GRAPHICS_DISPLAY_CONFIGURATION_POLICY_H_
#define MIR_GRAPHICS_DISPLAY_CONFIGURATION_POLICY_H_
namespace mir
{
namespace graphics
{
class DisplayConfiguration;
class DisplayConfigurationPolicy
{
public:
virtual ~DisplayConfigurationPolicy() = default;
virtual void apply_to(DisplayConfiguration& conf) = 0;
protected:
DisplayConfigurationPolicy() = default;
DisplayConfigurationPolicy(DisplayConfigurationPolicy const& c) = delete;
DisplayConfigurationPolicy& operator=(DisplayConfigurationPolicy const& c) = delete;
};
}
}
#endif /* MIR_GRAPHICS_DISPLAY_CONFIGURATION_POLICY_H_ */
./include/platform/mir/graphics/buffer_properties.h 0000644 0000041 0000041 00000004056 13115234416 023004 0 ustar www-data www-data /*
* Copyright © 2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef MIR_GRAPHICS_BUFFER_PROPERTIES_H_
#define MIR_GRAPHICS_BUFFER_PROPERTIES_H_
#include "mir/geometry/size.h"
#include "mir_toolkit/common.h"
namespace mir
{
namespace graphics
{
/**
* How a buffer is going to be used.
*
* The usage is not just a hint; for example, depending on the platform, a
* 'hardware' buffer may not support direct pixel access.
*/
enum class BufferUsage
{
undefined,
/** rendering using GL */
hardware,
/** rendering using direct pixel access */
software
};
/**
* Buffer creation properties.
*/
struct BufferProperties
{
BufferProperties() :
size(),
format(mir_pixel_format_invalid),
usage(BufferUsage::undefined)
{
}
BufferProperties(const geometry::Size& size,
const MirPixelFormat& format,
BufferUsage usage) :
size{size},
format{format},
usage{usage}
{
}
geometry::Size size;
MirPixelFormat format;
BufferUsage usage;
};
inline bool operator==(BufferProperties const& lhs, BufferProperties const& rhs)
{
return lhs.size == rhs.size &&
lhs.format == rhs.format &&
lhs.usage == rhs.usage;
}
inline bool operator!=(BufferProperties const& lhs, BufferProperties const& rhs)
{
return !(lhs == rhs);
}
}
}
#endif // MIR_GRAPHICS_BUFFER_PROPERTIES_H_
./include/platform/mir/graphics/cursor_image.h 0000644 0000041 0000041 00000002663 13115234416 021740 0 ustar www-data www-data /*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Robert Carr
*/
#ifndef MIR_GRAPHICS_CURSOR_IMAGE_H_
#define MIR_GRAPHICS_CURSOR_IMAGE_H_
#include "mir/geometry/size.h"
#include "mir/geometry/displacement.h"
namespace mir
{
namespace graphics
{
class CursorImage
{
public:
virtual ~CursorImage() = default;
virtual void const* as_argb_8888() const = 0;
virtual geometry::Size size() const = 0;
// We use "hotspot" to mean the offset within a cursor image
// which should be placed at the onscreen
// location of the pointer.
virtual geometry::Displacement hotspot() const = 0;
protected:
CursorImage() = default;
CursorImage(CursorImage const&) = delete;
CursorImage& operator=(CursorImage const&) = delete;
};
}
}
#endif /* MIR_GRAPHICS_CURSOR_IMAGE_H_ */
./include/platform/mir/graphics/frame.h 0000644 0000041 0000041 00000003016 13115234664 020351 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Daniel van Vugt
*/
#ifndef MIR_GRAPHICS_FRAME_H_
#define MIR_GRAPHICS_FRAME_H_
#include "mir/time/posix_timestamp.h"
#include
namespace mir { namespace graphics {
/**
* Frame is a unique identifier for a frame displayed on an output.
*
* This MSC/UST terminology is used because that's what the rest of the
* industry calls it:
* GLX: https://www.opengl.org/registry/specs/OML/glx_sync_control.txt
* WGL: https://www.opengl.org/registry/specs/OML/wgl_sync_control.txt
* EGL: https://bugs.chromium.org/p/chromium/issues/attachmentText?aid=178027
* Mesa: "get_sync_values" functions
*/
struct Frame
{
typedef mir::time::PosixTimestamp Timestamp;
int64_t msc = 0; /**< Media Stream Counter */
Timestamp ust; /**< Unadjusted System Time */
};
}} // namespace mir::graphics
#endif // MIR_GRAPHICS_FRAME_H_
./include/platform/mir/graphics/event_handler_register.h 0000644 0000041 0000041 00000003640 13115234416 023777 0 ustar www-data www-data /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Alan Griffiths
*/
#ifndef MIR_GRAPHICS_EVENT_HANDLER_REGISTER_H_
#define MIR_GRAPHICS_EVENT_HANDLER_REGISTER_H_
#include
#include
#include "mir/module_deleter.h"
namespace mir
{
namespace graphics
{
class EventHandlerRegister
{
public:
virtual void register_signal_handler(
std::initializer_list signals,
std::function const& handler) = 0;
virtual void register_signal_handler(
std::initializer_list signals,
mir::UniqueModulePtr> handler) = 0;
virtual void register_fd_handler(
std::initializer_list fds,
void const* owner,
std::function const& handler) = 0;
virtual void register_fd_handler(
std::initializer_list fds,
void const* owner,
mir::UniqueModulePtr> handler) = 0;
virtual void unregister_fd_handler(void const* owner) = 0;
protected:
EventHandlerRegister() = default;
virtual ~EventHandlerRegister() = default;
EventHandlerRegister(EventHandlerRegister const&) = delete;
EventHandlerRegister& operator=(EventHandlerRegister const&) = delete;
};
}
}
#endif /* MIR_GRAPHICS_EVENT_HANDLER_REGISTER_H_ */
./include/platform/mir/graphics/display_configuration.h 0000644 0000041 0000041 00000016654 13115234664 023667 0 ustar www-data www-data /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef MIR_GRAPHICS_DISPLAY_CONFIGURATION_H_
#define MIR_GRAPHICS_DISPLAY_CONFIGURATION_H_
#include "mir/int_wrapper.h"
#include "mir/geometry/size.h"
#include "mir/geometry/rectangle.h"
#include "mir/geometry/point.h"
#include "mir/graphics/gamma_curves.h"
#include "mir_toolkit/common.h"
#include
#include
#include
namespace mir
{
namespace graphics
{
namespace detail { struct GraphicsConfCardIdTag; struct GraphicsConfOutputIdTag; }
typedef IntWrapper DisplayConfigurationCardId;
typedef IntWrapper DisplayConfigurationOutputId;
/**
* Configuration information for a display card.
*/
struct DisplayConfigurationCard
{
DisplayConfigurationCardId id;
size_t max_simultaneous_outputs;
};
/**
* The type of a display output.
*/
enum class DisplayConfigurationOutputType
{
unknown = mir_output_type_unknown,
vga = mir_output_type_vga,
dvii = mir_output_type_dvii,
dvid = mir_output_type_dvid,
dvia = mir_output_type_dvia,
composite = mir_output_type_composite,
svideo = mir_output_type_svideo,
lvds = mir_output_type_lvds,
component = mir_output_type_component,
ninepindin = mir_output_type_ninepindin,
displayport = mir_output_type_displayport,
hdmia = mir_output_type_hdmia,
hdmib = mir_output_type_hdmib,
tv = mir_output_type_tv,
edp = mir_output_type_edp,
virt = mir_output_type_virtual,
dsi = mir_output_type_dsi,
dpi = mir_output_type_dpi,
};
/**
* Configuration information for a display output mode.
*/
struct DisplayConfigurationMode
{
geometry::Size size;
double vrefresh_hz;
};
/**
* Configuration information for a display output.
*/
struct DisplayConfigurationOutput
{
/** The output's id. */
DisplayConfigurationOutputId id;
/** The id of the card the output is connected to. */
DisplayConfigurationCardId card_id;
/** The type of the output. */
DisplayConfigurationOutputType type;
/** The pixel formats supported by the output */
std::vector pixel_formats;
/** The modes supported by the output. */
std::vector modes;
/** The index in the 'modes' vector of the preferred output mode. */
uint32_t preferred_mode_index;
/** The physical size of the output. */
geometry::Size physical_size_mm;
/** Whether the output is connected. */
bool connected;
/** Whether the output is used in the configuration. */
bool used;
/** The top left point of this output in the virtual coordinate space. */
geometry::Point top_left;
/** The index in the 'modes' vector of the current output mode. */
uint32_t current_mode_index;
/** The current output pixel format. A matching entry should be found in the 'pixel_formats' vector*/
MirPixelFormat current_format;
/** Current power mode **/
MirPowerMode power_mode;
MirOrientation orientation;
/** Requested scale factor for this output, for HiDPI support */
float scale;
/** Form factor of this output; phone display, tablet, monitor, TV, projector... */
MirFormFactor form_factor;
/** Subpixel arrangement of this output */
MirSubpixelArrangement subpixel_arrangement;
/** The current gamma for the display */
GammaCurves gamma;
MirOutputGammaSupported gamma_supported;
/** EDID of the display, if non-empty */
std::vector edid;
/** The logical rectangle occupied by the output, based on its position,
current mode and orientation (rotation) */
geometry::Rectangle extents() const;
bool valid() const;
};
/**
* Mirror of a DisplayConfigurationOutput, with some fields limited to
* being read-only, preventing users from changing things they shouldn't.
*/
struct UserDisplayConfigurationOutput
{
DisplayConfigurationOutputId const& id;
DisplayConfigurationCardId const& card_id;
DisplayConfigurationOutputType const& type;
std::vector const& pixel_formats;
std::vector const& modes;
uint32_t const& preferred_mode_index;
geometry::Size const& physical_size_mm;
bool const& connected;
bool& used;
geometry::Point& top_left;
uint32_t& current_mode_index;
MirPixelFormat& current_format;
MirPowerMode& power_mode;
MirOrientation& orientation;
float& scale;
MirFormFactor& form_factor;
MirSubpixelArrangement& subpixel_arrangement;
GammaCurves& gamma;
MirOutputGammaSupported const& gamma_supported;
std::vector const& edid;
UserDisplayConfigurationOutput(DisplayConfigurationOutput& master);
geometry::Rectangle extents() const;
};
std::ostream& operator<<(std::ostream& out, DisplayConfigurationCard const& val);
bool operator==(DisplayConfigurationCard const& val1, DisplayConfigurationCard const& val2);
bool operator!=(DisplayConfigurationCard const& val1, DisplayConfigurationCard const& val2);
std::ostream& operator<<(std::ostream& out, DisplayConfigurationMode const& val);
bool operator==(DisplayConfigurationMode const& val1, DisplayConfigurationMode const& val2);
bool operator!=(DisplayConfigurationMode const& val1, DisplayConfigurationMode const& val2);
std::ostream& operator<<(std::ostream& out, DisplayConfigurationOutput const& val);
bool operator==(DisplayConfigurationOutput const& val1, DisplayConfigurationOutput const& val2);
bool operator!=(DisplayConfigurationOutput const& val1, DisplayConfigurationOutput const& val2);
/**
* Interface to a configuration of display cards and outputs.
*/
class DisplayConfiguration
{
public:
virtual ~DisplayConfiguration() = default;
/** Executes a function object for each card in the configuration. */
virtual void for_each_card(std::function f) const = 0;
/** Executes a function object for each output in the configuration. */
virtual void for_each_output(std::function f) const = 0;
virtual void for_each_output(std::function f) = 0;
virtual std::unique_ptr clone() const = 0;
virtual bool valid() const;
protected:
DisplayConfiguration() = default;
DisplayConfiguration(DisplayConfiguration const& c) = delete;
DisplayConfiguration& operator=(DisplayConfiguration const& c) = delete;
};
bool operator==(DisplayConfiguration const& lhs, DisplayConfiguration const& rhs);
bool operator!=(DisplayConfiguration const& lhs, DisplayConfiguration const& rhs);
std::ostream& operator<<(std::ostream& out, DisplayConfiguration const& val);
}
}
#endif /* MIR_GRAPHICS_DISPLAY_CONFIGURATION_H_ */
./include/platform/mir/graphics/gamma_curves.h 0000644 0000041 0000041 00000002724 13115234664 021735 0 ustar www-data www-data /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Brandon Schaefer
*/
#ifndef MIR_GRAPHICS_GAMMA_CURVES_H_
#define MIR_GRAPHICS_GAMMA_CURVES_H_
#include
#include
namespace mir
{
namespace graphics
{
typedef std::vector GammaCurve;
class GammaCurves
{
public:
GammaCurves() = default;
GammaCurves(GammaCurves const& other) = default;
GammaCurves(GammaCurves&& other) = default;
GammaCurves(GammaCurve const& red,
GammaCurve const& green,
GammaCurve const& blue);
GammaCurves& operator=(GammaCurves const& other) = default;
GammaCurves& operator=(GammaCurves&& other) = default;
GammaCurve red;
GammaCurve green;
GammaCurve blue;
};
class LinearGammaLUTs : public GammaCurves
{
public:
explicit LinearGammaLUTs(int size);
};
}
}
#endif
./include/platform/mir/graphics/display_buffer.h 0000644 0000041 0000041 00000007436 13115234664 022267 0 ustar www-data www-data /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef MIR_GRAPHICS_DISPLAY_BUFFER_H_
#define MIR_GRAPHICS_DISPLAY_BUFFER_H_
#include
#include
#include
#include