diff --git a/src/video/bwindow/SDL_BWin.h b/src/video/bwindow/SDL_BWin.h index 0e423a1a9..a1afc86c9 100644 --- a/src/video/bwindow/SDL_BWin.h +++ b/src/video/bwindow/SDL_BWin.h @@ -81,7 +81,7 @@ class SDL_BWin:public BDirectWindow _buffer_created = _buffer_dirty = false; _trash_window_buffer = false; _buffer_locker = new BLocker(); - _window_buffer = NULL; + _bitmap = NULL; _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread", B_NORMAL_PRIORITY, (void*) this); @@ -394,27 +394,29 @@ class SDL_BWin:public BDirectWindow uint32 GetRowBytes() { return _row_bytes; } int32 GetFbX() { return _bounds.left; } int32 GetFbY() { return _bounds.top; } - int32 GetFbHeight() { return _bounds.bottom - _bounds.top + 1; } - int32 GetFbWidth() { return _bounds.right - _bounds.left + 1; } +// int32 GetFbHeight() { return _bounds.bottom - _bounds.top + 1; } +// int32 GetFbWidth() { return _bounds.right - _bounds.left + 1; } bool ConnectionEnabled() { return !_connection_disabled; } bool Connected() { return _connected; } clipping_rect *GetClips() { return _clips; } int32 GetNumClips() { return _num_clips; } uint8* GetBufferPx() { return _bits; } int32 GetBytesPerPx() { return _bytes_per_px; } - uint8* GetWindowFramebuffer() { return _window_buffer; } +// uint8* GetWindowFramebuffer() { return _window_buffer; } bool CanTrashWindowBuffer() { return _trash_window_buffer; } bool BufferExists() { return _buffer_created; } bool BufferIsDirty() { return _buffer_dirty; } + BBitmap *GetBitmap() { return _bitmap; } /* Setter methods */ void SetID(int32 id) { _id = id; } 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 UnlockBuffer() { _buffer_locker->Unlock(); } void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; } void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; } + void SetBitmap(BBitmap *bitmap) { _bitmap = bitmap; } private: @@ -588,9 +590,11 @@ private: clipping_rect *_clips; int32 _num_clips; 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; thread_id _draw_thread_id; + + BBitmap *_bitmap; }; #endif diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index 7b93f800f..0ebeb7cbb 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -60,17 +60,21 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, int32 bpp = ColorSpaceToBitsPerPixel(bmode.space); *format = BPPToSDLPxFormat(bpp); - /* pitch = width of screen, in bytes */ - *pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx(); - - /* Create a copy of the pixel buffer if it doesn't recycle */ - *pixels = bwin->GetWindowFramebuffer(); - if( (*pixels) != NULL ) { - SDL_free(*pixels); + /* Create the new bitmap object */ + BBitmap *bitmap = bwin->GetBitmap(); + if(bitmap) { + delete bitmap; } - *pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * - bwin->GetBytesPerPx(), sizeof(uint8)); - bwin->SetWindowFramebuffer((uint8*)(*pixels)); + bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space, + false, /* Views not accepted */ + 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->SetTrashBuffer(false); @@ -106,13 +110,13 @@ int32 BE_DrawThread(void *data) { while(bwin->ConnectionEnabled()) { if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) { bwin->LockBuffer(); - int32 windowPitch = window->surface->pitch; + BBitmap *bitmap = bwin->GetBitmap(); + int32 windowPitch = bitmap->BytesPerRow(); int32 bufferPitch = bwin->GetRowBytes(); uint8 *windowpx; uint8 *bufferpx; int32 BPP = bwin->GetBytesPerPx(); - uint8 *windowBaseAddress = (uint8*)window->surface->pixels; int32 windowSub = bwin->GetFbX() * BPP + bwin->GetFbY() * windowPitch; clipping_rect *clips = bwin->GetClips(); @@ -128,8 +132,9 @@ int32 BE_DrawThread(void *data) { int32 height = clips[i].bottom - clips[i].top + 1; bufferpx = bwin->GetBufferPx() + clips[i].top * bufferPitch + clips[i].left * BPP; - windowpx = windowBaseAddress + - clips[i].top * windowPitch + clips[i].left * BPP - windowSub; + windowpx = (uint8*)bitmap->Bits(); + + clips[i].top * windowPitch + clips[i].left * BPP - + windowSub; /* Copy each row of pixels from the window buffer into the frame buffer */ @@ -160,9 +165,9 @@ void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) { bwin->LockBuffer(); /* Free and clear the window buffer */ - uint8* winBuffer = bwin->GetWindowFramebuffer(); - SDL_free(winBuffer); - bwin->SetWindowFramebuffer(NULL); + BBitmap *bitmap = bwin->GetBitmap(); + delete bitmap; + bwin->SetBitmap(NULL); bwin->SetBufferExists(false); bwin->UnlockBuffer(); }