mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add bounds checking to a TextView string length
Before xous-ipc's fixed-length string guaranteed this thing fit into a single page. Now, we can send potentially unbounded amounts of text between servers. I don't think it makes sense to send more than a few k of text to render on the screen at once, given our screen sizes, so I've added a patch that truncates the text to the previous length that things would truncate to. The behavior is the same as before, except that you will over-allocate memory on the heap in the sending process as you shove more string data into a TextView than can be rendered. Previously, the TextView would just truncate the data and discard the data. The truncation happens at the point where you try to hand the record off to another process, so, one could in theory try to make this recoverable by adding a layer that splits the textview into more manageable chunks or pages the data, but that is an exercise for another day.
This commit is contained in:
parent
e61a2e3238
commit
921be1cf8b
3 changed files with 16 additions and 5 deletions
|
|
@ -24,7 +24,7 @@ pub use graphics_server::api::{Point, Rectangle};
|
|||
pub use graphics_server::api::{TextOp, TextView};
|
||||
use ime_plugin_api::{ApiToken, ImefCallback};
|
||||
use num_traits::*;
|
||||
use xous::{send_message, Message, CID};
|
||||
use xous::{CID, Message, send_message};
|
||||
use xous_ipc::Buffer;
|
||||
|
||||
#[doc = include_str!("../README.md")]
|
||||
|
|
@ -146,10 +146,16 @@ impl Gam {
|
|||
}
|
||||
}
|
||||
|
||||
/// this "posts" a textview -- it's not a "draw" as the update is neither guaranteed nor instantaneous
|
||||
/// This "posts" a textview -- it's not a "draw" as the update is neither guaranteed nor instantaneous
|
||||
/// the GAM first has to check that the textview is allowed to be updated, and then it will decide when
|
||||
/// the actual screen update is allowed
|
||||
///
|
||||
/// This will also truncate any text that is too long to fit into a single paged-sized transaction, as set
|
||||
/// by `graphics_server::api::TEXTVIEW_LEN`
|
||||
pub fn post_textview(&self, tv: &mut TextView) -> Result<(), xous::Error> {
|
||||
if tv.text.len() > graphics_server::api::TEXTVIEW_LEN {
|
||||
tv.text.truncate(graphics_server::api::TEXTVIEW_LEN);
|
||||
}
|
||||
tv.set_op(TextOp::Render);
|
||||
// force the clip_rect to none, in case a stale value from a previous bounds computation was hanging
|
||||
// out the bounds should /always/ come from the GAM canvas when doing a "live fire" redraw
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ impl From<usize> for TextOp {
|
|||
}
|
||||
|
||||
// roughly 168 bytes to represent the rest of the struct, and we want to fill out the 4096 byte page with text
|
||||
const TEXTVIEW_LEN: usize = 3072;
|
||||
pub const TEXTVIEW_LEN: usize = 3072;
|
||||
pub const TEXTVIEW_DEFAULT_STYLE: GlyphStyle = GlyphStyle::Regular;
|
||||
|
||||
#[derive(Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ pub mod op;
|
|||
pub mod fontmap;
|
||||
pub use api::ArchivedBulkRead;
|
||||
pub use api::BulkRead;
|
||||
use api::Opcode; // if you prefer to map the api into your local namespace
|
||||
use api::{Opcode, TEXTVIEW_LEN}; // if you prefer to map the api into your local namespace
|
||||
pub use fontmap::*;
|
||||
use num_traits::ToPrimitive;
|
||||
use xous::{send_message, Message};
|
||||
use xous::{Message, send_message};
|
||||
use xous_ipc::Buffer;
|
||||
#[derive(Debug)]
|
||||
pub struct Gfx {
|
||||
|
|
@ -134,7 +134,12 @@ impl Gfx {
|
|||
}
|
||||
}
|
||||
|
||||
/// This function will truncate a TextView string if it is too long to transmit in
|
||||
/// a single page of memory.
|
||||
pub fn draw_textview(&self, tv: &mut TextView) -> Result<(), xous::Error> {
|
||||
if tv.text.len() > TEXTVIEW_LEN {
|
||||
tv.text.truncate(TEXTVIEW_LEN);
|
||||
}
|
||||
let mut buf = Buffer::into_buf(tv.clone()).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend_mut(self.conn, Opcode::DrawTextView.to_u32().unwrap())
|
||||
.or(Err(xous::Error::InternalError))?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue