jint JAVANAME(FskViewGL_unsetFskSurface)(JNIEnv* env, jobject viewObj) {
	FskWindow		fWin 		= FskWindowGetActive();
	FskThread		drawThread	= fWin->thread;

	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "[%p] FskViewGL_unsetFskSurface(%p, %p) calling ShutdownGLCallback()", (void*)pthread_self(), env, viewObj);
	JAVANAME(FskView_unsetFskSurface)(env, viewObj);

	FskThreadPostCallback(drawThread, ShutdownGLCallback, NULL, NULL, NULL, NULL);

	return 1;
}
static void ShutdownGLCallback(void *v1, void *v2, void *v3, void *v4) {
	FskNotificationPost(kFskNotificationGLContextAboutToLose);

	FskECMAScriptHibernate();
	{	FskWindow fWin = FskWindowGetActive();
		if (fWin)
			::FskPortReleaseGLResources(fWin->port);	/* This calls, in turn, FskGLEffectsShutdown(), which calls FskGLEffectCacheDispose() and FskGLEffectsShutdown() */
	}
	FskGLShutdown();

	FskNotificationPost(kFskNotificationGLContextLost);
}
jint JAVANAME(KinomaPlay_doPause)(JNIEnv* env, jclass clazz) {
	FskErr		err			= kFskErrNone;
	FskWindow	fWin 		= FskWindowGetActive();
	FskThread	drawThread;

	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "[%p] KinomaPlay_doPause(%p, %p, %p) calling ShutdownGLCallback()", (void*)pthread_self(), env, clazz, fWin);
	BAIL_IF_NULL(fWin, err, kFskErrBadState);
	drawThread = fWin->thread;

	err = FskThreadPostCallback(drawThread, ShutdownGLCallback, NULL, NULL, NULL, NULL);

bail:
	return !err;
}
jint JAVANAME(FskView_setFskSurface)(JNIEnv* env, jobject viewObj, jobject surfaceObject)
{
	int didLock;

	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "gingerbread setFskSurface\n");
	theNativeWindow = ANativeWindow_fromSurface(env, surfaceObject);

	if (!fbGlobals || !fbGlobals->frameBuffer) {
        FskInstrumentedTypePrintfMinimal(&gAndroidMainBlockTypeInstrumentation, "MDK - %p fbGlobals or ->frameBuffer %p is NULL here! -__ CHECK BAD BUILD\n", fbGlobals, fbGlobals ? fbGlobals->frameBuffer : 0);
		return kFskErrNone;
	}
	// was above the fbGlobals check - will we lose "surface" if we hit the case above?
	fbGlobals->surface = theNativeWindow;
    FskInstrumentedTypePrintfDebug(&gAndroidWindowTypeInstrumentation, "theNativeWindow/fbGlobals->surface is %p\n", theNativeWindow);

	didLock = (0 ==FskMutexTrylock(fbGlobals->screenMutex));

	FskWindow win = FskWindowGetActive();
	int invalidate = 0;

	if ((fbGlobals->frameBuffer->bounds.height != gScreenHeight)
		|| (fbGlobals->frameBuffer->bounds.width != gScreenWidth)) {

	}
	else {
		FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "gingerbread setFskSurface - NOT about to copy from backing store (%d x %d).\n",  fbGlobals->frameBuffer->bounds.width, fbGlobals->frameBuffer->bounds.height);

		invalidate = 1;
	}

	if (invalidate && win) {
		FskRectangleRecord b;
		FskPortGetBounds(win->port, &b);
		FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "gingerbread - invalidating port bounds %d %d %d %d\n", b.x, b.y, b.width, b.height);
		FskPortInvalidateRectangle(win->port, &b);
	}

	if (didLock) {
		FskInstrumentedTypePrintfVerbose(&gAndroidMainBlockTypeInstrumentation, "releasing from trylock\n");
		FskMutexRelease(fbGlobals->screenMutex);
	}

	return 1;
}
Exemple #5
0
static void drawingPumpCallback(void *arg0, void *arg1, void *arg2, void *arg3)
{
	UInt32 callback = (UInt32)arg0;
	UInt32 pending;
	FskWindow win = FskWindowGetActive();

//	MLOG("[%s] In drawing pump callback %ld, pre-fired: %ld\n", threadName, callback, gKplScreen->callbackFiredCount);
	gKplScreen->callbackFiredCount = callback;

	pending = gKplScreen->callbackPostedCount - gKplScreen->callbackFiredCount;
	if (pending > 0) {
		MLOG("[%s] There are %d callbacks pending, skip callback %ld\n", threadName, pending, callback);
		return;
	}

	if (gKplScreen->drawingPumpEnabled && (NULL != win)) {
		drawingPumpUpdate(win);
	}
}
jint JAVANAME(KinomaPlay_doResume)(JNIEnv* env, jclass clazz) {
	FskErr		err			= kFskErrNone;
	FskWindow	fWin 		= FskWindowGetActive();
	FskThread	drawThread;

	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation,"[%p] KinomaPlay_doResume(%p, %p, %p)", (void*)pthread_self(), env, clazz, fWin);
	BAIL_IF_NULL(fWin, err, kFskErrBadState);
	drawThread = fWin->thread;
	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "KinomaPlay_doResume: drawThread is %p %s", drawThread, drawThread ? "" : ", bailing");
	BAIL_IF_NULL(drawThread, err, kFskErrBadState);
	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "KinomaPlay_doResume calling InitGLCallback");

	FskMutexAcquire(jniRespMutex);
	err = FskThreadPostCallback(drawThread, InitGLCallback, theNativeWindow, NULL, NULL, NULL);
	if (!gQuitting) {
		FskConditionWait(jniRespCond, jniRespMutex);
		FskMutexRelease(jniRespMutex);
	}

	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "KinomaPlay_doResume: FskThreadPostCallback(InitGLCallback) returns %d", err);
	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "[%p] KinomaPlay_doResume successful", (void*)pthread_self());
