PatternHandler: remove unused code

hrev17117 implemented B_OP_COPY with a special treatment for text.
hrev21929 introduced the color cache to speed up that text drawing.
hrev52753 removed the special treatment of text in B_OP_COPY, but left the
color cache and the text flag behind.

Change-Id: Ib506c80a660e829132bce3ec1cb354fcfbab266c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4931
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Máximo Castañeda 2022-01-31 20:12:08 +01:00 committed by waddlesplash
parent 1f357f79ca
commit 9a7906eadb
7 changed files with 18 additions and 83 deletions

View File

@ -363,7 +363,7 @@ DrawingEngine::SetBlendingMode(source_alpha srcAlpha, alpha_function alphaFunc)
void
DrawingEngine::SetPattern(const struct pattern& pattern)
{
fPainter->SetPattern(pattern, false);
fPainter->SetPattern(pattern);
}

View File

@ -18,7 +18,6 @@
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <Bitmap.h>
#include <GraphicsDefs.h>
@ -184,7 +183,6 @@ Painter::Painter()
fInternal(fPatternHandler),
fSubpixelPrecise(false),
fValidClipping(false),
fDrawingText(false),
fAttached(false),
fPenSize(1.0),
@ -201,8 +199,7 @@ Painter::Painter()
fSubpixUnpackedScanline, fSubpixRasterizer, fMaskedUnpackedScanline,
fTransform)
{
fPixelFormat.SetDrawingMode(fDrawingMode, fAlphaSrcMode, fAlphaFncMode,
false);
fPixelFormat.SetDrawingMode(fDrawingMode, fAlphaSrcMode, fAlphaFncMode);
#if ALIASED_DRAWING
fRasterizer.gamma(agg::gamma_threshold(0.5));
@ -439,12 +436,11 @@ Painter::SetFillRule(int32 fillRule)
// SetPattern
void
Painter::SetPattern(const pattern& p, bool drawingText)
Painter::SetPattern(const pattern& p)
{
if (!(p == *fPatternHandler.GetR5Pattern()) || drawingText != fDrawingText) {
if (p != *fPatternHandler.GetR5Pattern()) {
fPatternHandler.SetPattern(p);
fDrawingText = drawingText;
_UpdateDrawingMode(fDrawingText);
_UpdateDrawingMode();
// update renderer color if necessary
if (fPatternHandler.IsSolidHigh()) {
@ -1344,7 +1340,7 @@ Painter::DrawString(const char* utf8String, uint32 length, BPoint baseLine,
// text is not rendered with patterns, but we need to
// make sure that the previous pattern is restored
pattern oldPattern = *fPatternHandler.GetR5Pattern();
SetPattern(B_SOLID_HIGH, true);
SetPattern(B_SOLID_HIGH);
bounds = fTextRenderer.RenderString(utf8String, length,
baseLine, fClippingRegion->Frame(), false, NULL, delta,
@ -1370,7 +1366,7 @@ Painter::DrawString(const char* utf8String, uint32 length,
// text is not rendered with patterns, but we need to
// make sure that the previous pattern is restored
pattern oldPattern = *fPatternHandler.GetR5Pattern();
SetPattern(B_SOLID_HIGH, true);
SetPattern(B_SOLID_HIGH);
bounds = fTextRenderer.RenderString(utf8String, length,
offsets, fClippingRegion->Frame(), false, NULL,
@ -1560,7 +1556,7 @@ Painter::_Clipped(const BRect& rect) const
// _UpdateDrawingMode
void
Painter::_UpdateDrawingMode(bool drawingText)
Painter::_UpdateDrawingMode()
{
// The AGG renderers have their own color setting, however
// almost all drawing mode classes ignore the color given
@ -1571,19 +1567,10 @@ Painter::_UpdateDrawingMode(bool drawingText)
// has been implemented for B_OP_COPY and a couple others (the
// DrawingMode*Solid ones) as of now. The PixelFormat knows the
// PatternHandler and makes its decision based on the pattern.
// The last parameter to SetDrawingMode() is a special flag
// for when Painter is used to draw text. In this case, another
// special version of B_OP_COPY is used that acts like R5 in that
// anti-aliased pixel are not rendered against the actual background
// but the current low color instead. This way, the frame buffer
// doesn't need to be read.
// When a solid pattern is used, _SetRendererColor()
// has to be called so that all internal colors in the renderes
// are up to date for use by the solid drawing mode version.
fPixelFormat.SetDrawingMode(fDrawingMode, fAlphaSrcMode, fAlphaFncMode,
drawingText);
if (drawingText)
fPatternHandler.MakeOpCopyColorCache();
fPixelFormat.SetDrawingMode(fDrawingMode, fAlphaSrcMode, fAlphaFncMode);
}

View File

@ -89,8 +89,7 @@ public:
void SetStrokeMode(cap_mode lineCap,
join_mode joinMode, float miterLimit);
void SetFillRule(int32 fillRule);
void SetPattern(const pattern& p,
bool drawingText = false);
void SetPattern(const pattern& p);
inline pattern Pattern() const
{ return *fPatternHandler.GetR5Pattern(); }
void SetDrawingMode(drawing_mode mode);
@ -266,7 +265,7 @@ private:
void _UpdateFont() const;
void _UpdateLineWidth();
void _UpdateDrawingMode(bool drawingText = false);
void _UpdateDrawingMode();
void _SetRendererColor(const rgb_color& color) const;
// drawing functions stroke/fill
@ -337,7 +336,6 @@ private:
// for internal coordinate rounding/transformation
bool fSubpixelPrecise : 1;
bool fValidClipping : 1;
bool fDrawingText : 1;
bool fAttached : 1;
bool fIdentityTransform : 1;

View File

@ -157,7 +157,7 @@ PixelFormat::~PixelFormat()
// SetDrawingMode
void
PixelFormat::SetDrawingMode(drawing_mode mode, source_alpha alphaSrcMode,
alpha_function alphaFncMode, bool text)
alpha_function alphaFncMode)
{
switch (mode) {
// These drawing modes discard source pixels

View File

@ -99,8 +99,7 @@ class PixelFormat {
void SetDrawingMode(drawing_mode mode,
source_alpha alphaSrcMode,
alpha_function alphaFncMode,
bool text);
alpha_function alphaFncMode);
// AGG "pixel format" interface
inline unsigned width() const

View File

@ -9,7 +9,6 @@
#include "PatternHandler.h"
#include <stdio.h>
#include <string.h>
#include <Point.h>
@ -31,10 +30,8 @@ PatternHandler::PatternHandler(void)
fHighColor(kBlack),
fLowColor(kWhite),
fXOffset(0),
fYOffset(0),
fColorsWhenCached(ULONGLONG_MAX)
fYOffset(0)
{
memset((void*)fOpCopyColorCache, 255, 256 * sizeof(rgb_color));
}
/*!
@ -49,10 +46,8 @@ PatternHandler::PatternHandler(const int8* pat)
fHighColor(kBlack),
fLowColor(kWhite),
fXOffset(0),
fYOffset(0),
fColorsWhenCached(ULONGLONG_MAX)
fYOffset(0)
{
memset((void*)fOpCopyColorCache, 255, 256 * sizeof(rgb_color));
}
/*!
@ -67,10 +62,8 @@ PatternHandler::PatternHandler(const uint64& pat)
fHighColor(kBlack),
fLowColor(kWhite),
fXOffset(0),
fYOffset(0),
fColorsWhenCached(ULONGLONG_MAX)
fYOffset(0)
{
memset((void*)fOpCopyColorCache, 255, 256 * sizeof(rgb_color));
}
/*!
@ -85,10 +78,8 @@ PatternHandler::PatternHandler(const Pattern& pat)
fHighColor(kBlack),
fLowColor(kWhite),
fXOffset(0),
fYOffset(0),
fColorsWhenCached(ULONGLONG_MAX)
fYOffset(0)
{
memset((void*)fOpCopyColorCache, 255, 256 * sizeof(rgb_color));
}
/*!
@ -102,10 +93,8 @@ PatternHandler::PatternHandler(const PatternHandler& other)
fHighColor(other.fHighColor),
fLowColor(other.fLowColor),
fXOffset(other.fXOffset),
fYOffset(other.fYOffset),
fColorsWhenCached(ULONGLONG_MAX)
fYOffset(other.fYOffset)
{
memset((void*)fOpCopyColorCache, 255, 256 * sizeof(rgb_color));
}
//! Destructor does nothing
@ -237,34 +226,3 @@ PatternHandler::SetOffsets(int32 x, int32 y)
fYOffset = y & 7;
}
void
PatternHandler::MakeOpCopyColorCache()
{
uint64 t = *(uint32*)&fHighColor;
uint64 colors = (t << 32) | *(uint32*)&fLowColor;
if (fColorsWhenCached == colors)
return;
fColorsWhenCached = colors;
// ramp from low color to high color
uint8 rA = fLowColor.red;
uint8 gA = fLowColor.green;
uint8 bA = fLowColor.blue;
uint8 rB = fHighColor.red;
uint8 gB = fHighColor.green;
uint8 bB = fHighColor.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;
}
}

View File

@ -131,10 +131,6 @@ class PatternHandler {
void SetOffsets(int32 x, int32 y);
void MakeOpCopyColorCache();
inline const rgb_color* OpCopyColorCache() const
{ return fOpCopyColorCache; }
private:
Pattern fPattern;
rgb_color fHighColor;
@ -142,9 +138,6 @@ class PatternHandler {
uint16 fXOffset;
uint16 fYOffset;
rgb_color fOpCopyColorCache[256];
uint64 fColorsWhenCached;
};
/*!