Skip to content

Commit 637f4a1

Browse files
committed
Fix the issue causing the logo to not show when using the compatibility renderer
1 parent f0d15bb commit 637f4a1

File tree

3 files changed

+103
-86
lines changed

3 files changed

+103
-86
lines changed

main/main.cpp

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,7 @@ Error _parse_resource_dummy(void *p_data, VariantParser::Stream *p_stream, Ref<R
25522552
return OK;
25532553
}
25542554

2555-
Error Main::setup2() {
2555+
Error Main::setup2(bool p_show_boot_logo) {
25562556
Thread::make_main_thread(); // Make whatever thread call this the main thread.
25572557
set_current_thread_safe_for_nodes(true);
25582558

@@ -2896,12 +2896,6 @@ Error Main::setup2() {
28962896

28972897
MAIN_PRINT("Main: Setup Logo");
28982898

2899-
#if !defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
2900-
bool show_logo = false;
2901-
#else
2902-
bool show_logo = true;
2903-
#endif
2904-
29052899
if (init_windowed) {
29062900
//do none..
29072901
} else if (init_maximized) {
@@ -2913,67 +2907,11 @@ Error Main::setup2() {
29132907
DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP, true);
29142908
}
29152909

2916-
MAIN_PRINT("Main: Load Boot Image");
2917-
29182910
Color clear = GLOBAL_DEF_BASIC("rendering/environment/defaults/default_clear_color", Color(0.3, 0.3, 0.3));
29192911
RenderingServer::get_singleton()->set_default_clear_color(clear);
29202912

2921-
if (show_logo) { //boot logo!
2922-
const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true);
2923-
const String boot_logo_path = String(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges();
2924-
const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true);
2925-
const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true);
2926-
2927-
Ref<Image> boot_logo;
2928-
2929-
if (boot_logo_image) {
2930-
if (!boot_logo_path.is_empty()) {
2931-
boot_logo.instantiate();
2932-
Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo);
2933-
if (load_err) {
2934-
ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash.");
2935-
}
2936-
}
2937-
} else {
2938-
// Create a 1×1 transparent image. This will effectively hide the splash image.
2939-
boot_logo.instantiate();
2940-
boot_logo->initialize_data(1, 1, false, Image::FORMAT_RGBA8);
2941-
boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0));
2942-
}
2943-
2944-
Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
2945-
2946-
#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH)
2947-
boot_bg_color =
2948-
GLOBAL_DEF_BASIC("application/boot_splash/bg_color",
2949-
(editor || project_manager) ? boot_splash_editor_bg_color : boot_splash_bg_color);
2950-
#endif
2951-
if (boot_logo.is_valid()) {
2952-
RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale,
2953-
boot_logo_filter);
2954-
2955-
} else {
2956-
#ifndef NO_DEFAULT_BOOT_LOGO
2957-
MAIN_PRINT("Main: Create bootsplash");
2958-
#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH)
2959-
Ref<Image> splash = (editor || project_manager) ? memnew(Image(boot_splash_editor_png)) : memnew(Image(boot_splash_png));
2960-
#else
2961-
Ref<Image> splash = memnew(Image(boot_splash_png));
2962-
#endif
2963-
2964-
MAIN_PRINT("Main: ClearColor");
2965-
RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color);
2966-
MAIN_PRINT("Main: Image");
2967-
RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false);
2968-
#endif
2969-
}
2970-
2971-
#if defined(TOOLS_ENABLED) && defined(MACOS_ENABLED)
2972-
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && OS::get_singleton()->get_bundle_icon_path().is_empty()) {
2973-
Ref<Image> icon = memnew(Image(app_icon_png));
2974-
DisplayServer::get_singleton()->set_icon(icon);
2975-
}
2976-
#endif
2913+
if (p_show_boot_logo) {
2914+
setup_boot_logo();
29772915
}
29782916

29792917
MAIN_PRINT("Main: Clear Color");
@@ -3216,6 +3154,71 @@ Error Main::setup2() {
32163154
return OK;
32173155
}
32183156

3157+
void Main::setup_boot_logo() {
3158+
MAIN_PRINT("Main: Load Boot Image");
3159+
3160+
#if !defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
3161+
bool show_logo = false;
3162+
#else
3163+
bool show_logo = true;
3164+
#endif
3165+
3166+
if (show_logo) { //boot logo!
3167+
const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true);
3168+
const String boot_logo_path = String(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges();
3169+
const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true);
3170+
const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true);
3171+
3172+
Ref<Image> boot_logo;
3173+
3174+
if (boot_logo_image) {
3175+
if (!boot_logo_path.is_empty()) {
3176+
boot_logo.instantiate();
3177+
Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo);
3178+
if (load_err) {
3179+
ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash.");
3180+
}
3181+
}
3182+
} else {
3183+
// Create a 1×1 transparent image. This will effectively hide the splash image.
3184+
boot_logo.instantiate();
3185+
boot_logo->initialize_data(1, 1, false, Image::FORMAT_RGBA8);
3186+
boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0));
3187+
}
3188+
3189+
Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
3190+
3191+
#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH)
3192+
boot_bg_color = GLOBAL_DEF_BASIC("application/boot_splash/bg_color", (editor || project_manager) ? boot_splash_editor_bg_color : boot_splash_bg_color);
3193+
#endif
3194+
if (boot_logo.is_valid()) {
3195+
RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, boot_logo_filter);
3196+
3197+
} else {
3198+
#ifndef NO_DEFAULT_BOOT_LOGO
3199+
MAIN_PRINT("Main: Create bootsplash");
3200+
#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH)
3201+
Ref<Image> splash = (editor || project_manager) ? memnew(Image(boot_splash_editor_png)) : memnew(Image(boot_splash_png));
3202+
#else
3203+
Ref<Image> splash = memnew(Image(boot_splash_png));
3204+
#endif
3205+
3206+
MAIN_PRINT("Main: ClearColor");
3207+
RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color);
3208+
MAIN_PRINT("Main: Image");
3209+
RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false);
3210+
#endif
3211+
}
3212+
3213+
#if defined(TOOLS_ENABLED) && defined(MACOS_ENABLED)
3214+
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && OS::get_singleton()->get_bundle_icon_path().is_empty()) {
3215+
Ref<Image> icon = memnew(Image(app_icon_png));
3216+
DisplayServer::get_singleton()->set_icon(icon);
3217+
}
3218+
#endif
3219+
}
3220+
}
3221+
32193222
String Main::get_rendering_driver_name() {
32203223
return rendering_driver;
32213224
}

