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

Render thread partially corrected

parent bf4cf189
......@@ -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) {
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;
};
......
......@@ -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()
......@@ -153,6 +152,11 @@ 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) {
......@@ -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) {
......@@ -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;
/* Whatever the case, I think this merits a repaint event */
// _RepaintEvent();
/* Now we check for a good buffer */
// SetBufferExists(!_trash_window_buffer);
}
break;
case B_DIRECT_STOP:
_connected = false;
break;
}
UnlockBuffer();
}
......@@ -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; }
......@@ -603,7 +604,7 @@ private:
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;
};
......
......@@ -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);
}
......
......@@ -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));
}
bwin->SetBufferExists(true);
bwin->SetTrashBuffer(false);
bwin->UnlockBuffer();
return 0;
}
......@@ -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);
}
}
......
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