Skip to content

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 switcher of running applications: a scenario that reaches it, and where the purple comes from

vcvkk33054e500378
diff --git a/userland/rc.jobs.switcher b/userland/rc.jobs.switcher
index a48358d..63f1091 100644
--- a/userland/rc.jobs.switcher
+++ b/userland/rc.jobs.switcher
@@ -1,10 +1,12 @@
# Commands run by the launchd job com.redwood.demo (see com.redwood.demo.plist).
# The switcher of running applications (RC_JOBS=rc.jobs.switcher, gpu=1): three applications are
-# started one after another, the first two left running by the home button and the third kept on
-# the screen, and then SpringBoard is asked to open the switcher, where the cards behind the front
-# one are dimmed. Those of the two on the left came out purple instead. (Neither a drag up from
-# the bottom edge nor two presses of the home button opens it: the touches put in here do not
-# reach iOS's system gestures, and the home button only goes home. See switcher() in inject_sb.c.)
+# started one after another (ones that ask nothing: an application that puts up a question of its
+# own -- Photos asks about notifications -- leaves a modal alert on the screen, and with one of
+# those up iOS opens no switcher at all), the first two left running by the home button and the
+# third kept on the screen; then a drag up from the bottom edge that stops a third of the way and
+# waits opens the switcher, where the cards behind the front one are dimmed. Those of the two on
+# the left came out purple instead. (If the drag brings nothing, the notification asks SpringBoard
+# itself: see switcher() in inject_sb.c.)
# The first minute and a half after the boot the four cores are busy with the start-up's own work
# and an application started then takes much longer than it should (see rc.jobs.fps): the taps
# wait for it to be over.
@@ -12,5 +14,6 @@
/redwood/bin/rwtouch wait 25 swipe 0.5 0.985 0.5 0.3 200 wait 70
/redwood/bin/rwtouch tap 0.151 0.358 wait 20 button home wait 8
/redwood/bin/rwtouch tap 0.383 0.358 wait 20 button home wait 8
-/redwood/bin/rwtouch tap 0.614 0.358 wait 20
-/redwood/bin/rwtouch notify com.redwood.switcher wait 45
+/redwood/bin/rwtouch tap 0.614 0.481 wait 20
+/redwood/bin/rwtouch drag 0.5 0.995 0.5 0.62 600 2500 wait 8
+/redwood/bin/rwtouch notify com.redwood.layers wait 30
diff --git a/userland/src/eagl.c b/userland/src/eagl.c
index 411a4ad..d89c4b1 100644
--- a/userland/src/eagl.c
+++ b/userland/src/eagl.c
@@ -270,6 +270,8 @@ struct eagl {
GLint group_blend_func[4];
GLuint box; /* and one that makes a picture eight times smaller */
GLint box_matrix, box_places;
+ GLuint blur4; /* and for the four samples of a shadow's blur (blur4_fragment) */
+ GLint blur4_matrix, blur4_places;
GLuint halve, vblur; /* and two for the blur whose radius varies (vblur_level(), vblur_draw_begin()) */
GLint halve_texel, vblur_matrix, vblur_radius, vblur_levels, vblur_normalize, vblur_paint;
struct vblur_chain {
@@ -1457,6 +1459,10 @@ trace_placed_draw(struct eagl *e, GLenum mode, GLenum type, const void *indices,
char textures[160] = "";
size_t used = 0;
+ if (trace_shaders) {
+ trace_program(e); /* (gltrace_shaders=1: the text of each program as it first draws here) */
+ }
+
if (e->arrays[0].pointer == NULL || e->arrays[0].type != GL_FLOAT) {
return;
}
@@ -1656,6 +1662,7 @@ static const char table_fragment[] =
#define FUNCTION_DOWNSAMPLE_8 28
#define FUNCTION_VARIABLE_DOWNSAMPLE 38
#define FUNCTION_VARIABLE_BLUR 39
+#define FUNCTION_SHADOW_BLUR 40
#define FUNCTION_VIBRANT_MATRIX 45
static const char vibrant_fragment[] =
@@ -1703,6 +1710,29 @@ static const char masking_fragment[] =
* on a picture too dark: the minus came out stained with what was behind it instead of the
* light grey it is on a phone.
*/
+/*
+ * "sb3" (40): four samples around a point, averaged -- the same four places as "ds4" is given,
+ * one pixel out each way, with no weights of its own. It is asked for where a shadow is laid
+ * over what is behind it (the cards of the switcher of running applications) and in the home
+ * screen's edit mode. CoreAnimation's OpenGL ES renderer has no shader for it and, unlike the
+ * ones it never asks about, it asks and is told no -- and then what needs it is not drawn at
+ * all, so the shadow is missing. This waits for a way to hand CoreAnimation a program where it
+ * looks for one: answering that the renderer has the function (src/inject.c, glyes=40) only
+ * kills the window server, and no draw with no program ever arrives here (see there).
+ */
+static const char blur4_fragment[] =
+ "#version 300 es\n"
+ "uniform lowp sampler2D texture0;\n"
+ "uniform highp vec2 places[4];\n"
+ "in lowp vec4 color;\n"
+ "in highp vec2 texcoord;\n"
+ "out lowp vec4 result;\n"
+ "void main() {\n"
+ " highp vec2 middle = texcoord / vec2(textureSize(texture0, 0));\n"
+ " result = .25 * (texture(texture0, middle + places[0]) + texture(texture0, middle + places[1]) +\n"
+ " texture(texture0, middle + places[2]) + texture(texture0, middle + places[3]));\n"
+ "}\n";
+
static const char box_fragment[] =
"#version 300 es\n"
"uniform lowp sampler2D texture0;\n"
@@ -1720,6 +1750,25 @@ static const char box_fragment[] =
" result = sum * .0625;\n"
"}\n";
+static int function_numbers; /* boot-arg glnumbers=1 */
+
+/* Four of a function's numbers at a time, for the line above (one of a few buffers in turn). */
+static const char *
+number_text(const float *values, size_t from, size_t count)
+{
+ static char texts[5][80];
+ static unsigned which;
+ char *text = texts[which++ % (sizeof(texts) / sizeof(texts[0]))];
+
+ if (from >= count) {
+ return "";
+ }
+ snprintf(text, sizeof(texts[0]), " [%g %g %g %g]", (double)values[from],
+ from + 1 < count ? (double)values[from + 1] : 0.0, from + 2 < count ? (double)values[from + 2] : 0.0,
+ from + 3 < count ? (double)values[from + 3] : 0.0);
+ return text;
+}
+
static void *ca_context; /* CoreAnimation's GLContext */
static GLfloat function_values[90][20];
static uint8_t function_given[90];
@@ -1734,13 +1783,18 @@ redwood_gl_function_values(void *context, unsigned function, unsigned index, siz
if (function >= 90 || index != 0 || components * count > 20) {
return;
}
+ /* (boot-arg glnumbers=1: every set of numbers a function is given that is not the one before,
+ up to a dozen of them -- the same function serves many a layer, with a matrix of its own) */
+ if (!said[function] || (function_numbers && said[function] < 12 &&
+ memcmp(function_values[function], values, components * count * sizeof(values[0])) != 0)) {
+ said[function]++;
+ say("redwood-gl: CoreAnimation gives its function %u numbers: %zu of %zu:%s%s%s%s%s%s%s%s%s%s\n", function, count,
+ components, number_text(values, 0, components * count), number_text(values, 4, components * count),
+ number_text(values, 8, components * count), number_text(values, 12, components * count),
+ number_text(values, 16, components * count), "", "", "", "", "");
+ }
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 */
@@ -2114,13 +2168,14 @@ plain_program(const char *fragment, const char *what)
* in those seconds (which is what tells the screens of a scenario apart); and with that the
* count of each since the start.
*/
-enum { CENSUS_NOT_DRAWN, CENSUS_PLAIN, CENSUS_TABLE, CENSUS_VIBRANT, CENSUS_MASKING, CENSUS_BOX, CENSUS_LEVEL, CENSUS_VBLUR,
- CENSUS_KINDS };
+enum { CENSUS_NOT_DRAWN, CENSUS_PLAIN, CENSUS_TABLE, CENSUS_VIBRANT, CENSUS_MASKING, CENSUS_BOX, CENSUS_BLUR4, CENSUS_LEVEL,
+ CENSUS_VBLUR, CENSUS_KINDS };
static const char *const census_kinds[CENSUS_KINDS] = {
"NOT DRAWN (no program, and no texture, or nothing of ours to draw it with, or it would read what it writes)", "drawn as the picture it is given (colour times texture)",
"drawn through a table (ours, for the home indicator)", "drawn with our program for a colour matrix over what is behind",
"drawn with our program for a colour matrix over premultiplied pixels",
"drawn with our program that makes a picture eight times smaller",
+ "drawn with our program that averages four samples around a point (a shadow's blur)",
"made into a level of ours, half the size of the one before (a blur whose radius varies)",
"drawn with our program that reads the levels by the mask (a blur whose radius varies)",
};
@@ -2829,6 +2884,24 @@ plain_draw_begin(struct eagl *e, GLint enabled[4])
return true;
}
}
+ if (e->bound[0] != 0 && plain_draws != 3 && function == FUNCTION_SHADOW_BLUR && function_given[function] == 8) {
+ if (e->blur4 == 0) {
+ e->blur4 = plain_program(blur4_fragment, "four samples around a point");
+ e->blur4_matrix = glGetUniformLocation(e->blur4, "vertex_matrix");
+ e->blur4_places = glGetUniformLocation(e->blur4, "places");
+ }
+ census_draw(e, function, CENSUS_BLUR4);
+ glUseProgram(e->blur4);
+ glUniformMatrix4fv(e->blur4_matrix, 1, 0, e->matrix != NULL ? e->matrix : identity);
+ glUniform2fv(e->blur4_places, 4, function_values[function]);
+ 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 && plain_draws != 3 && function == FUNCTION_DOWNSAMPLE_8 && function_given[function] == 8) {
if (e->box == 0) {
e->box = plain_program(box_fragment, "eight times smaller, sixteen samples");
@@ -3829,6 +3902,7 @@ install(void)
trace_lit = strstr(arguments, "gltrace_lit=1") != NULL;
trace_look = strstr(arguments, "gltrace_look=1") != NULL;
trace_shaders = strstr(arguments, "gltrace_shaders=1") != NULL;
+ function_numbers = strstr(arguments, "glnumbers=1") != NULL;
trace_uniforms_on = strstr(arguments, "gltrace_uniforms=1") != NULL;
if ((argument = strstr(arguments, "gltrace_corners=")) != NULL) {
trace_corners = (GLsizei)strtol(argument + 16, NULL, 10);
diff --git a/userland/src/inject.c b/userland/src/inject.c
index 2f318ce..2982639 100644
--- a/userland/src/inject.c
+++ b/userland/src/inject.c
@@ -227,14 +227,36 @@ static int (*orig_function_supported)(void *context);
* For finding out what a missing function is for: with it the draw is made, its numbers arrive
* (function_uniform below), and the picture says whether the thing was that function's.
*/
+/*
+ * Saying yes to a function the renderer has no shader for is not enough and not safe. Told yes for
+ * "sb3" (40) -- the four samples of a shadow's blur, which our OpenGL ES library has a stand-in for
+ * (eagl.c, blur4_fragment) -- CoreAnimation takes the way of one it has a shader for, finds none,
+ * and the window server dies; it came back every half a minute, with SpringBoard after it, and the
+ * stand-in was never reached: a function it asks about and is told yes to is not one it draws with
+ * no program. What is needed is to hand it a program where it looks for one, which is another
+ * entry of the same table. Until then it is told the truth, and what needs that function is not
+ * drawn -- the shadow under a card of the switcher of running applications.
+ */
static uint8_t say_yes[90];
static void
functions_said_yes(const char *arguments)
{
static const char names[] = REDWOOD_CA_FUNCTIONS;
- const char *argument = strstr(arguments, "glyes=");
+ const char *argument = strstr(arguments, "glno=");
+ /* glno=N[,N...]: and the other way about, for seeing what a function of ours stands in for */
+ for (argument = argument != NULL ? argument + 5 : NULL; argument != NULL && *argument >= '0' && *argument <= '9';) {
+ unsigned function = (unsigned)strtoul(argument, (char **)&argument, 10);
+
+ if (function < 90) {
+ say_yes[function] = 0;
+ say("redwood: the renderer will not answer that it has CoreAnimation's function %u (\"%.3s\")\n",
+ function, names + 4 * function);
+ }
+ argument = *argument == ',' ? argument + 1 : NULL;
+ }
+ argument = strstr(arguments, "glyes=");
for (argument = argument != NULL ? argument + 6 : NULL; argument != NULL && *argument >= '0' && *argument <= '9';) {
unsigned function = (unsigned)strtoul(argument, (char **)&argument, 10);
@@ -255,10 +277,10 @@ my_function_supported(void *context)
int supported = orig_function_supported(context);
uint8_t function = *(*(uint8_t **)((char *)context + 0x10) + 0x10);
- if (!supported && function < 90 && say_yes[function]) {
+ if (!supported && function < 90 && say_yes[function] && gl_loaded) {
if (!said[function]) {
said[function] = 1;
- say("redwood: CoreAnimation's function %u (\"%.3s\"): the renderer says it has it (glyes)\n",
+ say("redwood: CoreAnimation's function %u (\"%.3s\"): the renderer is made to say it has it\n",
function, names + 4 * function);
}
return 1;