Commit 41cbb17d authored by Nathan Heisey's avatar Nathan Heisey

Render thread partially corrected

parent bf4cf189
...@@ -345,7 +345,7 @@ private: ...@@ -345,7 +345,7 @@ private:
} }
win = GetSDLWindow(winID); win = GetSDLWindow(winID);
SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h); SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h);
/* FIXME: Attempt at fixing rendering problems */ /* FIXME: Attempt at fixing rendering problems */
BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); BE_UpdateWindowFramebuffer(NULL,win,NULL,-1);
} }
...@@ -356,66 +356,28 @@ private: ...@@ -356,66 +356,28 @@ private:
/* Vector imitators */ /* Vector functions: Wraps vector stuff in case we need to change
implementation */
void _SetSDLWindow(SDL_Window *win, int32 winID) { void _SetSDLWindow(SDL_Window *win, int32 winID) {
window_map[winID] = win; window_map[winID] = win;
} }
int32 _GetNumWindowSlots() { int32 _GetNumWindowSlots() {
#ifdef __cplusplus
return window_map.size(); return window_map.size();
#else
return _size;
#endif
} }
void _PopBackWindow() { void _PopBackWindow() {
#ifdef __cplusplus
window_map.pop_back(); window_map.pop_back();
#else
--_size;
#endif
} }
void _PushBackWindow(SDL_Window *win) { void _PushBackWindow(SDL_Window *win) {
#ifdef __cplusplus
window_map.push_back(win); 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 */ /* Members */
#ifdef __cplusplus
vector<SDL_Window*> window_map; /* Keeps track of SDL_Windows by index-id */ 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; display_mode *saved_mode;
}; };
......
...@@ -77,14 +77,13 @@ class SDL_BWin:public BDirectWindow ...@@ -77,14 +77,13 @@ class SDL_BWin:public BDirectWindow
/* Handle framebuffer stuff */ /* Handle framebuffer stuff */
_connected = _connection_disabled = false; _connected = _connection_disabled = false;
_buffer_created = _buffer_dirty = false; _buffer_created = _buffer_dirty = false;
_trash__window_buffer = false; _trash_window_buffer = false;
_buffer_locker = new BLocker(); _buffer_locker = new BLocker();
_window_buffer = NULL; _window_buffer = NULL;
_draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread", _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread",
B_NORMAL_PRIORITY, (void*) this); B_NORMAL_PRIORITY, (void*) this);
resume_thread(_draw_thread_id); resume_thread(_draw_thread_id);
// LockBuffer(); /* Unlocked by buffer initialization */
} }
virtual ~ SDL_BWin() virtual ~ SDL_BWin()
...@@ -153,8 +152,13 @@ class SDL_BWin:public BDirectWindow ...@@ -153,8 +152,13 @@ class SDL_BWin:public BDirectWindow
if(!_connected && _connection_disabled) { if(!_connected && _connection_disabled) {
return; 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(); LockBuffer();
switch(info->buffer_state & B_DIRECT_MODE_MASK) { switch(info->buffer_state & B_DIRECT_MODE_MASK) {
case B_DIRECT_START: case B_DIRECT_START:
_connected = true; _connected = true;
...@@ -165,12 +169,6 @@ class SDL_BWin:public BDirectWindow ...@@ -165,12 +169,6 @@ class SDL_BWin:public BDirectWindow
_clips = NULL; _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; _num_clips = info->clip_list_count;
_clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect)); _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect));
if(_clips) { if(_clips) {
...@@ -181,16 +179,18 @@ class SDL_BWin:public BDirectWindow ...@@ -181,16 +179,18 @@ class SDL_BWin:public BDirectWindow
_row_bytes = info->bytes_per_row; _row_bytes = info->bytes_per_row;
_bounds = info->window_bounds; _bounds = info->window_bounds;
_bytes_per_px = info->bits_per_pixel / 8; _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; break;
case B_DIRECT_STOP: case B_DIRECT_STOP:
_connected = false; _connected = false;
break; break;
} }
UnlockBuffer(); UnlockBuffer();
} }
...@@ -401,17 +401,18 @@ class SDL_BWin:public BDirectWindow ...@@ -401,17 +401,18 @@ class SDL_BWin:public BDirectWindow
uint8* GetBufferPx() { return _bits; } uint8* GetBufferPx() { return _bits; }
int32 GetBytesPerPx() { return _bytes_per_px; } int32 GetBytesPerPx() { return _bytes_per_px; }
uint8* GetWindowFramebuffer() { return _window_buffer; } uint8* GetWindowFramebuffer() { return _window_buffer; }
bool CanTrashWindowBuffer() { return _trash__window_buffer; } bool CanTrashWindowBuffer() { return _trash_window_buffer; }
bool BufferExists() { return _buffer_created; } bool BufferExists() { return _buffer_created; }
bool BufferIsDirty() { return _buffer_dirty; } bool BufferIsDirty() { return _buffer_dirty; }
/* Setter methods */ /* Setter methods */
void SetID(int32 id) { _id = id; } 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 SetWindowFramebuffer(uint8* fb) { _window_buffer = fb; }
void LockBuffer() { _buffer_locker->Lock(); } void LockBuffer() { _buffer_locker->Lock(); }
void UnlockBuffer() { _buffer_locker->Unlock(); } void UnlockBuffer() { _buffer_locker->Unlock(); }
void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; } void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; }
void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; }
...@@ -603,7 +604,7 @@ private: ...@@ -603,7 +604,7 @@ private:
int32 _num_clips; int32 _num_clips;
int32 _bytes_per_px; 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; bool _trash_window_buffer;
thread_id _draw_thread_id; thread_id _draw_thread_id;
}; };
......
...@@ -149,10 +149,10 @@ void BE_InitOSKeymap() { ...@@ -149,10 +149,10 @@ void BE_InitOSKeymap() {
keymap[0x63] = SDL_GetScancodeFromKey(SDLK_RIGHT); keymap[0x63] = SDL_GetScancodeFromKey(SDLK_RIGHT);
keymap[0x64] = SDL_GetScancodeFromKey(SDLK_KP_0); keymap[0x64] = SDL_GetScancodeFromKey(SDLK_KP_0);
keymap[0x65] = SDL_GetScancodeFromKey(SDLK_KP_PERIOD); keymap[0x65] = SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI); /* FIXME: Is this the right translation? */ keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI);
keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI); /* FIXME: Is this the right translation? */ keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI);
keymap[0x68] = SDL_GetScancodeFromKey(SDLK_MENU); 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[0x6a] = SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
keymap[0x6b] = SDL_GetScancodeFromKey(SDLK_POWER); keymap[0x6b] = SDL_GetScancodeFromKey(SDLK_POWER);
} }
......
...@@ -217,12 +217,12 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, ...@@ -217,12 +217,12 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
if(!bscreen.IsValid()) { if(!bscreen.IsValid()) {
return -1; return -1;
} }
while(!bwin->Connected()) { snooze(100); }
while(!bwin->Connected()) { snooze(100); }
/* Make sure we have exclusive access to frame buffer data */ /* Make sure we have exclusive access to frame buffer data */
bwin->LockBuffer(); bwin->LockBuffer();
/* format */ /* format */
display_mode bmode; display_mode bmode;
bscreen.GetMode(&bmode); bscreen.GetMode(&bmode);
...@@ -234,16 +234,15 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, ...@@ -234,16 +234,15 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
/* Create a copy of the pixel buffer if it doesn't recycle */ /* Create a copy of the pixel buffer if it doesn't recycle */
*pixels = bwin->GetWindowFramebuffer(); *pixels = bwin->GetWindowFramebuffer();
if( bwin->CanTrashWindowBuffer() || (*pixels) == NULL) { if( (*pixels) != NULL ) {
if( (*pixels) != NULL ) { SDL_free(*pixels);
SDL_free(*pixels);
}
*pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() *
bwin->GetBytesPerPx(), sizeof(uint8));
bwin->SetWindowFramebuffer((uint8*)(*pixels));
} }
*pixels = SDL_calloc((*pitch) * bwin->GetFbHeight() *
bwin->GetBytesPerPx(), sizeof(uint8));
bwin->SetWindowFramebuffer((uint8*)(*pixels));
bwin->SetBufferExists(true); bwin->SetBufferExists(true);
bwin->SetTrashBuffer(false);
bwin->UnlockBuffer(); bwin->UnlockBuffer();
return 0; return 0;
} }
...@@ -305,15 +304,19 @@ int32 BE_DrawThread(void *data) { ...@@ -305,15 +304,19 @@ int32 BE_DrawThread(void *data) {
buffer */ buffer */
for(y = 0; y < height; ++y) for(y = 0; y < height; ++y)
{ {
if(bwin->CanTrashWindowBuffer()) {
goto escape; /* Break out before the buffer is killed */
}
memcpy(bufferpx, windowpx, width * BPP); memcpy(bufferpx, windowpx, width * BPP);
bufferpx += bufferPitch; bufferpx += bufferPitch;
windowpx += windowPitch; windowpx += windowPitch;
} }
} }
bwin->SetBufferDirty(false); bwin->SetBufferDirty(false);
escape:
bwin->UnlockBuffer(); bwin->UnlockBuffer();
} else { } else {
snooze(1000); snooze(16000);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment