Compare commits

...

18 Commits

Author SHA1 Message Date
Dmitrii Morskii
553e4d11a5 fix issues related to JCK 2023-10-17 14:38:40 +02:00
Dmitrii Morskii
0bbafae6bf fix copyrights header 2023-10-04 18:54:28 +02:00
Dmitrii Morskii
1d0105b3a1 fix remarks 2023-09-28 13:25:43 +02:00
Dmitrii Morskii
d682fdc1c6 fix way of choosing toolkit 2023-09-27 20:44:49 +02:00
Dmitrii Morskii
c7129f47b4 fix destruction part 2023-09-25 20:12:06 +02:00
Dmitrii Morskii
15dd319fd2 fix another remark 2023-09-20 14:13:26 +02:00
Dmitrii Morskii
f64b20fb61 fix remark 2023-09-20 13:18:07 +02:00
Dmitrii Morskii
a47c47cad6 remove redundant flags for BUILD_LIBWLSPLASHSCREEN 2023-09-07 14:21:03 +02:00
Dmitrii Morskii
78a11def36 more refactoring 2023-09-07 14:03:54 +02:00
Dmitrii Morskii
5b0ce47c3f small refactoring 2023-09-07 13:18:40 +02:00
Dmitrii Morskii
5e7eb34ccd remove redundant includes pt.2 2023-09-07 12:34:06 +02:00
Dmitrii Morskii
488f1a8ed5 remove redundant includes 2023-09-07 12:03:12 +02:00
Dmitrii Morskii
65f4f63b7a fixed macos building 2023-09-07 11:48:48 +02:00
Dmitrii Morskii
20552219ac made common way to choose toolkit 2023-09-06 20:30:33 +02:00
Dmitrii Morskii
241e25c71d fix windows compilation 2023-09-06 07:13:41 +01:00
Dmitrii Morskii
4caf51df96 fix remarks 2023-09-05 19:47:10 +02:00
Dmitrii Morskii
b9ec56133a small fix 2023-08-24 23:20:51 +02:00
Dmitrii Morskii
f8b85fc4ff implement SplashScreen on wayland 2023-08-24 23:13:06 +02:00
23 changed files with 1236 additions and 379 deletions

View File

@@ -334,6 +334,7 @@ ifeq ($(call isTargetOs, windows macosx), false)
common/awt \
common/java2d \
common/font \
common/wayland \
#
LIBAWT_WLAWT_EXCLUDES := medialib debug opengl x11
@@ -354,6 +355,7 @@ ifeq ($(call isTargetOs, windows macosx), false)
common/font \
common/java2d/wl \
common/java2d/vulkan \
common/wayland \
#
# Enable 'wakefield' extension for java.awt.Robot support
@@ -865,6 +867,7 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
#
LIBSPLASHSCREEN_HEADER_DIRS += common/awt/utility
LIBSPLASHSCREEN_HEADER_DIRS += common/awt/systemscale
ifeq ($(USE_EXTERNAL_LIBGIF), false)
LIBSPLASHSCREEN_HEADER_DIRS += libsplashscreen/giflib
@@ -920,6 +923,8 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
endif
endif
LIBSPLASHSCREEN_CFLAGS += $(CFLAGS_JDKLIB) $(GIFLIB_CFLAGS) $(LIBJPEG_CFLAGS) $(PNG_CFLAGS) $(LIBZ_CFLAGS)
ifeq ($(call isTargetOs, macosx), true)
LIBSPLASHSCREEN_CFLAGS += -DWITH_MACOSX
@@ -934,11 +939,10 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
else ifeq ($(call isTargetOs, windows), true)
LIBSPLASHSCREEN_CFLAGS += -DWITH_WIN32
else
LIBWLSPLASHSCREEN_CFLAGS := -DWITH_WL $(LIBSPLASHSCREEN_CFLAGS) $(X_CFLAGS)
LIBSPLASHSCREEN_CFLAGS += -DWITH_X11 $(X_CFLAGS)
endif
LIBSPLASHSCREEN_LIBS :=
ifeq ($(call isTargetOs, macosx), true)
LIBSPLASHSCREEN_LIBS += \
$(LIBM) -lpthread -liconv -losxapp \
@@ -954,48 +958,59 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
endif
LIBSPLASHSCREEN_HEADER_DIRS += \
libsplashscreen \
libosxapp \
java.base:libjava \
#
LIBSPLASHSCREEN_EXCLUDE_FILES := imageioJPEG.c jpegdecoder.c pngtest.c
LIBSPLASHSCREEN_LDFLAGS := $(LDFLAGS_JDKLIB) $(call SET_SHARED_LIBRARY_ORIGIN)
LIBSPLASHSCREEN_LIBS := $(JDKLIB_LIBS) $(LIBSPLASHSCREEN_LIBS) $(LIBZ_LIBS) $(GIFLIB_LIBS) $(LIBJPEG_LIBS) $(PNG_LIBS)
LIBSPLASHSCREEN_DISABLED_WARNINGS_gcc := sign-compare implicit-fallthrough shift-negative-value maybe-uninitialized unused-function type-limits unused-result
LIBSPLASHSCREEN_DISABLED_WARNINGS_clang := deprecated-non-prototype format-nonliteral sign-compare incompatible-pointer-types deprecated-declarations
LIBSPLASHSCREEN_DISABLED_WARNINGS_microsoft := 4018 4267 4244
LIBWLSPLASHSCREEN_HEADER_DIRS := common/wayland
LIBWLSPLASHSCREEN_EXTRA_SRC := common/wayland
$(eval $(call SetupJdkLibrary, BUILD_LIBSPLASHSCREEN, \
NAME := splashscreen, \
EXTRA_SRC := $(LIBSPLASHSCREEN_EXTRA_SRC), \
EXTRA_SRC := $(LIBSPLASHSCREEN_EXTRA_SRC) libxsplashscreen libsplashscreen, \
EXCLUDE_SRC_PATTERNS := $(LIBSPLASHSCREEN_EXCLUDE_SRC_PATTERNS), \
EXCLUDE_FILES := imageioJPEG.c jpegdecoder.c pngtest.c, \
DISABLED_WARNINGS_gcc := $(LIBSPLASHSCREEN_DISABLED_WARNINGS_gcc), \
DISABLED_WARNINGS_clang := $(LIBSPLASHSCREEN_DISABLED_WARNINGS_clang), \
DISABLED_WARNINGS_microsoft := $(LIBSPLASHSCREEN_DISABLED_WARNINGS_microsoft), \
EXCLUDE_FILES := $(LIBSPLASHSCREEN_EXCLUDE_FILES), \
EXCLUDES := $(LIBSPLASHSCREEN_EXCLUDES), \
OPTIMIZATION := LOW, \
CFLAGS := $(CFLAGS_JDKLIB) $(LIBSPLASHSCREEN_CFLAGS) \
$(GIFLIB_CFLAGS) $(LIBJPEG_CFLAGS) $(PNG_CFLAGS) $(LIBZ_CFLAGS), \
EXTRA_HEADER_DIRS := $(LIBSPLASHSCREEN_HEADER_DIRS), \
DISABLED_WARNINGS_gcc_dgif_lib.c := sign-compare, \
DISABLED_WARNINGS_gcc_jcmaster.c := implicit-fallthrough, \
DISABLED_WARNINGS_gcc_jdphuff.c := shift-negative-value, \
DISABLED_WARNINGS_gcc_png.c := maybe-uninitialized, \
DISABLED_WARNINGS_gcc_pngerror.c := maybe-uninitialized, \
DISABLED_WARNINGS_gcc_splashscreen_gfx_impl.c := implicit-fallthrough maybe-uninitialized, \
DISABLED_WARNINGS_gcc_splashscreen_impl.c := implicit-fallthrough sign-compare unused-function, \
DISABLED_WARNINGS_gcc_splashscreen_sys.c := type-limits unused-result, \
DISABLED_WARNINGS_clang := deprecated-non-prototype, \
DISABLED_WARNINGS_clang_dgif_lib.c := sign-compare, \
DISABLED_WARNINGS_clang_gzwrite.c := format-nonliteral, \
DISABLED_WARNINGS_clang_splashscreen_impl.c := sign-compare, \
DISABLED_WARNINGS_clang_splashscreen_png.c := incompatible-pointer-types, \
DISABLED_WARNINGS_clang_splashscreen_sys.m := deprecated-declarations, \
DISABLED_WARNINGS_microsoft_dgif_lib.c := 4018 4267, \
DISABLED_WARNINGS_microsoft_splashscreen_impl.c := 4018 4267 4244, \
DISABLED_WARNINGS_microsoft_splashscreen_png.c := 4267, \
DISABLED_WARNINGS_microsoft_splashscreen_sys.c := 4267 4244, \
LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN), \
CFLAGS := $(LIBSPLASHSCREEN_CFLAGS), \
EXTRA_HEADER_DIRS := libxsplashscreen $(LIBSPLASHSCREEN_HEADER_DIRS), \
LDFLAGS := $(LIBSPLASHSCREEN_LDFLAGS), \
LDFLAGS_macosx := -L$(INSTALL_LIBRARIES_HERE), \
LDFLAGS_windows := -delayload:user32.dll, \
LIBS := $(JDKLIB_LIBS) $(LIBSPLASHSCREEN_LIBS) $(LIBZ_LIBS) \
$(GIFLIB_LIBS) $(LIBJPEG_LIBS) $(PNG_LIBS), \
LIBS := $(LIBSPLASHSCREEN_LIBS), \
LIBS_aix := -liconv, \
))
$(eval $(call SetupJdkLibrary, BUILD_LIBWLSPLASHSCREEN, \
NAME := wlsplashscreen, \
EXTRA_SRC := $(LIBSPLASHSCREEN_EXTRA_SRC) $(LIBWLSPLASHSCREEN_EXTRA_SRC) libwlsplashscreen libsplashscreen, \
EXCLUDE_SRC_PATTERNS := $(LIBSPLASHSCREEN_EXCLUDE_SRC_PATTERNS), \
DISABLED_WARNINGS_gcc := $(LIBSPLASHSCREEN_DISABLED_WARNINGS_gcc), \
DISABLED_WARNINGS_clang := $(LIBSPLASHSCREEN_DISABLED_WARNINGS_clang), \
EXCLUDE_FILES := $(LIBSPLASHSCREEN_EXCLUDE_FILES), \
EXCLUDES := $(LIBSPLASHSCREEN_EXCLUDES), \
OPTIMIZATION := LOW, \
CFLAGS := $(LIBWLSPLASHSCREEN_CFLAGS), \
EXTRA_HEADER_DIRS := $(LIBSPLASHSCREEN_HEADER_DIRS) $(LIBWLSPLASHSCREEN_HEADER_DIRS) libwlsplashscreen, \
LDFLAGS := $(LIBSPLASHSCREEN_LDFLAGS), \
LIBS := -lwayland-client -lwayland-cursor $(LIBSPLASHSCREEN_LIBS), \
LIBS_aix := -liconv, \
))
TARGETS += $(BUILD_LIBSPLASHSCREEN)
ifeq ($(call isTargetOs, linux), true)
TARGETS += $(BUILD_LIBWLSPLASHSCREEN)
endif
ifeq ($(call isTargetOs, macosx), true)
$(BUILD_LIBSPLASHSCREEN): $(call FindLib, $(MODULE), osxapp)

