blob: 55abb5098955376b46ee8bb03383ea8c17f9139e [file] [log] [blame]
Pierre Ossmancbd1b2c2009-03-20 16:05:04 +00001/* Copyright 2009 Pierre Ossman for Cendio AB
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// Management class for the RFB virtual screens
20
21#ifndef __RFB_SCREENSET_INCLUDED__
22#define __RFB_SCREENSET_INCLUDED__
23
24#include <rfb/Rect.h>
25#include <list>
26#include <set>
27
28namespace rfb {
29
30 // rfb::Screen
31 //
32 // Represents a single RFB virtual screen, which includes
33 // coordinates, an id and flags.
34
35 struct Screen {
36 Screen(void) : id(0), flags(0) {};
37 Screen(rdr::U32 id_, int x_, int y_, int w_, int h_, rdr::U32 flags_) :
38 id(id_), dimensions(x_, y_, x_+w_, y_+h_), flags(flags_) {};
39 rdr::U32 id;
40 Rect dimensions;
41 rdr::U32 flags;
42 };
43
44 // rfb::ScreenSet
45 //
46 // Represents a complete screen configuration, excluding framebuffer
47 // dimensions.
48
49 struct ScreenSet {
50 ScreenSet(void) {};
Pierre Ossman34e62f32009-03-20 21:46:12 +000051
52 typedef std::list<Screen>::iterator iterator;
53 typedef std::list<Screen>::const_iterator const_iterator;
54
55 inline iterator begin(void) { return screens.begin(); };
56 inline const_iterator begin(void) const { return screens.begin(); };
57 inline iterator end(void) { return screens.end(); };
58 inline const_iterator end(void) const { return screens.end(); };
59
60 inline int num_screens(void) const { return screens.size(); };
61
Pierre Ossmancbd1b2c2009-03-20 16:05:04 +000062 inline void add_screen(const Screen screen) { screens.push_back(screen); };
Pierre Ossman34e62f32009-03-20 21:46:12 +000063 inline void remove_screen(rdr::U32 id) {
64 std::list<Screen>::iterator iter;
65 for (iter = screens.begin();iter != screens.end();++iter) {
66 if (iter->id == id)
67 screens.erase(iter);
68 }
69 }
70
Pierre Ossmancbd1b2c2009-03-20 16:05:04 +000071 inline bool validate(int fb_width, int fb_height) const {
72 std::list<Screen>::const_iterator iter;
73 std::set<rdr::U32> seen_ids;
74 Rect fb_rect;
75
76 if (screens.empty())
77 return false;
Pierre Ossman34e62f32009-03-20 21:46:12 +000078 if (num_screens() > 255)
79 return false;
Pierre Ossmancbd1b2c2009-03-20 16:05:04 +000080
81 fb_rect.setXYWH(0, 0, fb_width, fb_height);
82
83 for (iter = screens.begin();iter != screens.end();++iter) {
84 if (iter->dimensions.is_empty())
85 return false;
86 if (!iter->dimensions.enclosed_by(fb_rect))
87 return false;
88 if (seen_ids.find(iter->id) != seen_ids.end())
89 return false;
90 seen_ids.insert(iter->id);
91 }
92
93 return true;
94 };
Pierre Ossman34e62f32009-03-20 21:46:12 +000095
Pierre Ossmancbd1b2c2009-03-20 16:05:04 +000096 std::list<Screen> screens;
97 };
98
99};
100
101#endif
102