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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 class ColoredLayer : public Layer, public LayerDelegate { | 51 class ColoredLayer : public Layer, public LayerDelegate { |
52 public: | 52 public: |
53 explicit ColoredLayer(SkColor color) | 53 explicit ColoredLayer(SkColor color) |
54 : Layer(ui::LAYER_TEXTURED), | 54 : Layer(ui::LAYER_TEXTURED), |
55 color_(color), | 55 color_(color), |
56 draw_(true) { | 56 draw_(true) { |
57 set_delegate(this); | 57 set_delegate(this); |
58 } | 58 } |
59 | 59 |
60 virtual ~ColoredLayer() {} | 60 ~ColoredLayer() override {} |
61 | 61 |
62 // Overridden from LayerDelegate: | 62 // Overridden from LayerDelegate: |
63 virtual void OnPaintLayer(gfx::Canvas* canvas) override { | 63 void OnPaintLayer(gfx::Canvas* canvas) override { |
64 if (draw_) { | 64 if (draw_) { |
65 canvas->DrawColor(color_); | 65 canvas->DrawColor(color_); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 virtual void OnDelegatedFrameDamage( | 69 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
70 const gfx::Rect& damage_rect_in_dip) override {} | |
71 | 70 |
72 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) override { | 71 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
73 } | |
74 | 72 |
75 virtual base::Closure PrepareForLayerBoundsChange() override { | 73 base::Closure PrepareForLayerBoundsChange() override { |
76 return base::Closure(); | 74 return base::Closure(); |
77 } | 75 } |
78 | 76 |
79 void set_color(SkColor color) { color_ = color; } | 77 void set_color(SkColor color) { color_ = color; } |
80 void set_draw(bool draw) { draw_ = draw; } | 78 void set_draw(bool draw) { draw_ = draw; } |
81 | 79 |
82 private: | 80 private: |
83 SkColor color_; | 81 SkColor color_; |
84 bool draw_; | 82 bool draw_; |
85 | 83 |
86 DISALLOW_COPY_AND_ASSIGN(ColoredLayer); | 84 DISALLOW_COPY_AND_ASSIGN(ColoredLayer); |
87 }; | 85 }; |
88 | 86 |
89 const int kFrames = 100; | 87 const int kFrames = 100; |
90 | 88 |
91 // Benchmark base class, hooks up drawing callback and displaying FPS. | 89 // Benchmark base class, hooks up drawing callback and displaying FPS. |
92 class BenchCompositorObserver : public ui::CompositorObserver { | 90 class BenchCompositorObserver : public ui::CompositorObserver { |
93 public: | 91 public: |
94 explicit BenchCompositorObserver(int max_frames) | 92 explicit BenchCompositorObserver(int max_frames) |
95 : start_time_(), | 93 : start_time_(), |
96 frames_(0), | 94 frames_(0), |
97 max_frames_(max_frames) { | 95 max_frames_(max_frames) { |
98 } | 96 } |
99 | 97 |
100 virtual void OnCompositingDidCommit(ui::Compositor* compositor) override {} | 98 void OnCompositingDidCommit(ui::Compositor* compositor) override {} |
101 | 99 |
102 virtual void OnCompositingStarted(Compositor* compositor, | 100 void OnCompositingStarted(Compositor* compositor, |
103 base::TimeTicks start_time) override {} | 101 base::TimeTicks start_time) override {} |
104 | 102 |
105 virtual void OnCompositingEnded(Compositor* compositor) override { | 103 void OnCompositingEnded(Compositor* compositor) override { |
106 if (start_time_.is_null()) { | 104 if (start_time_.is_null()) { |
107 start_time_ = TimeTicks::Now(); | 105 start_time_ = TimeTicks::Now(); |
108 } else { | 106 } else { |
109 ++frames_; | 107 ++frames_; |
110 if (frames_ % kFrames == 0) { | 108 if (frames_ % kFrames == 0) { |
111 TimeTicks now = TimeTicks::Now(); | 109 TimeTicks now = TimeTicks::Now(); |
112 double ms = (now - start_time_).InMillisecondsF() / kFrames; | 110 double ms = (now - start_time_).InMillisecondsF() / kFrames; |
113 LOG(INFO) << "FPS: " << 1000.f / ms << " (" << ms << " ms)"; | 111 LOG(INFO) << "FPS: " << 1000.f / ms << " (" << ms << " ms)"; |
114 start_time_ = now; | 112 start_time_ = now; |
115 } | 113 } |
116 } | 114 } |
117 if (max_frames_ && frames_ == max_frames_) { | 115 if (max_frames_ && frames_ == max_frames_) { |
118 base::MessageLoop::current()->Quit(); | 116 base::MessageLoop::current()->Quit(); |
119 } else { | 117 } else { |
120 Draw(); | 118 Draw(); |
121 } | 119 } |
122 } | 120 } |
123 | 121 |
124 virtual void OnCompositingAborted(Compositor* compositor) override {} | 122 void OnCompositingAborted(Compositor* compositor) override {} |
125 | 123 |
126 virtual void OnCompositingLockStateChanged( | 124 void OnCompositingLockStateChanged(Compositor* compositor) override {} |
127 Compositor* compositor) override {} | |
128 | 125 |
129 virtual void Draw() {} | 126 virtual void Draw() {} |
130 | 127 |
131 int frames() const { return frames_; } | 128 int frames() const { return frames_; } |
132 | 129 |
133 private: | 130 private: |
134 TimeTicks start_time_; | 131 TimeTicks start_time_; |
135 int frames_; | 132 int frames_; |
136 int max_frames_; | 133 int max_frames_; |
137 | 134 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 212 |
216 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); | 213 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); |
217 webgl_.SetTextureMailbox( | 214 webgl_.SetTextureMailbox( |
218 cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), | 215 cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), |
219 cc::SingleReleaseCallback::Create( | 216 cc::SingleReleaseCallback::Create( |
220 base::Bind(ReturnMailbox, context_provider_, texture)), | 217 base::Bind(ReturnMailbox, context_provider_, texture)), |
221 bounds.size()); | 218 bounds.size()); |
222 compositor->AddObserver(this); | 219 compositor->AddObserver(this); |
223 } | 220 } |
224 | 221 |
225 virtual ~WebGLBench() { | 222 ~WebGLBench() override { |
226 webgl_.SetShowSolidColorContent(); | 223 webgl_.SetShowSolidColorContent(); |
227 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 224 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
228 gl->DeleteFramebuffers(1, &fbo_); | 225 gl->DeleteFramebuffers(1, &fbo_); |
229 compositor_->RemoveObserver(this); | 226 compositor_->RemoveObserver(this); |
230 } | 227 } |
231 | 228 |
232 virtual void Draw() override { | 229 void Draw() override { |
233 if (do_draw_) { | 230 if (do_draw_) { |
234 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 231 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
235 gl->ClearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f); | 232 gl->ClearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f); |
236 gl->Clear(GL_COLOR_BUFFER_BIT); | 233 gl->Clear(GL_COLOR_BUFFER_BIT); |
237 gl->Flush(); | 234 gl->Flush(); |
238 } | 235 } |
239 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size())); | 236 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size())); |
240 compositor_->ScheduleDraw(); | 237 compositor_->ScheduleDraw(); |
241 } | 238 } |
242 | 239 |
(...skipping 19 matching lines...) Expand all Loading... |
262 Compositor* compositor, | 259 Compositor* compositor, |
263 int max_frames) | 260 int max_frames) |
264 : BenchCompositorObserver(max_frames), | 261 : BenchCompositorObserver(max_frames), |
265 layer_(layer), | 262 layer_(layer), |
266 compositor_(compositor) { | 263 compositor_(compositor) { |
267 compositor->AddObserver(this); | 264 compositor->AddObserver(this); |
268 layer_->set_draw( | 265 layer_->set_draw( |
269 !CommandLine::ForCurrentProcess()->HasSwitch("disable-draw")); | 266 !CommandLine::ForCurrentProcess()->HasSwitch("disable-draw")); |
270 } | 267 } |
271 | 268 |
272 virtual ~SoftwareScrollBench() { | 269 ~SoftwareScrollBench() override { compositor_->RemoveObserver(this); } |
273 compositor_->RemoveObserver(this); | |
274 } | |
275 | 270 |
276 virtual void Draw() override { | 271 void Draw() override { |
277 layer_->set_color( | 272 layer_->set_color( |
278 SkColorSetARGBInline(255*(frames() % kFrames)/kFrames, 255, 0, 255)); | 273 SkColorSetARGBInline(255*(frames() % kFrames)/kFrames, 255, 0, 255)); |
279 layer_->SchedulePaint(gfx::Rect(layer_->bounds().size())); | 274 layer_->SchedulePaint(gfx::Rect(layer_->bounds().size())); |
280 } | 275 } |
281 | 276 |
282 private: | 277 private: |
283 ColoredLayer* layer_; | 278 ColoredLayer* layer_; |
284 Compositor* compositor_; | 279 Compositor* compositor_; |
285 | 280 |
286 DISALLOW_COPY_AND_ASSIGN(SoftwareScrollBench); | 281 DISALLOW_COPY_AND_ASSIGN(SoftwareScrollBench); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100)); | 359 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100)); |
365 #endif | 360 #endif |
366 | 361 |
367 host->Show(); | 362 host->Show(); |
368 base::MessageLoopForUI::current()->Run(); | 363 base::MessageLoopForUI::current()->Run(); |
369 focus_client.reset(); | 364 focus_client.reset(); |
370 host.reset(); | 365 host.reset(); |
371 | 366 |
372 return 0; | 367 return 0; |
373 } | 368 } |
OLD | NEW |