Merge pull request #97698 from Calinou/displayserver-can-create-rendering-device-add-caching
Add caching to `DisplayServer::can_create_rendering_device()`
This commit is contained in:
commit
34913f2781
2 changed files with 23 additions and 0 deletions
|
@ -1229,6 +1229,12 @@ bool DisplayServer::can_create_rendering_device() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (created_rendering_device == RenderingDeviceCreationStatus::SUCCESS) {
|
||||||
|
return true;
|
||||||
|
} else if (created_rendering_device == RenderingDeviceCreationStatus::FAILURE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Error err;
|
Error err;
|
||||||
RenderingContextDriver *rcd = nullptr;
|
RenderingContextDriver *rcd = nullptr;
|
||||||
|
|
||||||
|
@ -1258,7 +1264,14 @@ bool DisplayServer::can_create_rendering_device() {
|
||||||
memdelete(rd);
|
memdelete(rd);
|
||||||
rd = nullptr;
|
rd = nullptr;
|
||||||
if (err == OK) {
|
if (err == OK) {
|
||||||
|
// Creating a RenderingDevice is quite slow.
|
||||||
|
// Cache the result for future usage, so that it's much faster on subsequent calls.
|
||||||
|
created_rendering_device = RenderingDeviceCreationStatus::SUCCESS;
|
||||||
|
memdelete(rcd);
|
||||||
|
rcd = nullptr;
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
created_rendering_device = RenderingDeviceCreationStatus::FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -594,6 +594,16 @@ public:
|
||||||
static Vector<String> get_create_function_rendering_drivers(int p_index);
|
static Vector<String> get_create_function_rendering_drivers(int p_index);
|
||||||
static DisplayServer *create(int p_index, const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error);
|
static DisplayServer *create(int p_index, const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error);
|
||||||
|
|
||||||
|
enum RenderingDeviceCreationStatus {
|
||||||
|
UNKNOWN,
|
||||||
|
SUCCESS,
|
||||||
|
FAILURE,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Used to cache the result of `can_create_rendering_device()` when RenderingDevice isn't currently being used.
|
||||||
|
// This is done as creating a RenderingDevice is quite slow.
|
||||||
|
static inline RenderingDeviceCreationStatus created_rendering_device = RenderingDeviceCreationStatus::UNKNOWN;
|
||||||
|
|
||||||
static bool can_create_rendering_device();
|
static bool can_create_rendering_device();
|
||||||
|
|
||||||
DisplayServer();
|
DisplayServer();
|
||||||
|
|
Loading…
Reference in a new issue