blob: 0783871014ef36eac68750cf7a8198d4de03f87c [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) {};
51 inline void add_screen(const Screen screen) { screens.push_back(screen); };
52 inline bool validate(int fb_width, int fb_height) const {
53 std::list<Screen>::const_iterator iter;
54 std::set<rdr::U32> seen_ids;
55 Rect fb_rect;
56
57 if (screens.empty())
58 return false;
59
60 fb_rect.setXYWH(0, 0, fb_width, fb_height);
61
62 for (iter = screens.begin();iter != screens.end();++iter) {
63 if (iter->dimensions.is_empty())
64 return false;
65 if (!iter->dimensions.enclosed_by(fb_rect))
66 return false;
67 if (seen_ids.find(iter->id) != seen_ids.end())
68 return false;
69 seen_ids.insert(iter->id);
70 }
71
72 return true;
73 };
74 std::list<Screen> screens;
75 };
76
77};
78
79#endif
80