@ng-native/desktop 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/bin/app-config.mjs +1 -0
- package/bin/archive.mjs +166 -0
- package/bin/autolink.mjs +61 -30
- package/bin/cli.mjs +127 -27
- package/bin/host.mjs +255 -58
- package/bin/package-linux.mjs +1394 -0
- package/bin/package.mjs +171 -35
- package/bin/plist.mjs +6 -2
- package/bin/png-icon.mjs +315 -0
- package/bin/prebuilt.mjs +147 -26
- package/bin/toolchain.mjs +258 -19
- package/native/CMakeLists.txt +64 -6
- package/native/appkit/CMakeLists.txt +2 -1
- package/native/appkit/appkit-backend.h +1 -0
- package/native/appkit/appkit-backend.mm +13 -0
- package/native/appkit/header-toolbar.mm +28 -25
- package/native/appkit/host-view.h +10 -0
- package/native/appkit/host-view.mm +146 -40
- package/native/appkit/input-replay.h +6 -0
- package/native/appkit/input-replay.mm +21 -12
- package/native/appkit/main.mm +11 -7
- package/native/appkit/native-controls.mm +13 -1
- package/native/appkit/split-view.mm +7 -13
- package/native/appkit/text-input-field.h +4 -0
- package/native/appkit/text-input-field.mm +20 -1
- package/native/cmake/curl.cmake +79 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
- package/native/cmake/libraries/react-native-worklets.cmake +5 -0
- package/native/cmake/linked-modules.cmake +20 -4
- package/native/cmake/react-native.cmake +18 -1
- package/native/core/include/ngn/accent-colors.h +38 -0
- package/native/core/include/ngn/accessibility-relations.h +65 -0
- package/native/core/include/ngn/accessibility.h +26 -0
- package/native/core/include/ngn/animated-frame-loop.h +56 -0
- package/native/core/include/ngn/app-info.h +24 -8
- package/native/core/include/ngn/app-menus.h +14 -1
- package/native/core/include/ngn/app-windows.h +15 -2
- package/native/core/include/ngn/aria-role.h +96 -0
- package/native/core/include/ngn/audio.h +2 -0
- package/native/core/include/ngn/camera.h +9 -0
- package/native/core/include/ngn/control-sizes.h +7 -2
- package/native/core/include/ngn/crash-report.h +31 -0
- package/native/core/include/ngn/curl-network.h +93 -0
- package/native/core/include/ngn/dbus-menu.h +39 -0
- package/native/core/include/ngn/default-menu.h +36 -0
- package/native/core/include/ngn/desktop-expo.h +7 -1
- package/native/core/include/ngn/desktop-modules.h +22 -0
- package/native/core/include/ngn/desktop-props.h +21 -1
- package/native/core/include/ngn/desktop-view-props.h +6 -0
- package/native/core/include/ngn/focus-order.h +10 -0
- package/native/core/include/ngn/header-bar.h +22 -0
- package/native/core/include/ngn/host-os.h +6 -0
- package/native/core/include/ngn/host-reload.h +21 -0
- package/native/core/include/ngn/host-state.h +23 -0
- package/native/core/include/ngn/image-source.h +26 -1
- package/native/core/include/ngn/input-script.h +3 -3
- package/native/core/include/ngn/input.h +4 -1
- package/native/core/include/ngn/launch-frame.h +21 -0
- package/native/core/include/ngn/launch-settings.h +23 -5
- package/native/core/include/ngn/mounting-backend.h +5 -0
- package/native/core/include/ngn/mounting-manager.h +1 -0
- package/native/core/include/ngn/native-controls.h +26 -5
- package/native/core/include/ngn/notification-schedule.h +74 -0
- package/native/core/include/ngn/notifications.h +2 -1
- package/native/core/include/ngn/openssl-update-crypto.h +15 -0
- package/native/core/include/ngn/photo-library.h +60 -20
- package/native/core/include/ngn/posix-locale.h +43 -0
- package/native/core/include/ngn/runtime.h +5 -0
- package/native/core/include/ngn/safe-areas.h +14 -2
- package/native/core/include/ngn/split-view.h +78 -0
- package/native/core/include/ngn/surface-metrics.h +7 -0
- package/native/core/include/ngn/system.h +14 -0
- package/native/core/include/ngn/text-input.h +13 -0
- package/native/core/include/ngn/text-units.h +38 -0
- package/native/core/include/ngn/updates.h +14 -2
- package/native/core/include/ngn/view-box.h +40 -0
- package/native/core/include/ngn/view-transform.h +15 -0
- package/native/core/include/ngn/web-browser.h +46 -0
- package/native/core/src/accent-colors.cpp +88 -0
- package/native/core/src/accessibility-relations.cpp +138 -0
- package/native/core/src/accessibility.cpp +50 -0
- package/native/core/src/animated-frame-loop.cpp +166 -0
- package/native/core/src/app-menus.cpp +26 -9
- package/native/core/src/app-windows.cpp +27 -6
- package/native/core/src/aria-role.cpp +127 -0
- package/native/core/src/control-sizes.cpp +9 -5
- package/native/core/src/crash-report.cpp +196 -0
- package/native/core/src/curl-network.cpp +1562 -0
- package/native/core/src/dbus-menu.cpp +71 -0
- package/native/core/src/default-menu.cpp +134 -0
- package/native/core/src/desktop-view-props.cpp +14 -0
- package/native/core/src/focus-order.cpp +19 -0
- package/native/core/src/header-bar.cpp +20 -0
- package/native/core/src/host-os.cpp +19 -0
- package/native/core/src/host-reload.cpp +45 -0
- package/native/core/src/host-state.cpp +8 -0
- package/native/core/src/image-source.cpp +90 -0
- package/native/core/src/input-dispatcher.cpp +27 -5
- package/native/core/src/input-script.cpp +3 -2
- package/native/core/src/launch-settings.cpp +76 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
- package/native/core/src/modules/app-info.cpp +55 -6
- package/native/core/src/modules/app-modules.cpp +1 -1
- package/native/core/src/modules/audio.cpp +4 -2
- package/native/core/src/modules/camera.cpp +8 -11
- package/native/core/src/modules/desktop-expo.cpp +10 -5
- package/native/core/src/modules/desktop-modules.cpp +106 -41
- package/native/core/src/modules/file-photo-picker.cpp +408 -0
- package/native/core/src/modules/notifications.cpp +13 -17
- package/native/core/src/modules/photo-library.cpp +42 -13
- package/native/core/src/modules/web-browser.cpp +89 -0
- package/native/core/src/mounting-manager.cpp +12 -0
- package/native/core/src/native-controls.cpp +42 -1
- package/native/core/src/notification-schedule.cpp +429 -0
- package/native/core/src/openssl-update-crypto.cpp +83 -0
- package/native/core/src/posix-locale.cpp +192 -0
- package/native/core/src/runtime.cpp +30 -1
- package/native/core/src/safe-areas.cpp +19 -4
- package/native/core/src/spawn-rules.cpp +4 -1
- package/native/core/src/split-view.cpp +93 -0
- package/native/core/src/system.cpp +19 -0
- package/native/core/src/text-input.cpp +18 -1
- package/native/core/src/text-units.cpp +99 -0
- package/native/core/src/updates.cpp +76 -17
- package/native/core/src/view-box.cpp +75 -40
- package/native/core/src/view-transform.cpp +28 -0
- package/native/docker/Dockerfile +38 -0
- package/native/docker/Dockerfile.fedora +36 -0
- package/native/docker/glibc-floor.sh +49 -0
- package/native/gtk/CMakeLists.txt +137 -0
- package/native/gtk/accent-colour.cpp +57 -0
- package/native/gtk/accent-colour.h +41 -0
- package/native/gtk/accessibility-settings.cpp +159 -0
- package/native/gtk/accessibility-settings.h +62 -0
- package/native/gtk/accessible-text.cpp +151 -0
- package/native/gtk/accessible-text.h +49 -0
- package/native/gtk/accessible.cpp +306 -0
- package/native/gtk/accessible.h +75 -0
- package/native/gtk/alerts.cpp +267 -0
- package/native/gtk/alerts.h +30 -0
- package/native/gtk/animation-frames.cpp +159 -0
- package/native/gtk/animation-frames.h +20 -0
- package/native/gtk/app-info.cpp +91 -0
- package/native/gtk/app-info.h +25 -0
- package/native/gtk/app-windows.cpp +439 -0
- package/native/gtk/app-windows.h +150 -0
- package/native/gtk/audio.cpp +370 -0
- package/native/gtk/audio.h +54 -0
- package/native/gtk/auth-session.cpp +73 -0
- package/native/gtk/auth-session.h +16 -0
- package/native/gtk/battery.cpp +110 -0
- package/native/gtk/battery.h +19 -0
- package/native/gtk/box-paint.cpp +262 -0
- package/native/gtk/box-paint.h +32 -0
- package/native/gtk/cairo-canvas.cpp +755 -0
- package/native/gtk/cairo-canvas.h +49 -0
- package/native/gtk/camera.cpp +909 -0
- package/native/gtk/camera.h +69 -0
- package/native/gtk/capture.cpp +46 -0
- package/native/gtk/capture.h +19 -0
- package/native/gtk/clock-format.cpp +151 -0
- package/native/gtk/clock-format.h +36 -0
- package/native/gtk/crypto.cpp +75 -0
- package/native/gtk/crypto.h +14 -0
- package/native/gtk/dbus-properties.cpp +131 -0
- package/native/gtk/dbus-properties.h +61 -0
- package/native/gtk/drag-and-drop.cpp +339 -0
- package/native/gtk/drag-and-drop.h +30 -0
- package/native/gtk/file-dialogs.cpp +239 -0
- package/native/gtk/file-dialogs.h +21 -0
- package/native/gtk/file-system.cpp +212 -0
- package/native/gtk/file-system.h +25 -0
- package/native/gtk/focus.cpp +282 -0
- package/native/gtk/focus.h +37 -0
- package/native/gtk/fonts.cpp +89 -0
- package/native/gtk/fonts.h +22 -0
- package/native/gtk/gst-frames.cpp +150 -0
- package/native/gtk/gst-frames.h +47 -0
- package/native/gtk/gst-playback.cpp +496 -0
- package/native/gtk/gst-playback.h +81 -0
- package/native/gtk/gtk-backend.cpp +690 -0
- package/native/gtk/gtk-backend.h +134 -0
- package/native/gtk/host-sources.cpp +354 -0
- package/native/gtk/host-sources.h +46 -0
- package/native/gtk/image-manipulator.cpp +254 -0
- package/native/gtk/image-manipulator.h +30 -0
- package/native/gtk/image-view.cpp +256 -0
- package/native/gtk/image-view.h +54 -0
- package/native/gtk/input-replay.cpp +299 -0
- package/native/gtk/input-replay.h +36 -0
- package/native/gtk/launcher-badge.cpp +29 -0
- package/native/gtk/launcher-badge.h +21 -0
- package/native/gtk/locales.cpp +131 -0
- package/native/gtk/locales.h +23 -0
- package/native/gtk/location.cpp +274 -0
- package/native/gtk/location.h +19 -0
- package/native/gtk/main.cpp +1092 -0
- package/native/gtk/menus.cpp +447 -0
- package/native/gtk/menus.h +100 -0
- package/native/gtk/native-controls.cpp +831 -0
- package/native/gtk/native-controls.h +58 -0
- package/native/gtk/network-state.cpp +72 -0
- package/native/gtk/network-state.h +24 -0
- package/native/gtk/notifications.cpp +235 -0
- package/native/gtk/notifications.h +30 -0
- package/native/gtk/pango-text.cpp +274 -0
- package/native/gtk/pango-text.h +73 -0
- package/native/gtk/portal.cpp +451 -0
- package/native/gtk/portal.h +71 -0
- package/native/gtk/printing.cpp +338 -0
- package/native/gtk/printing.h +34 -0
- package/native/gtk/proxy-resolver.cpp +74 -0
- package/native/gtk/proxy-resolver.h +20 -0
- package/native/gtk/screens.cpp +1461 -0
- package/native/gtk/screens.h +274 -0
- package/native/gtk/scroll-view.cpp +414 -0
- package/native/gtk/scroll-view.h +82 -0
- package/native/gtk/secret-store.cpp +120 -0
- package/native/gtk/secret-store.h +27 -0
- package/native/gtk/settings-portal.cpp +129 -0
- package/native/gtk/settings-portal.h +47 -0
- package/native/gtk/split-view.cpp +1105 -0
- package/native/gtk/split-view.h +195 -0
- package/native/gtk/status-notifier.cpp +487 -0
- package/native/gtk/status-notifier.h +43 -0
- package/native/gtk/surface-input.cpp +251 -0
- package/native/gtk/surface-input.h +57 -0
- package/native/gtk/system-access.cpp +295 -0
- package/native/gtk/system-access.h +37 -0
- package/native/gtk/text-field.cpp +827 -0
- package/native/gtk/text-field.h +78 -0
- package/native/gtk/video.cpp +527 -0
- package/native/gtk/video.h +47 -0
- package/native/gtk/view-widget.cpp +431 -0
- package/native/gtk/view-widget.h +105 -0
- package/native/gtk/window-scale.cpp +95 -0
- package/native/gtk/window-scale.h +35 -0
- package/native/scripts/atspi-check.py +310 -0
- package/native/scripts/atspi-check.test.py +48 -0
- package/native/scripts/build.sh +20 -3
- package/native/scripts/compilers.sh +17 -0
- package/native/scripts/deb-depends-check.sh +22 -0
- package/native/scripts/fetch.sh +23 -2
- package/native/scripts/launch-cell.sh +157 -0
- package/native/scripts/launch-probe.sh +14 -3
- package/native/scripts/make-prebuilt.mjs +133 -44
- package/native/scripts/prebuilt-host-cache.mjs +71 -40
- package/native/scripts/reset-for-compilers.sh +44 -0
- package/native/scripts/start-xvfb.sh +35 -0
- package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
- package/native/shim/worklets/linux-reanimated-props.h +14 -0
- package/native/shim/worklets/linux-worklets.h +23 -0
- package/package.json +6 -3
- package/prebuilt.json +70 -6
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
#include "image-manipulator.h"
|
|
2
|
+
|
|
3
|
+
#include <gdk/gdk.h>
|
|
4
|
+
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
5
|
+
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
#include <cmath>
|
|
8
|
+
#include <cstdlib>
|
|
9
|
+
#include <stdexcept>
|
|
10
|
+
#include <string>
|
|
11
|
+
|
|
12
|
+
namespace ngn::gtk {
|
|
13
|
+
|
|
14
|
+
namespace {
|
|
15
|
+
|
|
16
|
+
struct Header {
|
|
17
|
+
bool prepared{false};
|
|
18
|
+
int width{0};
|
|
19
|
+
int height{0};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// The orientation tag's value (1 to 8) a decoded image carries, 1 where it has none.
|
|
23
|
+
int orientationOf(GdkPixbuf *pixbuf) {
|
|
24
|
+
const gchar *value = pixbuf ? gdk_pixbuf_get_option(pixbuf, "orientation") : nullptr;
|
|
25
|
+
int orientation = value ? std::atoi(value) : 1;
|
|
26
|
+
return orientation >= 1 && orientation <= 8 ? orientation : 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The image decoded and turned the right way up, or null for bytes no loader reads.
|
|
30
|
+
GdkPixbuf *uprightPixbuf(const std::string &bytes) {
|
|
31
|
+
GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
|
|
32
|
+
bool written = gdk_pixbuf_loader_write(loader, reinterpret_cast<const guchar *>(bytes.data()), bytes.size(), nullptr);
|
|
33
|
+
bool closed = gdk_pixbuf_loader_close(loader, nullptr);
|
|
34
|
+
GdkPixbuf *decoded = written && closed ? gdk_pixbuf_loader_get_pixbuf(loader) : nullptr;
|
|
35
|
+
GdkPixbuf *upright = decoded ? gdk_pixbuf_apply_embedded_orientation(decoded) : nullptr;
|
|
36
|
+
g_object_unref(loader);
|
|
37
|
+
return upright;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Cairo reports a failure (a size it cannot allocate, say) as an error object, not null: a later
|
|
41
|
+
// step drawing on it would go on to a blank image that encodes as if it were the edit.
|
|
42
|
+
void throwUnlessOk(cairo_status_t status) {
|
|
43
|
+
if (status != CAIRO_STATUS_SUCCESS) {
|
|
44
|
+
throw std::runtime_error(std::string("Could not draw the image: ") + cairo_status_to_string(status));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
cairo_surface_t *surfaceOf(GdkPixbuf *pixbuf) {
|
|
49
|
+
int width = gdk_pixbuf_get_width(pixbuf), height = gdk_pixbuf_get_height(pixbuf);
|
|
50
|
+
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
|
|
51
|
+
cairo_t *cr = cairo_create(surface);
|
|
52
|
+
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
|
|
53
|
+
cairo_paint(cr);
|
|
54
|
+
auto status = cairo_status(cr) != CAIRO_STATUS_SUCCESS ? cairo_status(cr) : cairo_surface_status(surface);
|
|
55
|
+
cairo_destroy(cr);
|
|
56
|
+
if (status != CAIRO_STATUS_SUCCESS) {
|
|
57
|
+
cairo_surface_destroy(surface);
|
|
58
|
+
throwUnlessOk(status);
|
|
59
|
+
}
|
|
60
|
+
return surface;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A new surface of the step's size with `image` drawn into it as the step says.
|
|
64
|
+
cairo_surface_t *apply(cairo_surface_t *image, const ImageStep &step) {
|
|
65
|
+
double width = cairo_image_surface_get_width(image), height = cairo_image_surface_get_height(image);
|
|
66
|
+
double outWidth = step.size.width, outHeight = step.size.height;
|
|
67
|
+
cairo_surface_t *out = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, step.size.width, step.size.height);
|
|
68
|
+
cairo_t *cr = cairo_create(out);
|
|
69
|
+
switch (step.kind) {
|
|
70
|
+
case ImageStep::Kind::Crop:
|
|
71
|
+
cairo_set_source_surface(cr, image, -step.x, -step.y);
|
|
72
|
+
break;
|
|
73
|
+
case ImageStep::Kind::Resize:
|
|
74
|
+
cairo_scale(cr, outWidth / width, outHeight / height);
|
|
75
|
+
cairo_set_source_surface(cr, image, 0, 0);
|
|
76
|
+
// The edge pixels repeat outward, so an upscale does not blend them with transparent black.
|
|
77
|
+
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_PAD);
|
|
78
|
+
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_GOOD);
|
|
79
|
+
break;
|
|
80
|
+
case ImageStep::Kind::FlipHorizontal:
|
|
81
|
+
cairo_translate(cr, outWidth, 0);
|
|
82
|
+
cairo_scale(cr, -1, 1);
|
|
83
|
+
cairo_set_source_surface(cr, image, 0, 0);
|
|
84
|
+
break;
|
|
85
|
+
case ImageStep::Kind::FlipVertical:
|
|
86
|
+
cairo_translate(cr, 0, outHeight);
|
|
87
|
+
cairo_scale(cr, 1, -1);
|
|
88
|
+
cairo_set_source_surface(cr, image, 0, 0);
|
|
89
|
+
break;
|
|
90
|
+
case ImageStep::Kind::Rotate:
|
|
91
|
+
// Cairo's y runs down, so a positive angle turns clockwise on screen.
|
|
92
|
+
cairo_translate(cr, outWidth / 2, outHeight / 2);
|
|
93
|
+
cairo_rotate(cr, step.degrees * G_PI / 180);
|
|
94
|
+
cairo_set_source_surface(cr, image, -width / 2, -height / 2);
|
|
95
|
+
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_GOOD);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
cairo_paint(cr);
|
|
99
|
+
auto status = cairo_status(cr) != CAIRO_STATUS_SUCCESS ? cairo_status(cr) : cairo_surface_status(out);
|
|
100
|
+
cairo_destroy(cr);
|
|
101
|
+
if (status != CAIRO_STATUS_SUCCESS) {
|
|
102
|
+
cairo_surface_destroy(out);
|
|
103
|
+
throwUnlessOk(status);
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
class PixbufCodec final : public ImageCodec {
|
|
109
|
+
public:
|
|
110
|
+
// The header's size, read until the loader knows it, and the orientation, which a JPEG's
|
|
111
|
+
// loader has read by then too.
|
|
112
|
+
std::optional<ImageSize> size(const std::string &bytes) override {
|
|
113
|
+
GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
|
|
114
|
+
Header header;
|
|
115
|
+
g_signal_connect(loader, "area-prepared", G_CALLBACK(+[](GdkPixbufLoader *, gpointer data) {
|
|
116
|
+
static_cast<Header *>(data)->prepared = true;
|
|
117
|
+
}), &header);
|
|
118
|
+
g_signal_connect(loader, "size-prepared", G_CALLBACK(+[](GdkPixbufLoader *, int width, int height, gpointer data) {
|
|
119
|
+
static_cast<Header *>(data)->width = width;
|
|
120
|
+
static_cast<Header *>(data)->height = height;
|
|
121
|
+
}), &header);
|
|
122
|
+
constexpr size_t chunk = 64 * 1024;
|
|
123
|
+
bool failed = false;
|
|
124
|
+
for (size_t at = 0; at < bytes.size() && !header.prepared && !failed; at += chunk) {
|
|
125
|
+
failed = !gdk_pixbuf_loader_write(loader, reinterpret_cast<const guchar *>(bytes.data() + at), std::min(chunk, bytes.size() - at), nullptr);
|
|
126
|
+
}
|
|
127
|
+
// All of it written and no image yet: closing finishes what the loader can read.
|
|
128
|
+
bool closed = !header.prepared && !failed;
|
|
129
|
+
if (closed) {
|
|
130
|
+
gdk_pixbuf_loader_close(loader, nullptr);
|
|
131
|
+
}
|
|
132
|
+
std::optional<ImageSize> size;
|
|
133
|
+
if (header.prepared && header.width > 0 && header.height > 0) {
|
|
134
|
+
size = ImageSize{header.width, header.height};
|
|
135
|
+
// 5 to 8 turn the image a quarter.
|
|
136
|
+
if (orientationOf(gdk_pixbuf_loader_get_pixbuf(loader)) >= 5) {
|
|
137
|
+
std::swap(size->width, size->height);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// A loader left part way through says so as it closes; that is expected here.
|
|
141
|
+
if (!closed) {
|
|
142
|
+
gdk_pixbuf_loader_close(loader, nullptr);
|
|
143
|
+
}
|
|
144
|
+
g_object_unref(loader);
|
|
145
|
+
return size;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
bool encodes(const std::string &format) override {
|
|
149
|
+
std::string name = format == "jpg" ? "jpeg" : format;
|
|
150
|
+
GSList *formats = gdk_pixbuf_get_formats();
|
|
151
|
+
bool found = false;
|
|
152
|
+
for (GSList *at = formats; at && !found; at = at->next) {
|
|
153
|
+
auto *candidate = static_cast<GdkPixbufFormat *>(at->data);
|
|
154
|
+
gchar *candidateName = gdk_pixbuf_format_get_name(candidate);
|
|
155
|
+
found = name == candidateName && gdk_pixbuf_format_is_writable(candidate);
|
|
156
|
+
g_free(candidateName);
|
|
157
|
+
}
|
|
158
|
+
g_slist_free(formats);
|
|
159
|
+
return found;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
std::string render(const std::string &bytes, const std::vector<ImageStep> &steps, const std::string &format, double quality) override {
|
|
163
|
+
GdkPixbuf *upright = uprightPixbuf(bytes);
|
|
164
|
+
if (!upright) {
|
|
165
|
+
throw std::runtime_error("Image cannot be found");
|
|
166
|
+
}
|
|
167
|
+
cairo_surface_t *image = nullptr;
|
|
168
|
+
try {
|
|
169
|
+
image = surfaceOf(upright);
|
|
170
|
+
} catch (...) {
|
|
171
|
+
g_object_unref(upright);
|
|
172
|
+
throw;
|
|
173
|
+
}
|
|
174
|
+
g_object_unref(upright);
|
|
175
|
+
for (const auto &step : steps) {
|
|
176
|
+
cairo_surface_t *next = nullptr;
|
|
177
|
+
try {
|
|
178
|
+
next = apply(image, step);
|
|
179
|
+
} catch (...) {
|
|
180
|
+
cairo_surface_destroy(image);
|
|
181
|
+
throw;
|
|
182
|
+
}
|
|
183
|
+
cairo_surface_destroy(image);
|
|
184
|
+
image = next;
|
|
185
|
+
}
|
|
186
|
+
cairo_surface_flush(image);
|
|
187
|
+
GdkPixbuf *result = gdk_pixbuf_get_from_surface(image, 0, 0, cairo_image_surface_get_width(image), cairo_image_surface_get_height(image));
|
|
188
|
+
cairo_surface_destroy(image);
|
|
189
|
+
if (!result) {
|
|
190
|
+
throw std::runtime_error("Could not read the image from the drawing context");
|
|
191
|
+
}
|
|
192
|
+
gchar *buffer = nullptr;
|
|
193
|
+
gsize length = 0;
|
|
194
|
+
GError *error = nullptr;
|
|
195
|
+
bool saved = false;
|
|
196
|
+
if (format == "png") {
|
|
197
|
+
saved = gdk_pixbuf_save_to_buffer(result, &buffer, &length, "png", &error, nullptr);
|
|
198
|
+
} else if (format == "webp") {
|
|
199
|
+
auto level = std::to_string(static_cast<int>(std::lround(std::clamp(quality, 0.0, 1.0) * 100)));
|
|
200
|
+
saved = gdk_pixbuf_save_to_buffer(result, &buffer, &length, "webp", &error, "quality", level.c_str(), nullptr);
|
|
201
|
+
} else {
|
|
202
|
+
// JPEG has no alpha, so it is given the colour channels only (see withoutAlpha).
|
|
203
|
+
auto level = std::to_string(static_cast<int>(std::lround(std::clamp(quality, 0.0, 1.0) * 100)));
|
|
204
|
+
GdkPixbuf *opaque = withoutAlpha(result);
|
|
205
|
+
saved = opaque && gdk_pixbuf_save_to_buffer(opaque, &buffer, &length, "jpeg", &error, "quality", level.c_str(), nullptr);
|
|
206
|
+
g_clear_object(&opaque);
|
|
207
|
+
}
|
|
208
|
+
g_object_unref(result);
|
|
209
|
+
if (!saved) {
|
|
210
|
+
g_clear_error(&error);
|
|
211
|
+
throw std::runtime_error("Cannot create image data for given image format");
|
|
212
|
+
}
|
|
213
|
+
std::string out(buffer, length);
|
|
214
|
+
g_free(buffer);
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
} // namespace
|
|
220
|
+
|
|
221
|
+
GdkPixbuf *withoutAlpha(GdkPixbuf *pixbuf) {
|
|
222
|
+
if (!gdk_pixbuf_get_has_alpha(pixbuf)) {
|
|
223
|
+
return GDK_PIXBUF(g_object_ref(pixbuf));
|
|
224
|
+
}
|
|
225
|
+
int width = gdk_pixbuf_get_width(pixbuf), height = gdk_pixbuf_get_height(pixbuf);
|
|
226
|
+
GdkPixbuf *opaque = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height);
|
|
227
|
+
if (!opaque) {
|
|
228
|
+
return nullptr;
|
|
229
|
+
}
|
|
230
|
+
const guchar *from = gdk_pixbuf_read_pixels(pixbuf);
|
|
231
|
+
guchar *to = gdk_pixbuf_get_pixels(opaque);
|
|
232
|
+
size_t fromStride = gdk_pixbuf_get_rowstride(pixbuf), toStride = gdk_pixbuf_get_rowstride(opaque);
|
|
233
|
+
size_t channels = gdk_pixbuf_get_n_channels(pixbuf);
|
|
234
|
+
for (size_t y = 0; y < static_cast<size_t>(height); ++y) {
|
|
235
|
+
for (size_t x = 0; x < static_cast<size_t>(width); ++x) {
|
|
236
|
+
std::copy_n(from + y * fromStride + x * channels, 3, to + y * toStride + x * 3);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return opaque;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
std::shared_ptr<ImageCodec> makeImageCodec() {
|
|
243
|
+
return std::make_shared<PixbufCodec>();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
std::optional<std::pair<double, double>> imagePixelSize(const std::string &path) {
|
|
247
|
+
int width = 0, height = 0;
|
|
248
|
+
if (!gdk_pixbuf_get_file_info(path.c_str(), &width, &height) || width <= 0 || height <= 0) {
|
|
249
|
+
return std::nullopt;
|
|
250
|
+
}
|
|
251
|
+
return std::pair<double, double>(width, height);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The OS half of NgNativeImageManipulator on Linux (the core's image-manipulator.h): gdk-pixbuf
|
|
2
|
+
// decodes the image the right way up by its Exif orientation, cairo draws each step, and
|
|
3
|
+
// gdk-pixbuf encodes the result in a format it has a writer for (JPEG and PNG; WebP only with a
|
|
4
|
+
// WebP loader installed).
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "ngn/image-manipulator.h"
|
|
8
|
+
|
|
9
|
+
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
10
|
+
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include <optional>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <utility>
|
|
15
|
+
|
|
16
|
+
namespace ngn::gtk {
|
|
17
|
+
|
|
18
|
+
std::shared_ptr<ImageCodec> makeImageCodec();
|
|
19
|
+
|
|
20
|
+
// An image file's size in pixels as stored (before its Exif orientation), from its header; nothing
|
|
21
|
+
// for a file no gdk-pixbuf loader reads. ImagePicker describes a pick with it.
|
|
22
|
+
std::optional<std::pair<double, double>> imagePixelSize(const std::string &path);
|
|
23
|
+
|
|
24
|
+
// `pixbuf`'s colour channels in a new pixbuf without alpha, a new reference to it where it has
|
|
25
|
+
// none, or null where the new pixbuf cannot be allocated. JPEG is saved from one: gdk-pixbuf 2.44
|
|
26
|
+
// and later, built with its glycin backend (as Fedora's is), write JPEG through glycin, whose
|
|
27
|
+
// encoder refuses an image with alpha.
|
|
28
|
+
GdkPixbuf *withoutAlpha(GdkPixbuf *pixbuf);
|
|
29
|
+
|
|
30
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
#include "image-view.h"
|
|
2
|
+
|
|
3
|
+
#include "app-windows.h"
|
|
4
|
+
#include "box-paint.h"
|
|
5
|
+
#include "window-scale.h"
|
|
6
|
+
|
|
7
|
+
#include "ngn/file-system.h"
|
|
8
|
+
#include "ngn/image-source.h"
|
|
9
|
+
|
|
10
|
+
#include <react/renderer/components/image/ImageEventEmitter.h>
|
|
11
|
+
#include <react/renderer/components/image/ImageProps.h>
|
|
12
|
+
|
|
13
|
+
#include <algorithm>
|
|
14
|
+
#include <mutex>
|
|
15
|
+
#include <utility>
|
|
16
|
+
|
|
17
|
+
using namespace facebook::react;
|
|
18
|
+
|
|
19
|
+
namespace ngn::gtk {
|
|
20
|
+
|
|
21
|
+
namespace {
|
|
22
|
+
|
|
23
|
+
std::mutex gLoadingMutex;
|
|
24
|
+
std::shared_ptr<Http> gHttp;
|
|
25
|
+
std::shared_ptr<ImageCache> gCache;
|
|
26
|
+
|
|
27
|
+
std::shared_ptr<const ImageEventEmitter> emitterOf(const ViewData &view) {
|
|
28
|
+
return std::dynamic_pointer_cast<const ImageEventEmitter>(view.emitter);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void setTexture(ImageLoad &load, GdkTexture *texture) {
|
|
32
|
+
if (load.texture) {
|
|
33
|
+
g_object_unref(load.texture);
|
|
34
|
+
}
|
|
35
|
+
load.texture = texture;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void failed(ViewData &view, const std::string &message) {
|
|
39
|
+
view.image->error = message;
|
|
40
|
+
if (auto e = emitterOf(view)) {
|
|
41
|
+
e->onError({.error = message});
|
|
42
|
+
e->onLoadEnd();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// What a read answers, on the UI thread: a texture the caller then owns, or null and why.
|
|
47
|
+
struct Answer {
|
|
48
|
+
std::function<void(GdkTexture *, const std::string &)> done;
|
|
49
|
+
GdkTexture *texture{nullptr};
|
|
50
|
+
std::string error;
|
|
51
|
+
Answer() = default;
|
|
52
|
+
Answer(const Answer &) = delete;
|
|
53
|
+
Answer &operator=(const Answer &) = delete;
|
|
54
|
+
~Answer() {
|
|
55
|
+
if (texture) {
|
|
56
|
+
g_object_unref(texture);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Queued for the UI thread's loop, never run in the caller's turn, which can be the UI thread's
|
|
62
|
+
// own (a cache hit) or a network thread that took the main context between two of its turns.
|
|
63
|
+
void answer(std::shared_ptr<Answer> answer) {
|
|
64
|
+
onMainContext([answer = std::move(answer)] { answer->done(std::exchange(answer->texture, nullptr), answer->error); });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
struct Decode {
|
|
68
|
+
std::shared_ptr<Answer> answer;
|
|
69
|
+
std::string bytes;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// GDK decodes on any thread: the UI thread only draws, even for bytes the cache held.
|
|
73
|
+
void decode(gpointer data, gpointer) {
|
|
74
|
+
std::unique_ptr<Decode> job(static_cast<Decode *>(data));
|
|
75
|
+
GBytes *bytes = g_bytes_new(job->bytes.data(), job->bytes.size());
|
|
76
|
+
GError *problem = nullptr;
|
|
77
|
+
job->answer->texture = gdk_texture_new_from_bytes(bytes, &problem);
|
|
78
|
+
g_bytes_unref(bytes);
|
|
79
|
+
if (!job->answer->texture) {
|
|
80
|
+
job->answer->error = std::string("Could not decode the image: ") + (problem ? problem->message : "unknown format");
|
|
81
|
+
}
|
|
82
|
+
if (problem) {
|
|
83
|
+
g_error_free(problem);
|
|
84
|
+
}
|
|
85
|
+
answer(std::move(job->answer));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
void decodeOffThread(std::shared_ptr<Answer> answer, std::string bytes) {
|
|
89
|
+
static GThreadPool *pool = g_thread_pool_new(decode, nullptr, static_cast<gint>(std::max(1u, g_get_num_processors())), FALSE, nullptr);
|
|
90
|
+
g_thread_pool_push(pool, new Decode{std::move(answer), std::move(bytes)}, nullptr);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
void load(ViewData &view) {
|
|
94
|
+
ImageLoad &load = *view.image;
|
|
95
|
+
uint64_t turn = ++load.turn;
|
|
96
|
+
setTexture(load, nullptr);
|
|
97
|
+
load.error.clear();
|
|
98
|
+
if (view.widget) {
|
|
99
|
+
gtk_widget_queue_draw(view.widget);
|
|
100
|
+
}
|
|
101
|
+
if (!load.source) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (auto e = emitterOf(view)) {
|
|
105
|
+
e->onLoadStart();
|
|
106
|
+
}
|
|
107
|
+
std::weak_ptr<ImageLoad> weak = view.image;
|
|
108
|
+
readImage(*load.source, [weak, turn](GdkTexture *texture, const std::string &error) {
|
|
109
|
+
auto load = weak.lock();
|
|
110
|
+
// An answer for a load since superseded, or for a view that went, shows nothing.
|
|
111
|
+
if (!load || load->turn != turn || !load->view) {
|
|
112
|
+
if (texture) {
|
|
113
|
+
g_object_unref(texture);
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
ViewData &view = *load->view;
|
|
118
|
+
if (!texture) {
|
|
119
|
+
failed(view, error);
|
|
120
|
+
} else {
|
|
121
|
+
setTexture(*load, texture);
|
|
122
|
+
load->error.clear();
|
|
123
|
+
if (auto e = emitterOf(view)) {
|
|
124
|
+
ImageSource source;
|
|
125
|
+
source.uri = load->source->uri;
|
|
126
|
+
source.size = {static_cast<Float>(gdk_texture_get_width(texture)), static_cast<Float>(gdk_texture_get_height(texture))};
|
|
127
|
+
e->onLoad(source);
|
|
128
|
+
e->onLoadEnd();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (view.widget) {
|
|
132
|
+
gtk_widget_queue_draw(view.widget);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} // namespace
|
|
138
|
+
|
|
139
|
+
void readImage(const ImageSource &source, std::function<void(GdkTexture *texture, const std::string &error)> done) {
|
|
140
|
+
std::shared_ptr<Http> http;
|
|
141
|
+
std::shared_ptr<ImageCache> cache;
|
|
142
|
+
{
|
|
143
|
+
std::lock_guard lock(gLoadingMutex);
|
|
144
|
+
http = gHttp;
|
|
145
|
+
cache = gCache;
|
|
146
|
+
}
|
|
147
|
+
if (!http) {
|
|
148
|
+
auto reply = std::make_shared<Answer>();
|
|
149
|
+
reply->done = std::move(done);
|
|
150
|
+
reply->error = "Images cannot load: the host gave no HTTP client";
|
|
151
|
+
answer(std::move(reply));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
loadImageSource(http, cache, viewFileAccess().get(), source, [done = std::move(done)](std::string bytes, const std::string &error) {
|
|
155
|
+
auto reply = std::make_shared<Answer>();
|
|
156
|
+
reply->done = done;
|
|
157
|
+
reply->error = error;
|
|
158
|
+
if (!error.empty()) {
|
|
159
|
+
answer(std::move(reply));
|
|
160
|
+
} else {
|
|
161
|
+
decodeOffThread(std::move(reply), std::move(bytes));
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
void useImageLoading(std::shared_ptr<Http> http, std::shared_ptr<ImageCache> cache) {
|
|
167
|
+
std::lock_guard lock(gLoadingMutex);
|
|
168
|
+
gHttp = std::move(http);
|
|
169
|
+
gCache = std::move(cache);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
void makeImageView(GtkWidget *widget, ViewData &view) {
|
|
173
|
+
g_signal_connect(widget, "notify::scale-factor", G_CALLBACK(+[](GtkWidget *scaled, GParamSpec *, gpointer) {
|
|
174
|
+
if (ViewData *d = viewData(scaled); d && d->image) {
|
|
175
|
+
applyImageProps(*d, windowScale(scaled));
|
|
176
|
+
}
|
|
177
|
+
}), nullptr);
|
|
178
|
+
applyImageProps(view, windowScale(widget));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
void applyImageProps(ViewData &view, double screenScale) {
|
|
182
|
+
auto props = std::dynamic_pointer_cast<const ImageProps>(view.props);
|
|
183
|
+
if (!props) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (!view.image) {
|
|
187
|
+
view.image = std::make_shared<ImageLoad>();
|
|
188
|
+
view.image->view = &view;
|
|
189
|
+
}
|
|
190
|
+
// The source whose scale is nearest the screen's, as React Native iOS picks.
|
|
191
|
+
auto source = pickImageSource(props->sources, screenScale);
|
|
192
|
+
auto ¤t = view.image->source;
|
|
193
|
+
if (source.has_value() == current.has_value() && (!source || sameImageRequest(*source, *current))) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
current = std::move(source);
|
|
197
|
+
load(view);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
void snapshotImage(const ViewData &view, GtkSnapshot *snapshot, const BoxDescription &box) {
|
|
201
|
+
auto props = std::dynamic_pointer_cast<const ImageProps>(view.props);
|
|
202
|
+
if (!view.image || !view.image->texture || !props || box.bounds.width <= 0 || box.bounds.height <= 0) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
GdkTexture *texture = view.image->texture;
|
|
206
|
+
std::pair<double, double> pixels{gdk_texture_get_width(texture), gdk_texture_get_height(texture)};
|
|
207
|
+
// `repeat` tiles the image from the top left at its size in points, as React Native iOS draws it.
|
|
208
|
+
bool tiled = props->resizeMode == facebook::react::ImageResizeMode::Repeat;
|
|
209
|
+
ImageRect rect;
|
|
210
|
+
if (tiled) {
|
|
211
|
+
double scale = view.image->source && view.image->source->scale > 0 ? view.image->source->scale : 1;
|
|
212
|
+
rect = {0, 0, pixels.first / scale, pixels.second / scale};
|
|
213
|
+
} else {
|
|
214
|
+
rect = placeImage(imageContentFit(props->resizeMode), nullptr, pixels, {box.bounds.width, box.bounds.height});
|
|
215
|
+
}
|
|
216
|
+
// The image is cut to the view, in its rounded shape, as the macOS host's layer masks it.
|
|
217
|
+
GskRoundedRect outline = gskRoundedRect(box.bounds, box.radii);
|
|
218
|
+
gtk_snapshot_push_rounded_clip(snapshot, &outline);
|
|
219
|
+
graphene_rect_t at;
|
|
220
|
+
graphene_rect_init(
|
|
221
|
+
&at, static_cast<float>(box.bounds.x + rect.x), static_cast<float>(box.bounds.y + rect.y), static_cast<float>(rect.width),
|
|
222
|
+
static_cast<float>(rect.height));
|
|
223
|
+
if (tiled) {
|
|
224
|
+
graphene_rect_t whole;
|
|
225
|
+
graphene_rect_init(&whole, static_cast<float>(box.bounds.x), static_cast<float>(box.bounds.y), static_cast<float>(box.bounds.width),
|
|
226
|
+
static_cast<float>(box.bounds.height));
|
|
227
|
+
gtk_snapshot_push_repeat(snapshot, &whole, &at);
|
|
228
|
+
}
|
|
229
|
+
if (props->tintColor && *props->tintColor) {
|
|
230
|
+
// The tint in the image's shape: its colour where the image has alpha, as React Native iOS
|
|
231
|
+
// draws a template image.
|
|
232
|
+
auto c = colorComponentsFromColor(*props->tintColor);
|
|
233
|
+
GdkRGBA tint{c.red, c.green, c.blue, c.alpha};
|
|
234
|
+
gtk_snapshot_push_mask(snapshot, GSK_MASK_MODE_ALPHA);
|
|
235
|
+
gtk_snapshot_append_texture(snapshot, texture, &at);
|
|
236
|
+
gtk_snapshot_pop(snapshot);
|
|
237
|
+
gtk_snapshot_append_color(snapshot, &tint, &at);
|
|
238
|
+
gtk_snapshot_pop(snapshot);
|
|
239
|
+
} else {
|
|
240
|
+
gtk_snapshot_append_texture(snapshot, texture, &at);
|
|
241
|
+
}
|
|
242
|
+
if (tiled) {
|
|
243
|
+
gtk_snapshot_pop(snapshot);
|
|
244
|
+
}
|
|
245
|
+
gtk_snapshot_pop(snapshot);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
void destroyImage(ViewData &view) {
|
|
249
|
+
if (view.image) {
|
|
250
|
+
view.image->view = nullptr;
|
|
251
|
+
setTexture(*view.image, nullptr);
|
|
252
|
+
view.image.reset();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// An `Image` on GTK: its source read through the core (loadImageSource, over the host's HTTP client
|
|
2
|
+
// and an in-memory cache), decoded by GDK off the UI thread, and drawn in the view's snapshot where
|
|
3
|
+
// its resizeMode puts it, cut to the view's shape, as the macOS host's layer draws it. It reports
|
|
4
|
+
// load start, load (with the image's size in pixels), error and load end.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "view-widget.h"
|
|
8
|
+
|
|
9
|
+
#include "ngn/expo-image.h"
|
|
10
|
+
#include "ngn/network.h"
|
|
11
|
+
#include "ngn/view-box.h"
|
|
12
|
+
|
|
13
|
+
#include <react/renderer/imagemanager/primitives.h>
|
|
14
|
+
|
|
15
|
+
#include <gtk/gtk.h>
|
|
16
|
+
|
|
17
|
+
#include <cstdint>
|
|
18
|
+
#include <functional>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <optional>
|
|
21
|
+
#include <string>
|
|
22
|
+
|
|
23
|
+
namespace ngn::gtk {
|
|
24
|
+
|
|
25
|
+
struct ImageLoad {
|
|
26
|
+
// The view the load draws in, until it goes.
|
|
27
|
+
ViewData *view{nullptr};
|
|
28
|
+
// The source picked, which a change of props loads again only when it is a new request.
|
|
29
|
+
std::optional<facebook::react::ImageSource> source;
|
|
30
|
+
// Moved on by each load: an answer for an earlier one, even of the same uri, is ignored.
|
|
31
|
+
uint64_t turn{0};
|
|
32
|
+
GdkTexture *texture{nullptr};
|
|
33
|
+
// What the last load answered: the texture shown, or why there is none.
|
|
34
|
+
std::string error;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// The client and the cache every Image loads through. Without them, a load fails.
|
|
38
|
+
void useImageLoading(std::shared_ptr<Http> http, std::shared_ptr<ImageCache> cache);
|
|
39
|
+
|
|
40
|
+
// Reads `source` as an Image does and decodes it off the UI thread, answering once, in a later turn
|
|
41
|
+
// of the UI thread: a texture the caller owns, or null and why.
|
|
42
|
+
void readImage(const facebook::react::ImageSource &source, std::function<void(GdkTexture *texture, const std::string &error)> done);
|
|
43
|
+
|
|
44
|
+
// Loads the source the view's props pick, and picks again as the widget's scale changes: in a
|
|
45
|
+
// window on another monitor, or moved to one, a whole step at a time; GtkBackend::windowRescaled
|
|
46
|
+
// picks again at a fractional one.
|
|
47
|
+
void makeImageView(GtkWidget *widget, ViewData &view);
|
|
48
|
+
// Loads the source the view's props pick when it is a new request.
|
|
49
|
+
void applyImageProps(ViewData &view, double screenScale);
|
|
50
|
+
// Draws the loaded image inside `box`'s shape.
|
|
51
|
+
void snapshotImage(const ViewData &view, GtkSnapshot *snapshot, const BoxDescription &box);
|
|
52
|
+
void destroyImage(ViewData &view);
|
|
53
|
+
|
|
54
|
+
} // namespace ngn::gtk
|