UI cleanup + startup time improvement (#2295)

old-commit-hash: 671183184b
commatwo_master
Adeeb Shihadeh 5 years ago committed by GitHub
parent 9589d518a2
commit 51d59aefca
  1. 13
      common/apk.py
  2. 3
      selfdrive/assets/img_comma.png
  3. 57
      selfdrive/ui/paint.cc
  4. 17
      selfdrive/ui/ui.hpp

@ -3,6 +3,7 @@ import subprocess
import glob import glob
import hashlib import hashlib
import shutil import shutil
import threading
from common.basedir import BASEDIR from common.basedir import BASEDIR
from selfdrive.swaglog import cloudlog from selfdrive.swaglog import cloudlog
@ -27,8 +28,10 @@ def install_apk(path):
return ret == 0 return ret == 0
def start_offroad(): def start_offroad():
set_package_permissions() def f():
system("am start -n ai.comma.plus.offroad/.MainActivity") set_package_permissions()
system("am start -n ai.comma.plus.offroad/.MainActivity")
threading.Thread(target=f).start()
def set_package_permissions(): def set_package_permissions():
pm_grant("ai.comma.plus.offroad", "android.permission.ACCESS_FINE_LOCATION") pm_grant("ai.comma.plus.offroad", "android.permission.ACCESS_FINE_LOCATION")
@ -90,8 +93,10 @@ def update_apks():
assert success assert success
def pm_apply_packages(cmd): def pm_apply_packages(cmd):
for p in android_packages: def f():
system("pm %s %s" % (cmd, p)) for p in android_packages:
system("pm %s %s" % (cmd, p))
threading.Thread(target=f).start()
if __name__ == "__main__": if __name__ == "__main__":
update_apks() update_apks()

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bc951a4f1e65bf2eab8cfb7e6c25a193520e6fe860bcca973fbc792a6b7a544d
size 11250

@ -18,12 +18,12 @@ extern "C"{
// TODO: this is also hardcoded in common/transformations/camera.py // TODO: this is also hardcoded in common/transformations/camera.py
// TODO: choose based on frame input size // TODO: choose based on frame input size
#ifdef QCOM2 #ifdef QCOM2
const mat3 intrinsic_matrix = (mat3){{ const mat3 intrinsic_matrix = (mat3){{
2648.0, 0.0, 1928.0/2, 2648.0, 0.0, 1928.0/2,
0.0, 2648.0, 1208.0/2, 0.0, 2648.0, 1208.0/2,
0.0, 0.0, 1.0 0.0, 0.0, 1.0
}}; }};
#else #else
const mat3 intrinsic_matrix = (mat3){{ const mat3 intrinsic_matrix = (mat3){{
910., 0., 582., 910., 0., 582.,
@ -32,14 +32,6 @@ const mat3 intrinsic_matrix = (mat3){{
}}; }};
#endif #endif
const uint8_t alert_colors[][4] = {
[STATUS_OFFROAD] = {0x07, 0x23, 0x39, 0xf1},
[STATUS_DISENGAGED] = {0x17, 0x33, 0x49, 0xc8},
[STATUS_ENGAGED] = {0x17, 0x86, 0x44, 0xf1},
[STATUS_WARNING] = {0xDA, 0x6F, 0x25, 0xf1},
[STATUS_ALERT] = {0xC9, 0x22, 0x31, 0xf1},
};
// Projects a point in car to space to the corresponding point in full frame // Projects a point in car to space to the corresponding point in full frame
// image space. // image space.
vec3 car_space_to_full_frame(const UIState *s, vec4 car_space_projective) { vec3 car_space_to_full_frame(const UIState *s, vec4 car_space_projective) {
@ -233,13 +225,13 @@ static void ui_draw_track(UIState *s, bool is_mpc, track_vertices_data *pvd) {
NVGpaint track_bg; NVGpaint track_bg;
if (is_mpc) { if (is_mpc) {
// Draw colored MPC track // Draw colored MPC track
const Color clr = bg_colors[s->status]; const NVGcolor clr = bg_colors[s->status];
track_bg = nvgLinearGradient(s->vg, s->fb_w, s->fb_h, s->fb_w, s->fb_h*.4, track_bg = nvgLinearGradient(s->vg, s->fb_w, s->fb_h, s->fb_w, s->fb_h*.4,
nvgRGBA(clr.r, clr.g, clr.b, 255), nvgRGBA(clr.r, clr.g, clr.b, 255/2)); nvgRGBA(clr.r, clr.g, clr.b, 255), nvgRGBA(clr.r, clr.g, clr.b, 255/2));
} else { } else {
// Draw white vision track // Draw white vision track
track_bg = nvgLinearGradient(s->vg, s->fb_w, s->fb_h, s->fb_w, s->fb_h*.4, track_bg = nvgLinearGradient(s->vg, s->fb_w, s->fb_h, s->fb_w, s->fb_h*.4,
COLOR_WHITE, COLOR_WHITE_ALPHA(0)); COLOR_WHITE, COLOR_WHITE_ALPHA(0));
} }
nvgFillPaint(s->vg, track_bg); nvgFillPaint(s->vg, track_bg);
nvgFill(s->vg); nvgFill(s->vg);
@ -443,23 +435,14 @@ static void ui_draw_vision_event(UIState *s) {
// draw winding road sign // draw winding road sign
const int img_turn_size = 160*1.5; const int img_turn_size = 160*1.5;
ui_draw_image(s->vg, viz_event_x - (img_turn_size / 4), viz_event_y + bdr_s - 25, img_turn_size, img_turn_size, s->img_turn, 1.0f); ui_draw_image(s->vg, viz_event_x - (img_turn_size / 4), viz_event_y + bdr_s - 25, img_turn_size, img_turn_size, s->img_turn, 1.0f);
} else { } else if (s->scene.controls_state.getEngageable()) {
// draw steering wheel // draw steering wheel
const int bg_wheel_size = 96; const int bg_wheel_size = 96;
const int bg_wheel_x = viz_event_x + (viz_event_w-bg_wheel_size); const int bg_wheel_x = viz_event_x + (viz_event_w-bg_wheel_size);
const int bg_wheel_y = viz_event_y + (bg_wheel_size/2); const int bg_wheel_y = viz_event_y + (bg_wheel_size/2);
NVGcolor color = COLOR_BLACK_ALPHA(0); const NVGcolor color = bg_colors[s->status];
if (s->status == STATUS_ENGAGED) {
color = nvgRGBA(23, 134, 68, 255);
} else if (s->status == STATUS_WARNING) {
color = COLOR_OCHRE;
} else {
color = nvgRGBA(23, 51, 73, 255);
}
if (s->scene.controls_state.getEngageable()){ ui_draw_circle_image(s->vg, bg_wheel_x, bg_wheel_y, bg_wheel_size, s->img_wheel, color, 1.0f, bg_wheel_y - 25);
ui_draw_circle_image(s->vg, bg_wheel_x, bg_wheel_y, bg_wheel_size, s->img_wheel, color, 1.0f, bg_wheel_y - 25);
}
} }
} }
@ -541,7 +524,7 @@ static void ui_draw_vision_footer(UIState *s) {
ui_draw_vision_face(s); ui_draw_vision_face(s);
} }
void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size, int va_color, void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size, UIStatus va_color,
const char* va_text1, const char* va_text2) { const char* va_text1, const char* va_text2) {
static std::map<cereal::ControlsState::AlertSize, const int> alert_size_map = { static std::map<cereal::ControlsState::AlertSize, const int> alert_size_map = {
{cereal::ControlsState::AlertSize::NONE, 0}, {cereal::ControlsState::AlertSize::NONE, 0},
@ -552,7 +535,8 @@ void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size,
const UIScene *scene = &s->scene; const UIScene *scene = &s->scene;
bool longAlert1 = strlen(va_text1) > 15; bool longAlert1 = strlen(va_text1) > 15;
const uint8_t *color = alert_colors[va_color]; NVGcolor color = bg_colors[va_color];
color.a *= s->alert_blinking_alpha;
int alr_s = alert_size_map[va_size]; int alr_s = alert_size_map[va_size];
const int alr_x = scene->viz_rect.x - bdr_s; const int alr_x = scene->viz_rect.x - bdr_s;
@ -560,10 +544,10 @@ void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size,
const int alr_h = alr_s+(va_size==cereal::ControlsState::AlertSize::NONE?0:bdr_s); const int alr_h = alr_s+(va_size==cereal::ControlsState::AlertSize::NONE?0:bdr_s);
const int alr_y = s->fb_h-alr_h; const int alr_y = s->fb_h-alr_h;
ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, nvgRGBA(color[0],color[1],color[2],(color[3]*s->alert_blinking_alpha))); ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, color);
NVGpaint gradient = nvgLinearGradient(s->vg, alr_x, alr_y, alr_x, alr_y+alr_h, NVGpaint gradient = nvgLinearGradient(s->vg, alr_x, alr_y, alr_x, alr_y+alr_h,
nvgRGBAf(0.0,0.0,0.0,0.05), nvgRGBAf(0.0,0.0,0.0,0.35)); nvgRGBAf(0.0,0.0,0.0,0.05), nvgRGBAf(0.0,0.0,0.0,0.35));
ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, gradient); ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, gradient);
nvgFillColor(s->vg, COLOR_WHITE); nvgFillColor(s->vg, COLOR_WHITE);
@ -589,6 +573,7 @@ void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size,
static void ui_draw_vision(UIState *s) { static void ui_draw_vision(UIState *s) {
const UIScene *scene = &s->scene; const UIScene *scene = &s->scene;
const Rect &viz_rect = scene->viz_rect; const Rect &viz_rect = scene->viz_rect;
// Draw video frames // Draw video frames
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
glViewport(viz_rect.x+scene->ui_viz_ro, viz_rect.y, s->fb_w - bdr_s*2, viz_rect.h); glViewport(viz_rect.x+scene->ui_viz_ro, viz_rect.y, s->fb_w - bdr_s*2, viz_rect.h);
@ -618,8 +603,8 @@ static void ui_draw_vision(UIState *s) {
} }
static void ui_draw_background(UIState *s) { static void ui_draw_background(UIState *s) {
const Color color = bg_colors[s->status]; const NVGcolor color = bg_colors[s->status];
glClearColor(color.r/256.0, color.g/256.0, color.b/256.0, 1.0); glClearColor(color.r, color.g, color.b, 1.0);
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
} }
@ -656,7 +641,7 @@ void ui_draw_image(NVGcontext *vg, float x, float y, float w, float h, int image
void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGcolor color, float r, int width) { void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGcolor color, float r, int width) {
nvgBeginPath(vg); nvgBeginPath(vg);
r > 0? nvgRoundedRect(vg, x, y, w, h, r) : nvgRect(vg, x, y, w, h); r > 0 ? nvgRoundedRect(vg, x, y, w, h, r) : nvgRect(vg, x, y, w, h);
if (width) { if (width) {
nvgStrokeColor(vg, color); nvgStrokeColor(vg, color);
nvgStrokeWidth(vg, width); nvgStrokeWidth(vg, width);

@ -33,7 +33,6 @@
#define COLOR_WHITE_ALPHA(x) nvgRGBA(255, 255, 255, x) #define COLOR_WHITE_ALPHA(x) nvgRGBA(255, 255, 255, x)
#define COLOR_YELLOW nvgRGBA(218, 202, 37, 255) #define COLOR_YELLOW nvgRGBA(218, 202, 37, 255)
#define COLOR_RED nvgRGBA(201, 34, 49, 255) #define COLOR_RED nvgRGBA(201, 34, 49, 255)
#define COLOR_OCHRE nvgRGBA(218, 111, 37, 255)
#define UI_BUF_COUNT 4 #define UI_BUF_COUNT 4
@ -62,10 +61,6 @@ const int TRACK_POINTS_MAX_CNT = 50 * 2;
const int SET_SPEED_NA = 255; const int SET_SPEED_NA = 255;
typedef struct Color {
uint8_t r, g, b;
} Color;
typedef enum NetStatus { typedef enum NetStatus {
NET_CONNECTED, NET_CONNECTED,
NET_DISCONNECTED, NET_DISCONNECTED,
@ -80,12 +75,12 @@ typedef enum UIStatus {
STATUS_ALERT, STATUS_ALERT,
} UIStatus; } UIStatus;
static std::map<UIStatus, Color> bg_colors = { static std::map<UIStatus, NVGcolor> bg_colors = {
{STATUS_OFFROAD, {0x07, 0x23, 0x39}}, {STATUS_OFFROAD, nvgRGBA(0x07, 0x23, 0x39, 0xf1)},
{STATUS_DISENGAGED, {0x17, 0x33, 0x49}}, {STATUS_DISENGAGED, nvgRGBA(0x17, 0x33, 0x49, 0xc8)},
{STATUS_ENGAGED, {0x17, 0x86, 0x44}}, {STATUS_ENGAGED, nvgRGBA(0x17, 0x86, 0x44, 0xf1)},
{STATUS_WARNING, {0xDA, 0x6F, 0x25}}, {STATUS_WARNING, nvgRGBA(0xDA, 0x6F, 0x25, 0xf1)},
{STATUS_ALERT, {0xC9, 0x22, 0x31}}, {STATUS_ALERT, nvgRGBA(0xC9, 0x22, 0x31, 0xf1)},
}; };
typedef struct UIScene { typedef struct UIScene {

Loading…
Cancel
Save