1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add useful functions to <sortix/kernel/video.h> API.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-12-16 02:06:29 +01:00
parent 9a608e5bb2
commit b380dd49c1
2 changed files with 45 additions and 0 deletions

View file

@ -54,6 +54,10 @@ namespace Video {
void Init(TextBufferHandle* textbufhandle);
bool RegisterDriver(const char* name, VideoDriver* driver);
char* GetCurrentMode();
char* GetDriverName(size_t index);
size_t GetCurrentDriverIndex();
size_t GetNumDrivers();
size_t LookupDriverIndexOfMode(const char* mode);
bool Supports(const char* mode);
bool SwitchMode(const char* mode);
char** GetModes(size_t* modesnum);

View file

@ -120,6 +120,26 @@ void Init(TextBufferHandle* thetextbufhandle)
currentmode = NULL;
}
size_t GetCurrentDriverIndex()
{
ScopedLock lock(&videolock);
return currentdrvid;
}
size_t GetNumDrivers()
{
ScopedLock lock(&videolock);
return numdrivers;
}
char* GetDriverName(size_t index)
{
ScopedLock lock(&videolock);
if ( numdrivers <= index || !drivers[index].name )
return String::Clone("none");
return String::Clone(drivers[index].name);
}
static DriverEntry* CurrentDriverEntry()
{
if ( currentdrvid == SIZE_MAX ) { return NULL; }
@ -413,6 +433,27 @@ bool Supports(const char* mode)
return drvent->driver->Supports(mode);
}
size_t LookupDriverIndexOfMode(const char* mode)
{
const char* needle = "driver=";
size_t needlelen = strlen(needle);
while ( *mode )
{
if ( !strncmp(mode, needle, needlelen) )
{
const char* name = mode + needlelen;
size_t namelen = strcspn(name, ",");
ScopedLock lock(&videolock);
for ( size_t i = 0; i < numdrivers; i++ )
if ( !strncmp(drivers[i].name, name, namelen) )
return i;
return SIZE_MAX;
}
mode += strcspn(mode, ",") + 1;
}
return SIZE_MAX;
}
off_t FrameSize()
{
ScopedLock lock(&videolock);