xref: /haiku/src/servers/app/drawing/interface/local/AccelerantHWInterface.h (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
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 			status_t			_OpenAccelerant(int device);
111 			status_t			_SetupDefaultHooks();
112 			void				_UpdateHooksAfterModeChange();
113 			status_t			_UpdateModeList();
114 			status_t			_UpdateFrameBufferConfig();
115 			void				_RegionToRectParams(/*const*/ BRegion* region,
116 									uint32* count) const;
117 			void				_CopyRegion(const clipping_rect* sortedRectList,
118 									uint32 count, int32 xOffset, int32 yOffset,
119 									bool inBackBuffer);
120 			uint32				_NativeColor(const rgb_color& color) const;
121 			status_t			_FindBestMode(const display_mode& compareMode,
122 									float compareAspectRatio,
123 									display_mode& modeFound,
124 									int32 *_diff = NULL) const;
125 			status_t			_SetFallbackMode(display_mode& mode) const;
126 			void				_SetSystemPalette();
127 			void				_SetGrayscalePalette();
128 
129 private:
130 			int					fCardFD;
131 			image_id			fAccelerantImage;
132 			GetAccelerantHook	fAccelerantHook;
133 			engine_token*		fEngineToken;
134 			sync_token			fSyncToken;
135 
136 			// required hooks - guaranteed to be valid
137 			accelerant_mode_count	fAccGetModeCount;
138 			get_mode_list			fAccGetModeList;
139 			get_frame_buffer_config	fAccGetFrameBufferConfig;
140 			set_display_mode		fAccSetDisplayMode;
141 			get_display_mode		fAccGetDisplayMode;
142 			get_pixel_clock_limits	fAccGetPixelClockLimits;
143 
144 			// optional accelerant hooks
145 			acquire_engine			fAccAcquireEngine;
146 			release_engine			fAccReleaseEngine;
147 			sync_to_token			fAccSyncToToken;
148 			get_timing_constraints	fAccGetTimingConstraints;
149 			propose_display_mode	fAccProposeDisplayMode;
150 			get_preferred_display_mode fAccGetPreferredDisplayMode;
151 			get_monitor_info		fAccGetMonitorInfo;
152 			get_edid_info			fAccGetEDIDInfo;
153 			fill_rectangle			fAccFillRect;
154 			invert_rectangle		fAccInvertRect;
155 			screen_to_screen_blit	fAccScreenBlit;
156 			set_cursor_shape		fAccSetCursorShape;
157 			set_cursor_bitmap		fAccSetCursorBitmap;
158 			move_cursor				fAccMoveCursor;
159 			show_cursor				fAccShowCursor;
160 
161 			// dpms hooks
162 			dpms_capabilities	fAccDPMSCapabilities;
163 			dpms_mode			fAccDPMSMode;
164 			set_dpms_mode		fAccSetDPMSMode;
165 
166 			// brightness hooks
167 			set_brightness		fAccSetBrightness;
168 			get_brightness		fAccGetBrightness;
169 
170 			// overlay hooks
171 			overlay_count				fAccOverlayCount;
172 			overlay_supported_spaces	fAccOverlaySupportedSpaces;
173 			overlay_supported_features	fAccOverlaySupportedFeatures;
174 			allocate_overlay_buffer		fAccAllocateOverlayBuffer;
175 			release_overlay_buffer		fAccReleaseOverlayBuffer;
176 			get_overlay_constraints		fAccGetOverlayConstraints;
177 			allocate_overlay			fAccAllocateOverlay;
178 			release_overlay				fAccReleaseOverlay;
179 			configure_overlay			fAccConfigureOverlay;
180 
181 			frame_buffer_config	fFrameBufferConfig;
182 			int					fModeCount;
183 			display_mode*		fModeList;
184 
185 			ObjectDeleter<RenderingBuffer>
186 								fBackBuffer;
187 			ObjectDeleter<AccelerantBuffer>
188 								fFrontBuffer;
189 			bool				fOffscreenBackBuffer;
190 
191 			display_mode		fDisplayMode;
192 			bool				fInitialModeSwitch;
193 
194 			sem_id				fRetraceSemaphore;
195 
196 	mutable	fill_rect_params*	fRectParams;
197 	mutable	uint32				fRectParamsCount;
198 	mutable	blit_params*		fBlitParams;
199 	mutable	uint32				fBlitParamsCount;
200 };
201 
202 #endif // ACCELERANT_HW_INTERFACE_H
203