Moved png from drivers to a module.

This commit is contained in:
Relintai 2023-12-17 13:56:04 +01:00
parent 9599e22768
commit 094ff36131
40 changed files with 111 additions and 23 deletions

View File

@ -30,27 +30,10 @@
#include "register_driver_types.h" #include "register_driver_types.h"
#include "drivers/png/image_loader_png.h"
#include "drivers/png/resource_saver_png.h"
static ImageLoaderPNG *image_loader_png;
static Ref<ResourceSaverPNG> resource_saver_png;
void register_core_driver_types() { void register_core_driver_types() {
image_loader_png = memnew(ImageLoaderPNG);
ImageLoader::add_image_format_loader(image_loader_png);
resource_saver_png.instance();
ResourceSaver::add_resource_format_saver(resource_saver_png);
} }
void unregister_core_driver_types() { void unregister_core_driver_types() {
if (image_loader_png) {
memdelete(image_loader_png);
}
ResourceSaver::remove_resource_format_saver(resource_saver_png);
resource_saver_png.unref();
} }
void register_driver_types() { void register_driver_types() {

View File

@ -93,7 +93,7 @@ if env["builtin_freetype"]:
# Also requires libpng headers # Also requires libpng headers
if env["builtin_libpng"]: if env["builtin_libpng"]:
env_freetype.Prepend(CPPPATH=["#thirdparty/libpng"]) env_freetype.Prepend(CPPPATH=["#modules/png/libpng"])
sfnt = thirdparty_dir + "src/sfnt/sfnt.c" sfnt = thirdparty_dir + "src/sfnt/sfnt.c"
# Must be done after all CPPDEFINES are being set so we can copy them. # Must be done after all CPPDEFINES are being set so we can copy them.

View File

@ -1,5 +1,7 @@
def can_build(env, platform): def can_build(env, platform):
env.module_add_dependencies("freetype", ["png"], False)
return True return True

View File

@ -1,8 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
Import("env") Import("env")
Import("env_modules")
env_png = env.Clone() env_png = env_modules.Clone()
# Thirdparty source files # Thirdparty source files
@ -57,7 +58,7 @@ if env["builtin_libpng"]:
neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/palette_neon_intrinsics.c")) neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/palette_neon_intrinsics.c"))
thirdparty_obj += neon_sources thirdparty_obj += neon_sources
env.drivers_sources += thirdparty_obj env.modules_sources += thirdparty_obj
# Pandemonium source files # Pandemonium source files
@ -65,7 +66,7 @@ if env["builtin_libpng"]:
driver_obj = [] driver_obj = []
env_png.add_source_files(driver_obj, "*.cpp") env_png.add_source_files(driver_obj, "*.cpp")
env.drivers_sources += driver_obj env.modules_sources += driver_obj
# Needed to force rebuilding the driver files when the thirdparty library is updated. # Needed to force rebuilding the driver files when the thirdparty library is updated.
env.Depends(driver_obj, thirdparty_obj) env.Depends(driver_obj, thirdparty_obj)

6
modules/png/config.py Normal file
View File

@ -0,0 +1,6 @@
def can_build(env, platform):
return True
def configure(env):
pass

View File

@ -32,7 +32,7 @@
#include "core/os/os.h" #include "core/os/os.h"
#include "core/string/print_string.h" #include "core/string/print_string.h"
#include "drivers/png/png_driver_common.h" #include "png_driver_common.h"
#include <string.h> #include <string.h>

View File

@ -0,0 +1,58 @@
/*************************************************************************/
/* register_types.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "register_types.h"
#include "image_loader_png.h"
#include "resource_saver_png.h"
static ImageLoaderPNG *image_loader_png = NULL;
static Ref<ResourceSaverPNG> resource_saver_png;
void register_png_types(ModuleRegistrationLevel p_level) {
if (p_level == MODULE_REGISTRATION_LEVEL_CORE) {
image_loader_png = memnew(ImageLoaderPNG);
ImageLoader::add_image_format_loader(image_loader_png);
resource_saver_png.instance();
ResourceSaver::add_resource_format_saver(resource_saver_png);
}
}
void unregister_png_types(ModuleRegistrationLevel p_level) {
if (p_level == MODULE_REGISTRATION_LEVEL_CORE) {
if (image_loader_png) {
memdelete(image_loader_png);
}
ResourceSaver::remove_resource_format_saver(resource_saver_png);
resource_saver_png.unref();
}
}

View File

@ -0,0 +1,38 @@
#ifndef PNG_REGISTER_TYPES_H
#define PNG_REGISTER_TYPES_H
/*************************************************************************/
/* register_types.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "modules/register_module_types.h"
void register_png_types(ModuleRegistrationLevel p_level);
void unregister_png_types(ModuleRegistrationLevel p_level);
#endif // BMP_REGISTER_TYPES_H

View File

@ -32,7 +32,7 @@
#include "core/io/image.h" #include "core/io/image.h"
#include "core/os/file_access.h" #include "core/os/file_access.h"
#include "drivers/png/png_driver_common.h" #include "png_driver_common.h"
#include "scene/resources/texture.h" #include "scene/resources/texture.h"
Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {