diff options
| author | Alberto Aguirre <alberto.aguirre@canonical.com> | 2017-01-15 00:44:02 (GMT) |
|---|---|---|
| committer | Alberto Aguirre <alberto.aguirre@canonical.com> | 2017-01-15 00:44:02 (GMT) |
| commit | 7c8c501b67bb9ca2059838947b8eab918779fd36 (patch) | |
| tree | 1dafa5e985742d38842c03bfba34825742915601 | |
| parent | 7ee3257f876047d1dc7ec58985831714f86dbd7a (diff) | |
Add workaround for mir bug LP: #1656164
Workaround for black-screen on RPi3
| -rw-r--r-- | drm-init-gamma/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | drm-init-gamma/src/CMakeLists.txt | 9 | ||||
| -rw-r--r-- | drm-init-gamma/src/drm-init-gamma.cpp | 83 | ||||
| -rwxr-xr-x | run-miral | 3 | ||||
| -rw-r--r-- | snapcraft.yaml | 8 |
5 files changed, 115 insertions, 0 deletions
diff --git a/drm-init-gamma/CMakeLists.txt b/drm-init-gamma/CMakeLists.txt new file mode 100644 index 0000000..f096a58 --- /dev/null +++ b/drm-init-gamma/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required (VERSION 3.0) +project(drm-init-gamma) + +include (GNUInstallDirs) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++14") + +find_package(PkgConfig) +pkg_check_modules(DRM REQUIRED libdrm) + +add_subdirectory(src) diff --git a/drm-init-gamma/src/CMakeLists.txt b/drm-init-gamma/src/CMakeLists.txt new file mode 100644 index 0000000..dcdc31d --- /dev/null +++ b/drm-init-gamma/src/CMakeLists.txt @@ -0,0 +1,9 @@ +include_directories(${DRM_INCLUDE_DIRS}) + +add_executable(drm-init-gamma drm-init-gamma.cpp) +target_link_libraries(drm-init-gamma ${DRM_LDFLAGS} ${DRM_LIBRARIES}) + +install( + TARGETS drm-init-gamma + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/drm-init-gamma/src/drm-init-gamma.cpp b/drm-init-gamma/src/drm-init-gamma.cpp new file mode 100644 index 0000000..6499711 --- /dev/null +++ b/drm-init-gamma/src/drm-init-gamma.cpp @@ -0,0 +1,83 @@ +#include <fcntl.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <xf86drm.h> +#include <xf86drmMode.h> + +#include <cstdint> + +#include <algorithm> +#include <limits> +#include <iostream> +#include <stdexcept> +#include <vector> + +namespace +{ +using GammaLUT = std::vector<uint16_t>; + +GammaLUT make_linear_ramp(uint32_t size) +{ + GammaLUT lut(size); + auto const step = std::numeric_limits<GammaLUT::value_type>::max() / (size - 1); + GammaLUT::value_type n = 0; + std::generate(lut.begin(), lut.end(), [&n, step]{ auto current = n; n += step; return current; }); + return lut; +} + +class DrmVersion +{ +public: + DrmVersion(int fd) : ver(drmGetVersion(fd)) {} + ~DrmVersion() { drmFreeVersion(ver); } + + drmVersionPtr operator->() { return ver; } +private: + drmVersionPtr ver{nullptr}; +}; + +class Drm +{ +public: + Drm() : fd(open("/dev/dri/card0", O_RDWR | O_CLOEXEC)) + { + if (fd < 1) + throw std::runtime_error("Could not open DRM device"); + if (!is_vc4()) + throw std::runtime_error("Not a VC4 drm device"); + } + ~Drm() { close(fd); } + + bool is_vc4() + { + DrmVersion info(fd); + return "vc4" == std::string(info->name); + } + + void set_gamma() + { + uint32_t const size = 256; + uint32_t const crtc_id = 48; + + GammaLUT lut = make_linear_ramp(size); + if (drmModeCrtcSetGamma(fd, crtc_id, size, &lut[0], &lut[0], &lut[0]) != 0) + { + throw std::runtime_error("failed to set Gamma LUT on drm device"); + } + } +private: + int fd; +}; +} + +int main() +try +{ + Drm drm; + drm.set_gamma(); +} +catch (std::exception const& e) +{ + std::cerr << "error: " << e.what() << std::endl; +} @@ -32,6 +32,9 @@ export MIR_CLIENT_PLATFORM_PATH=$SNAP/mir-libs/$ARCH/mir/client-platform export MIR_SERVER_PLATFORM_PATH=$SNAP/mir-libs/$ARCH/mir/server-platform export LD_LIBRARY_PATH="$SNAP/mir-libs/$ARCH:$SNAP/mir-libs/$ARCH/mesa-egl:$LD_LIBRARY_PATH" +# Workaround for mir bug LP:#1656164 +$SNAP/bin/drm-init-gamma + while true; do bin_to_run=$(choose_kiosk_or_shell) diff --git a/snapcraft.yaml b/snapcraft.yaml index 1d3c8d0..07e6865 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -42,3 +42,11 @@ parts: inotify-tools: plugin: nil stage-packages: [inotify-tools] + + drm-init-gamma: + plugin: cmake + source: drm-init-gamma + build-packages: + - build-essential + - libdrm-dev + - pkg-config |
