Skip to content

ui: fill the bg with disengaged color if no frame #35451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions selfdrive/ui/onroad/augmented_road_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class AugmentedRoadView(CameraView):
def __init__(self, stream_type: VisionStreamType = VisionStreamType.VISION_STREAM_ROAD):
super().__init__("camerad", stream_type)
self._set_placeholder_color(BORDER_COLORS[UIStatus.DISENGAGED])

self.device_camera: DeviceCameraConfig | None = None
self.view_from_calib = view_frame_from_device_frame.copy()
Expand Down
12 changes: 12 additions & 0 deletions selfdrive/ui/onroad/cameraview.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def __init__(self, name: str, stream_type: VisionStreamType):
self.egl_images: dict[int, EGLImage] = {}
self.egl_texture: rl.Texture | None = None

self._placeholder_color : rl.Color | None = None

# Initialize EGL for zero-copy rendering on TICI
if TICI:
if not init_egl():
Expand All @@ -84,6 +86,10 @@ def __init__(self, name: str, stream_type: VisionStreamType):
self.egl_texture = rl.load_texture_from_image(temp_image)
rl.unload_image(temp_image)

def _set_placeholder_color(self, color: rl.Color):
"""Set a placeholder color to be drawn when no frame is available."""
self._placeholder_color = color

def switch_stream(self, stream_type: VisionStreamType) -> None:
if self._stream_type != stream_type:
cloudlog.debug(f'switching stream from {self._stream_type} to {stream_type}')
Expand Down Expand Up @@ -130,6 +136,7 @@ def _calc_frame_matrix(self, rect: rl.Rectangle) -> np.ndarray:

def render(self, rect: rl.Rectangle):
if not self._ensure_connection():
self._draw_placeholder(rect)
return

# Try to get a new buffer without blocking
Expand All @@ -139,6 +146,7 @@ def render(self, rect: rl.Rectangle):
self.frame = buffer

if not self.frame:
self._draw_placeholder(rect)
return

transform = self._calc_frame_matrix(rect)
Expand All @@ -163,6 +171,10 @@ def render(self, rect: rl.Rectangle):
else:
self._render_textures(src_rect, dst_rect)

def _draw_placeholder(self, rect: rl.Rectangle):
if self._placeholder_color:
rl.draw_rectangle_rec(rect, self._placeholder_color)

def _render_egl(self, src_rect: rl.Rectangle, dst_rect: rl.Rectangle) -> None:
"""Render using EGL for direct buffer access"""
if self.frame is None or self.egl_texture is None:
Expand Down
Loading