Replaced window backbuffer with BBitmap
This commit is contained in:
parent
2dda407120
commit
3c7c721663
2 changed files with 32 additions and 23 deletions
|
@ -81,7 +81,7 @@ class SDL_BWin:public BDirectWindow
|
||||||
_buffer_created = _buffer_dirty = false;
|
_buffer_created = _buffer_dirty = false;
|
||||||
_trash_window_buffer = false;
|
_trash_window_buffer = false;
|
||||||
_buffer_locker = new BLocker();
|
_buffer_locker = new BLocker();
|
||||||
_window_buffer = NULL;
|
_bitmap = NULL;
|
||||||
|
|
||||||
_draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread",
|
_draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread",
|
||||||
B_NORMAL_PRIORITY, (void*) this);
|
B_NORMAL_PRIORITY, (void*) this);
|
||||||
|
@ -394,27 +394,29 @@ class SDL_BWin:public BDirectWindow
|
||||||
uint32 GetRowBytes() { return _row_bytes; }
|
uint32 GetRowBytes() { return _row_bytes; }
|
||||||
int32 GetFbX() { return _bounds.left; }
|
int32 GetFbX() { return _bounds.left; }
|
||||||
int32 GetFbY() { return _bounds.top; }
|
int32 GetFbY() { return _bounds.top; }
|
||||||
int32 GetFbHeight() { return _bounds.bottom - _bounds.top + 1; }
|
// int32 GetFbHeight() { return _bounds.bottom - _bounds.top + 1; }
|
||||||
int32 GetFbWidth() { return _bounds.right - _bounds.left + 1; }
|
// int32 GetFbWidth() { return _bounds.right - _bounds.left + 1; }
|
||||||
bool ConnectionEnabled() { return !_connection_disabled; }
|
bool ConnectionEnabled() { return !_connection_disabled; }
|
||||||
bool Connected() { return _connected; }
|
bool Connected() { return _connected; }
|
||||||
clipping_rect *GetClips() { return _clips; }
|
clipping_rect *GetClips() { return _clips; }
|
||||||
int32 GetNumClips() { return _num_clips; }
|
int32 GetNumClips() { return _num_clips; }
|
||||||
uint8* GetBufferPx() { return _bits; }
|
uint8* GetBufferPx() { return _bits; }
|
||||||
int32 GetBytesPerPx() { return _bytes_per_px; }
|
int32 GetBytesPerPx() { return _bytes_per_px; }
|
||||||
uint8* GetWindowFramebuffer() { return _window_buffer; }
|
// uint8* GetWindowFramebuffer() { return _window_buffer; }
|
||||||
bool CanTrashWindowBuffer() { return _trash_window_buffer; }
|
bool CanTrashWindowBuffer() { return _trash_window_buffer; }
|
||||||
bool BufferExists() { return _buffer_created; }
|
bool BufferExists() { return _buffer_created; }
|
||||||
bool BufferIsDirty() { return _buffer_dirty; }
|
bool BufferIsDirty() { return _buffer_dirty; }
|
||||||
|
BBitmap *GetBitmap() { return _bitmap; }
|
||||||
|
|
||||||
/* Setter methods */
|
/* Setter methods */
|
||||||
void SetID(int32 id) { _id = id; }
|
void SetID(int32 id) { _id = id; }
|
||||||
void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; }
|
void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; }
|
||||||
void SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; }
|
// void SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; }
|
||||||
void LockBuffer() { _buffer_locker->Lock(); }
|
void LockBuffer() { _buffer_locker->Lock(); }
|
||||||
void UnlockBuffer() { _buffer_locker->Unlock(); }
|
void UnlockBuffer() { _buffer_locker->Unlock(); }
|
||||||
void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; }
|
void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; }
|
||||||
void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; }
|
void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; }
|
||||||
|
void SetBitmap(BBitmap *bitmap) { _bitmap = bitmap; }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -588,9 +590,11 @@ private:
|
||||||
clipping_rect *_clips;
|
clipping_rect *_clips;
|
||||||
int32 _num_clips;
|
int32 _num_clips;
|
||||||
int32 _bytes_per_px;
|
int32 _bytes_per_px;
|
||||||
uint8 *_window_buffer; /* A copy of the window buffer */
|
// uint8 *_window_buffer; /* A copy of the window buffer */
|
||||||
bool _trash_window_buffer;
|
bool _trash_window_buffer;
|
||||||
thread_id _draw_thread_id;
|
thread_id _draw_thread_id;
|
||||||
|
|
||||||
|
BBitmap *_bitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -60,17 +60,21 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
|
||||||
int32 bpp = ColorSpaceToBitsPerPixel(bmode.space);
|
int32 bpp = ColorSpaceToBitsPerPixel(bmode.space);
|
||||||
*format = BPPToSDLPxFormat(bpp);
|
*format = BPPToSDLPxFormat(bpp);
|
||||||
|
|
||||||
/* pitch = width of screen, in bytes */
|
/* Create the new bitmap object */
|
||||||
*pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx();
|
BBitmap *bitmap = bwin->GetBitmap();
|
||||||
|
if(bitmap) {
|
||||||
/* Create a copy of the pixel buffer if it doesn't recycle */
|
delete bitmap;
|
||||||
*pixels = bwin->GetWindowFramebuffer();
|
|
||||||
if( (*pixels) != NULL ) {
|
|
||||||
SDL_free(*pixels);
|
|
||||||
}
|
}
|
||||||
*pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() *
|
bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
|
||||||
bwin->GetBytesPerPx(), sizeof(uint8));
|
false, /* Views not accepted */
|
||||||
bwin->SetWindowFramebuffer((uint8*)(*pixels));
|
true); /* Contiguous memory required */
|
||||||
|
bwin->SetBitmap(bitmap);
|
||||||
|
|
||||||
|
/* Set the pixel pointer */
|
||||||
|
*pixels = bitmap->Bits();
|
||||||
|
|
||||||
|
/* pitch = width of window, in bytes */
|
||||||
|
*pitch = bitmap->BytesPerRow();
|
||||||
|
|
||||||
bwin->SetBufferExists(true);
|
bwin->SetBufferExists(true);
|
||||||
bwin->SetTrashBuffer(false);
|
bwin->SetTrashBuffer(false);
|
||||||
|
@ -106,13 +110,13 @@ int32 BE_DrawThread(void *data) {
|
||||||
while(bwin->ConnectionEnabled()) {
|
while(bwin->ConnectionEnabled()) {
|
||||||
if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
|
if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
|
||||||
bwin->LockBuffer();
|
bwin->LockBuffer();
|
||||||
int32 windowPitch = window->surface->pitch;
|
BBitmap *bitmap = bwin->GetBitmap();
|
||||||
|
int32 windowPitch = bitmap->BytesPerRow();
|
||||||
int32 bufferPitch = bwin->GetRowBytes();
|
int32 bufferPitch = bwin->GetRowBytes();
|
||||||
uint8 *windowpx;
|
uint8 *windowpx;
|
||||||
uint8 *bufferpx;
|
uint8 *bufferpx;
|
||||||
|
|
||||||
int32 BPP = bwin->GetBytesPerPx();
|
int32 BPP = bwin->GetBytesPerPx();
|
||||||
uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
|
|
||||||
int32 windowSub = bwin->GetFbX() * BPP +
|
int32 windowSub = bwin->GetFbX() * BPP +
|
||||||
bwin->GetFbY() * windowPitch;
|
bwin->GetFbY() * windowPitch;
|
||||||
clipping_rect *clips = bwin->GetClips();
|
clipping_rect *clips = bwin->GetClips();
|
||||||
|
@ -128,8 +132,9 @@ int32 BE_DrawThread(void *data) {
|
||||||
int32 height = clips[i].bottom - clips[i].top + 1;
|
int32 height = clips[i].bottom - clips[i].top + 1;
|
||||||
bufferpx = bwin->GetBufferPx() +
|
bufferpx = bwin->GetBufferPx() +
|
||||||
clips[i].top * bufferPitch + clips[i].left * BPP;
|
clips[i].top * bufferPitch + clips[i].left * BPP;
|
||||||
windowpx = windowBaseAddress +
|
windowpx = (uint8*)bitmap->Bits(); +
|
||||||
clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
|
clips[i].top * windowPitch + clips[i].left * BPP -
|
||||||
|
windowSub;
|
||||||
|
|
||||||
/* Copy each row of pixels from the window buffer into the frame
|
/* Copy each row of pixels from the window buffer into the frame
|
||||||
buffer */
|
buffer */
|
||||||
|
@ -160,9 +165,9 @@ void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
|
||||||
bwin->LockBuffer();
|
bwin->LockBuffer();
|
||||||
|
|
||||||
/* Free and clear the window buffer */
|
/* Free and clear the window buffer */
|
||||||
uint8* winBuffer = bwin->GetWindowFramebuffer();
|
BBitmap *bitmap = bwin->GetBitmap();
|
||||||
SDL_free(winBuffer);
|
delete bitmap;
|
||||||
bwin->SetWindowFramebuffer(NULL);
|
bwin->SetBitmap(NULL);
|
||||||
bwin->SetBufferExists(false);
|
bwin->SetBufferExists(false);
|
||||||
bwin->UnlockBuffer();
|
bwin->UnlockBuffer();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue