Replaced window backbuffer with BBitmap
authorNathan Heisey <nathanheisey@gmail.com>
Wed, 03 Aug 2011 06:22:33 +0000
changeset 5933 5f8a7ebc88e5
parent 5932 cd08863bcb49
child 5934 01531d8d1e01
Replaced window backbuffer with BBitmap
src/video/bwindow/SDL_BWin.h
src/video/bwindow/SDL_bframebuffer.cc
--- a/src/video/bwindow/SDL_BWin.h	Wed Aug 03 05:09:36 2011 +0000
+++ b/src/video/bwindow/SDL_BWin.h	Wed Aug 03 06:22:33 2011 +0000
@@ -81,7 +81,7 @@
         _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 @@
 	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 @@
     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
--- a/src/video/bwindow/SDL_bframebuffer.cc	Wed Aug 03 05:09:36 2011 +0000
+++ b/src/video/bwindow/SDL_bframebuffer.cc	Wed Aug 03 06:22:33 2011 +0000
@@ -60,17 +60,21 @@
 	int32 bpp = ColorSpaceToBitsPerPixel(bmode.space);
 	*format = BPPToSDLPxFormat(bpp);
 
-	/* pitch = width of screen, in bytes */
-	*pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx();
+	/* Create the new bitmap object */
+	BBitmap *bitmap = bwin->GetBitmap();
+	if(bitmap) {
+		delete bitmap;
+	}
+	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();
 
-	/* Create a copy of the pixel buffer if it doesn't recycle */
-	*pixels = bwin->GetWindowFramebuffer();
-	if( (*pixels) != NULL ) {
-		SDL_free(*pixels);
-	}
-	*pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * 
-		bwin->GetBytesPerPx(), sizeof(uint8));
-	bwin->SetWindowFramebuffer((uint8*)(*pixels));
+	/* pitch = width of window, in bytes */
+	*pitch = bitmap->BytesPerRow();
 
 	bwin->SetBufferExists(true);
 	bwin->SetTrashBuffer(false);
@@ -106,13 +110,13 @@
 	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 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 @@
 	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();
 }