6 #include <Application.h>
13 static BRect
* sFrames
= NULL
;
14 static uint32 sNumFrames
= 0;
17 class TestApp
: public BApplication
{
19 TestApp(uint32 numWindows
, bool views
);
22 virtual void ReadyToRun();
25 void _CreateFrames(uint32 numWindows
);
26 int32
_WindowCreator();
27 static int32
_ThreadStarter(void* data
);
38 class TestWindow
: public BWindow
{
40 TestWindow(BRect frame
, bool createView
);
41 virtual ~TestWindow();
45 TestApp::TestApp(uint32 numWindows
, bool views
)
47 BApplication("application/x.vnd-Haiku.window-creation"),
50 fMaxWindows(numWindows
),
54 fScreenFrame
= BScreen().Frame();
55 _CreateFrames(numWindows
);
68 thread_id thread
= spawn_thread(_ThreadStarter
, "Window creator",
69 B_NORMAL_PRIORITY
, this);
70 resume_thread(thread
);
75 TestApp::_CreateFrames(uint32 numWindows
)
77 BRect
frame(0, 0, 50, 50);
78 uint32 numHorizontal
= (fScreenFrame
.IntegerWidth() + 1)
79 / (frame
.IntegerWidth() + 1);
80 uint32 numVertical
= (fScreenFrame
.IntegerHeight() + 1)
81 / (frame
.IntegerHeight() + 1);
82 sNumFrames
= numHorizontal
* numVertical
;
83 sFrames
= new BRect
[sNumFrames
];
84 for (uint32 i
= 0; i
< sNumFrames
; i
++) {
86 frame
.OffsetBy(50, 0);
87 if (!fScreenFrame
.Contains(frame
))
88 frame
.OffsetTo(0, frame
.bottom
+ 1);
94 TestApp::_WindowCreator()
96 bigtime_t startTime
= system_time();
98 while (fNumWindows
< fMaxWindows
) {
99 if (fFrameNum
>= sNumFrames
)
102 BWindow
* window
= new TestWindow(sFrames
[fFrameNum
++], fTestViews
);
107 bigtime_t endTime
= system_time();
109 printf("Test completed. %ld windows created in %lld usecs.\n", fNumWindows
,
110 endTime
- startTime
);
112 PostMessage(B_QUIT_REQUESTED
);
118 TestApp::_ThreadStarter(void* data
)
120 return static_cast<TestApp
*>(data
)->_WindowCreator();
124 TestWindow::TestWindow(BRect frame
, bool views
)
126 BWindow(frame
, "Test", B_TITLED_WINDOW
, B_ASYNCHRONOUS_CONTROLS
)
129 AddChild(new BBox(Bounds()));
133 TestWindow::~TestWindow()
139 main(int argc
, char** argv
)
141 uint32 numWindows
= 10;
142 bool testViews
= false;
144 numWindows
= atoi(argv
[1]);
147 if (!strcmp(argv
[2], "views"))
151 TestApp
app(numWindows
, testViews
);