Choco OS  V.0.16.9.0
Join to the chocolate world
oc_screen.c
Go to the documentation of this file.
1 
27 #include <oc_screen.h>
28 #include <oc_object.h>
29 #include <oc_string.h>
30 
36 #define _________________________________________TYPES_SECTION______________________________________________________________________________
37 
38 //==========================================================================================================================================
42 //==========================================================================================================================================
43 struct Screen_t
44 {
46  oC_Driver_t Driver;
47  char Name[30];
48  void * Config;
49  void * Context;
50  bool Configured;
51 };
52 
53 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
54 
60 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
61 
62 //==========================================================================================================================================
66 //==========================================================================================================================================
67 static const oC_Allocator_t Allocator = {
68  .Name = "Screen"
69 };
70 
71 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
72 
73 
79 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
80 
81 //==========================================================================================================================================
100 //==========================================================================================================================================
101 oC_Screen_t oC_Screen_New( oC_Driver_t Driver , const void * Config , const char * Name )
102 {
103  oC_Screen_t screen = NULL;
104  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
105 
106  if(
107  ErrorCondition( isaddresscorrect(Driver) , oC_ErrorCode_WrongAddress )
108  && ErrorCondition( oC_Driver_GetDriverType(Driver) == GRAPHICS_DRIVER , oC_ErrorCode_NotGraphicDriver )
109  && ErrorCondition( isaddresscorrect(Driver) , oC_ErrorCode_WrongAddress )
110  && ErrorCondition( isaddresscorrect(Name) , oC_ErrorCode_WrongAddress )
111  )
112  {
113  screen = kmalloc(sizeof(struct Screen_t) , &Allocator , AllocationFlags_CanWait1Second | AllocationFlags_ZeroFill);
114 
115  if(screen != NULL)
116  {
117  screen->ObjectControl = oC_CountObjectControl(screen,oC_ObjectId_Screen);
118  screen->Driver = Driver;
119  screen->Config = kmalloc(Driver->ConfigurationSize,&Allocator, AllocationFlags_CanWait1Second);
120  screen->Context = NULL;
121  screen->Configured = false;
122 
123  if(screen->Config != NULL)
124  {
125  strncpy(screen->Name,Name,sizeof(screen->Name));
126  memcpy(screen->Config,Config,Driver->ConfigurationSize);
127  }
128  else
129  {
130  oC_SaveIfFalse("Screen::new: cannot release screen memory", kfree(screen,AllocationFlags_CanWait1Second) , oC_ErrorCode_ReleaseError);
131  oC_SaveError("Screen::new: cannot allocate memory for config" , oC_ErrorCode_AllocationError);
132  }
133  }
134  else
135  {
136  oC_SaveError("Screen::new: cannot allocate memory for screen" , oC_ErrorCode_AllocationError);
137  }
138  }
139  else
140  {
141  oC_SaveError("Screen::new: Cannot create screen - " , errorCode);
142  }
143 
144  return screen;
145 }
146 
147 //==========================================================================================================================================
159 //==========================================================================================================================================
161 {
162  return isram(Screen) && oC_CheckObjectControl(Screen,oC_ObjectId_Screen,Screen->ObjectControl);
163 }
164 
165 //==========================================================================================================================================
184 //==========================================================================================================================================
186 {
187  bool deleted = false;
188 
189  if(isaddresscorrect(Screen) && oC_Screen_IsCorrect(*Screen))
190  {
191  oC_Screen_t localScreen = *Screen;
192 
193  if(localScreen->Configured == true)
194  {
195  oC_SaveIfErrorOccur("Screen::delete: Cannot unconfigure screen - " , oC_Driver_Unconfigure(localScreen->Driver,localScreen->Config,&localScreen->Context));
196  }
197 
198  deleted = kfree(localScreen->Config,AllocationFlags_CanWait1Second);
199 
200  if(!deleted)
201  {
202  oC_SaveError("Screen::delete: Cannot release config memory - " , oC_ErrorCode_ReleaseError);
203  }
204 
205  if(kfree(localScreen,AllocationFlags_CanWait1Second))
206  {
207  deleted = deleted && true;
208  }
209  else
210  {
211  oC_SaveError("Screen::delete: Cannot release screen memory - " , oC_ErrorCode_ReleaseError);
212  }
213  }
214 
215  return deleted;
216 }
217 
218 
219 //==========================================================================================================================================
233 //==========================================================================================================================================
235 {
236  return oC_Screen_IsCorrect(Screen) && Screen->Configured;
237 }
238 
239 //==========================================================================================================================================
256 //==========================================================================================================================================
257 oC_ErrorCode_t oC_Screen_Configure( oC_Screen_t Screen )
258 {
259  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
260 
261  if(
262  ErrorCondition( oC_Screen_IsCorrect(Screen) , oC_ErrorCode_ObjectNotCorrect )
263  && ErrorCondition( Screen->Configured == false , oC_ErrorCode_AlreadyConfigured )
264  && oC_AssignErrorCode(&errorCode , oC_Driver_Configure(Screen->Driver,Screen->Config,&Screen->Context))
265  )
266  {
267  Screen->Configured = true;
268  errorCode = oC_ErrorCode_None;
269  }
270 
271  return errorCode;
272 }
273 
274 //==========================================================================================================================================
291 //==========================================================================================================================================
292 oC_ErrorCode_t oC_Screen_Unconfigure( oC_Screen_t Screen )
293 {
294  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
295 
296  if(
297  ErrorCondition( oC_Screen_IsCorrect(Screen) , oC_ErrorCode_ObjectNotCorrect )
298  && ErrorCondition( Screen->Configured == true , oC_ErrorCode_NotConfiguredYet )
299  && oC_AssignErrorCode(&errorCode , oC_Driver_Unconfigure(Screen->Driver,Screen->Config,&Screen->Context))
300  )
301  {
302  Screen->Configured = false;
303  errorCode = oC_ErrorCode_None;
304  }
305 
306  return errorCode;
307 }
308 
309 //==========================================================================================================================================
323 //==========================================================================================================================================
324 oC_ErrorCode_t oC_Screen_ReadColorMap( oC_Screen_t Screen , oC_ColorMap_t ** outColorMap )
325 {
326  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
327 
328  if(
329  ErrorCondition( oC_Screen_IsCorrect(Screen) , oC_ErrorCode_ObjectNotCorrect )
330  && ErrorCondition( Screen->Configured == true , oC_ErrorCode_NotConfiguredYet )
331  && ErrorCondition( isram(outColorMap) , oC_ErrorCode_OutputAddressNotInRAM )
332  )
333  {
334  errorCode = oC_Driver_ReadColorMap(Screen->Driver,Screen->Context,outColorMap);
335  }
336 
337  return errorCode;
338 }
339 
340 //==========================================================================================================================================
355 //==========================================================================================================================================
356 oC_ErrorCode_t oC_Screen_ReadResolution( oC_Screen_t Screen , oC_Pixel_ResolutionUInt_t * outWidth , oC_Pixel_ResolutionUInt_t * outHeight )
357 {
358  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
359 
360  if(
361  ErrorCondition( oC_Screen_IsCorrect(Screen) , oC_ErrorCode_ObjectNotCorrect )
362  && ErrorCondition( Screen->Configured == true , oC_ErrorCode_NotConfiguredYet )
363  && ErrorCondition( isram(outWidth) , oC_ErrorCode_OutputAddressNotInRAM )
364  && ErrorCondition( isram(outHeight) , oC_ErrorCode_OutputAddressNotInRAM )
365  )
366  {
367  errorCode = oC_Driver_ReadResolution(Screen->Driver,Screen->Context,outWidth,outHeight);
368  }
369 
370  return errorCode;
371 }
372 
373 //==========================================================================================================================================
385 //==========================================================================================================================================
386 const char * oC_Screen_GetName( oC_Screen_t Screen )
387 {
388  const char * name = "unknown";
389 
390  if(oC_Screen_IsCorrect(Screen))
391  {
392  name = Screen->Name;
393  }
394  else
395  {
396  name = "incorrect";
397  }
398 
399  return name;
400 }
401 
402 //==========================================================================================================================================
414 //==========================================================================================================================================
415 oC_Driver_t oC_Screen_GetDriver( oC_Screen_t Screen )
416 {
417  oC_Driver_t driver = NULL;
418 
419  if(oC_Screen_IsCorrect(Screen))
420  {
421  driver = Screen->Driver;
422  }
423 
424  return driver;
425 }
426 
427 
428 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
const char * oC_Screen_GetName(oC_Screen_t Screen)
returns name of the screen
Definition: oc_screen.c:386
char Name[30]
Name of the screen - useful for screen identification.
Definition: oc_screen.c:47
const char * Name
Definition: oc_stdlib.h:161
identifier for allocations
Definition: oc_stdlib.h:159
oC_Screen_t oC_Screen_New(oC_Driver_t Driver, const void *Config, const char *Name)
creates new screen object
Definition: oc_screen.c:101
bool oC_Screen_Delete(oC_Screen_t *Screen)
Destroys the Screen object.
Definition: oc_screen.c:185
void * Context
Pointer to the driver context.
Definition: oc_screen.c:49
static const oC_Allocator_t Allocator
the allocator definition for identify the module allocations
Definition: oc_screen.c:67
oC_ErrorCode_t oC_Screen_ReadResolution(oC_Screen_t Screen, oC_Pixel_ResolutionUInt_t *outWidth, oC_Pixel_ResolutionUInt_t *outHeight)
reads resolution of the screen
Definition: oc_screen.c:356
The file with helper macros for managing objects.
bool Configured
This flag is set to true if the driver configuration was done and was finished with successful result...
Definition: oc_screen.c:50
uint32_t oC_ObjectControl_t
stores object control value
Definition: oc_object.h:141
stores screen object data
Definition: oc_screen.c:43
oC_Driver_t Driver
Pointer to the graphic driver that handles the screen.
Definition: oc_screen.c:46
File with interface for the screen objects.
static oC_ObjectControl_t oC_CountObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId)
counts object control for object
Definition: oc_object.h:168
static bool oC_CheckObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId, oC_ObjectControl_t ObjectControl)
checks if object control is correct
Definition: oc_object.h:203
bool oC_Screen_IsConfigured(oC_Screen_t Screen)
checks if the screen is configured to work
Definition: oc_screen.c:234
oC_ErrorCode_t oC_Screen_Configure(oC_Screen_t Screen)
configures graphics driver to work
Definition: oc_screen.c:257
oC_Driver_t oC_Screen_GetDriver(oC_Screen_t Screen)
returns driver associated with the screen
Definition: oc_screen.c:415
The file with interface for string library.
bool oC_Screen_IsCorrect(oC_Screen_t Screen)
checks if the Screen object is correct
Definition: oc_screen.c:160
oC_ErrorCode_t oC_Screen_ReadColorMap(oC_Screen_t Screen, oC_ColorMap_t **outColorMap)
reads pointer to the color map
Definition: oc_screen.c:324
oC_ObjectControl_t ObjectControl
Magic number counted by the Object module.
Definition: oc_screen.c:45
void * Config
Pointer to the screen configuration.
Definition: oc_screen.c:48
oC_ErrorCode_t oC_Screen_Unconfigure(oC_Screen_t Screen)
unconfigures graphics driver
Definition: oc_screen.c:292
#define NULL
pointer to a zero
Definition: oc_null.h:37