Skip to content

Commit

Permalink
Merge pull request #76309 from Calinou/custom-mouse-cursor-error-comp…
Browse files Browse the repository at this point in the history
…ressed

Add support for VRAM-compressed custom mouse cursor images
  • Loading branch information
akien-mga committed Apr 22, 2023
2 parents 66d9a6a + 303bf24 commit 898873b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/classes/Input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3300,6 +3300,11 @@
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
Expand Down
7 changes: 6 additions & 1 deletion platform/web/display_server_web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 898873b

Please sign in to comment.