|
From: John M M. <jo...@us...> - 2003-03-05 19:54:33
|
Update of /cvsroot/squeak/squeak/platforms/Mac OS/vm
In directory sc8-pr-cvs1:/tmp/cvs-serv18639/squeak/platforms/Mac OS/vm
Modified Files:
sqMacNSPlugin.c
Log Message:
3.5.0b4 Fix for safari plugin support. use real pthreads for os-x. Fix race conditions at startup time.
Index: sqMacNSPlugin.c
===================================================================
RCS file: /cvsroot/squeak/squeak/platforms/Mac OS/vm/sqMacNSPlugin.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** sqMacNSPlugin.c 8 Aug 2002 04:45:11 -0000 1.8
--- sqMacNSPlugin.c 5 Mar 2003 19:54:29 -0000 1.9
***************
*** 71,74 ****
--- 71,75 ----
#include "sqMacFileLogic.h"
#include "FilePlugin.h"
+ #include "sqMacTime.h"
#include "npapi.h"
***************
*** 108,112 ****
*
**********/
-
#define ENABLE_URL_FETCH
#define IMAGE_NAME "SqueakPlugin.image"
--- 109,112 ----
***************
*** 141,147 ****
#if PLUGIN_TRACE
! int printOnOSXPascal(unsigned char *msg);
! #define PLUGINDEBUGSTR(msg) printOnOSXPascal(msg);
! //#define PLUGINDEBUGSTR(msg) ::DebugStr(msg)
#else
#define PLUGINDEBUGSTR
--- 141,147 ----
#if PLUGIN_TRACE
! //int printOnOSXPascal(unsigned char *msg);
! //#define PLUGINDEBUGSTR(msg) printOnOSXPascal(msg);
! #define PLUGINDEBUGSTR(msg) DebugStr(msg)
#else
#define PLUGINDEBUGSTR
***************
*** 166,169 ****
--- 166,173 ----
extern int thisSession; /* from sqFilePrims.c: */
+ #if defined ( __APPLE__ ) && defined ( __MACH__ )
+ pthread_mutex_t gEventDrawLock;
+ extern TMTask gTMTask;
+ #endif
/*** Local Variables ***/
***************
*** 204,208 ****
/*** Functions Imported from sqMacWindow ***/
! void ioSetFullScreenRestore();
/*** From VM ***/
--- 208,212 ----
/*** Functions Imported from sqMacWindow ***/
! int ioSetFullScreenRestore();
/*** From VM ***/
***************
*** 310,314 ****
int16 argc, char* argn[], char* argv[], NPSavedData* saved) {
int i;
- long threadGestaltInfo;
OSErr err;
--- 314,317 ----
***************
*** 338,351 ****
gSavePortClipRgn = NewRgn();
- if ((Gestalt( gestaltThreadMgrAttr, &threadGestaltInfo) == noErr) &&
- threadGestaltInfo & (1<<gestaltThreadMgrPresent) &&
- ((Ptr) NewThread != (Ptr)kUnresolvedCFragSymbolAddress)) {
-
- gThreadManager = true;
- err = createNewThread();
- if (err != noErr)
- gThreadManager = false;
- }
-
return NPERR_NO_ERROR;
--- 341,344 ----
***************
*** 394,402 ****
NPError NPP_SetWindow(NPP instance, NPWindow* window) {
NP_Port* port;
!
! if (window == NULL) return NPERR_NO_ERROR;
! if (window->window == NULL) {
return NPERR_NO_ERROR;
! }
if (window->width == 0 && window->height == 0) {
if (gIWasRunning) {
--- 387,395 ----
NPError NPP_SetWindow(NPP instance, NPWindow* window) {
NP_Port* port;
! OSErr err;
!
! if (window == NULL || window->window == NULL)
return NPERR_NO_ERROR;
!
if (window->width == 0 && window->height == 0) {
if (gIWasRunning) {
***************
*** 407,418 ****
}
! gIWasRunning = true;
netscapeWindow = window;
port = (NP_Port *) netscapeWindow->window;
! stWindow = (WindowPtr) port->port;
needsUpdate = true;
ioLoadFunctionFrom(NULL, "DropPlugin");
if (gSqueakThread != kNoThreadID)
! SetThreadState (gSqueakThread,kReadyThreadState,kNoThreadID); //OK start Squeak
return NPERR_NO_ERROR;
--- 400,422 ----
}
!
netscapeWindow = window;
port = (NP_Port *) netscapeWindow->window;
! stWindow = GetWindowFromPort(port->port);
needsUpdate = true;
+
+ if (gIWasRunning)
+ return NPERR_NO_ERROR;
+ gIWasRunning = true;
+
ioLoadFunctionFrom(NULL, "DropPlugin");
+
+ gThreadManager = true;
+ err = createNewThread();
+ if (err != noErr)
+ gThreadManager = false;
+
if (gSqueakThread != kNoThreadID)
! SetThreadState (gSqueakThread,kReadyThreadState,kNoThreadID); //OK start Squeak (os-9)
return NPERR_NO_ERROR;
***************
*** 580,583 ****
--- 584,588 ----
}
+ if (gThreadManager)
SqueakYieldToAnyThread(); //Give some time up, needed for Netscape
***************
*** 686,694 ****
}
if (getFullScreenFlag()) {
! ok = WaitNextEvent(everyEvent, &theEvent,0,null);
eventPtr = &theEvent;
SqueakYieldToAnyThread();
}
} while (getFullScreenFlag());
return true;
}
--- 691,700 ----
}
if (getFullScreenFlag()) {
! ok = WaitNextEvent(everyEvent, &theEvent,1,null);
eventPtr = &theEvent;
SqueakYieldToAnyThread();
}
} while (getFullScreenFlag());
+
return true;
}
***************
*** 700,703 ****
--- 706,713 ----
SetClip(gSavePortClipRgn);
SetPort((GrafPtr) gOldPort);
+ #if defined ( __APPLE__ ) && defined ( __MACH__ )
+ UnlockPortBits((GrafPtr)GetWindowPort(stWindow));
+ pthread_mutex_unlock(&gEventDrawLock);
+ #endif
}
***************
*** 706,709 ****
--- 716,722 ----
Rect clipRect;
+ #if defined ( __APPLE__ ) && defined ( __MACH__ )
+ pthread_mutex_lock(&gEventDrawLock);
+ #endif
port = (NP_Port *) netscapeWindow->window;
***************
*** 711,716 ****
/* save old graphics port and switch to ours */
GetPort((GrafPtr *) &gOldPort);
- SetPort((GrafPtr) port->port);
stWindow = (WindowPtr) port->port;
/* save old drawing environment */
--- 724,732 ----
/* save old graphics port and switch to ours */
GetPort((GrafPtr *) &gOldPort);
stWindow = (WindowPtr) port->port;
+ #if defined ( __APPLE__ ) && defined ( __MACH__ )
+ LockPortBits((GrafPtr)GetWindowPort(stWindow));
+ #endif
+ SetPort((GrafPtr) port->port);
/* save old drawing environment */
***************
*** 738,743 ****
Rect dstRect = { 0, 0, 0, 0 };
Rect srcRect = { 0, 0, 0, 0 };
! RgnHandle maskRect = nil;
! Boolean restorePort=false;
if (stWindow == nil || exitRequested) {
--- 754,758 ----
Rect dstRect = { 0, 0, 0, 0 };
Rect srcRect = { 0, 0, 0, 0 };
! static RgnHandle maskRect = nil;
if (stWindow == nil || exitRequested) {
***************
*** 745,762 ****
}
- restorePort = true;
StartDraw();
- /*if (((NP_Port *) netscapeWindow->window)->port != (struct CGrafPort *) stWindow) {
- StartDraw();
- restorePort = true;
- }*/
- dstRect.left = 0;
- dstRect.top = 0;
dstRect.right = width;
dstRect.bottom = height;
-
- srcRect.left = 0;
- srcRect.top = 0;
srcRect.right = width;
srcRect.bottom = height;
--- 760,767 ----
***************
*** 780,794 ****
/* create a mask region so that only the affected rectangle is copied */
maskRect = NewRgn();
SetRectRgn(maskRect, affectedL, affectedT, affectedR, affectedB);
- SetPortWindowPort(stWindow);
CopyBits((BitMap *) *stPixMap, GetPortBitMapForCopyBits(GetWindowPort(stWindow)), &srcRect, &dstRect, srcCopy, maskRect);
! /* causes IE to crash #if TARGET_API_MAC_CARBON
! QDFlushPortBuffer (GetWindowPort(stWindow), maskRect);
! #endif */
! DisposeRgn(maskRect);
!
! if (restorePort)
EndDraw();
}
--- 785,796 ----
/* create a mask region so that only the affected rectangle is copied */
+ if (maskRect == nil)
maskRect = NewRgn();
SetRectRgn(maskRect, affectedL, affectedT, affectedR, affectedB);
CopyBits((BitMap *) *stPixMap, GetPortBitMapForCopyBits(GetWindowPort(stWindow)), &srcRect, &dstRect, srcCopy, maskRect);
! #if defined ( __APPLE__ ) && defined ( __MACH__ )
! QDFlushPortBuffer ((struct CGrafPort*)stWindow, maskRect);
! #endif
EndDraw();
}
***************
*** 854,861 ****
long junk;
char mail[8];
- if (thisInstance == null) return -1;
- handle = FindIdleURLRequest();
- if (handle < 0) return handle;
urlRequests[handle].id = nextRequestID++;
urlRequests[handle].status = STATUS_IN_PROGRESS;
--- 856,865 ----
long junk;
char mail[8];
+ NPError err;
+
+ if (thisInstance == null) return -1;
+ handle = FindIdleURLRequest();
+ if (handle < 0) return handle;
urlRequests[handle].id = nextRequestID++;
urlRequests[handle].status = STATUS_IN_PROGRESS;
***************
*** 1064,1069 ****
oldNetscapeWindow = netscapeWindow;
oldStWindow = stWindow;
! #if TARGET_API_MAC_CARBON & !defined(PLUGIN)
! GetWindowGreatestAreaDevice(stWindow,kWindowContentRgn,&dominantGDevice,&windRect);
#else
dominantGDevice = getDominateDevice(stWindow,&windRect);
--- 1068,1073 ----
oldNetscapeWindow = netscapeWindow;
oldStWindow = stWindow;
! #if TARGET_API_MAC_CARBON
! GetWindowGreatestAreaDevice((GrafPtr) FrontWindow(),kWindowContentRgn,&dominantGDevice,&windRect);
#else
dominantGDevice = getDominateDevice(stWindow,&windRect);
***************
*** 1101,1105 ****
}
! void ioSetFullScreenRestore()
{
if (gRestorableStateForScreen != nil) {
--- 1105,1109 ----
}
! int ioSetFullScreenRestore()
{
if (gRestorableStateForScreen != nil) {
***************
*** 1458,1462 ****
! void OpenFileReadOnly(SQFile *f, char *fileName) {
/* Opens the given file for reading using the supplied sqFile
structure. This is a simplified version of sqFileOpen() that
--- 1462,1466 ----
! void OpenFileReadOnly(SQFile *f, char *MacfileName) {
/* Opens the given file for reading using the supplied sqFile
structure. This is a simplified version of sqFileOpen() that
***************
*** 1465,1468 ****
--- 1469,1480 ----
we only allow reading of this file. Sets the primitive
failure flag if not successful. */
+ char fileName[1024];
+ sqImageFile remember;
+
+ if (*MacfileName == NULL) {
+ interpreterProxy->success(false);
+ return;
+ }
+ sqFilenameFromStringOpen(fileName,(long) MacfileName, strlen(MacfileName));
f->file = fopen(fileName, "rb");
***************
*** 1535,1542 ****
int i;
if (thisInstance == nil) return;
thisInstance = nil;
exitRequested = true;
!
/* do { This hangs things, not sure what to do about outstanding URL requests...
URLFetchInProgress = false;
--- 1547,1559 ----
int i;
+ #if defined ( __APPLE__ ) && defined ( __MACH__ )
+ pthread_mutex_lock(&gEventDrawLock);
+ #endif
if (thisInstance == nil) return;
thisInstance = nil;
exitRequested = true;
! #if defined ( __APPLE__ ) && defined ( __MACH__ )
! pthread_mutex_unlock(&gEventDrawLock);
! #endif
/* do { This hangs things, not sure what to do about outstanding URL requests...
URLFetchInProgress = false;
***************
*** 1555,1561 ****
--- 1572,1589 ----
while(gSqueakThread != kNoThreadID && YieldToThread(gSqueakThread) == noErr){};
+ #if defined ( __APPLE__ ) && defined ( __MACH__ )
+ if (gTMTask.tmAddr) {
+
+ RemoveTimeTask((QElemPtr)&gTMTask);
+ DisposeTimerUPP(gTMTask.tmAddr);
+ gTMTask.tmAddr = NULL;
+ }
+ #endif
+
plugInShutdown();
ioSetFullScreenRestore();
NPP_Initialize(); /* reset local variables */
+ ignoreFirstEvent=false;
+ gIWasRunning=false;
}
|