main/main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ class Main {
7272

7373
static int test_entrypoint(int argc, char *argv[], bool &tests_need_run);
7474
static Error setup(const char *execpath, int argc, char *argv[], bool p_second_phase = true);
75-
static Error setup2(); // The thread calling setup2() will effectively become the main thread.
75+
static Error setup2(bool p_show_boot_logo = true); // The thread calling setup2() will effectively become the main thread.
7676
static String get_rendering_driver_name();
77+
static void setup_boot_logo();
7778
#ifdef TESTS_ENABLED
7879
static Error test_setup();
7980
static void test_cleanup();

platform/android/java_godot_lib_jni.cpp

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ static AndroidInputHandler *input_handler = nullptr;
6767
static GodotJavaWrapper *godot_java = nullptr;
6868
static GodotIOJavaWrapper *godot_io_java = nullptr;
6969

70+
enum StartupStep {
71+
STEP_TERMINATED = -1,
72+
STEP_SETUP,
73+
STEP_SHOW_LOGO,
74+
STEP_STARTED
75+
};
76+
7077
static SafeNumeric<int> step; // Shared between UI and render threads
7178

7279
static Size2 new_size;
@@ -76,7 +83,7 @@ static Vector3 magnetometer;
7683
static Vector3 gyroscope;
7784

7885
static void _terminate(JNIEnv *env, bool p_restart = false) {
79-
step.set(-1); // Ensure no further steps are attempted and no further events are sent
86+
step.set(STEP_TERMINATED); // Ensure no further steps are attempted and no further events are sent
8087

8188
// lets cleanup
8289
// Unregister android plugins
@@ -203,7 +210,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, j
203210
os_android->set_display_size(Size2i(p_width, p_height));
204211

205212
// No need to reset the surface during startup
206-
if (step.get() > 0) {
213+
if (step.get() > STEP_SETUP) {
207214
if (p_surface) {
208215
ANativeWindow *native_window = ANativeWindow_fromSurface(env, p_surface);
209216
os_android->set_native_window(native_window);
@@ -216,7 +223,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, j
216223

217224
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jclass clazz, jobject p_surface) {
218225
if (os_android) {
219-
if (step.get() == 0) {
226+
if (step.get() == STEP_SETUP) {
220227
// During startup
221228
if (p_surface) {
222229
ANativeWindow *native_window = ANativeWindow_fromSurface(env, p_surface);
@@ -230,7 +237,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *en
230237
}
231238

232239
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jclass clazz) {
233-
if (step.get() == 0) {
240+
if (step.get() <= STEP_SETUP) {
234241
return;
235242
}
236243

@@ -244,20 +251,26 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ttsCallback(JNIEnv *e
244251
}
245252

246253
JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jclass clazz) {
247-
if (step.get() == -1) {
254+
if (step.get() == STEP_TERMINATED) {
248255
return true;
249256
}
250257

251-
if (step.get() == 0) {
258+
if (step.get() == STEP_SETUP) {
252259
// Since Godot is initialized on the UI thread, main_thread_id was set to that thread's id,
253260
// but for Godot purposes, the main thread is the one running the game loop
254-
Main::setup2();
261+
Main::setup2(false); // The logo is shown in the next frame otherwise we run into rendering issues
255262
input_handler = new AndroidInputHandler();
256263
step.increment();
257264
return true;
258265
}
259266

260-
if (step.get() == 1) {
267+
if (step.get() == STEP_SHOW_LOGO) {
268+
Main::setup_boot_logo();
269+
step.increment();
270+
return true;
271+
}
272+
273+
if (step.get() == STEP_STARTED) {
261274
if (Main::start() != EXIT_SUCCESS) {
262275
return true; // should exit instead and print the error
263276
}
@@ -283,7 +296,7 @@ JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env,
283296

284297
// Called on the UI thread
285298
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchMouseEvent(JNIEnv *env, jclass clazz, jint p_event_type, jint p_button_mask, jfloat p_x, jfloat p_y, jfloat p_delta_x, jfloat p_delta_y, jboolean p_double_click, jboolean p_source_mouse_relative, jfloat p_pressure, jfloat p_tilt_x, jfloat p_tilt_y) {
286-
if (step.get() <= 0) {
299+
if (step.get() <= STEP_SETUP) {
287300
return;
288301
}
289302

@@ -292,7 +305,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchMouseEvent(JN
292305

293306
// Called on the UI thread
294307
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchTouchEvent(JNIEnv *env, jclass clazz, jint ev, jint pointer, jint pointer_count, jfloatArray position, jboolean p_double_tap) {
295-
if (step.get() <= 0) {
308+
if (step.get() <= STEP_SETUP) {
296309
return;
297310
}
298311

@@ -313,23 +326,23 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchTouchEvent(JN
313326

314327
// Called on the UI thread
315328
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnify(JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_factor) {
316-
if (step.get() <= 0) {
329+
if (step.get() <= STEP_SETUP) {
317330
return;
318331
}
319332
input_handler->process_magnify(Point2(p_x, p_y), p_factor);
320333
}
321334

322335
// Called on the UI thread
323336
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_pan(JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_delta_x, jfloat p_delta_y) {
324-
if (step.get() <= 0) {
337+
if (step.get() <= STEP_SETUP) {
325338
return;
326339
}
327340
input_handler->process_pan(Point2(p_x, p_y), Vector2(p_delta_x, p_delta_y));
328341
}
329342

330343
// Called on the UI thread
331344
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed) {
332-
if (step.get() <= 0) {
345+
if (step.get() <= STEP_SETUP) {
333346
return;
334347
}
335348

@@ -344,7 +357,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env
344357

345358
// Called on the UI thread
346359
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value) {
347-
if (step.get() <= 0) {
360+
if (step.get() <= STEP_SETUP) {
348361
return;
349362
}
350363

@@ -359,7 +372,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env,
359372

360373
// Called on the UI thread
361374
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y) {
362-
if (step.get() <= 0) {
375+
if (step.get() <= STEP_SETUP) {
363376
return;
364377
}
365378

@@ -396,7 +409,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(
396409

397410
// Called on the UI thread
398411
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_physical_keycode, jint p_unicode, jint p_key_label, jboolean p_pressed, jboolean p_echo) {
399-
if (step.get() <= 0) {
412+
if (step.get() <= STEP_SETUP) {
400413
return;
401414
}
402415
input_handler->process_key_event(p_physical_keycode, p_unicode, p_key_label, p_pressed, p_echo);
@@ -419,15 +432,15 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env
419432
}
420433

421434
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz) {
422-
if (step.get() <= 0) {
435+
if (step.get() <= STEP_SETUP) {
423436
return;
424437
}
425438

426439
os_android->main_loop_focusin();
427440
}
428441

429442
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz) {
430-
if (step.get() <= 0) {
443+
if (step.get() <= STEP_SETUP) {
431444
return;
432445
}
433446

@@ -516,7 +529,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResu
516529
}
517530

518531
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNIEnv *env, jclass clazz) {
519-
if (step.get() <= 0) {
532+
if (step.get() <= STEP_SETUP) {
520533
return;
521534
}
522535

@@ -528,7 +541,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNI
528541
}
529542

530543
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIEnv *env, jclass clazz) {
531-
if (step.get() <= 0) {
544+
if (step.get() <= STEP_SETUP) {
532545
return;
533546
}
534547

0 commit comments

Comments
 (0)