genode/repos/os/src/server/nitpicker/session.h
Norman Feske d22cddd1e8 nitpicker: Perform redraw asynchronously
This patch changes nitpicker's way of redrawing. Originally, redraw
operations were triggered immediately by the RPC functions invoked by
clients. In the presence of clients that invoked a large number of those
functions, the server could become overloaded with processing redraw
operations. The new version performs redraw operations out of band with
the RPC functions. Similar to the design of the DOpE GUI server, redraw
operations are processed periodically. The RPC functions merely modify
meta data and track the dirty areas that need to be updated.
Consequently, nitpicker's RPC functions become light-weight operations.

As a nice collateral effect of this patch, nitpicker's internal
structure could be simplified because the drawing backend is no longer
needed by the code that dispatches the RPC interface.
2014-08-11 15:55:32 +02:00

144 lines
3.6 KiB
C++

/*
* \brief Nitpicker session interface
* \author Norman Feske
* \date 2006-08-09
*/
/*
* Copyright (C) 2006-2013 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.
*/
#ifndef _SESSION_H_
#define _SESSION_H_
/* Genode includes */
#include <util/list.h>
#include <util/string.h>
#include <os/session_policy.h>
/* local includes */
#include "color.h"
#include "canvas.h"
class View;
class Session;
namespace Input { class Event; }
typedef Genode::List<Session> Session_list;
class Session : public Session_list::Element
{
private:
Genode::Session_label const _label;
Color _color;
Texture_base const *_texture = { 0 };
bool _uses_alpha = { false };
View *_background = 0;
int _v_offset;
unsigned char const *_input_mask = { 0 };
bool const _stay_top;
public:
/**
* Constructor
*
* \param label session label
* \param v_offset vertical screen offset of session
* \param stay_top true for views that stay always in front
*/
Session(Genode::Session_label const &label, int v_offset, bool stay_top)
:
_label(label), _v_offset(v_offset), _stay_top(stay_top)
{ }
virtual ~Session() { }
virtual void submit_input_event(Input::Event ev) = 0;
virtual void submit_sync() = 0;
Genode::Session_label const &label() const { return _label; }
Texture_base const *texture() const { return _texture; }
void texture(Texture_base const *texture, bool uses_alpha)
{
_texture = texture;
_uses_alpha = uses_alpha;
}
/**
* Set input mask buffer
*
* \param mask input mask buffer containing a byte value per texture
* pixel, which describes the policy of handling user
* input referring to the pixel. If set to zero, the input
* is passed through the view such that it can be handled
* by one of the subsequent views in the view stack. If
* set to one, the input is consumed by the view. If
* 'input_mask' is a null pointer, user input is
* unconditionally consumed by the view.
*/
void input_mask(unsigned char const *mask) { _input_mask = mask; }
Color color() const { return _color; }
View *background() const { return _background; }
void background(View *background) { _background = background; }
bool stay_top() const { return _stay_top; }
/**
* Return true if session uses an alpha channel
*/
bool uses_alpha() const { return _texture && _uses_alpha; }
/**
* Return vertical offset of session
*/
int v_offset() const { return _v_offset; }
/**
* Return input mask value at specified buffer position
*/
unsigned char input_mask_at(Point p) const
{
if (!_input_mask || !_texture) return 0;
/* check boundaries */
if ((unsigned)p.x() >= _texture->size().w()
|| (unsigned)p.y() >= _texture->size().h())
return 0;
return _input_mask[p.y()*_texture->size().w() + p.x()];
}
/**
* Set session color according to the list of configured policies
*
* Select the policy that matches the label. If multiple policies
* match, select the one with the largest number of characters.
*/
void apply_session_color()
{
/* use white by default */
_color = WHITE;
try {
Genode::Session_policy policy(_label);
/* read color attribute */
policy.attribute("color").value(&_color);
} catch (...) { }
}
};
#endif