xref: /haiku/src/servers/app/drawing/HWInterface.h (revision 0e50eab75e25d0d82090e22dbff766dfaa6f5e86)
1 /*
2  * Copyright 2005-2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 #ifndef HW_INTERFACE_H
9 #define HW_INTERFACE_H
10 
11 
12 #include "MultiLocker.h"
13 
14 #include <video_overlay.h>
15 
16 #include <Accelerant.h>
17 #include <GraphicsCard.h>
18 #include <OS.h>
19 #include <Region.h>
20 
21 
22 class Overlay;
23 class RenderingBuffer;
24 class RGBColor;
25 class ServerBitmap;
26 class ServerCursor;
27 class UpdateQueue;
28 class BString;
29 
30 enum {
31 	HW_ACC_COPY_REGION					= 0x00000001,
32 	HW_ACC_FILL_REGION					= 0x00000002,
33 	HW_ACC_INVERT_REGION				= 0x00000004,
34 };
35 
36 class HWInterface : public MultiLocker {
37  public:
38 								HWInterface(bool doubleBuffered = false);
39 	virtual						~HWInterface();
40 
41 	// You need to WriteLock
42 	virtual	status_t			Initialize();
43 	virtual	status_t			Shutdown() = 0;
44 
45 	// screen mode stuff
46 	virtual	status_t			SetMode(const display_mode &mode) = 0;
47 	virtual	void				GetMode(display_mode *mode) = 0;
48 
49 	virtual status_t			GetDeviceInfo(accelerant_device_info *info) = 0;
50 	virtual status_t			GetFrameBufferConfig(frame_buffer_config& config) = 0;
51 	virtual status_t			GetModeList(display_mode **mode_list,
52 											uint32 *count) = 0;
53 	virtual status_t			GetPixelClockLimits(display_mode *mode,
54 													uint32 *low,
55 													uint32 *high) = 0;
56 	virtual status_t			GetTimingConstraints(display_timing_constraints *dtc) = 0;
57 	virtual status_t			ProposeMode(display_mode *candidate,
58 											const display_mode *low,
59 											const display_mode *high) = 0;
60 
61 	virtual sem_id				RetraceSemaphore() = 0;
62 	virtual status_t			WaitForRetrace(bigtime_t timeout = B_INFINITE_TIMEOUT) = 0;
63 
64 	virtual status_t			SetDPMSMode(const uint32 &state) = 0;
65 	virtual uint32				DPMSMode() = 0;
66 	virtual uint32				DPMSCapabilities() = 0;
67 
68 	virtual status_t			GetAccelerantPath(BString &path);
69 	virtual status_t			GetDriverPath(BString &path);
70 
71 	// query for available hardware accleration and perform it
72 	// (Initialize() must have been called already)
73 	virtual	uint32				AvailableHWAcceleration() const
74 									{ return 0; }
75 
76 	virtual	void				CopyRegion(const clipping_rect* sortedRectList,
77 										   uint32 count,
78 										   int32 xOffset, int32 yOffset) {}
79 	virtual	void				FillRegion(/*const*/ BRegion& region,
80 										   const RGBColor& color,
81 										   bool autoSync) {}
82 	virtual	void				InvertRegion(/*const*/ BRegion& region) {}
83 
84 	virtual	void				Sync() {}
85 
86 	// cursor handling (these do their own Read/Write locking)
87 			ServerCursor*		Cursor() const { return fCursor; }
88 	virtual	void				SetCursor(ServerCursor* cursor);
89 	virtual	void				SetCursorVisible(bool visible);
90 			bool				IsCursorVisible();
91 	virtual	void				ObscureCursor();
92 	virtual	void				MoveCursorTo(const float& x,
93 											 const float& y);
94 			BPoint				GetCursorPosition();
95 
96 			void				SetDragBitmap(const ServerBitmap* bitmap,
97 											  const BPoint& offsetFromCursor);
98 
99 	// overlay support
100 	virtual overlay_token		AcquireOverlayChannel();
101 	virtual void				ReleaseOverlayChannel(overlay_token token);
102 
103 	virtual bool				CheckOverlayRestrictions(int32 width, int32 height,
104 									color_space colorSpace);
105 	virtual const overlay_buffer* AllocateOverlayBuffer(int32 width, int32 height,
106 									color_space space);
107 	virtual void				FreeOverlayBuffer(const overlay_buffer* buffer);
108 
109 	virtual void				ConfigureOverlay(Overlay* overlay);
110 	virtual void				HideOverlay(Overlay* overlay);
111 
112 	// frame buffer access (you need to ReadLock!)
113 			RenderingBuffer*	DrawingBuffer() const;
114 	virtual	RenderingBuffer*	FrontBuffer() const = 0;
115 	virtual	RenderingBuffer*	BackBuffer() const = 0;
116 	virtual	bool				IsDoubleBuffered() const;
117 
118 	// Invalidate is planned to be used for scheduling an area for updating
119 	// you need to WriteLock!
120 	virtual	status_t			Invalidate(const BRect& frame);
121 	// while as CopyBackToFront() actually performs the operation
122 			status_t			CopyBackToFront(const BRect& frame);
123 
124 	// TODO: Just a quick and primitive way to get single buffered mode working.
125 	// Later, the implementation should be smarter, right now, it will
126 	// draw the cursor for almost every drawing operation.
127 	// It seems to me BeOS hides the cursor (in laymans words) before
128 	// BView::Draw() is called (if the cursor is within that views clipping region),
129 	// then, after all drawing commands that triggered have been caried out,
130 	// it shows the cursor again. This approach would have the adventage of
131 	// the code not cluttering/slowing down DrawingEngine.
132 	// For now, we hide the cursor for any drawing operation that has
133 	// a bounding box containing the cursor (in DrawingEngine) so
134 	// the cursor hiding is completely transparent from code using DrawingEngine.
135 	// ---
136 	// NOTE: Investigate locking for these! The client code should already hold a
137 	// ReadLock, but maybe these functions should acquire a WriteLock!
138 			bool				HideSoftwareCursor(const BRect& area);
139 			void				HideSoftwareCursor();
140 			void				ShowSoftwareCursor();
141 
142  protected:
143 	// implement this in derived classes
144 	virtual	void				_DrawCursor(BRect area) const;
145 
146 	// does the actual transfer and handles color space conversion
147 			void				_CopyToFront(uint8* src, uint32 srcBPR,
148 											 int32 x, int32 y,
149 											 int32 right, int32 bottom) const;
150 
151 			BRect				_CursorFrame() const;
152 			void				_RestoreCursorArea() const;
153 			void				_AdoptDragBitmap(const ServerBitmap* bitmap,
154 												 const BPoint& offset);
155 
156 			// If we draw the cursor somewhere in the drawing buffer,
157 			// we need to backup its contents before drawing, so that
158 			// we can restore that area when the cursor needs to be
159 			// drawn somewhere else.
160 			struct buffer_clip {
161 								buffer_clip(int32 width, int32 height)
162 								{
163 									bpr = width * 4;
164 									if (bpr > 0 && height > 0)
165 										buffer = new uint8[bpr * height];
166 									else
167 										buffer = NULL;
168 									left = 0;
169 									top = 0;
170 									right = -1;
171 									bottom = -1;
172 									cursor_hidden = true;
173 								}
174 								~buffer_clip()
175 								{
176 									delete[] buffer;
177 								}
178 				uint8*			buffer;
179 				int32			left;
180 				int32			top;
181 				int32			right;
182 				int32			bottom;
183 				int32			bpr;
184 				bool			cursor_hidden;
185 			};
186 
187 			buffer_clip*		fCursorAreaBackup;
188 
189 			ServerCursor*		fCursor;
190 			const ServerBitmap*	fDragBitmap;
191 			BPoint				fDragBitmapOffset;
192 			ServerCursor*		fCursorAndDragBitmap;
193 			bool				fCursorVisible;
194 			bool				fCursorObscured;
195 			BPoint				fCursorLocation;
196 			bool				fDoubleBuffered;
197 
198  private:
199 			UpdateQueue*		fUpdateExecutor;
200 };
201 
202 #endif // HW_INTERFACE_H
203