A test I am currently working on which is supposed to behave a bit like

Firefox. It stores the active clipping region of a view when Draw() is
invoked, and uses that for asynchronous drawing. The test already shows
a couple of problems. When PushState() / PopState() is used, it is not
equivalent to ConstrainClippingRegion(&someRegion) /
ConstrainClippingRegion(NULL). Another problem shows when adding delays
(currently disabled), there should not be any difference, regardless of
how much delay is inserted into the asynchronous drawing.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25150 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2008-04-25 10:53:23 +00:00
parent b35b070b59
commit cda5b8808f
3 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,17 @@
SubDir HAIKU_TOP src tests servers app scrollbar ;
SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ;
UseHeaders [ FDirName os app ] ;
UseHeaders [ FDirName os interface ] ;
SimpleTest AsyncDrawing :
main.cpp
: be ;
if ( $(TARGET_PLATFORM) = libbe_test ) {
HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : AsyncDrawing
: tests!apps ;
}

View File

@ -0,0 +1,120 @@
#include <stdio.h>
#include <Application.h>
#include <Region.h>
#include <View.h>
#include <Window.h>
enum {
MSG_REDRAW = 'shhd'
};
#define TEST_DELAYS 0
class View : public BView {
public:
View(BRect frame, uint8 r, uint8 g, uint8 b, uint8 a)
: BView(frame, "view", B_FOLLOW_ALL, B_WILL_DRAW)
{
SetDrawingMode(B_OP_ALPHA);
SetHighColor(r, g, b, a);
}
virtual void Draw(BRect updateRect)
{
BRegion region;
GetClippingRegion(&region);
BMessage message(MSG_REDRAW);
int32 count = region.CountRects();
for (int32 i = 0; i < count; i++)
message.AddRect("rect", region.RectAt(i));
be_app->PostMessage(&message);
}
void AsyncRedraw(BRegion& region)
{
if (!LockLooper())
return;
#if 0
ConstrainClippingRegion(&region);
FillRect(Bounds());
ConstrainClippingRegion(NULL);
#else
PushState();
ConstrainClippingRegion(&region);
FillRect(Bounds());
PopState();
#endif
UnlockLooper();
}
};
class Application : public BApplication {
public:
Application()
: BApplication("application/x-vnd.stippi-async.drawing")
, fDelay(true)
{
BWindow* window = new BWindow(BRect(50, 50, 350, 250),
"Test Window", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_QUIT_ON_WINDOW_CLOSE);
fView = new View(window->Bounds(), 255, 80, 155, 128);
window->AddChild(fView);
window->Show();
window = new BWindow(BRect(150, 150, 450, 350),
"Drag Window", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_QUIT_ON_WINDOW_CLOSE);
window->Show();
SetPulseRate(100000);
}
virtual void Pulse()
{
fDelay = true;
}
virtual void MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_REDRAW:
{
#if TEST_DELAYS
if (fDelay) {
snooze(200000);
fDelay = false;
}
#endif
BRegion region;
BRect rect;
for (int32 i = 0;
message->FindRect("rect", i, &rect) == B_OK; i++)
region.Include(rect);
fView->AsyncRedraw(region);
break;
}
default:
BApplication::MessageReceived(message);
break;
}
}
private:
View* fView;
bool fDelay;
};
int
main(int argc, char* argv[])
{
Application app;
app.Run();
return 0;
}

View File

@ -0,0 +1,18 @@
#!/bin/sh
../../../../../generated/tests/libbe_test/x86/apps/run_haiku_registrar || exit
if test -f ../../../../../generated/tests/libbe_test/x86/apps/haiku_app_server; then
../../../../../generated/tests/libbe_test/x86/apps/haiku_app_server &
else
echo "You need to \"TARGET_PLATFORM=r5 jam install-test-apps\" first."
fi
sleep 1s
if test -f ../../../../../generated/tests/libbe_test/x86/apps/AsyncDrawing; then
../../../../../generated/tests/libbe_test/x86/apps/AsyncDrawing
else
echo "You need to \"TARGET_PLATFORM=r5 jam install-test-apps\" first."
fi