Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 247bcc7

Browse files
committed
[[ Bug 10881 ]] Fix Android openGL compositor surface height issue
This patch fixes an issue on Android where the SurfaceView is being resized when the keyboard is activated and deactivated. We do not resize the view for keyboard activation and as the openGL coordinate system has bottom-left origin the bottom of the stack was being rendered where the top should be. This patch changes the openGL tile cache to request the surface height directly through EGL APIs. As these APIs are unavailable on iOS the change is `#ifdef`d for Android only. Additionally to ensure the stack is re-drawn without necessarily re-rendering it the patch implements a new `MCScreenDC::refresh_current_window()` API. This is particularly important for when the keyboard is hidden as otherwise the area previously occupied by it will be black.
1 parent a5f3460 commit 247bcc7

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

docs/notes/bugfix-10881.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix stack rendering when keyboard activated and deactivated on Android with acceleratedRendering

engine/kernel.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
'libraries':
234234
[
235235
'-lGLESv1_CM',
236+
'-lEGL',
236237
'-ljnigraphics',
237238
'-llog',
238239
'-lm',

engine/src/mblandroiddc.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,16 @@ void MCScreenDC::do_fit_window(bool p_immediate_resize, bool p_post_message)
695695
}
696696
}
697697

698+
void MCScreenDC::refresh_current_window(void)
699+
{
700+
if (m_current_window == nil)
701+
return;
702+
703+
MCStack *t_stack = (MCStack *)m_current_window;
704+
705+
t_stack -> dirtyrect(t_stack -> view_getstackvisiblerect());
706+
}
707+
698708
Window MCScreenDC::get_current_window(void)
699709
{
700710
return m_current_window;
@@ -2769,8 +2779,8 @@ static void doSurfaceChangedCallback(void *p_is_init)
27692779
// We can now re-enable screen updates.
27702780
MCRedrawEnableScreenUpdates();
27712781

2772-
// Force a screen redraw
2773-
MCRedrawUpdateScreen();
2782+
// Force a redraw of the current window without re-rendering
2783+
static_cast<MCScreenDC *>(MCscreen) -> refresh_current_window();
27742784
}
27752785

27762786
JNIEXPORT void JNICALL Java_com_runrev_android_OpenGLView_doSurfaceChanged(JNIEnv *env, jobject object, jobject p_view)

engine/src/mbldc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class MCScreenDC: public MCUIDC
244244
// MW-2012-11-14: [[ Bug 10514 ]] Returns the current window on display.
245245
Window get_current_window(void);
246246

247+
void refresh_current_window(void);
247248
private:
248249
// The top-left of the mobile 'window' in screen co-ordinates.
249250
int32_t m_window_left;

engine/src/mbliphonedc.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,11 @@ static void MCScreenDCDoSnapshot(void *p_env)
850850
return m_current_window;
851851
}
852852

853+
void MCScreenDC::refresh_current_window(void)
854+
{
855+
856+
}
857+
853858
////////////////////////////////////////////////////////////////////////////////
854859

855860
extern void *coretext_font_create_with_name_size_and_style(MCStringRef p_name, uint32_t p_size, bool p_bold, bool p_italic);

engine/src/tilecachegl.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern void MCIPhoneSwitchToOpenGL(void);
4040
#define GL_GLEXT_PROTOTYPES
4141
#include <GLES/gl.h>
4242
#include <GLES/glext.h>
43+
#include <EGL/egl.h>
4344
extern void MCAndroidEnableOpenGLMode(void);
4445
extern void MCAndroidDisableOpenGLMode(void);
4546
#else
@@ -390,7 +391,17 @@ void MCTileCacheOpenGLCompositor_DeallocateTile(void *p_context, void *p_tile)
390391

391392
static void MCTileCacheOpenGLCompositor_PrepareFrame(MCTileCacheOpenGLCompositorContext *self)
392393
{
393-
self -> viewport_height = MCTileCacheGetViewport(self -> tilecache) . height;
394+
#if defined(_ANDROID_MOBILE)
395+
EGLint t_height;
396+
eglQuerySurface(eglGetCurrentDisplay(),
397+
eglGetCurrentSurface(EGL_DRAW),
398+
EGL_HEIGHT,
399+
&t_height);
400+
401+
self -> viewport_height = t_height;
402+
#else
403+
self -> viewport_height = MCTileCacheGetViewport(self -> tilecache) . height;
404+
#endif
394405
self -> current_texture = 0;
395406
self -> current_color = 0xffffffff;
396407
self -> current_opacity = 255;

0 commit comments

Comments
 (0)