Fix cursor blinking in integrated GPUs

Optimization for Input::set_custom_mouse_cursor when used inside
_process function. (Avoids cursor blinking in low end devices)
This commit is contained in:
Guilherme Felipe 2019-07-08 17:37:18 -03:00
parent 5e495750a3
commit a9a0d0fb15
8 changed files with 75 additions and 0 deletions

View file

@ -448,6 +448,18 @@ void OS_JavaScript::set_cursor_shape(CursorShape p_shape) {
void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
if (p_cursor.is_valid()) {
Map<CursorShape, Vector<Variant> >::Element *cursor_c = cursors_cache.find(p_shape);
if (cursor_c) {
if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
set_cursor_shape(p_shape);
return;
}
cursors_cache.erase(p_shape);
}
Ref<Texture> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
@ -551,6 +563,11 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s
cursors[p_shape] = url;
Vector<Variant> params;
params.push_back(p_cursor);
params.push_back(p_hotspot);
cursors_cache.insert(p_shape, params);
} else if (cursors[p_shape] != "") {
/* clang-format off */
EM_ASM({

View file

@ -52,6 +52,7 @@ class OS_JavaScript : public OS_Unix {
Ref<InputEventKey> deferred_key_event;
CursorShape cursor_shape;
String cursors[CURSOR_MAX];
Map<CursorShape, Vector<Variant> > cursors_cache;
Point2 touches[32];
Point2i last_click_pos;

View file

@ -119,6 +119,7 @@ public:
CursorShape cursor_shape;
NSCursor *cursors[CURSOR_MAX];
Map<CursorShape, Vector<Variant> > cursors_cache;
MouseMode mouse_mode;
String title;

View file

@ -1770,7 +1770,20 @@ OS::CursorShape OS_OSX::get_cursor_shape() const {
}
void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
if (p_cursor.is_valid()) {
Map<CursorShape, Vector<Variant> >::Element *cursor_c = cursors_cache.find(p_shape);
if (cursor_c) {
if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
set_cursor_shape(p_shape);
return;
}
cursors_cache.erase(p_shape);
}
Ref<Texture> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
@ -1855,6 +1868,11 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
[cursors[p_shape] release];
cursors[p_shape] = cursor;
Vector<Variant> params;
params.push_back(p_cursor);
params.push_back(p_hotspot);
cursors_cache.insert(p_shape, params);
if (p_shape == cursor_shape) {
if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
[cursor set];

View file

@ -2367,7 +2367,20 @@ OS::CursorShape OS_Windows::get_cursor_shape() const {
}
void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
if (p_cursor.is_valid()) {
Map<CursorShape, Vector<Variant> >::Element *cursor_c = cursors_cache.find(p_shape);
if (cursor_c) {
if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
set_cursor_shape(p_shape);
return;
}
cursors_cache.erase(p_shape);
}
Ref<Texture> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
@ -2450,6 +2463,11 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
cursors[p_shape] = CreateIconIndirect(&iconinfo);
Vector<Variant> params;
params.push_back(p_cursor);
params.push_back(p_hotspot);
cursors_cache.insert(p_shape, params);
if (p_shape == cursor_shape) {
if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
SetCursor(cursors[p_shape]);

View file

@ -155,6 +155,7 @@ class OS_Windows : public OS {
HCURSOR cursors[CURSOR_MAX] = { NULL };
CursorShape cursor_shape;
Map<CursorShape, Vector<Variant> > cursors_cache;
InputDefault *input;
JoypadWindows *joypad;

View file

@ -2878,7 +2878,20 @@ OS::CursorShape OS_X11::get_cursor_shape() const {
}
void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
if (p_cursor.is_valid()) {
Map<CursorShape, Vector<Variant> >::Element *cursor_c = cursors_cache.find(p_shape);
if (cursor_c) {
if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
set_cursor_shape(p_shape);
return;
}
cursors_cache.erase(p_shape);
}
Ref<Texture> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
@ -2947,6 +2960,11 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
// Save it for a further usage
cursors[p_shape] = XcursorImageLoadCursor(x11_display, cursor_image);
Vector<Variant> params;
params.push_back(p_cursor);
params.push_back(p_hotspot);
cursors_cache.insert(p_shape, params);
if (p_shape == current_cursor) {
if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
XDefineCursor(x11_display, x11_window, cursors[p_shape]);

View file

@ -170,6 +170,7 @@ class OS_X11 : public OS_Unix {
Cursor cursors[CURSOR_MAX];
Cursor null_cursor;
CursorShape current_cursor;
Map<CursorShape, Vector<Variant> > cursors_cache;
InputDefault *input;