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.
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"
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;
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
);
43 class DrawQuadPerfTest
: public testing::Test
{
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() {
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
,
81 quads
->push_back(quad
);
85 void RunIterateResourceTest(const std::string
& test_name
, int quad_count
) {
87 std::vector
<DrawQuad
*> quads
;
88 GenerateTextureDrawQuads(quad_count
, &quads
);
91 DrawQuad::ResourceIteratorCallback callback
= base::Bind(&Increment
);
93 for (auto* quad
: quads
)
94 quad
->IterateResources(callback
);
96 } while (!timer_
.HasTimeLimitExpired());
98 perf_test::PrintResult("draw_quad_iterate_resources", "", test_name
,
99 timer_
.LapsPerSecond(), "runs/s", true);
104 scoped_ptr
<RenderPass
> render_pass_
;
105 SharedQuadState
* shared_state_
;
109 TEST_F(DrawQuadPerfTest
, IterateResources
) {
110 RunIterateResourceTest("10_quads", 10);
111 RunIterateResourceTest("100_quads", 100);
112 RunIterateResourceTest("500_quads", 500);