bail:
	return !err;
}
jint JAVANAME(FskViewGL_setFskSurface)(JNIEnv* env, jobject viewObj, jobject surfaceObj) {
	FskWindow		fWin 		= FskWindowGetActive();
	FskErr			err			= kFskErrNone;
	FskErr			retErr;
	FskThread		drawThread;

	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "[%p] FskViewGL_setFskSurface(%p, %p, %p)", (void*)pthread_self(), env, viewObj, surfaceObj);

	ANativeWindow *nw = theNativeWindow;
	theNativeWindow = ANativeWindow_fromSurface(env, surfaceObj);
	fbGlobals->surface = theNativeWindow;

	if (theNativeWindow && theNativeWindow == nw) {
		FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, " native window surface is same as before - don't setFskSurface twice\n");
		return 0;
	}

	FskGLSetNativeWindow((void*)theNativeWindow);
	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "FskViewGL_setFskSurface: active window is %p%s", fWin, fWin ? "" : ", bailing");

	BAIL_IF_NULL(fWin, err, kFskErrBadState);
	drawThread	= fWin->thread;
	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "FskViewGL_setFskSurface: drawThread is %p %s", drawThread, drawThread ? "" : ", bailing");
	BAIL_IF_NULL(drawThread, err, kFskErrBadState);
	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "FskViewGL_setFskSurface calling InitGLCallback");

	/* MDK - we need to wait for the callback to complete it's action in the other thread before we continue. I'm doing this by means of the jniRespCond.
	* However, at startup, we don't have the target thread to do it's work yet, so allow this through once at initialization.
	*/
	static int pass = 0;
	if (pass != 0)
		FskMutexAcquire(jniRespMutex);

	FskInstrumentedTypePrintfVerbose(&gAndroidMainBlockTypeInstrumentation, " about to post callback and wait for response from InitGLCallback\n");
	err = FskThreadPostCallback(drawThread, InitGLCallback, theNativeWindow, NULL, NULL, NULL);

	if (pass++ != 0) {
		if (!gQuitting) {
			FskConditionWait(jniRespCond, jniRespMutex);
			FskMutexRelease(jniRespMutex);
		}
	}
	else
		usleep(500);


	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "FskViewGL_setFskSurface: FskThreadPostCallback(InitGLCallback) returns %d", err);

	gScreenWidth = fbGlobals->frameBuffer->bounds.width;
	gScreenHeight = fbGlobals->frameBuffer->bounds.height;

    if (fWin) {
        FskRectangleRecord b;
        FskPortGetBounds(fWin->port, &b);
        FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, " - gl invalidating port bounds %d %d %d %d\n", b.x, b.y, b.width, b.height);
        FskPortInvalidateRectangle(fWin->port, &b);
    }

bail:
	return !err;
}