fix onwindowattach/detach for mac

This commit is contained in:
David Rose 2009-11-13 01:20:52 +00:00
parent aea6f4c9e8
commit db28251d40
5 changed files with 46 additions and 23 deletions

View File

@ -2385,11 +2385,17 @@ free_pointers() {
////////////////////////////////////////////////////////////////////
void GraphicsStateGuardian::
close_gsg() {
// Protect from multiple calls, and also inform any other functions
// not to try to create new stuff while we're going down.
if (_closing_gsg) {
return;
}
_closing_gsg = true;
if (display_cat.is_debug()) {
display_cat.debug()
<< this << " close_gsg " << get_type() << "\n";
}
_closing_gsg = true;
free_pointers();
// As tempting as it may be to try to release all the textures and

View File

@ -345,6 +345,14 @@ internal_close_window() {
_buffer = NULL;
}
// Tell our parent window (if any) that we're no longer its child.
if (_window_handle != (WindowHandle *)NULL &&
_parent_window_handle != (WindowHandle *)NULL) {
_parent_window_handle->detach_child(_window_handle);
}
_window_handle = NULL;
_parent_window_handle = NULL;
_is_valid = false;
}
@ -395,6 +403,7 @@ internal_open_window() {
}
}
}
_parent_window_handle = window_handle;
if (_filename.empty()) {
_is_valid = false;
@ -422,6 +431,14 @@ internal_open_window() {
<< "SubprocessWindow reading " << _filename << "\n";
}
// Create a WindowHandle for ourselves
_window_handle = NativeWindowHandle::make_subprocess(_filename);
// And tell our parent window that we're now its child.
if (_parent_window_handle != (WindowHandle *)NULL) {
_parent_window_handle->attach_child(_window_handle);
}
return true;
}

View File

@ -157,11 +157,7 @@ destroy_buffer(int fd, size_t mmap_size, const string &filename,
buffer->~SubprocessWindowBuffer();
close_buffer(fd, mmap_size, filename, buffer);
// This isn't really necessary, since our child process should have
// unlinked it; but we do it anyway just for good measure (for
// instance, in case the child process never got started). I
// suppose there is some risk that we will accidentally delete
// someone else's file this way, but the risk is small.
// Now we can unlink the file.
unlink(filename.c_str());
}
@ -243,7 +239,10 @@ open_buffer(int &fd, size_t &mmap_size, const string &filename) {
// Now that we've successfully opened and mapped the file, we can
// safely delete it from the file system.
unlink(filename.c_str());
// Actually, unlinking it now prevents us from detaching and
// reattaching to the same file later. Boo.
// unlink(filename.c_str());
SubprocessWindowBuffer *buffer = (SubprocessWindowBuffer *)shared_mem;
assert(buffer->_mmap_size == mmap_size);
@ -263,9 +262,6 @@ close_buffer(int fd, size_t mmap_size, const string &filename,
SubprocessWindowBuffer *buffer) {
munmap((void *)buffer, mmap_size);
close(fd);
// Guess we shouldn't unlink() the file here, since we already did
// in open_buffer().
}
////////////////////////////////////////////////////////////////////

View File

@ -75,6 +75,7 @@ osxGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe,
osxGraphicsStateGuardian::
~osxGraphicsStateGuardian() {
if (_aglcontext != (AGLContext)NULL) {
aglSetCurrentContext(NULL);
aglDestroyContext(_aglcontext);
report_agl_error("aglDestroyContext");
_aglcontext = (AGLContext)NULL;

View File

@ -403,9 +403,16 @@ do_resize() {
<< " " << viewRect.size.height << "\n";
}
// ping gl
aglUpdateContext(aglGetCurrentContext());
report_agl_error("aglUpdateContext .. This is a Resize..");
AGLContext context = get_gsg_context();
if (context != (AGLContext)NULL) {
// ping gl
if (!aglSetCurrentContext(context)) {
report_agl_error("aglSetCurrentContext");
}
aglUpdateContext(context);
report_agl_error("aglUpdateContext .. This is a Resize..");
}
if (osxdisplay_cat.is_debug()) {
osxdisplay_cat.debug()
<< "Resize Complete.....\n";
@ -849,23 +856,19 @@ begin_frame(FrameMode mode, Thread *current_thread) {
if (_is_fullscreen) {
aglSetFullScreen(get_gsg_context(),0,0,0,0);
report_agl_error ("aglSetFullScreen");
if (!aglSetCurrentContext(get_gsg_context())) {
report_agl_error ("aglSetCurrentContext");
}
} else {
if (full_screen_window != NULL) {
return false;
}
if (!aglSetDrawable (get_gsg_context(), GetWindowPort (_osx_window))) {
if (!aglSetDrawable(get_gsg_context(), GetWindowPort (_osx_window))) {
report_agl_error("aglSetDrawable");
}
if (!aglSetCurrentContext(get_gsg_context())) {
report_agl_error ("aglSetCurrentContext");
}
}
if (!aglSetCurrentContext(get_gsg_context())) {
report_agl_error ("aglSetCurrentContext");
}
_gsg->reset_if_new();