use a timer on mac for smoother updates

This commit is contained in:
David Rose 2009-07-21 20:19:47 +00:00
parent b614a05a12
commit 865ea20789
2 changed files with 42 additions and 12 deletions

View File

@ -74,7 +74,8 @@ P3DInstance(P3D_request_ready_func *func, void *user_data) :
_shared_mmap_size = 0;
_swbuffer = NULL;
_reversed_buffer = NULL;
_mouse_active = false;
_mouse_active = true;
_frame_timer = NULL;
#endif // __APPLE__
// Set some initial properties.
@ -110,6 +111,11 @@ P3DInstance::
}
#ifdef __APPLE__
if (_frame_timer != NULL) {
CFRunLoopTimerInvalidate(_frame_timer);
CFRelease(_frame_timer);
}
if (_swbuffer != NULL) {
SubprocessWindowBuffer::destroy_buffer(_shared_fd, _shared_mmap_size,
_shared_filename, _swbuffer);
@ -510,17 +516,6 @@ handle_event(P3D_event_data event) {
bool keep_event = false;
switch (er->what) {
case nullEvent:
// We appear to get this event pretty frequently when nothing else
// is going on. Great; we'll take advantage of it to request a
// refresh, which will cause updateEvt to be triggered (if the
// instance is still onscreen).
if (_instance_window_opened && _swbuffer != NULL && _swbuffer->ready_for_read()) {
request_refresh();
}
keep_event = true;
break;
case mouseDown:
case mouseUp:
{
@ -828,6 +823,18 @@ handle_notify_request(const string &message) {
delete _splash_window;
_splash_window = NULL;
}
#ifdef __APPLE__
// Start a timer to update the frame repeatedly. This seems to be
// steadier than waiting for nullEvent.
CFRunLoopTimerContext timer_context;
memset(&timer_context, 0, sizeof(timer_context));
timer_context.info = this;
_frame_timer = CFRunLoopTimerCreate
(NULL, 0, 1.0 / 60.0, 0, 0, timer_callback, &timer_context);
CFRunLoopRef run_loop = CFRunLoopGetCurrent();
CFRunLoopAddTimer(run_loop, _frame_timer, kCFRunLoopCommonModes);
#endif // __APPLE__
}
}
@ -1163,6 +1170,22 @@ add_modifier_flags(unsigned int &swb_flags, int modifiers) {
#endif // __APPLE__
}
#ifdef __APPLE__
////////////////////////////////////////////////////////////////////
// Function: P3DInstance::timer_callback
// Access: Private
// Description: OSX only: this callback is associated with a
// CFRunLoopTimer, to be called periodically for
// updating the frame.
////////////////////////////////////////////////////////////////////
void P3DInstance::
timer_callback(CFRunLoopTimerRef timer, void *info) {
P3DInstance *self = (P3DInstance *)info;
self->request_refresh();
//self->paint_window();
}
#endif // __APPLE__
////////////////////////////////////////////////////////////////////
// Function: P3DInstance::SplashDownload::Constructor
// Access: Public

View File

@ -24,6 +24,7 @@
#ifdef __APPLE__
#include "subprocessWindowBuffer.h"
#include <CoreFoundation/CoreFoundation.h>
#endif
#include <deque>
@ -110,6 +111,10 @@ private:
void paint_window();
void add_modifier_flags(unsigned int &swb_flags, int modifiers);
#ifdef __APPLE__
static void timer_callback(CFRunLoopTimerRef timer, void *info);
#endif // __APPLE__
P3D_request_ready_func *_func;
P3D_object *_browser_script_object;
P3DToplevelObject *_panda_script_object;
@ -137,6 +142,8 @@ private:
SubprocessWindowBuffer *_swbuffer;
char *_reversed_buffer;
bool _mouse_active;
CFRunLoopTimerRef _frame_timer;
#endif // __APPLE__
P3DSplashWindow *_splash_window;