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 GetAccelerantPath(BString& path); 60 virtual status_t GetDriverPath(BString& path); 61 62 // query for available hardware accleration 63 virtual uint32 AvailableHWAcceleration() const; 64 65 // accelerated drawing 66 virtual void CopyRegion(const clipping_rect* sortedRectList, 67 uint32 count, int32 xOffset, int32 yOffset); 68 virtual void FillRegion(/*const*/ BRegion& region, 69 const rgb_color& color, bool autoSync); 70 virtual void InvertRegion(/*const*/ BRegion& region); 71 72 virtual void Sync(); 73 74 // overlay support 75 virtual overlay_token AcquireOverlayChannel(); 76 virtual void ReleaseOverlayChannel(overlay_token token); 77 78 virtual status_t GetOverlayRestrictions(const Overlay* overlay, 79 overlay_restrictions* restrictions); 80 virtual bool CheckOverlayRestrictions(int32 width, 81 int32 height, color_space colorSpace); 82 virtual const overlay_buffer* AllocateOverlayBuffer(int32 width, 83 int32 height, color_space space); 84 virtual void FreeOverlayBuffer(const overlay_buffer* buffer); 85 86 virtual void ConfigureOverlay(Overlay* overlay); 87 virtual void HideOverlay(Overlay* overlay); 88 89 // cursor handling 90 virtual void SetCursor(ServerCursor* cursor); 91 virtual void SetCursorVisible(bool visible); 92 virtual void MoveCursorTo(float x, float y); 93 94 // frame buffer access 95 virtual RenderingBuffer* FrontBuffer() const; 96 virtual RenderingBuffer* BackBuffer() const; 97 virtual bool IsDoubleBuffered() const; 98 99 protected: 100 virtual void _CopyBackToFront(/*const*/ BRegion& region); 101 102 virtual void _DrawCursor(IntRect area) const; 103 104 private: 105 int _OpenGraphicsDevice(int deviceNumber); 106 status_t _OpenAccelerant(int device); 107 status_t _SetupDefaultHooks(); 108 void _UpdateHooksAfterModeChange(); 109 status_t _UpdateModeList(); 110 status_t _UpdateFrameBufferConfig(); 111 void _RegionToRectParams(/*const*/ BRegion* region, 112 uint32* count) const; 113 void _CopyRegion(const clipping_rect* sortedRectList, 114 uint32 count, int32 xOffset, int32 yOffset, 115 bool inBackBuffer); 116 uint32 _NativeColor(const rgb_color& color) const; 117 status_t _FindBestMode(const display_mode& compareMode, 118 float compareAspectRatio, 119 display_mode& modeFound, 120 int32 *_diff = NULL) const; 121 status_t _SetFallbackMode(display_mode& mode) const; 122 void _SetSystemPalette(); 123 void _SetGrayscalePalette(); 124 125 private: 126 int fCardFD; 127 image_id fAccelerantImage; 128 GetAccelerantHook fAccelerantHook; 129 engine_token* fEngineToken; 130 sync_token fSyncToken; 131 132 // required hooks - guaranteed to be valid 133 acquire_engine fAccAcquireEngine; 134 release_engine fAccReleaseEngine; 135 sync_to_token fAccSyncToToken; 136 accelerant_mode_count fAccGetModeCount; 137 get_mode_list fAccGetModeList; 138 get_frame_buffer_config fAccGetFrameBufferConfig; 139 set_display_mode fAccSetDisplayMode; 140 get_display_mode fAccGetDisplayMode; 141 get_pixel_clock_limits fAccGetPixelClockLimits; 142 143 // optional accelerant hooks 144 get_timing_constraints fAccGetTimingConstraints; 145 propose_display_mode fAccProposeDisplayMode; 146 get_preferred_display_mode fAccGetPreferredDisplayMode; 147 get_monitor_info fAccGetMonitorInfo; 148 get_edid_info fAccGetEDIDInfo; 149 fill_rectangle fAccFillRect; 150 invert_rectangle fAccInvertRect; 151 screen_to_screen_blit fAccScreenBlit; 152 set_cursor_shape fAccSetCursorShape; 153 set_cursor_bitmap fAccSetCursorBitmap; 154 move_cursor fAccMoveCursor; 155 show_cursor fAccShowCursor; 156 157 // dpms hooks 158 dpms_capabilities fAccDPMSCapabilities; 159 dpms_mode fAccDPMSMode; 160 set_dpms_mode fAccSetDPMSMode; 161 162 // overlay hooks 163 overlay_count fAccOverlayCount; 164 overlay_supported_spaces fAccOverlaySupportedSpaces; 165 overlay_supported_features fAccOverlaySupportedFeatures; 166 allocate_overlay_buffer fAccAllocateOverlayBuffer; 167 release_overlay_buffer fAccReleaseOverlayBuffer; 168 get_overlay_constraints fAccGetOverlayConstraints; 169 allocate_overlay fAccAllocateOverlay; 170 release_overlay fAccReleaseOverlay; 171 configure_overlay fAccConfigureOverlay; 172 173 frame_buffer_config fFrameBufferConfig; 174 int fModeCount; 175 display_mode* fModeList; 176 177 RenderingBuffer* fBackBuffer; 178 AccelerantBuffer* fFrontBuffer; 179 bool fOffscreenBackBuffer; 180 181 display_mode fDisplayMode; 182 bool fInitialModeSwitch; 183 184 sem_id fRetraceSemaphore; 185 186 mutable fill_rect_params* fRectParams; 187 mutable uint32 fRectParamsCount; 188 mutable blit_params* fBlitParams; 189 mutable uint32 fBlitParamsCount; 190 }; 191 192 #endif // ACCELERANT_HW_INTERFACE_H 193