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