Skip to content

Commit

Permalink
As a result of the previous commit, we are now getting events from th…
Browse files Browse the repository at this point in the history
…e Wacom decoder at a significantly higher rate and therefore we need a quick way to deduplicate refreshes. Better alternatives would include timestamping which should be doable with low overhead since the events we get from the device actually have usec granularity timestamps
  • Loading branch information
not-avail committed Jul 3, 2018
1 parent f62cedf commit 1629c52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
30 changes: 21 additions & 9 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ extern crate libremarkable;

extern crate chrono;

extern crate atomic;

use atomic::Atomic;

use chrono::{DateTime, Local};

use std::sync::Mutex;
Expand Down Expand Up @@ -115,15 +119,22 @@ fn on_wacom_input(app: &mut appctx::ApplicationContext, input: wacom::WacomEvent
rad as usize,
color,
);
framebuffer.partial_refresh(
&rect,
PartialRefreshMode::Async,
waveform_mode::WAVEFORM_MODE_DU,
display_temp::TEMP_USE_REMARKABLE_DRAW,
dither_mode::EPDC_FLAG_EXP1,
DRAWING_QUANT_BIT,
false,
);

if !LAST_REFRESHED_CANVAS_RECT
.load(Ordering::Relaxed)
.contains_rect(&rect)
{
framebuffer.partial_refresh(
&rect,
PartialRefreshMode::Async,
waveform_mode::WAVEFORM_MODE_DU,
display_temp::TEMP_USE_REMARKABLE_DRAW,
dither_mode::EPDC_FLAG_EXP1,
DRAWING_QUANT_BIT,
false,
);
LAST_REFRESHED_CANVAS_RECT.store(rect, Ordering::Relaxed);
}
}
wacom_stack.push((y as i32, x as i32));
}
Expand Down Expand Up @@ -565,6 +576,7 @@ lazy_static! {
static ref WACOM_IN_RANGE: AtomicBool = AtomicBool::new(false);
static ref WACOM_HISTORY: Mutex<Vec<(i32, i32)>> = Mutex::new(Vec::new());
static ref G_COUNTER: Mutex<u32> = Mutex::new(0);
static ref LAST_REFRESHED_CANVAS_RECT: Atomic<mxcfb_rect> = Atomic::new(mxcfb_rect::invalid());
static ref SAVED_CANVAS: Mutex<Option<storage::CompressedCanvasState>> = Mutex::new(None);
}

Expand Down
5 changes: 5 additions & 0 deletions src/framebuffer/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ impl mxcfb_rect {
|| y < self.top
|| y > (self.top + self.height))
}

pub fn contains_rect(&self, rect: &mxcfb_rect) -> bool {
self.contains_point(rect.top, rect.left)
&& self.contains_point(rect.top + rect.height, rect.left + rect.width)
}
}

#[derive(Copy, Clone, Debug, PartialEq)]
Expand Down

0 comments on commit 1629c52

Please sign in to comment.