xref: /haiku/src/servers/app/drawing/interface/remote/RemoteHWInterface.h (revision 8eafd6cd04e4d540cbad2ef07f9eb58a297a3b30)
1 /*
2  * Copyright 2009, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz <mmlr@mlotz.ch>
7  */
8 #ifndef REMOTE_HW_INTERFACE_H
9 #define REMOTE_HW_INTERFACE_H
10 
11 #include "HWInterface.h"
12 
13 #include <AutoDeleter.h>
14 #include <Locker.h>
15 #include <ObjectList.h>
16 
17 class BNetEndpoint;
18 class StreamingRingBuffer;
19 class NetSender;
20 class NetReceiver;
21 class RemoteEventStream;
22 class RemoteMessage;
23 
24 struct callback_info;
25 
26 
27 class RemoteHWInterface : public HWInterface {
28 public:
29 									RemoteHWInterface(const char* target);
30 virtual								~RemoteHWInterface();
31 
32 virtual	status_t					Initialize();
33 virtual	status_t					Shutdown();
34 
35 virtual	DrawingEngine*				CreateDrawingEngine();
36 virtual	EventStream*				CreateEventStream();
37 
38 virtual	status_t					SetMode(const display_mode& mode);
39 virtual	void						GetMode(display_mode* mode);
40 virtual	status_t					GetPreferredMode(display_mode* mode);
41 
42 virtual status_t					GetDeviceInfo(accelerant_device_info* info);
43 virtual status_t					GetFrameBufferConfig(
44 										frame_buffer_config& config);
45 
46 virtual status_t					GetModeList(display_mode** _modeList,
47 										uint32* _count);
48 virtual status_t					GetPixelClockLimits(display_mode* mode,
49 										uint32* _low, uint32* _high);
50 virtual status_t					GetTimingConstraints(
51 										display_timing_constraints* constraints);
52 virtual status_t					ProposeMode(display_mode* candidate,
53 										const display_mode* low,
54 										const display_mode* high);
55 
56 virtual sem_id						RetraceSemaphore();
57 virtual status_t					WaitForRetrace(
58 										bigtime_t timeout = B_INFINITE_TIMEOUT);
59 
60 virtual status_t					SetDPMSMode(uint32 state);
61 virtual uint32						DPMSMode();
62 virtual uint32						DPMSCapabilities();
63 
64 virtual status_t			SetBrightness(float);
65 virtual status_t			GetBrightness(float*);
66 
67 		// cursor handling
68 virtual	void						SetCursor(ServerCursor* cursor);
69 virtual	void						SetCursorVisible(bool visible);
70 virtual	void						MoveCursorTo(float x, float y);
71 virtual	void						SetDragBitmap(const ServerBitmap* bitmap,
72 										const BPoint& offsetFormCursor);
73 
74 		// frame buffer access
75 virtual	RenderingBuffer*			FrontBuffer() const;
76 virtual	RenderingBuffer*			BackBuffer() const;
77 virtual	bool						IsDoubleBuffered() const;
78 
79 virtual	status_t					InvalidateRegion(BRegion& region);
80 virtual	status_t					Invalidate(const BRect& frame);
81 virtual	status_t					CopyBackToFront(const BRect& frame);
82 
83 		// drawing engine interface
84 		StreamingRingBuffer*		ReceiveBuffer()
85 										{ return fReceiveBuffer.Get(); }
86 		StreamingRingBuffer*		SendBuffer() { return fSendBuffer.Get(); }
87 
88 typedef bool (*CallbackFunction)(void* cookie, RemoteMessage& message);
89 
90 		status_t					AddCallback(uint32 token,
91 										CallbackFunction callback,
92 										void* cookie);
93 		bool						RemoveCallback(uint32 token);
94 
95 private:
96 		callback_info*				_FindCallback(uint32 token);
97 static	int							_CallbackCompare(const uint32* key,
98 										const callback_info* info);
99 
100 static	int32						_EventThreadEntry(void* data);
101 		status_t					_EventThread();
102 
103 static	status_t					_NewConnectionCallback(void *cookie,
104 										BNetEndpoint &endpoint);
105 		status_t					_NewConnection(BNetEndpoint &endpoint);
106 
107 		void						_Disconnect();
108 
109 		void						_FillDisplayModeTiming(display_mode &mode);
110 
111 		const char*					fTarget;
112 		status_t					fInitStatus;
113 		bool						fIsConnected;
114 		uint32						fProtocolVersion;
115 		uint32						fConnectionSpeed;
116 		display_mode				fFallbackMode;
117 		display_mode				fCurrentMode;
118 		display_mode				fClientMode;
119 		uint16						fListenPort;
120 
121 		ObjectDeleter<BNetEndpoint>	fListenEndpoint;
122 		ObjectDeleter<StreamingRingBuffer>
123 									fSendBuffer;
124 		ObjectDeleter<StreamingRingBuffer>
125 									fReceiveBuffer;
126 
127 		ObjectDeleter<NetSender>	fSender;
128 		ObjectDeleter<NetReceiver>	fReceiver;
129 
130 		thread_id					fEventThread;
131 		ObjectDeleter<RemoteEventStream>
132 									fEventStream;
133 
134 		BLocker						fCallbackLocker;
135 		BObjectList<callback_info>	fCallbacks;
136 };
137 
138 #endif // REMOTE_HW_INTERFACE_H
139