From 2768ac2b48cb200f5e4c80a667a150dfc2d50a06 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Boric Date: Sat, 30 Nov 2019 20:13:02 +0100 Subject: [PATCH] [escher] Remove statically-allocated buffers --- escher/src/chevron_view.cpp | 5 ++--- escher/src/ellipsis_view.cpp | 5 ++--- escher/src/gauge_view.cpp | 5 ++--- escher/src/key_view.cpp | 5 ++--- escher/src/switch_view.cpp | 7 +++---- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/escher/src/chevron_view.cpp b/escher/src/chevron_view.cpp index b6c7b32d2..0ac38c794 100644 --- a/escher/src/chevron_view.cpp +++ b/escher/src/chevron_view.cpp @@ -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 @@ -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 { diff --git a/escher/src/ellipsis_view.cpp b/escher/src/ellipsis_view.cpp index f965ea447..4a659b6a9 100644 --- a/escher/src/ellipsis_view.cpp +++ b/escher/src/ellipsis_view.cpp @@ -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 @@ -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 { diff --git a/escher/src/gauge_view.cpp b/escher/src/gauge_view.cpp index f22d7ecf6..71c0dc05d 100644 --- a/escher/src/gauge_view.cpp +++ b/escher/src/gauge_view.cpp @@ -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 { diff --git a/escher/src/key_view.cpp b/escher/src/key_view.cpp index 1c1022f5b..d61598fec 100644 --- a/escher/src/key_view.cpp +++ b/escher/src/key_view.cpp @@ -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 { diff --git a/escher/src/switch_view.cpp b/escher/src/switch_view.cpp index a88dfb7a0..b06d51620 100644 --- a/escher/src/switch_view.cpp +++ b/escher/src/switch_view.cpp @@ -46,8 +46,6 @@ 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 @@ -55,13 +53,14 @@ void SwitchView::drawRect(KDContext * ctx, KDRect rect) const { 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 {