Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Render thread partially corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
antifinidictor committed Jul 28, 2011
1 parent 722973e commit 9ff5078
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 70 deletions.
44 changes: 3 additions & 41 deletions src/main/beos/SDL_BApp.h
Expand Up @@ -345,7 +345,7 @@ class SDL_BApp : public BApplication {
}
win = GetSDLWindow(winID);
SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h);

/* FIXME: Attempt at fixing rendering problems */
BE_UpdateWindowFramebuffer(NULL,win,NULL,-1);
}
Expand All @@ -356,66 +356,28 @@ class SDL_BApp : public BApplication {



/* Vector imitators */
/* Vector functions: Wraps vector stuff in case we need to change
implementation */
void _SetSDLWindow(SDL_Window *win, int32 winID) {
window_map[winID] = win;
}

int32 _GetNumWindowSlots() {
#ifdef __cplusplus
return window_map.size();
#else
return _size;
#endif
}


void _PopBackWindow() {
#ifdef __cplusplus
window_map.pop_back();
#else
--_size;
#endif
}

void _PushBackWindow(SDL_Window *win) {
#ifdef __cplusplus
window_map.push_back(win);
#else
/* Resize array */
if(_length == _size) {
_ResizeArray();
}

window_map[_size] = win;
++_size;
#endif
}

#ifndef __cplusplus
_ResizeArray() {
_length += 4; /* Increase capacity by some arbitrary number */
SDL_Window *temp = (SDL_Window*)SDL_calloc(_length,
sizeof(SDL_Window*));

/* Move windows from old list to new list */
int32 i;
for(i = 0; i < _size; ++i) {
temp[i] = window_map[i];
}
SDL_free(window_map);
window_map = temp;
}
#endif

/* Members */
#ifdef __cplusplus
vector<SDL_Window*> window_map; /* Keeps track of SDL_Windows by index-id */
#else
int32 _size;
int32 _length;
SDL_Window *window_map;
#endif

display_mode *saved_mode;
};
Expand Down
31 changes: 16 additions & 15 deletions src/video/bwindow/SDL_BWin.h
Expand Up @@ -77,14 +77,13 @@ class SDL_BWin:public BDirectWindow
/* Handle framebuffer stuff */
_connected = _connection_disabled = false;
_buffer_created = _buffer_dirty = false;
_trash__window_buffer = false;
_trash_window_buffer = false;
_buffer_locker = new BLocker();
_window_buffer = NULL;

_draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread",
B_NORMAL_PRIORITY, (void*) this);
resume_thread(_draw_thread_id);
// LockBuffer(); /* Unlocked by buffer initialization */
}

virtual ~ SDL_BWin()
Expand Down Expand Up @@ -153,8 +152,13 @@ class SDL_BWin:public BDirectWindow
if(!_connected && _connection_disabled) {
return;
}

/* Determine if the pixel buffer is usable after this update */
_trash_window_buffer = _trash_window_buffer
|| ((info->buffer_state & B_BUFFER_RESIZED)
|| (info->buffer_state & B_BUFFER_RESET));
LockBuffer();

switch(info->buffer_state & B_DIRECT_MODE_MASK) {
case B_DIRECT_START:
_connected = true;
Expand All @@ -165,12 +169,6 @@ class SDL_BWin:public BDirectWindow
_clips = NULL;
}

/* Can we reuse the window's pixel buffer after this? */
_trash__window_buffer = ((info->buffer_state & B_BUFFER_RESIZED)
|| (info->buffer_state & B_BUFFER_RESET)
|| ((info->buffer_state & B_DIRECT_MODE_MASK)
== B_DIRECT_START));

_num_clips = info->clip_list_count;
_clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect));
if(_clips) {
Expand All @@ -181,16 +179,18 @@ class SDL_BWin:public BDirectWindow
_row_bytes = info->bytes_per_row;
_bounds = info->window_bounds;
_bytes_per_px = info->bits_per_pixel / 8;
_buffer_dirty = true;

/* Now we check for a good buffer */
// SetBufferExists(!_trash_window_buffer);
}

