refactoring, but there's going to be even more of it
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11104 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -17,6 +17,116 @@ const pattern kStripes = (pattern){ { 0xc7, 0x8f, 0x1f, 0x3e, 0x7c, 0xf8, 0xf1,
|
||||
const pattern kDotted = (pattern){ { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa } };
|
||||
const pattern kDottedBigger = (pattern){ { 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc } };
|
||||
|
||||
template<class Surface>
|
||||
bigtime_t
|
||||
test(Surface& s,
|
||||
uint32 width, uint32 height, BPoint origin, float scale,
|
||||
float penSize,
|
||||
rgb_color lineColor1, rgb_color lineColor2,
|
||||
BRect rect, BRect roundRect,
|
||||
rgb_color rectColorH, rgb_color rectColorL,
|
||||
float angle, float span, rgb_color arcColor,
|
||||
rgb_color ellipseColorH, rgb_color ellipseColorL,
|
||||
BPoint center, float xRadius, float yRadius,
|
||||
rgb_color roundRectColorH, rgb_color roundRectColorL,
|
||||
BFont* font, BPoint stringLocation1, BPoint stringLocation2,
|
||||
const char* string1, const char* string2,
|
||||
rgb_color textColor1, rgb_color textColor2, rgb_color alphaColor,
|
||||
BBitmap* testBitmap, BRect testBitmapCrop, BRect testBitmapDestRect)
|
||||
{
|
||||
bigtime_t now = system_time();
|
||||
|
||||
s.SetOrigin(origin);
|
||||
s.SetScale(scale);
|
||||
|
||||
s.SetDrawingMode(B_OP_COPY);
|
||||
// s.SetDrawingMode(B_OP_SUBTRACT);
|
||||
// s.SetDrawingMode(B_OP_OVER);
|
||||
s.SetHighColor(lineColor1);
|
||||
s.SetLowColor(lineColor2);
|
||||
for (uint32 y = 0; y <= height / 2; y += 10)
|
||||
s.StrokeLine(BPoint(0, 0), BPoint(width / 2, y)/*, kDottedBigger*/);
|
||||
for (uint32 x = 0; x <= width; x += 10)
|
||||
s.StrokeLine(BPoint(0, 0), BPoint(x, height)/*, kDottedBigger*/);
|
||||
s.SetPenSize(penSize * 5);
|
||||
s.SetHighColor(rectColorH);
|
||||
s.SetLowColor(rectColorL);
|
||||
// s.SetScale(1.0);
|
||||
// s.SetOrigin(B_ORIGIN);
|
||||
// s.SetDrawingMode(B_OP_INVERT);
|
||||
s.SetDrawingMode(B_OP_COPY);
|
||||
// s.StrokeRect(rect);
|
||||
s.StrokeRect(rect, kStripes);
|
||||
|
||||
// s.ConstrainClipping(noClip);
|
||||
/* s.SetPenLocation(BPoint(230.0, 30.0));
|
||||
s.StrokeLine(BPoint(250.0, 30.0));
|
||||
s.StrokeLine(BPoint(250.0, 50.0));
|
||||
s.StrokeLine(BPoint(230.0, 50.0));
|
||||
s.StrokeLine(BPoint(230.0, 30.0));*/
|
||||
|
||||
s.SetHighColor(ellipseColorH);
|
||||
s.SetLowColor(ellipseColorL);
|
||||
// s.SetDrawingMode(B_OP_OVER);
|
||||
s.SetDrawingMode(B_OP_ERASE);
|
||||
s.StrokeEllipse(center, xRadius, yRadius, kDottedBigger);
|
||||
s.SetHighColor(arcColor);
|
||||
s.SetDrawingMode(B_OP_INVERT);
|
||||
s.FillArc(center, xRadius * 2, yRadius * 2, angle, span);
|
||||
// s.StrokeArc(center, xRadius * 2, yRadius * 2, angle, span);
|
||||
s.SetDrawingMode(B_OP_OVER);
|
||||
s.SetPenSize(2.0);
|
||||
s.StrokeEllipse(center, xRadius * 3, yRadius * 2);
|
||||
// s.FillEllipse(center, xRadius * 3, yRadius * 2);
|
||||
// s.StrokeLine(bounds.RightTop());
|
||||
// s.FillRect(rect);
|
||||
s.SetHighColor(roundRectColorH);
|
||||
s.SetLowColor(roundRectColorL);
|
||||
s.SetPenSize(1.0);
|
||||
// s.SetDrawingMode(B_OP_SELECT);
|
||||
s.StrokeRoundRect(roundRect, 40, 40);
|
||||
// s.FillRoundRect(roundRect, 40, 40);
|
||||
|
||||
s.SetFont(font);
|
||||
s.SetHighColor(textColor1);
|
||||
s.SetDrawingMode(B_OP_OVER);
|
||||
s.DrawString(string1, stringLocation1);
|
||||
s.DrawString(string2);
|
||||
s.StrokeLine(BPoint(width - 1, 0));
|
||||
|
||||
// s.SetScale(2.5);
|
||||
s.SetDrawingMode(B_OP_INVERT);
|
||||
s.SetHighColor(textColor2);
|
||||
s.DrawString("H", stringLocation2);
|
||||
s.DrawString("e");
|
||||
s.DrawString("l");
|
||||
s.DrawString("l");
|
||||
s.DrawString("o");
|
||||
s.DrawString(" ");
|
||||
s.DrawString("N");
|
||||
s.DrawString("u");
|
||||
s.DrawString("r");
|
||||
s.DrawString("s");
|
||||
s.DrawString("e");
|
||||
s.DrawString("!");
|
||||
// s.SetHighColor(0, 60, 240);
|
||||
// s.DrawString("Hello Nurse!", stringLocation2);
|
||||
|
||||
// bitmap drawing
|
||||
s.SetScale(1.5);
|
||||
s.SetDrawingMode(B_OP_ALPHA);
|
||||
// s.SetDrawingMode(B_OP_SELECT);
|
||||
// s.SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
|
||||
s.SetHighColor(alphaColor);
|
||||
s.DrawBitmap(testBitmap, testBitmapCrop, testBitmapDestRect);
|
||||
|
||||
s.Sync();
|
||||
|
||||
return system_time() - now;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// main
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@@ -61,28 +171,32 @@ fprintf(stdout, "done\n");
|
||||
float penSize = 3.0;
|
||||
float scale = 1.0;
|
||||
rgb_color lineColor1 = (rgb_color){ 20, 20, 20, 255 };
|
||||
// rgb_color lineColor2 = (rgb_color){ 20, 20, 20, 255 };
|
||||
rgb_color textColor1 = (rgb_color){ 200, 200, 200, 255 };
|
||||
rgb_color lineColor2 = (rgb_color){ 220, 120, 80, 255 };
|
||||
rgb_color textColor1 = (rgb_color){ 91, 105, 98, 120 };
|
||||
rgb_color textColor2 = (rgb_color){ 200, 200, 200, 255 };
|
||||
// rgb_color textColor2 = (rgb_color){ 200, 200, 200, 255 };
|
||||
rgb_color rectColorH = (rgb_color){ 255, 0, 0, 255 };
|
||||
rgb_color rectColorL = (rgb_color){ 0, 0, 255, 255 };
|
||||
rgb_color arcColor = (rgb_color){ 255, 0, 0, 255 };
|
||||
rgb_color ellipseColorH = (rgb_color){ 255, 255, 0, 255 };
|
||||
rgb_color ellipseColorL = (rgb_color){ 128, 0, 50, 255 };
|
||||
rgb_color roundRectColor = (rgb_color){ 0, 0, 255, 255 };
|
||||
rgb_color roundRectColorH = (rgb_color){ 0, 0, 255, 255 };
|
||||
rgb_color roundRectColorL = (rgb_color){ 255, 0, 0, 255 };
|
||||
rgb_color alphaColor = (rgb_color){ 0, 0, 0, 120 };
|
||||
|
||||
// TODO: Painter behaves differently when origin has subpixel offset
|
||||
// BPoint origin(20.3, 10.8);
|
||||
BPoint origin(20, 10);
|
||||
BRect rect(20.2, 45.6, 219.0, 139.0);
|
||||
BRect rect2(40, 100, 250, 220.0);
|
||||
BRect roundRect(40, 100, 250, 220.0);
|
||||
BPoint center(bounds.Width() / 2.0, bounds.Height() / 2.0);
|
||||
float xRadius = 30.0;
|
||||
float yRadius = 20.0;
|
||||
float angle = 40.0;
|
||||
float span = 230.0;
|
||||
const char* string = "The Quick Brown Fox...";
|
||||
const char* string1 = "The Quick Brown Fox...";
|
||||
const char* string2 = "jumps!";
|
||||
BPoint stringLocation(10.0, 220.0);
|
||||
BPoint stringLocation1(10.0, 220.0);
|
||||
BPoint stringLocation2(30.0 / 2.5, 115.0 / 2.5);
|
||||
BFont font(be_plain_font);
|
||||
font.SetSize(12.0);
|
||||
@@ -101,7 +215,7 @@ fprintf(stdout, "done\n");
|
||||
h[0] = (uint8)((float)x / (float)bitmapWidth * 255.0);
|
||||
h[1] = (uint8)((float)y / (float)bitmapHeight * 255.0);
|
||||
h[2] = 255 - (uint8)((float)y / (float)bitmapHeight * 255.0);
|
||||
h[3] = 255;
|
||||
h[3] = (uint8)((float)y / (float)bitmapHeight * 255.0);
|
||||
h += 4;
|
||||
}
|
||||
bits += bpr;
|
||||
@@ -132,86 +246,33 @@ fprintf(stdout, "done\n");
|
||||
uint32 height = buffer->Height();
|
||||
|
||||
// painter.ConstrainClipping(clip);
|
||||
painter.SetScale(scale);
|
||||
// painter.SetPenSize(penSize);
|
||||
painter.SetOrigin(origin);
|
||||
|
||||
bigtime_t painterNow = system_time();
|
||||
int32 iterations = 20;
|
||||
|
||||
painter.SetDrawingMode(B_OP_SUBTRACT);
|
||||
painter.SetHighColor(lineColor1);
|
||||
for (uint32 y = 0; y <= height / 2; y += 10)
|
||||
painter.StrokeLine(BPoint(0, 0), BPoint(width / 2, y));
|
||||
for (uint32 x = 0; x <= width; x += 10)
|
||||
painter.StrokeLine(BPoint(0, 0), BPoint(x, height));
|
||||
painter.SetPenSize(penSize * 5);
|
||||
painter.SetHighColor(rectColorH);
|
||||
painter.SetLowColor(rectColorL);
|
||||
// painter.SetScale(1.0);
|
||||
// painter.SetOrigin(B_ORIGIN);
|
||||
// painter.SetDrawingMode(B_OP_INVERT);
|
||||
painter.SetDrawingMode(B_OP_COPY);
|
||||
// painter.StrokeRect(rect);
|
||||
painter.StrokeRect(rect, kStripes);
|
||||
fprintf(stdout, "Painter...");
|
||||
fflush(stdout);
|
||||
|
||||
// painter.ConstrainClipping(noClip);
|
||||
/* painter.SetPenLocation(BPoint(230.0, 30.0));
|
||||
painter.StrokeLine(BPoint(250.0, 30.0));
|
||||
painter.StrokeLine(BPoint(250.0, 50.0));
|
||||
painter.StrokeLine(BPoint(230.0, 50.0));
|
||||
painter.StrokeLine(BPoint(230.0, 30.0));*/
|
||||
bigtime_t painterNow = 0;
|
||||
for (int32 i = 0; i < iterations; i++) {
|
||||
// reset bitmap contents
|
||||
memset(bitmap->Bits(), 255, bitmap->BitsLength());
|
||||
// run test
|
||||
painterNow += test(painter,
|
||||
width, height, origin, scale, penSize,
|
||||
lineColor1, lineColor2,
|
||||
rect, roundRect,
|
||||
rectColorH, rectColorL,
|
||||
angle, span, arcColor,
|
||||
ellipseColorH, ellipseColorL,
|
||||
center, xRadius, yRadius,
|
||||
roundRectColorH, roundRectColorL,
|
||||
&font, stringLocation1, stringLocation2,
|
||||
string1, string2,
|
||||
textColor1, textColor2, alphaColor,
|
||||
testBitmap, testBitmapCrop, testBitmapDestRect);
|
||||
}
|
||||
|
||||
painter.SetHighColor(ellipseColorH);
|
||||
painter.SetLowColor(ellipseColorL);
|
||||
painter.SetDrawingMode(B_OP_OVER);
|
||||
painter.StrokeEllipse(center, xRadius, yRadius, kDottedBigger);
|
||||
painter.SetHighColor(arcColor);
|
||||
painter.SetDrawingMode(B_OP_INVERT);
|
||||
painter.FillArc(center, xRadius * 2, yRadius * 2, angle, span);
|
||||
// painter.StrokeArc(center, xRadius * 2, yRadius * 2, angle, span);
|
||||
painter.SetDrawingMode(B_OP_OVER);
|
||||
painter.SetPenSize(2.0);
|
||||
painter.StrokeEllipse(center, xRadius * 3, yRadius * 2);
|
||||
// painter.FillEllipse(center, xRadius * 3, yRadius * 2);
|
||||
// painter.StrokeLine(bounds.RightTop());
|
||||
// painter.FillRect(rect);
|
||||
painter.SetHighColor(roundRectColor);
|
||||
painter.SetPenSize(1.0);
|
||||
painter.StrokeRoundRect(rect2, 40, 40);
|
||||
// painter.FillRoundRect(rect2, 40, 40);
|
||||
|
||||
painter.SetFont(font);
|
||||
painter.SetHighColor(textColor1);
|
||||
painter.SetDrawingMode(B_OP_OVER);
|
||||
painter.DrawString(string, stringLocation);
|
||||
painter.DrawString(string2);
|
||||
painter.StrokeLine(bounds.RightTop());
|
||||
|
||||
// painter.SetScale(2.5);
|
||||
painter.SetDrawingMode(B_OP_INVERT);
|
||||
painter.DrawString("H", stringLocation2);
|
||||
painter.DrawString("e");
|
||||
painter.DrawString("l");
|
||||
painter.DrawString("l");
|
||||
painter.DrawString("o");
|
||||
painter.DrawString(" ");
|
||||
painter.DrawString("N");
|
||||
painter.DrawString("u");
|
||||
painter.DrawString("r");
|
||||
painter.DrawString("s");
|
||||
painter.DrawString("e");
|
||||
painter.DrawString("!");
|
||||
// painter.SetHighColor(0, 60, 240);
|
||||
// painter.DrawString("Hello Nurse!", stringLocation2);
|
||||
|
||||
// bitmap drawing
|
||||
painter.SetScale(1.5);
|
||||
painter.SetDrawingMode(B_OP_BLEND);
|
||||
painter.DrawBitmap(testBitmap, testBitmapCrop, testBitmapDestRect);
|
||||
|
||||
|
||||
painterNow = system_time() - painterNow;
|
||||
printf("Painter: %lld µsecs\n", painterNow);
|
||||
fprintf(stdout, " %lld µsecs\n", painterNow / iterations);
|
||||
|
||||
BitmapView* painterView = new BitmapView(bounds, "view", bitmap);
|
||||
|
||||
@@ -222,90 +283,36 @@ printf("Painter: %lld µsecs\n", painterNow);
|
||||
bitmap->AddChild(view);
|
||||
|
||||
// view->ConstrainClippingRegion(&clip);
|
||||
view->SetScale(scale);
|
||||
// view->SetPenSize(penSize);
|
||||
view->SetOrigin(origin);
|
||||
|
||||
bigtime_t viewNow = system_time();
|
||||
fprintf(stdout, "BView...");
|
||||
fflush(stdout);
|
||||
|
||||
view->SetDrawingMode(B_OP_SUBTRACT);
|
||||
view->SetHighColor(lineColor1);
|
||||
for (uint32 y = 0; y <= height / 2; y += 10)
|
||||
view->StrokeLine(BPoint(0, 0), BPoint(width / 2, y));
|
||||
for (uint32 x = 0; x <= width; x += 10)
|
||||
view->StrokeLine(BPoint(0, 0), BPoint(x, height));
|
||||
view->SetPenSize(penSize * 5);
|
||||
view->SetHighColor(rectColorH);
|
||||
view->SetLowColor(rectColorL);
|
||||
// view->SetScale(1.0);
|
||||
// view->SetOrigin(B_ORIGIN);
|
||||
// view->SetDrawingMode(B_OP_INVERT);
|
||||
view->SetDrawingMode(B_OP_COPY);
|
||||
// view->StrokeRect(rect);
|
||||
view->StrokeRect(rect, kStripes);
|
||||
bigtime_t viewNow = 0;
|
||||
for (int32 i = 0; i < iterations; i++) {
|
||||
// reset bitmap contents
|
||||
memset(bitmap->Bits(), 255, bitmap->BitsLength());
|
||||
// run test
|
||||
viewNow += test(*view,
|
||||
width, height, origin, scale, penSize,
|
||||
lineColor1, lineColor2,
|
||||
rect, roundRect,
|
||||
rectColorH, rectColorL,
|
||||
angle, span, arcColor,
|
||||
ellipseColorH, ellipseColorL,
|
||||
center, xRadius, yRadius,
|
||||
roundRectColorH, roundRectColorL,
|
||||
&font, stringLocation1, stringLocation2,
|
||||
string1, string2,
|
||||
textColor1, textColor2, alphaColor,
|
||||
testBitmap, testBitmapCrop, testBitmapDestRect);
|
||||
}
|
||||
|
||||
// view->ConstrainClippingRegion(&noClip);
|
||||
/* view->MovePenTo(BPoint(230.0, 30.0));
|
||||
view->StrokeLine(BPoint(250.0, 30.0));
|
||||
view->StrokeLine(BPoint(250.0, 50.0));
|
||||
view->StrokeLine(BPoint(230.0, 50.0));
|
||||
view->StrokeLine(BPoint(230.0, 30.0));*/
|
||||
fprintf(stdout, " %lld µsecs\n", viewNow / iterations);
|
||||
|
||||
view->SetHighColor(ellipseColorH);
|
||||
view->SetLowColor(ellipseColorL);
|
||||
view->SetDrawingMode(B_OP_OVER);
|
||||
view->StrokeEllipse(center, xRadius, yRadius, kDottedBigger);
|
||||
view->SetDrawingMode(B_OP_INVERT);
|
||||
view->SetHighColor(arcColor);
|
||||
view->FillArc(center, xRadius * 2, yRadius * 2, angle, span);
|
||||
// view->StrokeArc(center, xRadius * 2, yRadius * 2, angle, span);
|
||||
view->SetDrawingMode(B_OP_OVER);
|
||||
view->SetPenSize(2.0);
|
||||
view->StrokeEllipse(center, xRadius * 3, yRadius * 2);
|
||||
// view->FillEllipse(center, xRadius * 3, yRadius * 2);
|
||||
// view->StrokeLine(bounds.RightTop());
|
||||
// view->FillRect(rect);
|
||||
view->SetHighColor(roundRectColor);
|
||||
view->SetPenSize(1.0);
|
||||
view->StrokeRoundRect(rect2, 40, 40);
|
||||
// view->FillRoundRect(rect2, 40, 40);
|
||||
|
||||
// text drawing
|
||||
view->SetFont(&font);
|
||||
view->SetHighColor(textColor1);
|
||||
view->SetDrawingMode(B_OP_OVER);
|
||||
view->DrawString(string, stringLocation);
|
||||
view->DrawString(string2);
|
||||
view->StrokeLine(bounds.RightTop());
|
||||
|
||||
// view->SetScale(2.5);
|
||||
view->SetDrawingMode(B_OP_INVERT);
|
||||
view->DrawString("H", stringLocation2);
|
||||
view->DrawString("e");
|
||||
view->DrawString("l");
|
||||
view->DrawString("l");
|
||||
view->DrawString("o");
|
||||
view->DrawString(" ");
|
||||
view->DrawString("N");
|
||||
view->DrawString("u");
|
||||
view->DrawString("r");
|
||||
view->DrawString("s");
|
||||
view->DrawString("e");
|
||||
view->DrawString("!");
|
||||
// view->SetHighColor(0, 60, 240);
|
||||
// view->DrawString("Hello Nurse!", stringLocation2);
|
||||
|
||||
// bitmap drawing
|
||||
view->SetScale(1.5);
|
||||
view->SetLowColor(0, 0, 0, 0);
|
||||
view->SetDrawingMode(B_OP_BLEND);
|
||||
view->DrawBitmap(testBitmap, testBitmapCrop, testBitmapDestRect);
|
||||
|
||||
view->Sync();
|
||||
|
||||
viewNow = system_time() - viewNow;
|
||||
printf("BView: %lld µsecs\n", viewNow);
|
||||
printf("BView is %lld times faster.\n", painterNow / viewNow);
|
||||
if (painterNow > viewNow)
|
||||
printf("BView is %.2f times faster.\n", (float)painterNow / (float)viewNow);
|
||||
else
|
||||
printf("Painter is %.2f times faster.\n", (float)viewNow / (float)painterNow);
|
||||
|
||||
bitmap->Unlock();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user