optimize transite_to_layer: skip the next frame if it is too slow in each loop

This commit is contained in:
Vincent Wei
2021-04-30 17:13:58 +08:00
parent 44bb22925f
commit e3e79aaf86

View File

@@ -1135,14 +1135,17 @@ static void transit_to_layer (CompositorCtxt* ctxt, MG_Layer* to_layer)
_DBG_PRINTF ("cp.percent: %f, cp.scale: %f\n", cp.percent, cp.scale);
t_ms = composite_layers (ctxt, layers, 2, &cp);
if (t_ms > 50)
if (t_ms >= 20) {
_WRN_PRINTF ("Too slow to composite layers: %u\n", t_ms);
cp.scale -= 0.04f;
}
else {
usleep ((20 - t_ms) * 1000);
cp.scale -= 0.02f;
}
total_time_ms += t_ms;
total_times++;
usleep (10 * 1000);
cp.scale -= 0.02f;
}
// Step 2) Move to the new topmost layer
@@ -1155,14 +1158,17 @@ static void transit_to_layer (CompositorCtxt* ctxt, MG_Layer* to_layer)
_DBG_PRINTF ("cp.percent: %f, cp.scale: %f\n", cp.percent, cp.scale);
t_ms = composite_layers (ctxt, layers, 2, &cp);
if (t_ms > 50)
if (t_ms >= 20) {
_WRN_PRINTF ("Too slow to composite layers: %u\n", t_ms);
cp.percent -= 9.0f;
}
else {
usleep ((20 - t_ms) * 1000);
cp.percent -= 4.5f;
}
total_time_ms += t_ms;
total_times++;
usleep (20 * 1000);
cp.percent -= 4.5f;
}
// Step 3) Zoom in the new topmost layer
@@ -1175,14 +1181,17 @@ static void transit_to_layer (CompositorCtxt* ctxt, MG_Layer* to_layer)
_DBG_PRINTF ("cp.percent: %f, cp.scale: %f\n", cp.percent, cp.scale);
t_ms = composite_layers (ctxt, layers, 2, &cp);
if (t_ms > 50)
if (t_ms >= 20) {
_WRN_PRINTF ("Too slow to composite layers: %u\n", t_ms);
cp.scale += 0.04f;
}
else {
usleep ((20 - t_ms) * 1000);
cp.scale += 0.02f;
}
total_time_ms += t_ms;
total_times++;
usleep (10 * 1000);
cp.scale += 0.02f;
}
}
else {
@@ -1198,14 +1207,17 @@ static void transit_to_layer (CompositorCtxt* ctxt, MG_Layer* to_layer)
_DBG_PRINTF ("cp.percent: %f, cp.scale: %f\n", cp.percent, cp.scale);
t_ms = composite_layers (ctxt, layers, 2, &cp);
if (t_ms > 50)
if (t_ms >= 20) {
_WRN_PRINTF ("Too slow to composite layers: %u\n", t_ms);
cp.scale -= 0.04f;
}
else {
usleep ((20 - t_ms) * 1000);
cp.scale -= 0.02f;
}
total_time_ms += t_ms;
total_times++;
usleep (10 * 1000);
cp.scale -= 0.02f;
}
// Step 2) Move the current topmost layer
@@ -1217,14 +1229,17 @@ static void transit_to_layer (CompositorCtxt* ctxt, MG_Layer* to_layer)
_DBG_PRINTF ("cp.percent: %f, cp.scale: %f\n", cp.percent, cp.scale);
t_ms = composite_layers (ctxt, layers, 2, &cp);
if (t_ms > 50)
if (t_ms >= 20) {
_WRN_PRINTF ("Too slow to composite layers: %u\n", t_ms);
cp.percent += 9.0f;
}
else {
usleep ((20 - t_ms) * 1000);
cp.percent += 4.5f;
}
total_time_ms += t_ms;
total_times++;
usleep (20 * 1000);
cp.percent += 4.5f;
}
// Step 3) Zoom in the new topmost layer
@@ -1237,14 +1252,17 @@ static void transit_to_layer (CompositorCtxt* ctxt, MG_Layer* to_layer)
_DBG_PRINTF ("cp.percent: %f, cp.scale: %f\n", cp.percent, cp.scale);
t_ms = composite_layers (ctxt, layers, 2, &cp);
if (t_ms > 50)
if (t_ms >= 20) {
_WRN_PRINTF ("Too slow to composite layers: %u\n", t_ms);
cp.scale += 0.04f;
}
else {
usleep ((20 - t_ms) * 1000);
cp.scale += 0.02f;
}
total_time_ms += t_ms;
total_times++;
usleep (10 * 1000);
cp.scale += 0.02f;
}
}