| 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 #include "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 2210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2221 | 2221 |
| 2222 root->SetOpacity(0.5f); | 2222 root->SetOpacity(0.5f); |
| 2223 WaitForSwap(); | 2223 WaitForSwap(); |
| 2224 EXPECT_EQ(1u, animation_observer.animation_step_count()); | 2224 EXPECT_EQ(1u, animation_observer.animation_step_count()); |
| 2225 | 2225 |
| 2226 EXPECT_FALSE(animation_observer.shutdown()); | 2226 EXPECT_FALSE(animation_observer.shutdown()); |
| 2227 ResetCompositor(); | 2227 ResetCompositor(); |
| 2228 EXPECT_TRUE(animation_observer.shutdown()); | 2228 EXPECT_TRUE(animation_observer.shutdown()); |
| 2229 } | 2229 } |
| 2230 | 2230 |
| 2231 // A simple AnimationMetricsReporter class that remembers smoothness metric |
| 2232 // when animation completes. |
| 2233 class TestMetricsReporter : public ui::AnimationMetricsReporter { |
| 2234 public: |
| 2235 TestMetricsReporter() {} |
| 2236 ~TestMetricsReporter() override {} |
| 2237 |
| 2238 bool report_called() { return report_called_; } |
| 2239 int value() const { return value_; } |
| 2240 |
| 2241 protected: |
| 2242 void Report(int value) override { |
| 2243 value_ = value; |
| 2244 report_called_ = true; |
| 2245 } |
| 2246 |
| 2247 private: |
| 2248 bool report_called_ = false; |
| 2249 int value_ = -1; |
| 2250 |
| 2251 DISALLOW_COPY_AND_ASSIGN(TestMetricsReporter); |
| 2252 }; |
| 2253 |
| 2254 // Starts an animation and tests that incrementing compositor frame count can |
| 2255 // be used to report animation smoothness metrics. |
| 2256 TEST_F(LayerWithRealCompositorTest, ReportMetrics) { |
| 2257 std::unique_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); |
| 2258 GetCompositor()->SetRootLayer(root.get()); |
| 2259 LayerAnimator* animator = root->GetAnimator(); |
| 2260 std::unique_ptr<ui::LayerAnimationElement> animation_element = |
| 2261 ui::LayerAnimationElement::CreateColorElement( |
| 2262 SK_ColorRED, base::TimeDelta::FromMilliseconds(100)); |
| 2263 ui::LayerAnimationSequence* animation_sequence = |
| 2264 new ui::LayerAnimationSequence(std::move(animation_element)); |
| 2265 TestMetricsReporter reporter; |
| 2266 animation_sequence->SetAnimationMetricsReporter(&reporter); |
| 2267 animator->StartAnimation(animation_sequence); |
| 2268 while (!reporter.report_called()) |
| 2269 WaitForSwap(); |
| 2270 ResetCompositor(); |
| 2271 // Even though most of the time 100% smooth animations are expected, on the |
| 2272 // test bots this cannot be guaranteed. Therefore simply check that some |
| 2273 // value was reported. |
| 2274 EXPECT_GT(reporter.value(), 0); |
| 2275 } |
| 2276 |
| 2231 TEST(LayerDebugInfoTest, LayerNameDoesNotClobber) { | 2277 TEST(LayerDebugInfoTest, LayerNameDoesNotClobber) { |
| 2232 Layer layer(LAYER_NOT_DRAWN); | 2278 Layer layer(LAYER_NOT_DRAWN); |
| 2233 layer.set_name("foo"); | 2279 layer.set_name("foo"); |
| 2234 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = | 2280 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = |
| 2235 layer.TakeDebugInfo(nullptr); | 2281 layer.TakeDebugInfo(nullptr); |
| 2236 std::string trace_format("bar,"); | 2282 std::string trace_format("bar,"); |
| 2237 debug_info->AppendAsTraceFormat(&trace_format); | 2283 debug_info->AppendAsTraceFormat(&trace_format); |
| 2238 std::string expected("bar,{\"layer_name\":\"foo\"}"); | 2284 std::string expected("bar,{\"layer_name\":\"foo\"}"); |
| 2239 EXPECT_EQ(expected, trace_format); | 2285 EXPECT_EQ(expected, trace_format); |
| 2240 } | 2286 } |
| 2241 | 2287 |
| 2242 } // namespace ui | 2288 } // namespace ui |
| OLD | NEW |