Get rid of special B_OP_COPY implementation for rendering text
Since BeOS had no anti-aliased drawing except for text, it didn't matter whether drawing diagonal lines (for example) in B_OP_COPY or B_OP_OVER. Applying the meaning of B_OP_COPY strictly to everything else would have broken pretty much every existing BeOS, resulting in broken drawing for anything but straight lines and rectangles. The solution was to treat B_OP_COPY just like B_OP_OVER *except* for text rendering, where we could be compatible with the BeOS behavior. Nevertheless, one can sometimes observe apps using B_OP_COPY where they /should/ be using B_OP_OVER for rendering text, resulting in white edges around the glyphs where the actual LowColor() does not match the current background on which the text is rendered. There is however a problem when glyphs in a string overlap. Some fonts have overlapping glyphs by default (handwriting, etc). With the LCD sub-pixel filtering, this problem is visible even in fonts where glyphs don't overlap normally, for example 'lt'. The leftmost pixel of the 't' is smeared due to the filtering and produces an almost transparent pixel which is rendered (using the low color as the background) on top of the 'l'. To fix this, one would have to render the string into an alpha mask buffer first, and then blend it all at once using B_OP_COPY. This however defeats the point of B_OP_COPY, which is to be a performance optimization. So instead, I opted for the solution that is already in place for everything else, which is to make B_OP_COPY behave like B_OP_OVER. For the case that this would have produced a difference, i.e. rendering with the solid high color, one needs to clear the background using the low color, before rendering text, or it would have looked broken. So in practice, there cannot be a difference. Change-Id: I4348902ae754507f1429e0a9575f03d8ecbce333 Reviewed-on: https://review.haiku-os.org/c/877 Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
parent
0991a51b01
commit
57e2488804
@ -322,7 +322,7 @@ Painter::SetDrawState(const DrawState* state, int32 xOffset, int32 yOffset)
|
||||
SetHighColor(state->HighColor());
|
||||
SetLowColor(state->LowColor());
|
||||
|
||||
if (updateDrawingMode || fPixelFormat.UsesOpCopyForText())
|
||||
if (updateDrawingMode)
|
||||
_UpdateDrawingMode();
|
||||
}
|
||||
|
||||
|
@ -1,160 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006, Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* DrawingMode implementing B_OP_COPY for text on B_RGBA32.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DRAWING_MODE_COPY_TEXT_H
|
||||
#define DRAWING_MODE_COPY_TEXT_H
|
||||
|
||||
#include "DrawingModeCopy.h"
|
||||
|
||||
// blend_pixel_copy_text
|
||||
void
|
||||
blend_pixel_copy_text(int x, int y, const color_type& c, uint8 cover,
|
||||
agg_buffer* buffer, const PatternHandler* pattern)
|
||||
{
|
||||
uint8* p = buffer->row_ptr(y) + (x << 2);
|
||||
if (cover == 255) {
|
||||
ASSIGN_COPY(p, c.r, c.g, c.b, c.a);
|
||||
} else {
|
||||
rgb_color l = pattern->LowColor();
|
||||
BLEND_COPY(p, c.r, c.g, c.b, cover,
|
||||
l.red, l.green, l.blue);
|
||||
}
|
||||
}
|
||||
|
||||
// blend_hline_copy_text
|
||||
void
|
||||
blend_hline_copy_text(int x, int y, unsigned len,
|
||||
const color_type& c, uint8 cover,
|
||||
agg_buffer* buffer, const PatternHandler* pattern)
|
||||
{
|
||||
if (cover == 255) {
|
||||
// cache the color as 32bit value
|
||||
uint32 v;
|
||||
uint8* p8 = (uint8*)&v;
|
||||
p8[0] = (uint8)c.b;
|
||||
p8[1] = (uint8)c.g;
|
||||
p8[2] = (uint8)c.r;
|
||||
p8[3] = 255;
|
||||
// row offset as 32bit pointer
|
||||
uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x;
|
||||
do {
|
||||
*p32 = v;
|
||||
p32++;
|
||||
} while(--len);
|
||||
} else {
|
||||
uint8* p = buffer->row_ptr(y) + (x << 2);
|
||||
rgb_color l = pattern->LowColor();
|
||||
do {
|
||||
BLEND_COPY(p, c.r, c.g, c.b, cover,
|
||||
l.red, l.green, l.blue);
|
||||
p += 4;
|
||||
} while(--len);
|
||||
}
|
||||
}
|
||||
|
||||
// blend_solid_hspan_copy_text
|
||||
void
|
||||
blend_solid_hspan_copy_text(int x, int y, unsigned len,
|
||||
const color_type& c, const uint8* covers,
|
||||
agg_buffer* buffer,
|
||||
const PatternHandler* pattern)
|
||||
{
|
||||
//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();
|
||||
do {
|
||||
// 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++;
|
||||
// p += 4;
|
||||
} while(--len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// blend_solid_vspan_copy_text
|
||||
void
|
||||
blend_solid_vspan_copy_text(int x, int y, unsigned len,
|
||||
const color_type& c, const uint8* covers,
|
||||
agg_buffer* buffer,
|
||||
const PatternHandler* pattern)
|
||||
{
|
||||
uint8* p = buffer->row_ptr(y) + (x << 2);
|
||||
rgb_color l = pattern->LowColor();
|
||||
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);
|
||||
}
|
||||
}
|
||||
covers++;
|
||||
p += buffer->stride();
|
||||
} while(--len);
|
||||
}
|
||||
|
||||
|
||||
// blend_color_hspan_copy_text
|
||||
void
|
||||
blend_color_hspan_copy_text(int x, int y, unsigned len,
|
||||
const color_type* colors, const uint8* covers,
|
||||
uint8 cover,
|
||||
agg_buffer* buffer,
|
||||
const PatternHandler* pattern)
|
||||
{
|
||||
uint8* p = buffer->row_ptr(y) + (x << 2);
|
||||
rgb_color l = pattern->LowColor();
|
||||
if (covers) {
|
||||
// non-solid opacity
|
||||
do {
|
||||
if(*covers) {
|
||||
if(*covers == 255) {
|
||||
ASSIGN_COPY(p, colors->r, colors->g, colors->b, colors->a);
|
||||
} else {
|
||||
BLEND_COPY(p, colors->r, colors->g, colors->b, *covers,
|
||||
l.red, l.green, l.blue);
|
||||
}
|
||||
}
|
||||
covers++;
|
||||
p += 4;
|
||||
++colors;
|
||||
} while(--len);
|
||||
} else {
|
||||
// solid full opcacity
|
||||
if (cover == 255) {
|
||||
do {
|
||||
ASSIGN_COPY(p, colors->r, colors->g, colors->b, colors->a);
|
||||
p += 4;
|
||||
++colors;
|
||||
} while(--len);
|
||||
// solid partial opacity
|
||||
} else if (cover) {
|
||||
do {
|
||||
BLEND_COPY(p, colors->r, colors->g, colors->b, cover,
|
||||
l.red, l.green, l.blue);
|
||||
p += 4;
|
||||
++colors;
|
||||
} while(--len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DRAWING_MODE_COPY_TEXT_H
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* Copyright 2008, Andrej Spielmann <andrej.spielmann@seh.ox.ac.uk>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
* DrawingMode implementing B_OP_COPY for text on B_RGBA32.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DRAWING_MODE_COPY_TEXT_SUBPIX_H
|
||||
#define DRAWING_MODE_COPY_TEXT_SUBPIX_H
|
||||
|
||||
#include "DrawingModeCopySUBPIX.h"
|
||||
#include "GlobalSubpixelSettings.h"
|
||||
|
||||
// blend_solid_hspan_copy_text_subpix
|
||||
void
|
||||
blend_solid_hspan_copy_text_subpix(int x, int y, unsigned len,
|
||||
const color_type& c, const uint8* covers, agg_buffer* buffer,
|
||||
const PatternHandler* pattern)
|
||||
{
|
||||
//printf("blend_solid_hspan_copy_text(%d, %d)\n", x, len);
|
||||
uint8* p = buffer->row_ptr(y) + (x << 2);
|
||||
rgb_color l = pattern->LowColor();
|
||||
const int subpixelL = gSubpixelOrderingRGB ? 2 : 0;
|
||||
const int subpixelM = 1;
|
||||
const int subpixelR = gSubpixelOrderingRGB ? 0 : 2;
|
||||
do {
|
||||
BLEND_COPY_SUBPIX(p, c.r, c.g, c.b, covers[subpixelL],
|
||||
covers[subpixelM], covers[subpixelR], l.red, l.green, l.blue);
|
||||
covers += 3;
|
||||
p += 4;
|
||||
x++;
|
||||
len -= 3;
|
||||
} while (len);
|
||||
}
|
||||
|
||||
#endif // DRAWING_MODE_COPY_TEXT_SUBPIX_H
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "DrawingModeBlend.h"
|
||||
#include "DrawingModeCopy.h"
|
||||
#include "DrawingModeCopySolid.h"
|
||||
#include "DrawingModeCopyText.h"
|
||||
#include "DrawingModeErase.h"
|
||||
#include "DrawingModeInvert.h"
|
||||
#include "DrawingModeMin.h"
|
||||
@ -46,7 +45,6 @@
|
||||
#include "DrawingModeBlendSUBPIX.h"
|
||||
#include "DrawingModeCopySUBPIX.h"
|
||||
#include "DrawingModeCopySolidSUBPIX.h"
|
||||
#include "DrawingModeCopyTextSUBPIX.h"
|
||||
#include "DrawingModeEraseSUBPIX.h"
|
||||
#include "DrawingModeInvertSUBPIX.h"
|
||||
#include "DrawingModeMinSUBPIX.h"
|
||||
@ -139,7 +137,6 @@ PixelFormat::PixelFormat(agg::rendering_buffer& rb,
|
||||
const PatternHandler* handler)
|
||||
: fBuffer(&rb),
|
||||
fPatternHandler(handler),
|
||||
fUsesOpCopyForText(false),
|
||||
|
||||
fBlendPixel(blend_pixel_empty),
|
||||
fBlendHLine(blend_hline_empty),
|
||||
@ -162,10 +159,9 @@ void
|
||||
PixelFormat::SetDrawingMode(drawing_mode mode, source_alpha alphaSrcMode,
|
||||
alpha_function alphaFncMode, bool text)
|
||||
{
|
||||
fUsesOpCopyForText = false;
|
||||
switch (mode) {
|
||||
// these drawing modes discard source pixels
|
||||
// which have the current low color
|
||||
// These drawing modes discard source pixels
|
||||
// which have the current low color.
|
||||
case B_OP_OVER:
|
||||
if (fPatternHandler->IsSolid()) {
|
||||
fBlendPixel = blend_pixel_over_solid;
|
||||
@ -207,21 +203,10 @@ PixelFormat::SetDrawingMode(drawing_mode mode, source_alpha alphaSrcMode,
|
||||
fBlendColorHSpan = blend_color_hspan_select;
|
||||
break;
|
||||
|
||||
// in these drawing modes, the current high
|
||||
// and low color are treated equally
|
||||
// In these drawing modes, the current high
|
||||
// and low color are treated equally.
|
||||
case B_OP_COPY:
|
||||
if (text) {
|
||||
fBlendPixel = blend_pixel_copy_text;
|
||||
fBlendHLine = blend_hline_copy_text;
|
||||
fBlendSolidHSpanSubpix = blend_solid_hspan_copy_text_subpix;
|
||||
fBlendSolidHSpan = blend_solid_hspan_copy_text;
|
||||
fBlendSolidVSpan = blend_solid_vspan_copy_text;
|
||||
fBlendColorHSpan = blend_color_hspan_copy_text;
|
||||
// set the special flag so that Painter
|
||||
// knows if an update is needed even though
|
||||
// "nothing changed"
|
||||
fUsesOpCopyForText = true;
|
||||
} else if (fPatternHandler->IsSolid()) {
|
||||
if (fPatternHandler->IsSolid()) {
|
||||
fBlendPixel = blend_pixel_copy_solid;
|
||||
fBlendHLine = blend_hline_copy_solid;
|
||||
fBlendSolidHSpanSubpix = blend_solid_hspan_copy_solid_subpix;
|
||||
@ -278,7 +263,7 @@ PixelFormat::SetDrawingMode(drawing_mode mode, source_alpha alphaSrcMode,
|
||||
fBlendColorHSpan = blend_color_hspan_max;
|
||||
break;
|
||||
|
||||
// this drawing mode is the only one considering
|
||||
// This drawing mode is the only one considering
|
||||
// alpha at all. In B_CONSTANT_ALPHA, the alpha
|
||||
// value from the current high color is used for
|
||||
// all computations. In B_PIXEL_ALPHA, the alpha
|
||||
|
@ -71,9 +71,6 @@ class PixelFormat {
|
||||
alpha_function alphaFncMode,
|
||||
bool text);
|
||||
|
||||
inline bool UsesOpCopyForText() const
|
||||
{ return fUsesOpCopyForText; }
|
||||
|
||||
// AGG "pixel format" interface
|
||||
inline unsigned width() const
|
||||
{ return fBuffer->width(); }
|
||||
@ -140,7 +137,6 @@ class PixelFormat {
|
||||
private:
|
||||
agg::rendering_buffer* fBuffer;
|
||||
const PatternHandler* fPatternHandler;
|
||||
bool fUsesOpCopyForText;
|
||||
|
||||
blend_pixel_f fBlendPixel;
|
||||
blend_line fBlendHLine;
|
||||
|
Loading…
Reference in New Issue
Block a user