Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / quads / draw_quad_perftest.cc
blob459d4eaf9f03a626a01596d24e42e03f77a37eb3
1 // Copyright 2015 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.
5 #include <vector>
7 #include "base/bind.h"
8 #include "base/time/time.h"
9 #include "cc/debug/lap_timer.h"
10 #include "cc/quads/draw_quad.h"
11 #include "cc/quads/render_pass.h"
12 #include "cc/quads/texture_draw_quad.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/perf/perf_test.h"
16 namespace cc {
17 namespace {
19 static const int kTimeLimitMillis = 2000;
20 static const int kWarmupRuns = 5;
21 static const int kTimeCheckInterval = 10;
23 ResourceId Increment(ResourceId resource_id) {
24 return resource_id + 1;
27 SharedQuadState* CreateSharedQuadState(RenderPass* render_pass) {
28 gfx::Transform quad_transform = gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
29 gfx::Size content_bounds(26, 28);
30 gfx::Rect visible_content_rect(10, 12, 14, 16);
31 gfx::Rect clip_rect(19, 21, 23, 25);
32 bool is_clipped = false;
33 float opacity = 1.f;
34 int sorting_context_id = 65536;
35 SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
37 SharedQuadState* state = render_pass->CreateAndAppendSharedQuadState();
38 state->SetAll(quad_transform, content_bounds, visible_content_rect, clip_rect,
39 is_clipped, opacity, blend_mode, sorting_context_id);
40 return state;
43 class DrawQuadPerfTest : public testing::Test {
44 public:
45 DrawQuadPerfTest()
46 : timer_(kWarmupRuns,
47 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
48 kTimeCheckInterval) {}
50 void CreateRenderPass() {
51 render_pass_ = RenderPass::Create();
52 SharedQuadState* new_shared_state(
53 CreateSharedQuadState(render_pass_.get()));
54 shared_state_ = render_pass_->CreateAndAppendSharedQuadState();
55 shared_state_->CopyFrom(new_shared_state);
58 void CleanUpRenderPass() {
59 render_pass_.reset();
60 shared_state_ = nullptr;
63 void GenerateTextureDrawQuads(int count, std::vector<DrawQuad*>* quads) {
64 for (int i = 0; i < count; ++i) {
65 TextureDrawQuad* quad =
66 render_pass_->CreateAndAppendDrawQuad<TextureDrawQuad>();
67 gfx::Rect rect(0, 0, 100, 100);
68 ResourceId resource_id = 1;
69 bool premultiplied_alpha = true;
70 gfx::PointF uv_top_left(0, 0);
71 gfx::PointF uv_bottom_right(1, 1);
72 SkColor background_color = SK_ColorRED;
73 float vertex_opacity[4] = {1.f, 1.f, 1.f, 1.f};
74 bool y_flipped = false;
75 bool nearest_neighbor = true;
77 quad->SetNew(shared_state_, rect, rect, rect, resource_id,
78 premultiplied_alpha, uv_top_left, uv_bottom_right,
79 background_color, vertex_opacity, y_flipped,
80 nearest_neighbor);
81 quads->push_back(quad);
85 void RunIterateResourceTest(const std::string& test_name, int quad_count) {
86 CreateRenderPass();
87 std::vector<DrawQuad*> quads;
88 GenerateTextureDrawQuads(quad_count, &quads);
90 timer_.Reset();
91 DrawQuad::ResourceIteratorCallback callback = base::Bind(&Increment);
92 do {
93 for (auto* quad : quads)
94 quad->IterateResources(callback);
95 timer_.NextLap();
96 } while (!timer_.HasTimeLimitExpired());
98 perf_test::PrintResult("draw_quad_iterate_resources", "", test_name,
99 timer_.LapsPerSecond(), "runs/s", true);
100 CleanUpRenderPass();
103 private:
104 scoped_ptr<RenderPass> render_pass_;
105 SharedQuadState* shared_state_;
106 LapTimer timer_;
109 TEST_F(DrawQuadPerfTest, IterateResources) {
110 RunIterateResourceTest("10_quads", 10);
111 RunIterateResourceTest("100_quads", 100);
112 RunIterateResourceTest("500_quads", 500);
115 } // namespace
116 } // namespace cc