-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make it You could also have |
||
|
||
// 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. | ||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.