View File

@@ -154,6 +154,14 @@
/* Store the name of the executable once computed */
static char *execname = NULL;
typedef enum awt_toolkit {
TK_UNKNOWN = 0,
TK_X11 = 1,
TK_WAYLAND = 2
} awt_toolkit;
static awt_toolkit _awt_toolkit = TK_UNKNOWN;
/*
* execname accessor from other parts of platform dependent logic
*/
@@ -646,7 +654,6 @@ SetExecname(char **argv)
}
/* --- Splash Screen shared library support --- */
static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen");
static void* hSplashLib = NULL;
void* SplashProcAddress(const char* name) {
@@ -659,8 +666,15 @@ void* SplashProcAddress(const char* name) {
JLI_ReportErrorMessage(JRE_ERROR1);
return NULL;
}
#if defined(__linux__)
const char* splash_screen_so = _awt_toolkit == TK_WAYLAND ?
JNI_LIB_NAME("wlsplashscreen") : JNI_LIB_NAME("splashscreen");
#else
const char* splash_screen_so = JNI_LIB_NAME("splashscreen");
#endif
ret = JLI_Snprintf(splashPath, sizeof(splashPath), "%s/lib/%s",
jrePath, SPLASHSCREEN_SO);
jrePath, splash_screen_so);
if (ret >= (int) sizeof(splashPath)) {
JLI_ReportErrorMessage(JRE_ERROR11);
@@ -747,11 +761,34 @@ CallJavaMainInNewThread(jlong stack_size, void* args) {
/* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */
#define MAX_PID_STR_SZ 20
static char*
getToolkitNameByEnv() {
if (_awt_toolkit == TK_UNKNOWN) {
char *xdg_session_type = getenv("XDG_SESSION_TYPE");
if (xdg_session_type != NULL && strcmp(xdg_session_type, "wayland") == 0) {
_awt_toolkit = TK_WAYLAND;
} else if (xdg_session_type != NULL && strcmp(xdg_session_type, "x11") == 0) {
_awt_toolkit = TK_X11;
} else if (getenv("DISPLAY") != NULL) {
_awt_toolkit = TK_X11;
} else if (getenv("WAYLAND_DISPLAY") != NULL) {
_awt_toolkit = TK_WAYLAND;
}
}
return _awt_toolkit == TK_WAYLAND ? "WLToolkit" : "XToolkit";
}
int
JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
int argc, char **argv,
int mode, char *what, int ret)
{
char *toolkit_name = getToolkitNameByEnv();
size_t toolkit_name_size = JLI_StrLen("-Dawt.toolkit.name=") + JLI_StrLen(toolkit_name) + 1;
char *toolkit_option = (char *)JLI_MemAlloc(toolkit_name_size);
snprintf(toolkit_option, toolkit_name_size, "-Dawt.toolkit.name=%s", toolkit_name);
AddOption(toolkit_option, NULL);
ShowSplashScreen();
return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
}
@@ -768,11 +805,16 @@ RegisterThread()
// stubbed out for windows and *nixes.
}
/*
* on unix, we return a false to indicate this option is not applicable
*/
jboolean
ProcessPlatformOption(const char *arg)
{
if (JLI_StrCCmp(arg, "-Dawt.toolkit.name=WLToolkit") == 0) {
_awt_toolkit = TK_WAYLAND;
return JNI_TRUE;
} else if (JLI_StrCCmp(arg, "-Dawt.toolkit.name=XToolkit") == 0) {
_awt_toolkit = TK_X11;
return JNI_TRUE;
}
return JNI_FALSE;
}

View File

@@ -70,4 +70,7 @@ public class PlatformGraphicsInfo {
"but this program performed an operation which requires it.";
}
public static String getSplashScreenLib() {
return "splashscreen";
}
}

View File

