[apps] Remove statically-allocated buffers

This commit is contained in:
Jean-Baptiste Boric
2019-11-30 20:12:38 +01:00
committed by EmilieNumworks
parent b59085bd7f
commit 64d0b3107f
6 changed files with 18 additions and 23 deletions

View File

@@ -54,9 +54,6 @@ bool BatteryView::setIsPlugged(bool isPlugged) {
return false;
}
KDColor s_flashWorkingBuffer[BatteryView::k_flashHeight*BatteryView::k_flashWidth];
KDColor s_tickWorkingBuffer[BatteryView::k_tickHeight*BatteryView::k_tickWidth];
void BatteryView::drawRect(KDContext * ctx, KDRect rect) const {
assert(m_chargeState != Ion::Battery::Charge::EMPTY);
/* We draw from left to right. The middle part representing the battery
@@ -72,7 +69,8 @@ void BatteryView::drawRect(KDContext * ctx, KDRect rect) const {
// Charging: Yellow background with flash
ctx->fillRect(KDRect(batteryInsideX, 0, batteryInsideWidth, k_batteryHeight), Palette::YellowLight);
KDRect frame((k_batteryWidth-k_flashWidth)/2, 0, k_flashWidth, k_flashHeight);
ctx->blendRectWithMask(frame, KDColorWhite, (const uint8_t *)flashMask, s_flashWorkingBuffer);
KDColor flashWorkingBuffer[BatteryView::k_flashHeight*BatteryView::k_flashWidth];
ctx->blendRectWithMask(frame, KDColorWhite, (const uint8_t *)flashMask, flashWorkingBuffer);
} else if (m_chargeState == Ion::Battery::Charge::LOW) {
assert(!m_isPlugged);
// Low: Quite empty battery
@@ -91,7 +89,8 @@ void BatteryView::drawRect(KDContext * ctx, KDRect rect) const {
if (m_isPlugged) {
// Plugged and full: Full battery with tick
KDRect frame((k_batteryWidth-k_tickWidth)/2, (k_batteryHeight-k_tickHeight)/2, k_tickWidth, k_tickHeight);
ctx->blendRectWithMask(frame, Palette::YellowDark, (const uint8_t *)tickMask, s_tickWorkingBuffer);
KDColor tickWorkingBuffer[BatteryView::k_tickHeight*BatteryView::k_tickWidth];
ctx->blendRectWithMask(frame, Palette::YellowDark, (const uint8_t *)tickMask, tickWorkingBuffer);
}
}

View File

@@ -48,16 +48,15 @@ void ArrowView::setColor(KDColor color) {
}
}
KDColor s_arrowWorkingBuffer[10*9];
void ArrowView::drawRect(KDContext * ctx, KDRect rect) const {
KDColor arrowWorkingBuffer[10*9];
ctx->fillRect(bounds(), KDColorWhite);
KDCoordinate startLine = m_directionIsUp ? k_arrowHeight : 0;
KDCoordinate startArrow = m_directionIsUp ? 0 : bounds().height()-k_arrowHeight;
ctx->fillRect(KDRect((Ion::Display::Width-k_arrowThickness)/2, startLine, k_arrowThickness, bounds().height()-k_arrowHeight), m_color);
KDRect frame((Ion::Display::Width-k_arrowWidth)/2, startArrow, k_arrowWidth, k_arrowHeight);
const uint8_t * mask = m_directionIsUp ? (const uint8_t *)arrowUpMask : (const uint8_t *)arrowDownMask;
ctx->blendRectWithMask(frame, m_color, mask, s_arrowWorkingBuffer);
ctx->blendRectWithMask(frame, m_color, mask, arrowWorkingBuffer);
}
}

View File

@@ -12,11 +12,10 @@ const uint8_t lockMask[LockView::k_lockHeight][LockView::k_lockWidth] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
};
KDColor s_lockWorkingBuffer[LockView::k_lockHeight*LockView::k_lockWidth];
void LockView::drawRect(KDContext * ctx, KDRect rect) const {
KDRect frame((bounds().width() - k_lockWidth)/2, (bounds().height()-k_lockHeight)/2, k_lockWidth, k_lockHeight);
ctx->blendRectWithMask(frame, KDColorWhite, (const uint8_t *)lockMask, s_lockWorkingBuffer);
KDColor lockWorkingBuffer[LockView::k_lockHeight*LockView::k_lockWidth];
ctx->blendRectWithMask(frame, KDColorWhite, (const uint8_t *)lockMask, lockWorkingBuffer);
}
KDSize LockView::minimalSizeForOptimalDisplay() const {

View File

@@ -25,13 +25,12 @@ const uint8_t okMask[OkView::k_okSize][OkView::k_okSize] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
};
KDColor s_okWorkingBuffer[OkView::k_okSize*OkView::k_okSize];
void OkView::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
KDRect frame((width-k_okSize)/2, (height-k_okSize)/2, k_okSize, k_okSize);
ctx->blendRectWithMask(frame, KDColorBlack, (const uint8_t *)okMask, s_okWorkingBuffer);
KDColor okWorkingBuffer[OkView::k_okSize*OkView::k_okSize];
ctx->blendRectWithMask(frame, KDColorBlack, (const uint8_t *)okMask, okWorkingBuffer);
}
KDSize OkView::minimalSizeForOptimalDisplay() const {

View File

@@ -2,10 +2,9 @@
namespace Shared {
static KDColor s_cursorWorkingBuffer[Dots::LargeDotDiameter*Dots::LargeDotDiameter];
void RoundCursorView::drawRect(KDContext * ctx, KDRect rect) const {
KDRect r = bounds();
KDColor cursorWorkingBuffer[Dots::LargeDotDiameter*Dots::LargeDotDiameter];
#ifdef GRAPH_CURSOR_SPEEDUP
/* Beware that only the pixels of the intersection of rect with KDContext's
* clipping rect are pulled. All other pixels are left unaltered. Indeed
@@ -15,7 +14,7 @@ void RoundCursorView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->getPixels(r, m_underneathPixelBuffer);
m_underneathPixelBufferLoaded = true;
#endif
ctx->blendRectWithMask(r, m_color, (const uint8_t *)Dots::LargeDotMask, s_cursorWorkingBuffer);
ctx->blendRectWithMask(r, m_color, (const uint8_t *)Dots::LargeDotMask, cursorWorkingBuffer);
}
KDSize RoundCursorView::minimalSizeForOptimalDisplay() const {
@@ -67,10 +66,11 @@ bool RoundCursorView::eraseCursorIfPossible() {
return false;
}
// Erase the cursor
KDColor cursorWorkingBuffer[Dots::LargeDotDiameter*Dots::LargeDotDiameter];
KDContext * ctx = KDIonContext::sharedContext();
ctx->setOrigin(currentFrame.origin());
ctx->setClippingRect(currentFrame);
ctx->fillRectWithPixels(KDRect(0,0,k_cursorSize, k_cursorSize), m_underneathPixelBuffer, s_cursorWorkingBuffer);
ctx->fillRectWithPixels(KDRect(0,0,k_cursorSize, k_cursorSize), m_underneathPixelBuffer, cursorWorkingBuffer);
// TODO Restore the context to previous values?
return true;
}

View File

@@ -105,15 +105,14 @@ const uint8_t bottomBrace[braceExtremumHeight][braceExtremumWidth] = {
{0xFF, 0xFF, 0xF7, 0x25, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00},
};
KDColor s_braceWorkingBuffer[60];
void EquationListView::BraceView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorWhite);
KDCoordinate height = bounds().height();
KDCoordinate margin = 3;
ctx->blendRectWithMask(KDRect(margin, 0, braceExtremumWidth, braceExtremumHeight), KDColorBlack, (const uint8_t *)topBrace, (KDColor *)(s_braceWorkingBuffer));
ctx->blendRectWithMask(KDRect(0, height/2-braceCenterHeight/2, braceCenterWidth, braceCenterHeight), KDColorBlack, (const uint8_t *)middleBrace, (KDColor *)(s_braceWorkingBuffer));
ctx->blendRectWithMask(KDRect(margin, height-braceExtremumHeight, braceExtremumWidth, braceExtremumHeight), KDColorBlack, (const uint8_t *)bottomBrace, (KDColor *)(s_braceWorkingBuffer));
KDColor braceWorkingBuffer[60];
ctx->blendRectWithMask(KDRect(margin, 0, braceExtremumWidth, braceExtremumHeight), KDColorBlack, (const uint8_t *)topBrace, (KDColor *)(braceWorkingBuffer));
ctx->blendRectWithMask(KDRect(0, height/2-braceCenterHeight/2, braceCenterWidth, braceCenterHeight), KDColorBlack, (const uint8_t *)middleBrace, (KDColor *)(braceWorkingBuffer));
ctx->blendRectWithMask(KDRect(margin, height-braceExtremumHeight, braceExtremumWidth, braceExtremumHeight), KDColorBlack, (const uint8_t *)bottomBrace, (KDColor *)(braceWorkingBuffer));
ctx->fillRect(KDRect(margin, braceExtremumHeight, 1, height/2-braceCenterHeight/2-braceExtremumHeight), KDColorBlack);
ctx->fillRect(KDRect(margin, height/2+braceCenterHeight/2, 1, height/2-braceExtremumHeight/2-braceExtremumHeight), KDColorBlack);
}