Telemetry support for iframes.
[chromium-blink-merge.git] / cc / surfaces / surface_aggregator_test_helpers.cc
bloba1bb0be948825af4f642baa9d14f4db3506e7c9b
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/mock_quad_culler.h"
18 #include "cc/test/render_pass_test_common.h"
19 #include "cc/test/render_pass_test_utils.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkXfermode.h"
23 namespace cc {
24 namespace test {
26 void AddTestSurfaceQuad(TestRenderPass* pass,
27 const gfx::Size& surface_size,
28 int 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 float opacity = 1.0;
35 SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
37 scoped_ptr<SharedQuadState> shared_quad_state = SharedQuadState::Create();
38 shared_quad_state->SetAll(content_to_target_transform,
39 content_bounds,
40 visible_content_rect,
41 clip_rect,
42 is_clipped,
43 opacity,
44 blend_mode);
45 pass->shared_quad_state_list.push_back(shared_quad_state.Pass());
47 scoped_ptr<SurfaceDrawQuad> surface_quad = SurfaceDrawQuad::Create();
48 gfx::Rect quad_rect = gfx::Rect(surface_size);
49 surface_quad->SetNew(
50 pass->shared_quad_state_list.back(), gfx::Rect(surface_size), surface_id);
51 pass->quad_list.push_back(surface_quad.PassAs<DrawQuad>());
53 void AddTestRenderPassQuad(TestRenderPass* pass,
54 RenderPass::Id render_pass_id) {
55 MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
56 AppendQuadsData data(pass->id);
57 gfx::Rect output_rect = gfx::Rect(0, 0, 5, 5);
58 SharedQuadState* shared_state =
59 quad_sink.UseSharedQuadState(SharedQuadState::Create());
60 shared_state->SetAll(gfx::Transform(),
61 output_rect.size(),
62 output_rect,
63 output_rect,
64 false,
66 SkXfermode::kSrcOver_Mode);
67 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create();
68 quad->SetNew(shared_state,
69 output_rect,
70 render_pass_id,
71 false,
73 output_rect,
74 gfx::RectF(),
75 FilterOperations(),
76 FilterOperations());
77 quad_sink.Append(quad.PassAs<DrawQuad>(), &data);
80 void AddQuadInPass(TestRenderPass* pass, Quad desc) {
81 switch (desc.material) {
82 case DrawQuad::SOLID_COLOR:
83 AddQuad(pass, gfx::Rect(0, 0, 5, 5), desc.color);
84 break;
85 case DrawQuad::SURFACE_CONTENT:
86 AddTestSurfaceQuad(pass, gfx::Size(5, 5), desc.surface_id);
87 break;
88 case DrawQuad::RENDER_PASS:
89 AddTestRenderPassQuad(pass, desc.render_pass_id);
90 break;
91 default:
92 NOTREACHED();
96 void AddPasses(RenderPassList* pass_list,
97 const gfx::Rect& output_rect,
98 Pass* passes,
99 size_t pass_count) {
100 gfx::Transform root_transform;
101 for (size_t i = 0; i < pass_count; ++i) {
102 Pass pass = passes[i];
103 TestRenderPass* test_pass =
104 AddRenderPass(pass_list, pass.id, output_rect, root_transform);
105 for (size_t j = 0; j < pass.quad_count; ++j) {
106 AddQuadInPass(test_pass, pass.quads[j]);
111 void TestQuadMatchesExpectations(Quad expected_quad, DrawQuad* quad) {
112 switch (expected_quad.material) {
113 case DrawQuad::SOLID_COLOR: {
114 ASSERT_EQ(DrawQuad::SOLID_COLOR, quad->material);
116 const SolidColorDrawQuad* solid_color_quad =
117 SolidColorDrawQuad::MaterialCast(quad);
119 EXPECT_EQ(expected_quad.color, solid_color_quad->color);
120 break;
122 default:
123 NOTREACHED();
124 break;
128 void TestPassMatchesExpectations(Pass expected_pass, RenderPass* pass) {
129 ASSERT_EQ(expected_pass.quad_count, pass->quad_list.size());
130 for (size_t i = 0u; i < pass->quad_list.size(); ++i) {
131 SCOPED_TRACE(base::StringPrintf("Quad number %" PRIuS, i));
132 TestQuadMatchesExpectations(expected_pass.quads[i], pass->quad_list.at(i));
136 void TestPassesMatchExpectations(Pass* expected_passes,
137 size_t expected_pass_count,
138 RenderPassList* passes) {
139 ASSERT_EQ(expected_pass_count, passes->size());
141 for (size_t i = 0; i < passes->size(); ++i) {
142 SCOPED_TRACE(base::StringPrintf("Pass number %" PRIuS, i));
143 RenderPass* pass = passes->at(i);
144 TestPassMatchesExpectations(expected_passes[i], pass);
148 void SubmitFrame(Pass* passes, size_t pass_count, Surface* surface) {
149 RenderPassList pass_list;
150 AddPasses(&pass_list, gfx::Rect(surface->size()), passes, pass_count);
152 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
153 pass_list.swap(frame_data->render_pass_list);
155 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
156 frame->delegated_frame_data = frame_data.Pass();
158 surface->QueueFrame(frame.Pass());
161 void QueuePassAsFrame(scoped_ptr<RenderPass> pass, Surface* surface) {
162 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
163 delegated_frame_data->render_pass_list.push_back(pass.Pass());
165 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
166 child_frame->delegated_frame_data = delegated_frame_data.Pass();
168 surface->QueueFrame(child_frame.Pass());
171 } // namespace test
172 } // namespace cc