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.  
  13. #include "libnsfb.h"
  14. #include "libnsfb_plot.h"
  15. #include "libnsfb_event.h"
  16.  
  17. #include "nsfb.h"
  18. #include "surface.h"
  19. #include "plot.h"
  20.  
  21. #define UNUSED(x) ((x) = (x))
  22.  
  23. static int ram_defaults(nsfb_t *nsfb)
  24. {
  25.     nsfb->width = 0;
  26.     nsfb->height = 0;
  27.     nsfb->format = NSFB_FMT_ABGR8888;
  28.  
  29.     /* select default sw plotters for bpp */
  30.     select_plotters(nsfb);
  31.  
  32.     return 0;
  33. }
  34.  
  35.  
  36. static int ram_initialise(nsfb_t *nsfb)
  37. {
  38.     size_t size = (nsfb->width * nsfb->height * nsfb->bpp) / 8;
  39.  
  40.     nsfb->ptr = realloc(nsfb->ptr, size);
  41.     nsfb->linelen = (nsfb->width * nsfb->bpp) / 8;
  42.  
  43.     return 0;
  44. }
  45.  
  46. static int ram_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format)
  47. {
  48.     int startsize;
  49.     int endsize;
  50.  
  51.     startsize = (nsfb->width * nsfb->height * nsfb->bpp) / 8;
  52.  
  53.     if (width > 0) {
  54.         nsfb->width = width;
  55.     }
  56.  
  57.     if (height > 0) {
  58.         nsfb->height = height;
  59.     }
  60.  
  61.     if (format != NSFB_FMT_ANY) {
  62.         nsfb->format = format;
  63.     }
  64.  
  65.     /* select soft plotters appropriate for format */
  66.     select_plotters(nsfb);
  67.  
  68.     endsize = (nsfb->width * nsfb->height * nsfb->bpp) / 8;
  69.     if ((nsfb->ptr != NULL) && (startsize != endsize)) {
  70.         nsfb->ptr = realloc(nsfb->ptr, endsize);
  71.     }
  72.     nsfb->linelen = (nsfb->width * nsfb->bpp) / 8;
  73.  
  74.     return 0;
  75. }
  76.  
  77.  
  78. static int ram_finalise(nsfb_t *nsfb)
  79. {
  80.     free(nsfb->ptr);
  81.  
  82.     return 0;
  83. }
  84.  
  85. static bool ram_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
  86. {
  87.     UNUSED(nsfb);
  88.     UNUSED(event);
  89.     UNUSED(timeout);
  90.     return false;
  91. }
  92.  
  93. const nsfb_surface_rtns_t ram_rtns = {
  94.     .defaults = ram_defaults,
  95.     .initialise = ram_initialise,
  96.     .finalise = ram_finalise,
  97.     .input = ram_input,
  98.     .geometry = ram_set_geometry,
  99. };
  100.  
  101. NSFB_SURFACE_DEF(ram, NSFB_SURFACE_RAM, &ram_rtns)
  102.  
  103. /*
  104.  * Local variables:
  105.  *  c-basic-offset: 4
  106.  *  tab-width: 8
  107.  * End:
  108.  */
  109.