Numworks Epsilon  1.4.1
Graphing Calculator Operating System
display.cpp
Go to the documentation of this file.
1 #include "display.h"
2 #include <kandinsky.h>
3 
4 extern "C" {
5 #include <SDL/SDL.h>
6 #include <assert.h>
7 #include <stdlib.h>
8 #include <emscripten.h>
9 }
10 
11 SDL_Surface * screen = nullptr;
14 
15 namespace Ion {
16 namespace Display {
17 
18 void pushRect(KDRect r, const KDColor * pixels) {
19  sFrameBuffer.pushRect(r, pixels);
20 }
21 
23  sFrameBuffer.pushRectUniform(r, c);
24 }
25 
26 void pullRect(KDRect r, KDColor * pixels) {
27  sFrameBuffer.pullRect(r, pixels);
28 }
29 
30 void waitForVBlank() {
31 }
32 
33 }
34 }
35 
36 namespace Ion {
37 namespace Display {
38 namespace Emscripten {
39 
40 void init() {
41  SDL_Init(SDL_INIT_VIDEO);
42  screen = SDL_SetVideoMode(Ion::Display::Width, Ion::Display::Height, 32, SDL_SWSURFACE);
43  EM_ASM("SDL.defaults.copyOnLock = false; SDL.defaults.discardOnLock = true; SDL.defaults.opaqueFrontBuffer = false;");
44 }
45 
46 void refresh() {
47  // Simply push the whole buffer to the surface
48  if (SDL_MUSTLOCK(screen)) {
49  SDL_LockSurface(screen);
50  }
51  int pixelNumber = 0;
52  for (int j=0; j<Ion::Display::Height; j++) {
53  for (int i=0; i<Ion::Display::Width; i++) {
54  KDColor c = sPixels[pixelNumber++];
55  *((Uint32*)screen->pixels + j * Ion::Display::Width + i) = SDL_MapRGB(screen->format, c.red(), c.green(), c.blue());
56  }
57  }
58 
59  if (SDL_MUSTLOCK(screen)) {
60  SDL_UnlockSurface(screen);
61  }
62  SDL_UpdateRect(screen, 0, 0, Ion::Display::Width, Ion::Display::Height);
63 }
64 
65 }
66 }
67 }
void pushRectUniform(KDRect rect, KDColor color)
Definition: framebuffer.cpp:29
constexpr int Width
Definition: display.h:26
void Display(const char *input)
Definition: display.cpp:11
void pullRect(KDRect r, KDColor *pixels)
Definition: display.cpp:26
void pushRect(KDRect r, const KDColor *pixels)
Definition: display.cpp:14
SDL_Surface * screen
Definition: display.cpp:11
Definition: size.h:6
c(generic_all_nodes)
void pushRect(KDRect rect, const KDColor *pixels)
Definition: framebuffer.cpp:18
void pullRect(KDRect rect, KDColor *pixels)
Definition: framebuffer.cpp:45
Definition: rect.h:26
Definition: color.h:6
Definition: backlight.h:6
void pushRectUniform(KDRect r, KDColor c)
Definition: display.cpp:20
constexpr int Height
Definition: display.h:27
void waitForVBlank()
Definition: display.cpp:32