Update perf expectations since static linking ffmpeg.
[chromium-blink-merge.git] / cc / surfaces / surface_aggregator_test_helpers.cc
blobb21b37e28d64a63174d135b077e275bf4234c7c7
1 // Copyright 2014 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 "cc/surfaces/surface_aggregator_test_helpers.h"
7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.h"
9 #include "cc/layers/append_quads_data.h"
10 #include "cc/output/compositor_frame.h"
11 #include "cc/output/delegated_frame_data.h"
12 #include "cc/quads/render_pass_draw_quad.h"
13 #include "cc/quads/shared_quad_state.h"
14 #include "cc/quads/solid_color_draw_quad.h"
15 #include "cc/quads/surface_draw_quad.h"
16 #include "cc/surfaces/surface.h"
17 #include "cc/test/render_pass_test_common.h"
18 #include "cc/test/render_pass_test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/skia/include/core/SkXfermode.h"
22 namespace cc {
23 namespace test {
25 void AddTestSurfaceQuad(TestRenderPass* pass,
26 const gfx::Size& surface_size,
27 float opacity,
28 SurfaceId surface_id) {
29 gfx::Transform content_to_target_transform;
30 gfx::Size content_bounds = surface_size;
31 gfx::Rect visible_content_rect = gfx::Rect(surface_size);
32 gfx::Rect clip_rect = gfx::Rect(surface_size);
33 bool is_clipped = false;
34 SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
36 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
37 shared_quad_state->SetAll(content_to_target_transform,
38 content_bounds,
39 visible_content_rect,
40 clip_rect,
41 is_clipped,
42 opacity,
43 blend_mode,
44 0);
46 SurfaceDrawQuad* surface_quad =
47 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
48 gfx::Rect quad_rect = gfx::Rect(surface_size);
49 surface_quad->SetNew(pass->shared_quad_state_list.back(),
50 gfx::Rect(surface_size),
51 gfx::Rect(surface_size),
52 surface_id);
54 void AddTestRenderPassQuad(TestRenderPass* pass, RenderPassId render_pass_id) {
55 gfx::Rect output_rect = gfx::Rect(0, 0, 5, 5);
56 SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
57 shared_state->SetAll(gfx::Transform(),
58 output_rect.size(),
59 output_rect,
60 output_rect,
61 false,
63 SkXfermode::kSrcOver_Mode,
64 0);
65 RenderPassDrawQuad* quad =
66 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
67 quad->SetNew(shared_state,
68 output_rect,
69 output_rect,
70 render_pass_id,
72 gfx::Vector2dF(),
73 gfx::Size(),
74 FilterOperations(),
75 gfx::Vector2dF(),
76 FilterOperations());
79 void AddQuadInPass(TestRenderPass* pass, Quad desc) {
80 switch (desc.material) {
81 case DrawQuad::SOLID_COLOR:
82 AddQuad(pass, gfx::Rect(0, 0, 5, 5), desc.color);
83 break;
84 case DrawQuad::SURFACE_CONTENT:
85 AddTestSurfaceQuad(pass, gfx::Size(5, 5), desc.opacity, desc.surface_id);
86 break;
87 case DrawQuad::RENDER_PASS:
88 AddTestRenderPassQuad(pass, desc.render_pass_id);
89 break;
90 default:
91 NOTREACHED();
95 void AddPasses(RenderPassList* pass_list,
96 const gfx::Rect& output_rect,
97 Pass* passes,
98 size_t pass_count) {
99 gfx::Transform root_transform;
100 for (size_t i = 0; i < pass_count; ++i) {
101 Pass pass = passes[i];
102 TestRenderPass* test_pass =
103 AddRenderPass(pass_list, pass.id, output_rect, root_transform);
104 for (size_t j = 0; j < pass.quad_count; ++j) {
105 AddQuadInPass(test_pass, pass.quads[j]);
110 void TestQuadMatchesExpectations(Quad expected_quad, const DrawQuad* quad) {
111 switch (expected_quad.material) {
112 case DrawQuad::SOLID_COLOR: {
113 ASSERT_EQ(DrawQuad::SOLID_COLOR, quad->material);
115 const SolidColorDrawQuad* solid_color_quad =
116 SolidColorDrawQuad::MaterialCast(quad);
118 EXPECT_EQ(expected_quad.color, solid_color_quad->color);
119 break;
121 case DrawQuad::RENDER_PASS: {
122 ASSERT_EQ(DrawQuad::RENDER_PASS, quad->material);
124 const RenderPassDrawQuad* render_pass_quad =
125 RenderPassDrawQuad::MaterialCast(quad);
127 EXPECT_EQ(expected_quad.render_pass_id, render_pass_quad->render_pass_id);
128 break;
130 default:
131 NOTREACHED();
132 break;
136 void TestPassMatchesExpectations(Pass expected_pass, const RenderPass* pass) {
137 ASSERT_EQ(expected_pass.quad_count, pass->quad_list.size());
138 for (auto iter = pass->quad_list.cbegin(); iter != pass->quad_list.cend();
139 ++iter) {
140 SCOPED_TRACE(base::StringPrintf("Quad number %" PRIuS, iter.index()));
141 TestQuadMatchesExpectations(expected_pass.quads[iter.index()], *iter);
145 void TestPassesMatchExpectations(Pass* expected_passes,
146 size_t expected_pass_count,
147 const RenderPassList* passes) {
148 ASSERT_EQ(expected_pass_count, passes->size());
150 for (size_t i = 0; i < passes->size(); ++i) {
151 SCOPED_TRACE(base::StringPrintf("Pass number %" PRIuS, i));
152 RenderPass* pass = passes->at(i);
153 TestPassMatchesExpectations(expected_passes[i], pass);
157 } // namespace test
158 } // namespace cc