Skip to content

Commit

Permalink
feat: add show_update_regions property to HeadlessWidget to show …
Browse files Browse the repository at this point in the history
…the regions that are updated in each frame as a debug feature
  • Loading branch information
sassanh committed Oct 29, 2024
1 parent a5f6749 commit 3f41d2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- feat: divide each frame into multiple rectangles, compare rectangle with the same rectangle in the previous frame and update only the changed ones
- feat: add two throttling mechanisms to avoid sending too many frames to the display, one based on total bandwidth of all draw commands of all `HeadlessWidget`s and the other based on set fps of a particular `HeadlessWidget`
- feat: add `show_update_regions` property to `HeadlessWidget` to show the regions that are updated in each frame as a debug feature

## Version 0.11.1

Expand Down
26 changes: 24 additions & 2 deletions headless_kivy/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
from pathlib import Path
from typing import TYPE_CHECKING, ClassVar, Self

import numpy as np
from kivy.metrics import dp
from kivy.properties import BooleanProperty

from headless_kivy import config
from headless_kivy.logger import logger

if TYPE_CHECKING:
import numpy as np
from kivy.graphics.context_instructions import Color
from kivy.graphics.fbo import Fbo
from kivy.graphics.vertex_instructions import Rectangle
Expand All @@ -23,6 +24,7 @@ class DebugMixin:
fbo: Fbo
fbo_render_color: Color
fbo_render_rectangle: Rectangle
show_update_regions = BooleanProperty(0)

x: int
y: int
Expand Down Expand Up @@ -56,9 +58,29 @@ def set_debug_info(self: Self) -> None:
def render_debug_info(
self: Self,
rect_: tuple[int, int, int, int],
_: list[tuple[int, int, int, int]],
regions: list[tuple[int, int, int, int]],
data: NDArray[np.uint8],
) -> None:
if self.show_update_regions:
for rect in regions:
self.update_region_seed = (self.update_region_seed + 1) % 3
data[
rect[1] : rect[3],
rect[0] : rect[2],
:,
] = (
data[
rect[1] : rect[3],
rect[0] : rect[2],
:,
]
* 0.5
).astype(np.uint8)
data[
rect[1] : rect[3],
rect[0] : rect[2],
[(rect[0] + rect[1] + self.update_region_seed) % 7 % 3, 3],
] += 127
if config.is_debug_mode():
x1, y1, x2, y2 = rect_
self.rendered_frames += 1
Expand Down

0 comments on commit 3f41d2b

Please sign in to comment.