| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <utility> |
| 6 |
| 7 #include "base/test/launcher/unit_test_launcher.h" |
| 8 #include "base/test/test_suite.h" |
| 9 #include "cc/ipc/cc_param_traits.h" |
| 10 #include "cc/ipc/compositor_frame.mojom.h" |
| 11 #include "cc/ipc/compositor_frame_metadata_struct_traits.h" |
| 12 #include "cc/ipc/compositor_frame_struct_traits.h" |
| 13 #include "cc/ipc/render_pass_struct_traits.h" |
| 14 #include "cc/ipc/selection_struct_traits.h" |
| 15 #include "cc/ipc/shared_quad_state_struct_traits.h" |
| 16 #include "cc/ipc/surface_id_struct_traits.h" |
| 17 #include "cc/ipc/transferable_resource_struct_traits.h" |
| 18 #include "cc/output/compositor_frame.h" |
| 19 #include "cc/quads/picture_draw_quad.h" |
| 20 #include "gpu/ipc/common/mailbox_holder_struct_traits.h" |
| 21 #include "gpu/ipc/common/mailbox_struct_traits.h" |
| 22 #include "gpu/ipc/common/sync_token_struct_traits.h" |
| 23 #include "ipc/ipc_message.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "testing/perf/perf_test.h" |
| 26 #include "ui/events/mojo/latency_info_struct_traits.h" |
| 27 #include "ui/gfx/geometry/mojo/geometry.mojom.h" |
| 28 #include "ui/gfx/geometry/mojo/geometry_struct_traits.h" |
| 29 #include "ui/gfx/mojo/selection_bound_struct_traits.h" |
| 30 |
| 31 using cc::CompositorFrame; |
| 32 using cc::DelegatedFrameData; |
| 33 using cc::DrawQuad; |
| 34 using cc::RenderPass; |
| 35 using cc::SharedQuadState; |
| 36 using cc::SolidColorDrawQuad; |
| 37 |
| 38 namespace content { |
| 39 namespace { |
| 40 |
| 41 static const int kTimeLimitMillis = 2000; |
| 42 static const int kNumWarmupRuns = 20; |
| 43 static const int kTimeCheckInterval = 10; |
| 44 |
| 45 class CCSerializationPerfTest : public testing::Test { |
| 46 protected: |
| 47 static void RunTestParamTraits(const std::string& test_name, |
| 48 const CompositorFrame& frame) { |
| 49 for (int i = 0; i < kNumWarmupRuns; ++i) { |
| 50 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 51 IPC::ParamTraits<CompositorFrame>::Write(&msg, frame); |
| 52 } |
| 53 |
| 54 base::TimeTicks start = base::TimeTicks::Now(); |
| 55 base::TimeTicks end = |
| 56 start + base::TimeDelta::FromMilliseconds(kTimeLimitMillis); |
| 57 base::TimeDelta min_time; |
| 58 size_t count = 0; |
| 59 while (start < end) { |
| 60 for (int i = 0; i < kTimeCheckInterval; ++i) { |
| 61 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 62 IPC::ParamTraits<CompositorFrame>::Write(&msg, frame); |
| 63 ++count; |
| 64 } |
| 65 |
| 66 base::TimeTicks now = base::TimeTicks::Now(); |
| 67 if (now - start < min_time || min_time.is_zero()) |
| 68 min_time = now - start; |
| 69 start = base::TimeTicks::Now(); |
| 70 } |
| 71 |
| 72 perf_test::PrintResult( |
| 73 "ParamTraits: min_frame_serialization_time", "", test_name, |
| 74 min_time.InMillisecondsF() / kTimeCheckInterval * 1000, "us", true); |
| 75 perf_test::PrintResult("ParamTraits: num runs in 2 seconds", "", test_name, |
| 76 count, "", true); |
| 77 } |
| 78 |
| 79 static void RunTestStructTraits(const std::string& test_name, |
| 80 const CompositorFrame& frame) { |
| 81 for (int i = 0; i < kNumWarmupRuns; ++i) { |
| 82 mojo::Array<uint8_t> data = cc::mojom::CompositorFrame::Serialize(&frame); |
| 83 DCHECK_GT(data.size(), 0u); |
| 84 } |
| 85 |
| 86 base::TimeTicks start = base::TimeTicks::Now(); |
| 87 base::TimeTicks end = |
| 88 start + base::TimeDelta::FromMilliseconds(kTimeLimitMillis); |
| 89 base::TimeDelta min_time; |
| 90 size_t count = 0; |
| 91 while (start < end) { |
| 92 for (int i = 0; i < kTimeCheckInterval; ++i) { |
| 93 mojo::Array<uint8_t> data = |
| 94 cc::mojom::CompositorFrame::Serialize(&frame); |
| 95 DCHECK_GT(data.size(), 0u); |
| 96 ++count; |
| 97 } |
| 98 |
| 99 base::TimeTicks now = base::TimeTicks::Now(); |
| 100 if (now - start < min_time || min_time.is_zero()) |
| 101 min_time = now - start; |
| 102 start = base::TimeTicks::Now(); |
| 103 } |
| 104 |
| 105 perf_test::PrintResult( |
| 106 "StructTraits min_frame_serialization_time", "", test_name, |
| 107 min_time.InMillisecondsF() / kTimeCheckInterval * 1000, "us", true); |
| 108 perf_test::PrintResult("StructTraits: num runs in 2 seconds", "", test_name, |
| 109 count, "", true); |
| 110 } |
| 111 |
| 112 static void RunTest(const std::string& test_name, CompositorFrame frame) { |
| 113 RunTestStructTraits(test_name, frame); |
| 114 RunTestParamTraits(test_name, frame); |
| 115 } |
| 116 }; |
| 117 |
| 118 TEST_F(CCSerializationPerfTest, DelegatedFrame_ManyQuads_1_4000) { |
| 119 CompositorFrame frame; |
| 120 |
| 121 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 122 render_pass->CreateAndAppendSharedQuadState(); |
| 123 for (int i = 0; i < 4000; ++i) { |
| 124 const gfx::Rect bounds(100, 100, 100, 100); |
| 125 const bool kForceAntiAliasingOff = true; |
| 126 SolidColorDrawQuad* quad = |
| 127 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 128 quad->SetNew(render_pass->shared_quad_state_list.back(), bounds, bounds, |
| 129 SK_ColorRED, kForceAntiAliasingOff); |
| 130 } |
| 131 |
| 132 frame.delegated_frame_data.reset(new DelegatedFrameData); |
| 133 frame.delegated_frame_data->render_pass_list.push_back( |
| 134 std::move(render_pass)); |
| 135 |
| 136 RunTest("DelegatedFrame_ManyQuads_1_4000", std::move(frame)); |
| 137 } |
| 138 |
| 139 TEST_F(CCSerializationPerfTest, DelegatedFrame_ManyQuads_1_100000) { |
| 140 CompositorFrame frame; |
| 141 |
| 142 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 143 render_pass->CreateAndAppendSharedQuadState(); |
| 144 for (int i = 0; i < 100000; ++i) { |
| 145 const gfx::Rect bounds(100, 100, 100, 100); |
| 146 const bool kForceAntiAliasingOff = true; |
| 147 SolidColorDrawQuad* quad = |
| 148 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 149 quad->SetNew(render_pass->shared_quad_state_list.back(), bounds, bounds, |
| 150 SK_ColorRED, kForceAntiAliasingOff); |
| 151 } |
| 152 |
| 153 frame.delegated_frame_data.reset(new DelegatedFrameData); |
| 154 frame.delegated_frame_data->render_pass_list.push_back( |
| 155 std::move(render_pass)); |
| 156 |
| 157 RunTest("DelegatedFrame_ManyQuads_1_100000", std::move(frame)); |
| 158 } |
| 159 |
| 160 TEST_F(CCSerializationPerfTest, DelegatedFrame_ManyQuads_4000_4000) { |
| 161 CompositorFrame frame; |
| 162 |
| 163 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 164 for (int i = 0; i < 4000; ++i) { |
| 165 const gfx::Rect bounds(100, 100, 100, 100); |
| 166 const bool kForceAntiAliasingOff = true; |
| 167 render_pass->CreateAndAppendSharedQuadState(); |
| 168 SolidColorDrawQuad* quad = |
| 169 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 170 quad->SetNew(render_pass->shared_quad_state_list.back(), bounds, bounds, |
| 171 SK_ColorRED, kForceAntiAliasingOff); |
| 172 } |
| 173 |
| 174 frame.delegated_frame_data.reset(new DelegatedFrameData); |
| 175 frame.delegated_frame_data->render_pass_list.push_back( |
| 176 std::move(render_pass)); |
| 177 |
| 178 RunTest("DelegatedFrame_ManyQuads_4000_4000", std::move(frame)); |
| 179 } |
| 180 |
| 181 TEST_F(CCSerializationPerfTest, DelegatedFrame_ManyQuads_100000_100000) { |
| 182 CompositorFrame frame; |
| 183 |
| 184 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 185 for (int i = 0; i < 100000; ++i) { |
| 186 render_pass->CreateAndAppendSharedQuadState(); |
| 187 const gfx::Rect bounds(100, 100, 100, 100); |
| 188 const bool kForceAntiAliasingOff = true; |
| 189 SolidColorDrawQuad* quad = |
| 190 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 191 quad->SetNew(render_pass->shared_quad_state_list.back(), bounds, bounds, |
| 192 SK_ColorRED, kForceAntiAliasingOff); |
| 193 } |
| 194 |
| 195 frame.delegated_frame_data.reset(new DelegatedFrameData); |
| 196 frame.delegated_frame_data->render_pass_list.push_back( |
| 197 std::move(render_pass)); |
| 198 |
| 199 RunTest("DelegatedFrame_ManyQuads_100000_100000", std::move(frame)); |
| 200 } |
| 201 |
| 202 TEST_F(CCSerializationPerfTest, DelegatedFrame_ManyRenderPasses_10000_100) { |
| 203 CompositorFrame frame; |
| 204 frame.delegated_frame_data.reset(new DelegatedFrameData); |
| 205 |
| 206 for (int i = 0; i < 1000; ++i) { |
| 207 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 208 for (int j = 0; j < 100; ++j) { |
| 209 render_pass->CreateAndAppendSharedQuadState(); |
| 210 const gfx::Rect bounds(100, 100, 100, 100); |
| 211 const bool kForceAntiAliasingOff = true; |
| 212 SolidColorDrawQuad* quad = |
| 213 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 214 quad->SetNew(render_pass->shared_quad_state_list.back(), bounds, bounds, |
| 215 SK_ColorRED, kForceAntiAliasingOff); |
| 216 } |
| 217 frame.delegated_frame_data->render_pass_list.push_back( |
| 218 std::move(render_pass)); |
| 219 } |
| 220 |
| 221 RunTest("DelegatedFrame_ManyRenderPasses_10000_100", std::move(frame)); |
| 222 } |
| 223 |
| 224 } // namespace |
| 225 } // namespace content |
| OLD | NEW |