1 #include <Application.h> 2 #include <Box.h> 3 #include <OS.h> 4 #include <Screen.h> 5 #include <Window.h> 6 7 #include <stdio.h> 8 #include <stdlib.h> 9 10 11 static BRect *sFrames = NULL; 12 static uint32 sNumFrames = 0; 13 14 15 class TestApp : public BApplication { 16 public: 17 TestApp(uint32 numWindows, bool views); 18 virtual ~TestApp(); 19 20 virtual void ReadyToRun(); 21 22 private: 23 uint32 fFrameNum; 24 BRect fScreenFrame; 25 uint32 fNumWindows; 26 uint32 fMaxWindows; 27 bool fTestViews; 28 29 void _CreateFrames(uint32 numWindows); 30 int32 _WindowCreator(); 31 static int32 _ThreadStarter(void *data); 32 }; 33 34 35 class TestWindow : public BWindow { 36 public: 37 TestWindow(BRect frame, bool createView); 38 virtual ~TestWindow(); 39 40 41 }; 42 43 44 TestApp::TestApp(uint32 numWindows, bool views) 45 : BApplication("application/x.vnd-Haiku.window-creation"), 46 fScreenFrame(), 47 fNumWindows(0), 48 fMaxWindows(numWindows), 49 fTestViews(views) 50 51 { 52 fScreenFrame = BScreen().Frame(); 53 _CreateFrames(numWindows); 54 } 55 56 57 TestApp::~TestApp() 58 { 59 delete[] sFrames; 60 } 61 62 63 void 64 TestApp::ReadyToRun() 65 { 66 thread_id thread = spawn_thread(_ThreadStarter, "Window creator", B_NORMAL_PRIORITY, this); 67 resume_thread(thread); 68 } 69 70 71 void 72 TestApp::_CreateFrames(uint32 numWindows) 73 { 74 BRect frame(0, 0, 50, 50); 75 uint32 numHorizontal = (fScreenFrame.IntegerWidth() + 1) / (frame.IntegerWidth() + 1); 76 uint32 numVertical = (fScreenFrame.IntegerHeight() + 1) / (frame.IntegerHeight() + 1); 77 sNumFrames = numHorizontal * numVertical; 78 sFrames = new BRect[sNumFrames]; 79 for (int32 i = 0; i < sNumFrames; i++) { 80 sFrames[i] = frame; 81 frame.OffsetBy(50, 0); 82 if (!fScreenFrame.Contains(frame)) 83 frame.OffsetTo(0, frame.bottom + 1); 84 } 85 } 86 87 88 int32 89 TestApp::_WindowCreator() 90 { 91 bigtime_t startTime = system_time(); 92 93 while (fNumWindows < fMaxWindows) { 94 if (fFrameNum >= sNumFrames) 95 fFrameNum = 0; 96 97 BWindow *window = new TestWindow(sFrames[fFrameNum++], fTestViews); 98 window->Show(); 99 fNumWindows++; 100 } 101 102 bigtime_t endTime = system_time(); 103 104 printf("Test completed. %ld windows created in %lld usecs.\n", fNumWindows, endTime - startTime); 105 106 PostMessage(B_QUIT_REQUESTED); 107 return B_OK; 108 } 109 110 111 int32 112 TestApp::_ThreadStarter(void *data) 113 { 114 return static_cast<TestApp *>(data)->_WindowCreator(); 115 } 116 117 118 TestWindow::TestWindow(BRect frame, bool views) 119 : BWindow(frame, "Test", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) 120 { 121 if (views) 122 AddChild(new BBox(Bounds())); 123 } 124 125 126 TestWindow::~TestWindow() 127 { 128 } 129 130 131 132 // main 133 int 134 main(int argc, char** argv) 135 { 136 uint32 numWindows = 10; 137 bool testViews = false; 138 if (argc > 1) { 139 numWindows = atoi(argv[1]); 140 } 141 142 if (argc > 2) { 143 if (!strcmp(argv[2], "views")) 144 testViews = true; 145 } 146 147 TestApp app(numWindows, testViews); 148 app.Run(); 149 150 return 0; 151 } 152