[AD] Duplicate "surfaceCreated" on Android - explanation needed |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: allegro-developers@xxxxxxxxxx
- Subject: [AD] Duplicate "surfaceCreated" on Android - explanation needed
- From: Max Savenkov <max.savenkov@xxxxxxxxxx>
- Date: Tue, 20 Oct 2015 22:59:49 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:from:subject:message-id:date:user-agent:mime-version :content-type:content-transfer-encoding; bh=SvRZhWaz9um6BXshV8fd0Ka6TmjjjOlFJgb4m3IpJAA=; b=yUN+0Gy9p/s45Vks3F+lr5EoA48n1hihszbVWL9Bx2ZNdwxVtrKtBHLCyKaqmDeR0d qCHm4oQfOoPV6IheAG/VvaOkbA9bDxgGlu2HjuLcd2bMAhIFGj8fYnCvWXlTlMHj6Y6X U+0O/eglCbQqIn9ppoT9scBZAH10RiGEasRYZbrEtmynAe0bY8iS7NflBdhbnOHlG8SS iC0FqxckZ9lcfgpCrZVaTxLID4wm88ciA8bSus1zsaREvrote8lREWKQ0uNfBFTK/k0y rjQeG+cZQ6uQ1IRTnmt8PNi3dAezh8R7s4C4V6eNp+oQHI+bOotKuLqLpW2Rmwmwj5wr fdHw==
From what I understand from documentation
(https://source.android.com/devices/graphics/architecture.html), a
Surface is created automatically for SurfaceView (AllegroSurface, in our
case), whenever it is about to become visible ("When the SurfaceView's
View component is about to become visible, the framework asks the
WindowManager to ask SurfaceFlinger to create a new Surface."). However,
I see that AllegroActivity has a "createSurface" method, which creates a
new AllegroSurface explicitly.
When I minimize my game and restore it, I get the following log:
============================================
AllegroEGL: destroying egl_Surface
AllegroEGL: destroying egl_Context
AllegroSurface: surfaceDestroyed end
AllegroActivity: onSaveInstanceState
AllegroActivity: onStop.
// Here, the game is paused and restored
AllegroActivity: onRestart.
AllegroActivity: onStart.
AllegroActivity: onResume
allegro : android D 24548: android_system.c:303
Java_org_liballeg_android_AllegroActivity_nativeOnResume [ 69.49768]
resume activity
allegro : android D 24548: android_system.c:316
Java_org_liballeg_android_AllegroActivity_nativeOnResume [ 69.49773] got
display: 0x5d55fd20
AllegroActivity: postCreateSurface
AllegroActivity: onResume end
Choreographer: Skipped 388 frames! The application may be doing too
much work on its main thread.
AllegroSurface: surfaceCreated
// Later:
D AllegroActivity: createSurface
// ... lots of action ...
D AllegroActivity: createSurface end
AllegroSurface: surfaceCreated
allegro : display D 24548: android_display.c:43
Java_org_liballeg_android_AllegroSurface_nativeOnCreate [ 103.95028]
nativeOnCreate
allegro : display D 24548: android_display.c:50
Java_org_liballeg_android_AllegroSurface_nativeOnCreate [ 103.95049]
AllegroSurface_nativeOnCreate
D AllegroSurface: Grabbing focus
AllegroSurface: surfaceCreated end
============================================
As you can see, Allegro gets "surfaceCreated" callback twice: first
time, as per documentation, it happens right after onResume. The second
time, it happens when postCreateSurface finally had a chance to run its
way. Unfortunately, each "surfafeCreated" callback leads to spawning of
RESUME_DRAWING events and bitmap re-creation. It ends in chaos.
So, two questions:
1) Why does Allegro creates surface explicitly, when it is should be
created automatically? Is the observed behaviour a bug, or intended?
2) Is there any way to avoid duplicate events & bitmaps re-creation?