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 <unistd.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "surface.h"
  16. #include "plot.h"
  17.  
  18. #define MAX_SURFACES 16
  19.  
  20. #define UNUSED(x) ((x) = (x))
  21.  
  22. struct nsfb_surface_s {
  23.     enum nsfb_type_e type;
  24.     const nsfb_surface_rtns_t *rtns;
  25.     const char *name;
  26. };
  27.  
  28. static struct nsfb_surface_s surfaces[MAX_SURFACES];
  29. static int surface_count = 0;
  30.  
  31. /* internal routine which lets surfaces register their presence at runtime */
  32. void _nsfb_register_surface(const enum nsfb_type_e type,
  33.                              const nsfb_surface_rtns_t *rtns,
  34.                              const char *name)
  35. {
  36.     if (surface_count >= MAX_SURFACES)
  37.         return; /* no space for additional surfaces */
  38.  
  39.     surfaces[surface_count].type = type;
  40.     surfaces[surface_count].rtns = rtns;
  41.     surfaces[surface_count].name = name;
  42.     surface_count++;
  43. }
  44.  
  45. /* default surface implementations */
  46.  
  47. static int surface_defaults(nsfb_t *nsfb)
  48. {
  49.     nsfb->width = 800;
  50.     nsfb->height = 600;
  51.     nsfb->format = NSFB_FMT_XRGB8888;
  52.  
  53.     /* select default sw plotters for bpp */
  54.     select_plotters(nsfb);
  55.  
  56.     return 0;
  57. }
  58.  
  59. static int surface_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
  60. {
  61.     UNUSED(nsfb);
  62.     UNUSED(box);
  63.     return 0;
  64. }
  65.  
  66. static int surface_update(nsfb_t *nsfb, nsfb_bbox_t *box)
  67. {
  68.     UNUSED(nsfb);
  69.     UNUSED(box);
  70.     return 0;
  71. }
  72.  
  73. static int surface_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
  74. {
  75.     UNUSED(nsfb);
  76.     UNUSED(cursor);
  77.     return 0;
  78. }
  79.  
  80. static int surface_parameters(nsfb_t *nsfb, const char *parameters)
  81. {
  82.     UNUSED(nsfb);
  83.     UNUSED(parameters);
  84.     return 0;
  85. }
  86.  
  87. /* exported interface documented in surface.h */
  88. nsfb_surface_rtns_t *
  89. nsfb_surface_get_rtns(enum nsfb_type_e type)
  90. {
  91.     int fend_loop;
  92.     nsfb_surface_rtns_t *rtns = NULL;
  93.  
  94.     for (fend_loop = 0; fend_loop < surface_count; fend_loop++) {
  95.         /* surface type must match and have a initialisor, finaliser
  96.          * and input method
  97.          */
  98.         if ((surfaces[fend_loop].type == type) &&
  99.             (surfaces[fend_loop].rtns->initialise != NULL) &&
  100.             (surfaces[fend_loop].rtns->finalise != NULL) &&
  101.             (surfaces[fend_loop].rtns->input != NULL) ) {
  102.              
  103.             rtns = malloc(sizeof(nsfb_surface_rtns_t));
  104.             if (rtns == NULL) {
  105.                 continue;
  106.             }
  107.  
  108.             memcpy(rtns,
  109.                    surfaces[fend_loop].rtns,
  110.                    sizeof(nsfb_surface_rtns_t));
  111.  
  112.             /* The rest may be empty but to avoid the null check every time
  113.              * provide default implementations.
  114.              */
  115.             if (rtns->defaults == NULL) {
  116.                 rtns->defaults = surface_defaults;
  117.             }
  118.  
  119.             if (rtns->claim == NULL) {
  120.                 rtns->claim = surface_claim;
  121.             }
  122.  
  123.             if (rtns->update == NULL) {
  124.                 rtns->update = surface_update;
  125.             }
  126.  
  127.             if (rtns->cursor == NULL) {
  128.                 rtns->cursor = surface_cursor;
  129.             }
  130.  
  131.             if (rtns->parameters == NULL) {
  132.                 rtns->parameters = surface_parameters;
  133.             }
  134.            
  135.             break;
  136.         }
  137.     }
  138.     return rtns;
  139. }
  140.  
  141. /* exported interface defined in libnsfb.h */
  142. enum nsfb_type_e
  143. nsfb_type_from_name(const char *name)
  144. {
  145.     int fend_loop;
  146.  
  147.     for (fend_loop = 0; fend_loop < surface_count; fend_loop++) {
  148.         if (strcmp(surfaces[fend_loop].name, name) == 0)
  149.             return surfaces[fend_loop].type;
  150.     }
  151.     return NSFB_SURFACE_NONE;
  152. }
  153.  
  154. /*
  155.  * Local variables:
  156.  *  c-basic-offset: 4
  157.  *  tab-width: 8
  158.  * End:
  159.  */
  160.