• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "cc/surfaces/surface_aggregator_test_helpers.h"
6 
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"
21 
22 namespace cc {
23 namespace test {
24 
AddTestSurfaceQuad(TestRenderPass * pass,const gfx::Size & surface_size,SurfaceId surface_id)25 void AddTestSurfaceQuad(TestRenderPass* pass,
26                         const gfx::Size& surface_size,
27                         SurfaceId surface_id) {
28   gfx::Transform content_to_target_transform;
29   gfx::Size content_bounds = surface_size;
30   gfx::Rect visible_content_rect = gfx::Rect(surface_size);
31   gfx::Rect clip_rect = gfx::Rect(surface_size);
32   bool is_clipped = false;
33   float opacity = 1.0;
34   SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
35 
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);
45 
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);
53 }
AddTestRenderPassQuad(TestRenderPass * pass,RenderPassId render_pass_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,
62                        1,
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,
71                0,
72                gfx::RectF(),
73                FilterOperations(),
74                gfx::Vector2dF(),
75                FilterOperations());
76 }
77 
AddQuadInPass(TestRenderPass * pass,Quad desc)78 void AddQuadInPass(TestRenderPass* pass, Quad desc) {
79   switch (desc.material) {
80     case DrawQuad::SOLID_COLOR:
81       AddQuad(pass, gfx::Rect(0, 0, 5, 5), desc.color);
82       break;
83     case DrawQuad::SURFACE_CONTENT:
84       AddTestSurfaceQuad(pass, gfx::Size(5, 5), desc.surface_id);
85       break;
86     case DrawQuad::RENDER_PASS:
87       AddTestRenderPassQuad(pass, desc.render_pass_id);
88       break;
89     default:
90       NOTREACHED();
91   }
92 }
93 
AddPasses(RenderPassList * pass_list,const gfx::Rect & output_rect,Pass * passes,size_t pass_count)94 void AddPasses(RenderPassList* pass_list,
95                const gfx::Rect& output_rect,
96                Pass* passes,
97                size_t pass_count) {
98   gfx::Transform root_transform;
99   for (size_t i = 0; i < pass_count; ++i) {
100     Pass pass = passes[i];
101     TestRenderPass* test_pass =
102         AddRenderPass(pass_list, pass.id, output_rect, root_transform);
103     for (size_t j = 0; j < pass.quad_count; ++j) {
104       AddQuadInPass(test_pass, pass.quads[j]);
105     }
106   }
107 }
108 
TestQuadMatchesExpectations(Quad expected_quad,const DrawQuad * quad)109 void TestQuadMatchesExpectations(Quad expected_quad, const DrawQuad* quad) {
110   switch (expected_quad.material) {
111     case DrawQuad::SOLID_COLOR: {
112       ASSERT_EQ(DrawQuad::SOLID_COLOR, quad->material);
113 
114       const SolidColorDrawQuad* solid_color_quad =
115           SolidColorDrawQuad::MaterialCast(quad);
116 
117       EXPECT_EQ(expected_quad.color, solid_color_quad->color);
118       break;
119     }
120     case DrawQuad::RENDER_PASS: {
121       ASSERT_EQ(DrawQuad::RENDER_PASS, quad->material);
122 
123       const RenderPassDrawQuad* render_pass_quad =
124           RenderPassDrawQuad::MaterialCast(quad);
125 
126       EXPECT_EQ(expected_quad.render_pass_id, render_pass_quad->render_pass_id);
127       break;
128     }
129     default:
130       NOTREACHED();
131       break;
132   }
133 }
134 
TestPassMatchesExpectations(Pass expected_pass,const RenderPass * pass)135 void TestPassMatchesExpectations(Pass expected_pass, const RenderPass* pass) {
136   ASSERT_EQ(expected_pass.quad_count, pass->quad_list.size());
137   size_t i = 0;
138   for (QuadList::ConstIterator iter = pass->quad_list.begin();
139        iter != pass->quad_list.end();
140        ++iter) {
141     SCOPED_TRACE(base::StringPrintf("Quad number %" PRIuS, i));
142     TestQuadMatchesExpectations(expected_pass.quads[i], &*iter);
143     ++i;
144   }
145 }
146 
TestPassesMatchExpectations(Pass * expected_passes,size_t expected_pass_count,const RenderPassList * passes)147 void TestPassesMatchExpectations(Pass* expected_passes,
148                                  size_t expected_pass_count,
149                                  const RenderPassList* passes) {
150   ASSERT_EQ(expected_pass_count, passes->size());
151 
152   for (size_t i = 0; i < passes->size(); ++i) {
153     SCOPED_TRACE(base::StringPrintf("Pass number %" PRIuS, i));
154     RenderPass* pass = passes->at(i);
155     TestPassMatchesExpectations(expected_passes[i], pass);
156   }
157 }
158 
159 }  // namespace test
160 }  // namespace cc
161