From 905f9591ab664cdef498d689d413ea2d40ebb442 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sun, 19 Feb 2012 19:17:47 +0100 Subject: GUI: Speed up alpha blending with black for classic dialog backgrounds --- graphics/VectorRendererSpec.cpp | 32 +++++++++++++++++++++++++++++++- graphics/VectorRendererSpec.h | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'graphics') diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp index efe38cbc5d..28b475f8db 100644 --- a/graphics/VectorRendererSpec.cpp +++ b/graphics/VectorRendererSpec.cpp @@ -527,6 +527,35 @@ blendPixelPtr(PixelType *ptr, PixelType color, uint8 alpha) { (idst & _alphaMask)); } +template +inline void VectorRendererSpec:: +darkenFill(PixelType *ptr, PixelType *end) { + PixelType mask = (PixelType)((3 << _format.rShift) | (3 << _format.gShift) | (3 << _format.bShift)); + + if (!g_system->hasFeature(OSystem::kFeatureOverlaySupportsAlpha)) { + // !kFeatureOverlaySupportsAlpha (but might have alpha bits) + + while (ptr != end) { + *ptr = ((*ptr & ~mask) >> 2) | _alphaMask; + ++ptr; + } + } else { + // kFeatureOverlaySupportsAlpha + // assuming at least 3 alpha bits + + mask |= 3 << _format.aShift; + PixelType addA = (PixelType)(255 >> _format.aLoss) << _format.aShift; + addA -= (addA >> 2); + + while (ptr != end) { + // Darken the colour, and increase the alpha + // (0% -> 75%, 100% -> 100%) + *ptr = (PixelType)(((*ptr & ~mask) >> 2) + addA); + ++ptr; + } + } +} + /******************************************************************** ******************************************************************** * Primitive shapes drawing - Public API calls - VectorRendererSpec * @@ -1020,8 +1049,9 @@ drawBevelSquareAlg(int x, int y, int w, int h, int bevel, PixelType top_color, P PixelType *ptr_fill = (PixelType *)_activeSurface->getBasePtr(x, y); if (fill) { + assert((_bgColor & ~_alphaMask) == 0); // only support black while (height--) { - blendFill(ptr_fill, ptr_fill + w, _bgColor, 200); + darkenFill(ptr_fill, ptr_fill + w); ptr_fill += pitch; } } diff --git a/graphics/VectorRendererSpec.h b/graphics/VectorRendererSpec.h index 39505d3c27..7812e77b22 100644 --- a/graphics/VectorRendererSpec.h +++ b/graphics/VectorRendererSpec.h @@ -201,6 +201,8 @@ protected: while (first != last) blendPixelPtr(first++, color, alpha); } + void darkenFill(PixelType *first, PixelType *last); + const PixelFormat _format; const PixelType _redMask, _greenMask, _blueMask, _alphaMask; -- cgit v1.2.3