From 834e47d2cfd8a33fbdaeb9aa4bbf945b7a288b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Tue, 3 Jan 2017 12:51:49 +0100 Subject: [PATCH] fb_sdl: remove deprecated APIs Issue #1987. --- .../drivers/framebuffer/spec/sdl/fb_sdl.cc | 137 ++++++++---------- .../src/drivers/framebuffer/spec/sdl/input.cc | 15 +- .../src/drivers/framebuffer/spec/sdl/input.h | 4 +- .../drivers/framebuffer/spec/sdl/target.mk | 2 +- 4 files changed, 74 insertions(+), 84 deletions(-) diff --git a/repos/os/src/drivers/framebuffer/spec/sdl/fb_sdl.cc b/repos/os/src/drivers/framebuffer/spec/sdl/fb_sdl.cc index 27610ad7a7..b73c8a3af0 100644 --- a/repos/os/src/drivers/framebuffer/spec/sdl/fb_sdl.cc +++ b/repos/os/src/drivers/framebuffer/spec/sdl/fb_sdl.cc @@ -6,43 +6,46 @@ */ /* - * Copyright (C) 2006-2016 Genode Labs GmbH + * Copyright (C) 2006-2017 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. */ +/* Genode includes */ +#include +#include +#include +#include +#include + /* Linux includes */ #include -/* Genode includes */ -#include -#include -#include -#include -#include -#include -#include -#include - /* local includes */ #include "input.h" - -using Genode::Attached_ram_dataspace; +namespace Framebuffer { + class Session_component; + using namespace Genode; +} -namespace Framebuffer { class Session_component; } +namespace Fb_sdl { + class Main; + using namespace Genode; +} -class Framebuffer::Session_component : public Genode::Rpc_object + +class Framebuffer::Session_component : public Rpc_object { private: SDL_Surface *_screen { nullptr }; - Mode _mode; - Genode::Dataspace_capability _fb_ds_cap; - void *_fb_ds_addr; + Mode _mode; + Dataspace_capability _fb_ds_cap; + void *_fb_ds_addr; Timer::Connection _timer; @@ -51,21 +54,21 @@ class Framebuffer::Session_component : public Genode::Rpc_object /** * Constructor */ - Session_component(Framebuffer::Mode mode, - Genode::Dataspace_capability fb_ds_cap, void *fb_ds_addr) + Session_component(Env &env, Framebuffer::Mode mode, + Dataspace_capability fb_ds_cap, void *fb_ds_addr) : - _mode(mode), _fb_ds_cap(fb_ds_cap), _fb_ds_addr(fb_ds_addr) + _mode(mode), _fb_ds_cap(fb_ds_cap), _fb_ds_addr(fb_ds_addr), _timer(env) { } void screen(SDL_Surface *screen) { _screen = screen; } - Genode::Dataspace_capability dataspace() override { return _fb_ds_cap; } + Dataspace_capability dataspace() override { return _fb_ds_cap; } Mode mode() const override { return _mode; } - void mode_sigh(Genode::Signal_context_capability) override { } + void mode_sigh(Signal_context_capability) override { } - void sync_sigh(Genode::Signal_context_capability sigh) override + void sync_sigh(Signal_context_capability sigh) override { _timer.sigh(sigh); if (sigh.valid()) @@ -75,10 +78,10 @@ class Framebuffer::Session_component : public Genode::Rpc_object void refresh(int x, int y, int w, int h) override { /* clip refresh area to screen boundaries */ - int x1 = Genode::max(x, 0); - int y1 = Genode::max(y, 0); - int x2 = Genode::min(x + w - 1, _mode.width() - 1); - int y2 = Genode::min(y + h - 1, _mode.height() - 1); + int x1 = max(x, 0); + int y1 = max(y, 0); + int x2 = min(x + w - 1, _mode.width() - 1); + int y2 = min(y + h - 1, _mode.height() - 1); if (x1 <= x2 && y1 <= y2) { @@ -131,56 +134,42 @@ namespace Input { } -/** - * Read integer value from config attribute - */ -template -static T config_arg(char const *attr, T const &default_value) -{ - long value = default_value; - - try { Genode::config()->xml_node().attribute(attr).value(&value); } - catch (...) { } - - return value; -} - - -struct Main +struct Fb_sdl::Main { /* fatal exceptions */ - struct Sdl_init_failed { }; - struct Sdl_videodriver_not_supported { }; - struct Sdl_setvideomode_failed { }; + struct Sdl_init_failed : Exception { }; + struct Sdl_videodriver_not_supported : Exception { }; + struct Sdl_setvideomode_failed : Exception { }; - Genode::Env &env; + Env &_env; - int fb_width { config_arg("width", 1024) }; - int fb_height { config_arg("height", 768) }; + Attached_rom_dataspace _config { _env, "config" }; - Framebuffer::Mode fb_mode { fb_width, fb_height, Framebuffer::Mode::RGB565 }; + int const _fb_width = _config.xml().attribute_value("width", 1024UL); + int const _fb_height = _config.xml().attribute_value("height", 768UL); - Attached_ram_dataspace fb_ds { &env.ram(), - fb_mode.width()*fb_mode.height()*fb_mode.bytes_per_pixel() }; + Framebuffer::Mode _fb_mode { _fb_width, _fb_height, Framebuffer::Mode::RGB565 }; - Framebuffer::Session_component fb_session { fb_mode, fb_ds.cap(), fb_ds.local_addr() }; + Attached_ram_dataspace _fb_ds { _env.ram(), _env.rm(), + _fb_mode.width()*_fb_mode.height()*_fb_mode.bytes_per_pixel() }; - Genode::Static_root fb_root { env.ep().manage(fb_session) }; + Framebuffer::Session_component _fb_session { _env, _fb_mode, _fb_ds.cap(), _fb_ds.local_addr() }; - Input::Session_component input_session { env, env.ram() }; - Input::Root_component input_root { env.ep().rpc_ep(), input_session }; + Static_root _fb_root { _env.ep().manage(_fb_session) }; - Input::Handler_component input_handler_component { input_session }; - Input::Handler_client input_handler_client { env.ep().manage(input_handler_component) }; + Input::Session_component _input_session { _env, _env.ram() }; + Input::Root_component _input_root { _env.ep().rpc_ep(), _input_session }; - Main(Genode::Env &env) : env(env) + Input::Handler_component _input_handler_component { _input_session }; + Input::Handler_client _input_handler_client { _env.ep().manage(_input_handler_component) }; + + Main(Env &env) : _env(env) { /* * Initialize libSDL window */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) - { - Genode::error("SDL_Init failed (", Genode::Cstring(SDL_GetError()), ")"); + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + error("SDL_Init failed (", Genode::Cstring(SDL_GetError()), ")"); throw Sdl_init_failed(); } @@ -190,29 +179,29 @@ struct Main char driver[16] = { 0 }; SDL_VideoDriverName(driver, sizeof(driver)); if (::strcmp(driver, "x11") != 0) { - Genode::error("fb_sdl works on X11 only. " - "Your SDL backend is ", Genode::Cstring(driver), "."); + error("fb_sdl works on X11 only. " + "Your SDL backend is ", Genode::Cstring(driver), "."); throw Sdl_videodriver_not_supported(); } - SDL_Surface *screen = SDL_SetVideoMode(fb_mode.width(), fb_mode.height(), - fb_mode.bytes_per_pixel()*8, SDL_SWSURFACE); + SDL_Surface *screen = SDL_SetVideoMode(_fb_mode.width(), _fb_mode.height(), + _fb_mode.bytes_per_pixel()*8, SDL_SWSURFACE); if (!screen) { - Genode::error("SDL_SetVideoMode failed (", Genode::Cstring(SDL_GetError()), ")"); + error("SDL_SetVideoMode failed (", Genode::Cstring(SDL_GetError()), ")"); throw Sdl_setvideomode_failed(); } - fb_session.screen(screen); + _fb_session.screen(screen); SDL_ShowCursor(0); - Genode::log("creating virtual framebuffer for mode ", fb_mode); + log("creating virtual framebuffer for mode ", _fb_mode); - env.parent().announce(env.ep().manage(fb_root)); - env.parent().announce(env.ep().manage(input_root)); + _env.parent().announce(env.ep().manage(_fb_root)); + _env.parent().announce(env.ep().manage(_input_root)); - init_input_backend(input_handler_client); + init_input_backend(_env, _input_handler_client); } }; -void Component::construct(Genode::Env &env) { static Main inst(env); } +void Component::construct(Genode::Env &env) { static Fb_sdl::Main inst(env); } diff --git a/repos/os/src/drivers/framebuffer/spec/sdl/input.cc b/repos/os/src/drivers/framebuffer/spec/sdl/input.cc index a522ef79b4..2ef725f51f 100644 --- a/repos/os/src/drivers/framebuffer/spec/sdl/input.cc +++ b/repos/os/src/drivers/framebuffer/spec/sdl/input.cc @@ -6,7 +6,7 @@ */ /* - * Copyright (C) 2006-2016 Genode Labs GmbH + * Copyright (C) 2006-2017 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. @@ -16,7 +16,6 @@ #include /* Genode includes */ -#include #include #include @@ -214,17 +213,16 @@ static Input::Event wait_for_sdl_event() namespace Input { - enum { STACK_SIZE = 4096*sizeof(long) }; struct Backend; } -struct Input::Backend : Genode::Thread_deprecated +struct Input::Backend : Genode::Thread { Handler &handler; - Backend(Input::Handler &handler) + Backend(Genode::Env &env, Input::Handler &handler) : - Genode::Thread_deprecated("input_backend"), + Genode::Thread(env, "input_backend", 4 * 1024 * sizeof(long)), handler(handler) { start(); @@ -246,4 +244,7 @@ struct Input::Backend : Genode::Thread_deprecated }; -void init_input_backend(Input::Handler &h) { static Input::Backend inst(h); } +void init_input_backend(Genode::Env &env, Input::Handler &h) +{ + static Input::Backend inst(env, h); +} diff --git a/repos/os/src/drivers/framebuffer/spec/sdl/input.h b/repos/os/src/drivers/framebuffer/spec/sdl/input.h index 2aea8b8ece..1e94b753a2 100644 --- a/repos/os/src/drivers/framebuffer/spec/sdl/input.h +++ b/repos/os/src/drivers/framebuffer/spec/sdl/input.h @@ -6,7 +6,7 @@ */ /* - * Copyright (C) 2006-2016 Genode Labs GmbH + * Copyright (C) 2006-2017 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. @@ -25,6 +25,6 @@ struct Input::Handler virtual void event(Input::Event) = 0; }; -void init_input_backend(Input::Handler &); +void init_input_backend(Genode::Env &, Input::Handler &); #endif /* _DRIVERS__FRAMEBUFFER__SPEC__SDL__INPUT_H_ */ diff --git a/repos/os/src/drivers/framebuffer/spec/sdl/target.mk b/repos/os/src/drivers/framebuffer/spec/sdl/target.mk index 94106e429a..33f0461701 100644 --- a/repos/os/src/drivers/framebuffer/spec/sdl/target.mk +++ b/repos/os/src/drivers/framebuffer/spec/sdl/target.mk @@ -1,5 +1,5 @@ TARGET = fb_sdl -LIBS = lx_hybrid config +LIBS = lx_hybrid REQUIRES = linux sdl SRC_CC = fb_sdl.cc input.cc LX_LIBS = sdl