Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
  3.  *
  4.  * This file is part of libnsfb, http://www.netsurf-browser.org/
  5.  * Licenced under the MIT License,
  6.  *                http://www.opensource.org/licenses/mit-license.php
  7.  */
  8.  
  9. #include <stdbool.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #include "libnsfb.h"
  15. #include "libnsfb_plot.h"
  16. #include "libnsfb_event.h"
  17. #include "nsfb.h"
  18. #include "palette.h"
  19. #include "surface.h"
  20.  
  21. /* exported interface documented in libnsfb.h */
  22. nsfb_t*
  23. nsfb_new(const enum nsfb_type_e surface_type)
  24. {
  25.     nsfb_t *newfb;
  26.     newfb = calloc(1, sizeof(nsfb_t));
  27.     if (newfb == NULL)
  28.         return NULL;
  29.  
  30.     /* obtain surface routines */
  31.     newfb->surface_rtns = nsfb_surface_get_rtns(surface_type);
  32.     if (newfb->surface_rtns == NULL) {
  33.         free(newfb);
  34.         return NULL;
  35.     }
  36.  
  37.     newfb->surface_rtns->defaults(newfb);
  38.  
  39.     return newfb;
  40. }
  41.  
  42. /* exported interface documented in libnsfb.h */
  43. int
  44. nsfb_init(nsfb_t *nsfb)
  45. {
  46.     return nsfb->surface_rtns->initialise(nsfb);
  47. }
  48.  
  49. /* exported interface documented in libnsfb.h */
  50. int
  51. nsfb_free(nsfb_t *nsfb)
  52. {
  53.     int ret;
  54.  
  55.     if (nsfb->palette != NULL)
  56.         nsfb_palette_free(nsfb->palette);
  57.  
  58.     ret = nsfb->surface_rtns->finalise(nsfb);
  59.     free(nsfb);
  60.     return ret;
  61. }
  62.  
  63. /* exported interface documented in libnsfb.h */
  64. bool
  65. nsfb_event(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
  66. {
  67.     return nsfb->surface_rtns->input(nsfb, event, timeout);
  68. }
  69.  
  70. /* exported interface documented in libnsfb.h */
  71. int
  72. nsfb_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
  73. {
  74.     return nsfb->surface_rtns->claim(nsfb, box);
  75. }
  76.  
  77. /* exported interface documented in libnsfb.h */
  78. int
  79. nsfb_update(nsfb_t *nsfb, nsfb_bbox_t *box)
  80. {
  81.     return nsfb->surface_rtns->update(nsfb, box);
  82. }
  83.  
  84. /* exported interface documented in libnsfb.h */
  85. int
  86. nsfb_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format)
  87. {
  88.     if (width <= 0)
  89.         width = nsfb->width;        
  90.  
  91.     if (height <= 0)
  92.         height = nsfb->height;        
  93.  
  94.     if (format == NSFB_FMT_ANY)
  95.             format = nsfb->format;
  96.  
  97.     return nsfb->surface_rtns->geometry(nsfb, width, height, format);
  98. }
  99.  
  100. /* exported interface documented in libnsfb.h */
  101. int nsfb_set_parameters(nsfb_t *nsfb, const char *parameters)
  102. {
  103.     if ((parameters == NULL) || (*parameters == 0)) {
  104.         return -1;
  105.     }
  106.  
  107.     if (nsfb->parameters != NULL) {
  108.         free(nsfb->parameters);
  109.     }
  110.  
  111.     nsfb->parameters = strdup(parameters);
  112.  
  113.     return nsfb->surface_rtns->parameters(nsfb, parameters);
  114. }
  115.  
  116. /* exported interface documented in libnsfb.h */
  117. int
  118. nsfb_get_geometry(nsfb_t *nsfb, int *width, int *height, enum nsfb_format_e *format)
  119. {
  120.     if (width != NULL)
  121.         *width = nsfb->width;
  122.  
  123.     if (height != NULL)
  124.         *height = nsfb->height;
  125.  
  126.     if (format != NULL)
  127.         *format = nsfb->format;
  128.  
  129.     return 0;
  130. }
  131.  
  132. /* exported interface documented in libnsfb.h */
  133. int
  134. nsfb_get_buffer(nsfb_t *nsfb, uint8_t **ptr, int *linelen)
  135. {
  136.     if (ptr != NULL) {
  137.         *ptr = nsfb->ptr;
  138.     }
  139.     if (linelen != NULL) {
  140.         *linelen = nsfb->linelen;
  141.     }
  142.     return 0;
  143. }
  144.  
  145.  
  146. /*
  147.  * Local variables:
  148.  *  c-basic-offset: 4
  149.  *  tab-width: 8
  150.  * End:
  151.  */
  152.  
  153.