Skip to content
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

Add way to improve performance by using more memory #96

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 23 additions & 7 deletions src/pixel-display-impl_.toit
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ abstract class PixelDisplay implements Window:
inner-width: return driver_.width
inner-height: return driver_.width

/**
By default, the display is rendered in patches that have
a max size of 2-8k, depending on the bits per pixel. On devices
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
a max size of 2-8k, depending on the bits per pixel. On devices
a max size of 2-8k pixels, depending on the bits per pixel. On devices

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a user's point of view setting the memory used might be easier. Like "you are allowed to use 20K of RAM for each patch". Not really sure about that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what it is already though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the TwoColorPixelDisplay then set it to a higher value? I would have expected the 2-color display to use the least amount of memory.

with a large amount of memory this patch size can be increased,
which may improve performance.
During rendering, the display may allocate extra buffers for
multiple color components, transparency, and clipping, so the
effective memory use may be higher than this number.
*/
max-patch-size/int := 2000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make it := ? and always set it in the constructor?
Otherwise you might get misled by just looking here (and not realizing that some displays, like the two-color one) set it to a different value.

You could also have TWO-COLOR-DEFAULT-PATCH-SIZE... constants.


// Need-to-redraw is tracked as a bit array of dirty bits, arranged in
// SSD1306 layout so we can use bitmap-rectangle to invalidate areas.
// One bit in the dirty map covers an area of 8x8 pixels of the display.
Expand Down Expand Up @@ -527,17 +538,18 @@ class TwoColorPixelDisplay_ extends PixelDisplay:
constructor driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null:
super driver --inverted=inverted --portrait=portrait --transform=transform
background_ = two-color.WHITE
max-patch-size = 4000

max-canvas-height_ width/int -> int:
height := 0
width-rounded := round-up width 8
height-rounded := round-up driver_.height 8
if width-rounded * height-rounded >> 3 < 4000:
if width-rounded * height-rounded >> 3 < max-patch-size:
// If we can fit both the red and black plane in < 8k then do that.
height = height-rounded
else:
// Some multiple of 8 where each plane fits in one page.
height = (4000 / width-rounded) << 3
height = (max-patch-size / width-rounded) << 3
// We can't work well with canvases that are less than 8 pixels tall.
return max 8 height

Expand Down Expand Up @@ -584,17 +596,19 @@ abstract class TwoBitPixelDisplay_ extends PixelDisplay:

constructor driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null:
super driver --inverted=inverted --portrait=portrait --transform=transform
max-patch-size = 8000

max-canvas-height_ width:
width-rounded := round-up width 8
height-rounded := round-up driver_.height 8
height := ?
if width-rounded * height-rounded >> 3 < 4000:
per-plane-size := max-patch-size >> 1
if width-rounded * height-rounded >> 3 < per-plane-size:
// If we can fit both the red and black plane in < 8k then do that.
height = height-rounded
else:
// Some multiple of 8 where each plane fits in one page.
height = (4000 / width-rounded) << 3
height = (per-plane-size / width-rounded) << 3
// We can't work well with canvases that are less than 8 pixels tall.
return max 8 height

Expand All @@ -617,7 +631,7 @@ class GrayScalePixelDisplay_ extends PixelDisplay:
max-canvas-height_ width:
height := 0
// Keep each color component under 2k so you can fit two on a page.
height = round-down (2000 / width) 8
height = round-down (max-patch-size / width) 8
// We can't work well with canvases that are less than 4 pixels tall.
return height < 8 ? 4 : height

Expand All @@ -643,7 +657,7 @@ class SeveralColorPixelDisplay_ extends PixelDisplay:
max-canvas-height_ width:
height := 0
// Keep each color component under 2k so you can fit two on a page.
height = round-down (2000 / width) 8
height = round-down (max-patch-size / width) 8
// We can't work well with canvases that are less than 4 pixels tall.
return height < 8 ? 4 : height

Expand All @@ -665,12 +679,14 @@ class TrueColorPixelDisplay_ extends PixelDisplay:
constructor driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null:
super driver --inverted=inverted --portrait=portrait --transform=transform
background_ = true-color.WHITE
max-patch-size = 6000

max-canvas-height_ width:
height := 0
max-component-size := max-patch-size / 3
// Keep each color component under 2k then the packed 3-colors-in-2-bytes
// format is still less than a page.
height = round-down (2000 / width) 8
height = round-down (max-component-size / width) 8
// We can't work well with canvases that are less than 4 pixels tall.
return max 4 height

Expand Down
Binary file modified tests/gold/rounded-window-visualized.toit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/rounded-window-visualized.toit
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ main args:
// Window-relative coordinates.
text.move-to -10 7

// Larger patches.
display.max-patch-size = 10_0000

display.draw

driver.write-png
2 changes: 1 addition & 1 deletion tests/toit-png-tools