xref: /haiku/src/servers/app/drawing/interface/local/AccelerantHWInterface.h (revision 1978089f7cec856677e46204e992c7273d70b9af)
1 /*
2  * Copyright 2005-2016, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  *		Axel Dörfler, axeld@pinc-software.de
8  *		Michael Lotz <mmlr@mlotz.ch>
9  */
10 #ifndef ACCELERANT_HW_INTERFACE_H
11 #define ACCELERANT_HW_INTERFACE_H
12 
13 
14 #include "HWInterface.h"
15 
16 #include <AutoDeleter.h>
17 #include <image.h>
18 #include <video_overlay.h>
19 
20 
21 class AccelerantBuffer;
22 class RenderingBuffer;
23 
24 
25 class AccelerantHWInterface : public HWInterface {
26 public:
27 								AccelerantHWInterface();
28 	virtual						~AccelerantHWInterface();
29 
30 	virtual	status_t			Initialize();
31 	virtual	status_t			Shutdown();
32 
33 	virtual	status_t			SetMode(const display_mode& mode);
34 	virtual	void				GetMode(display_mode* mode);
35 
36 	virtual status_t			GetDeviceInfo(accelerant_device_info* info);
37 	virtual status_t			GetFrameBufferConfig(
38 									frame_buffer_config& config);
39 
40 	virtual status_t			GetModeList(display_mode** _modeList,
41 									uint32* _count);
42 	virtual status_t			GetPixelClockLimits(display_mode* mode,
43 									uint32* _low, uint32* _high);
44 	virtual status_t			GetTimingConstraints(display_timing_constraints*
45 									constraints);
46 	virtual status_t			ProposeMode(display_mode* candidate,
47 									const display_mode* low,
48 									const display_mode* high);
49 	virtual	status_t			GetPreferredMode(display_mode* mode);
50 	virtual status_t			GetMonitorInfo(monitor_info* info);
51 
52 	virtual sem_id				RetraceSemaphore();
53 	virtual status_t			WaitForRetrace(
54 									bigtime_t timeout = B_INFINITE_TIMEOUT);
55 
56 	virtual status_t			SetDPMSMode(uint32 state);
57 	virtual uint32				DPMSMode();
58 	virtual uint32				DPMSCapabilities();
59 
60 	virtual status_t			SetBrightness(float);
61 	virtual status_t			GetBrightness(float*);
62 
63 	virtual status_t			GetAccelerantPath(BString& path);
64 	virtual status_t			GetDriverPath(BString& path);
65 
66 	// query for available hardware accleration
67 	virtual	uint32				AvailableHWAcceleration() const;
68 
69 	// accelerated drawing
70 	virtual	void				CopyRegion(const clipping_rect* sortedRectList,
71 									uint32 count, int32 xOffset, int32 yOffset);
72 	virtual	void				FillRegion(/*const*/ BRegion& region,
73 									const rgb_color& color, bool autoSync);
74 	virtual	void				InvertRegion(/*const*/ BRegion& region);
75 
76 	virtual	void				Sync();
77 
78 	// overlay support
79 	virtual overlay_token		AcquireOverlayChannel();
80 	virtual void				ReleaseOverlayChannel(overlay_token token);
81 
82 	virtual status_t			GetOverlayRestrictions(const Overlay* overlay,
83 									overlay_restrictions* restrictions);
84 	virtual bool				CheckOverlayRestrictions(int32 width,
85 									int32 height, color_space colorSpace);
86 	virtual const overlay_buffer* AllocateOverlayBuffer(int32 width,
87 									int32 height, color_space space);
88 	virtual void				FreeOverlayBuffer(const overlay_buffer* buffer);
89 
90 	virtual void				ConfigureOverlay(Overlay* overlay);
91 	virtual void				HideOverlay(Overlay* overlay);
92 
93 	// cursor handling
94 	virtual	void				SetCursor(ServerCursor* cursor);
95 	virtual	void				SetCursorVisible(bool visible);
96 	virtual	void				MoveCursorTo(float x, float y);
97 
98 	// frame buffer access
99 	virtual	RenderingBuffer*	FrontBuffer() const;
100 	virtual	RenderingBuffer*	BackBuffer() const;
101 	virtual	bool				IsDoubleBuffered() const;
102 
103 protected:
104 	virtual	void				_CopyBackToFront(/*const*/ BRegion& region);
105 
106 	virtual	void				_DrawCursor(IntRect area) const;
107 
108 private:
109 			int					_OpenGraphicsDevice(int deviceNumber);
110 			bool				_RecursiveScan(const char* directory, int deviceNumber,
111 									int& count, char* _path);
112 			status_t			_OpenAccelerant(int device);
113 			status_t			_SetupDefaultHooks();
114 			void				_UpdateHooksAfterModeChange();
115 			status_t			_UpdateModeList();
116 			status_t			_UpdateFrameBufferConfig();
117 			void				_RegionToRectParams(/*const*/ BRegion* region,
118 									uint32* count) const;
119 			void				_CopyRegion(const clipping_rect* sortedRectList,
120 									uint32 count, int32 xOffset, int32 yOffset,
121 									bool inBackBuffer);
122 			uint32				_NativeColor(const rgb_color& color) const;
123 			status_t			_FindBestMode(const display_mode& compareMode,
124 									float compareAspectRatio,
125 									display_mode& modeFound,
126 									int32 *_diff = NULL) const;
127 			status_t			_SetFallbackMode(display_mode& mode) const;
128 			void				_SetSystemPalette();
129 			void				_SetGrayscalePalette();
130 
131 private:
132 			int					fCardFD;
133 			image_id			fAccelerantImage;
134 			GetAccelerantHook	fAccelerantHook;
135 			engine_token*		fEngineToken;
136 			sync_token			fSyncToken;
137 
138 			// required hooks - guaranteed to be valid
139 			accelerant_mode_count	fAccGetModeCount;
140 			get_mode_list			fAccGetModeList;
141 			get_frame_buffer_config	fAccGetFrameBufferConfig;
142 			set_display_mode		fAccSetDisplayMode;
143 			get_display_mode		fAccGetDisplayMode;
144 			get_pixel_clock_limits	fAccGetPixelClockLimits;
145 
146 			// optional accelerant hooks
147 			acquire_engine			fAccAcquireEngine;
148 			release_engine			fAccReleaseEngine;
149 			sync_to_token			fAccSyncToToken;
150 			get_timing_constraints	fAccGetTimingConstraints;
151 			propose_display_mode	fAccProposeDisplayMode;
152 			get_preferred_display_mode fAccGetPreferredDisplayMode;
153 			get_monitor_info		fAccGetMonitorInfo;
154 			get_edid_info			fAccGetEDIDInfo;
155 			fill_rectangle			fAccFillRect;
156 			invert_rectangle		fAccInvertRect;
157 			screen_to_screen_blit	fAccScreenBlit;
158 			set_cursor_shape		fAccSetCursorShape;
159 			set_cursor_bitmap		fAccSetCursorBitmap;
160 			move_cursor				fAccMoveCursor;
161 			show_cursor				fAccShowCursor;
162 
163 			// dpms hooks
164 			dpms_capabilities	fAccDPMSCapabilities;
165 			dpms_mode			fAccDPMSMode;
166 			set_dpms_mode		fAccSetDPMSMode;
167 
168 			// brightness hooks
169 			set_brightness		fAccSetBrightness;
170 			get_brightness		fAccGetBrightness;
171 
172 			// overlay hooks
173 			overlay_count				fAccOverlayCount;
174 			overlay_supported_spaces	fAccOverlaySupportedSpaces;
175 			overlay_supported_features	fAccOverlaySupportedFeatures;
176 			allocate_overlay_buffer		fAccAllocateOverlayBuffer;
177 			release_overlay_buffer		fAccReleaseOverlayBuffer;
178 			get_overlay_constraints		fAccGetOverlayConstraints;
179 			allocate_overlay			fAccAllocateOverlay;
180 			release_overlay				fAccReleaseOverlay;
181 			configure_overlay			fAccConfigureOverlay;
182 
183 			frame_buffer_config	fFrameBufferConfig;
184 			int					fModeCount;
185 			display_mode*		fModeList;
186 
187 			ObjectDeleter<RenderingBuffer>
188 								fBackBuffer;
189 			ObjectDeleter<AccelerantBuffer>
190 								fFrontBuffer;
191 			bool				fOffscreenBackBuffer;
192 
193 			display_mode		fDisplayMode;
194 			bool				fInitialModeSwitch;
195 
196 			sem_id				fRetraceSemaphore;
197 
198 	mutable	fill_rect_params*	fRectParams;
199 	mutable	uint32				fRectParamsCount;
200 	mutable	blit_params*		fBlitParams;
201 	mutable	uint32				fBlitParamsCount;
202 };
203 
204 #endif // ACCELERANT_HW_INTERFACE_H
205