[escher] Avoid holding a working buffer for all chevron view

Change-Id: Ib8c5f085b57dd0417215d7e8689833dfee138699
This commit is contained in:
Émilie Feral
2017-02-16 16:38:35 +01:00
parent 0d8629c752
commit 4a1735c29e
2 changed files with 5 additions and 4 deletions

View File

@@ -9,13 +9,12 @@ public:
void drawRect(KDContext * ctx, KDRect rect) const override;
void setHighlighted(bool highlight);
KDSize minimalSizeForOptimalDisplay() override;
private:
/* k_chevronHeight and k_chevronWidth are the dimensions of the chevron. */
constexpr static KDCoordinate k_chevronHeight = 16;
constexpr static KDCoordinate k_chevronWidth = 8;
private:
constexpr static KDCoordinate k_chevronRightMargin = 20;
bool m_highlighted;
KDColor m_workingBuffer[k_chevronWidth*k_chevronHeight];
};
#endif

View File

@@ -49,6 +49,8 @@ void ChevronView::setHighlighted(bool highlight) {
markRectAsDirty(bounds());
}
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
@@ -58,9 +60,9 @@ void ChevronView::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate chevronHalfHeight = k_chevronHeight/2;
KDRect frame(width - k_chevronRightMargin, heightCenter -chevronHalfHeight, k_chevronWidth, k_chevronHeight);
if (m_highlighted) {
ctx->fillRectWithPixels(frame, highlightedChevronPixel, (KDColor *)m_workingBuffer);
ctx->fillRectWithPixels(frame, highlightedChevronPixel, (KDColor *)s_workingBuffer);
} else {
ctx->fillRectWithPixels(frame, chevronPixel, (KDColor *)m_workingBuffer);
ctx->fillRectWithPixels(frame, chevronPixel, (KDColor *)s_workingBuffer);
}
}