serenity/Widgets/FrameBufferSDL.cpp
2018-10-10 16:49:36 +02:00

60 lines
1 KiB
C++

#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);
}