1 /* 2 (c) Copyright 2001-2011 The world wide DirectFB Open Source Community (directfb.org) 3 (c) Copyright 2000-2004 Convergence (integrated media) GmbH 4 5 All rights reserved. 6 7 Written by Denis Oliver Kropp <dok@directfb.org>, 8 Andreas Hundt <andi@fischlustig.de>, 9 Sven Neumann <neo@directfb.org>, 10 Ville Syrjälä <syrjala@sci.fi> and 11 Claudio Ciccani <klan@users.sf.net>. 12 13 This library is free software; you can redistribute it and/or 14 modify it under the terms of the GNU Lesser General Public 15 License as published by the Free Software Foundation; either 16 version 2 of the License, or (at your option) any later version. 17 18 This library is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 Lesser General Public License for more details. 22 23 You should have received a copy of the GNU Lesser General Public 24 License along with this library; if not, write to the 25 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 26 Boston, MA 02111-1307, USA. 27 */ 28 29 #ifndef __GFXCARD_H__ 30 #define __GFXCARD_H__ 31 32 #include <pthread.h> 33 34 #include <direct/modules.h> 35 36 #include <fusion/call.h> 37 #include <fusion/lock.h> 38 #include <fusion/property.h> 39 40 #include <core/coretypes.h> 41 42 #include <directfb.h> 43 44 45 typedef enum { 46 CCF_CLIPPING = 0x00000001, 47 CCF_NOTRIEMU = 0x00000002, 48 CCF_READSYSMEM = 0x00000004, 49 CCF_WRITESYSMEM= 0x00000008, 50 CCF_AUXMEMORY = 0x00000010, 51 CCF_RENDEROPTS = 0x00000020 52 } CardCapabilitiesFlags; 53 54 struct __DFB_CoreGraphicsSerial { 55 unsigned int serial; 56 unsigned int generation; 57 }; 58 59 typedef struct { 60 CardCapabilitiesFlags flags; 61 62 DFBAccelerationMask accel; 63 DFBSurfaceBlittingFlags blitting; 64 DFBSurfaceDrawingFlags drawing; 65 DFBAccelerationMask clip; 66 } CardCapabilities; 67 68 typedef struct { 69 unsigned int surface_byteoffset_alignment; 70 unsigned int surface_pixelpitch_alignment; 71 unsigned int surface_bytepitch_alignment; 72 73 unsigned int surface_max_power_of_two_pixelpitch; 74 unsigned int surface_max_power_of_two_bytepitch; 75 unsigned int surface_max_power_of_two_height; 76 77 DFBDimension dst_min; 78 DFBDimension dst_max; 79 DFBDimension src_min; 80 DFBDimension src_max; 81 } CardLimitations; 82 83 DECLARE_MODULE_DIRECTORY( dfb_graphics_drivers ); 84 85 /* 86 * Increase this number when changes result in binary incompatibility! 87 */ 88 #define DFB_GRAPHICS_DRIVER_ABI_VERSION 34 89 90 #define DFB_GRAPHICS_DRIVER_INFO_NAME_LENGTH 40 91 #define DFB_GRAPHICS_DRIVER_INFO_VENDOR_LENGTH 60 92 #define DFB_GRAPHICS_DRIVER_INFO_URL_LENGTH 100 93 #define DFB_GRAPHICS_DRIVER_INFO_LICENSE_LENGTH 40 94 95 #define DFB_GRAPHICS_DEVICE_INFO_NAME_LENGTH 48 96 #define DFB_GRAPHICS_DEVICE_INFO_VENDOR_LENGTH 64 97 98 99 typedef struct { 100 int major; /* major version */ 101 int minor; /* minor version */ 102 } GraphicsDriverVersion; /* major.minor, e.g. 0.1 */ 103 104 typedef struct { 105 GraphicsDriverVersion version; 106 107 char name[DFB_GRAPHICS_DRIVER_INFO_NAME_LENGTH]; 108 /* Name of driver, e.g. 'Matrox Driver' */ 109 110 char vendor[DFB_GRAPHICS_DRIVER_INFO_VENDOR_LENGTH]; 111 /* Vendor (or author) of the driver, 112 e.g. 'directfb.org' or 'Denis Oliver Kropp' */ 113 114 char url[DFB_GRAPHICS_DRIVER_INFO_URL_LENGTH]; 115 /* URL for driver updates, 116 e.g. 'http://www.directfb.org/' */ 117 118 char license[DFB_GRAPHICS_DRIVER_INFO_LICENSE_LENGTH]; 119 /* License, e.g. 'LGPL' or 'proprietary' */ 120 121 unsigned int driver_data_size; 122 unsigned int device_data_size; 123 } GraphicsDriverInfo; 124 125 typedef struct { 126 char name[DFB_GRAPHICS_DEVICE_INFO_NAME_LENGTH]; 127 /* Device name, e.g. 'G400' */ 128 129 char vendor[DFB_GRAPHICS_DEVICE_INFO_VENDOR_LENGTH]; 130 /* Vendor of the device, 131 e.g. 'Matrox' or 'ATI' */ 132 133 /* hardware acceleration capabilities */ 134 CardCapabilities caps; 135 136 /* hardware limitations */ 137 CardLimitations limits; 138 } GraphicsDeviceInfo; 139 140 typedef struct _GraphicsDeviceFuncs { 141 /* 142 * function that is called after variable screeninfo is changed 143 * (used for buggy fbdev drivers, that reinitialize something when 144 * calling FBIO_PUT_VSCREENINFO) 145 */ 146 void (*AfterSetVar)( void *driver_data, void *device_data ); 147 148 /* 149 * Called after driver->InitDevice() and during dfb_gfxcard_unlock( true ). 150 * The driver should do the one time initialization of the engine, 151 * e.g. writing some registers that are supposed to have a fixed value. 152 * 153 * This happens after mode switching or after returning from 154 * OpenGL state (e.g. DRI driver). 155 */ 156 void (*EngineReset)( void *driver_data, void *device_data ); 157 158 /* 159 * Makes sure that graphics hardware has finished all operations. 160 * 161 * This method is called before the CPU accesses a surface' buffer 162 * that had been written to by the hardware after this method has been 163 * called the last time. 164 * 165 * It's also called before entering the OpenGL state (e.g. DRI driver). 166 */ 167 DFBResult (*EngineSync)( void *driver_data, void *device_data ); 168 169 /* 170 * Called during dfb_gfxcard_lock() to notify the driver that 171 * the current rendering state is no longer valid. 172 */ 173 void (*InvalidateState)( void *driver_data, void *device_data ); 174 175 /* 176 * after the video memory has been written to by the CPU (e.g. modification 177 * of a texture) make sure the accelerator won't use cached texture data 178 */ 179 void (*FlushTextureCache)( void *driver_data, void *device_data ); 180 181 /* 182 * After the video memory has been written to by the accelerator 183 * make sure the CPU won't read back cached data. 184 */ 185 void (*FlushReadCache)( void *driver_data, void *device_data ); 186 187 /* 188 * Called before a software access to a video surface buffer. 189 */ 190 void (*SurfaceEnter)( void *driver_data, void *device_data, 191 CoreSurfaceBuffer *buffer, DFBSurfaceLockFlags flags ); 192 193 /* 194 * Called after a software access to a video surface buffer. 195 */ 196 void (*SurfaceLeave)( void *driver_data, void *device_data, CoreSurfaceBuffer *buffer ); 197 198 /* 199 * Return the serial of the last (queued) operation. 200 * 201 * The serial is used to wait for finishing a specific graphics 202 * operation instead of the whole engine being idle. 203 */ 204 void (*GetSerial)( void *driver_data, void *device_data, CoreGraphicsSerial *serial ); 205 206 /* 207 * Makes sure that graphics hardware has finished the specified operation. 208 */ 209 DFBResult (*WaitSerial)( void *driver_data, void *device_data, const CoreGraphicsSerial *serial ); 210 211 /* 212 * emit any buffered commands, i.e. trigger processing 213 */ 214 void (*EmitCommands) ( void *driver_data, void *device_data ); 215 216 /* 217 * Check if the function 'accel' can be accelerated with the 'state'. 218 * If that's true, the function sets the 'accel' bit in 'state->accel'. 219 * Otherwise the function just returns, no need to clear the bit. 220 */ 221 void (*CheckState)( void *driver_data, void *device_data, 222 CardState *state, DFBAccelerationMask accel ); 223 224 /* 225 * Program card for execution of the function 'accel' with the 'state'. 226 * 'state->modified' contains information about changed entries. 227 * This function has to set at least 'accel' in 'state->set'. 228 * The driver should remember 'state->modified' and clear it. 229 * The driver may modify 'funcs' depending on 'state' settings. 230 */ 231 void (*SetState) ( void *driver_data, void *device_data, 232 struct _GraphicsDeviceFuncs *funcs, 233 CardState *state, DFBAccelerationMask accel ); 234 235 /* 236 * drawing functions 237 */ 238 bool (*FillRectangle) ( void *driver_data, void *device_data, 239 DFBRectangle *rect ); 240 241 bool (*DrawRectangle) ( void *driver_data, void *device_data, 242 DFBRectangle *rect ); 243 244 bool (*DrawLine) ( void *driver_data, void *device_data, 245 DFBRegion *line ); 246 247 bool (*FillTriangle) ( void *driver_data, void *device_data, 248 DFBTriangle *tri ); 249 250 bool (*FillTrapezoid) ( void *driver_data, void *device_data, 251 DFBTrapezoid *trap ); 252 253 /* 254 * blitting functions 255 */ 256 bool (*Blit) ( void *driver_data, void *device_data, 257 DFBRectangle *rect, int dx, int dy ); 258 259 bool (*Blit2) ( void *driver_data, void *device_data, 260 DFBRectangle *rect, int dx, int dy, int sx2, int sy2 ); 261 262 bool (*StretchBlit) ( void *driver_data, void *device_data, 263 DFBRectangle *srect, DFBRectangle *drect ); 264 265 bool (*TextureTriangles)( void *driver_data, void *device_data, 266 DFBVertex *vertices, int num, 267 DFBTriangleFormation formation ); 268 269 /* 270 * Signal beginning of a sequence of operations using this state. 271 * Any number of states can be 'drawing'. 272 */ 273 void (*StartDrawing)( void *driver_data, void *device_data, CardState *state ); 274 275 /* 276 * Signal end of sequence, i.e. destination surface is consistent again. 277 */ 278 void (*StopDrawing)( void *driver_data, void *device_data, CardState *state ); 279 } GraphicsDeviceFuncs; 280 281 typedef struct { 282 int (*Probe) (CoreGraphicsDevice *device); 283 void (*GetDriverInfo) (CoreGraphicsDevice *device, 284 GraphicsDriverInfo *driver_info); 285 286 DFBResult (*InitDriver) (CoreGraphicsDevice *device, 287 GraphicsDeviceFuncs *funcs, 288 void *driver_data, 289 void *device_data, 290 CoreDFB *core); 291 292 DFBResult (*InitDevice) (CoreGraphicsDevice *device, 293 GraphicsDeviceInfo *device_info, 294 void *driver_data, 295 void *device_data); 296 297 void (*CloseDevice) (CoreGraphicsDevice *device, 298 void *driver_data, 299 void *device_data); 300 void (*CloseDriver) (CoreGraphicsDevice *device, 301 void *driver_data); 302 } GraphicsDriverFuncs; 303 304 typedef enum { 305 GDLF_NONE = 0x00000000, 306 307 GDLF_WAIT = 0x00000001, 308 GDLF_SYNC = 0x00000002, 309 GDLF_INVALIDATE = 0x00000004, 310 GDLF_RESET = 0x00000008 311 } GraphicsDeviceLockFlags; 312 313 DFBResult dfb_gfxcard_lock( GraphicsDeviceLockFlags flags ); 314 void dfb_gfxcard_unlock( void ); 315 316 bool dfb_gfxcard_state_check( CardState *state, DFBAccelerationMask accel ); 317 318 /* 319 * Signal beginning of a sequence of operations using this state. 320 * Any number of states can be 'drawing'. 321 */ 322 void dfb_gfxcard_start_drawing( CoreGraphicsDevice *device, 323 CardState *state ); 324 325 /* 326 * Signal end of sequence, i.e. destination surface is consistent again. 327 */ 328 void dfb_gfxcard_stop_drawing ( CoreGraphicsDevice *device, 329 CardState *state ); 330 331 /* 332 * drawing functions, lock source and destination surfaces, 333 * handle clipping and drawing method (hardware/software) 334 */ 335 void dfb_gfxcard_fillrectangles ( const DFBRectangle *rects, 336 int num, 337 CardState *state ); 338 339 void dfb_gfxcard_drawrectangle ( DFBRectangle *rect, 340 CardState *state ); 341 342 void dfb_gfxcard_drawlines ( DFBRegion *lines, 343 int num_lines, 344 CardState *state ); 345 346 void dfb_gfxcard_fillspans ( int y, 347 DFBSpan *spans, 348 int num_spans, 349 CardState *state ); 350 351 void dfb_gfxcard_filltriangles ( const DFBTriangle *tris, 352 int num, 353 CardState *state ); 354 355 void dfb_gfxcard_filltrapezoids ( const DFBTrapezoid *traps, 356 int num, 357 CardState *state ); 358 359 void dfb_gfxcard_blit ( DFBRectangle *rect, 360 int dx, 361 int dy, 362 CardState *state ); 363 364 void dfb_gfxcard_batchblit ( DFBRectangle *rects, 365 DFBPoint *points, 366 int num, 367 CardState *state ); 368 369 void dfb_gfxcard_batchblit2 ( DFBRectangle *rects, 370 DFBPoint *points, 371 DFBPoint *points2, 372 int num, 373 CardState *state ); 374 375 void dfb_gfxcard_tileblit ( DFBRectangle *rect, 376 int dx1, 377 int dy1, 378 int dx2, 379 int dy2, 380 CardState *state ); 381 382 void dfb_gfxcard_stretchblit ( DFBRectangle *srect, 383 DFBRectangle *drect, 384 CardState *state ); 385 386 void dfb_gfxcard_texture_triangles ( DFBVertex *vertices, 387 int num, 388 DFBTriangleFormation formation, 389 CardState *state ); 390 391 392 393 394 395 396 void dfb_gfxcard_drawstring ( const u8 *text, 397 int bytes, 398 DFBTextEncodingID encoding, 399 int x, 400 int y, 401 CoreFont *font, 402 unsigned int layers, 403 CoreGraphicsStateClient *client ); 404 405 void dfb_gfxcard_drawglyph ( CoreGlyphData **glyph, 406 int x, 407 int y, 408 CoreFont *font, 409 unsigned int layers, 410 CoreGraphicsStateClient *client ); 411 412 413 414 415 416 bool dfb_gfxcard_drawstring_check_state ( CoreFont *font, 417 CardState *state ); 418 419 420 DFBResult dfb_gfxcard_sync( void ); 421 422 void dfb_gfxcard_invalidate_state( void ); 423 DFBResult dfb_gfxcard_wait_serial( const CoreGraphicsSerial *serial ); 424 void dfb_gfxcard_flush_texture_cache( void ); 425 void dfb_gfxcard_flush_read_cache( void ); 426 void dfb_gfxcard_after_set_var( void ); 427 void dfb_gfxcard_surface_enter( CoreSurfaceBuffer *buffer, DFBSurfaceLockFlags flags ); 428 void dfb_gfxcard_surface_leave( CoreSurfaceBuffer *buffer ); 429 430 DFBResult dfb_gfxcard_adjust_heap_offset( int offset ); 431 432 void dfb_gfxcard_get_capabilities ( CardCapabilities *ret_caps ); 433 void dfb_gfxcard_get_device_info ( GraphicsDeviceInfo *ret_info ); 434 void dfb_gfxcard_get_driver_info ( GraphicsDriverInfo *ret_info ); 435 436 int dfb_gfxcard_reserve_memory ( CoreGraphicsDevice *device, 437 unsigned int size ); 438 int dfb_gfxcard_reserve_auxmemory ( CoreGraphicsDevice *device, 439 unsigned int size ); 440 441 unsigned int dfb_gfxcard_memory_length ( void ); 442 unsigned int dfb_gfxcard_auxmemory_length ( void ); 443 444 void *dfb_gfxcard_get_device_data ( void ); 445 void *dfb_gfxcard_get_driver_data ( void ); 446 447 CoreGraphicsDevice *dfb_gfxcard_get_primary ( void ); 448 449 /* 450 * Graphics drivers call this function to get access to MMIO regions. 451 * 452 * device: Graphics device to map 453 * offset: Offset from MMIO base (default offset is 0) 454 * length: Length of mapped region (-1 uses default length) 455 * 456 * Returns the virtual address or NULL if mapping failed. 457 */ 458 volatile void *dfb_gfxcard_map_mmio( CoreGraphicsDevice *device, 459 unsigned int offset, 460 int length ); 461 462 /* 463 * Graphics drivers call this function to unmap MMIO regions. 464 * 465 * addr: Virtual address returned by gfxcard_map_mmio 466 * length: Length of mapped region (-1 uses default length) 467 */ 468 void dfb_gfxcard_unmap_mmio( CoreGraphicsDevice *device, 469 volatile void *addr, 470 int length ); 471 472 int dfb_gfxcard_get_accelerator( CoreGraphicsDevice *device ); 473 474 void dfb_gfxcard_get_limits( CoreGraphicsDevice *device, 475 CardLimitations *ret_limits ); 476 477 void dfb_gfxcard_calc_buffer_size( CoreGraphicsDevice *device, 478 CoreSurfaceBuffer *buffer, 479 int *ret_pitch, 480 int *ret_length ); 481 482 unsigned long dfb_gfxcard_memory_physical ( CoreGraphicsDevice *device, 483 unsigned int offset ); 484 void *dfb_gfxcard_memory_virtual ( CoreGraphicsDevice *device, 485 unsigned int offset ); 486 487 unsigned long dfb_gfxcard_auxmemory_physical( CoreGraphicsDevice *device, 488 unsigned int offset ); 489 void *dfb_gfxcard_auxmemory_virtual ( CoreGraphicsDevice *device, 490 unsigned int offset ); 491 492 493 /* Hook for registering additional screen(s) and layer(s) in app or lib initializing DirectFB. */ 494 extern void (*__DFB_CoreRegisterHook)( CoreDFB *core, CoreGraphicsDevice *device, void *ctx ); 495 extern void *__DFB_CoreRegisterHookCtx; 496 497 498 499 500 501 typedef struct { 502 int magic; 503 504 /* amount of usable memory */ 505 unsigned int videoram_length; 506 unsigned int auxram_length; 507 unsigned int auxram_offset; 508 509 char *module_name; 510 511 GraphicsDriverInfo driver_info; 512 GraphicsDeviceInfo device_info; 513 void *device_data; 514 515 FusionSkirmish lock; 516 GraphicsDeviceLockFlags lock_flags; 517 518 /* 519 * Points to the current state of the graphics card. 520 */ 521 CardState *state; 522 FusionID holder; /* Fusion ID of state owner. */ 523 } DFBGraphicsCoreShared; 524 525 struct __DFB_DFBGraphicsCore { 526 int magic; 527 528 CoreDFB *core; 529 530 DFBGraphicsCoreShared *shared; 531 532 DirectModuleEntry *module; 533 const GraphicsDriverFuncs *driver_funcs; 534 535 void *driver_data; 536 void *device_data; /* copy of shared->device_data */ 537 538 CardCapabilities caps; /* local caps */ 539 CardLimitations limits; /* local limits */ 540 541 GraphicsDeviceFuncs funcs; 542 }; 543 544 545 #endif 546 547