Skip to content

Commit 24582e0

Browse files
committed
Store display dimensions in member variables for improved frame processing
1 parent df30ef0 commit 24582e0

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

components/remote_webview/remote_webview.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ void RemoteWebView::setup() {
2727
return;
2828
}
2929

30+
display_width_ = display_->get_width();
31+
display_height_ = display_->get_height();
32+
3033
q_decode_ = xQueueCreate(cfg::decode_queue_depth, sizeof(WsMsg));
3134
ws_send_mtx_ = xSemaphoreCreateMutex();
3235

@@ -299,15 +302,12 @@ void RemoteWebView::process_frame_packet_(const uint8_t *data, size_t len)
299302
frame_bytes_ += len;
300303
frame_tiles_ += fi.tile_count;
301304

302-
const int FB_W = display_ ? display_->get_width() : 480;
303-
const int FB_H = display_ ? display_->get_height() : 480;
304-
305305
for (uint16_t i = 0; i < fi.tile_count; i++) {
306306
proto::TileHeader th{};
307307
if (!proto::parse_tile_header(data, len, th, off)) return;
308308
if (off + th.dlen > len) return;
309309

310-
if (th.w == 0 || th.h == 0 || th.w > FB_W || th.h > FB_H) {
310+
if (th.w == 0 || th.h == 0 || th.w > display_width_ || th.h > display_height_) {
311311
off += th.dlen;
312312
continue;
313313
}
@@ -317,7 +317,6 @@ void RemoteWebView::process_frame_packet_(const uint8_t *data, size_t len)
317317
}
318318

319319
off += th.dlen;
320-
taskYIELD();
321320
}
322321

323322
if (fi.flags & proto::kFlafLastOfFrame) {
@@ -408,7 +407,7 @@ bool RemoteWebView::decode_jpeg_tile_software_(int16_t dst_x, int16_t dst_y, con
408407
return false;
409408
}
410409

411-
jd_.setMaxOutputSize(4 * 2048);
410+
jd_.setMaxOutputSize(8 * 2048);
412411
jd_.setPixelType(rgb565_big_endian_ ? RGB565_BIG_ENDIAN : RGB565_LITTLE_ENDIAN);
413412

414413
const int rc = jd_.decode(dst_x, dst_y, 0);
@@ -427,21 +426,18 @@ int RemoteWebView::jpeg_draw_cb_s_(JPEGDRAW *p) {
427426

428427
int RemoteWebView::jpeg_draw_cb_(JPEGDRAW *p) {
429428
int32_t x = p->x, y = p->y, w = p->iWidth, h = p->iHeight;
430-
const int FB_W = display_->get_width();
431-
const int FB_H = display_->get_height();
432-
433-
if (x >= FB_W || y >= FB_H) return 1;
434-
if (x + w > FB_W) w = FB_W - x;
435-
if (y + h > FB_H) h = FB_H - y;
429+
430+
if (x >= display_width_ || y >= display_height_) return 1;
431+
if (x + w > display_width_) w = display_width_ - x;
432+
if (y + h > display_height_) h = display_height_ - y;
436433
if (w <= 0 || h <= 0) return 1;
437434

438-
const bool big_endian = rgb565_big_endian_;
439435
display_->draw_pixels_at(
440436
x, y, w, h,
441437
(const uint8_t *)p->pPixels,
442438
esphome::display::COLOR_ORDER_RGB,
443439
esphome::display::COLOR_BITNESS_565,
444-
big_endian
440+
rgb565_big_endian_
445441
);
446442

447443
return 1;
@@ -627,10 +623,8 @@ std::string RemoteWebView::build_ws_uri_() const {
627623
const std::string id = resolve_device_id_();
628624
append_q_str_(uri, "id", id.c_str());
629625

630-
const int W = display_ ? display_->get_width() : 0;
631-
const int H = display_ ? display_->get_height() : 0;
632-
append_q_int_(uri, "w", W);
633-
append_q_int_(uri, "h", H);
626+
append_q_int_(uri, "w", display_width_);
627+
append_q_int_(uri, "h", display_height_);
634628

635629
append_q_int_(uri, "r", rotation_);
636630
append_q_int_(uri, "ts", tile_size_);

components/remote_webview/remote_webview.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class RemoteWebView : public Component {
7171
display::Display *display_{nullptr};
7272
touchscreen::Touchscreen *touch_ = nullptr;
7373
class RemoteWebViewTouchListener *touch_listener_ = nullptr;
74+
int display_width_{0};
75+
int display_height_{0};
7476
std::string url_;
7577
std::string server_host_;
7678
std::string device_id_;

0 commit comments

Comments
 (0)