@@ -288,7 +288,7 @@ SplashRedrawWindow(Splash * splash) {
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
// drop the reference to the old view and image
[splash->window setContentView: nil];
SplashUpdateScreenData(splash);
SplashUpdateScreenData(splash, false);
// NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ?
NSBitmapImageRep * rep = [[NSBitmapImageRep alloc]

View File

@@ -29,6 +29,7 @@ import java.awt.image.*;
import java.net.URL;
import java.net.URLConnection;
import java.io.File;
import sun.awt.PlatformGraphicsInfo;
import sun.util.logging.PlatformLogger;
import sun.awt.image.SunWritableRaster;
@@ -132,7 +133,7 @@ public final class SplashScreen {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("splashscreen");
System.loadLibrary(PlatformGraphicsInfo.getSplashScreenLib());
return null;
}
});

View File

@@ -29,6 +29,10 @@
/* splashscreen_gfx is a general purpose code for converting pixmaps between various visuals
it is not very effective, but is universal and concise */
#if !defined(WITH_WIN32)
#include "splashscreen_config_common.h"
#endif
#include "splashscreen_config.h"
enum

View File

@@ -25,6 +25,8 @@
#include "splashscreen_gfx_impl.h"
#include <stddef.h>
/* *INDENT-OFF* */
const byte_t baseDitherMatrix[DITHER_SIZE][DITHER_SIZE] = {
/* Bayer's order-4 dither array. Generated by the code given in

View File

@@ -132,7 +132,7 @@ SplashIsStillLooping(Splash * splash)
}
void
SplashUpdateScreenData(Splash * splash)
SplashUpdateScreenData(Splash * splash, bool reuseScreenData)
{
ImageRect srcRect, dstRect;
if (splash->currentFrame < 0) {
@@ -142,7 +142,7 @@ SplashUpdateScreenData(Splash * splash)
initRect(&srcRect, 0, 0, splash->width, splash->height, 1,
splash->width * sizeof(rgbquad_t),
splash->frames[splash->currentFrame].bitmapBits, &splash->imageFormat);
if (splash->screenData) {
if (splash->screenData && !reuseScreenData) {
free(splash->screenData);
}
splash->screenStride = splash->width * splash->screenFormat.depthBytes;
@@ -151,7 +151,9 @@ SplashUpdateScreenData(Splash * splash)
(splash->screenStride + splash->byteAlignment - 1) &
~(splash->byteAlignment - 1);
}
splash->screenData = malloc(splash->height * splash->screenStride);
if (!reuseScreenData) {
splash->screenData = malloc(splash->height * splash->screenStride);
}
initRect(&dstRect, 0, 0, splash->width, splash->height, 1,
splash->screenStride, splash->screenData, &splash->screenFormat);
if (splash->overlayData) {

View File

@@ -26,10 +26,18 @@
#ifndef SPLASHSCREEN_IMPL_H
#define SPLASHSCREEN_IMPL_H
#if !defined(WITH_WIN32)
#include "splashscreen_config_common.h"
#include "systemScale.h"
#endif
#include "splashscreen_config.h"
#include "splashscreen_gfx.h"
#include "jni.h"
#include <string.h>
#include <stdbool.h>
JNIEXPORT int
SplashLoadMemory(void *pdata, int size); /* requires preloading the file */
@@ -68,6 +76,12 @@ typedef struct SplashImage
#define SPLASH_COLOR_MAP_SIZE 0x100
typedef struct ScreenInfo {
int width;
int height;
int scale;
} ScreenInfo;
typedef struct Splash
{
ImageFormat screenFormat; /* must be preset before image decoding */
@@ -86,6 +100,7 @@ typedef struct Splash
ImageFormat overlayFormat;
void *screenData;
int screenStride; /* stored scanline length in bytes */
ScreenInfo screenInfo;
int currentFrame; // currentFrame==-1 means image is not loaded
int loopCount;
int x, y;
@@ -111,6 +126,15 @@ typedef struct Splash
pthread_mutex_t lock;
Cursor cursor;
XWMHints* wmHints;
#elif defined(WITH_WL)
int controlpipe[2];
Buffer main_buffer;
Buffer *buffers;
wayland_state *state;
int window_width;
int window_height;
int native_scale;
pthread_mutex_t lock;
#elif defined(WITH_MACOSX)
pthread_mutex_t lock;
int controlpipe[2];
@@ -151,7 +175,7 @@ void SplashNextFrame(Splash * splash);
void SplashStart(Splash * splash);
void SplashDone(Splash * splash);
void SplashUpdateScreenData(Splash * splash);
void SplashUpdateScreenData(Splash * splash, bool reuseData);
void SplashCleanup(Splash * splash);

View File

@@ -148,4 +148,11 @@ public class PlatformGraphicsInfo {
but this program performed an operation which requires it,
""";
}
public static String getSplashScreenLib() {
if (PlatformGraphicsInfo.getToolkitID() == PlatformGraphicsInfo.TK_WAYLAND) {
return "wlsplashscreen";
}
return "splashscreen";
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, JetBrains s.r.o.. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "memory_utils.h"
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
static void
RandomName(char *buf) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
long r = ts.tv_nsec;
while (*buf) {
*buf++ = 'A' + (r & 15) + (r & 16) * 2;
r >>= 5;
}
}
static int
CreateSharedMemoryFile(const char* baseName) {
// constructing the full name of the form /baseName-XXXXXX
int baseLen = strlen(baseName);
char *name = (char*) malloc(baseLen + 9);
if (!name)
return -1;
name[0] = '/';
strcpy(name + 1, baseName);
strcpy(name + baseLen + 1, "-XXXXXX");
int retries = 100;
do {
RandomName(name + baseLen + 2);
--retries;
int fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
if (fd >= 0) {
shm_unlink(name);
free(name);
return fd;
}
} while (retries > 0 && errno == EEXIST);
free(name);
return -1;
}
int
AllocateSharedMemoryFile(size_t size, const char* baseName) {
int fd = CreateSharedMemoryFile(baseName);
if (fd < 0)
return -1;
int ret;
do {
ret = ftruncate(fd, size);
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
close(fd);
return -1;
}
return fd;
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, JetBrains s.r.o.. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef MEMORY_UTILS_H
#define MEMORY_UTILS_H
#include <stdlib.h>
int
AllocateSharedMemoryFile(size_t size, const char* baseName);
#endif // MEMORY_UTILS_H

View File

@@ -46,6 +46,7 @@
#include "WLToolkit.h"
#include "WLRobotPeer.h"
#include "WLGraphicsEnvironment.h"
#include "memory_utils.h"
#ifdef WAKEFIELD_ROBOT
#include "wakefield-client-protocol.h"
@@ -1229,59 +1230,6 @@ void awt_output_flush()
wl_flush_to_server(getEnv());
}
static void
RandomName(char *buf) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
long r = ts.tv_nsec;
while (*buf) {
*buf++ = 'A' + (r & 15) + (r & 16) * 2;
r >>= 5;
}
}
static int
CreateSharedMemoryFile(const char* baseName) {
// constructing the full name of the form /baseName-XXXXXX
int baseLen = strlen(baseName);
char *name = (char*) malloc(baseLen + 9);
if (!name)
return -1;
name[0] = '/';
strcpy(name + 1, baseName);
strcpy(name + baseLen + 1, "-XXXXXX");
int retries = 100;
do {
RandomName(name + baseLen + 2);
--retries;
int fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
if (fd >= 0) {
shm_unlink(name);
free(name);
return fd;
}
} while (retries > 0 && errno == EEXIST);
free(name);
return -1;
}
static int
AllocateSharedMemoryFile(size_t size, const char* baseName) {
int fd = CreateSharedMemoryFile(baseName);
if (fd < 0)
return -1;
int ret;
do {
ret = ftruncate(fd, size);
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
close(fd);
return -1;
}
return fd;
}
struct wl_shm_pool *CreateShmPool(size_t size, const char *name, void **data) {
if (size <= 0)
return NULL;

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, JetBrains s.r.o.. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef SPLASHSCREEN_CONFIG_COMMON_H
#define SPLASHSCREEN_CONFIG_COMMON_H
#include <inttypes.h>
typedef uint32_t rgbquad_t;
typedef uint16_t word_t;
typedef uint8_t byte_t;
#define SPLASHCTL_QUIT 'Q'
#define SPLASHCTL_UPDATE 'U'
#define SPLASHCTL_RECONFIGURE 'R'
#define INLINE static
#endif

View File

@@ -0,0 +1,271 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, JetBrains s.r.o.. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "splashscreen_impl.h"
#include <sys/time.h>
#include <iconv.h>
#include <langinfo.h>
#include <locale.h>
#include <fcntl.h>
#include <poll.h>
#include <sizecalc.h>
#include <pthread.h>
const int POLL_EVENT_TIMEOUT = 50;
void SplashEventLoop(Splash * splash);
bool SplashCreateWindow(Splash * splash);
void SplashRedrawWindow(Splash * splash);
void SplashUpdateCursor(Splash * splash);
void SplashSetup(Splash * splash);
void SplashUpdateShape(Splash * splash);
bool SplashReconfigureNow(Splash * splash);
bool FlushEvents(Splash * splash);
bool DispatchEvents(Splash * splash);
int GetDisplayFD(Splash * splash);
/* Could use npt but decided to cut down on linked code size */
char*
SplashConvertStringAlloc(const char* in, int* size) {
const char *codeset;
const char *codeset_out;
iconv_t cd;
size_t rc;
char *buf = NULL, *out;
size_t bufSize, inSize, outSize;
const char* old_locale;
if (!in) {
return NULL;
}
old_locale = setlocale(LC_ALL, "");
codeset = nl_langinfo(CODESET);
if ( codeset == NULL || codeset[0] == 0 ) {
goto done;
}
/* we don't need BOM in output so we choose native BE or LE encoding here */
codeset_out = (platformByteOrder()==BYTE_ORDER_MSBFIRST) ?
"UCS-2BE" : "UCS-2LE";
cd = iconv_open(codeset_out, codeset);
if (cd == (iconv_t)-1 ) {
goto done;
}
inSize = strlen(in);
buf = SAFE_SIZE_ARRAY_ALLOC(malloc, inSize, 2);
if (!buf) {
return NULL;
}
bufSize = inSize*2; // need 2 bytes per char for UCS-2, this is
// 2 bytes per source byte max
out = buf; outSize = bufSize;
/* linux iconv wants char** source and solaris wants const char**...
cast to void* */
rc = iconv(cd, (void*)&in, &inSize, &out, &outSize);
iconv_close(cd);
if (rc == (size_t)-1) {
free(buf);
buf = NULL;
} else {
if (size) {
*size = (bufSize-outSize)/2; /* bytes to wchars */
}
}
done:
setlocale(LC_ALL, old_locale);
return buf;
}
void
SplashEventLoop(Splash * splash) {
struct pollfd pfd[2];
int rc;
unsigned lastCursorUpdate;
pfd[0].fd = splash->controlpipe[0];
pfd[0].events = POLLIN | POLLPRI;
pfd[0].revents = 0;
pfd[1].fd = GetDisplayFD(splash);
pfd[1].events = POLLIN | POLLPRI;
pfd[1].revents = 0;
lastCursorUpdate = SplashTime();
while (true) {
if (!FlushEvents(splash)) {
break;
}
if (splash->isVisible > 0 && splash->currentFrame >= 0 &&
SplashTime() >= splash->time + splash->frames[splash->currentFrame].delay) {
SplashNextFrame(splash);
SplashUpdateShape(splash);
SplashRedrawWindow(splash);
}
SplashUnlock(splash);
rc = poll(pfd, 2, POLL_EVENT_TIMEOUT);
SplashLock(splash);
if (SplashTime() - lastCursorUpdate > 100) {
SplashUpdateCursor(splash);
lastCursorUpdate = SplashTime();
}
if (rc <= 0) {
continue;
}
if (pfd[1].revents) {
if (!DispatchEvents(splash)) {
break;
}
}
if (pfd[0].revents) {
char buf;
if (read(splash->controlpipe[0], &buf, sizeof(buf)) > 0) {
switch (buf) {
case SPLASHCTL_UPDATE:
if (splash->isVisible > 0) {
SplashRedrawWindow(splash);
}
break;
case SPLASHCTL_RECONFIGURE:
if (splash->isVisible > 0) {
if (!SplashReconfigureNow(splash)) {
return;
}
}
break;
case SPLASHCTL_QUIT:
return;
}
}
}
}
}
unsigned
SplashTime(void) {
struct timeval tv;
struct timezone tz;
unsigned long long msec;
gettimeofday(&tv, &tz);
msec = (unsigned long long) tv.tv_sec * 1000 + (unsigned long long) tv.tv_usec / 1000;
return (unsigned) msec;
}
void
SplashPThreadDestructor(void *data) {
Splash *splash = data;
if (splash) {
SplashCleanup(splash);
}
}
void *
SplashScreenThread(void *data) {
Splash *splash = data;
SplashLock(splash);
pipe(splash->controlpipe);
fcntl(splash->controlpipe[0], F_SETFL, fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK);
splash->time = SplashTime();
bool init = SplashCreateWindow(splash);
fflush(stdout);
if (init) {
SplashSetup(splash);
SplashRedrawWindow(splash);
SplashEventLoop(splash);
}
SplashUnlock(splash);
SplashDone(splash);
splash->isVisible=-1;
return 0;
}
void
SplashCreateThread(Splash * splash) {
pthread_t thr;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
}
void
sendctl(Splash * splash, char code) {
if (splash && splash->controlpipe[1]) {
write(splash->controlpipe[1], &code, 1);
}
}
void
SplashLock(Splash * splash) {
pthread_mutex_lock(&splash->lock);
}
void
SplashUnlock(Splash * splash) {
pthread_mutex_unlock(&splash->lock);
}
void
SplashClosePlatform(Splash * splash) {
sendctl(splash, SPLASHCTL_QUIT);
}
void
SplashUpdate(Splash * splash) {
sendctl(splash, SPLASHCTL_UPDATE);
}
void
SplashReconfigure(Splash * splash) {
sendctl(splash, SPLASHCTL_RECONFIGURE);
}
JNIEXPORT jboolean
SplashGetScaledImageName(const char* jarName, const char* fileName,
float *scaleFactor, char *scaledImgName,
const size_t scaledImageNameLength) {
*scaleFactor = 1;
#ifndef __linux__
return JNI_FALSE;
#endif
*scaleFactor = (float) getNativeScaleFactor(NULL, 1);
return GetScaledImageName(fileName, scaledImgName, scaleFactor, scaledImageNameLength);
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, JetBrains s.r.o.. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef SPLASHSCREEN_CONFIG_H
#define SPLASHSCREEN_CONFIG_H
#include <stdbool.h>
typedef struct Buffer {
void *data;
int size;
struct wl_buffer *wl_buffer;
bool available;
} Buffer;
typedef struct wayland_state {
struct wl_display *wl_display;
struct wl_registry *wl_registry;
struct wl_shm *wl_shm;
struct wl_compositor *wl_compositor;
struct wl_subcompositor *wl_subcompositor;
struct wl_output *wl_output;
struct wl_seat *wl_seat;
struct wl_pointer *pointer;
struct xdg_wm_base *xdg_wm_base;
struct wl_surface *wl_surface;
struct wl_surface *wl_subsurfaces_surface;
struct wl_subsurface *wl_subsurfaces_subsurface;
struct xdg_surface *xdg_surface;
struct xdg_toplevel *xdg_toplevel;
struct wl_cursor_theme *cursor_theme;
struct wl_cursor *default_cursor;
struct wl_surface *cursor_surface;
} wayland_state;
// Actually the following Rect machinery is unused since we don't use shapes
typedef int RECT_T;
#define RECT_EQ_X(r1,r2) ((r1) == (r2))
#define RECT_SET(r,xx,yy,ww,hh) ;
#define RECT_INC_HEIGHT(r) ;
#endif

View File

@@ -0,0 +1,537 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, JetBrains s.r.o.. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "splashscreen_impl.h"
#include <fcntl.h>
#include <wayland-client.h>
#include <wayland-cursor.h>
#include <pthread.h>
#include <sys/mman.h>
#include "memory_utils.h"
#include "xdg-shell-client-protocol.h"
static const int BUFFERS_COUNT = 3;
static bool is_cursor_animated = false;
#define NULL_CHECK_CLEANUP(val, message) if (val == NULL) { fprintf(stderr, "%s\n", message); goto cleanup; }
#define NULL_CHECK(val, message) if (val == NULL) { fprintf(stderr, "%s\n", message); return false; }
#define DESTROY_NOT_NULL(val, destructor) if (val != NULL) { destructor(val); }
bool SplashReconfigureNow(Splash * splash);
void SplashRedrawWindow(Splash * splash);
void SplashReconfigure(Splash * splash);
static bool
alloc_buffer(int width, int height, struct wl_shm *wl_shm, Buffer *buffer, int format, int format_size) {
int size = width * height * format_size;
int fd = AllocateSharedMemoryFile(size, "splashscreen");
buffer->size = size;
if (fd == -1) {
return false;
}
buffer->data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buffer->data == MAP_FAILED) {
close(fd);
return false;
}
struct wl_shm_pool *pool = wl_shm_create_pool(wl_shm, fd, size);
buffer->wl_buffer = wl_shm_pool_create_buffer(pool, 0, width, height, width * format_size, format);
if (buffer->wl_buffer == NULL) {
return false;
}
wl_shm_pool_destroy(pool);
close(fd);
return true;
}
static void
destroy_buffer(Buffer *buffer) {
if (buffer->data != MAP_FAILED && buffer->data != NULL) {
munmap(buffer->data, buffer->size);
}
if (buffer->wl_buffer) {
wl_buffer_destroy(buffer->wl_buffer);
}
}
static void
registry_global(void *data, struct wl_registry *wl_registry, uint32_t name, const char *interface, uint32_t version) {
wayland_state *state = data;
if (strcmp(interface, wl_shm_interface.name) == 0) {
state->wl_shm = wl_registry_bind(
wl_registry, name, &wl_shm_interface, 1);
} else if (strcmp(interface, wl_compositor_interface.name) == 0) {
state->wl_compositor = wl_registry_bind(
wl_registry, name, &wl_compositor_interface, 4);
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
state->wl_seat = wl_registry_bind(
wl_registry, name, &wl_seat_interface, 1);
} else if (strcmp(interface, wl_subcompositor_interface.name) == 0) {
state->wl_subcompositor = wl_registry_bind(
wl_registry, name, &wl_subcompositor_interface, 1);
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
state->xdg_wm_base = wl_registry_bind(
wl_registry, name, &xdg_wm_base_interface, 1);
} else if (strcmp(interface, wl_output_interface.name) == 0) {
state->wl_output = wl_registry_bind(
wl_registry, name, &wl_output_interface, 2);
}
}
static void
registry_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name) {
}
static const struct wl_registry_listener wl_registry_listener = {
.global = registry_global,
.global_remove = registry_global_remove,
};
static void
wl_buffer_release(void *data, struct wl_buffer *wl_buffer) {
Buffer* buffer = data;
buffer->available = true;
}
static const struct wl_buffer_listener wl_buffer_listener = {
.release = wl_buffer_release,
};
static void
wl_output_geometry(void *data, struct wl_output * wl_output, int32_t x, int32_t y, int32_t physical_width,
int32_t physical_height, int32_t subpixel, const char *make, const char *model, int32_t transform) {
}
static void
wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor) {
ScreenInfo *output = data;
output->scale = factor;
}
static void
wl_output_mode(
void *data,
struct wl_output *wl_output,
uint32_t flags,
int32_t width,
int32_t height,
int32_t refresh) {
ScreenInfo *output = data;
output->width = width;
output->height = height;
}
static void
wl_output_name(
void *data,
struct wl_output *wl_output,
const char *name) {
}
static void
wl_output_description(
void *data,
struct wl_output *wl_output,
const char *description) {
}
static void
wl_output_done(
void *data,
struct wl_output *wl_output) {
}
struct wl_output_listener wl_output_listener = {
.geometry = &wl_output_geometry,
.mode = &wl_output_mode,
.name = &wl_output_name,
.description = &wl_output_description,
.done = &wl_output_done,
.scale = &wl_output_scale
};
void
xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial) {
struct Splash *splash = data;
xdg_surface_ack_configure(xdg_surface, serial);
SplashReconfigure(splash);
}
static const struct xdg_surface_listener xdg_surface_listener = {
.configure = xdg_surface_configure,
};
static void
handle_toplevel_configure(void *data, struct xdg_toplevel *toplevel, int32_t width, int32_t height,
struct wl_array *states) {
struct Splash *splash = data;
if (width > 0 && height > 0 && (splash->window_width == 0 || splash->window_height == 0)) {
splash->window_width = width;
splash->window_height = height;
}
SplashReconfigure(splash);
}
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
.configure = handle_toplevel_configure,
};
static void
pointer_handle_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface,
wl_fixed_t sx, wl_fixed_t sy) {
wayland_state *state = data;
is_cursor_animated = true;
struct wl_cursor_image *image = state->default_cursor->images[0];
wl_pointer_set_cursor(pointer, serial, state->cursor_surface, image->hotspot_x, image->hotspot_y);
}
static void
pointer_handle_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface) {
is_cursor_animated = false;
}
static void
pointer_handle_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t sx, wl_fixed_t sy) {
}
static void
pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
}
static const struct wl_pointer_listener pointer_listener = {
.enter = pointer_handle_enter,
.leave = pointer_handle_leave,
.motion = pointer_handle_motion,
.button = pointer_handle_button,
};
static void
seat_handle_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps) {
wayland_state *state = data;
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !state->pointer) {
state->pointer = wl_seat_get_pointer(seat);
wl_pointer_add_listener(state->pointer, &pointer_listener, state);
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && state->pointer) {
wl_pointer_destroy(state->pointer);
state->pointer = NULL;
}
}
static const struct wl_seat_listener wl_seat_listener = {
.capabilities = seat_handle_capabilities,
};
static void
xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial) {
xdg_wm_base_pong(xdg_wm_base, serial);
}
static const struct xdg_wm_base_listener xdg_wm_base_listener = {
.ping = xdg_wm_base_ping,
};
bool
SplashCreateWindow(Splash * splash) {
splash->native_scale = getNativeScaleFactor(NULL, 1);
if (splash->native_scale == -1.0) {
splash->native_scale = 1.0;
}
wl_output_add_listener(splash->state->wl_output, &wl_output_listener, &splash->screenInfo);
splash->state->wl_surface = wl_compositor_create_surface(splash->state->wl_compositor);
NULL_CHECK(splash->state->wl_surface, "Cannot create surface\n")
splash->state->wl_subsurfaces_surface = wl_compositor_create_surface(splash->state->wl_compositor);
NULL_CHECK(splash->state->wl_subsurfaces_surface, "Cannot create surface\n")
wl_surface_set_buffer_scale(splash->state->wl_subsurfaces_surface, (int) splash->scaleFactor);
wl_surface_set_buffer_scale(splash->state->wl_surface, splash->native_scale);
xdg_wm_base_add_listener(splash->state->xdg_wm_base, &xdg_wm_base_listener, splash->state);
splash->state->xdg_surface = xdg_wm_base_get_xdg_surface(splash->state->xdg_wm_base, splash->state->wl_surface);
NULL_CHECK(splash->state->xdg_surface, "Cannot get xdg_surface\n")
xdg_surface_add_listener(splash->state->xdg_surface, &xdg_surface_listener, splash);
splash->state->xdg_toplevel = xdg_surface_get_toplevel(splash->state->xdg_surface);
NULL_CHECK(splash->state->xdg_toplevel, "Cannot get xdg_toplevel\n")
xdg_toplevel_set_maximized(splash->state->xdg_toplevel);
xdg_toplevel_add_listener(splash->state->xdg_toplevel, &xdg_toplevel_listener, splash);
splash->state->cursor_surface = wl_compositor_create_surface(splash->state->wl_compositor);
NULL_CHECK(splash->state->cursor_surface, "Cannot get cursor_surface\n")
wl_seat_add_listener(splash->state->wl_seat, &wl_seat_listener, splash->state);
splash->state->wl_subsurfaces_subsurface = wl_subcompositor_get_subsurface(
splash->state->wl_subcompositor, splash->state->wl_subsurfaces_surface, splash->state->wl_surface);
NULL_CHECK(splash->state->wl_subsurfaces_subsurface, "Cannot create subsurface\n")
wl_subsurface_set_desync(splash->state->wl_subsurfaces_subsurface);
splash->state->cursor_theme = wl_cursor_theme_load(NULL, 32, splash->state->wl_shm);
NULL_CHECK(splash->state->cursor_theme, "unable to load default theme\n")
splash->state->default_cursor = wl_cursor_theme_get_cursor(splash->state->cursor_theme, "watch");
NULL_CHECK(splash->state->default_cursor, "unable to load pointer\n")
return true;
}
int
SplashInitPlatform(Splash * splash) {
#if (defined DEBUG)
_Xdebug = 1;
#endif
pthread_mutex_init(&splash->lock, NULL);
splash->buffers = 0;
splash->window_width = 0;
splash->window_height = 0;
splash->state = malloc(sizeof(wayland_state));
NULL_CHECK_CLEANUP(splash->state, "Cannot allocate enough memory\n")
splash->buffers = malloc(sizeof(Buffer) * BUFFERS_COUNT);
NULL_CHECK_CLEANUP(splash->buffers, "Cannot allocate enough memory\n")
splash->state->wl_display = NULL;
splash->state->wl_registry = NULL;
splash->state->wl_shm = NULL;
splash->state->wl_compositor = NULL;
splash->state->wl_subcompositor = NULL;
splash->state->wl_seat = NULL;
splash->state->xdg_wm_base = NULL;
splash->state->wl_subsurfaces_subsurface = NULL;
splash->state->wl_surface = NULL;
splash->state->wl_subsurfaces_surface = NULL;
splash->state->xdg_surface = NULL;
splash->state->xdg_toplevel = NULL;
splash->state->pointer = NULL;
splash->state->cursor_surface = NULL;
splash->main_buffer.wl_buffer = NULL;
splash->main_buffer.data = NULL;
for (int i = 0; i < BUFFERS_COUNT; i++) {
splash->buffers[i].wl_buffer = NULL;
splash->buffers[i].data = NULL;
splash->buffers[i].available = false;
}
splash->byteAlignment = 1;
splash->maskRequired = 0;
initFormat(&splash->screenFormat, 0xff0000, 0xff00, 0xff, 0xff000000);
splash->screenFormat.byteOrder = BYTE_ORDER_LSBFIRST;
splash->screenFormat.depthBytes = 4;
splash->state->wl_display = wl_display_connect(NULL);
NULL_CHECK_CLEANUP(splash->state->wl_display, "Cannot connect to display\n")
splash->state->wl_registry = wl_display_get_registry(splash->state->wl_display);
NULL_CHECK_CLEANUP(splash->state->wl_registry, "Cannot get display's registry\n")
wl_registry_add_listener(splash->state->wl_registry, &wl_registry_listener, splash->state);
wl_display_roundtrip(splash->state->wl_display);
NULL_CHECK_CLEANUP(splash->state->wl_shm, "wl_shm not initialized\n")
NULL_CHECK_CLEANUP(splash->state->wl_compositor, "wl_compositor not initialized\n")
NULL_CHECK_CLEANUP(splash->state->wl_subcompositor, "wl_subcompositor not initialized\n")
NULL_CHECK_CLEANUP(splash->state->wl_seat, "wl_seat not initialized\n")
NULL_CHECK_CLEANUP(splash->state->xdg_wm_base, "xdg_wm_base not initialized\n")
NULL_CHECK_CLEANUP(splash->state->wl_output, "wl_output not initialized\n")
return true;
cleanup:
SplashDonePlatform(splash);
return false;
}
bool
SplashReconfigureNow(Splash * splash) {
int scale = (int) splash->scaleFactor;
int offsetX = splash->screenInfo.width - splash->window_width * splash->screenInfo.scale;
int offsetY = splash->screenInfo.height - splash->window_height * splash->screenInfo.scale;
splash->x = (splash->screenInfo.width - splash->width / scale) / 2;
splash->y = (splash->screenInfo.height - splash->height / scale) / 2;
int localX = (splash->x - offsetX) / splash->screenInfo.scale;
int localY = (splash->y - offsetY) / splash->screenInfo.scale;
wl_subsurface_set_position(splash->state->wl_subsurfaces_subsurface, localX, localY);
destroy_buffer(&splash->main_buffer);
for (int i = 0; i < BUFFERS_COUNT; i++) {
destroy_buffer(&splash->buffers[i]);
splash->buffers[i].available = false;
}
struct wl_region *region = wl_compositor_create_region(splash->state->wl_compositor);
wl_region_subtract(region, 0, 0, splash->window_width, splash->window_height);
wl_region_add(region, localX, localY, splash->width / scale, splash->height / scale);
wl_surface_set_input_region(splash->state->wl_surface, region);
wl_surface_set_opaque_region(splash->state->wl_surface, region);
wl_region_destroy(region);
for (int i = 0; i < BUFFERS_COUNT; i++) {
if (!alloc_buffer(splash->width, splash->height, splash->state->wl_shm, &splash->buffers[i],
WL_SHM_FORMAT_XRGB8888, 4)) {
fprintf(stderr, "%s\n", "Cannot allocate enough memory");
return false;
}
wl_buffer_add_listener(splash->buffers[i].wl_buffer, &wl_buffer_listener, &splash->buffers[i]);
splash->buffers[i].available = true;
}
if (!alloc_buffer(splash->window_width * splash->native_scale, splash->window_height * splash->native_scale,
splash->state->wl_shm, &splash->main_buffer, WL_SHM_FORMAT_ARGB8888, 4)) {
fprintf(stderr, "%s\n", "Cannot allocate enough memory");
return false;
}
memset(splash->main_buffer.data, 0, splash->window_width * splash->window_height * 4);
wl_surface_attach(splash->state->wl_surface, splash->main_buffer.wl_buffer, 0, 0);
wl_surface_damage(splash->state->wl_surface, 0, 0, splash->window_width, splash->window_height);
wl_surface_commit(splash->state->wl_surface);
SplashRedrawWindow(splash);
return true;
}
void
SplashRedrawWindow(Splash * splash) {
for (int i = 0; i < BUFFERS_COUNT; i++) {
if (splash->buffers[i].available) {
splash->screenData = splash->buffers[i].data;
SplashUpdateScreenData(splash, true);
wl_surface_attach(splash->state->wl_subsurfaces_surface, splash->buffers[i].wl_buffer, 0, 0);
wl_surface_damage(splash->state->wl_subsurfaces_surface, 0, 0, splash->window_width, splash->window_height);
wl_surface_commit(splash->state->wl_subsurfaces_surface);
splash->buffers[i].available = false;
break;
}
}
}
bool
FlushEvents(Splash * splash) {
return wl_display_flush(splash->state->wl_display) != -1;
}
bool
DispatchEvents(Splash * splash) {
return wl_display_dispatch(splash->state->wl_display) != -1;
}
int
GetDisplayFD(Splash * splash) {
return wl_display_get_fd(splash->state->wl_display);
}
void
SplashUpdateCursor(Splash * splash) {
static int index = 0;
if (is_cursor_animated) {
wayland_state *state = splash->state;
struct wl_buffer *buffer;
struct wl_cursor *cursor = state->default_cursor;
struct wl_cursor_image *image;
if (cursor) {
image = state->default_cursor->images[index];
index = (index + 1) % (state->default_cursor->image_count);
buffer = wl_cursor_image_get_buffer(image);
if (!buffer)
return;
wl_surface_attach(state->cursor_surface, buffer, 0, 0);
wl_surface_damage(state->cursor_surface, 0, 0, image->width, image->height);
wl_surface_commit(state->cursor_surface);
}
}
}
void
SplashCleanupPlatform(Splash * splash) {
}
void
SplashDonePlatform(Splash * splash) {
pthread_mutex_destroy(&splash->lock);
if (splash == NULL) {
return;
}
DESTROY_NOT_NULL(splash->state->wl_shm, wl_shm_destroy)
DESTROY_NOT_NULL(splash->state->wl_compositor, wl_compositor_destroy)
DESTROY_NOT_NULL(splash->state->wl_subcompositor, wl_subcompositor_destroy)
DESTROY_NOT_NULL(splash->state->wl_seat, wl_seat_destroy)
DESTROY_NOT_NULL(splash->state->xdg_wm_base, xdg_wm_base_destroy)
DESTROY_NOT_NULL(splash->state->wl_subsurfaces_subsurface, wl_subsurface_destroy)
DESTROY_NOT_NULL(splash->state->wl_surface, wl_surface_destroy)
DESTROY_NOT_NULL(splash->state->wl_subsurfaces_surface, wl_surface_destroy)
DESTROY_NOT_NULL(splash->state->xdg_surface, xdg_surface_destroy)
DESTROY_NOT_NULL(splash->state->xdg_toplevel, xdg_toplevel_destroy)
DESTROY_NOT_NULL(splash->state->pointer, wl_pointer_destroy)
DESTROY_NOT_NULL(splash->state->cursor_surface, wl_surface_destroy)
destroy_buffer(&splash->main_buffer);
if (splash->buffers) {
for (int i = 0; i < BUFFERS_COUNT; i++) {
destroy_buffer(&splash->buffers[i]);
}
free(splash->buffers);
}
if (splash->state->wl_display) {
wl_display_flush(splash->state->wl_display);
wl_display_disconnect(splash->state->wl_display);
}
free(splash->state);
}
void
SplashSetup(Splash * splash) {
}
void
SplashUpdateShape(Splash * splash) {
}
void
SplashInitFrameShape(Splash * splash, int imageIndex) {
}

View File

@@ -30,20 +30,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "systemScale.h"
typedef uint32_t rgbquad_t;
typedef uint16_t word_t;
typedef uint8_t byte_t;
typedef XRectangle RECT_T;
#define RECT_EQ_X(r1,r2) ((r1).x==(r2).x && (r1).width==(r2).width)
@@ -51,10 +38,4 @@ typedef XRectangle RECT_T;
(r).height=(hh);
#define RECT_INC_HEIGHT(r) (r).height++;
#define SPLASHCTL_QUIT 'Q'
#define SPLASHCTL_UPDATE 'U'
#define SPLASHCTL_RECONFIGURE 'R'
#define INLINE static
#endif

View File

@@ -24,85 +24,25 @@
*/
#include "splashscreen_impl.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <X11/Xmd.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <sys/types.h>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
#include <iconv.h>
#include <langinfo.h>
#include <locale.h>
#include <fcntl.h>
#include <poll.h>
#include <sizecalc.h>
#include "jni.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
static Bool shapeSupported;
static int shapeEventBase, shapeErrorBase;
void SplashRemoveDecoration(Splash * splash);
/* Could use npt but decided to cut down on linked code size */
char* SplashConvertStringAlloc(const char* in, int* size) {
const char *codeset;
const char *codeset_out;
iconv_t cd;
size_t rc;
char *buf = NULL, *out;
size_t bufSize, inSize, outSize;
const char* old_locale;
if (!in) {
return NULL;
}
old_locale = setlocale(LC_ALL, "");
codeset = nl_langinfo(CODESET);
if ( codeset == NULL || codeset[0] == 0 ) {
goto done;
}
/* we don't need BOM in output so we choose native BE or LE encoding here */
codeset_out = (platformByteOrder()==BYTE_ORDER_MSBFIRST) ?
"UCS-2BE" : "UCS-2LE";
cd = iconv_open(codeset_out, codeset);
if (cd == (iconv_t)-1 ) {
goto done;
}
inSize = strlen(in);
buf = SAFE_SIZE_ARRAY_ALLOC(malloc, inSize, 2);
if (!buf) {
return NULL;
}
bufSize = inSize*2; // need 2 bytes per char for UCS-2, this is
// 2 bytes per source byte max
out = buf; outSize = bufSize;
/* linux iconv wants char** source and solaris wants const char**...
cast to void* */
rc = iconv(cd, (void*)&in, &inSize, &out, &outSize);
iconv_close(cd);
if (rc == (size_t)-1) {
free(buf);
buf = NULL;
} else {
if (size) {
*size = (bufSize-outSize)/2; /* bytes to wchars */
}
}
done:
setlocale(LC_ALL, old_locale);
return buf;
}
void
SplashInitFrameShape(Splash * splash, int imageIndex) {
ImageRect maskRect;
@@ -136,25 +76,6 @@ SplashInitFrameShape(Splash * splash, int imageIndex) {
free(rects);
}
unsigned
SplashTime(void) {
struct timeval tv;
struct timezone tz;
unsigned long long msec;
gettimeofday(&tv, &tz);
msec = (unsigned long long) tv.tv_sec * 1000 +
(unsigned long long) tv.tv_usec / 1000;
return (unsigned) msec;
}
void
msec2timeval(unsigned time, struct timeval *tv) {
tv->tv_sec = time / 1000;
tv->tv_usec = (time % 1000) * 1000;
}
int
GetNumAvailableColors(Display * display, Screen * screen, unsigned map_entries) {
unsigned long pmr[1];
@@ -208,7 +129,8 @@ FreeColors(Display * display, Screen * screen, int numColors,
XFreeColors(display, cmap, pr, numColors, 0);
}
static void SplashCenter(Splash * splash) {
static void
SplashCenter(Splash * splash) {
Atom type, atom, actual_type;
int status, actual_format;
unsigned long nitems, bytes_after;
@@ -236,7 +158,8 @@ static void SplashCenter(Splash * splash) {
splash->y = (XHeightOfScreen(splash->screen) - splash->height) / 2;
}
static void SplashUpdateSizeHints(Splash * splash) {
static void
SplashUpdateSizeHints(Splash * splash) {
if (splash->window) {
XSizeHints sizeHints;
@@ -249,7 +172,7 @@ static void SplashUpdateSizeHints(Splash * splash) {
}
}
void
bool
SplashCreateWindow(Splash * splash) {
XSizeHints sizeHints;
@@ -277,6 +200,8 @@ SplashCreateWindow(Splash * splash) {
splash->wmHints->initial_state = NormalState;
XSetWMHints(splash->display, splash->window, splash->wmHints);
}
return (bool) splash->window;
}
/* for changing the visible shape of a window to an nonrectangular form */
@@ -333,7 +258,7 @@ SplashRedrawWindow(Splash * splash) {
// much sense as SplashUpdateScreenData always re-generates
// the image completely, so whole window is always redrawn
SplashUpdateScreenData(splash);
SplashUpdateScreenData(splash, false);
ximage = XCreateImage(splash->display, splash->visual,
splash->screenFormat.depthBytes * 8, ZPixmap, 0, (char *) NULL,
splash->width, splash->height, 8, 0);
@@ -352,7 +277,8 @@ SplashRedrawWindow(Splash * splash) {
XFlush(splash->display);
}
void SplashReconfigureNow(Splash * splash) {
void
SplashReconfigureNow(Splash * splash) {
SplashCenter(splash);
if (splash->window) {
XUnmapWindow(splash->display, splash->window);
@@ -369,15 +295,6 @@ void SplashReconfigureNow(Splash * splash) {
SplashRedrawWindow(splash);
}
void
sendctl(Splash * splash, char code) {
// if (splash->isVisible>0) {
if (splash && splash->controlpipe[1]) {
write(splash->controlpipe[1], &code, 1);
}
}
int
HandleError(Display * disp, XErrorEvent * err) {
// silently ignore non-fatal errors
@@ -548,93 +465,38 @@ SplashDonePlatform(Splash * splash) {
XCloseDisplay(splash->display);
}
void
SplashEventLoop(Splash * splash) {
bool
FlushEvents(Splash * splash) {
return true;
}
/* Different from win32 implementation - this loop
uses poll timeouts instead of a timer */
/* we should have splash _locked_ on entry!!! */
bool
DispatchEvents(Splash * splash) {
// we're not using "while(XPending)", processing one event
// at a time to avoid control pipe starvation
if (XPending(splash->display)) {
XEvent evt;
int xconn = XConnectionNumber(splash->display);
while (1) {
struct pollfd pfd[2];
int timeout = -1;
int ctl = splash->controlpipe[0];
int rc;
int pipes_empty;
pfd[0].fd = xconn;
pfd[0].events = POLLIN | POLLPRI;
pfd[1].fd = ctl;
pfd[1].events = POLLIN | POLLPRI;
errno = 0;
if (splash->isVisible>0 && SplashIsStillLooping(splash)) {
timeout = splash->time + splash->frames[splash->currentFrame].delay
- SplashTime();
if (timeout < 0) {
timeout = 0;
}
}
SplashUnlock(splash);
rc = poll(pfd, 2, timeout);
SplashLock(splash);
if (splash->isVisible > 0 && splash->currentFrame >= 0 &&
SplashTime() >= splash->time + splash->frames[splash->currentFrame].delay) {
SplashNextFrame(splash);
SplashUpdateShape(splash);
SplashRedrawWindow(splash);
}
if (rc <= 0) {
errno = 0;
continue;
}
pipes_empty = 0;
while(!pipes_empty) {
char buf;
pipes_empty = 1;
if (read(ctl, &buf, sizeof(buf)) > 0) {
pipes_empty = 0;
switch (buf) {
case SPLASHCTL_UPDATE:
if (splash->isVisible>0) {
SplashRedrawWindow(splash);
}
break;
case SPLASHCTL_RECONFIGURE:
if (splash->isVisible>0) {
SplashReconfigureNow(splash);
}
break;
case SPLASHCTL_QUIT:
return;
XNextEvent(splash->display, &evt);
switch (evt.type) {
case Expose:
if (splash->isVisible>0) {
// we're doing full redraw so we just
// skip the remaining painting events in the queue
while(XCheckTypedEvent(splash->display, Expose,
&evt));
SplashRedrawWindow(splash);
}
}
// we're not using "while(XPending)", processing one event
// at a time to avoid control pipe starvation
if (XPending(splash->display)) {
XEvent evt;
pipes_empty = 0;
XNextEvent(splash->display, &evt);
switch (evt.type) {
case Expose:
if (splash->isVisible>0) {
// we're doing full redraw so we just
// skip the remaining painting events in the queue
while(XCheckTypedEvent(splash->display, Expose,
&evt));
SplashRedrawWindow(splash);
}
break;
/* ... */
}
}
break;
/* ... */
}
}
return true;
}
int
GetDisplayFD(Splash * splash) {
return XConnectionNumber(splash->display);
}
/* we can't use OverrideRedirect for the window as the window should not be
@@ -725,93 +587,13 @@ SplashRemoveDecoration(Splash * splash) {
}
void
SplashPThreadDestructor(void *arg) {
/* this will be used in case of emergency thread exit on xlib error */
Splash *splash = (Splash *) arg;
if (splash) {
SplashCleanup(splash);
}
}
void *
SplashScreenThread(void *param) {
Splash *splash = (Splash *) param;
// pthread_key_t key;
// pthread_key_create(&key, SplashPThreadDestructor);
// pthread_setspecific(key, splash);
SplashLock(splash);
pipe(splash->controlpipe);
fcntl(splash->controlpipe[0], F_SETFL,
fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK);
splash->time = SplashTime();
SplashCreateWindow(splash);
fflush(stdout);
if (splash->window) {
SplashRemoveDecoration(splash);
XStoreName(splash->display, splash->window, "Java");
XMapRaised(splash->display, splash->window);
SplashUpdateShape(splash);
SplashRedrawWindow(splash);
//map the splash coordinates as per system scale
splash->x /= splash->scaleFactor;
splash->y /= splash->scaleFactor;
SplashEventLoop(splash);
}
SplashUnlock(splash);
SplashDone(splash);
splash->isVisible=-1;
return 0;
SplashSetup(Splash * splash) {
SplashRemoveDecoration(splash);
XStoreName(splash->display, splash->window, "Java");
XMapRaised(splash->display, splash->window);
SplashUpdateShape(splash);
}
void
SplashCreateThread(Splash * splash) {
pthread_t thr;
pthread_attr_t attr;
int rc;
pthread_attr_init(&attr);
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
}
void
SplashLock(Splash * splash) {
pthread_mutex_lock(&splash->lock);
}
void
SplashUnlock(Splash * splash) {
pthread_mutex_unlock(&splash->lock);
}
void
SplashClosePlatform(Splash * splash) {
sendctl(splash, SPLASHCTL_QUIT);
}
void
SplashUpdate(Splash * splash) {
sendctl(splash, SPLASHCTL_UPDATE);
}
void
SplashReconfigure(Splash * splash) {
sendctl(splash, SPLASHCTL_RECONFIGURE);
}
JNIEXPORT jboolean
SplashGetScaledImageName(const char* jarName, const char* fileName,
float *scaleFactor, char *scaledImgName,
const size_t scaledImageNameLength)
{
*scaleFactor = 1;
#ifndef __linux__
return JNI_FALSE;
#endif
*scaleFactor = (float)getNativeScaleFactor(NULL, 1);
return GetScaledImageName(fileName, scaledImgName, scaleFactor, scaledImageNameLength);
}
SplashUpdateCursor(Splash * splash) {
}

View File

@@ -55,4 +55,7 @@ public class PlatformGraphicsInfo {
"but this program performed an operation which requires it.";
}
public static String getSplashScreenLib() {
return "splashscreen";
}
}

View File

@@ -218,7 +218,7 @@ SplashRedrawWindow(Splash * splash)
return;
}
SplashUpdateScreenData(splash);
SplashUpdateScreenData(splash, false);
if (splash->isLayered) {
BLENDFUNCTION bf;
POINT ptSrc;