| 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 #if defined(USE_X11) | 5 #if defined(USE_X11) |
| 6 #include <X11/Xlib.h> | 6 #include <X11/Xlib.h> |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 const int kFrames = 100; | 87 const int kFrames = 100; |
| 88 | 88 |
| 89 // Benchmark base class, hooks up drawing callback and displaying FPS. | 89 // Benchmark base class, hooks up drawing callback and displaying FPS. |
| 90 class BenchCompositorObserver : public ui::CompositorObserver { | 90 class BenchCompositorObserver : public ui::CompositorObserver { |
| 91 public: | 91 public: |
| 92 explicit BenchCompositorObserver(int max_frames) | 92 explicit BenchCompositorObserver(int max_frames) |
| 93 : start_time_(), | 93 : start_time_(), |
| 94 frames_(0), | 94 frames_(0), |
| 95 max_frames_(max_frames) { | 95 max_frames_(max_frames) { |
| 96 } | 96 } |
| 97 virtual ~BenchCompositorObserver() {} |
| 97 | 98 |
| 98 void OnCompositingDidCommit(ui::Compositor* compositor) override {} | 99 void OnCompositingDidCommit(ui::Compositor* compositor) override {} |
| 99 | 100 |
| 100 void OnCompositingStarted(Compositor* compositor, | 101 void OnCompositingStarted(Compositor* compositor, |
| 101 base::TimeTicks start_time) override {} | 102 base::TimeTicks start_time) override {} |
| 102 | 103 |
| 103 void OnCompositingEnded(Compositor* compositor) override { | 104 void OnCompositingEnded(Compositor* compositor) override { |
| 104 if (start_time_.is_null()) { | 105 if (start_time_.is_null()) { |
| 105 start_time_ = TimeTicks::Now(); | 106 start_time_ = TimeTicks::Now(); |
| 106 } else { | 107 } else { |
| 107 ++frames_; | 108 ++frames_; |
| 108 if (frames_ % kFrames == 0) { | 109 if (frames_ % kFrames == 0) { |
| 109 TimeTicks now = TimeTicks::Now(); | 110 TimeTicks now = TimeTicks::Now(); |
| 110 double ms = (now - start_time_).InMillisecondsF() / kFrames; | 111 double ms = (now - start_time_).InMillisecondsF() / kFrames; |
| 111 LOG(INFO) << "FPS: " << 1000.f / ms << " (" << ms << " ms)"; | 112 LOG(INFO) << "FPS: " << 1000.f / ms << " (" << ms << " ms)"; |
| 112 start_time_ = now; | 113 start_time_ = now; |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 if (max_frames_ && frames_ == max_frames_) { | 116 if (max_frames_ && frames_ == max_frames_) { |
| 116 base::MessageLoop::current()->Quit(); | 117 base::MessageLoop::current()->Quit(); |
| 117 } else { | 118 } else { |
| 118 Draw(); | 119 Draw(); |
| 119 } | 120 } |
| 120 } | 121 } |
| 121 | 122 |
| 122 void OnCompositingAborted(Compositor* compositor) override {} | 123 void OnCompositingAborted(Compositor* compositor) override {} |
| 123 | 124 |
| 124 void OnCompositingLockStateChanged(Compositor* compositor) override {} | 125 void OnCompositingLockStateChanged(Compositor* compositor) override {} |
| 125 | 126 |
| 127 void OnCompositingShuttingDown(ui::Compositor* compositor) override {} |
| 128 |
| 126 virtual void Draw() {} | 129 virtual void Draw() {} |
| 127 | 130 |
| 128 int frames() const { return frames_; } | 131 int frames() const { return frames_; } |
| 129 | 132 |
| 130 private: | 133 private: |
| 131 TimeTicks start_time_; | 134 TimeTicks start_time_; |
| 132 int frames_; | 135 int frames_; |
| 133 int max_frames_; | 136 int max_frames_; |
| 134 | 137 |
| 135 DISALLOW_COPY_AND_ASSIGN(BenchCompositorObserver); | 138 DISALLOW_COPY_AND_ASSIGN(BenchCompositorObserver); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100)); | 362 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100)); |
| 360 #endif | 363 #endif |
| 361 | 364 |
| 362 host->Show(); | 365 host->Show(); |
| 363 base::MessageLoopForUI::current()->Run(); | 366 base::MessageLoopForUI::current()->Run(); |
| 364 focus_client.reset(); | 367 focus_client.reset(); |
| 365 host.reset(); | 368 host.reset(); |
| 366 | 369 |
| 367 return 0; | 370 return 0; |
| 368 } | 371 } |
| OLD | NEW |