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