From f6a495f2725dec6a220dad5b019609f93deca1d9 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Fri, 27 Nov 2026 18:07:14 +0000 Subject: [PATCH] feat: add Progress Indicator Podcast and iTunes U lists show a half-filled status circle next to an item that has been started but not finished, including an unfinished replay. The circle follows the saved resume position, or the live one while the item plays, and keeps Apple's outline and colours. Unplayed and finished items, group rows and All rows keep the stock icons. From RevolaOS extensions 72562b52fe7e. --- Makefile | 3 +- NOTICE | 5 +- README.md | 1 + catalog/sources.toml | 5 + extensions/progress-indicator/Makefile | 3 + extensions/progress-indicator/README.md | 9 + .../assets/LICENSE.cupertino-icons | 20 + .../assets/settings-progress-indicator.png | Bin 0 -> 887 bytes .../assets/settings-progress-indicator.svg | 5 + extensions/progress-indicator/bitmap.c | 117 ++++++ extensions/progress-indicator/bitmap.h | 8 + extensions/progress-indicator/listing.toml | 7 + extensions/progress-indicator/main.c | 160 ++++++++ extensions/progress-indicator/manifest.toml | 13 + .../screenshots/podcast-list.png | Bin 0 -> 13218 bytes .../progress-indicator/tests/contracts.c | 375 ++++++++++++++++++ extensions/progress-indicator/tests/run.py | 63 +++ 17 files changed, 792 insertions(+), 2 deletions(-) create mode 100644 extensions/progress-indicator/Makefile create mode 100644 extensions/progress-indicator/README.md create mode 100644 extensions/progress-indicator/assets/LICENSE.cupertino-icons create mode 100644 extensions/progress-indicator/assets/settings-progress-indicator.png create mode 100644 extensions/progress-indicator/assets/settings-progress-indicator.svg create mode 100644 extensions/progress-indicator/bitmap.c create mode 100644 extensions/progress-indicator/bitmap.h create mode 100644 extensions/progress-indicator/listing.toml create mode 100644 extensions/progress-indicator/main.c create mode 100644 extensions/progress-indicator/manifest.toml create mode 100644 extensions/progress-indicator/screenshots/podcast-list.png create mode 100644 extensions/progress-indicator/tests/contracts.c create mode 100644 extensions/progress-indicator/tests/run.py diff --git a/Makefile b/Makefile index 32d96f0..1a4db59 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-3.0-only SDK ?= ../osos-lab/rvx-sdk OUT ?= build -extensions := balance crossfeed dsp night-shift playback-log +extensions := balance crossfeed dsp night-shift playback-log progress-indicator .PHONY: all $(extensions) all: $(extensions) @@ -16,6 +16,7 @@ check: $(PYTHON) extensions/balance/tests/run.py "$(abspath $(SDK))" $(PYTHON) extensions/crossfeed/tests/run.py "$(abspath $(SDK))" $(PYTHON) extensions/dsp/tests/run.py "$(abspath $(SDK))" + $(PYTHON) extensions/progress-indicator/tests/run.py "$(abspath $(SDK))" @mkdir -p "$(OUT)" $(CC) $(TEST_FLAGS) extensions/night-shift/test.c -o "$(OUT)/test-night-shift" "$(OUT)/test-night-shift" diff --git a/NOTICE b/NOTICE index 8f60e86..641b139 100644 --- a/NOTICE +++ b/NOTICE @@ -4,7 +4,10 @@ Balance, Crossfeed, DSP and the Night Shift scheduling and gamma code are from RevolaOS extensions, revision 36d197b180e55a304ea0468de4330c0d07fe715f. Night Shift derives from kayboll’s RepriseOS work. Playback Log derives from the work of brilliant-alien and lgreitis in osos-lab. Its Settings artwork is -from osos-lab commit 10485fa. The original RevolaOS notice follows. +from osos-lab commit 10485fa. Progress Indicator is from RevolaOS extensions, +revision 72562b52fe7e4074a3479caac86b84ec1d285966. Its catalog icon is a +Cupertino Icons glyph (MIT), see the LICENSE.cupertino-icons beside it. The +original RevolaOS notice follows. RevolaOS Copyright (C) 2026 The RevolaOS Authors. GPL-3.0-only. diff --git a/README.md b/README.md index c7692aa..6089976 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,6 @@ This repository hosts the source for these RepriseOS extensions and accepts prop - [Night Shift](extensions/night-shift/) warms the display manually or automatically from sunset to sunrise. - [Playback Log](extensions/playback-log/) records listening history for scrobbling and optional detailed reports. - [Crossfeed](extensions/crossfeed/) blends a little of each stereo channel into the other for headphone listening. It uses the included [DSP library](extensions/dsp/). +- [Progress Indicator](extensions/progress-indicator/) shows a half-filled status circle for partially played podcasts and iTunes U items. To add your extension to the catalog, open a PR following the [submission guide](catalog/README.md). Later releases are picked up automatically. diff --git a/catalog/sources.toml b/catalog/sources.toml index 1e88372..1e5c693 100644 --- a/catalog/sources.toml +++ b/catalog/sources.toml @@ -22,3 +22,8 @@ tag_prefix = "playback-log/v" repo = "RepriseOS/repriseos-extensions" path = "extensions/dsp" tag_prefix = "dsp/v" + +[progress-indicator] +repo = "RepriseOS/repriseos-extensions" +path = "extensions/progress-indicator" +tag_prefix = "progress-indicator/v" diff --git a/extensions/progress-indicator/Makefile b/extensions/progress-indicator/Makefile new file mode 100644 index 0000000..d72aab2 --- /dev/null +++ b/extensions/progress-indicator/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-3.0-only +main_SOURCES := main.c bitmap.c +include $(SDK)/rv.mk diff --git a/extensions/progress-indicator/README.md b/extensions/progress-indicator/README.md new file mode 100644 index 0000000..77c79e9 --- /dev/null +++ b/extensions/progress-indicator/README.md @@ -0,0 +1,9 @@ +# Progress Indicator + +Shows a half-filled status circle for partially played podcasts and iTunes U items in Apple's item lists, including an unfinished replay. Unplayed and completed items, group rows and All rows keep the stock look. The circle follows the saved resume position, or the live one while the item plays, and keeps the stock outline and colours. + +| | | +|---|---| +| Default | on | +| Memory | image, plus 16 bytes per list model it has drawn in, freed with the model or on disable | +| Settings | none | diff --git a/extensions/progress-indicator/assets/LICENSE.cupertino-icons b/extensions/progress-indicator/assets/LICENSE.cupertino-icons new file mode 100644 index 0000000..581f84c --- /dev/null +++ b/extensions/progress-indicator/assets/LICENSE.cupertino-icons @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2016 Vladimir Kharlampidi + +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. \ No newline at end of file diff --git a/extensions/progress-indicator/assets/settings-progress-indicator.png b/extensions/progress-indicator/assets/settings-progress-indicator.png new file mode 100644 index 0000000000000000000000000000000000000000..9e1babc57762dff7ef19c5ebb82ef9167bdc1313 GIT binary patch literal 887 zcmeAS@N?(olHy`uVBq!ia0vp^en4Ew0VEhU?en+-q?nSt-CY>|xA&jf59G0zc>21s zzv7k_lr+%(r)&WfQY~?fC`m~yNwrEYN(E93Mg~S^x`u|jM&==g=2k|gRwfqO1_o9J z20RcptHiCL_Dxd=P=f~ChLX(O)Z&uF+ydNsw0vd|EB};^kX`ewzZ}@TY~_XB+1rd)MU+iqo^_%kxpQAp%Z|SZ zAHHtC+goJ!aQR%R+r~T4UC8iUvD<_WNRU2#{;uqf!cl*7T7zf_NHC_GieCQ-O^f9(y+rTdwlyp3A+=Fm$g zNsZ;XQEwW`6YuxgG6-+`{#L6mCP(H$S8MgtQ<|GueP(Yhn`3FqWRd@b&1Q#=!+y{1 z={6R78M`jd7VOVi>VInS@kx`;vaLJpetCsTsg%X@NT*3AoAora9|XnSd2i`?u~Prk z)yhIGk5%RcrgeA3J+HF8n<2kF^I>1il-pmdcX(ZDYmEN>*zb+C$|>F7g}sxe@!Xj+ zeOksOll%v1dv{FB@-$|9*D79qvCO09YI#$Xp>M!#XSwFnTRf!>ZSg*rT*Ci$^6q7G zcYYBwNVRO%OV8tZu&K4%*P`ey!{ckIMYnPTC;sM~GCOzHl=6o`s~Pr|`E~|cU*EuC z@Wy1fs(4OJwBUk(*NY;>H}Co=yWq-`Ws%cvef4M5NQ*UHxv@Z?{MS2v1}@%rvqG$c zI=$oSw|$o2wT|0S>O0R*1^B Qz+}we>FVdQ&MBb@0Q^sdXaE2J literal 0 HcmV?d00001 diff --git a/extensions/progress-indicator/assets/settings-progress-indicator.svg b/extensions/progress-indicator/assets/settings-progress-indicator.svg new file mode 100644 index 0000000..2dd5f2a --- /dev/null +++ b/extensions/progress-indicator/assets/settings-progress-indicator.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/extensions/progress-indicator/bitmap.c b/extensions/progress-indicator/bitmap.c new file mode 100644 index 0000000..8550c09 --- /dev/null +++ b/extensions/progress-indicator/bitmap.c @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ + +#include "bitmap.h" +#include "osos-2.0.5.h" +#include + +enum { + icon_width = 13, + icon_height = 29, + palette_capacity = 70, + output_pixels = BMap_payload + 4 + palette_capacity * 4, + output_size = output_pixels + icon_width * icon_height, +}; + +/* Drawables borrow module-lifetime, word-aligned BMaps for each icon variant. */ +static uint32_t half_icons[4][(output_size + 3) / 4]; +static const uint16_t icon_sizes[] = {537, 597, 533, 593}; +_Static_assert(sizeof half_icons[0] >= output_size, "Half-circle bitmap capacity"); + +/* Inner semicircle coverage, out of 64 samples per pixel. Rows start at y=0 + * for video and y=10 for audio; columns start at x=6. The 23 partial pixels + * require at most 23 additional palette entries. */ +static const uint8_t inner_coverage[9][5] = { + {12, 11, 0, 0, 0}, {48, 64, 49, 6, 0}, {48, 64, 64, 52, 1}, + {48, 64, 64, 64, 19}, {48, 64, 64, 64, 32}, {48, 64, 64, 64, 26}, + {48, 64, 64, 61, 6}, {48, 64, 63, 21, 0}, {30, 35, 10, 0, 0}, +}; + +static uint32_t icon_word(const uint8_t *p) +{ + return p[0] | (uint32_t)p[1] << 8 | (uint32_t)p[2] << 16 | (uint32_t)p[3] << 24; +} + +/* Derive from the current themed pixels. Only the interior of the right half + * changes; the native antialiased outline and the video glyph stay intact. */ +const void *progress_bitmap(const uint8_t *source, unsigned variant) +{ + if (variant >= 4) + return NULL; + unsigned size = icon_sizes[variant]; + if (!source || source[BMap_format] != BMapFormat_Indexed8 || + source[BMap_format + 1] || source[BMap_stride] != icon_width || + source[BMap_stride + 1] || source[BMap_depth] != 8 || source[BMap_depth + 1] || + icon_word(source + BMap_bounds) || icon_word(source + BMap_bounds + 4) || + icon_word(source + BMap_bounds + 8) != icon_height || + icon_word(source + BMap_bounds + 12) != icon_width || + icon_word(source + BMap_payload_bytes) != size - BMap_payload) + return NULL; + unsigned colors = icon_word(source + BMap_payload); + unsigned pixels = BMap_payload + 4 + colors * 4; + if (colors > 256 || pixels + 13 * 29 != size) + return NULL; + unsigned transparent = 0; + while (transparent < colors && source[BMap_payload + 4 + transparent * 4 + 3]) + transparent++; + if (transparent == colors) + return NULL; + + /* Validate before modifying storage that an earlier drawable may borrow. + * Each partially covered pixel can add at most one palette entry; fully + * cleared pixels use the existing transparent entry. */ + enum { extra = 23 }; + + if (colors + extra > palette_capacity) + return NULL; + for (unsigned i = 0; i < icon_width * icon_height; i++) + if (source[pixels + i] >= colors) + return NULL; + + uint8_t *image = (void *)half_icons[variant]; + for (unsigned i = 0; i < output_pixels; i++) + image[i] = i < pixels ? source[i] : 0; + for (unsigned i = 0; i < icon_width * icon_height; i++) + image[output_pixels + i] = source[pixels + i]; + half_icons[variant][BMap_payload_bytes / 4] = output_size - BMap_payload; + half_icons[variant][BMap_payload / 4] = palette_capacity; + + unsigned top = variant < 2 ? 0 : 10; + unsigned used = colors; + for (unsigned y = 0; y < 9; y++) { + for (unsigned x = 0; x < 5; x++) { + unsigned clear = inner_coverage[y][x]; + if (!clear) + continue; + unsigned pixel = output_pixels + (top + y) * icon_width + x + 6; + const uint8_t *color = source + BMap_payload + 4 + image[pixel] * 4; + unsigned alpha = (color[3] * (64 - clear) + 32) / 64; + if (!alpha) { + image[pixel] = transparent; + continue; + } + unsigned match = 0; + for (; match < used; match++) { + const uint8_t *candidate = image + BMap_payload + 4 + match * 4; + if (candidate[0] == color[0] && candidate[1] == color[1] && + candidate[2] == color[2] && candidate[3] == alpha) + break; + } + if (match == used) { + uint8_t *added = image + BMap_payload + 4 + used++ * 4; + for (unsigned i = 0; i < 3; i++) + added[i] = color[i]; + added[3] = alpha; + } + image[pixel] = match; + } + } + return image; +} + +int progress_bitmap_owns(const void *payload) +{ + for (unsigned i = 0; i < 4; i++) + if (payload == (const uint8_t *)half_icons[i] + BMap_payload) + return 1; + return 0; +} diff --git a/extensions/progress-indicator/bitmap.h b/extensions/progress-indicator/bitmap.h new file mode 100644 index 0000000..684f0be --- /dev/null +++ b/extensions/progress-indicator/bitmap.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +#ifndef PROGRESS_BITMAP_H +#define PROGRESS_BITMAP_H +#include +/* Four word-aligned variants, borrowed until the next rebuild or unload. */ +const void *progress_bitmap(const uint8_t *source, unsigned variant); +int progress_bitmap_owns(const void *payload); +#endif diff --git a/extensions/progress-indicator/listing.toml b/extensions/progress-indicator/listing.toml new file mode 100644 index 0000000..aa7dd4b --- /dev/null +++ b/extensions/progress-indicator/listing.toml @@ -0,0 +1,7 @@ +details = "Podcast and iTunes U lists show a half-filled circle next to an item you have started but not finished; unplayed items keep the full dot and finished ones none. The circle follows the saved position, or the live one while the item plays." + +icon = "assets/settings-progress-indicator.png" + +[[screenshots]] +file = "screenshots/podcast-list.png" +alt = "A podcast's episode list: a full dot before the unplayed episode, a half-filled circle before the partly played one and none before the finished one." diff --git a/extensions/progress-indicator/main.c b/extensions/progress-indicator/main.c new file mode 100644 index 0000000..4c85240 --- /dev/null +++ b/extensions/progress-indicator/main.c @@ -0,0 +1,160 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ + +#include "bitmap.h" +#include "osos-2.0.5.h" +#include "rv_api.h" +#include "rv_media.h" +#include "rv_sites.h" +#include "rv_ui.h" +#include + +static const struct rv_api *api; +static rv_extension_handle self; +static int stopping; + +/* The UI task owns models and this list. Both native destructor routes remove + * their model before its embedded bitmaps are destroyed. */ +struct borrower { + struct borrower *next; + void *model; + const void *native[2]; +}; +static struct borrower *borrowers; + +static void *icon_of(void *model, unsigned selected) +{ + return (uint8_t *)model + (selected ? MediaListModel_selected_status_icon + : MediaListModel_status_icon); +} + +/* Player locked. */ +static int in_progress(struct MediaItem *item, void *player) +{ + if (!rv_item_valid(item) || + !rv_item_value(item, MediaItem_remembers_position_method)) + return 0; + uint32_t start = rv_item_value(item, MediaItem_start_time_method); + uint32_t end = rv_item_value(item, MediaItem_stop_time_method); + if (!end) + end = rv_item_value(item, MediaItem_duration_method); + if (end <= start) + return 0; + uint32_t position = rv_item_value(item, MediaItem_bookmark_method); + if (RV_FIELD(player, MediaPlayer_current_track, void *)) + rv_player_position_of(player, item, &position); + return position > start && position < end; +} + +static struct borrower *remember(void *model) +{ + for (struct borrower *b = borrowers; b; b = b->next) + if (b->model == model) + return b; + struct borrower *b = api->alloc(self, sizeof *b); + if (b) { + *b = (struct borrower){.next = borrowers, .model = model}; + borrowers = b; + } + return b; +} + +static uint32_t destroy(uintptr_t model, const void *next) +{ + for (struct borrower **link = &borrowers; *link; link = &(*link)->next) { + struct borrower *b = *link; + if (b->model == (void *)model) { + *link = b->next; + api->free(self, b); + break; + } + } + return api->hook_next(next, model, 0, 0, 0, 0, 0); +} + +static uint32_t property(uintptr_t model_address, uint32_t type, uint32_t property, + uint32_t row, const void *next, uintptr_t *out) +{ + uint32_t handled = + api->hook_next(next, model_address, type, property, row, (uintptr_t)out, 0); + if (!handled || stopping || type != Property_Drawable || (int32_t)row < 0 || + (property != Property_PodcastStatus && + property != Property_PodcastStatusSelected && + property != Property_ITunesUStatus && + property != Property_ITunesUStatusSelected)) + return handled; + void *model = (void *)model_address; + if (RV_FIELD(model, MediaListModel_all_row, uint8_t)) { + if (!row) + return handled; + row--; + } + void *player = MediaPlayer_GetInstance(); + void *source = LibraryModelRef_Get((uint8_t *)model + MediaListModel_source); + if (!player || !source) + return handled; + uint32_t storage[MediaItem_bytes / 4]; + struct MediaItem *item = (void *)storage; + Mutex_Lock((uint8_t *)player + MediaPlayer_mutex); + rv_model_item(source, (int32_t)row, item); + int partial = in_progress(item, player); + int video = partial && MediaItem_HasKind8062(item); + MediaItem_Destroy(item); + Mutex_Unlock((uint8_t *)player + MediaPlayer_mutex); + if (!partial) + return handled; + unsigned selected = property == Property_PodcastStatusSelected || + property == Property_ITunesUStatusSelected; + unsigned variant = (video ? 0 : 2) + (selected ? 0 : 1); + const void *native = ResourceService_GetBitmap( + UI_GetResourceService(), RES_MediaStatus_VideoSelected_Bitmap + variant); + const void *bitmap = progress_bitmap(native, variant); + if (!bitmap) + return handled; + void *icon = icon_of(model, selected); + const uint8_t *payload = RV_FIELD(icon, Bitmap_pixels, const uint8_t *); + if (!payload || progress_bitmap_owns(payload) || + RV_FIELD(icon, Bitmap_owns_pixels, uint8_t)) + return handled; + struct borrower *b = remember(model); + if (!b) + return handled; + /* Preserve the native glyph, including its empty state during a replay. */ + b->native[selected] = payload - BMap_payload; + Bitmap_LoadResource(icon, bitmap, 0, 0); + *out = (uintptr_t)icon; + return handled; +} + +static void unload(void) +{ + stopping = 1; + while (borrowers) { + struct borrower *b = borrowers; + borrowers = b->next; + for (unsigned selected = 0; selected < 2; selected++) { + void *icon = icon_of(b->model, selected); + if (progress_bitmap_owns(RV_FIELD(icon, Bitmap_pixels, const void *))) + Bitmap_LoadResource(icon, b->native[selected], 0, 0); + } + api->free(self, b); + } +} + +static const struct rv_hook hooks[] = { + RV_HOOK_FILTER(RV_SITE_MediaListModel_IndexedProperty_slot, property), + RV_HOOK_FILTER(RV_SITE_MediaListModel_Destroy_slot, destroy), + RV_HOOK_FILTER(RV_SITE_MediaListModel_Destroy_call, destroy), +}; +static const struct rv_descriptor descriptor = { + .size = sizeof descriptor, + RV_HOOKS(hooks), + .unload = unload, +}; + +const struct rv_descriptor *rv_module_entry(const struct rv_api *core, + rv_extension_handle handle) +{ + api = core; + self = handle; + return &descriptor; +} diff --git a/extensions/progress-indicator/manifest.toml b/extensions/progress-indicator/manifest.toml new file mode 100644 index 0000000..b9905cd --- /dev/null +++ b/extensions/progress-indicator/manifest.toml @@ -0,0 +1,13 @@ +id = "progress-indicator" +name = "Progress Indicator" +description = "Show half-filled status circles for partially played podcasts and iTunes U items." +version = "0.1.0" +author = "RevolaOS" +license = "GPL-3.0-only" +api = "1.82" +stability = "beta" +category = "media" + +[[module]] +name = "main" +trigger = "always" diff --git a/extensions/progress-indicator/screenshots/podcast-list.png b/extensions/progress-indicator/screenshots/podcast-list.png new file mode 100644 index 0000000000000000000000000000000000000000..636db07b8ead62a37aeb548a94060229d12fedd6 GIT binary patch literal 13218 zcmeIZWmFwqw60k=!4oWj;1FDc%f{Ua?(R--cMA@|HArxGcb5bY?!n!y>-+lLamPKU z&**!9^`HJzqjs^`dsVHq=A6$v-yNyv?L?Wd+;}g7FN3LeOsi|gb#q)=L#9=(=0>{qje#ApA=L%AK zji`v5XskMy4{bphn-{A>0g`voXzH>gCKs=Np2$J2RDLcw7Ii0x*4j-g(=n;F? zlLPT58&8Cad?hM*$c~c(1_Sp`r{l@{CkAwXr{M-GaXVP$X;XWK&!67jX6<`B5&93E zB18#!XiBdszAMUK%^^o3B}rckZK(+Dj9q$`;tjey!=g(_LrcZ#P}G#FcSh#*GH_c- zJqxd*8~yQ0h}waF#5cWEkup?_SpKVLB_NQRF`^+ybVB4Rc-Cy;FUOCBM#_6MpTpFn z5QCvp)J-ztv#IVPGxJ>^W*?;kzE2SWh*`1>D1<05Ou27?mJ2ZCNEcm{Mq!M-1&JO0P5D zj23-cKV`f*9n_H{E+-n&iPw;&MfQqEy-bhd!7PGNsMn5!4vsWxS;Zm~ zAr`Ya0vzOIE}zP^^h-_a8D@o_e0(oIcnk7B?@f2#24M2bYj-+$-}O|zhVgsSrZ=a3 zxSyA(qbwP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XEeAd8=mbW0$vkPd~DI!h$z1u%* zO}@-hphLR!ZtU{uyO-(EY5EFY%)msy(prAXCny2E-^UmqL6a)yb+Hs;oJlk9m*|WL zD)gk)N)IT3X^`OHJGD_~Xo$>NMWTG@mKf&Sj630huFFy=7`H67EGjgOMF_hYte}3n zCqTULR#~N<_lqtEt9gi0T5Be)+DJn!60eoleBIoXQ)J>;6`Cy=(|&e?7Qy@CC)!BA zsHVh~cU4o=LD8X~Y-Oq*lQ0bF%Eh9+{ZQk~ikD4vUd^B!478vlcU> zou-+)IQS!Pw7Bl2eOPA6$RzxO@vrK*=C%IY&8i+O;5UCh7g2IsY~A2k9u-ZD>fY=( z3gIKHf0dWdrvTuGkpKKUdeBRJ72?ADQ|JE(;S`H>tuRez%brvX)Ijj}bjnJAr@lUZ(oX7Qi z_2(-wPojyz;<>>Ns59ay`pS!O7+KIM|4+vTjR2j3kwR2)hLwIDeSzTDRJB62aveIH zVAwOo_lHju5qZ_-Uq@HQklQURHg&6+bcW=2K<2dP>@pm$8#)lp8?I7-?Zpl4Z_g{V z@Hc|m?Hk#x0k^+%rGlc$Y+2g)uWgh6eS*8?2MO*tSc{IUX8(MM@3?j*8w)8{Ue;!bDmiDFBkiQsE%sZ(1EWz~){ykT zp+Iah!oMu0clO_4*}xA-Kkh6^m{#{c-bCjAwgdQ|8iN1-%m3#_>Hi1MIop V_nka0_}d#mQdCZ)LP$U0{{r!%5Ig_? literal 0 HcmV?d00001 diff --git a/extensions/progress-indicator/tests/contracts.c b/extensions/progress-indicator/tests/contracts.c new file mode 100644 index 0000000..c4c945f --- /dev/null +++ b/extensions/progress-indicator/tests/contracts.c @@ -0,0 +1,375 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +#include +#include +#include +#include "../main.c" +#include "../bitmap.c" + +static uint8_t images[4][600]; +static uintptr_t methods[128], source_methods[256]; +static uintptr_t *source = source_methods; +static uint8_t player[MediaPlayer_mutex + 16]; +static uint8_t model[MediaListModel_selected_status_icon + Bitmap_bytes]; +static uint8_t model2[sizeof model]; +static uint32_t bookmark, start, stop, duration = 3600000, live, generation = 7; +static int valid = 1, remembers = 1, video, current, same = 1, have_player = 1; +static int locked, allocations, fail_alloc, calls, item_calls, native_result = 1; +static int marker, other_record; + +static uint32_t get_bookmark(struct MediaItem *i) +{ + (void)i; + return bookmark; +} + +static uint32_t get_start(struct MediaItem *i) +{ + (void)i; + return start; +} + +static uint32_t get_stop(struct MediaItem *i) +{ + (void)i; + return stop; +} + +static uint32_t get_duration(struct MediaItem *i) +{ + (void)i; + return duration; +} + +static uint32_t get_remembers(struct MediaItem *i) +{ + (void)i; + return remembers; +} + +struct MediaItem *MediaItem_InitFromRecord(struct MediaItem *i, void *record, + uint8_t flags) +{ + (void)flags; + memset(i, 0, MediaItem_bytes); + RV_FIELD(i, 0, void *) = methods; + RV_FIELD(i, MediaItem_record, void *) = record; + RV_FIELD(i, MediaItem_generation, uint32_t) = generation; + return i; +} + +void MediaItem_Destroy(struct MediaItem *i) +{ + (void)i; +} + +int MediaItem_IsValid(struct MediaItem *i) +{ + (void)i; + return valid; +} + +uint32_t MediaItem_HasKind8062(struct MediaItem *i) +{ + (void)i; + return video; +} + +void *MediaPlayer_GetInstance(void) +{ + return have_player ? player : NULL; +} + +int MediaPlayer_GetCurrentItem(void *p, struct MediaItem *i) +{ + assert(p == player && locked); + MediaItem_InitFromRecord(i, same == 2 ? &other_record : &marker, 0); + RV_FIELD(i, MediaItem_generation, uint32_t) += !same; + return 1; +} + +uint32_t MediaPlayer_GetPosition(void *p) +{ + assert(p == player && locked); + return live; +} + +int Mutex_Lock(void *p) +{ + assert(p == player + MediaPlayer_mutex && !locked); + locked++; + return 0; +} + +int Mutex_Unlock(void *p) +{ + assert(p == player + MediaPlayer_mutex && locked); + locked--; + return 0; +} + +void *LibraryModelRef_Get(void *p) +{ + (void)p; + return &source; +} + +static void get_item(struct MediaItem *i, void *p, uint32_t row) +{ + assert(p == &source && locked && row < 10); + item_calls++; + MediaItem_InitFromRecord(i, &marker, 0); +} + +void *UI_GetResourceService(void) +{ + return images; +} + +void *ResourceService_GetBitmap(void *service, uint32_t id) +{ + assert(service == images && id >= RES_MediaStatus_VideoSelected_Bitmap); + unsigned variant = id - RES_MediaStatus_VideoSelected_Bitmap; + assert(variant < 4); + return images[variant]; +} + +void Bitmap_LoadResource(void *b, const void *resource, uint32_t a, uint32_t flags) +{ + assert(resource && !locked && !a && !flags); + RV_FIELD(b, Bitmap_pixels, const uint8_t *) = + (const uint8_t *)resource + BMap_payload; +} + +static void *allocate(rv_extension_handle h, uint32_t bytes) +{ + (void)h; + if (fail_alloc) + return NULL; + allocations++; + return calloc(1, bytes); +} + +static void release(rv_extension_handle h, void *p) +{ + (void)h; + allocations--; + free(p); +} + +static uint32_t next_call(const void *next, uintptr_t m, uintptr_t type, uintptr_t prop, + uintptr_t row, uintptr_t out, uintptr_t unused) +{ + (void)row; + (void)unused; + assert(!locked); + calls++; + if (next == &marker) { + assert(!borrowers || borrowers->model != (void *)m); + return 42; + } + assert(type == Property_Drawable || !type); + unsigned selected = prop == Property_PodcastStatusSelected || + prop == Property_ITunesUStatusSelected; + Bitmap_LoadResource(icon_of((void *)m, selected), images[3], 0, 0); + *(uintptr_t *)out = (uintptr_t)icon_of((void *)m, selected); + return native_result; +} +static const struct rv_api test_api = { + .alloc = allocate, .free = release, .hook_next = next_call}; + +static void put_word(uint8_t *p, uint32_t value) +{ + memcpy(p, &value, 4); +} + +static int render_on(void *m, uint32_t prop, uint32_t row) +{ + uintptr_t out; + RV_FIELD(player, MediaPlayer_current_track, void *) = current ? &marker : NULL; + assert(property((uintptr_t)m, Property_Drawable, prop, row, NULL, &out) == + (uint32_t)native_result); + return progress_bitmap_owns(RV_FIELD((void *)out, Bitmap_pixels, void *)); +} + +static int render(void) +{ + return render_on(model, Property_PodcastStatus, 2); +} + +/* Check decoded pixels against the semicircle geometry. */ +static void check_pixels(unsigned variant) +{ + const uint8_t *source = images[variant]; + const uint8_t *result = progress_bitmap(images[variant], variant); + assert(result); + unsigned input = 32 + icon_word(source + 28) * 4; + unsigned output = 32 + icon_word(result + 28) * 4; + int center_y = variant < 2 ? 67 : 227; + for (int y = 0; y < 29; y++) { + for (int x = 0; x < 13; x++) { + unsigned clear = 0; + if (x >= 6 && x < 11) { + for (int sy = 0; sy < 8; sy++) { + int dy = y * 16 + sy * 2 - 7 - center_y; + for (int sx = 0; sx < 8; sx++) { + int dx = x * 16 + sx * 2 - 7 - 96; + clear += dx >= -4 && dx * dx + dy * dy < 64 * 64; + } + } + } + const uint8_t *before = source + 32 + source[input + y * 13 + x] * 4; + const uint8_t *after = result + 32 + result[output + y * 13 + x] * 4; + unsigned alpha = (before[3] * (64 - clear) + 32) / 64; + assert(after[3] == alpha); + if (alpha) + assert(!memcmp(before, after, 3)); + } + } +} + +int main(void) +{ + methods[MediaItem_bookmark_method / sizeof(uintptr_t)] = (uintptr_t)get_bookmark; + methods[MediaItem_start_time_method / sizeof(uintptr_t)] = (uintptr_t)get_start; + methods[MediaItem_stop_time_method / sizeof(uintptr_t)] = (uintptr_t)get_stop; + methods[MediaItem_duration_method / sizeof(uintptr_t)] = (uintptr_t)get_duration; + methods[MediaItem_remembers_position_method / sizeof(uintptr_t)] = + (uintptr_t)get_remembers; + source_methods[SongModel_get_item_method / sizeof(uintptr_t)] = (uintptr_t)get_item; + for (unsigned v = 0; v < 4; v++) { + uint8_t *b = images[v]; + b[BMap_format] = BMapFormat_Indexed8; + b[BMap_stride] = 13; + b[BMap_depth] = 8; + put_word(b + BMap_bounds + 8, 29); + put_word(b + BMap_bounds + 12, 13); + put_word(b + BMap_payload_bytes, icon_sizes[v] - BMap_payload); + unsigned colors = (icon_sizes[v] - 32 - 13 * 29) / 4; + put_word(b + BMap_payload, colors); + for (unsigned j = 1; j < colors; j++) { + b[32 + j * 4] = j * 5; + b[33 + j * 4] = 255 - j * 3; + b[34 + j * 4] = j * 7; + b[35 + j * 4] = j * 5; + } + for (unsigned j = 0; j < 13 * 29; j++) + b[32 + colors * 4 + j] = j % colors; + check_pixels(v); + } + rv_module_entry(&test_api, NULL); + assert(!render()); + bookmark = 60000; + assert(render()); + assert(allocations == 1); + for (int j = 0; j < 50; j++) + assert(render()); + assert(allocations == 1); + assert(render_on(model, Property_PodcastStatusSelected, 2)); + assert(render_on(model, Property_ITunesUStatus, 2)); + assert(render_on(model, Property_ITunesUStatusSelected, 2)); + video = 1; + assert(render()); + video = 0; + bookmark = duration; + assert(!render()); + bookmark = UINT32_MAX; + assert(!render()); + start = 30000; + stop = 120000; + bookmark = start; + assert(!render()); + bookmark++; + assert(render()); + bookmark = stop; + assert(!render()); + stop = start; + assert(!render()); + start = stop = 0; + duration = 0; + assert(!render()); + duration = 3600000; + bookmark = 60000; + current = 1; + live = 0; + assert(!render()); + live = 90000; + assert(render()); + live = duration; + assert(!render()); + same = 0; + assert(render()); + same = 2; + assert(render()); + same = 1; + current = 0; + valid = 0; + assert(!render()); + valid = 1; + remembers = 0; + assert(!render()); + remembers = 1; + have_player = 0; + assert(!render()); + have_player = 1; + int before = item_calls; + assert(!render_on(model, Property_ItemId, 2)); + assert(item_calls == before); + RV_FIELD(model, MediaListModel_all_row, uint8_t) = 1; + assert(!render_on(model, Property_PodcastStatus, 0)); + assert(item_calls == before); + assert(render_on(model, Property_PodcastStatus, 3)); + RV_FIELD(model, MediaListModel_all_row, uint8_t) = 0; + native_result = 0; + assert(!render()); + native_result = 1; + assert(!render_on(model, Property_PodcastStatus, UINT32_MAX)); + uint8_t saved[sizeof half_icons[3]]; + assert(render()); + memcpy(saved, half_icons[3], sizeof saved); + unsigned colors = icon_word(images[3] + BMap_payload), pixels = 32 + colors * 4; + uint8_t last = images[3][pixels + 376]; + images[3][pixels + 376] = colors; + assert(!render()); + assert(!memcmp(saved, half_icons[3], sizeof saved)); + images[3][pixels + 376] = last; + images[3][35] = 255; + assert(!render()); + assert(!memcmp(saved, half_icons[3], sizeof saved)); + images[3][35] = 0; + put_word(images[3] + BMap_payload, 0x40000000u + colors); + assert(!render()); + assert(!memcmp(saved, half_icons[3], sizeof saved)); + put_word(images[3] + BMap_payload, colors); + put_word(images[3] + BMap_bounds, 1); + assert(!render()); + put_word(images[3] + BMap_bounds, 0); + images[3][0] = 0; + assert(!render()); + images[3][0] = BMapFormat_Indexed8; + images[3][36] = 17; + assert(render()); + assert(((uint8_t *)half_icons[3])[36] == 17); + fail_alloc = 1; + assert(!render_on(model2, Property_PodcastStatus, 2)); + fail_alloc = 0; + assert(render_on(model2, Property_PodcastStatus, 2)); + assert(allocations == 2); + assert(destroy((uintptr_t)model2, &marker) == 42); + assert(allocations == 1); + memset(model2, 0xa5, + sizeof model2); /* Dead model must never be touched on unload. */ + unload(); + assert(!allocations && !borrowers); + for (unsigned selected = 0; selected < 2; selected++) + assert(!progress_bitmap_owns( + RV_FIELD(icon_of(model, selected), Bitmap_pixels, void *))); + assert(!render()); + stopping = 0; + for (int j = 0; j < 20; j++) { + assert(render()); + unload(); + assert(!allocations); + stopping = 0; + } + return 0; +} diff --git a/extensions/progress-indicator/tests/run.py b/extensions/progress-indicator/tests/run.py new file mode 100644 index 0000000..d76fc3c --- /dev/null +++ b/extensions/progress-indicator/tests/run.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-only +"""Run native-contract fixtures with a staged SDK: python3 tests/run.py SDK.""" + +import re +import subprocess +import sys +import tempfile +from pathlib import Path + +root = Path(__file__).resolve().parent +sdk = Path(sys.argv[1]).resolve() +with tempfile.TemporaryDirectory(prefix="progress-indicator-tests-") as name: + work = Path(name) + # Widen pointer-bearing native layouts on the host. BMap bytes remain ARM-format. + header = (sdk / "osos-2.0.5.h").read_text() + prefixes = ( + "MediaItem_", + "MediaPlayer_", + "MediaListModel_", + "SongModel_", + "Bitmap_", + ) + + def widen(match): + key, value = match.groups() + return ( + f"#define {key} {int(value, 16) * 2:#x}" + if key.startswith(prefixes) + else match[0] + ) + + header = re.sub(r"#define (\w+) (0x[0-9a-f]+)", widen, header) + (work / "osos-2.0.5.h").write_text(header) + api = (sdk / "rv_api.h").read_text() + api = re.sub(r"uint32_t ([abcdef])([,)])", r"uintptr_t \1\2", api) + (work / "rv_api.h").write_text(api) + for file in ("rv_ui.h", "rv_sites.h", "rv_media.h"): + (work / file).write_text((sdk / file).read_text()) + executable = work / "contracts" + subprocess.run( + [ + "cc", + "-std=c11", + "-Wall", + "-Wextra", + "-Werror", + # GCC takes the SDK's rv_player_position_of passing the unfilled + # `current` to rv_media_item(const void *) as a read. + "-Wno-unknown-warning-option", + "-Wno-error=maybe-uninitialized", + "-g", + "-fsanitize=address,undefined", + "-I", + str(work), + str(root / "contracts.c"), + "-o", + str(executable), + ], + check=True, + ) + subprocess.run([str(executable)], check=True) +print("Progress Indicator contracts passed")