Android NTP: Most visited tile clicks should have PageTransition.AUTO_BOOKMARK
[chromium-blink-merge.git] / cc / surfaces / surface_aggregator_test_helpers.cc
blob45b57d0ffe78fcd5bcab088ee136581d072a2fe3
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_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/skia/include/core/SkXfermode.h"
21 namespace cc {
22 namespace test {
24 void AddSurfaceQuad(RenderPass* pass,
25 const gfx::Size& surface_size,
26 float opacity,
27 SurfaceId surface_id) {
28 gfx::Transform layer_to_target_transform;
29 gfx::Size layer_bounds = surface_size;
30 gfx::Rect visible_layer_rect = gfx::Rect(surface_size);
31 gfx::Rect clip_rect = gfx::Rect(surface_size);
32 bool is_clipped = false;
33 SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
35 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
36 shared_quad_state->SetAll(layer_to_target_transform, layer_bounds,
37 visible_layer_rect, clip_rect, is_clipped, opacity,
38 blend_mode, 0);
40 SurfaceDrawQuad* surface_quad =
41 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
42 gfx::Rect quad_rect = gfx::Rect(surface_size);
43 surface_quad->SetNew(pass->shared_quad_state_list.back(),
44 gfx::Rect(surface_size),
45 gfx::Rect(surface_size),
46 surface_id);
48 void AddRenderPassQuad(RenderPass* pass, RenderPassId render_pass_id) {
49 gfx::Rect output_rect = gfx::Rect(0, 0, 5, 5);
50 SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
51 shared_state->SetAll(gfx::Transform(),
52 output_rect.size(),
53 output_rect,
54 output_rect,
55 false,
57 SkXfermode::kSrcOver_Mode,
58 0);
59 RenderPassDrawQuad* quad =
60 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
61 quad->SetNew(shared_state,
62 output_rect,
63 output_rect,
64 render_pass_id,
66 gfx::Vector2dF(),
67 gfx::Size(),
68 FilterOperations(),
69 gfx::Vector2dF(),
70 FilterOperations());
73 void AddQuadInPass(RenderPass* pass, Quad desc) {
74 switch (desc.material) {
75 case DrawQuad::SOLID_COLOR:
76 AddQuad(pass, gfx::Rect(0, 0, 5, 5), desc.color);
77 break;
78 case DrawQuad::SURFACE_CONTENT:
79 AddSurfaceQuad(pass, gfx::Size(5, 5), desc.opacity, desc.surface_id);
80 break;
81 case DrawQuad::RENDER_PASS:
82 AddRenderPassQuad(pass, desc.render_pass_id);
83 break;
84 default:
85 NOTREACHED();
89 void AddPasses(RenderPassList* pass_list,
90 const gfx::Rect& output_rect,
91 Pass* passes,
92 size_t pass_count) {
93 gfx::Transform root_transform;
94 for (size_t i = 0; i < pass_count; ++i) {
95 Pass pass = passes[i];
96 RenderPass* test_pass =
97 AddRenderPass(pass_list, pass.id, output_rect, root_transform);
98 for (size_t j = 0; j < pass.quad_count; ++j) {
99 AddQuadInPass(test_pass, pass.quads[j]);
104 void TestQuadMatchesExpectations(Quad expected_quad, const DrawQuad* quad) {
105 switch (expected_quad.material) {
106 case DrawQuad::SOLID_COLOR: {
107 ASSERT_EQ(DrawQuad::SOLID_COLOR, quad->material);
109 const SolidColorDrawQuad* solid_color_quad =
110 SolidColorDrawQuad::MaterialCast(quad);
112 EXPECT_EQ(expected_quad.color, solid_color_quad->color);
113 break;
115 case DrawQuad::RENDER_PASS: {
116 ASSERT_EQ(DrawQuad::RENDER_PASS, quad->material);
118 const RenderPassDrawQuad* render_pass_quad =
119 RenderPassDrawQuad::MaterialCast(quad);
121 EXPECT_EQ(expected_quad.render_pass_id, render_pass_quad->render_pass_id);
122 break;
124 default:
125 NOTREACHED();
126 break;
130 void TestPassMatchesExpectations(Pass expected_pass, const RenderPass* pass) {
131 ASSERT_EQ(expected_pass.quad_count, pass->quad_list.size());
132 for (auto iter = pass->quad_list.cbegin(); iter != pass->quad_list.cend();
133 ++iter) {
134 SCOPED_TRACE(base::StringPrintf("Quad number %" PRIuS, iter.index()));
135 TestQuadMatchesExpectations(expected_pass.quads[iter.index()], *iter);
139 void TestPassesMatchExpectations(Pass* expected_passes,
140 size_t expected_pass_count,
141 const RenderPassList* passes) {
142 ASSERT_EQ(expected_pass_count, passes->size());
144 for (size_t i = 0; i < passes->size(); ++i) {
145 SCOPED_TRACE(base::StringPrintf("Pass number %" PRIuS, i));
146 RenderPass* pass = passes->at(i);
147 TestPassMatchesExpectations(expected_passes[i], pass);
151 } // namespace test
152 } // namespace cc