Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
The lock screen's clock and Control Center's buttons on the GPU: two more programs
vcvkkad541c71f1c1
diff --git a/README.md b/README.mdindex b5d4883..0c9cc86 100644--- a/README.md+++ b/README.md@@ -26,7 +26,7 @@| Работает | Не работает ||---|---|| Экран блокировки, разблокировка свайпом, домашний экран с полным набором значков (две страницы), стандартные обои iOS 16 | Звук, сеть (Wi-Fi/сотовая), Bluetooth, камера |-| Системные жесты: свайп снизу — «домой» и переключатель приложений, свайп от левого края — «назад», Пункт управления | Часы экрана блокировки не того цвета: красные, а с `gpu=1` белые, но поверх обоев красная пелена |+| Системные жесты: свайп снизу — «домой» и переключатель приложений, свайп от левого края — «назад», Пункт управления | Без `gpu=1` (программный рендер; в QEMU всегда) часы экрана блокировки просто белые, без «вибрации» под цвет обоев, и верх обоев под ними не затемнён || Запуск приложений: Настройки (вглубь), Часы, Календарь, Фото, Заметки и др.; расширения приложений (виджеты «Погода» и «Календарь» на домашнем экране рисуют своё содержимое — на телефоне; в QEMU им не хватает скорости) | Metal (приложения, рисующие через него сами); отрисовка самим Adreno есть, но пока опытная — см. «GPU» || Сенсорный экран телефона (Goodix GT9916), мультитач, пробуждение касанием | Без `cpus=N` работает одно ядро процессора || Несколько ядер процессора (`cpus=4`: четыре больших ядра телефона) | |@@ -197,6 +197,11 @@ CoreAnimation; если GPU не запустился, в журнале однне привязано к развёртке; панель обновляется 120 раз в секунду). Чтение кадра из шейдера(`EXT_shader_framebuffer_fetch`, им CoreAnimation рисует тени подписей) в freedreno исправлено заплаткой в`tools/mesa/freedreno-darwin.patch`; `glfetch=0` прячет расширение для сравнения.+У рендера OpenGL ES в QuartzCore 16.5 нет шейдеров для половины из девяноста «функций» CoreAnimation (у Metal+есть все); то, чему они нужны, он рисует вовсе без программы. Три такие функции `userland/src/eagl.c` рисует+своими программами по арифметике программного рендера: полоску «домой», цветовую матрицу над уже нарисованным+(`vibrantColorMatrix` — ею сделаны часы экрана блокировки и затемнение обоев под ними) и цветовую матрицу над+предумноженными пикселями (ею же — кнопки связи в Пункте управления, которые без неё были белыми кругами).Прерываний нет (ожидание опросом). GPU выключается при любом штатном конце сеанса (таймер, `./xl stop`, пятьпальцев); после паники следующий запуск сам останавливает его и запускает заново. Приложения, использующие Metalсами, от этого ничего не получают.@@ -232,8 +237,7 @@ CoreAnimation; если GPU не запустился, в журнале одн<img src="docs/maps.jpg" width="180" alt="Карты"></p>-Что на них не так: на экране блокировки поверх обоев красная пелена (слои часов рисуются неверно, в работе);-виджет «Погода» и магазины пусты, потому что нет сети. `docs/settings-about-qemu.png` — более старый снимок+Что на них не так: виджет «Погода» и магазины пусты, потому что нет сети. `docs/settings-about-qemu.png` — более старый снимок«Об этом устройстве» из QEMU.## Сборка из исходниковdiff --git a/docs/control-center.jpg b/docs/control-center.jpgindex 0d1532e..53a40df 100644Binary files a/docs/control-center.jpg and b/docs/control-center.jpg differdiff --git a/docs/lockscreen.jpg b/docs/lockscreen.jpgindex 296eb2b..a8f8df2 100644Binary files a/docs/lockscreen.jpg and b/docs/lockscreen.jpg differdiff --git a/userland/build.sh b/userland/build.shindex 14d3b56..7c69f70 100755--- a/userland/build.sh+++ b/userland/build.sh@@ -106,7 +106,7 @@ if [ -d $IOS/rootfs/usr/lib ]; then# our library for inside stock iOS programs (the jobs in INJECT are started with it)$DYN -dynamiclib -install_name /redwood/lib/libredwood.dylib -framework CoreFoundation -framework IOKit -lobjc \-o obj/libredwood.dylib src/inject.c- $DYN -dynamiclib -install_name /redwood/lib/libredwood-sb.dylib -framework CoreFoundation -lobjc \+ $DYN -dynamiclib -install_name /redwood/lib/libredwood-sb.dylib -framework CoreFoundation -framework IOKit -lobjc \-o obj/libredwood-sb.dylib src/inject_sb.c$DYN -dynamiclib -install_name /redwood/lib/libredwood-media.dylib -framework CoreFoundation -lobjc \-o obj/libredwood-media.dylib src/inject_media.cdiff --git a/userland/src/eagl.c b/userland/src/eagl.cindex c8bd343..87dd160 100644--- a/userland/src/eagl.c+++ b/userland/src/eagl.c@@ -218,6 +218,9 @@ struct eagl {GLuint program; /* the one in use, as CoreAnimation has it */GLuint plain, lookup; /* programs of ours for when that is none (plain_draw_begin()) */GLint plain_matrix, plain_textured, lookup_matrix;+ GLuint vibrant, masking; /* two more: what a colour matrix does to what is behind, and to the layer */+ int blended; /* blending is off for such a draw, to be put back after it */+ GLint vibrant_matrix, vibrant_colours, masking_matrix, masking_colours;unsigned unit; /* the texture unit being spoken of */GLuint bound[8]; /* the 2D texture bound to each of the first units */const GLfloat *matrix; /* where CoreAnimation keeps the matrix it gives its programs */@@ -1154,7 +1157,84 @@ static const char table_fragment[] =" result = vec4(clamp(both + over.rgb * (1. - under.a) + under.rgb * (1. - over.a), 0., opacity), opacity);\n""}\n";-static int plain_draws = 1; /* boot-arg glplain=0: leave such draws as they are; 2: also those without a texture */+/*+ * Two more are told apart by the "function" itself, which CoreAnimation's context has in a known+ * place while it draws (and which our library in the window server hands over with the context:+ * redwood_gl_function_values() below, called from inject.c). Both take a colour matrix, four+ * columns and what is added, the numbers function_values[] keeps.+ *+ * "vcm" (45), the filter vibrantColorMatrix: the layer is not drawn, it says how much of the+ * matrix is applied to what is behind it. The lock screen has two: a gradient over the whole+ * screen, opaque red at the top and clear at the bottom, under which the wallpaper is toned+ * down for the clock to be read; and the clock itself, through whose digits the wallpaper+ * comes out nearly white. Drawn as a picture, the first was a red veil over the wallpaper.+ * What the filter does is CoreAnimation's software renderer's to say (tex_vibrant_color_matrix:+ * the matrix over what is there, tex_color_matrix_4x4_bias, and tex_mix by the layer's alpha);+ * the matrix arithmetic is also in the OpenGL ES renderer's own shaders, colorMatrix4x4Bias.+ * What is there is read with EXT_shader_framebuffer_fetch.+ *+ * "c4p" (20), the filter colorMatrix told that its input is premultiplied+ * (inputPremultipliedValues): the matrix over the layer's pixels as they are. The clock's+ * digits pass through one that keeps nothing but red as alpha ("colorToAlphaMask") before they+ * are that mask; drawn as they were, they stayed white.+ */+#define FUNCTION_MATRIX_PREMULTIPLIED 20+#define FUNCTION_VIBRANT_MATRIX 45++static const char vibrant_fragment[] =+ "#version 300 es\n"+ "#extension GL_EXT_shader_framebuffer_fetch : require\n"+ "uniform lowp sampler2D texture0;\n"+ "uniform mediump vec4 colours[5];\n"+ "in lowp vec4 color;\n"+ "in highp vec2 texcoord;\n"+ "layout(location = 0) inout highp vec4 result;\n"+ "void main() {\n"+ " mediump vec4 layer = color * texture(texture0, texcoord / vec2(textureSize(texture0, 0)));\n"+ " mediump vec4 behind = result, s = behind;\n"+ " s.rgb = s.rgb / max(s.a, .005);\n"+ " s = s.r * colours[0] + s.g * colours[1] + s.b * colours[2] + s.a * colours[3] + colours[4];\n"+ " s.a = clamp(s.a, 0., 1.);\n"+ " s.rgb = clamp(s.rgb * s.a, 0., 1.);\n"+ " result = mix(behind, s, layer.a);\n"+ "}\n";+static const char masking_fragment[] =+ "#version 300 es\n"+ "uniform lowp sampler2D texture0;\n"+ "uniform mediump vec4 colours[5];\n"+ "in lowp vec4 color;\n"+ "in highp vec2 texcoord;\n"+ "out lowp vec4 result;\n"+ "void main() {\n"+ " mediump vec4 s = color * texture(texture0, texcoord / vec2(textureSize(texture0, 0)));\n"+ " result = clamp(s.r * colours[0] + s.g * colours[1] + s.b * colours[2] + s.a * colours[3] + colours[4], 0., 1.);\n"+ "}\n";++static void *ca_context; /* CoreAnimation's GLContext */+static GLfloat function_values[90][20];+static uint8_t function_given[90];++/* From inject.c, at every GLContext::function_uniform(): the numbers a function is given, which no shader of CoreAnimation's takes. */+void+redwood_gl_function_values(void *context, unsigned function, unsigned index, size_t components, size_t count, const float *values)+{+ static uint8_t said[90];++ ca_context = context;+ if (function >= 90 || index != 0 || components * count > 20) {+ return;+ }+ memcpy(function_values[function], values, components * count * sizeof(values[0]));+ function_given[function] = (uint8_t)(components * count);+ if (!said[function]) {+ said[function] = 1;+ say("redwood-gl: CoreAnimation gives its function %u numbers: %zu of %zu, the first %g %g %g %g\n", function, count,+ components, (double)values[0], (double)values[1], (double)values[2], (double)values[3]);+ }+}++/* boot-arg glplain=0: leave such draws as they are; 2: also those without a texture; 3: the two with a colour matrix drawn plainly too */+static int plain_draws = 1;/* One of our programs, made: CoreAnimation's own vertex arrays go in at the places it has them. */static GLuint@@ -1187,12 +1267,48 @@ static boolplain_draw_begin(struct eagl *e, GLint enabled[3]){static const GLfloat identity[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };+ static uint8_t said[90];+ unsigned function = ca_context != NULL ? *(*(uint8_t **)((char *)ca_context + 0x10) + 0x10) : 0;GLint rows = 0;GLuint program;if (e->program != 0 || !plain_draws || (plain_draws == 1 && e->bound[0] == 0)) {return false;}+ if (function < 90 && !said[function]) {+ said[function] = 1;+ say("redwood-gl: a draw with no program is CoreAnimation's function %u\n", function);+ }+ e->blended = 0;+ if (e->bound[0] != 0 && plain_draws != 3 && ((function == FUNCTION_VIBRANT_MATRIX && fetch_offered) ||+ function == FUNCTION_MATRIX_PREMULTIPLIED) && function_given[function] == 20) {+ bool vibrant = function == FUNCTION_VIBRANT_MATRIX;++ if (vibrant && e->vibrant == 0) {+ e->vibrant = plain_program(vibrant_fragment, "a colour matrix over what is behind");+ e->vibrant_matrix = glGetUniformLocation(e->vibrant, "vertex_matrix");+ e->vibrant_colours = glGetUniformLocation(e->vibrant, "colours");+ } else if (!vibrant && e->masking == 0) {+ e->masking = plain_program(masking_fragment, "a colour matrix over premultiplied pixels");+ e->masking_matrix = glGetUniformLocation(e->masking, "vertex_matrix");+ e->masking_colours = glGetUniformLocation(e->masking, "colours");+ }+ program = vibrant ? e->vibrant : e->masking;+ glUseProgram(program);+ glUniformMatrix4fv(vibrant ? e->vibrant_matrix : e->masking_matrix, 1, 0, e->matrix != NULL ? e->matrix : identity);+ glUniform4fv(vibrant ? e->vibrant_colours : e->masking_colours, 5, function_values[function]);+ if (vibrant && glIsEnabled(GL_BLEND)) {+ e->blended = 1; /* the program has blended already */+ glDisable(GL_BLEND);+ }+ for (GLuint i = 0; i < 3; i++) {+ glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled[i]);+ if (!enabled[i]) {+ glEnableVertexAttribArray(i);+ }+ }+ return true;+ }if (e->bound[0] != 0 && e->bound[1] != 0) {glActiveTexture(GL_TEXTURE0 + 1);glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &rows);@@ -1246,7 +1362,10 @@ plain_draw_end(struct eagl *e, const GLint enabled[3])}}glUseProgram(0);- (void)e;+ if (e->blended) {+ glEnable(GL_BLEND);+ e->blended = 0;+ }}static voiddiff --git a/userland/src/inject.c b/userland/src/inject.cindex f579a19..78286f4 100644--- a/userland/src/inject.c+++ b/userland/src/inject.c@@ -235,6 +235,27 @@ my_function_supported(void *context)return supported;}+/*+ * A function that takes numbers besides its textures (a colour matrix, say) is given them through+ * GLContext::function_uniform(), which hands them to the function's shader. The functions the+ * OpenGL ES renderer has no shader for are drawn all the same, with no program, and their numbers+ * go nowhere. Our OpenGL ES library draws some of those with programs of its own (eagl.c,+ * plain_draw_begin()): it is told the numbers here, and with them the context, in which it+ * finds which function a draw is.+ */+static void (*orig_function_uniform)(void *context, unsigned index, size_t components, size_t count, const float *values);+static void (*gl_function_values)(void *context, unsigned function, unsigned index, size_t components, size_t count,+ const float *values);++static void+my_function_uniform(void *context, unsigned index, size_t components, size_t count, const float *values)+{+ if (gl_function_values != NULL) {+ gl_function_values(context, *(*(uint8_t **)((char *)context + 0x10) + 0x10), index, components, count, values);+ }+ orig_function_uniform(context, index, components, count, values);+}+static voidwindow_server_fixes(void){@@ -251,6 +272,10 @@ window_server_fixes(void)if (gl_loaded) {orig_function_supported = replace_virtual("function_supported", VSLOT(VT_GLES_CONTEXT, 0x378), 0x1884a9308UL,my_function_supported);+ if (gl_function_values != NULL) {+ orig_function_uniform = replace_virtual("function_uniform", VSLOT(VT_GLES_CONTEXT, 0x388), 0x1884a9350UL,+ my_function_uniform);+ }}say("redwood: window server hooks %s\n", orig_is_ready && orig_ignore_update_p && orig_begin_update &&orig_finish_update && orig_renderer && orig_render_update ? "installed" : "INCOMPLETE");@@ -706,6 +731,7 @@ opengl_es(void)size_t size = sizeof(arguments) - 1;const char *argument;io_service_t gpu;+ void *library;int wanted = -1, told = 0;if (access(REDWOOD_GL, R_OK) != 0) {@@ -730,11 +756,13 @@ opengl_es(void)say("redwood: %s: CoreAnimation keeps its software renderer\n", told ? "gl=0" : "no GPU to draw with");return;}- if (dlopen(REDWOOD_GL, RTLD_NOW) == NULL) {+ if ((library = dlopen(REDWOOD_GL, RTLD_NOW)) == NULL) {say("redwood: %s: %s\n", REDWOOD_GL, dlerror());return;}gl_loaded = 1;+ gl_function_values = (void (*)(void *, unsigned, unsigned, size_t, size_t, const float *))dlsym(library,+ "redwood_gl_function_values");}__attribute__((constructor))diff --git a/userland/src/inject_sb.c b/userland/src/inject_sb.cindex b0c5f6f..9ccd101 100644--- a/userland/src/inject_sb.c+++ b/userland/src/inject_sb.c@@ -18,10 +18,14 @@* - The picture SpringBoard keeps of an application that leaves the screen (for the application* switcher and the next launch) is saved as JPEG or PNG, not as an ASTC texture: see* snapshot_output_format().+ * - Where CoreAnimation draws with its software renderer (QEMU; the phone without gpu=1) the+ * "vibrant" views draw their content as it is: see plain_vibrancy().* - Darwin notifications as a remote control, for scripts (rwtouch notify NAME):* com.redwood.unlock what the lock screen does after "swipe up to open"+ * com.redwood.layers write down the layers SpringBoard has on the screen: see layers()*/#include <CoreFoundation/CoreFoundation.h>+#include <IOKit/IOKitLib.h>#include <dispatch/dispatch.h>#include <notify.h>#include <objc/message.h>@@ -36,7 +40,7 @@static voidsay(const char *format, ...){- char line[256];+ char line[1280];va_list ap;int n;@@ -138,6 +142,58 @@ snapshot_output_format(__unused id self, __unused SEL selector, id snapshot)return SNAPSHOT_FORMAT_PNG;}+/* ---- the lock screen's clock without a GPU ------------------------------------------------------- */++#define REDWOOD_GL "/redwood/lib/libredwood-gl.dylib"++/* Does the window server draw with OpenGL ES? The same question, asked the same way, as opengl_es() in inject.c. */+static bool+gpu_draws(void)+{+ char arguments[1024] = "";+ size_t size = sizeof(arguments) - 1;+ const char *argument;+ io_service_t gpu;++ if (access(REDWOOD_GL, R_OK) != 0) {+ return false;+ }+ if (sysctlbyname("kern.bootargs", arguments, &size, NULL, 0) == 0) {+ for (argument = arguments; (argument = strstr(argument, "gl=")) != NULL; argument += 3) {+ if (argument == arguments || argument[-1] == ' ') {+ return argument[3] != '0';+ }+ }+ }+ gpu = IOServiceGetMatchingService(0, IOServiceMatching("RedwoodGPU"));+ if (gpu != 0) {+ IOObjectRelease(gpu);+ }+ return gpu != 0;+}++/*+ * The clock of the lock screen is a "vibrant" view (BSUIVibrancyEffectView in BaseBoardUI): its+ * digits are not drawn, they are a mask -- a copy of them through a colour matrix that keeps red+ * as alpha -- through which the filter vibrantColorMatrix lets the wallpaper behind come out+ * lighter; and a gradient over the whole screen, red at the top, tones the wallpaper down the+ * same way. On the GPU that is what is seen (eagl.c draws the two filters). CoreAnimation's+ * software renderer shows neither: the digits come out red, and the top of the wallpaper as it+ * was. Why was not found out; that renderer is in QuartzCore, not here.+ * Such views have a switch, the user default BSUIVibrancyEffectViewDisabled: with it they show+ * their content as it is drawn, the clock in plain white. It is set for this run of SpringBoard+ * alone (nothing is written), and only where the software renderer draws.+ */+static void+plain_vibrancy(void)+{+ if (gpu_draws()) {+ return;+ }+ CFPreferencesSetAppValue(CFSTR("BSUIVibrancyEffectViewDisabled"), kCFBooleanTrue, kCFPreferencesCurrentApplication);+ say("redwood: SpringBoard: no GPU draws, vibrant views are plain (the lock screen's clock is white)\n");+}+/* ---- remote control ------------------------------------------------------------------------------ */#define UNLOCK_SOURCE_COVER_SHEET 24 /* what the lock screen itself passes */@@ -167,6 +223,153 @@ unlock(void)}}+/*+ * What SpringBoard has put on the screen, as CoreAnimation has it: every layer of every window, a+ * line each -- class and name, place, opacity, what it shows (an image, a colour, another+ * process's layers), and what is done to it: its filters by type with their inputs, in order,+ * the compositing filter, the mask. That is where a picture that comes out wrong on one renderer+ * and right on another is described: the same description goes to both.+ */+#define SEND(type, object, name) ((type (*)(id, SEL))objc_msgSend)((id)(object), sel_registerName(name))+#define SEND1(type, object, name, argument_type, argument) \+ ((type (*)(id, SEL, argument_type))objc_msgSend)((id)(object), sel_registerName(name), argument)++static const char *+text_of(id object)+{+ id text = object ? SEND(id, object, "description") : NULL;++ return text ? SEND(const char *, text, "UTF8String") : "-";+}++static void+layer_filter(id filter, const char *what, int depth)+{+ static const char *const inputs[] = { "inputColorMatrix", "inputRadius", "inputAmount", "inputColor", "inputAngle",+ "inputPremultipliedValues", "inputNormalizeEdges", "inputReversed" };+ char line[1024];+ size_t n;++ if (!class_respondsToSelector(object_getClass(filter), sel_registerName("type"))) {+ say("redwood: layers: %*s %s %s\n", 2 * depth, "", what, text_of(filter)); /* a name alone */+ return;+ }+ n = (size_t)snprintf(line, sizeof(line), "%s %s \"%s\"%s", what, text_of(SEND(id, filter, "type")),+ text_of(SEND(id, filter, "name")), SEND(BOOL, filter, "isEnabled") ? "" : " (disabled)");+ for (size_t i = 0; i < sizeof(inputs) / sizeof(inputs[0]) && n < sizeof(line); i++) {+ id key = SEND1(id, objc_getClass("NSString"), "stringWithUTF8String:", const char *, inputs[i]);+ id value = SEND1(id, filter, "valueForKey:", id, key);+ float m[20];++ if (value == NULL) {+ continue;+ }+ if (i == 0 && class_respondsToSelector(object_getClass(value), sel_registerName("CAColorMatrixValue"))) {+ SEND1(void, value, "getValue:", void *, m);+ n += (size_t)snprintf(line + n, sizeof(line) - n, " %s [%.3g %.3g %.3g %.3g %.3g | %.3g %.3g %.3g %.3g %.3g | "+ "%.3g %.3g %.3g %.3g %.3g | %.3g %.3g %.3g %.3g %.3g]", inputs[i], m[0], m[1], m[2], m[3], m[4], m[5], m[6],+ m[7], m[8], m[9], m[10], m[11], m[12], m[13], m[14], m[15], m[16], m[17], m[18], m[19]);+ } else {+ n += (size_t)snprintf(line + n, sizeof(line) - n, " %s %s", inputs[i], text_of(value));+ }+ }+ say("redwood: layers: %*s %s\n", 2 * depth, "", line);+}++static void+layer_line(id layer, const char *role, int depth)+{+ struct { double x, y, w, h; } frame = SEND(typeof(frame), layer, "frame");+ const char *class_name = object_getClassName(layer);+ id contents = SEND(id, layer, "contents"), filters = SEND(id, layer, "filters"), mask = SEND(id, layer, "mask");+ id compositing = SEND(id, layer, "compositingFilter"), sublayers = SEND(id, layer, "sublayers");+ id background = SEND(id, layer, "backgroundFilters");+ void *colour = SEND(void *, layer, "backgroundColor");+ char more[512] = "";+ size_t n = 0;++ if (SEND(BOOL, layer, "isHidden")) {+ n += (size_t)snprintf(more + n, sizeof(more) - n, " HIDDEN");+ }+ if (contents != NULL) {+ id text = (id)CFCopyDescription((CFTypeRef)contents);++ n += (size_t)snprintf(more + n, sizeof(more) - n, " contents %.60s", text_of(text));+ CFRelease((CFTypeRef)text);+ }+ if (contents != NULL && class_respondsToSelector(object_getClass(layer), sel_registerName("contentsMultiplyColor")) &&+ SEND(void *, layer, "contentsMultiplyColor") != NULL) {+ id text = (id)CFCopyDescription(SEND(void *, layer, "contentsMultiplyColor"));+ const char *numbers = strstr(text_of(text), "( ");++ n += (size_t)snprintf(more + n, sizeof(more) - n, " times %.40s", numbers ? numbers : "?");+ CFRelease((CFTypeRef)text);+ }+ if (colour != NULL) {+ id text = (id)CFCopyDescription(colour);+ const char *numbers = strstr(text_of(text), "( ");++ n += (size_t)snprintf(more + n, sizeof(more) - n, " colour %.40s", numbers ? numbers : "?");+ CFRelease((CFTypeRef)text);+ }+ if (strcmp(class_name, "CAPortalLayer") == 0) {+ n += (size_t)snprintf(more + n, sizeof(more) - n, " PORTAL of %p%s%s", (void *)SEND(id, layer, "sourceLayer"),+ SEND(BOOL, layer, "hidesSourceLayer") ? " (hides it)" : "", SEND(BOOL, layer, "matchesOpacity") ? " (its opacity)" : "");+ } else if (strcmp(class_name, "CABackdropLayer") == 0) {+ n += (size_t)snprintf(more + n, sizeof(more) - n, " BACKDROP group \"%s\" scale %g%s", text_of(SEND(id, layer, "groupName")),+ SEND(double, layer, "scale"), SEND(BOOL, layer, "captureOnly") ? " (capture only)" : "");+ } else if (strcmp(class_name, "CAGradientLayer") == 0) {+ struct { double x, y; } from = SEND(typeof(from), layer, "startPoint"), to = SEND(typeof(to), layer, "endPoint");+ id colours = SEND(id, layer, "colors");++ n += (size_t)snprintf(more + n, sizeof(more) - n, " GRADIENT %s from %g,%g to %g,%g at %.40s:", text_of(SEND(id, layer, "type")),+ from.x, from.y, to.x, to.y, text_of(SEND(id, layer, "locations")));+ for (long i = 0; colours != NULL && i < SEND(long, colours, "count") && n < sizeof(more); i++) {+ id text = (id)CFCopyDescription((CFTypeRef)SEND1(id, colours, "objectAtIndex:", long, i));+ const char *numbers = strstr(text_of(text), "( ");++ n += (size_t)snprintf(more + n, sizeof(more) - n, " %.30s", numbers ? numbers : "?");+ CFRelease((CFTypeRef)text);+ }+ } else if (strcmp(class_name, "CALayerHost") == 0) {+ n += (size_t)snprintf(more + n, sizeof(more) - n, " HOST of context %#x", SEND(unsigned, layer, "contextId"));+ }+ say("redwood: layers: %*s%s%s %p \"%s\" %g,%g %gx%g opacity %g%s\n", 2 * depth, "", role, class_name, (void *)layer,+ text_of(SEND(id, layer, "name")), frame.x, frame.y, frame.w, frame.h, (double)SEND(float, layer, "opacity"), more);+ for (long i = 0; filters != NULL && i < SEND(long, filters, "count"); i++) {+ layer_filter(SEND1(id, filters, "objectAtIndex:", long, i), "filter", depth);+ }+ for (long i = 0; background != NULL && i < SEND(long, background, "count"); i++) {+ layer_filter(SEND1(id, background, "objectAtIndex:", long, i), "background filter", depth);+ }+ if (compositing != NULL) {+ layer_filter(compositing, "compositing filter", depth);+ }+ if (mask != NULL) {+ layer_line(mask, "MASK ", depth + 1);+ }+ for (long i = 0; sublayers != NULL && i < SEND(long, sublayers, "count"); i++) {+ layer_line(SEND1(id, sublayers, "objectAtIndex:", long, i), "", depth + 1);+ }+}++static void+layers(void)+{+ Class window = objc_getClass("UIWindow");+ SEL all = sel_registerName("allWindowsIncludingInternalWindows:onlyVisibleWindows:");+ id windows = window && class_getClassMethod(window, all) ? ((id (*)(Class, SEL, BOOL, BOOL))objc_msgSend)(window, all, 1, 1) : NULL;++ say("redwood: layers: %ld windows\n", windows ? SEND(long, windows, "count") : 0L);+ for (long i = 0; windows != NULL && i < SEND(long, windows, "count"); i++) {+ id w = SEND1(id, windows, "objectAtIndex:", long, i);++ say("redwood: layers: window %s level %g\n", object_getClassName(w), SEND(double, w, "windowLevel"));+ layer_line(SEND(id, w, "layer"), "", 1);+ }+ say("redwood: layers: end\n");+}+__attribute__((constructor))static voidredwood_springboard_init(void)@@ -185,6 +388,7 @@ redwood_springboard_init(void)"_setSetupRequiredReason:", 0x1c4cdd3a4UL, (IMP)set_setup_required_reason);snapshot_format = replace_method_of_kind('+', "XBApplicationSnapshotManifestImpl", "_outputFormatForSnapshot:",0x1f1c91480UL, (IMP)snapshot_output_format);+ plain_vibrancy();say("redwood: SpringBoard: activation %s, setup assistant %s, application snapshots %s\n",activation ? "answered here" : "NOT replaced", original_set_setup_required_reason ? "refused" : "NOT replaced",snapshot_format ? "as JPEG" : "NOT changed");@@ -201,4 +405,7 @@ redwood_springboard_init(void)notify_register_dispatch("com.redwood.unlock", &token, dispatch_get_main_queue(), ^(__unused int t) {unlock();});+ notify_register_dispatch("com.redwood.layers", &token, dispatch_get_main_queue(), ^(__unused int t) {+ layers();+ });}