OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This tool is used to benchmark the render model used by the compositor | 5 // This tool is used to benchmark the render model used by the compositor |
6 | 6 |
7 // Most of this file is derived from the source of the tile_render_bench tool, | 7 // Most of this file is derived from the source of the tile_render_bench tool, |
8 // and has been changed to support running a sequence of independent | 8 // and has been changed to support running a sequence of independent |
9 // simulations for our different render models and test cases. | 9 // simulations for our different render models and test cases. |
10 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <sys/dir.h> | 12 #include <sys/dir.h> |
13 #include <sys/file.h> | 13 #include <sys/file.h> |
14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
15 #include <sys/types.h> | 15 #include <sys/types.h> |
16 #include <X11/keysym.h> | 16 #include <X11/keysym.h> |
17 #include <X11/Xlib.h> | 17 #include <X11/Xlib.h> |
18 #include <X11/Xutil.h> | 18 #include <X11/Xutil.h> |
19 | 19 |
20 #include <queue> | 20 #include <queue> |
21 #include <string> | 21 #include <string> |
| 22 #include <utility> |
22 #include <vector> | 23 #include <vector> |
23 | 24 |
24 #include "base/at_exit.h" | 25 #include "base/at_exit.h" |
25 #include "base/bind.h" | 26 #include "base/bind.h" |
26 #include "base/command_line.h" | 27 #include "base/command_line.h" |
27 #include "base/files/file_enumerator.h" | 28 #include "base/files/file_enumerator.h" |
28 #include "base/files/file_path.h" | 29 #include "base/files/file_path.h" |
29 #include "base/files/file_util.h" | 30 #include "base/files/file_util.h" |
30 #include "base/location.h" | 31 #include "base/location.h" |
31 #include "base/message_loop/message_loop.h" | 32 #include "base/message_loop/message_loop.h" |
(...skipping 20 matching lines...) Expand all Loading... |
52 }; | 53 }; |
53 | 54 |
54 // Forward declarations | 55 // Forward declarations |
55 class Simulator; | 56 class Simulator; |
56 void _process_events(Simulator* sim); | 57 void _process_events(Simulator* sim); |
57 void _update_loop(Simulator* sim); | 58 void _update_loop(Simulator* sim); |
58 | 59 |
59 class Simulator { | 60 class Simulator { |
60 public: | 61 public: |
61 Simulator(int seconds_per_test, const base::FilePath& output_path) | 62 Simulator(int seconds_per_test, const base::FilePath& output_path) |
62 : current_sim_(NULL), | 63 : output_path_(output_path), |
63 output_path_(output_path), | 64 seconds_per_test_(seconds_per_test), |
64 seconds_per_test_(seconds_per_test), | 65 display_(nullptr), |
65 display_(NULL), | 66 window_(0), |
66 window_(0), | 67 gl_context_(nullptr), |
67 gl_context_(NULL), | 68 window_width_(WINDOW_WIDTH), |
68 window_width_(WINDOW_WIDTH), | 69 window_height_(WINDOW_HEIGHT), |
69 window_height_(WINDOW_HEIGHT), | 70 weak_factory_(this) {} |
70 weak_factory_(this) { | |
71 } | |
72 | 71 |
73 ~Simulator() { | 72 ~Simulator() { |
74 // Cleanup GL. | 73 // Cleanup GL. |
75 glXMakeCurrent(display_, 0, NULL); | 74 glXMakeCurrent(display_, 0, nullptr); |
76 glXDestroyContext(display_, gl_context_); | 75 glXDestroyContext(display_, gl_context_); |
77 | 76 |
78 // Destroy window and display. | 77 // Destroy window and display. |
79 XDestroyWindow(display_, window_); | 78 XDestroyWindow(display_, window_); |
80 XCloseDisplay(display_); | 79 XCloseDisplay(display_); |
81 } | 80 } |
82 | 81 |
83 void QueueTest(const base::FilePath& path) { | 82 void QueueTest(const base::FilePath& path) { |
84 SimulationSpecification spec; | 83 SimulationSpecification spec; |
85 | 84 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 145 |
147 void UpdateLoop() { | 146 void UpdateLoop() { |
148 if (UpdateTestStatus()) | 147 if (UpdateTestStatus()) |
149 UpdateCurrentTest(); | 148 UpdateCurrentTest(); |
150 } | 149 } |
151 | 150 |
152 private: | 151 private: |
153 // Initialize X11. Returns true if successful. This method creates the | 152 // Initialize X11. Returns true if successful. This method creates the |
154 // X11 window. Further initialization is done in X11VideoRenderer. | 153 // X11 window. Further initialization is done in X11VideoRenderer. |
155 bool InitX11() { | 154 bool InitX11() { |
156 display_ = XOpenDisplay(NULL); | 155 display_ = XOpenDisplay(nullptr); |
157 if (!display_) { | 156 if (!display_) { |
158 LOG(FATAL) << "Cannot open display"; | 157 LOG(FATAL) << "Cannot open display"; |
159 return false; | 158 return false; |
160 } | 159 } |
161 | 160 |
162 // Get properties of the screen. | 161 // Get properties of the screen. |
163 int screen = DefaultScreen(display_); | 162 int screen = DefaultScreen(display_); |
164 int root_window = RootWindow(display_, screen); | 163 int root_window = RootWindow(display_, screen); |
165 | 164 |
166 // Creates the window. | 165 // Creates the window. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 True /* Direct rendering */); | 204 True /* Direct rendering */); |
206 } | 205 } |
207 | 206 |
208 XFree(visual_info_list); | 207 XFree(visual_info_list); |
209 if (!gl_context_) { | 208 if (!gl_context_) { |
210 return false; | 209 return false; |
211 } | 210 } |
212 | 211 |
213 if (!glXMakeCurrent(display_, window_, gl_context_)) { | 212 if (!glXMakeCurrent(display_, window_, gl_context_)) { |
214 glXDestroyContext(display_, gl_context_); | 213 glXDestroyContext(display_, gl_context_); |
215 gl_context_ = NULL; | 214 gl_context_ = nullptr; |
216 return false; | 215 return false; |
217 } | 216 } |
218 | 217 |
219 return true; | 218 return true; |
220 } | 219 } |
221 | 220 |
222 bool InitializeNextTest() { | 221 bool InitializeNextTest() { |
223 SimulationSpecification& spec = sims_remaining_.front(); | 222 SimulationSpecification& spec = sims_remaining_.front(); |
224 LOG(INFO) << "Initializing test for " << spec.simulation_name << | 223 LOG(INFO) << "Initializing test for " << spec.simulation_name << "(" |
225 "(" << ModelToString(spec.model_under_test) << ")"; | 224 << ModelToString(spec.model_under_test) << ")"; |
226 const base::FilePath& path = spec.input_path; | 225 const base::FilePath& path = spec.input_path; |
227 | 226 |
228 RenderNode* root = NULL; | 227 std::unique_ptr<RenderNode> root = BuildRenderTreeFromFile(path); |
229 if (!(root = BuildRenderTreeFromFile(path))) { | 228 if (!root) { |
230 LOG(ERROR) << "Couldn't parse test configuration file " << | 229 LOG(ERROR) << "Couldn't parse test configuration file " |
231 path.LossyDisplayName(); | 230 << path.LossyDisplayName(); |
232 return false; | 231 return false; |
233 } | 232 } |
234 | 233 |
235 current_sim_ = ConstructSimulationModel(spec.model_under_test, | 234 current_sim_ = ConstructSimulationModel( |
236 root, | 235 spec.model_under_test, std::move(root), window_width_, window_height_); |
237 window_width_, | 236 return !!current_sim_; |
238 window_height_); | |
239 if (!current_sim_) | |
240 return false; | |
241 | |
242 return true; | |
243 } | 237 } |
244 | 238 |
245 void CleanupCurrentTest() { | 239 void CleanupCurrentTest() { |
246 LOG(INFO) << "Finished test " << sims_remaining_.front().simulation_name; | 240 LOG(INFO) << "Finished test " << sims_remaining_.front().simulation_name; |
247 | 241 |
248 delete current_sim_; | 242 current_sim_.reset(); |
249 current_sim_ = NULL; | |
250 } | 243 } |
251 | 244 |
252 void UpdateCurrentTest() { | 245 void UpdateCurrentTest() { |
253 ++sims_remaining_.front().frames_rendered; | 246 ++sims_remaining_.front().frames_rendered; |
254 | 247 |
255 if (current_sim_) | 248 if (current_sim_) |
256 current_sim_->Update(); | 249 current_sim_->Update(); |
257 | 250 |
258 glXSwapBuffers(display_, window_); | 251 glXSwapBuffers(display_, window_); |
259 | 252 |
260 XExposeEvent ev = { Expose, 0, 1, display_, window_, | 253 XExposeEvent ev = { Expose, 0, 1, display_, window_, |
261 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0 }; | 254 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0 }; |
262 XSendEvent(display_, | 255 XSendEvent(display_, |
263 window_, | 256 window_, |
264 False, | 257 False, |
265 ExposureMask, | 258 ExposureMask, |
266 reinterpret_cast<XEvent*>(&ev)); | 259 reinterpret_cast<XEvent*>(&ev)); |
267 | 260 |
268 base::ThreadTaskRunnerHandle::Get()->PostTask( | 261 base::ThreadTaskRunnerHandle::Get()->PostTask( |
269 FROM_HERE, | 262 FROM_HERE, |
270 base::Bind(&Simulator::UpdateLoop, weak_factory_.GetWeakPtr())); | 263 base::Bind(&Simulator::UpdateLoop, weak_factory_.GetWeakPtr())); |
271 } | 264 } |
272 | 265 |
273 void DumpOutput() { | 266 void DumpOutput() { |
274 LOG(INFO) << "Successfully ran " << sims_completed_.size() << " tests"; | 267 LOG(INFO) << "Successfully ran " << sims_completed_.size() << " tests"; |
275 | 268 |
276 FILE* f = base::OpenFile(output_path_, "w"); | 269 FILE* f = base::OpenFile(output_path_, "w"); |
277 | 270 |
278 if (!f) { | 271 if (!f) { |
279 LOG(ERROR) << "Failed to open output file " << | 272 LOG(ERROR) << "Failed to open output file " |
280 output_path_.LossyDisplayName(); | 273 << output_path_.LossyDisplayName(); |
281 exit(-1); | 274 exit(-1); |
282 } | 275 } |
283 | 276 |
284 LOG(INFO) << "Writing results to " << output_path_.LossyDisplayName(); | 277 LOG(INFO) << "Writing results to " << output_path_.LossyDisplayName(); |
285 | 278 |
286 fputs("{\n\t\"results\": [\n", f); | 279 fputs("{\n\t\"results\": [\n", f); |
287 | 280 |
288 while (sims_completed_.size()) { | 281 while (sims_completed_.size()) { |
289 SimulationSpecification i = sims_completed_.front(); | 282 SimulationSpecification i = sims_completed_.front(); |
290 fprintf(f, | 283 fprintf(f, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 324 } |
332 | 325 |
333 void Resize(int width, int height) { | 326 void Resize(int width, int height) { |
334 window_width_ = width; | 327 window_width_ = width; |
335 window_height_ = height; | 328 window_height_ = height; |
336 if (current_sim_) | 329 if (current_sim_) |
337 current_sim_->Resize(window_width_, window_height_); | 330 current_sim_->Resize(window_width_, window_height_); |
338 } | 331 } |
339 | 332 |
340 // Simulation task list for this execution | 333 // Simulation task list for this execution |
341 RenderModelSimulator* current_sim_; | 334 std::unique_ptr<RenderModelSimulator> current_sim_; |
342 queue<SimulationSpecification> sims_remaining_; | 335 queue<SimulationSpecification> sims_remaining_; |
343 queue<SimulationSpecification> sims_completed_; | 336 queue<SimulationSpecification> sims_completed_; |
344 base::FilePath output_path_; | 337 base::FilePath output_path_; |
345 // Amount of time to run each simulation | 338 // Amount of time to run each simulation |
346 int seconds_per_test_; | 339 int seconds_per_test_; |
347 // GUI data | 340 // GUI data |
348 Display* display_; | 341 Display* display_; |
349 Window window_; | 342 Window window_; |
350 GLXContext gl_context_; | 343 GLXContext gl_context_; |
351 int window_width_; | 344 int window_width_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } | 386 } |
394 } else { | 387 } else { |
395 LOG(INFO) << "(input path is a file)"; | 388 LOG(INFO) << "(input path is a file)"; |
396 sim.QueueTest(inPath); | 389 sim.QueueTest(inPath); |
397 } | 390 } |
398 | 391 |
399 sim.Run(); | 392 sim.Run(); |
400 | 393 |
401 return 0; | 394 return 0; |
402 } | 395 } |
OLD | NEW |