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