1*a68b6c25SAugustin Cavalier /*
2*a68b6c25SAugustin Cavalier * Copyright 2001-2009, Haiku.
3*a68b6c25SAugustin Cavalier * Distributed under the terms of the MIT License.
4*a68b6c25SAugustin Cavalier *
5*a68b6c25SAugustin Cavalier * Authors:
6*a68b6c25SAugustin Cavalier * DarkWyrm <bpmagic@columbus.rr.com>
7*a68b6c25SAugustin Cavalier * Stephan Aßmus <superstippi@gmx.de>
8*a68b6c25SAugustin Cavalier */
9*a68b6c25SAugustin Cavalier
10*a68b6c25SAugustin Cavalier
11*a68b6c25SAugustin Cavalier /*! BView/BWindow combination HWInterface implementation */
12*a68b6c25SAugustin Cavalier
13*a68b6c25SAugustin Cavalier
14*a68b6c25SAugustin Cavalier #include "ViewHWInterface.h"
15*a68b6c25SAugustin Cavalier
16*a68b6c25SAugustin Cavalier #include <new>
17*a68b6c25SAugustin Cavalier #include <stdio.h>
18*a68b6c25SAugustin Cavalier
19*a68b6c25SAugustin Cavalier #include <Application.h>
20*a68b6c25SAugustin Cavalier #include <Bitmap.h>
21*a68b6c25SAugustin Cavalier #include <Cursor.h>
22*a68b6c25SAugustin Cavalier #include <Locker.h>
23*a68b6c25SAugustin Cavalier #include <Message.h>
24*a68b6c25SAugustin Cavalier #include <MessageFilter.h>
25*a68b6c25SAugustin Cavalier #include <MessageRunner.h>
26*a68b6c25SAugustin Cavalier #include <Region.h>
27*a68b6c25SAugustin Cavalier #include <Screen.h>
28*a68b6c25SAugustin Cavalier #include <String.h>
29*a68b6c25SAugustin Cavalier #include <View.h>
30*a68b6c25SAugustin Cavalier #include <Window.h>
31*a68b6c25SAugustin Cavalier
32*a68b6c25SAugustin Cavalier #include <ServerProtocol.h>
33*a68b6c25SAugustin Cavalier
34*a68b6c25SAugustin Cavalier #include "BBitmapBuffer.h"
35*a68b6c25SAugustin Cavalier #include "PortLink.h"
36*a68b6c25SAugustin Cavalier #include "ServerConfig.h"
37*a68b6c25SAugustin Cavalier #include "ServerCursor.h"
38*a68b6c25SAugustin Cavalier #include "UpdateQueue.h"
39*a68b6c25SAugustin Cavalier
40*a68b6c25SAugustin Cavalier
41*a68b6c25SAugustin Cavalier #ifdef DEBUG_DRIVER_MODULE
42*a68b6c25SAugustin Cavalier # include <stdio.h>
43*a68b6c25SAugustin Cavalier # define STRACE(x) printf x
44*a68b6c25SAugustin Cavalier #else
45*a68b6c25SAugustin Cavalier # define STRACE(x) ;
46*a68b6c25SAugustin Cavalier #endif
47*a68b6c25SAugustin Cavalier
48*a68b6c25SAugustin Cavalier
49*a68b6c25SAugustin Cavalier const unsigned char kEmptyCursor[] = { 16, 1, 0, 0,
50*a68b6c25SAugustin Cavalier 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51*a68b6c25SAugustin Cavalier 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52*a68b6c25SAugustin Cavalier 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53*a68b6c25SAugustin Cavalier 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
54*a68b6c25SAugustin Cavalier
55*a68b6c25SAugustin Cavalier static const bool kDefaultDoubleBuffered = true;
56*a68b6c25SAugustin Cavalier
57*a68b6c25SAugustin Cavalier enum {
58*a68b6c25SAugustin Cavalier MSG_UPDATE = 'updt'
59*a68b6c25SAugustin Cavalier };
60*a68b6c25SAugustin Cavalier
61*a68b6c25SAugustin Cavalier
62*a68b6c25SAugustin Cavalier const char*
string_for_color_space(color_space format)63*a68b6c25SAugustin Cavalier string_for_color_space(color_space format)
64*a68b6c25SAugustin Cavalier {
65*a68b6c25SAugustin Cavalier const char* name = "<unkown format>";
66*a68b6c25SAugustin Cavalier switch (format) {
67*a68b6c25SAugustin Cavalier case B_RGBA64:
68*a68b6c25SAugustin Cavalier name = "B_RGBA64";
69*a68b6c25SAugustin Cavalier break;
70*a68b6c25SAugustin Cavalier case B_RGBA64_BIG:
71*a68b6c25SAugustin Cavalier name = "B_RGBA64_BIG";
72*a68b6c25SAugustin Cavalier break;
73*a68b6c25SAugustin Cavalier case B_RGB48:
74*a68b6c25SAugustin Cavalier name = "B_RGB48";
75*a68b6c25SAugustin Cavalier break;
76*a68b6c25SAugustin Cavalier case B_RGB48_BIG:
77*a68b6c25SAugustin Cavalier name = "B_RGB48_BIG";
78*a68b6c25SAugustin Cavalier break;
79*a68b6c25SAugustin Cavalier case B_RGB32:
80*a68b6c25SAugustin Cavalier name = "B_RGB32";
81*a68b6c25SAugustin Cavalier break;
82*a68b6c25SAugustin Cavalier case B_RGBA32:
83*a68b6c25SAugustin Cavalier name = "B_RGBA32";
84*a68b6c25SAugustin Cavalier break;
85*a68b6c25SAugustin Cavalier case B_RGB32_BIG:
86*a68b6c25SAugustin Cavalier name = "B_RGB32_BIG";
87*a68b6c25SAugustin Cavalier break;
88*a68b6c25SAugustin Cavalier case B_RGBA32_BIG:
89*a68b6c25SAugustin Cavalier name = "B_RGBA32_BIG";
90*a68b6c25SAugustin Cavalier break;
91*a68b6c25SAugustin Cavalier case B_RGB24:
92*a68b6c25SAugustin Cavalier name = "B_RGB24";
93*a68b6c25SAugustin Cavalier break;
94*a68b6c25SAugustin Cavalier case B_RGB24_BIG:
95*a68b6c25SAugustin Cavalier name = "B_RGB24_BIG";
96*a68b6c25SAugustin Cavalier break;
97*a68b6c25SAugustin Cavalier case B_CMAP8:
98*a68b6c25SAugustin Cavalier name = "B_CMAP8";
99*a68b6c25SAugustin Cavalier break;
100*a68b6c25SAugustin Cavalier case B_GRAY8:
101*a68b6c25SAugustin Cavalier name = "B_GRAY8";
102*a68b6c25SAugustin Cavalier break;
103*a68b6c25SAugustin Cavalier case B_GRAY1:
104*a68b6c25SAugustin Cavalier name = "B_GRAY1";
105*a68b6c25SAugustin Cavalier break;
106*a68b6c25SAugustin Cavalier default:
107*a68b6c25SAugustin Cavalier break;
108*a68b6c25SAugustin Cavalier }
109*a68b6c25SAugustin Cavalier return name;
110*a68b6c25SAugustin Cavalier }
111*a68b6c25SAugustin Cavalier
112*a68b6c25SAugustin Cavalier
113*a68b6c25SAugustin Cavalier static int32
run_app_thread(void * cookie)114*a68b6c25SAugustin Cavalier run_app_thread(void* cookie)
115*a68b6c25SAugustin Cavalier {
116*a68b6c25SAugustin Cavalier if (BApplication* app = (BApplication*)cookie) {
117*a68b6c25SAugustin Cavalier app->Lock();
118*a68b6c25SAugustin Cavalier app->Run();
119*a68b6c25SAugustin Cavalier delete app;
120*a68b6c25SAugustin Cavalier }
121*a68b6c25SAugustin Cavalier return 0;
122*a68b6c25SAugustin Cavalier }
123*a68b6c25SAugustin Cavalier
124*a68b6c25SAugustin Cavalier
125*a68b6c25SAugustin Cavalier //#define INPUTSERVER_TEST_MODE 1
126*a68b6c25SAugustin Cavalier
127*a68b6c25SAugustin Cavalier
128*a68b6c25SAugustin Cavalier class CardView : public BView {
129*a68b6c25SAugustin Cavalier public:
130*a68b6c25SAugustin Cavalier CardView(BRect bounds);
131*a68b6c25SAugustin Cavalier virtual ~CardView();
132*a68b6c25SAugustin Cavalier
133*a68b6c25SAugustin Cavalier virtual void AttachedToWindow();
134*a68b6c25SAugustin Cavalier virtual void Draw(BRect updateRect);
135*a68b6c25SAugustin Cavalier virtual void MessageReceived(BMessage* message);
136*a68b6c25SAugustin Cavalier
137*a68b6c25SAugustin Cavalier // CardView
138*a68b6c25SAugustin Cavalier void SetBitmap(const BBitmap* bitmap);
139*a68b6c25SAugustin Cavalier
140*a68b6c25SAugustin Cavalier void ForwardMessage(BMessage* message = NULL);
141*a68b6c25SAugustin Cavalier
142*a68b6c25SAugustin Cavalier private:
143*a68b6c25SAugustin Cavalier port_id fInputPort;
144*a68b6c25SAugustin Cavalier const BBitmap* fBitmap;
145*a68b6c25SAugustin Cavalier };
146*a68b6c25SAugustin Cavalier
147*a68b6c25SAugustin Cavalier class CardWindow : public BWindow {
148*a68b6c25SAugustin Cavalier public:
149*a68b6c25SAugustin Cavalier CardWindow(BRect frame);
150*a68b6c25SAugustin Cavalier virtual ~CardWindow();
151*a68b6c25SAugustin Cavalier
152*a68b6c25SAugustin Cavalier virtual void MessageReceived(BMessage* message);
153*a68b6c25SAugustin Cavalier virtual bool QuitRequested();
154*a68b6c25SAugustin Cavalier
155*a68b6c25SAugustin Cavalier // CardWindow
156*a68b6c25SAugustin Cavalier void SetBitmap(const BBitmap* bitmap);
157*a68b6c25SAugustin Cavalier void Invalidate(const BRect& area);
158*a68b6c25SAugustin Cavalier
159*a68b6c25SAugustin Cavalier private:
160*a68b6c25SAugustin Cavalier CardView* fView;
161*a68b6c25SAugustin Cavalier BRegion fUpdateRegion;
162*a68b6c25SAugustin Cavalier BLocker fUpdateLock;
163*a68b6c25SAugustin Cavalier };
164*a68b6c25SAugustin Cavalier
165*a68b6c25SAugustin Cavalier class CardMessageFilter : public BMessageFilter {
166*a68b6c25SAugustin Cavalier public:
167*a68b6c25SAugustin Cavalier CardMessageFilter(CardView* view);
168*a68b6c25SAugustin Cavalier
169*a68b6c25SAugustin Cavalier virtual filter_result Filter(BMessage* message, BHandler** _target);
170*a68b6c25SAugustin Cavalier
171*a68b6c25SAugustin Cavalier private:
172*a68b6c25SAugustin Cavalier CardView* fView;
173*a68b6c25SAugustin Cavalier };
174*a68b6c25SAugustin Cavalier
175*a68b6c25SAugustin Cavalier
176*a68b6c25SAugustin Cavalier // #pragma mark -
177*a68b6c25SAugustin Cavalier
178*a68b6c25SAugustin Cavalier
CardView(BRect bounds)179*a68b6c25SAugustin Cavalier CardView::CardView(BRect bounds)
180*a68b6c25SAugustin Cavalier :
181*a68b6c25SAugustin Cavalier BView(bounds, "graphics card view", B_FOLLOW_ALL, B_WILL_DRAW),
182*a68b6c25SAugustin Cavalier fBitmap(NULL)
183*a68b6c25SAugustin Cavalier {
184*a68b6c25SAugustin Cavalier SetViewColor(B_TRANSPARENT_32_BIT);
185*a68b6c25SAugustin Cavalier
186*a68b6c25SAugustin Cavalier #ifndef INPUTSERVER_TEST_MODE
187*a68b6c25SAugustin Cavalier fInputPort = create_port(200, SERVER_INPUT_PORT);
188*a68b6c25SAugustin Cavalier #else
189*a68b6c25SAugustin Cavalier fInputPort = create_port(100, "ViewInputDevice");
190*a68b6c25SAugustin Cavalier #endif
191*a68b6c25SAugustin Cavalier
192*a68b6c25SAugustin Cavalier #ifdef ENABLE_INPUT_SERVER_EMULATION
193*a68b6c25SAugustin Cavalier AddFilter(new CardMessageFilter(this));
194*a68b6c25SAugustin Cavalier #endif
195*a68b6c25SAugustin Cavalier }
196*a68b6c25SAugustin Cavalier
197*a68b6c25SAugustin Cavalier
~CardView()198*a68b6c25SAugustin Cavalier CardView::~CardView()
199*a68b6c25SAugustin Cavalier {
200*a68b6c25SAugustin Cavalier }
201*a68b6c25SAugustin Cavalier
202*a68b6c25SAugustin Cavalier
203*a68b6c25SAugustin Cavalier void
AttachedToWindow()204*a68b6c25SAugustin Cavalier CardView::AttachedToWindow()
205*a68b6c25SAugustin Cavalier {
206*a68b6c25SAugustin Cavalier }
207*a68b6c25SAugustin Cavalier
208*a68b6c25SAugustin Cavalier
209*a68b6c25SAugustin Cavalier void
Draw(BRect updateRect)210*a68b6c25SAugustin Cavalier CardView::Draw(BRect updateRect)
211*a68b6c25SAugustin Cavalier {
212*a68b6c25SAugustin Cavalier if (fBitmap != NULL)
213*a68b6c25SAugustin Cavalier DrawBitmapAsync(fBitmap, updateRect, updateRect);
214*a68b6c25SAugustin Cavalier }
215*a68b6c25SAugustin Cavalier
216*a68b6c25SAugustin Cavalier
217*a68b6c25SAugustin Cavalier /*! These functions emulate the Input Server by sending the *exact* same kind of
218*a68b6c25SAugustin Cavalier messages to the server's port. Being we're using a regular window, it would
219*a68b6c25SAugustin Cavalier make little sense to do anything else.
220*a68b6c25SAugustin Cavalier */
221*a68b6c25SAugustin Cavalier void
ForwardMessage(BMessage * message)222*a68b6c25SAugustin Cavalier CardView::ForwardMessage(BMessage* message)
223*a68b6c25SAugustin Cavalier {
224*a68b6c25SAugustin Cavalier if (message == NULL)
225*a68b6c25SAugustin Cavalier message = Window()->CurrentMessage();
226*a68b6c25SAugustin Cavalier if (message == NULL)
227*a68b6c25SAugustin Cavalier return;
228*a68b6c25SAugustin Cavalier
229*a68b6c25SAugustin Cavalier // remove some fields that potentially mess up our own message processing
230*a68b6c25SAugustin Cavalier BMessage copy = *message;
231*a68b6c25SAugustin Cavalier copy.RemoveName("screen_where");
232*a68b6c25SAugustin Cavalier copy.RemoveName("be:transit");
233*a68b6c25SAugustin Cavalier copy.RemoveName("be:view_where");
234*a68b6c25SAugustin Cavalier copy.RemoveName("be:cursor_needed");
235*a68b6c25SAugustin Cavalier copy.RemoveName("_view_token");
236*a68b6c25SAugustin Cavalier
237*a68b6c25SAugustin Cavalier size_t length = copy.FlattenedSize();
238*a68b6c25SAugustin Cavalier char stream[length];
239*a68b6c25SAugustin Cavalier
240*a68b6c25SAugustin Cavalier if (copy.Flatten(stream, length) == B_OK)
241*a68b6c25SAugustin Cavalier write_port(fInputPort, 0, stream, length);
242*a68b6c25SAugustin Cavalier }
243*a68b6c25SAugustin Cavalier
244*a68b6c25SAugustin Cavalier
245*a68b6c25SAugustin Cavalier void
MessageReceived(BMessage * message)246*a68b6c25SAugustin Cavalier CardView::MessageReceived(BMessage* message)
247*a68b6c25SAugustin Cavalier {
248*a68b6c25SAugustin Cavalier switch (message->what) {
249*a68b6c25SAugustin Cavalier default:
250*a68b6c25SAugustin Cavalier BView::MessageReceived(message);
251*a68b6c25SAugustin Cavalier break;
252*a68b6c25SAugustin Cavalier }
253*a68b6c25SAugustin Cavalier }
254*a68b6c25SAugustin Cavalier
255*a68b6c25SAugustin Cavalier
256*a68b6c25SAugustin Cavalier void
SetBitmap(const BBitmap * bitmap)257*a68b6c25SAugustin Cavalier CardView::SetBitmap(const BBitmap* bitmap)
258*a68b6c25SAugustin Cavalier {
259*a68b6c25SAugustin Cavalier if (bitmap != fBitmap) {
260*a68b6c25SAugustin Cavalier fBitmap = bitmap;
261*a68b6c25SAugustin Cavalier
262*a68b6c25SAugustin Cavalier if (Parent())
263*a68b6c25SAugustin Cavalier Invalidate();
264*a68b6c25SAugustin Cavalier }
265*a68b6c25SAugustin Cavalier }
266*a68b6c25SAugustin Cavalier
267*a68b6c25SAugustin Cavalier
268*a68b6c25SAugustin Cavalier // #pragma mark -
269*a68b6c25SAugustin Cavalier
270*a68b6c25SAugustin Cavalier
CardMessageFilter(CardView * view)271*a68b6c25SAugustin Cavalier CardMessageFilter::CardMessageFilter(CardView* view)
272*a68b6c25SAugustin Cavalier :
273*a68b6c25SAugustin Cavalier BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
274*a68b6c25SAugustin Cavalier fView(view)
275*a68b6c25SAugustin Cavalier {
276*a68b6c25SAugustin Cavalier }
277*a68b6c25SAugustin Cavalier
278*a68b6c25SAugustin Cavalier
279*a68b6c25SAugustin Cavalier filter_result
Filter(BMessage * message,BHandler ** target)280*a68b6c25SAugustin Cavalier CardMessageFilter::Filter(BMessage* message, BHandler** target)
281*a68b6c25SAugustin Cavalier {
282*a68b6c25SAugustin Cavalier switch (message->what) {
283*a68b6c25SAugustin Cavalier case B_KEY_DOWN:
284*a68b6c25SAugustin Cavalier case B_UNMAPPED_KEY_DOWN:
285*a68b6c25SAugustin Cavalier case B_KEY_UP:
286*a68b6c25SAugustin Cavalier case B_UNMAPPED_KEY_UP:
287*a68b6c25SAugustin Cavalier case B_MOUSE_DOWN:
288*a68b6c25SAugustin Cavalier case B_MOUSE_UP:
289*a68b6c25SAugustin Cavalier case B_MOUSE_WHEEL_CHANGED:
290*a68b6c25SAugustin Cavalier if (message->what == B_MOUSE_DOWN)
291*a68b6c25SAugustin Cavalier fView->SetMouseEventMask(B_POINTER_EVENTS);
292*a68b6c25SAugustin Cavalier
293*a68b6c25SAugustin Cavalier fView->ForwardMessage(message);
294*a68b6c25SAugustin Cavalier return B_SKIP_MESSAGE;
295*a68b6c25SAugustin Cavalier
296*a68b6c25SAugustin Cavalier case B_MOUSE_MOVED:
297*a68b6c25SAugustin Cavalier {
298*a68b6c25SAugustin Cavalier int32 transit;
299*a68b6c25SAugustin Cavalier if (message->FindInt32("be:transit", &transit) == B_OK
300*a68b6c25SAugustin Cavalier && transit == B_ENTERED_VIEW) {
301*a68b6c25SAugustin Cavalier // A bug in R5 prevents this call from having an effect if
302*a68b6c25SAugustin Cavalier // called elsewhere, and calling it here works, if we're lucky :-)
303*a68b6c25SAugustin Cavalier BCursor cursor(kEmptyCursor);
304*a68b6c25SAugustin Cavalier fView->SetViewCursor(&cursor, true);
305*a68b6c25SAugustin Cavalier }
306*a68b6c25SAugustin Cavalier fView->ForwardMessage(message);
307*a68b6c25SAugustin Cavalier return B_SKIP_MESSAGE;
308*a68b6c25SAugustin Cavalier }
309*a68b6c25SAugustin Cavalier }
310*a68b6c25SAugustin Cavalier
311*a68b6c25SAugustin Cavalier return B_DISPATCH_MESSAGE;
312*a68b6c25SAugustin Cavalier }
313*a68b6c25SAugustin Cavalier
314*a68b6c25SAugustin Cavalier
315*a68b6c25SAugustin Cavalier // #pragma mark -
316*a68b6c25SAugustin Cavalier
317*a68b6c25SAugustin Cavalier
CardWindow(BRect frame)318*a68b6c25SAugustin Cavalier CardWindow::CardWindow(BRect frame)
319*a68b6c25SAugustin Cavalier :
320*a68b6c25SAugustin Cavalier BWindow(frame, "Haiku App Server", B_TITLED_WINDOW,
321*a68b6c25SAugustin Cavalier B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NO_SERVER_SIDE_WINDOW_MODIFIERS),
322*a68b6c25SAugustin Cavalier fUpdateRegion(),
323*a68b6c25SAugustin Cavalier fUpdateLock("update lock")
324*a68b6c25SAugustin Cavalier {
325*a68b6c25SAugustin Cavalier fView = new CardView(Bounds());
326*a68b6c25SAugustin Cavalier AddChild(fView);
327*a68b6c25SAugustin Cavalier fView->MakeFocus();
328*a68b6c25SAugustin Cavalier // make it receive key events
329*a68b6c25SAugustin Cavalier }
330*a68b6c25SAugustin Cavalier
331*a68b6c25SAugustin Cavalier
~CardWindow()332*a68b6c25SAugustin Cavalier CardWindow::~CardWindow()
333*a68b6c25SAugustin Cavalier {
334*a68b6c25SAugustin Cavalier }
335*a68b6c25SAugustin Cavalier
336*a68b6c25SAugustin Cavalier
337*a68b6c25SAugustin Cavalier void
MessageReceived(BMessage * msg)338*a68b6c25SAugustin Cavalier CardWindow::MessageReceived(BMessage* msg)
339*a68b6c25SAugustin Cavalier {
340*a68b6c25SAugustin Cavalier STRACE("CardWindow::MessageReceived()\n");
341*a68b6c25SAugustin Cavalier switch (msg->what) {
342*a68b6c25SAugustin Cavalier case MSG_UPDATE:
343*a68b6c25SAugustin Cavalier STRACE("MSG_UPDATE\n");
344*a68b6c25SAugustin Cavalier // invalidate all areas in the view that need redrawing
345*a68b6c25SAugustin Cavalier if (fUpdateLock.LockWithTimeout(2000LL) >= B_OK) {
346*a68b6c25SAugustin Cavalier /* int32 count = fUpdateRegion.CountRects();
347*a68b6c25SAugustin Cavalier for (int32 i = 0; i < count; i++) {
348*a68b6c25SAugustin Cavalier fView->Invalidate(fUpdateRegion.RectAt(i));
349*a68b6c25SAugustin Cavalier }*/
350*a68b6c25SAugustin Cavalier BRect frame = fUpdateRegion.Frame();
351*a68b6c25SAugustin Cavalier if (frame.IsValid()) {
352*a68b6c25SAugustin Cavalier fView->Invalidate(frame);
353*a68b6c25SAugustin Cavalier // fView->Invalidate();
354*a68b6c25SAugustin Cavalier }
355*a68b6c25SAugustin Cavalier fUpdateRegion.MakeEmpty();
356*a68b6c25SAugustin Cavalier fUpdateLock.Unlock();
357*a68b6c25SAugustin Cavalier } else {
358*a68b6c25SAugustin Cavalier // see you next time
359*a68b6c25SAugustin Cavalier }
360*a68b6c25SAugustin Cavalier break;
361*a68b6c25SAugustin Cavalier default:
362*a68b6c25SAugustin Cavalier BWindow::MessageReceived(msg);
363*a68b6c25SAugustin Cavalier break;
364*a68b6c25SAugustin Cavalier }
365*a68b6c25SAugustin Cavalier STRACE("CardWindow::MessageReceived() - exit\n");
366*a68b6c25SAugustin Cavalier }
367*a68b6c25SAugustin Cavalier
368*a68b6c25SAugustin Cavalier
369*a68b6c25SAugustin Cavalier bool
QuitRequested()370*a68b6c25SAugustin Cavalier CardWindow::QuitRequested()
371*a68b6c25SAugustin Cavalier {
372*a68b6c25SAugustin Cavalier port_id serverport = find_port(SERVER_PORT_NAME);
373*a68b6c25SAugustin Cavalier
374*a68b6c25SAugustin Cavalier if (serverport >= 0) {
375*a68b6c25SAugustin Cavalier BPrivate::PortLink link(serverport);
376*a68b6c25SAugustin Cavalier link.StartMessage(B_QUIT_REQUESTED);
377*a68b6c25SAugustin Cavalier link.Flush();
378*a68b6c25SAugustin Cavalier } else
379*a68b6c25SAugustin Cavalier printf("ERROR: couldn't find the app_server's main port!");
380*a68b6c25SAugustin Cavalier
381*a68b6c25SAugustin Cavalier // we don't quit on ourself, we let us be Quit()!
382*a68b6c25SAugustin Cavalier return false;
383*a68b6c25SAugustin Cavalier }
384*a68b6c25SAugustin Cavalier
385*a68b6c25SAugustin Cavalier
386*a68b6c25SAugustin Cavalier void
SetBitmap(const BBitmap * bitmap)387*a68b6c25SAugustin Cavalier CardWindow::SetBitmap(const BBitmap* bitmap)
388*a68b6c25SAugustin Cavalier {
389*a68b6c25SAugustin Cavalier fView->SetBitmap(bitmap);
390*a68b6c25SAugustin Cavalier }
391*a68b6c25SAugustin Cavalier
392*a68b6c25SAugustin Cavalier
393*a68b6c25SAugustin Cavalier void
Invalidate(const BRect & frame)394*a68b6c25SAugustin Cavalier CardWindow::Invalidate(const BRect& frame)
395*a68b6c25SAugustin Cavalier {
396*a68b6c25SAugustin Cavalier if (LockWithTimeout(1000000) >= B_OK) {
397*a68b6c25SAugustin Cavalier fView->Invalidate(frame);
398*a68b6c25SAugustin Cavalier Unlock();
399*a68b6c25SAugustin Cavalier }
400*a68b6c25SAugustin Cavalier }
401*a68b6c25SAugustin Cavalier
402*a68b6c25SAugustin Cavalier
403*a68b6c25SAugustin Cavalier // #pragma mark -
404*a68b6c25SAugustin Cavalier
405*a68b6c25SAugustin Cavalier
ViewHWInterface()406*a68b6c25SAugustin Cavalier ViewHWInterface::ViewHWInterface()
407*a68b6c25SAugustin Cavalier :
408*a68b6c25SAugustin Cavalier HWInterface(),
409*a68b6c25SAugustin Cavalier fBackBuffer(NULL),
410*a68b6c25SAugustin Cavalier fFrontBuffer(NULL),
411*a68b6c25SAugustin Cavalier fWindow(NULL)
412*a68b6c25SAugustin Cavalier {
413*a68b6c25SAugustin Cavalier SetAsyncDoubleBuffered(kDefaultDoubleBuffered);
414*a68b6c25SAugustin Cavalier
415*a68b6c25SAugustin Cavalier fDisplayMode.virtual_width = 640;
416*a68b6c25SAugustin Cavalier fDisplayMode.virtual_height = 480;
417*a68b6c25SAugustin Cavalier fDisplayMode.space = B_RGBA32;
418*a68b6c25SAugustin Cavalier }
419*a68b6c25SAugustin Cavalier
420*a68b6c25SAugustin Cavalier
~ViewHWInterface()421*a68b6c25SAugustin Cavalier ViewHWInterface::~ViewHWInterface()
422*a68b6c25SAugustin Cavalier {
423*a68b6c25SAugustin Cavalier if (fWindow) {
424*a68b6c25SAugustin Cavalier fWindow->Lock();
425*a68b6c25SAugustin Cavalier fWindow->Quit();
426*a68b6c25SAugustin Cavalier }
427*a68b6c25SAugustin Cavalier
428*a68b6c25SAugustin Cavalier be_app->Lock();
429*a68b6c25SAugustin Cavalier be_app->Quit();
430*a68b6c25SAugustin Cavalier }
431*a68b6c25SAugustin Cavalier
432*a68b6c25SAugustin Cavalier
433*a68b6c25SAugustin Cavalier status_t
Initialize()434*a68b6c25SAugustin Cavalier ViewHWInterface::Initialize()
435*a68b6c25SAugustin Cavalier {
436*a68b6c25SAugustin Cavalier return B_OK;
437*a68b6c25SAugustin Cavalier }
438*a68b6c25SAugustin Cavalier
439*a68b6c25SAugustin Cavalier
440*a68b6c25SAugustin Cavalier status_t
Shutdown()441*a68b6c25SAugustin Cavalier ViewHWInterface::Shutdown()
442*a68b6c25SAugustin Cavalier {
443*a68b6c25SAugustin Cavalier return B_OK;
444*a68b6c25SAugustin Cavalier }
445*a68b6c25SAugustin Cavalier
446*a68b6c25SAugustin Cavalier
447*a68b6c25SAugustin Cavalier status_t
SetMode(const display_mode & mode)448*a68b6c25SAugustin Cavalier ViewHWInterface::SetMode(const display_mode& mode)
449*a68b6c25SAugustin Cavalier {
450*a68b6c25SAugustin Cavalier AutoWriteLocker _(this);
451*a68b6c25SAugustin Cavalier
452*a68b6c25SAugustin Cavalier status_t ret = B_OK;
453*a68b6c25SAugustin Cavalier // prevent from doing the unnecessary
454*a68b6c25SAugustin Cavalier if (fBackBuffer.IsSet() && fFrontBuffer.IsSet()
455*a68b6c25SAugustin Cavalier && fDisplayMode.virtual_width == mode.virtual_width
456*a68b6c25SAugustin Cavalier && fDisplayMode.virtual_height == mode.virtual_height
457*a68b6c25SAugustin Cavalier && fDisplayMode.space == mode.space)
458*a68b6c25SAugustin Cavalier return ret;
459*a68b6c25SAugustin Cavalier
460*a68b6c25SAugustin Cavalier // check if we support the mode
461*a68b6c25SAugustin Cavalier
462*a68b6c25SAugustin Cavalier display_mode* modes;
463*a68b6c25SAugustin Cavalier uint32 modeCount, i;
464*a68b6c25SAugustin Cavalier if (GetModeList(&modes, &modeCount) != B_OK)
465*a68b6c25SAugustin Cavalier return B_NO_MEMORY;
466*a68b6c25SAugustin Cavalier
467*a68b6c25SAugustin Cavalier for (i = 0; i < modeCount; i++) {
468*a68b6c25SAugustin Cavalier // we only care for the bare minimum
469*a68b6c25SAugustin Cavalier if (modes[i].virtual_width == mode.virtual_width
470*a68b6c25SAugustin Cavalier && modes[i].virtual_height == mode.virtual_height
471*a68b6c25SAugustin Cavalier && modes[i].space == mode.space) {
472*a68b6c25SAugustin Cavalier // take over settings
473*a68b6c25SAugustin Cavalier fDisplayMode = modes[i];
474*a68b6c25SAugustin Cavalier break;
475*a68b6c25SAugustin Cavalier }
476*a68b6c25SAugustin Cavalier }
477*a68b6c25SAugustin Cavalier
478*a68b6c25SAugustin Cavalier delete[] modes;
479*a68b6c25SAugustin Cavalier
480*a68b6c25SAugustin Cavalier if (i == modeCount)
481*a68b6c25SAugustin Cavalier return B_BAD_VALUE;
482*a68b6c25SAugustin Cavalier
483*a68b6c25SAugustin Cavalier BRect frame(0.0, 0.0, fDisplayMode.virtual_width - 1,
484*a68b6c25SAugustin Cavalier fDisplayMode.virtual_height - 1);
485*a68b6c25SAugustin Cavalier
486*a68b6c25SAugustin Cavalier // create the window if we don't have one already
487*a68b6c25SAugustin Cavalier if (!fWindow) {
488*a68b6c25SAugustin Cavalier // if the window has not been created yet, the BApplication
489*a68b6c25SAugustin Cavalier // has not been created either, but we need one to display
490*a68b6c25SAugustin Cavalier // a real BWindow in the test environment.
491*a68b6c25SAugustin Cavalier // be_app->Run() needs to be called in another thread
492*a68b6c25SAugustin Cavalier
493*a68b6c25SAugustin Cavalier if (be_app == NULL) {
494*a68b6c25SAugustin Cavalier BApplication* app = new BApplication(
495*a68b6c25SAugustin Cavalier "application/x-vnd.Haiku-test-app_server");
496*a68b6c25SAugustin Cavalier app->Unlock();
497*a68b6c25SAugustin Cavalier
498*a68b6c25SAugustin Cavalier thread_id appThread = spawn_thread(run_app_thread, "app thread",
499*a68b6c25SAugustin Cavalier B_NORMAL_PRIORITY, app);
500*a68b6c25SAugustin Cavalier if (appThread >= B_OK)
501*a68b6c25SAugustin Cavalier ret = resume_thread(appThread);
502*a68b6c25SAugustin Cavalier else
503*a68b6c25SAugustin Cavalier ret = appThread;
504*a68b6c25SAugustin Cavalier
505*a68b6c25SAugustin Cavalier if (ret < B_OK)
506*a68b6c25SAugustin Cavalier return ret;
507*a68b6c25SAugustin Cavalier }
508*a68b6c25SAugustin Cavalier
509*a68b6c25SAugustin Cavalier fWindow = new CardWindow(frame.OffsetToCopy(BPoint(50.0, 50.0)));
510*a68b6c25SAugustin Cavalier
511*a68b6c25SAugustin Cavalier // fire up the window thread but don't show it on screen yet
512*a68b6c25SAugustin Cavalier fWindow->Hide();
513*a68b6c25SAugustin Cavalier fWindow->Show();
514*a68b6c25SAugustin Cavalier }
515*a68b6c25SAugustin Cavalier
516*a68b6c25SAugustin Cavalier if (fWindow->Lock()) {
517*a68b6c25SAugustin Cavalier // just to be save
518*a68b6c25SAugustin Cavalier fWindow->SetBitmap(NULL);
519*a68b6c25SAugustin Cavalier
520*a68b6c25SAugustin Cavalier // free and reallocate the bitmaps while the window is locked,
521*a68b6c25SAugustin Cavalier // so that the view does not accidentally draw a freed bitmap
522*a68b6c25SAugustin Cavalier fBackBuffer.Unset();
523*a68b6c25SAugustin Cavalier fFrontBuffer.Unset();
524*a68b6c25SAugustin Cavalier
525*a68b6c25SAugustin Cavalier // NOTE: backbuffer is always B_RGBA32, this simplifies the
526*a68b6c25SAugustin Cavalier // drawing backend implementation tremendously for the time
527*a68b6c25SAugustin Cavalier // being. The color space conversion is handled in CopyBackToFront()
528*a68b6c25SAugustin Cavalier
529*a68b6c25SAugustin Cavalier // TODO: Above not true anymore for single buffered mode!!!
530*a68b6c25SAugustin Cavalier // -> fall back to double buffer for fDisplayMode.space != B_RGB32
531*a68b6c25SAugustin Cavalier // as intermediate solution...
532*a68b6c25SAugustin Cavalier bool doubleBuffered = true;
533*a68b6c25SAugustin Cavalier if ((color_space)fDisplayMode.space != B_RGB32
534*a68b6c25SAugustin Cavalier && (color_space)fDisplayMode.space != B_RGBA32)
535*a68b6c25SAugustin Cavalier doubleBuffered = true;
536*a68b6c25SAugustin Cavalier
537*a68b6c25SAugustin Cavalier BBitmap* frontBitmap
538*a68b6c25SAugustin Cavalier = new BBitmap(frame, 0, (color_space)fDisplayMode.space);
539*a68b6c25SAugustin Cavalier fFrontBuffer.SetTo(new BBitmapBuffer(frontBitmap));
540*a68b6c25SAugustin Cavalier
541*a68b6c25SAugustin Cavalier status_t err = fFrontBuffer->InitCheck();
542*a68b6c25SAugustin Cavalier if (err < B_OK) {
543*a68b6c25SAugustin Cavalier fFrontBuffer.Unset();
544*a68b6c25SAugustin Cavalier ret = err;
545*a68b6c25SAugustin Cavalier }
546*a68b6c25SAugustin Cavalier
547*a68b6c25SAugustin Cavalier if (err >= B_OK && doubleBuffered) {
548*a68b6c25SAugustin Cavalier // backbuffer is always B_RGBA32
549*a68b6c25SAugustin Cavalier // since we override IsDoubleBuffered(), the drawing buffer
550*a68b6c25SAugustin Cavalier // is in effect also always B_RGBA32.
551*a68b6c25SAugustin Cavalier BBitmap* backBitmap = new BBitmap(frame, 0, B_RGBA32);
552*a68b6c25SAugustin Cavalier fBackBuffer.SetTo(new BBitmapBuffer(backBitmap));
553*a68b6c25SAugustin Cavalier
554*a68b6c25SAugustin Cavalier err = fBackBuffer->InitCheck();
555*a68b6c25SAugustin Cavalier if (err < B_OK) {
556*a68b6c25SAugustin Cavalier fBackBuffer.Unset();
557*a68b6c25SAugustin Cavalier ret = err;
558*a68b6c25SAugustin Cavalier }
559*a68b6c25SAugustin Cavalier }
560*a68b6c25SAugustin Cavalier
561*a68b6c25SAugustin Cavalier _NotifyFrameBufferChanged();
562*a68b6c25SAugustin Cavalier
563*a68b6c25SAugustin Cavalier if (ret >= B_OK) {
564*a68b6c25SAugustin Cavalier // clear out buffers, alpha is 255 this way
565*a68b6c25SAugustin Cavalier // TODO: maybe this should handle different color spaces in different ways
566*a68b6c25SAugustin Cavalier if (fBackBuffer.IsSet())
567*a68b6c25SAugustin Cavalier memset(fBackBuffer->Bits(), 255, fBackBuffer->BitsLength());
568*a68b6c25SAugustin Cavalier memset(fFrontBuffer->Bits(), 255, fFrontBuffer->BitsLength());
569*a68b6c25SAugustin Cavalier
570*a68b6c25SAugustin Cavalier // change the window size and update the bitmap used for drawing
571*a68b6c25SAugustin Cavalier fWindow->ResizeTo(frame.Width(), frame.Height());
572*a68b6c25SAugustin Cavalier fWindow->SetBitmap(fFrontBuffer->Bitmap());
573*a68b6c25SAugustin Cavalier }
574*a68b6c25SAugustin Cavalier
575*a68b6c25SAugustin Cavalier // window is hidden when this function is called the first time
576*a68b6c25SAugustin Cavalier if (fWindow->IsHidden())
577*a68b6c25SAugustin Cavalier fWindow->Show();
578*a68b6c25SAugustin Cavalier
579*a68b6c25SAugustin Cavalier fWindow->Unlock();
580*a68b6c25SAugustin Cavalier } else {
581*a68b6c25SAugustin Cavalier ret = B_ERROR;
582*a68b6c25SAugustin Cavalier }
583*a68b6c25SAugustin Cavalier return ret;
584*a68b6c25SAugustin Cavalier }
585*a68b6c25SAugustin Cavalier
586*a68b6c25SAugustin Cavalier
587*a68b6c25SAugustin Cavalier void
GetMode(display_mode * mode)588*a68b6c25SAugustin Cavalier ViewHWInterface::GetMode(display_mode* mode)
589*a68b6c25SAugustin Cavalier {
590*a68b6c25SAugustin Cavalier if (mode && ReadLock()) {
591*a68b6c25SAugustin Cavalier *mode = fDisplayMode;
592*a68b6c25SAugustin Cavalier ReadUnlock();
593*a68b6c25SAugustin Cavalier }
594*a68b6c25SAugustin Cavalier }
595*a68b6c25SAugustin Cavalier
596*a68b6c25SAugustin Cavalier
597*a68b6c25SAugustin Cavalier status_t
GetDeviceInfo(accelerant_device_info * info)598*a68b6c25SAugustin Cavalier ViewHWInterface::GetDeviceInfo(accelerant_device_info* info)
599*a68b6c25SAugustin Cavalier {
600*a68b6c25SAugustin Cavalier // We really don't have to provide anything here because this is strictly
601*a68b6c25SAugustin Cavalier // a software-only driver, but we'll have some fun, anyway.
602*a68b6c25SAugustin Cavalier if (ReadLock()) {
603*a68b6c25SAugustin Cavalier info->version = 100;
604*a68b6c25SAugustin Cavalier sprintf(info->name, "Haiku, Inc. ViewHWInterface");
605*a68b6c25SAugustin Cavalier sprintf(info->chipset, "Haiku, Inc. Chipset");
606*a68b6c25SAugustin Cavalier sprintf(info->serial_no, "3.14159265358979323846");
607*a68b6c25SAugustin Cavalier info->memory = 134217728; // 128 MB, not that we really have that much. :)
608*a68b6c25SAugustin Cavalier info->dac_speed = 0xFFFFFFFF; // *heh*
609*a68b6c25SAugustin Cavalier
610*a68b6c25SAugustin Cavalier ReadUnlock();
611*a68b6c25SAugustin Cavalier }
612*a68b6c25SAugustin Cavalier
613*a68b6c25SAugustin Cavalier return B_OK;
614*a68b6c25SAugustin Cavalier }
615*a68b6c25SAugustin Cavalier
616*a68b6c25SAugustin Cavalier
617*a68b6c25SAugustin Cavalier status_t
GetFrameBufferConfig(frame_buffer_config & config)618*a68b6c25SAugustin Cavalier ViewHWInterface::GetFrameBufferConfig(frame_buffer_config& config)
619*a68b6c25SAugustin Cavalier {
620*a68b6c25SAugustin Cavalier if (!fFrontBuffer.IsSet())
621*a68b6c25SAugustin Cavalier return B_ERROR;
622*a68b6c25SAugustin Cavalier
623*a68b6c25SAugustin Cavalier config.frame_buffer = fFrontBuffer->Bits();
624*a68b6c25SAugustin Cavalier config.frame_buffer_dma = NULL;
625*a68b6c25SAugustin Cavalier config.bytes_per_row = fFrontBuffer->BytesPerRow();
626*a68b6c25SAugustin Cavalier
627*a68b6c25SAugustin Cavalier return B_OK;
628*a68b6c25SAugustin Cavalier }
629*a68b6c25SAugustin Cavalier
630*a68b6c25SAugustin Cavalier
631*a68b6c25SAugustin Cavalier status_t
GetModeList(display_mode ** _modes,uint32 * _count)632*a68b6c25SAugustin Cavalier ViewHWInterface::GetModeList(display_mode** _modes, uint32* _count)
633*a68b6c25SAugustin Cavalier {
634*a68b6c25SAugustin Cavalier AutoReadLocker _(this);
635*a68b6c25SAugustin Cavalier
636*a68b6c25SAugustin Cavalier #if 1
637*a68b6c25SAugustin Cavalier // setup a whole bunch of different modes
638*a68b6c25SAugustin Cavalier const struct resolution { int32 width, height; } resolutions[] = {
639*a68b6c25SAugustin Cavalier {640, 480}, {800, 600}, {1024, 768}, {1152, 864}, {1280, 960},
640*a68b6c25SAugustin Cavalier {1280, 1024}, {1400, 1050}, {1600, 1200}
641*a68b6c25SAugustin Cavalier };
642*a68b6c25SAugustin Cavalier uint32 resolutionCount = sizeof(resolutions) / sizeof(resolutions[0]);
643*a68b6c25SAugustin Cavalier const uint32 colors[] = {B_CMAP8, B_RGB15, B_RGB16, B_RGB32};
644*a68b6c25SAugustin Cavalier uint32 count = resolutionCount * 4;
645*a68b6c25SAugustin Cavalier
646*a68b6c25SAugustin Cavalier display_mode* modes = new(std::nothrow) display_mode[count];
647*a68b6c25SAugustin Cavalier if (modes == NULL)
648*a68b6c25SAugustin Cavalier return B_NO_MEMORY;
649*a68b6c25SAugustin Cavalier
650*a68b6c25SAugustin Cavalier *_modes = modes;
651*a68b6c25SAugustin Cavalier *_count = count;
652*a68b6c25SAugustin Cavalier
653*a68b6c25SAugustin Cavalier int32 index = 0;
654*a68b6c25SAugustin Cavalier for (uint32 i = 0; i < resolutionCount; i++) {
655*a68b6c25SAugustin Cavalier for (uint32 c = 0; c < 4; c++) {
656*a68b6c25SAugustin Cavalier modes[index].virtual_width = resolutions[i].width;
657*a68b6c25SAugustin Cavalier modes[index].virtual_height = resolutions[i].height;
658*a68b6c25SAugustin Cavalier modes[index].space = colors[c];
659*a68b6c25SAugustin Cavalier
660*a68b6c25SAugustin Cavalier modes[index].h_display_start = 0;
661*a68b6c25SAugustin Cavalier modes[index].v_display_start = 0;
662*a68b6c25SAugustin Cavalier modes[index].timing.h_display = resolutions[i].width;
663*a68b6c25SAugustin Cavalier modes[index].timing.v_display = resolutions[i].height;
664*a68b6c25SAugustin Cavalier modes[index].timing.h_total = 22000;
665*a68b6c25SAugustin Cavalier modes[index].timing.v_total = 22000;
666*a68b6c25SAugustin Cavalier modes[index].timing.pixel_clock = ((uint32)modes[index].timing.h_total
667*a68b6c25SAugustin Cavalier * modes[index].timing.v_total * 60) / 1000;
668*a68b6c25SAugustin Cavalier modes[index].flags = B_PARALLEL_ACCESS;
669*a68b6c25SAugustin Cavalier
670*a68b6c25SAugustin Cavalier index++;
671*a68b6c25SAugustin Cavalier }
672*a68b6c25SAugustin Cavalier }
673*a68b6c25SAugustin Cavalier #else
674*a68b6c25SAugustin Cavalier // support only a single mode, useful
675*a68b6c25SAugustin Cavalier // for testing a specific mode
676*a68b6c25SAugustin Cavalier display_mode *modes = new(nothrow) display_mode[1];
677*a68b6c25SAugustin Cavalier modes[0].virtual_width = 640;
678*a68b6c25SAugustin Cavalier modes[0].virtual_height = 480;
679*a68b6c25SAugustin Cavalier modes[0].space = B_CMAP8;
680*a68b6c25SAugustin Cavalier
681*a68b6c25SAugustin Cavalier *_modes = modes;
682*a68b6c25SAugustin Cavalier *_count = 1;
683*a68b6c25SAugustin Cavalier #endif
684*a68b6c25SAugustin Cavalier
685*a68b6c25SAugustin Cavalier return B_OK;
686*a68b6c25SAugustin Cavalier }
687*a68b6c25SAugustin Cavalier
688*a68b6c25SAugustin Cavalier
689*a68b6c25SAugustin Cavalier status_t
GetPixelClockLimits(display_mode * mode,uint32 * low,uint32 * high)690*a68b6c25SAugustin Cavalier ViewHWInterface::GetPixelClockLimits(display_mode* mode, uint32* low,
691*a68b6c25SAugustin Cavalier uint32* high)
692*a68b6c25SAugustin Cavalier {
693*a68b6c25SAugustin Cavalier return B_ERROR;
694*a68b6c25SAugustin Cavalier }
695*a68b6c25SAugustin Cavalier
696*a68b6c25SAugustin Cavalier
697*a68b6c25SAugustin Cavalier status_t
GetTimingConstraints(display_timing_constraints * constraints)698*a68b6c25SAugustin Cavalier ViewHWInterface::GetTimingConstraints(display_timing_constraints* constraints)
699*a68b6c25SAugustin Cavalier {
700*a68b6c25SAugustin Cavalier return B_ERROR;
701*a68b6c25SAugustin Cavalier }
702*a68b6c25SAugustin Cavalier
703*a68b6c25SAugustin Cavalier
704*a68b6c25SAugustin Cavalier status_t
ProposeMode(display_mode * candidate,const display_mode * low,const display_mode * high)705*a68b6c25SAugustin Cavalier ViewHWInterface::ProposeMode(display_mode* candidate, const display_mode* low,
706*a68b6c25SAugustin Cavalier const display_mode* high)
707*a68b6c25SAugustin Cavalier {
708*a68b6c25SAugustin Cavalier // We should be able to get away with this because we're not dealing with
709*a68b6c25SAugustin Cavalier // any specific hardware. This is a Good Thing(TM) because we can support
710*a68b6c25SAugustin Cavalier // any hardware we wish within reasonable expectaions and programmer
711*a68b6c25SAugustin Cavalier // laziness. :P
712*a68b6c25SAugustin Cavalier return B_OK;
713*a68b6c25SAugustin Cavalier }
714*a68b6c25SAugustin Cavalier
715*a68b6c25SAugustin Cavalier
716*a68b6c25SAugustin Cavalier status_t
SetDPMSMode(uint32 state)717*a68b6c25SAugustin Cavalier ViewHWInterface::SetDPMSMode(uint32 state)
718*a68b6c25SAugustin Cavalier {
719*a68b6c25SAugustin Cavalier AutoWriteLocker _(this);
720*a68b6c25SAugustin Cavalier
721*a68b6c25SAugustin Cavalier return BScreen().SetDPMS(state);
722*a68b6c25SAugustin Cavalier }
723*a68b6c25SAugustin Cavalier
724*a68b6c25SAugustin Cavalier
725*a68b6c25SAugustin Cavalier uint32
DPMSMode()726*a68b6c25SAugustin Cavalier ViewHWInterface::DPMSMode()
727*a68b6c25SAugustin Cavalier {
728*a68b6c25SAugustin Cavalier AutoReadLocker _(this);
729*a68b6c25SAugustin Cavalier
730*a68b6c25SAugustin Cavalier return BScreen().DPMSState();
731*a68b6c25SAugustin Cavalier }
732*a68b6c25SAugustin Cavalier
733*a68b6c25SAugustin Cavalier
734*a68b6c25SAugustin Cavalier uint32
DPMSCapabilities()735*a68b6c25SAugustin Cavalier ViewHWInterface::DPMSCapabilities()
736*a68b6c25SAugustin Cavalier {
737*a68b6c25SAugustin Cavalier AutoReadLocker _(this);
738*a68b6c25SAugustin Cavalier
739*a68b6c25SAugustin Cavalier return BScreen().DPMSCapabilites();
740*a68b6c25SAugustin Cavalier }
741*a68b6c25SAugustin Cavalier
742*a68b6c25SAugustin Cavalier
743*a68b6c25SAugustin Cavalier status_t
SetBrightness(float brightness)744*a68b6c25SAugustin Cavalier ViewHWInterface::SetBrightness(float brightness)
745*a68b6c25SAugustin Cavalier {
746*a68b6c25SAugustin Cavalier AutoReadLocker _(this);
747*a68b6c25SAugustin Cavalier
748*a68b6c25SAugustin Cavalier return BScreen().SetBrightness(brightness);
749*a68b6c25SAugustin Cavalier }
750*a68b6c25SAugustin Cavalier
751*a68b6c25SAugustin Cavalier
752*a68b6c25SAugustin Cavalier status_t
GetBrightness(float * brightness)753*a68b6c25SAugustin Cavalier ViewHWInterface::GetBrightness(float* brightness)
754*a68b6c25SAugustin Cavalier {
755*a68b6c25SAugustin Cavalier AutoReadLocker _(this);
756*a68b6c25SAugustin Cavalier
757*a68b6c25SAugustin Cavalier return BScreen().GetBrightness(brightness);
758*a68b6c25SAugustin Cavalier }
759*a68b6c25SAugustin Cavalier
760*a68b6c25SAugustin Cavalier
761*a68b6c25SAugustin Cavalier sem_id
RetraceSemaphore()762*a68b6c25SAugustin Cavalier ViewHWInterface::RetraceSemaphore()
763*a68b6c25SAugustin Cavalier {
764*a68b6c25SAugustin Cavalier return -1;
765*a68b6c25SAugustin Cavalier }
766*a68b6c25SAugustin Cavalier
767*a68b6c25SAugustin Cavalier
768*a68b6c25SAugustin Cavalier status_t
WaitForRetrace(bigtime_t timeout)769*a68b6c25SAugustin Cavalier ViewHWInterface::WaitForRetrace(bigtime_t timeout)
770*a68b6c25SAugustin Cavalier {
771*a68b6c25SAugustin Cavalier // Locking shouldn't be necessary here - R5 should handle this for us. :)
772*a68b6c25SAugustin Cavalier BScreen screen;
773*a68b6c25SAugustin Cavalier return screen.WaitForRetrace(timeout);
774*a68b6c25SAugustin Cavalier }
775*a68b6c25SAugustin Cavalier
776*a68b6c25SAugustin Cavalier
777*a68b6c25SAugustin Cavalier RenderingBuffer*
FrontBuffer() const778*a68b6c25SAugustin Cavalier ViewHWInterface::FrontBuffer() const
779*a68b6c25SAugustin Cavalier {
780*a68b6c25SAugustin Cavalier return fFrontBuffer.Get();
781*a68b6c25SAugustin Cavalier }
782*a68b6c25SAugustin Cavalier
783*a68b6c25SAugustin Cavalier
784*a68b6c25SAugustin Cavalier RenderingBuffer*
BackBuffer() const785*a68b6c25SAugustin Cavalier ViewHWInterface::BackBuffer() const
786*a68b6c25SAugustin Cavalier {
787*a68b6c25SAugustin Cavalier return fBackBuffer.Get();
788*a68b6c25SAugustin Cavalier }
789*a68b6c25SAugustin Cavalier
790*a68b6c25SAugustin Cavalier
791*a68b6c25SAugustin Cavalier bool
IsDoubleBuffered() const792*a68b6c25SAugustin Cavalier ViewHWInterface::IsDoubleBuffered() const
793*a68b6c25SAugustin Cavalier {
794*a68b6c25SAugustin Cavalier if (fFrontBuffer.IsSet())
795*a68b6c25SAugustin Cavalier return fBackBuffer.IsSet();
796*a68b6c25SAugustin Cavalier
797*a68b6c25SAugustin Cavalier return false;
798*a68b6c25SAugustin Cavalier }
799*a68b6c25SAugustin Cavalier
800*a68b6c25SAugustin Cavalier
801*a68b6c25SAugustin Cavalier status_t
Invalidate(const BRect & frame)802*a68b6c25SAugustin Cavalier ViewHWInterface::Invalidate(const BRect& frame)
803*a68b6c25SAugustin Cavalier {
804*a68b6c25SAugustin Cavalier status_t ret = HWInterface::Invalidate(frame);
805*a68b6c25SAugustin Cavalier
806*a68b6c25SAugustin Cavalier if (ret >= B_OK && fWindow && !IsDoubleBuffered())
807*a68b6c25SAugustin Cavalier fWindow->Invalidate(frame);
808*a68b6c25SAugustin Cavalier return ret;
809*a68b6c25SAugustin Cavalier }
810*a68b6c25SAugustin Cavalier
811*a68b6c25SAugustin Cavalier
812*a68b6c25SAugustin Cavalier status_t
CopyBackToFront(const BRect & frame)813*a68b6c25SAugustin Cavalier ViewHWInterface::CopyBackToFront(const BRect& frame)
814*a68b6c25SAugustin Cavalier {
815*a68b6c25SAugustin Cavalier status_t ret = HWInterface::CopyBackToFront(frame);
816*a68b6c25SAugustin Cavalier
817*a68b6c25SAugustin Cavalier if (ret >= B_OK && fWindow)
818*a68b6c25SAugustin Cavalier fWindow->Invalidate(frame);
819*a68b6c25SAugustin Cavalier return ret;
820*a68b6c25SAugustin Cavalier }
821