Skip to content

Commit

Permalink
[escher] Remove statically-allocated buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
boricj authored and EmilieNumworks committed Apr 8, 2020
1 parent 64d0b31 commit 2768ac2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
5 changes: 2 additions & 3 deletions escher/src/chevron_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const uint8_t chevronMask[ChevronView::k_chevronHeight][ChevronView::k_chevronWi
{0x0C, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
};

KDColor s_workingBuffer[ChevronView::k_chevronWidth*ChevronView::k_chevronHeight];

void ChevronView::drawRect(KDContext * ctx, KDRect rect) const {
/* Draw the chevron aligned on the right of the view and vertically centered.
* The heightCenter is the coordinate of the vertical middle of the view. That
Expand All @@ -24,7 +22,8 @@ void ChevronView::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate heightCenter = bounds().height()/2;
KDCoordinate chevronHalfHeight = k_chevronHeight/2;
KDRect frame(width - k_chevronWidth, heightCenter -chevronHalfHeight, k_chevronWidth, k_chevronHeight);
ctx->blendRectWithMask(frame, Palette::YellowDark, (const uint8_t *)chevronMask, s_workingBuffer);
KDColor workingBuffer[ChevronView::k_chevronWidth*ChevronView::k_chevronHeight];
ctx->blendRectWithMask(frame, Palette::YellowDark, (const uint8_t *)chevronMask, workingBuffer);
}

KDSize ChevronView::minimalSizeForOptimalDisplay() const {
Expand Down
5 changes: 2 additions & 3 deletions escher/src/ellipsis_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const uint8_t ellipsisMask[EllipsisView::k_ellipsisHeight][EllipsisView::k_ellip
{0xFF, 0xD1, 0xA1, 0xC1, 0xFF, 0xFF, 0xFF, 0xD1, 0xA1, 0xC1, 0xFF, 0xFF, 0xFF, 0xD1, 0xA1, 0xC1, 0xFF},
};

KDColor s_ellipsisWorkingBuffer[EllipsisView::k_ellipsisWidth*EllipsisView::k_ellipsisHeight];

void EllipsisView::drawRect(KDContext * ctx, KDRect rect) const {
/* Draw the ellipsis vertically and horizontally centered in the view.
* The heightCenter is the coordinate of the vertical middle of the view. That
Expand All @@ -18,7 +16,8 @@ void EllipsisView::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate heightCenter = bounds().height()/2;
KDCoordinate ellipsisHalfHeight = k_ellipsisHeight/2;
KDRect frame(widthCenter - ellipsisHalfWidth, heightCenter - ellipsisHalfHeight, k_ellipsisWidth, k_ellipsisHeight);
ctx->blendRectWithMask(frame, KDColorBlack, (const uint8_t *)ellipsisMask, s_ellipsisWorkingBuffer);
KDColor ellipsisWorkingBuffer[EllipsisView::k_ellipsisWidth*EllipsisView::k_ellipsisHeight];
ctx->blendRectWithMask(frame, KDColorBlack, (const uint8_t *)ellipsisMask, ellipsisWorkingBuffer);
}

KDSize EllipsisView::minimalSizeForOptimalDisplay() const {
Expand Down
5 changes: 2 additions & 3 deletions escher/src/gauge_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ void GaugeView::setBackgroundColor(KDColor color) {
}
}

KDColor s_gaugeIndicatorWorkingBuffer[GaugeView::k_indicatorDiameter*GaugeView::k_indicatorDiameter];

void GaugeView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), m_backgroundColor);
/* Draw the gauge centered vertically on all the width available */
KDCoordinate width = bounds().width()-k_indicatorDiameter;
KDCoordinate height = bounds().height();
KDColor gaugeIndicatorWorkingBuffer[GaugeView::k_indicatorDiameter*GaugeView::k_indicatorDiameter];

ctx->fillRect(KDRect(k_indicatorDiameter/2, (height-k_thickness)/2, width*m_level, k_thickness), Palette::YellowDark);
ctx->fillRect(KDRect(k_indicatorDiameter/2+width*m_level, (height-k_thickness)/2, width*(1.0f-m_level), k_thickness), Palette::GreyDark);
KDRect frame(width*m_level, (height-k_indicatorDiameter)/2, k_indicatorDiameter, k_indicatorDiameter);
ctx->blendRectWithMask(frame, Palette::YellowDark, (const uint8_t *)gaugeIndicatorMask, s_gaugeIndicatorWorkingBuffer);
ctx->blendRectWithMask(frame, Palette::YellowDark, (const uint8_t *)gaugeIndicatorMask, gaugeIndicatorWorkingBuffer);
}

KDSize GaugeView::minimalSizeForOptimalDisplay() const {
Expand Down
5 changes: 2 additions & 3 deletions escher/src/key_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ void KeyView::setType(Type type) {
markRectAsDirty(bounds());
}

KDColor s_keyWorkingBuffer[KeyView::k_keySize*KeyView::k_keySize];

void KeyView::drawRect(KDContext * ctx, KDRect rect) const {
/* Draw the key centered on the view. */
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
KDRect frame((width - k_keySize)/2, (height - k_keySize)/2, k_keySize, k_keySize);
ctx->blendRectWithMask(frame, KDColorBlack, mask(), s_keyWorkingBuffer);
KDColor keyWorkingBuffer[KeyView::k_keySize*KeyView::k_keySize];
ctx->blendRectWithMask(frame, KDColorBlack, mask(), keyWorkingBuffer);
}

KDSize KeyView::minimalSizeForOptimalDisplay() const {
Expand Down
7 changes: 3 additions & 4 deletions escher/src/switch_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,21 @@ void SwitchView::setState(bool state) {
markRectAsDirty(bounds());
}

KDColor s_switchWorkingBuffer[SwitchView::k_switchWidth*SwitchView::k_switchHeight];

void SwitchView::drawRect(KDContext * ctx, KDRect rect) const {
/* Draw the switch aligned on the right of the view and vertically centered.
* The heightCenter is the coordinate of the vertical middle of the view. That
* way, (heightCenter-switchHalfHeight) indicates the top the switch. */
KDCoordinate width = bounds().width();
KDCoordinate heightCenter = bounds().height()/2;
KDCoordinate switchHalfHeight = k_switchHeight/2;
KDColor switchWorkingBuffer[SwitchView::k_switchWidth*SwitchView::k_switchHeight];

KDColor mainColor = m_state ? Palette::YellowDark : Palette::GreyDark;
KDRect frame(width - k_switchWidth, heightCenter -switchHalfHeight, k_switchWidth, k_switchHeight);
ctx->blendRectWithMask(frame, mainColor, (const uint8_t *)switchMask, s_switchWorkingBuffer);
ctx->blendRectWithMask(frame, mainColor, (const uint8_t *)switchMask, switchWorkingBuffer);
KDCoordinate onOffX = width - (m_state ? k_onOffSize : k_switchWidth);
KDRect onOffFrame(onOffX, heightCenter -switchHalfHeight, k_onOffSize, k_onOffSize);
ctx->blendRectWithMask(onOffFrame, KDColorWhite, (const uint8_t *)onOffMask, s_switchWorkingBuffer);
ctx->blendRectWithMask(onOffFrame, KDColorWhite, (const uint8_t *)onOffMask, switchWorkingBuffer);
}

KDSize SwitchView::minimalSizeForOptimalDisplay() const {
Expand Down

0 comments on commit 2768ac2

Please sign in to comment.