summaryrefslogtreecommitdiff
path: root/Widgets/FrameBufferSDL.cpp
blob: f7dce0dfc805aa8c25d64b176fe4410863986eab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "FrameBufferSDL.h"
#include <AK/Assertions.h>

FrameBufferSDL* s_the = nullptr;

FrameBufferSDL& FrameBufferSDL::the()
{
    ASSERT(s_the);
    return *s_the;
}

FrameBufferSDL::FrameBufferSDL(unsigned width, unsigned height)
    : AbstractScreen(width, height)
{
    ASSERT(!s_the);
    s_the = this;
    initializeSDL();
}

FrameBufferSDL::~FrameBufferSDL()
{
    SDL_DestroyWindow(m_window);
    m_surface = nullptr;
    m_window = nullptr;

    SDL_Quit();
}

void FrameBufferSDL::show()
{
}

void FrameBufferSDL::initializeSDL()
{
    if (m_window)
        return;

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        ASSERT_NOT_REACHED();
    }

    m_window = SDL_CreateWindow(
        "FrameBuffer",
        SDL_WINDOWPOS_UNDEFINED, 
        SDL_WINDOWPOS_UNDEFINED, 
        width(),
        height(),
        SDL_WINDOW_SHOWN);

    ASSERT(m_window);

    m_surface = SDL_GetWindowSurface(m_window);
    ASSERT(m_surface);

    SDL_FillRect(m_surface, nullptr, SDL_MapRGB(m_surface->format, 0xff, 0xff, 0xff));

    SDL_UpdateWindowSurface(m_window);
}