Pausing Quantum Renderer
David.Hill at Oracle.com
Thu Nov 19 14:41:05 UTC 2015
On 11/18/15, 8:02 PM, Alexander Kouznetsov wrote:
> Shouldn't this be an equivalent of minimizing the window?
That just might work too, but may not be fast enough, would need to dig around in there to see how quickly it sets state so that the window would not be treated as dirty. If it needs to bubble up to the Stage, then probably not.
Part of the issue here is that the native graphic context is lost when you get the notification from the system, and so you want to stop banging on that lost context immediately. As the render lock is probably held at this point, toggling something that says "don't try rendering for a bit" might be the best bet.
> Best regards,
> Alexander Kouznetsov
> (408) 276-0387
> On 18 ноя 2015 12:45, Johan Vos wrote:
>> On Android, a JavaFX Application might transfer control to another app (and
>> become invisible) and enter the foreground later. In that case, the
>> GLSurface we are rendering on becomes invalid. In order to avoid problems
>> and save battery, we want to pause the renderer thread, but this turns out
>> to be more difficult than I expected.
>> When our app transfers control, we get a callback from Android. We
>> intercept this in javafxports, and we set the Screen width/height to 0/0 as
>> we don't want to render on the (invalid) surface while we lost control.
>> When we regain control, we resize the Screen and the app renders again.
>> The reason we set the width/height to 0/0 is because the PresentingPainter
>> will call SceneState.isValid() and this returns false in case getWidth() or
>> getHeight() are 0.
>> However, SceneState extends PresentableState and it overrides the update
>> method. It will call PresentatbleState.update() which will set the
>> viewWidth to the width of the new Screen (hence, 0) , but after that it
>> overwrites the viewWidth with camera.getViewWidth(). The latter still
>> contains the old value. A quick inspection shows that camera.setViewWidth()
>> is called when validate(...) is called on NGDefaultCamera, which is called
>> by ES2Context.updateRenderTarget() which happens during rendering, hence
>> *after* the PresentingPainter checks if the width is 0.
>> So immediately after we set the width of the Screen to 0 (on the FX App
>> Thread), a Pulse happens, and this one still things the screen is the
>> original size. While the pulse is happening, the android system destroys
>> our context, and the rendering fails. Moreover, the EGL system is in a
>> unpredictable state (recreating the surface fails).
>> A very dirty workaround for this is to wait for 1 pulse (with the new
>> pulselistener API this should be possible) before we return from the
>> callback method called by Android when the surface is about to be
>> destroyed. That way, we will have 1 bogus rendering on an existing (but
>> about-to-be-destroyed) surface.
>> But it would be better if there is some way to tell the quantum renderer to
>> immediately stop rendering. Existing pulses are no problem, as the
>> renderLock guarantuees that we set the size to 0 only when no other thread
>> (quantum renderer) has a lock on the renderLock.
>> - Johan
David Hill<David.Hill at Oracle.com>
Java Embedded Development
"A man's feet should be planted in his country, but his eyes should survey the world."
-- George Santayana (1863 - 1952)
More information about the openjfx-dev