diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-04-22 13:19:34 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-04-22 13:19:34 +0200 |
| commit | 898873b91e82dd2f16458197b21332cfe6cde003 (patch) | |
| tree | 42429029d5cf5c2718de75db3e94dcb1445ec699 | |
| parent | 66d9a6acdea7f78bf64aec671bcefd5116505191 (diff) | |
| parent | 303bf247dee16df54651c9e5d7c3d11ce53a55ec (diff) | |
| download | redot-engine-898873b91e82dd2f16458197b21332cfe6cde003.tar.gz | |
Merge pull request #76309 from Calinou/custom-mouse-cursor-error-compressed
Add support for VRAM-compressed custom mouse cursor images
| -rw-r--r-- | doc/classes/Input.xml | 2 | ||||
| -rw-r--r-- | platform/linuxbsd/x11/display_server_x11.cpp | 5 | ||||
| -rw-r--r-- | platform/macos/display_server_macos.mm | 5 | ||||
| -rw-r--r-- | platform/web/display_server_web.cpp | 7 | ||||
| -rw-r--r-- | platform/windows/display_server_windows.cpp | 5 |
5 files changed, 22 insertions, 2 deletions
diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml index d81812dc35..ecc9c3d89a 100644 --- a/doc/classes/Input.xml +++ b/doc/classes/Input.xml @@ -303,7 +303,7 @@ [param image]'s size must be lower than or equal to 256×256. To avoid rendering issues, sizes lower than or equal to 128×128 are recommended. [param hotspot] must be within [param image]'s size. [b]Note:[/b] [AnimatedTexture]s aren't supported as custom mouse cursors. If using an [AnimatedTexture], only the first frame will be displayed. - [b]Note:[/b] Only images imported with the [b]Lossless[/b], [b]Lossy[/b] or [b]Uncompressed[/b] compression modes are supported. The [b]Video RAM[/b] compression mode can't be used for custom cursors. + [b]Note:[/b] The [b]Lossless[/b], [b]Lossy[/b] or [b]Uncompressed[/b] compression modes are recommended. The [b]Video RAM[/b] compression mode can be used, but it will be decompressed on the CPU, which means loading times are slowed down and no memory is saved compared to lossless modes. [b]Note:[/b] On the web platform, the maximum allowed cursor image size is 128×128. Cursor images larger than 32×32 will also only be displayed if the mouse cursor image is entirely located within the page for [url=https://chromestatus.com/feature/5825971391299584]security reasons[/url]. </description> </method> diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 9d9d4ae43e..ac4fbe2068 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -2671,6 +2671,11 @@ void DisplayServerX11::cursor_set_custom_image(const Ref<Resource> &p_cursor, Cu Ref<Image> image = texture->get_image(); ERR_FAIL_COND(!image.is_valid()); + if (image->is_compressed()) { + image = image->duplicate(true); + Error err = image->decompress(); + ERR_FAIL_COND_MSG(err != OK, "Couldn't decompress VRAM-compressed custom mouse cursor image. Switch to a lossless compression mode in the Import dock."); + } // Create the cursor structure XcursorImage *cursor_image = XcursorImageCreate(texture_size.width, texture_size.height); diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 1bff23f227..5a7c309448 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -3300,6 +3300,11 @@ void DisplayServerMacOS::cursor_set_custom_image(const Ref<Resource> &p_cursor, Ref<Image> image = texture->get_image(); ERR_FAIL_COND(!image.is_valid()); + if (image->is_compressed()) { + image = image->duplicate(true); + Error err = image->decompress(); + ERR_FAIL_COND_MSG(err != OK, "Couldn't decompress VRAM-compressed custom mouse cursor image. Switch to a lossless compression mode in the Import dock."); + } NSBitmapImageRep *imgrep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nullptr diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index da55e8560a..28f1914c37 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -426,7 +426,12 @@ void DisplayServerWeb::cursor_set_custom_image(const Ref<Resource> &p_cursor, Cu ERR_FAIL_COND(!image.is_valid()); - image = image->duplicate(); + image = image->duplicate(true); + + if (image->is_compressed()) { + Error err = image->decompress(); + ERR_FAIL_COND_MSG(err != OK, "Couldn't decompress VRAM-compressed custom mouse cursor image. Switch to a lossless compression mode in the Import dock."); + } if (atlas_texture.is_valid()) { image->crop_from_point( diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index e910fd471f..02bb30ed38 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -1742,6 +1742,11 @@ void DisplayServerWindows::cursor_set_custom_image(const Ref<Resource> &p_cursor Ref<Image> image = texture->get_image(); ERR_FAIL_COND(!image.is_valid()); + if (image->is_compressed()) { + image = image->duplicate(true); + Error err = image->decompress(); + ERR_FAIL_COND_MSG(err != OK, "Couldn't decompress VRAM-compressed custom mouse cursor image. Switch to a lossless compression mode in the Import dock."); + } UINT image_size = texture_size.width * texture_size.height; |
