src/video/haiku/SDL_bframebuffer.cc
changeset 12201 8bdc4d340419
parent 12082 09999a0e8f9a
child 12503 806492103856
     1.1 --- a/src/video/haiku/SDL_bframebuffer.cc	Sat Aug 18 17:23:40 2018 -0400
     1.2 +++ b/src/video/haiku/SDL_bframebuffer.cc	Mon Sep 24 11:49:25 2018 -0700
     1.3 @@ -40,158 +40,158 @@
     1.4  #endif
     1.5  
     1.6  static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
     1.7 -	return ((SDL_BWin*)(window->driverdata));
     1.8 +    return ((SDL_BWin*)(window->driverdata));
     1.9  }
    1.10  
    1.11  static SDL_INLINE SDL_BApp *_GetBeApp() {
    1.12 -	return ((SDL_BApp*)be_app);
    1.13 +    return ((SDL_BApp*)be_app);
    1.14  }
    1.15  
    1.16  int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window * window,
    1.17                                         Uint32 * format,
    1.18                                         void ** pixels, int *pitch) {
    1.19 -	SDL_BWin *bwin = _ToBeWin(window);
    1.20 -	BScreen bscreen;
    1.21 -	if(!bscreen.IsValid()) {
    1.22 -		return -1;
    1.23 -	}
    1.24 +    SDL_BWin *bwin = _ToBeWin(window);
    1.25 +    BScreen bscreen;
    1.26 +    if(!bscreen.IsValid()) {
    1.27 +        return -1;
    1.28 +    }
    1.29  
    1.30 -	while(!bwin->Connected()) { snooze(100); }
    1.31 -	
    1.32 -	/* Make sure we have exclusive access to frame buffer data */
    1.33 -	bwin->LockBuffer();
    1.34 +    while(!bwin->Connected()) { snooze(100); }
    1.35 +    
    1.36 +    /* Make sure we have exclusive access to frame buffer data */
    1.37 +    bwin->LockBuffer();
    1.38  
    1.39 -	/* format */
    1.40 -	display_mode bmode;
    1.41 -	bscreen.GetMode(&bmode);
    1.42 -	int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode.space);
    1.43 -	*format = HAIKU_BPPToSDLPxFormat(bpp);
    1.44 +    /* format */
    1.45 +    display_mode bmode;
    1.46 +    bscreen.GetMode(&bmode);
    1.47 +    int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode.space);
    1.48 +    *format = HAIKU_BPPToSDLPxFormat(bpp);
    1.49  
    1.50 -	/* Create the new bitmap object */
    1.51 -	BBitmap *bitmap = bwin->GetBitmap();
    1.52 +    /* Create the new bitmap object */
    1.53 +    BBitmap *bitmap = bwin->GetBitmap();
    1.54  
    1.55 -	if(bitmap) {
    1.56 -		delete bitmap;
    1.57 -	}
    1.58 -	bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
    1.59 -			false,	/* Views not accepted */
    1.60 -			true);	/* Contiguous memory required */
    1.61 -			
    1.62 -	if(bitmap->InitCheck() != B_OK) {
    1.63 -		delete bitmap;
    1.64 -		return SDL_SetError("Could not initialize back buffer!");
    1.65 -	}
    1.66 +    if(bitmap) {
    1.67 +        delete bitmap;
    1.68 +    }
    1.69 +    bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
    1.70 +            false,    /* Views not accepted */
    1.71 +            true);    /* Contiguous memory required */
    1.72 +            
    1.73 +    if(bitmap->InitCheck() != B_OK) {
    1.74 +        delete bitmap;
    1.75 +        return SDL_SetError("Could not initialize back buffer!");
    1.76 +    }
    1.77  
    1.78  
    1.79 -	bwin->SetBitmap(bitmap);
    1.80 -	
    1.81 -	/* Set the pixel pointer */
    1.82 -	*pixels = bitmap->Bits();
    1.83 +    bwin->SetBitmap(bitmap);
    1.84 +    
    1.85 +    /* Set the pixel pointer */
    1.86 +    *pixels = bitmap->Bits();
    1.87  
    1.88 -	/* pitch = width of window, in bytes */
    1.89 -	*pitch = bitmap->BytesPerRow();
    1.90 +    /* pitch = width of window, in bytes */
    1.91 +    *pitch = bitmap->BytesPerRow();
    1.92  
    1.93 -	bwin->SetBufferExists(true);
    1.94 -	bwin->SetTrashBuffer(false);
    1.95 -	bwin->UnlockBuffer();
    1.96 -	return 0;
    1.97 +    bwin->SetBufferExists(true);
    1.98 +    bwin->SetTrashBuffer(false);
    1.99 +    bwin->UnlockBuffer();
   1.100 +    return 0;
   1.101  }
   1.102  
   1.103  
   1.104  
   1.105  int HAIKU_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
   1.106                                        const SDL_Rect * rects, int numrects) {
   1.107 -	if(!window)
   1.108 -		return 0;
   1.109 +    if(!window)
   1.110 +        return 0;
   1.111  
   1.112 -	SDL_BWin *bwin = _ToBeWin(window);
   1.113 +    SDL_BWin *bwin = _ToBeWin(window);
   1.114  
   1.115 -#ifdef DRAWTHREAD	
   1.116 -	bwin->LockBuffer();
   1.117 -	bwin->SetBufferDirty(true);
   1.118 -	bwin->UnlockBuffer();
   1.119 +#ifdef DRAWTHREAD    
   1.120 +    bwin->LockBuffer();
   1.121 +    bwin->SetBufferDirty(true);
   1.122 +    bwin->UnlockBuffer();
   1.123  #else
   1.124 -	bwin->SetBufferDirty(true);
   1.125 -	HAIKU_UpdateOnce(window);
   1.126 +    bwin->SetBufferDirty(true);
   1.127 +    HAIKU_UpdateOnce(window);
   1.128  #endif
   1.129  
   1.130 -	return 0;
   1.131 +    return 0;
   1.132  }
   1.133  
   1.134  int32 HAIKU_DrawThread(void *data) {
   1.135 -	SDL_BWin *bwin = (SDL_BWin*)data;
   1.136 -	
   1.137 -	BScreen bscreen;
   1.138 -	if(!bscreen.IsValid()) {
   1.139 -		return -1;
   1.140 -	}
   1.141 +    SDL_BWin *bwin = (SDL_BWin*)data;
   1.142 +    
   1.143 +    BScreen bscreen;
   1.144 +    if(!bscreen.IsValid()) {
   1.145 +        return -1;
   1.146 +    }
   1.147  
   1.148 -	while(bwin->ConnectionEnabled()) {
   1.149 -		if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
   1.150 -			bwin->LockBuffer();
   1.151 -			BBitmap *bitmap = NULL;
   1.152 -			bitmap = bwin->GetBitmap();
   1.153 -			int32 windowPitch = bitmap->BytesPerRow();
   1.154 -			int32 bufferPitch = bwin->GetRowBytes();
   1.155 -			uint8 *windowpx;
   1.156 -			uint8 *bufferpx;
   1.157 +    while(bwin->ConnectionEnabled()) {
   1.158 +        if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
   1.159 +            bwin->LockBuffer();
   1.160 +            BBitmap *bitmap = NULL;
   1.161 +            bitmap = bwin->GetBitmap();
   1.162 +            int32 windowPitch = bitmap->BytesPerRow();
   1.163 +            int32 bufferPitch = bwin->GetRowBytes();
   1.164 +            uint8 *windowpx;
   1.165 +            uint8 *bufferpx;
   1.166  
   1.167 -			int32 BPP = bwin->GetBytesPerPx();
   1.168 -			int32 windowSub = bwin->GetFbX() * BPP +
   1.169 -						  bwin->GetFbY() * windowPitch;
   1.170 -			clipping_rect *clips = bwin->GetClips();
   1.171 -			int32 numClips = bwin->GetNumClips();
   1.172 -			int i, y;
   1.173 +            int32 BPP = bwin->GetBytesPerPx();
   1.174 +            int32 windowSub = bwin->GetFbX() * BPP +
   1.175 +                          bwin->GetFbY() * windowPitch;
   1.176 +            clipping_rect *clips = bwin->GetClips();
   1.177 +            int32 numClips = bwin->GetNumClips();
   1.178 +            int i, y;
   1.179  
   1.180 -			/* Blit each clipping rectangle */
   1.181 -			bscreen.WaitForRetrace();
   1.182 -			for(i = 0; i < numClips; ++i) {
   1.183 -				/* Get addresses of the start of each clipping rectangle */
   1.184 -				int32 width = clips[i].right - clips[i].left + 1;
   1.185 -				int32 height = clips[i].bottom - clips[i].top + 1;
   1.186 -				bufferpx = bwin->GetBufferPx() + 
   1.187 -					clips[i].top * bufferPitch + clips[i].left * BPP;
   1.188 -				windowpx = (uint8*)bitmap->Bits() + 
   1.189 -					clips[i].top * windowPitch + clips[i].left * BPP -
   1.190 -					windowSub;
   1.191 +            /* Blit each clipping rectangle */
   1.192 +            bscreen.WaitForRetrace();
   1.193 +            for(i = 0; i < numClips; ++i) {
   1.194 +                /* Get addresses of the start of each clipping rectangle */
   1.195 +                int32 width = clips[i].right - clips[i].left + 1;
   1.196 +                int32 height = clips[i].bottom - clips[i].top + 1;
   1.197 +                bufferpx = bwin->GetBufferPx() + 
   1.198 +                    clips[i].top * bufferPitch + clips[i].left * BPP;
   1.199 +                windowpx = (uint8*)bitmap->Bits() + 
   1.200 +                    clips[i].top * windowPitch + clips[i].left * BPP -
   1.201 +                    windowSub;
   1.202  
   1.203 -				/* Copy each row of pixels from the window buffer into the frame
   1.204 -				   buffer */
   1.205 -				for(y = 0; y < height; ++y)
   1.206 -				{
   1.207 +                /* Copy each row of pixels from the window buffer into the frame
   1.208 +                   buffer */
   1.209 +                for(y = 0; y < height; ++y)
   1.210 +                {
   1.211  
   1.212 -					if(bwin->CanTrashWindowBuffer()) {
   1.213 -						goto escape;	/* Break out before the buffer is killed */
   1.214 -					}
   1.215 +                    if(bwin->CanTrashWindowBuffer()) {
   1.216 +                        goto escape;    /* Break out before the buffer is killed */
   1.217 +                    }
   1.218  
   1.219 -					memcpy(bufferpx, windowpx, width * BPP);
   1.220 -					bufferpx += bufferPitch;
   1.221 -					windowpx += windowPitch;
   1.222 -				}
   1.223 -			}
   1.224 +                    memcpy(bufferpx, windowpx, width * BPP);
   1.225 +                    bufferpx += bufferPitch;
   1.226 +                    windowpx += windowPitch;
   1.227 +                }
   1.228 +            }
   1.229  
   1.230 -			bwin->SetBufferDirty(false);
   1.231 +            bwin->SetBufferDirty(false);
   1.232  escape:
   1.233 -			bwin->UnlockBuffer();
   1.234 -		} else {
   1.235 -			snooze(16000);
   1.236 -		}
   1.237 -	}
   1.238 -	
   1.239 -	return B_OK;
   1.240 +            bwin->UnlockBuffer();
   1.241 +        } else {
   1.242 +            snooze(16000);
   1.243 +        }
   1.244 +    }
   1.245 +    
   1.246 +    return B_OK;
   1.247  }
   1.248  
   1.249  void HAIKU_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
   1.250 -	SDL_BWin *bwin = _ToBeWin(window);
   1.251 -	
   1.252 -	bwin->LockBuffer();
   1.253 -	
   1.254 -	/* Free and clear the window buffer */
   1.255 -	BBitmap *bitmap = bwin->GetBitmap();
   1.256 -	delete bitmap;
   1.257 -	bwin->SetBitmap(NULL);
   1.258 -	bwin->SetBufferExists(false);
   1.259 -	bwin->UnlockBuffer();
   1.260 +    SDL_BWin *bwin = _ToBeWin(window);
   1.261 +    
   1.262 +    bwin->LockBuffer();
   1.263 +    
   1.264 +    /* Free and clear the window buffer */
   1.265 +    BBitmap *bitmap = bwin->GetBitmap();
   1.266 +    delete bitmap;
   1.267 +    bwin->SetBitmap(NULL);
   1.268 +    bwin->SetBufferExists(false);
   1.269 +    bwin->UnlockBuffer();
   1.270  }
   1.271  
   1.272  
   1.273 @@ -203,50 +203,50 @@
   1.274   */
   1.275  #ifndef DRAWTHREAD
   1.276  static int32 HAIKU_UpdateOnce(SDL_Window *window) {
   1.277 -	SDL_BWin *bwin = _ToBeWin(window);
   1.278 -	BScreen bscreen;
   1.279 -	if(!bscreen.IsValid()) {
   1.280 -		return -1;
   1.281 -	}
   1.282 +    SDL_BWin *bwin = _ToBeWin(window);
   1.283 +    BScreen bscreen;
   1.284 +    if(!bscreen.IsValid()) {
   1.285 +        return -1;
   1.286 +    }
   1.287  
   1.288 -	if(bwin->ConnectionEnabled() && bwin->Connected()) {
   1.289 -		bwin->LockBuffer();
   1.290 -		int32 windowPitch = window->surface->pitch;
   1.291 -		int32 bufferPitch = bwin->GetRowBytes();
   1.292 -		uint8 *windowpx;
   1.293 -		uint8 *bufferpx;
   1.294 +    if(bwin->ConnectionEnabled() && bwin->Connected()) {
   1.295 +        bwin->LockBuffer();
   1.296 +        int32 windowPitch = window->surface->pitch;
   1.297 +        int32 bufferPitch = bwin->GetRowBytes();
   1.298 +        uint8 *windowpx;
   1.299 +        uint8 *bufferpx;
   1.300  
   1.301 -		int32 BPP = bwin->GetBytesPerPx();
   1.302 -		uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
   1.303 -		int32 windowSub = bwin->GetFbX() * BPP +
   1.304 -						  bwin->GetFbY() * windowPitch;
   1.305 -		clipping_rect *clips = bwin->GetClips();
   1.306 -		int32 numClips = bwin->GetNumClips();
   1.307 -		int i, y;
   1.308 +        int32 BPP = bwin->GetBytesPerPx();
   1.309 +        uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
   1.310 +        int32 windowSub = bwin->GetFbX() * BPP +
   1.311 +                          bwin->GetFbY() * windowPitch;
   1.312 +        clipping_rect *clips = bwin->GetClips();
   1.313 +        int32 numClips = bwin->GetNumClips();
   1.314 +        int i, y;
   1.315  
   1.316 -		/* Blit each clipping rectangle */
   1.317 -		bscreen.WaitForRetrace();
   1.318 -		for(i = 0; i < numClips; ++i) {
   1.319 -			/* Get addresses of the start of each clipping rectangle */
   1.320 -			int32 width = clips[i].right - clips[i].left + 1;
   1.321 -			int32 height = clips[i].bottom - clips[i].top + 1;
   1.322 -			bufferpx = bwin->GetBufferPx() + 
   1.323 -				clips[i].top * bufferPitch + clips[i].left * BPP;
   1.324 -			windowpx = windowBaseAddress + 
   1.325 -				clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
   1.326 +        /* Blit each clipping rectangle */
   1.327 +        bscreen.WaitForRetrace();
   1.328 +        for(i = 0; i < numClips; ++i) {
   1.329 +            /* Get addresses of the start of each clipping rectangle */
   1.330 +            int32 width = clips[i].right - clips[i].left + 1;
   1.331 +            int32 height = clips[i].bottom - clips[i].top + 1;
   1.332 +            bufferpx = bwin->GetBufferPx() + 
   1.333 +                clips[i].top * bufferPitch + clips[i].left * BPP;
   1.334 +            windowpx = windowBaseAddress + 
   1.335 +                clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
   1.336  
   1.337 -			/* Copy each row of pixels from the window buffer into the frame
   1.338 -			   buffer */
   1.339 -			for(y = 0; y < height; ++y)
   1.340 -			{
   1.341 -				memcpy(bufferpx, windowpx, width * BPP);
   1.342 -				bufferpx += bufferPitch;
   1.343 -				windowpx += windowPitch;
   1.344 -			}
   1.345 -		}
   1.346 -		bwin->UnlockBuffer();
   1.347 -	}
   1.348 -	return 0;
   1.349 +            /* Copy each row of pixels from the window buffer into the frame
   1.350 +               buffer */
   1.351 +            for(y = 0; y < height; ++y)
   1.352 +            {
   1.353 +                memcpy(bufferpx, windowpx, width * BPP);
   1.354 +                bufferpx += bufferPitch;
   1.355 +                windowpx += windowPitch;
   1.356 +            }
   1.357 +        }
   1.358 +        bwin->UnlockBuffer();
   1.359 +    }
   1.360 +    return 0;
   1.361  }
   1.362  #endif
   1.363