Merge pull request #109811 from bruvzg/svg_rename

Rename SVGTexture to DPITexture.
This commit is contained in:
Thaddeus Crews
2025-08-21 06:24:23 -05:00
13 changed files with 107 additions and 107 deletions

View File

@@ -43,8 +43,8 @@
#include "scene/gui/subviewport_container.h"
#include "scene/main/canvas_layer.h"
#include "scene/main/window.h"
#include "scene/resources/dpi_texture.h"
#include "scene/resources/mesh.h"
#include "scene/resources/svg_texture.h"
#include "scene/resources/text_line.h"
#include "scene/resources/world_2d.h"
#include "servers/audio_server.h"
@@ -1090,8 +1090,8 @@ bool Viewport::_set_size(const Size2i &p_size, const Size2 &p_size_2d_override,
TS->reference_oversampling_level(new_font_oversampling);
TS->unreference_oversampling_level(font_oversampling);
SVGTexture::reference_scaling_level(new_font_oversampling);
SVGTexture::unreference_scaling_level(font_oversampling);
DPITexture::reference_scaling_level(new_font_oversampling);
DPITexture::unreference_scaling_level(font_oversampling);
}
size = new_size;

View File

@@ -134,6 +134,7 @@
#if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
#include "scene/resources/navigation_mesh.h"
#endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
#include "scene/resources/dpi_texture.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/particle_process_material.h"
#include "scene/resources/placeholder_textures.h"
@@ -147,7 +148,6 @@
#include "scene/resources/style_box_line.h"
#include "scene/resources/style_box_texture.h"
#include "scene/resources/surface_tool.h"
#include "scene/resources/svg_texture.h"
#include "scene/resources/syntax_highlighter.h"
#include "scene/resources/text_line.h"
#include "scene/resources/text_paragraph.h"
@@ -1039,7 +1039,7 @@ void register_scene_types() {
GDREGISTER_CLASS(PlaceholderTexture2DArray);
GDREGISTER_CLASS(PlaceholderCubemap);
GDREGISTER_CLASS(PlaceholderCubemapArray);
GDREGISTER_CLASS(SVGTexture);
GDREGISTER_CLASS(DPITexture);
#ifndef DISABLE_DEPRECATED
GDREGISTER_CLASS(AnimatedTexture);
#endif

View File

@@ -1,5 +1,5 @@
/**************************************************************************/
/* svg_texture.cpp */
/* dpi_texture.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "svg_texture.h"
#include "dpi_texture.h"
#include "core/io/image_loader.h"
#include "scene/main/canvas_item.h"
@@ -41,10 +41,10 @@
#include "modules/svg/image_loader_svg.h"
#endif
Mutex SVGTexture::mutex;
HashMap<double, SVGTexture::ScalingLevel> SVGTexture::scaling_levels;
Mutex DPITexture::mutex;
HashMap<double, DPITexture::ScalingLevel> DPITexture::scaling_levels;
void SVGTexture::reference_scaling_level(double p_scale) {
void DPITexture::reference_scaling_level(double p_scale) {
uint32_t oversampling = CLAMP(p_scale, 0.1, 100.0) * 64;
if (oversampling == 64) {
return;
@@ -61,7 +61,7 @@ void SVGTexture::reference_scaling_level(double p_scale) {
}
}
void SVGTexture::unreference_scaling_level(double p_scale) {
void DPITexture::unreference_scaling_level(double p_scale) {
uint32_t oversampling = CLAMP(p_scale, 0.1, 100.0) * 64;
if (oversampling == 64) {
return;
@@ -73,7 +73,7 @@ void SVGTexture::unreference_scaling_level(double p_scale) {
if (sl) {
sl->refcount--;
if (sl->refcount == 0) {
for (SVGTexture *tx : sl->textures) {
for (DPITexture *tx : sl->textures) {
tx->_remove_scale(scale);
}
sl->textures.clear();
@@ -82,17 +82,17 @@ void SVGTexture::unreference_scaling_level(double p_scale) {
}
}
Ref<SVGTexture> SVGTexture::create_from_string(const String &p_source, float p_scale, float p_saturation, const Dictionary &p_color_map) {
Ref<SVGTexture> svg_texture;
svg_texture.instantiate();
svg_texture->set_source(p_source);
svg_texture->set_base_scale(p_scale);
svg_texture->set_saturation(p_saturation);
svg_texture->set_color_map(p_color_map);
return svg_texture;
Ref<DPITexture> DPITexture::create_from_string(const String &p_source, float p_scale, float p_saturation, const Dictionary &p_color_map) {
Ref<DPITexture> dpi_texture;
dpi_texture.instantiate();
dpi_texture->set_source(p_source);
dpi_texture->set_base_scale(p_scale);
dpi_texture->set_saturation(p_saturation);
dpi_texture->set_color_map(p_color_map);
return dpi_texture;
}
void SVGTexture::set_source(const String &p_source) {
void DPITexture::set_source(const String &p_source) {
if (source == p_source) {
return;
}
@@ -100,11 +100,11 @@ void SVGTexture::set_source(const String &p_source) {
_update_texture();
}
String SVGTexture::get_source() const {
String DPITexture::get_source() const {
return source;
}
void SVGTexture::set_base_scale(float p_scale) {
void DPITexture::set_base_scale(float p_scale) {
if (base_scale == p_scale) {
return;
}
@@ -114,11 +114,11 @@ void SVGTexture::set_base_scale(float p_scale) {
_update_texture();
}
float SVGTexture::get_base_scale() const {
float DPITexture::get_base_scale() const {
return base_scale;
}
void SVGTexture::set_saturation(float p_saturation) {
void DPITexture::set_saturation(float p_saturation) {
if (saturation == p_saturation) {
return;
}
@@ -127,11 +127,11 @@ void SVGTexture::set_saturation(float p_saturation) {
_update_texture();
}
float SVGTexture::get_saturation() const {
float DPITexture::get_saturation() const {
return saturation;
}
void SVGTexture::set_color_map(const Dictionary &p_color_map) {
void DPITexture::set_color_map(const Dictionary &p_color_map) {
if (color_map == p_color_map) {
return;
}
@@ -143,11 +143,11 @@ void SVGTexture::set_color_map(const Dictionary &p_color_map) {
_update_texture();
}
Dictionary SVGTexture::get_color_map() const {
Dictionary DPITexture::get_color_map() const {
return color_map;
}
void SVGTexture::_remove_scale(double p_scale) {
void DPITexture::_remove_scale(double p_scale) {
if (Math::is_equal_approx(p_scale, 1.0)) {
return;
}
@@ -161,7 +161,7 @@ void SVGTexture::_remove_scale(double p_scale) {
}
}
RID SVGTexture::_ensure_scale(double p_scale) const {
RID DPITexture::_ensure_scale(double p_scale) const {
uint32_t oversampling = CLAMP(p_scale, 0.1, 100.0) * 64;
if (oversampling == 64) {
if (base_texture.is_null()) {
@@ -179,14 +179,14 @@ RID SVGTexture::_ensure_scale(double p_scale) const {
MutexLock lock(mutex);
ScalingLevel *sl = scaling_levels.getptr(scale);
ERR_FAIL_NULL_V_MSG(sl, RID(), "Invalid scaling level");
sl->textures.insert(const_cast<SVGTexture *>(this));
sl->textures.insert(const_cast<DPITexture *>(this));
RID new_rid = _load_at_scale(scale, false);
texture_cache[scale] = new_rid;
return new_rid;
}
RID SVGTexture::_load_at_scale(double p_scale, bool p_set_size) const {
RID DPITexture::_load_at_scale(double p_scale, bool p_set_size) const {
Ref<Image> img;
img.instantiate();
#ifdef MODULE_SVG_ENABLED
@@ -227,7 +227,7 @@ RID SVGTexture::_load_at_scale(double p_scale, bool p_set_size) const {
return rid;
}
void SVGTexture::_clear() {
void DPITexture::_clear() {
for (KeyValue<double, RID> &tx : texture_cache) {
if (tx.value.is_valid()) {
RenderingServer::get_singleton()->free(tx.value);
@@ -241,12 +241,12 @@ void SVGTexture::_clear() {
alpha_cache.unref();
}
void SVGTexture::_update_texture() {
void DPITexture::_update_texture() {
_clear();
emit_changed();
}
Ref<Image> SVGTexture::get_image() const {
Ref<Image> DPITexture::get_image() const {
RID rid = _ensure_scale(1.0);
if (rid.is_valid()) {
return RenderingServer::get_singleton()->texture_2d_get(rid);
@@ -255,25 +255,25 @@ Ref<Image> SVGTexture::get_image() const {
}
}
int SVGTexture::get_width() const {
int DPITexture::get_width() const {
_ensure_scale(1.0);
return size.x;
}
int SVGTexture::get_height() const {
int DPITexture::get_height() const {
_ensure_scale(1.0);
return size.y;
}
RID SVGTexture::get_rid() const {
RID DPITexture::get_rid() const {
return _ensure_scale(1.0);
}
bool SVGTexture::has_alpha() const {
bool DPITexture::has_alpha() const {
return true;
}
RID SVGTexture::get_scaled_rid() const {
RID DPITexture::get_scaled_rid() const {
double scale = 1.0;
CanvasItem *ci = CanvasItem::get_current_item_drawn();
if (ci) {
@@ -285,19 +285,19 @@ RID SVGTexture::get_scaled_rid() const {
return _ensure_scale(scale);
}
void SVGTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose) const {
void DPITexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose) const {
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, size), get_scaled_rid(), false, p_modulate, p_transpose);
}
void SVGTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose) const {
void DPITexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose) const {
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, get_scaled_rid(), p_tile, p_modulate, p_transpose);
}
void SVGTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, bool p_clip_uv) const {
void DPITexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, bool p_clip_uv) const {
RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, get_scaled_rid(), p_src_rect, p_modulate, p_transpose, p_clip_uv);
}
bool SVGTexture::is_pixel_opaque(int p_x, int p_y) const {
bool DPITexture::is_pixel_opaque(int p_x, int p_y) const {
if (alpha_cache.is_null()) {
Ref<Image> img = get_image();
if (img.is_valid()) {
@@ -325,7 +325,7 @@ bool SVGTexture::is_pixel_opaque(int p_x, int p_y) const {
return true;
}
void SVGTexture::set_size_override(const Size2i &p_size) {
void DPITexture::set_size_override(const Size2i &p_size) {
if (size_override == p_size) {
return;
}
@@ -352,19 +352,19 @@ void SVGTexture::set_size_override(const Size2i &p_size) {
emit_changed();
}
void SVGTexture::_bind_methods() {
ClassDB::bind_static_method("SVGTexture", D_METHOD("create_from_string", "source", "scale", "saturation", "color_map"), &SVGTexture::create_from_string, DEFVAL(1.0), DEFVAL(1.0), DEFVAL(Dictionary()));
void DPITexture::_bind_methods() {
ClassDB::bind_static_method("DPITexture", D_METHOD("create_from_string", "source", "scale", "saturation", "color_map"), &DPITexture::create_from_string, DEFVAL(1.0), DEFVAL(1.0), DEFVAL(Dictionary()));
ClassDB::bind_method(D_METHOD("set_source", "source"), &SVGTexture::set_source);
ClassDB::bind_method(D_METHOD("get_source"), &SVGTexture::get_source);
ClassDB::bind_method(D_METHOD("set_base_scale", "base_scale"), &SVGTexture::set_base_scale);
ClassDB::bind_method(D_METHOD("get_base_scale"), &SVGTexture::get_base_scale);
ClassDB::bind_method(D_METHOD("set_saturation", "saturation"), &SVGTexture::set_saturation);
ClassDB::bind_method(D_METHOD("get_saturation"), &SVGTexture::get_saturation);
ClassDB::bind_method(D_METHOD("set_color_map", "color_map"), &SVGTexture::set_color_map);
ClassDB::bind_method(D_METHOD("get_color_map"), &SVGTexture::get_color_map);
ClassDB::bind_method(D_METHOD("set_size_override", "size"), &SVGTexture::set_size_override);
ClassDB::bind_method(D_METHOD("get_scaled_rid"), &SVGTexture::get_scaled_rid);
ClassDB::bind_method(D_METHOD("set_source", "source"), &DPITexture::set_source);
ClassDB::bind_method(D_METHOD("get_source"), &DPITexture::get_source);
ClassDB::bind_method(D_METHOD("set_base_scale", "base_scale"), &DPITexture::set_base_scale);
ClassDB::bind_method(D_METHOD("get_base_scale"), &DPITexture::get_base_scale);
ClassDB::bind_method(D_METHOD("set_saturation", "saturation"), &DPITexture::set_saturation);
ClassDB::bind_method(D_METHOD("get_saturation"), &DPITexture::get_saturation);
ClassDB::bind_method(D_METHOD("set_color_map", "color_map"), &DPITexture::set_color_map);
ClassDB::bind_method(D_METHOD("get_color_map"), &DPITexture::get_color_map);
ClassDB::bind_method(D_METHOD("set_size_override", "size"), &DPITexture::set_size_override);
ClassDB::bind_method(D_METHOD("get_scaled_rid"), &DPITexture::get_scaled_rid);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "_source", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_STORAGE), "set_source", "get_source");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "base_scale", PROPERTY_HINT_RANGE, "0.01,10.0,0.01"), "set_base_scale", "get_base_scale");
@@ -372,7 +372,7 @@ void SVGTexture::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "color_map", PROPERTY_HINT_DICTIONARY_TYPE, "Color;Color"), "set_color_map", "get_color_map");
}
SVGTexture::~SVGTexture() {
DPITexture::~DPITexture() {
_clear();
MutexLock lock(mutex);

View File

@@ -1,5 +1,5 @@
/**************************************************************************/
/* svg_texture.h */
/* dpi_texture.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -35,9 +35,9 @@
class BitMap;
class SVGTexture : public Texture2D {
GDCLASS(SVGTexture, Texture2D);
RES_BASE_EXTENSION("svgtex");
class DPITexture : public Texture2D {
GDCLASS(DPITexture, Texture2D);
RES_BASE_EXTENSION("dpitex");
String source;
float base_scale = 1.0;
@@ -46,7 +46,7 @@ class SVGTexture : public Texture2D {
Size2 size_override;
struct ScalingLevel {
HashSet<SVGTexture *> textures;
HashSet<DPITexture *> textures;
int32_t refcount = 1;
};
static Mutex mutex;
@@ -69,7 +69,7 @@ protected:
static void _bind_methods();
public:
static Ref<SVGTexture> create_from_string(const String &p_source, float p_scale = 1.0, float p_saturation = 1.0, const Dictionary &p_color_map = Dictionary());
static Ref<DPITexture> create_from_string(const String &p_source, float p_scale = 1.0, float p_saturation = 1.0, const Dictionary &p_color_map = Dictionary());
void set_source(const String &p_source);
String get_source() const;
@@ -102,5 +102,5 @@ public:
static void reference_scaling_level(double p_scale);
static void unreference_scaling_level(double p_scale);
~SVGTexture();
~DPITexture();
};

View File

@@ -31,12 +31,12 @@
#include "default_theme.h"
#include "core/io/image.h"
#include "scene/resources/dpi_texture.h"
#include "scene/resources/font.h"
#include "scene/resources/gradient_texture.h"
#include "scene/resources/image_texture.h"
#include "scene/resources/style_box_flat.h"
#include "scene/resources/style_box_line.h"
#include "scene/resources/svg_texture.h"
#include "scene/resources/theme.h"
#include "scene/scene_string_names.h"
#include "scene/theme/default_theme_icons.gen.h"
@@ -79,8 +79,8 @@ static Ref<StyleBoxFlat> sb_expand(Ref<StyleBoxFlat> p_sbox, float p_left, float
}
// See also `editor_generate_icon()` in `editor/themes/editor_icons.cpp`.
static Ref<SVGTexture> generate_icon(int p_index) {
return SVGTexture::create_from_string(default_theme_icons_sources[p_index], scale);
static Ref<DPITexture> generate_icon(int p_index) {
return DPITexture::create_from_string(default_theme_icons_sources[p_index], scale);
}
static Ref<StyleBox> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {