1 /*
2 * Copyright 2003-2009, Haiku Inc.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Stefano Ceccherini (burton666@libero.it)
7 * Axel Dörfler, axeld@pinc-software.de
8 */
9
10
11 #include <Screen.h>
12
13 #include <Window.h>
14
15 #include <PrivateScreen.h>
16
17
18 using namespace BPrivate;
19
20
BScreen(screen_id id)21 BScreen::BScreen(screen_id id)
22 {
23 fScreen = BPrivateScreen::Get(id.id);
24 }
25
26
BScreen(BWindow * window)27 BScreen::BScreen(BWindow* window)
28 {
29 fScreen = BPrivateScreen::Get(window);
30 }
31
32
~BScreen()33 BScreen::~BScreen()
34 {
35 BPrivateScreen::Put(fScreen);
36 }
37
38
39 bool
IsValid()40 BScreen::IsValid()
41 {
42 return fScreen != NULL && fScreen->IsValid();
43 }
44
45
46 status_t
SetToNext()47 BScreen::SetToNext()
48 {
49 if (fScreen != NULL) {
50 BPrivateScreen* screen = BPrivateScreen::GetNext(fScreen);
51 if (screen != NULL) {
52 fScreen = screen;
53 return B_OK;
54 }
55 }
56 return B_ERROR;
57 }
58
59
60 color_space
ColorSpace()61 BScreen::ColorSpace()
62 {
63 if (fScreen != NULL)
64 return fScreen->ColorSpace();
65
66 return B_NO_COLOR_SPACE;
67 }
68
69
70 BRect
Frame()71 BScreen::Frame()
72 {
73 if (fScreen != NULL)
74 return fScreen->Frame();
75
76 return BRect(0, 0, 0, 0);
77 }
78
79
80 screen_id
ID()81 BScreen::ID()
82 {
83 if (fScreen != NULL) {
84 screen_id id = { fScreen->ID() };
85 return id;
86 }
87
88 return B_MAIN_SCREEN_ID;
89 }
90
91
92 status_t
WaitForRetrace()93 BScreen::WaitForRetrace()
94 {
95 return WaitForRetrace(B_INFINITE_TIMEOUT);
96 }
97
98
99 status_t
WaitForRetrace(bigtime_t timeout)100 BScreen::WaitForRetrace(bigtime_t timeout)
101 {
102 if (fScreen != NULL)
103 return fScreen->WaitForRetrace(timeout);
104
105 return B_ERROR;
106 }
107
108
109 uint8
IndexForColor(uint8 red,uint8 green,uint8 blue,uint8 alpha)110 BScreen::IndexForColor(uint8 red, uint8 green, uint8 blue, uint8 alpha)
111 {
112 if (fScreen != NULL)
113 return fScreen->IndexForColor(red, green, blue, alpha);
114
115 return 0;
116 }
117
118
119 rgb_color
ColorForIndex(const uint8 index)120 BScreen::ColorForIndex(const uint8 index)
121 {
122 if (fScreen != NULL)
123 return fScreen->ColorForIndex(index);
124
125 return rgb_color();
126 }
127
128
129 uint8
InvertIndex(uint8 index)130 BScreen::InvertIndex(uint8 index)
131 {
132 if (fScreen != NULL)
133 return fScreen->InvertIndex(index);
134
135 return 0;
136 }
137
138
139 const color_map*
ColorMap()140 BScreen::ColorMap()
141 {
142 if (fScreen != NULL)
143 return fScreen->ColorMap();
144
145 return NULL;
146 }
147
148
149 status_t
GetBitmap(BBitmap ** _bitmap,bool drawCursor,BRect * bounds)150 BScreen::GetBitmap(BBitmap** _bitmap, bool drawCursor, BRect* bounds)
151 {
152 if (fScreen != NULL)
153 return fScreen->GetBitmap(_bitmap, drawCursor, bounds);
154
155 return B_ERROR;
156 }
157
158
159 status_t
ReadBitmap(BBitmap * bitmap,bool drawCursor,BRect * bounds)160 BScreen::ReadBitmap(BBitmap* bitmap, bool drawCursor, BRect* bounds)
161 {
162 if (fScreen != NULL)
163 return fScreen->ReadBitmap(bitmap, drawCursor, bounds);
164
165 return B_ERROR;
166 }
167
168
169 rgb_color
DesktopColor()170 BScreen::DesktopColor()
171 {
172 if (fScreen != NULL)
173 return fScreen->DesktopColor(B_CURRENT_WORKSPACE_INDEX);
174
175 return rgb_color();
176 }
177
178
179 rgb_color
DesktopColor(uint32 workspace)180 BScreen::DesktopColor(uint32 workspace)
181 {
182 if (fScreen != NULL)
183 return fScreen->DesktopColor(workspace);
184
185 return rgb_color();
186 }
187
188
189 void
SetDesktopColor(rgb_color color,bool stick)190 BScreen::SetDesktopColor(rgb_color color, bool stick)
191 {
192 if (fScreen != NULL)
193 fScreen->SetDesktopColor(color, B_CURRENT_WORKSPACE_INDEX, stick);
194 }
195
196
197 void
SetDesktopColor(rgb_color color,uint32 workspace,bool stick)198 BScreen::SetDesktopColor(rgb_color color, uint32 workspace, bool stick)
199 {
200 if (fScreen != NULL)
201 fScreen->SetDesktopColor(color, workspace, stick);
202 }
203
204
205 status_t
ProposeMode(display_mode * target,const display_mode * low,const display_mode * high)206 BScreen::ProposeMode(display_mode* target, const display_mode* low,
207 const display_mode* high)
208 {
209 if (fScreen != NULL)
210 return fScreen->ProposeMode(target, low, high);
211
212 return B_ERROR;
213 }
214
215
216 status_t
GetModeList(display_mode ** _modeList,uint32 * _count)217 BScreen::GetModeList(display_mode** _modeList, uint32* _count)
218 {
219 if (fScreen != NULL)
220 return fScreen->GetModeList(_modeList, _count);
221
222 return B_ERROR;
223 }
224
225
226 status_t
GetMode(display_mode * mode)227 BScreen::GetMode(display_mode* mode)
228 {
229 if (fScreen != NULL)
230 return fScreen->GetMode(B_CURRENT_WORKSPACE_INDEX, mode);
231
232 return B_ERROR;
233 }
234
235
236 status_t
GetMode(uint32 workspace,display_mode * mode)237 BScreen::GetMode(uint32 workspace, display_mode* mode)
238 {
239 if (fScreen != NULL)
240 return fScreen->GetMode(workspace, mode);
241
242 return B_ERROR;
243 }
244
245
246 status_t
SetMode(display_mode * mode,bool makeDefault)247 BScreen::SetMode(display_mode* mode, bool makeDefault)
248 {
249 if (fScreen != NULL)
250 return fScreen->SetMode(B_CURRENT_WORKSPACE_INDEX, mode, makeDefault);
251
252 return B_ERROR;
253 }
254
255
256 status_t
SetMode(uint32 workspace,display_mode * mode,bool makeDefault)257 BScreen::SetMode(uint32 workspace, display_mode* mode, bool makeDefault)
258 {
259 if (fScreen != NULL)
260 return fScreen->SetMode(workspace, mode, makeDefault);
261
262 return B_ERROR;
263 }
264
265
266 status_t
GetDeviceInfo(accelerant_device_info * info)267 BScreen::GetDeviceInfo(accelerant_device_info* info)
268 {
269 if (fScreen != NULL)
270 return fScreen->GetDeviceInfo(info);
271
272 return B_ERROR;
273 }
274
275
276 status_t
GetMonitorInfo(monitor_info * info)277 BScreen::GetMonitorInfo(monitor_info* info)
278 {
279 if (fScreen != NULL)
280 return fScreen->GetMonitorInfo(info);
281
282 return B_ERROR;
283 }
284
285
286 status_t
GetPixelClockLimits(display_mode * mode,uint32 * _low,uint32 * _high)287 BScreen::GetPixelClockLimits(display_mode* mode, uint32* _low, uint32* _high)
288 {
289 if (fScreen != NULL)
290 return fScreen->GetPixelClockLimits(mode, _low, _high);
291
292 return B_ERROR;
293 }
294
295
296 status_t
GetTimingConstraints(display_timing_constraints * constraints)297 BScreen::GetTimingConstraints(display_timing_constraints* constraints)
298 {
299 if (fScreen != NULL)
300 return fScreen->GetTimingConstraints(constraints);
301
302 return B_ERROR;
303 }
304
305
306 status_t
SetDPMS(uint32 dpmsState)307 BScreen::SetDPMS(uint32 dpmsState)
308 {
309 if (fScreen != NULL)
310 return fScreen->SetDPMS(dpmsState);
311
312 return B_ERROR;
313 }
314
315
316 uint32
DPMSState()317 BScreen::DPMSState()
318 {
319 if (fScreen != NULL)
320 return fScreen->DPMSState();
321
322 return 0;
323 }
324
325
326 uint32
DPMSCapabilites()327 BScreen::DPMSCapabilites()
328 {
329 if (fScreen != NULL)
330 return fScreen->DPMSCapabilites();
331
332 return 0;
333 }
334
335
336 status_t
GetBrightness(float * brightness)337 BScreen::GetBrightness(float* brightness)
338 {
339 if (fScreen != NULL)
340 return fScreen->GetBrightness(brightness);
341 return B_ERROR;
342 }
343
344
345 status_t
SetBrightness(float brightness)346 BScreen::SetBrightness(float brightness)
347 {
348 if (fScreen != NULL)
349 return fScreen->SetBrightness(brightness);
350 return B_ERROR;
351 }
352
353
354 // #pragma mark - Deprecated methods
355
356
357 BPrivate::BPrivateScreen*
private_screen()358 BScreen::private_screen()
359 {
360 return fScreen;
361 }
362
363
364 status_t
ProposeDisplayMode(display_mode * target,const display_mode * low,const display_mode * high)365 BScreen::ProposeDisplayMode(display_mode* target, const display_mode* low,
366 const display_mode* high)
367 {
368 return ProposeMode(target, low, high);
369 }
370
371
372 void*
BaseAddress()373 BScreen::BaseAddress()
374 {
375 if (fScreen != NULL)
376 return fScreen->BaseAddress();
377
378 return NULL;
379 }
380
381
382 uint32
BytesPerRow()383 BScreen::BytesPerRow()
384 {
385 if (fScreen != NULL)
386 return fScreen->BytesPerRow();
387
388 return 0;
389 }
390