#include "SDL_internal.h"
#ifdef SDL_VIDEO_DRIVER_HAIKU
#include "SDL_bframebuffer.h"
#include <AppKit.h>
#include <InterfaceKit.h>
#include "SDL_bmodes.h"
#include "SDL_BWin.h"
#include "../../core/haiku/SDL_BApp.h"
#ifdef __cplusplus
extern "C" {
#endif
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window)
{
return (SDL_BWin *)(window->internal);
}
static SDL_INLINE SDL_BLooper *_GetBeLooper()
{
return SDL_Looper;
}
bool HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, SDL_PixelFormat * format, void ** pixels, int *pitch)
{
SDL_BWin *bwin = _ToBeWin(window);
BScreen bscreen;
if (!bscreen.IsValid()) {
return false;
}
bwin->LockBuffer();
bwin->CreateView();
display_mode bmode;
bscreen.GetMode(&bmode);
*format = HAIKU_ColorSpaceToSDLPxFormat(bmode.space);
BBitmap *bitmap = bwin->GetBitmap();
if (bitmap) {
delete bitmap;
}
bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
false, true);
if (bitmap->InitCheck() != B_OK) {
delete bitmap;
return SDL_SetError("Could not initialize back buffer!");
}
bwin->SetBitmap(bitmap);
*pixels = bitmap->Bits();
*pitch = bitmap->BytesPerRow();
bwin->UnlockBuffer();
return true;
}
bool HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window,
const SDL_Rect * rects, int numrects) {
if (!window) {
return true;
}
SDL_BWin *bwin = _ToBeWin(window);
bwin->PostMessage(BWIN_UPDATE_FRAMEBUFFER);
return true;
}
void HAIKU_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window) {
SDL_BWin *bwin = _ToBeWin(window);
bwin->LockBuffer();
BBitmap *bitmap = bwin->GetBitmap();
delete bitmap;
bwin->SetBitmap(NULL);
bwin->RemoveView();
bwin->UnlockBuffer();
}
#ifdef __cplusplus
}
#endif
#endif