src/video/bwindow/SDL_bframebuffer.cc
changeset 5933 5f8a7ebc88e5
parent 5932 cd08863bcb49
child 5934 01531d8d1e01
equal deleted inserted replaced
5932:cd08863bcb49 5933:5f8a7ebc88e5
    58 	display_mode bmode;
    58 	display_mode bmode;
    59 	bscreen.GetMode(&bmode);
    59 	bscreen.GetMode(&bmode);
    60 	int32 bpp = ColorSpaceToBitsPerPixel(bmode.space);
    60 	int32 bpp = ColorSpaceToBitsPerPixel(bmode.space);
    61 	*format = BPPToSDLPxFormat(bpp);
    61 	*format = BPPToSDLPxFormat(bpp);
    62 
    62 
    63 	/* pitch = width of screen, in bytes */
    63 	/* Create the new bitmap object */
    64 	*pitch = bwin->GetFbWidth() * bwin->GetBytesPerPx();
    64 	BBitmap *bitmap = bwin->GetBitmap();
       
    65 	if(bitmap) {
       
    66 		delete bitmap;
       
    67 	}
       
    68 	bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
       
    69 			false,	/* Views not accepted */
       
    70 			true);	/* Contiguous memory required */
       
    71 	bwin->SetBitmap(bitmap);
       
    72 	
       
    73 	/* Set the pixel pointer */
       
    74 	*pixels = bitmap->Bits();
    65 
    75 
    66 	/* Create a copy of the pixel buffer if it doesn't recycle */
    76 	/* pitch = width of window, in bytes */
    67 	*pixels = bwin->GetWindowFramebuffer();
    77 	*pitch = bitmap->BytesPerRow();
    68 	if( (*pixels) != NULL ) {
       
    69 		SDL_free(*pixels);
       
    70 	}
       
    71 	*pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() * 
       
    72 		bwin->GetBytesPerPx(), sizeof(uint8));
       
    73 	bwin->SetWindowFramebuffer((uint8*)(*pixels));
       
    74 
    78 
    75 	bwin->SetBufferExists(true);
    79 	bwin->SetBufferExists(true);
    76 	bwin->SetTrashBuffer(false);
    80 	bwin->SetTrashBuffer(false);
    77 	bwin->UnlockBuffer();
    81 	bwin->UnlockBuffer();
    78 	return 0;
    82 	return 0;
   104 	}
   108 	}
   105 
   109 
   106 	while(bwin->ConnectionEnabled()) {
   110 	while(bwin->ConnectionEnabled()) {
   107 		if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
   111 		if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
   108 			bwin->LockBuffer();
   112 			bwin->LockBuffer();
   109 			int32 windowPitch = window->surface->pitch;
   113 			BBitmap *bitmap = bwin->GetBitmap();
       
   114 			int32 windowPitch = bitmap->BytesPerRow();
   110 			int32 bufferPitch = bwin->GetRowBytes();
   115 			int32 bufferPitch = bwin->GetRowBytes();
   111 			uint8 *windowpx;
   116 			uint8 *windowpx;
   112 			uint8 *bufferpx;
   117 			uint8 *bufferpx;
   113 
   118 
   114 			int32 BPP = bwin->GetBytesPerPx();
   119 			int32 BPP = bwin->GetBytesPerPx();
   115 			uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
       
   116 			int32 windowSub = bwin->GetFbX() * BPP +
   120 			int32 windowSub = bwin->GetFbX() * BPP +
   117 						  bwin->GetFbY() * windowPitch;
   121 						  bwin->GetFbY() * windowPitch;
   118 			clipping_rect *clips = bwin->GetClips();
   122 			clipping_rect *clips = bwin->GetClips();
   119 			int32 numClips = bwin->GetNumClips();
   123 			int32 numClips = bwin->GetNumClips();
   120 			int i, y;
   124 			int i, y;
   126 				/* Get addresses of the start of each clipping rectangle */
   130 				/* Get addresses of the start of each clipping rectangle */
   127 				int32 width = clips[i].right - clips[i].left + 1;
   131 				int32 width = clips[i].right - clips[i].left + 1;
   128 				int32 height = clips[i].bottom - clips[i].top + 1;
   132 				int32 height = clips[i].bottom - clips[i].top + 1;
   129 				bufferpx = bwin->GetBufferPx() + 
   133 				bufferpx = bwin->GetBufferPx() + 
   130 					clips[i].top * bufferPitch + clips[i].left * BPP;
   134 					clips[i].top * bufferPitch + clips[i].left * BPP;
   131 				windowpx = windowBaseAddress + 
   135 				windowpx = (uint8*)bitmap->Bits(); + 
   132 					clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
   136 					clips[i].top * windowPitch + clips[i].left * BPP -
       
   137 					windowSub;
   133 
   138 
   134 				/* Copy each row of pixels from the window buffer into the frame
   139 				/* Copy each row of pixels from the window buffer into the frame
   135 				   buffer */
   140 				   buffer */
   136 				for(y = 0; y < height; ++y)
   141 				for(y = 0; y < height; ++y)
   137 				{
   142 				{
   158 	SDL_BWin *bwin = _ToBeWin(window);
   163 	SDL_BWin *bwin = _ToBeWin(window);
   159 	
   164 	
   160 	bwin->LockBuffer();
   165 	bwin->LockBuffer();
   161 	
   166 	
   162 	/* Free and clear the window buffer */
   167 	/* Free and clear the window buffer */
   163 	uint8* winBuffer = bwin->GetWindowFramebuffer();
   168 	BBitmap *bitmap = bwin->GetBitmap();
   164 	SDL_free(winBuffer);
   169 	delete bitmap;
   165 	bwin->SetWindowFramebuffer(NULL);
   170 	bwin->SetBitmap(NULL);
   166 	bwin->SetBufferExists(false);
   171 	bwin->SetBufferExists(false);
   167 	bwin->UnlockBuffer();
   172 	bwin->UnlockBuffer();
   168 }
   173 }
   169 
   174 
   170 #ifdef __cplusplus
   175 #ifdef __cplusplus