diff --git a/src/servers/app/drawing/Painter/Painter.cpp b/src/servers/app/drawing/Painter/Painter.cpp index a9479cfd93..10bbcced05 100644 --- a/src/servers/app/drawing/Painter/Painter.cpp +++ b/src/servers/app/drawing/Painter/Painter.cpp @@ -1147,6 +1147,8 @@ Painter::_UpdateDrawingMode(bool drawingText) // are up to date for use by the solid drawing mode version. fPixelFormat.SetDrawingMode(fDrawingMode, fAlphaSrcMode, fAlphaFncMode, drawingText); + if (drawingText) + fPatternHandler.MakeOpCopyColorCache(); } // _SetRendererColor diff --git a/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopyText.h b/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopyText.h index f67cf768f7..b1a4097cb5 100644 --- a/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopyText.h +++ b/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopyText.h @@ -64,19 +64,24 @@ blend_solid_hspan_copy_text(int x, int y, unsigned len, agg_buffer* buffer, const PatternHandler* pattern) { - uint8* p = buffer->row_ptr(y) + (x << 2); - rgb_color l = pattern->LowColor().GetColor32(); +//printf("blend_solid_hspan_copy_text(%d, %d)\n", x, len); +// uint8* p = buffer->row_ptr(y) + (x << 2); + uint32* p = (uint32*)(buffer->row_ptr(y) + (x << 2)); + const uint32* cache = (const uint32*)pattern->OpCopyColorCache(); +// rgb_color l = pattern->LowColor().GetColor32(); do { - if (*covers) { - if(*covers == 255) { - ASSIGN_COPY(p, c.r, c.g, c.b, c.a); - } else { - BLEND_COPY(p, c.r, c.g, c.b, *covers, - l.red, l.green, l.blue); - } - } +// if (*covers) { + *p = cache[*covers]; +// if(*covers == 255) { +// ASSIGN_COPY(p, c.r, c.g, c.b, c.a); +// } else { +// BLEND_COPY(p, c.r, c.g, c.b, *covers, +// l.red, l.green, l.blue); +// } +// } covers++; - p += 4; + p++; +// p += 4; } while(--len); } diff --git a/src/servers/app/drawing/PatternHandler.cpp b/src/servers/app/drawing/PatternHandler.cpp index 7cb9173b60..318fb1f57c 100644 --- a/src/servers/app/drawing/PatternHandler.cpp +++ b/src/servers/app/drawing/PatternHandler.cpp @@ -9,6 +9,7 @@ #include "PatternHandler.h" #include +#include #include @@ -30,8 +31,10 @@ PatternHandler::PatternHandler(void) fHighColor(kBlack), fLowColor(kWhite), fXOffset(0), - fYOffset(0) + fYOffset(0), + fColorsWhenCached(ULONGLONG_MAX) { + memset(fOpCopyColorCache, 255, 256 * sizeof(rgb_color)); } /*! @@ -46,8 +49,10 @@ PatternHandler::PatternHandler(const int8* pat) fHighColor(kBlack), fLowColor(kWhite), fXOffset(0), - fYOffset(0) + fYOffset(0), + fColorsWhenCached(ULONGLONG_MAX) { + memset(fOpCopyColorCache, 255, 256 * sizeof(rgb_color)); } /*! @@ -62,8 +67,10 @@ PatternHandler::PatternHandler(const uint64& pat) fHighColor(kBlack), fLowColor(kWhite), fXOffset(0), - fYOffset(0) + fYOffset(0), + fColorsWhenCached(ULONGLONG_MAX) { + memset(fOpCopyColorCache, 255, 256 * sizeof(rgb_color)); } /*! @@ -78,8 +85,10 @@ PatternHandler::PatternHandler(const Pattern& pat) fHighColor(kBlack), fLowColor(kWhite), fXOffset(0), - fYOffset(0) + fYOffset(0), + fColorsWhenCached(ULONGLONG_MAX) { + memset(fOpCopyColorCache, 255, 256 * sizeof(rgb_color)); } /*! @@ -93,8 +102,10 @@ PatternHandler::PatternHandler(const PatternHandler& other) fHighColor(other.fHighColor), fLowColor(other.fLowColor), fXOffset(other.fXOffset), - fYOffset(other.fYOffset) + fYOffset(other.fYOffset), + fColorsWhenCached(ULONGLONG_MAX) { + memset(fOpCopyColorCache, 255, 256 * sizeof(rgb_color)); } //! Destructor does nothing @@ -189,7 +200,6 @@ void PatternHandler::SetColors(const rgb_color& high, const rgb_color& low) { fHighColor = high; - fLowColor = low; } /*! @@ -258,3 +268,39 @@ PatternHandler::SetOffsets(int32 x, int32 y) fYOffset = y & 7; } + +void +PatternHandler::MakeOpCopyColorCache() +{ + rgb_color highColor = fHighColor.GetColor32(); + rgb_color lowColor = fLowColor.GetColor32(); + + uint64 t1 = *(uint32*)&highColor; + uint32 t2 = *(uint32*)&lowColor; + + uint64 colors = (t1 << 32) | t2; + + if (fColorsWhenCached == colors) + return; + + fColorsWhenCached = colors; + + // ramp from low color to high color + uint8 rA = fLowColor.GetColor32().red; + uint8 gA = fLowColor.GetColor32().green; + uint8 bA = fLowColor.GetColor32().blue; + + uint8 rB = fHighColor.GetColor32().red; + uint8 gB = fHighColor.GetColor32().green; + uint8 bB = fHighColor.GetColor32().blue; + + for (int32 i = 0; i < 256; i++) { + // NOTE: rgb is twisted around, since this is + // only used as uint32 in the end + fOpCopyColorCache[i].red = (((bB - bA) * i) + (bA << 8)) >> 8; + fOpCopyColorCache[i].green = (((gB - gA) * i) + (gA << 8)) >> 8; + fOpCopyColorCache[i].blue = (((rB - rA) * i) + (rA << 8)) >> 8; + } +} + + diff --git a/src/servers/app/drawing/PatternHandler.h b/src/servers/app/drawing/PatternHandler.h index b8cb583b33..3b0f5ac3ef 100644 --- a/src/servers/app/drawing/PatternHandler.h +++ b/src/servers/app/drawing/PatternHandler.h @@ -131,6 +131,10 @@ class PatternHandler { void SetOffsets(int32 x, int32 y); + void MakeOpCopyColorCache(); + inline const rgb_color* OpCopyColorCache() const + { return fOpCopyColorCache; } + private: Pattern fPattern; RGBColor fHighColor; @@ -138,6 +142,9 @@ class PatternHandler { uint16 fXOffset; uint16 fYOffset; + + rgb_color fOpCopyColorCache[256]; + uint64 fColorsWhenCached; }; /*!