diff options
Diffstat (limited to 'platform/web')
-rw-r--r-- | platform/web/display_server_web.cpp | 52 | ||||
-rw-r--r-- | platform/web/export/export_plugin.cpp | 6 | ||||
-rw-r--r-- | platform/web/export/run_icon.svg | 2 | ||||
-rw-r--r-- | platform/web/http_client_web.cpp | 10 | ||||
-rw-r--r-- | platform/web/http_client_web.h | 1 | ||||
-rw-r--r-- | platform/web/js/libs/library_godot_display.js | 25 | ||||
-rw-r--r-- | platform/web/js/libs/library_godot_fetch.js | 15 |
7 files changed, 58 insertions, 53 deletions
diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index 951ce110e0..93b0496d74 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -35,6 +35,7 @@ #include "os_web.h" #include "core/config/project_settings.h" +#include "scene/resources/atlas_texture.h" #include "servers/rendering/dummy/rasterizer_dummy.h" #ifdef GLES3_ENABLED @@ -731,35 +732,40 @@ void DisplayServerWeb::send_window_event_callback(int p_notification) { } void DisplayServerWeb::set_icon(const Ref<Image> &p_icon) { - ERR_FAIL_COND(p_icon.is_null()); - Ref<Image> icon = p_icon; - if (icon->is_compressed()) { - icon = icon->duplicate(); - ERR_FAIL_COND(icon->decompress() != OK); - } - if (icon->get_format() != Image::FORMAT_RGBA8) { - if (icon == p_icon) { + if (p_icon.is_valid()) { + ERR_FAIL_COND(p_icon->get_width() <= 0 || p_icon->get_height() <= 0); + + Ref<Image> icon = p_icon; + if (icon->is_compressed()) { icon = icon->duplicate(); + ERR_FAIL_COND(icon->decompress() != OK); + } + if (icon->get_format() != Image::FORMAT_RGBA8) { + if (icon == p_icon) { + icon = icon->duplicate(); + } + icon->convert(Image::FORMAT_RGBA8); } - icon->convert(Image::FORMAT_RGBA8); - } - png_image png_meta; - memset(&png_meta, 0, sizeof png_meta); - png_meta.version = PNG_IMAGE_VERSION; - png_meta.width = icon->get_width(); - png_meta.height = icon->get_height(); - png_meta.format = PNG_FORMAT_RGBA; + png_image png_meta; + memset(&png_meta, 0, sizeof png_meta); + png_meta.version = PNG_IMAGE_VERSION; + png_meta.width = icon->get_width(); + png_meta.height = icon->get_height(); + png_meta.format = PNG_FORMAT_RGBA; - PackedByteArray png; - size_t len; - PackedByteArray data = icon->get_data(); - ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, nullptr)); + PackedByteArray png; + size_t len; + PackedByteArray data = icon->get_data(); + ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, nullptr)); - png.resize(len); - ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, nullptr)); + png.resize(len); + ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, nullptr)); - godot_js_display_window_icon_set(png.ptr(), len); + godot_js_display_window_icon_set(png.ptr(), len); + } else { + godot_js_display_window_icon_set(nullptr, 0); + } } void DisplayServerWeb::_dispatch_input_event(const Ref<InputEvent> &p_event) { diff --git a/platform/web/export/export_plugin.cpp b/platform/web/export/export_plugin.cpp index 83bf436c41..38e2714d9f 100644 --- a/platform/web/export/export_plugin.cpp +++ b/platform/web/export/export_plugin.cpp @@ -37,6 +37,7 @@ #include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/export/editor_export.h" +#include "scene/resources/image_texture.h" #include "modules/modules_enabled.gen.h" // For mono and svg. #ifdef MODULE_SVG_ENABLED @@ -674,11 +675,10 @@ EditorExportPlatformWeb::EditorExportPlatformWeb() { Ref<Image> img = memnew(Image); const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE); - ImageLoaderSVG img_loader; - img_loader.create_image_from_string(img, _web_logo_svg, EDSCALE, upsample, false); + ImageLoaderSVG::create_image_from_string(img, _web_logo_svg, EDSCALE, upsample, false); logo = ImageTexture::create_from_image(img); - img_loader.create_image_from_string(img, _web_run_icon_svg, EDSCALE, upsample, false); + ImageLoaderSVG::create_image_from_string(img, _web_run_icon_svg, EDSCALE, upsample, false); run_icon = ImageTexture::create_from_image(img); #endif diff --git a/platform/web/export/run_icon.svg b/platform/web/export/run_icon.svg index 494f53cb90..fa95e64e79 100644 --- a/platform/web/export/run_icon.svg +++ b/platform/web/export/run_icon.svg @@ -1 +1 @@ -<svg height="16" width="16" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="M3.143 1 5.48 27.504 15.967 31l10.553-3.496L28.857 1ZM23.78 9.565H11.473l.275 3.308h11.759l-.911 9.937-6.556 1.808v.02h-.073l-6.61-1.828-.402-5.076h3.195l.234 2.552 3.583.97 3.595-.97.402-4.165H8.788L7.93 6.37h16.145Z" fill="#eb6428" style="fill:#e0e0e0;fill-opacity:1" transform="translate(.586 .586) scale(.46337)"/></svg> +<svg height="16" width="16" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m2 1 1.09 12.357 4.9 1.63 4.9-1.63L13.98 1zm9.622 3.994h-5.74l.129 1.541h5.482l-.424 4.634-3.057.843v.01h-.033l-3.082-.853-.187-2.367h1.489l.11 1.19 1.67.452 1.676-.453.187-1.942h-5.21l-.4-4.546h7.527z" fill="#eb6428" style="fill:#e0e0e0;fill-opacity:1"/></svg> diff --git a/platform/web/http_client_web.cpp b/platform/web/http_client_web.cpp index 3e4ba5a2ae..ea9226a5a4 100644 --- a/platform/web/http_client_web.cpp +++ b/platform/web/http_client_web.cpp @@ -149,7 +149,15 @@ Error HTTPClientWeb::get_response_headers(List<String> *r_response) { } int64_t HTTPClientWeb::get_response_body_length() const { - return godot_js_fetch_body_length_get(js_id); + // Body length cannot be consistently retrieved from the web. + // Reading the "content-length" value will return a meaningless value when the response is compressed, + // as reading will return uncompressed chunks in any case, resulting in a mismatch between the detected + // body size and the actual size returned by repeatedly calling read_response_body_chunk. + // Additionally, while "content-length" is considered a safe CORS header, "content-encoding" is not, + // so using the "content-encoding" to decide if "content-length" is meaningful is not an option either. + // We simply must accept the fact that browsers are awful when it comes to networking APIs. + // See GH-47597, and GH-79327. + return -1; } PackedByteArray HTTPClientWeb::read_response_body_chunk() { diff --git a/platform/web/http_client_web.h b/platform/web/http_client_web.h index bb9672ab82..4d3c457a7d 100644 --- a/platform/web/http_client_web.h +++ b/platform/web/http_client_web.h @@ -51,7 +51,6 @@ extern int godot_js_fetch_read_headers(int p_id, void (*parse_callback)(int p_si extern int godot_js_fetch_read_chunk(int p_id, uint8_t *p_buf, int p_buf_size); extern void godot_js_fetch_free(int p_id); extern godot_js_fetch_state_t godot_js_fetch_state_get(int p_id); -extern int godot_js_fetch_body_length_get(int p_id); extern int godot_js_fetch_http_status_get(int p_id); extern int godot_js_fetch_is_chunked(int p_id); diff --git a/platform/web/js/libs/library_godot_display.js b/platform/web/js/libs/library_godot_display.js index ea2a846f90..746f858923 100644 --- a/platform/web/js/libs/library_godot_display.js +++ b/platform/web/js/libs/library_godot_display.js @@ -568,16 +568,23 @@ const GodotDisplay = { godot_js_display_window_icon_set__sig: 'vii', godot_js_display_window_icon_set: function (p_ptr, p_len) { let link = document.getElementById('-gd-engine-icon'); - if (link === null) { - link = document.createElement('link'); - link.rel = 'icon'; - link.id = '-gd-engine-icon'; - document.head.appendChild(link); - } const old_icon = GodotDisplay.window_icon; - const png = new Blob([GodotRuntime.heapSlice(HEAPU8, p_ptr, p_len)], { type: 'image/png' }); - GodotDisplay.window_icon = URL.createObjectURL(png); - link.href = GodotDisplay.window_icon; + if (p_ptr) { + if (link === null) { + link = document.createElement('link'); + link.rel = 'icon'; + link.id = '-gd-engine-icon'; + document.head.appendChild(link); + } + const png = new Blob([GodotRuntime.heapSlice(HEAPU8, p_ptr, p_len)], { type: 'image/png' }); + GodotDisplay.window_icon = URL.createObjectURL(png); + link.href = GodotDisplay.window_icon; + } else { + if (link) { + link.remove(); + } + GodotDisplay.window_icon = null; + } if (old_icon) { URL.revokeObjectURL(old_icon); } diff --git a/platform/web/js/libs/library_godot_fetch.js b/platform/web/js/libs/library_godot_fetch.js index 1bb48bfd6a..4ef24903e3 100644 --- a/platform/web/js/libs/library_godot_fetch.js +++ b/platform/web/js/libs/library_godot_fetch.js @@ -50,22 +50,17 @@ const GodotFetch = { return; } let chunked = false; - let bodySize = -1; response.headers.forEach(function (value, header) { const v = value.toLowerCase().trim(); const h = header.toLowerCase().trim(); if (h === 'transfer-encoding' && v === 'chunked') { chunked = true; } - if (h === 'content-length') { - bodySize = parseInt(v, 10); - } }); obj.status = response.status; obj.response = response; obj.reader = response.body.getReader(); obj.chunked = chunked; - obj.bodySize = bodySize; }, onerror: function (id, err) { @@ -87,7 +82,6 @@ const GodotFetch = { reading: false, status: 0, chunks: [], - bodySize: -1, }; const id = IDHandler.add(obj); const init = { @@ -224,15 +218,6 @@ const GodotFetch = { return p_buf_size - to_read; }, - godot_js_fetch_body_length_get__sig: 'ii', - godot_js_fetch_body_length_get: function (p_id) { - const obj = IDHandler.get(p_id); - if (!obj || !obj.response) { - return -1; - } - return obj.bodySize; - }, - godot_js_fetch_is_chunked__sig: 'ii', godot_js_fetch_is_chunked: function (p_id) { const obj = IDHandler.get(p_id); |