Chromium Code Reviews| 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( | |
| 2258 CreateColorLayer(SK_ColorGREEN, gfx::Rect(20, 20, 50, 50))); | |
| 2259 GetCompositor()->SetRootLayer(root.get()); | |
| 2260 LayerAnimator* animator = root->GetAnimator(); | |
| 2261 std::unique_ptr<ui::LayerAnimationElement> animation_element = | |
| 2262 ui::LayerAnimationElement::CreateColorElement( | |
| 2263 SK_ColorRED, base::TimeDelta::FromMilliseconds(100)); | |
| 2264 ui::LayerAnimationSequence* animation_sequence = | |
| 2265 new ui::LayerAnimationSequence(std::move(animation_element)); | |
| 2266 TestMetricsReporter reporter; | |
| 2267 animation_sequence->SetAnimationMetricsReporter(&reporter); | |
| 2268 animator->StartAnimation(animation_sequence); | |
| 2269 while (!reporter.report_called()) | |
| 2270 WaitForSwap(); | |
| 2271 ResetCompositor(); | |
| 2272 EXPECT_GT(reporter.value(), 90); | |
|
ajuma
2017/01/20 21:24:07
Just to make sure I understand, since the animatio
varkha
2017/01/20 22:05:24
Yes, you got me here. I saw a value of 100% and th
| |
| 2273 } | |
| 2274 | |
| 2231 TEST(LayerDebugInfoTest, LayerNameDoesNotClobber) { | 2275 TEST(LayerDebugInfoTest, LayerNameDoesNotClobber) { |
| 2232 Layer layer(LAYER_NOT_DRAWN); | 2276 Layer layer(LAYER_NOT_DRAWN); |
| 2233 layer.set_name("foo"); | 2277 layer.set_name("foo"); |
| 2234 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = | 2278 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = |
| 2235 layer.TakeDebugInfo(nullptr); | 2279 layer.TakeDebugInfo(nullptr); |
| 2236 std::string trace_format("bar,"); | 2280 std::string trace_format("bar,"); |
| 2237 debug_info->AppendAsTraceFormat(&trace_format); | 2281 debug_info->AppendAsTraceFormat(&trace_format); |
| 2238 std::string expected("bar,{\"layer_name\":\"foo\"}"); | 2282 std::string expected("bar,{\"layer_name\":\"foo\"}"); |
| 2239 EXPECT_EQ(expected, trace_format); | 2283 EXPECT_EQ(expected, trace_format); |
| 2240 } | 2284 } |
| 2241 | 2285 |
| 2242 } // namespace ui | 2286 } // namespace ui |
| OLD | NEW |