Issue 54: Android - flickering while switching Displayable
Status:  Fixed
Owner: ----
Closed:  Jan 2011
Reported by vitalyster, Jun 15, 2010
When midlet switching Displayable (fullscreen Canvas) I see some flickering.
With r2211 (as recommended in Android J2me converting manual) it is not so annoying, but in later revisions next Canvas sometime not cover all display area.

Tested with Android SDK emulator and r2211, r2377, r2390. 
Jun 17, 2010
#1 vitalyster
r2392 much better, with one issue:

Canvas.getHeight() and Graphics.getClipHeight() return different values, Canvas returns incorrect value.
Jun 17, 2010
Project Member #2 bar...@gmail.com
Does "much better" means that there is no flickering now (with r2392)?
Jun 18, 2010
#3 vitalyster
There is no flickering, but if Displayable relies on Canvas height and width - it may paints incorrectly, under display area, or so. Switching more times may obtain right size, may not.
Jun 18, 2010
Project Member #4 bar...@gmail.com
I'm not entirely sure what "switching Displayable" means. Is that a flipping a device from portait to the landscape position or switching between two different Displayable objects?
Jun 27, 2010
#6 vitalyster
I discover that regression was in r2304, older revisions returns size correctly
Nov 3, 2010
#7 vitalyster
r2423 improve size calculating, with attached patch it improve calculating more.
canvas.patch
4.0 KB   View   Download
Nov 4, 2010
Project Member #8 bar...@gmail.com
One question, you added to CanvasView:

        @Override
        public void onSizeChanged(int w, int h, int oldw, int oldh) {
            initGraphics(w, h);
        }

Is it necessary? I mean, there is already surfaceChanged callback mathod set in CanvasView which calls initGraphics with new size of the view.
Nov 8, 2010
#9 vitalyster
Yes, it not needed, I got debug log and see, that surfaceChanged properly called on device rotation and tell right sizes to application. But graphics still may paints incorrectly after several size changes, I have no idea why.
Nov 25, 2010
#10 vitalyster
r2446 is great - after device rotation graphics area first draws incorrectly but in second or shorter time period it repaints correctly.
Nov 26, 2010
#11 kr...@seznam.cz
I admit I haven't checked the canvas code thoroughly, so, I wonder how is sizeChanged event propagated user's Canvas? 

In my midlet I'm using GameCanvas, and I had to modify AndroidCanvasUI in order to have sizeChanged callback invoked (my diff against r2446 attached). But it was a long time, so maybe I should review it...

acui.diff
4.3 KB   View   Download
Nov 30, 2010
Project Member #12 bar...@gmail.com
r2447 calls the Canvas.sizeChanged. I modified the acui.diff in some places, but the functionality should be the same.
Dec 7, 2010
#13 vitalyster
Now greatly works with sizeChanged, but an older bug come again: after Display.setCurrent(...) - new Displayable(Canvas) not paints (showing black screen) until we explicitly call repaint().
Dec 7, 2010
#14 vitalyster
I've made some simpifications to AndroidCanvasUI: CanvasView extends base View class instead of SurfaceView, and haven't any listed problems with flickering and size changes. I think that is enough for simple (all j2me?) applications.
SimpleCanvasUI.patch
8.0 KB   View   Download
Dec 8, 2010
Project Member #15 bar...@gmail.com
I'm afraid I cannot accept the patch since you removed the setAndroidRepaintListener method from AndroidCanvasUI class. That functionality is used by other projects. Also graphics object accessible from getGraphics is created every time when onDraw method is called.
Dec 8, 2010
#16 vitalyster
second try: restored setAndroidRepaintListener and initGraphics methods
simpleacui2.patch
6.7 KB   View   Download
Dec 8, 2010
Project Member #17 bar...@gmail.com
I can see one problem with the latest patch, it removes support for scaling, previously it was handled in onDraw by:
androidCanvas.drawBitmap(bitmap, scale, null);
Dec 8, 2010
#18 vitalyster
If we can modify initGraphics parameters signature, then this patch should handle scaling properly
simpleacui3.patch
6.9 KB   View   Download
Dec 20, 2010
Project Member #19 bar...@gmail.com
simpleacui3.patch has been applied, let's test our applications now
Jan 5, 2011
Project Member #20 bar...@gmail.com
I had to revert the simpleacui3.patch since it makes flickering (repainting a canvas in a loop, causes the entire canvas to flicker with a white background).

while(true) {
   repaint();
   serviceRepaints();
}

Jan 16, 2011
Project Member #21 bar...@gmail.com
(No comment was entered for this change.)
Status: Fixed
Labels: Milestone-3.0