/* Whatever the case, I think this merits a repaint event */
// _RepaintEvent();
break;

case B_DIRECT_STOP:
_connected = false;
break;
}

UnlockBuffer();
}

Expand Down Expand Up @@ -401,17 +401,18 @@ class SDL_BWin:public BDirectWindow
uint8* GetBufferPx() { return _bits; }
int32 GetBytesPerPx() { return _bytes_per_px; }
uint8* GetWindowFramebuffer() { return _window_buffer; }
bool CanTrashWindowBuffer() { return _trash__window_buffer; }
bool CanTrashWindowBuffer() { return _trash_window_buffer; }
bool BufferExists() { return _buffer_created; }
bool BufferIsDirty() { return _buffer_dirty; }

/* Setter methods */
void SetID(int32 id) { _id = id; }
bool SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; }
void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; }
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; }



Expand Down Expand Up @@ -603,7 +604,7 @@ class SDL_BWin:public BDirectWindow
int32 _num_clips;
int32 _bytes_per_px;
uint8 *_window_buffer; /* A copy of the window buffer */
bool _trash__window_buffer;
bool _trash_window_buffer;
thread_id _draw_thread_id;
};

Expand Down
6 changes: 3 additions & 3 deletions src/video/bwindow/SDL_bkeyboard.cc
Expand Up @@ -149,10 +149,10 @@ void BE_InitOSKeymap() {
keymap[0x63] = SDL_GetScancodeFromKey(SDLK_RIGHT);
keymap[0x64] = SDL_GetScancodeFromKey(SDLK_KP_0);
keymap[0x65] = SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI); /* FIXME: Is this the right translation? */
keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI); /* FIXME: Is this the right translation? */
keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI);
keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI);
keymap[0x68] = SDL_GetScancodeFromKey(SDLK_MENU);
keymap[0x69] = SDL_GetScancodeFromKey(SDLK_UNKNOWN); /* FIXME: I couldn't find a translation */
keymap[0x69] = SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */
keymap[0x6a] = SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
keymap[0x6b] = SDL_GetScancodeFromKey(SDLK_POWER);
}
Expand Down
25 changes: 14 additions & 11 deletions src/video/bwindow/SDL_bmodes.cc
Expand Up @@ -217,12 +217,12 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
if(!bscreen.IsValid()) {
return -1;
}

while(!bwin->Connected()) { snooze(100); }

while(!bwin->Connected()) { snooze(100); }

/* Make sure we have exclusive access to frame buffer data */
bwin->LockBuffer();

/* format */
display_mode bmode;
bscreen.GetMode(&bmode);
Expand All @@ -234,16 +234,15 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,

/* Create a copy of the pixel buffer if it doesn't recycle */
*pixels = bwin->GetWindowFramebuffer();
if( bwin->CanTrashWindowBuffer() || (*pixels) == NULL) {
if( (*pixels) != NULL ) {
SDL_free(*pixels);
}
*pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() *
bwin->GetBytesPerPx(), sizeof(uint8));
bwin->SetWindowFramebuffer((uint8*)(*pixels));
if( (*pixels) != NULL ) {
SDL_free(*pixels);
}
*pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() *
bwin->GetBytesPerPx(), sizeof(uint8));
bwin->SetWindowFramebuffer((uint8*)(*pixels));

bwin->SetBufferExists(true);
bwin->SetTrashBuffer(false);
bwin->UnlockBuffer();
return 0;
}
Expand Down Expand Up @@ -305,15 +304,19 @@ int32 BE_DrawThread(void *data) {
buffer */
for(y = 0; y < height; ++y)
{
if(bwin->CanTrashWindowBuffer()) {
goto escape; /* Break out before the buffer is killed */
}
memcpy(bufferpx, windowpx, width * BPP);
bufferpx += bufferPitch;
windowpx += windowPitch;
}
}
bwin->SetBufferDirty(false);
escape:
bwin->UnlockBuffer();
} else {
snooze(1000);
snooze(16000);
}
}

Expand Down

0 comments on commit 9ff5078

Please sign in to comment.