src/video/bwindow/SDL_bframebuffer.cc
changeset 5936 116b7457e73a
parent 5934 01531d8d1e01
child 5938 b85b6326c498
equal deleted inserted replaced
5935:d52ded852194 5936:116b7457e73a
    30 
    30 
    31 #ifdef __cplusplus
    31 #ifdef __cplusplus
    32 extern "C" {
    32 extern "C" {
    33 #endif
    33 #endif
    34 
    34 
       
    35 int32 BE_UpdateOnce(SDL_Window *window);
       
    36 
    35 static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
    37 static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
    36 	return ((SDL_BWin*)(window->driverdata));
    38 	return ((SDL_BWin*)(window->driverdata));
    37 }
    39 }
    38 
    40 
    39 static inline SDL_BApp *_GetBeApp() {
    41 static inline SDL_BApp *_GetBeApp() {
    96                                       SDL_Rect * rects, int numrects) {
    98                                       SDL_Rect * rects, int numrects) {
    97 	if(!window)
    99 	if(!window)
    98 		return 0;
   100 		return 0;
    99 
   101 
   100 	SDL_BWin *bwin = _ToBeWin(window);
   102 	SDL_BWin *bwin = _ToBeWin(window);
   101 	
   103 
       
   104 #ifdef DRAWTHREAD	
   102 	bwin->LockBuffer();
   105 	bwin->LockBuffer();
   103 	bwin->SetBufferDirty(true);
   106 	bwin->SetBufferDirty(true);
   104 	bwin->UnlockBuffer();
   107 	bwin->UnlockBuffer();
       
   108 #else
       
   109 	bwin->SetBufferDirty(true);
       
   110 	BE_UpdateOnce(window);
       
   111 #endif
   105 
   112 
   106 	return 0;
   113 	return 0;
   107 }
   114 }
   108 
   115 
   109 int32 BE_DrawThread(void *data) {
   116 int32 BE_DrawThread(void *data) {
   146 
   153 
   147 				/* Copy each row of pixels from the window buffer into the frame
   154 				/* Copy each row of pixels from the window buffer into the frame
   148 				   buffer */
   155 				   buffer */
   149 				for(y = 0; y < height; ++y)
   156 				for(y = 0; y < height; ++y)
   150 				{
   157 				{
       
   158 
   151 					if(bwin->CanTrashWindowBuffer()) {
   159 					if(bwin->CanTrashWindowBuffer()) {
   152 						goto escape;	/* Break out before the buffer is killed */
   160 						goto escape;	/* Break out before the buffer is killed */
   153 					}
   161 					}
       
   162 
   154 //					printf("memcpy(0x%x, 0x%x, %i) ", bufferpx, windowpx, width * BPP);
   163 //					printf("memcpy(0x%x, 0x%x, %i) ", bufferpx, windowpx, width * BPP);
   155 					memcpy(bufferpx, windowpx, width * BPP);
   164 					memcpy(bufferpx, windowpx, width * BPP);
   156 					bufferpx += bufferPitch;
   165 					bufferpx += bufferPitch;
   157 					windowpx += windowPitch;
   166 					windowpx += windowPitch;
   158 				}
   167 				}
   181 	bwin->SetBitmap(NULL);
   190 	bwin->SetBitmap(NULL);
   182 	bwin->SetBufferExists(false);
   191 	bwin->SetBufferExists(false);
   183 	bwin->UnlockBuffer();
   192 	bwin->UnlockBuffer();
   184 }
   193 }
   185 
   194 
       
   195 
       
   196 int32 BE_UpdateOnce(SDL_Window *window) {
       
   197 	SDL_BWin *bwin = _ToBeWin(window);
       
   198 	BScreen bscreen;
       
   199 	if(!bscreen.IsValid()) {
       
   200 		return -1;
       
   201 	}
       
   202 
       
   203 	if(bwin->ConnectionEnabled() && bwin->Connected()) {
       
   204 		bwin->LockBuffer();
       
   205 		int32 windowPitch = window->surface->pitch;
       
   206 		int32 bufferPitch = bwin->GetRowBytes();
       
   207 		uint8 *windowpx;
       
   208 		uint8 *bufferpx;
       
   209 
       
   210 		int32 BPP = bwin->GetBytesPerPx();
       
   211 		uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
       
   212 		int32 windowSub = bwin->GetFbX() * BPP +
       
   213 						  bwin->GetFbY() * windowPitch;
       
   214 		clipping_rect *clips = bwin->GetClips();
       
   215 		int32 numClips = bwin->GetNumClips();
       
   216 		int i, y;
       
   217 
       
   218 		/* Blit each clipping rectangle */
       
   219 		bscreen.WaitForRetrace();
       
   220 		for(i = 0; i < numClips; ++i) {
       
   221 			clipping_rect rc = clips[i];
       
   222 			/* Get addresses of the start of each clipping rectangle */
       
   223 			int32 width = clips[i].right - clips[i].left + 1;
       
   224 			int32 height = clips[i].bottom - clips[i].top + 1;
       
   225 			bufferpx = bwin->GetBufferPx() + 
       
   226 				clips[i].top * bufferPitch + clips[i].left * BPP;
       
   227 			windowpx = windowBaseAddress + 
       
   228 				clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
       
   229 
       
   230 			/* Copy each row of pixels from the window buffer into the frame
       
   231 			   buffer */
       
   232 			for(y = 0; y < height; ++y)
       
   233 			{
       
   234 				memcpy(bufferpx, windowpx, width * BPP);
       
   235 				bufferpx += bufferPitch;
       
   236 				windowpx += windowPitch;
       
   237 			}
       
   238 		}
       
   239 		bwin->UnlockBuffer();
       
   240 	}
       
   241 	return 0;
       
   242 }
       
   243 
   186 #ifdef __cplusplus
   244 #ifdef __cplusplus
   187 }
   245 }
   188 #endif
   246 #endif