| OLD | NEW |
| (Empty) | |
| 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/output/compositor_frame.h" |
| 6 #include "cc/output/delegated_frame_data.h" |
| 7 #include "cc/quads/render_pass.h" |
| 8 #include "cc/quads/solid_color_draw_quad.h" |
| 9 #include "cc/quads/surface_draw_quad.h" |
| 10 #include "cc/surfaces/surface.h" |
| 11 #include "cc/surfaces/surface_aggregator.h" |
| 12 #include "cc/surfaces/surface_aggregator_test_helpers.h" |
| 13 #include "cc/surfaces/surface_manager.h" |
| 14 #include "cc/test/render_pass_test_common.h" |
| 15 #include "cc/test/render_pass_test_utils.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" |
| 18 |
| 19 namespace cc { |
| 20 namespace { |
| 21 const int kInvalidSurfaceId = -1; |
| 22 |
| 23 class SurfaceAggregatorTest : public testing::Test { |
| 24 public: |
| 25 SurfaceAggregatorTest() : aggregator_(&manager_) {} |
| 26 |
| 27 protected: |
| 28 SurfaceManager manager_; |
| 29 SurfaceAggregator aggregator_; |
| 30 }; |
| 31 |
| 32 TEST_F(SurfaceAggregatorTest, InvalidSurfaceId) { |
| 33 scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(kInvalidSurfaceId); |
| 34 EXPECT_FALSE(frame); |
| 35 } |
| 36 |
| 37 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { |
| 38 Surface one(&manager_, NULL, gfx::Size(5, 5)); |
| 39 scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(one.surface_id()); |
| 40 EXPECT_FALSE(frame); |
| 41 } |
| 42 |
| 43 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { |
| 44 public: |
| 45 SurfaceAggregatorValidSurfaceTest() |
| 46 : root_surface_(&manager_, NULL, gfx::Size(5, 5)) {} |
| 47 |
| 48 void AggregateAndVerify(test::Pass* expected_passes, |
| 49 size_t expected_pass_count) { |
| 50 scoped_ptr<CompositorFrame> aggregated_frame = |
| 51 aggregator_.Aggregate(root_surface_.surface_id()); |
| 52 |
| 53 ASSERT_TRUE(aggregated_frame); |
| 54 ASSERT_TRUE(aggregated_frame->delegated_frame_data); |
| 55 |
| 56 DelegatedFrameData* frame_data = |
| 57 aggregated_frame->delegated_frame_data.get(); |
| 58 |
| 59 TestPassesMatchExpectations( |
| 60 &frame_data->render_pass_list, expected_passes, expected_pass_count); |
| 61 } |
| 62 |
| 63 protected: |
| 64 Surface root_surface_; |
| 65 }; |
| 66 |
| 67 // Tests that a very simple frame containing only two solid color quads makes it |
| 68 // through the aggregator correctly. |
| 69 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleFrame) { |
| 70 test::Quad quads[] = {{'C', SK_ColorRED}, {'C', SK_ColorBLUE}}; |
| 71 test::Pass passes[] = {{quads, arraysize(quads)}}; |
| 72 |
| 73 SubmitFrame(passes, arraysize(passes), &root_surface_); |
| 74 |
| 75 AggregateAndVerify(passes, arraysize(passes)); |
| 76 } |
| 77 |
| 78 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSimpleFrame) { |
| 79 test::Quad quads[][2] = {{{'C', SK_ColorWHITE}, {'C', SK_ColorLTGRAY}}, |
| 80 {{'C', SK_ColorGRAY}, {'C', SK_ColorDKGRAY}}}; |
| 81 test::Pass passes[] = {{quads[0], arraysize(quads[0])}, |
| 82 {quads[1], arraysize(quads[1])}}; |
| 83 |
| 84 SubmitFrame(passes, arraysize(passes), &root_surface_); |
| 85 |
| 86 AggregateAndVerify(passes, arraysize(passes)); |
| 87 } |
| 88 |
| 89 // This tests very simple embedding. root_surface has a frame containing only a |
| 90 // surface quad referencing embedded_surface. embedded_surface has a frame |
| 91 // containing only a solid color quad. The solid color quad should be aggregated |
| 92 // into the final frame. |
| 93 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleSurfaceReference) { |
| 94 gfx::Size surface_size(5, 5); |
| 95 |
| 96 Surface embedded_surface(&manager_, NULL, surface_size); |
| 97 |
| 98 test::Quad embedded_quads[] = {{'C', SK_ColorGREEN}}; |
| 99 test::Pass embedded_passes[] = {{embedded_quads, arraysize(embedded_quads)}}; |
| 100 |
| 101 SubmitFrame(embedded_passes, arraysize(embedded_passes), &embedded_surface); |
| 102 |
| 103 test::Quad root_quads[] = {{'S', embedded_surface.surface_id()}}; |
| 104 test::Pass root_passes[] = {{root_quads, arraysize(root_quads)}}; |
| 105 |
| 106 SubmitFrame(root_passes, arraysize(root_passes), &root_surface_); |
| 107 |
| 108 test::Quad expected_quads[] = {{'C', SK_ColorGREEN}}; |
| 109 test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}}; |
| 110 AggregateAndVerify(expected_passes, arraysize(expected_passes)); |
| 111 } |
| 112 |
| 113 // This tests referencing a surface that has multiple render passes. |
| 114 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) { |
| 115 gfx::Size surface_size(5, 5); |
| 116 |
| 117 Surface embedded_surface(&manager_, NULL, surface_size); |
| 118 |
| 119 test::Quad embedded_quads[][1] = { |
| 120 {{'C', SK_ColorBLUE}}, {{'C', SK_ColorGREEN}}, {{'C', SK_ColorYELLOW}}}; |
| 121 test::Pass embedded_passes[] = { |
| 122 {embedded_quads[0], arraysize(embedded_quads[0])}, |
| 123 {embedded_quads[1], arraysize(embedded_quads[1])}, |
| 124 {embedded_quads[2], arraysize(embedded_quads[2])}}; |
| 125 |
| 126 SubmitFrame(embedded_passes, arraysize(embedded_passes), &embedded_surface); |
| 127 |
| 128 test::Quad root_quads[][1] = {{{'C', SK_ColorCYAN}}, |
| 129 {{'S', embedded_surface.surface_id()}}, |
| 130 {{'C', SK_ColorMAGENTA}}}; |
| 131 test::Pass root_passes[] = {{root_quads[0], arraysize(root_quads[0])}, |
| 132 {root_quads[1], arraysize(root_quads[1])}, |
| 133 {root_quads[2], arraysize(root_quads[2])}}; |
| 134 |
| 135 SubmitFrame(root_passes, arraysize(root_passes), &root_surface_); |
| 136 |
| 137 test::Quad expected_quads[][1] = {{{'C', SK_ColorCYAN}}, |
| 138 {{'C', SK_ColorBLUE}}, |
| 139 {{'C', SK_ColorGREEN}}, |
| 140 {{'C', SK_ColorYELLOW}}, |
| 141 {{'C', SK_ColorMAGENTA}}}; |
| 142 test::Pass expected_passes[] = { |
| 143 {expected_quads[0], arraysize(expected_quads[0])}, |
| 144 {expected_quads[1], arraysize(expected_quads[1])}, |
| 145 {expected_quads[2], arraysize(expected_quads[2])}, |
| 146 {expected_quads[3], arraysize(expected_quads[3])}, |
| 147 {expected_quads[4], arraysize(expected_quads[4])}}; |
| 148 AggregateAndVerify(expected_passes, arraysize(expected_passes)); |
| 149 } |
| 150 |
| 151 // Tests an invalid surface reference in a frame. The surface quad should just |
| 152 // be dropped. |
| 153 TEST_F(SurfaceAggregatorValidSurfaceTest, InvalidSurfaceReference) { |
| 154 test::Quad quads[] = {{'C', SK_ColorGREEN}, {'S', kInvalidSurfaceId}, |
| 155 {'C', SK_ColorBLUE}}; |
| 156 test::Pass passes[] = {{quads, arraysize(quads)}}; |
| 157 |
| 158 SubmitFrame(passes, arraysize(passes), &root_surface_); |
| 159 |
| 160 test::Quad expected_quads[] = {{'C', SK_ColorGREEN}, {'C', SK_ColorBLUE}}; |
| 161 test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}}; |
| 162 AggregateAndVerify(expected_passes, arraysize(expected_passes)); |
| 163 } |
| 164 |
| 165 // Tests a reference to a valid surface with no submitted frame. This quad |
| 166 // should also just be dropped. |
| 167 TEST_F(SurfaceAggregatorValidSurfaceTest, ValidSurfaceReferenceWithNoFrame) { |
| 168 Surface surface_with_no_frame(&manager_, NULL, gfx::Size(5, 5)); |
| 169 test::Quad quads[] = {{'C', SK_ColorGREEN}, |
| 170 {'S', surface_with_no_frame.surface_id()}, |
| 171 {'C', SK_ColorBLUE}}; |
| 172 test::Pass passes[] = {{quads, arraysize(quads)}}; |
| 173 |
| 174 SubmitFrame(passes, arraysize(passes), &root_surface_); |
| 175 |
| 176 test::Quad expected_quads[] = {{'C', SK_ColorGREEN}, {'C', SK_ColorBLUE}}; |
| 177 test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}}; |
| 178 AggregateAndVerify(expected_passes, arraysize(expected_passes)); |
| 179 } |
| 180 |
| 181 // Tests a surface quad referencing itself, generating a trivial cycle. |
| 182 // The quad creating the cycle should be dropped from the final frame. |
| 183 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleCyclicalReference) { |
| 184 test::Quad quads[] = {{'S', root_surface_.surface_id()}, |
| 185 {'C', SK_ColorYELLOW}}; |
| 186 test::Pass passes[] = {{quads, arraysize(quads)}}; |
| 187 |
| 188 SubmitFrame(passes, arraysize(passes), &root_surface_); |
| 189 |
| 190 test::Quad expected_quads[] = {{'C', SK_ColorYELLOW}}; |
| 191 test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}}; |
| 192 AggregateAndVerify(expected_passes, arraysize(expected_passes)); |
| 193 } |
| 194 |
| 195 // Tests a more complex cycle with one intermediate surface. |
| 196 TEST_F(SurfaceAggregatorValidSurfaceTest, TwoSurfaceCyclicalReference) { |
| 197 gfx::Size surface_size(5, 5); |
| 198 |
| 199 Surface child_surface(&manager_, NULL, surface_size); |
| 200 |
| 201 test::Quad parent_quads[] = {{'C', SK_ColorBLUE}, |
| 202 {'S', child_surface.surface_id()}, |
| 203 {'C', SK_ColorCYAN}}; |
| 204 test::Pass parent_passes[] = {{parent_quads, arraysize(parent_quads)}}; |
| 205 |
| 206 SubmitFrame(parent_passes, arraysize(parent_passes), &root_surface_); |
| 207 |
| 208 test::Quad child_quads[] = {{'C', SK_ColorGREEN}, |
| 209 {'S', root_surface_.surface_id()}, |
| 210 {'C', SK_ColorMAGENTA}}; |
| 211 test::Pass child_passes[] = {{child_quads, arraysize(child_quads)}}; |
| 212 |
| 213 SubmitFrame(child_passes, arraysize(child_passes), &child_surface); |
| 214 |
| 215 // The child surface's reference to the root_surface_ will be dropped, so |
| 216 // we'll end up with: |
| 217 // SK_ColorBLUE from the parent |
| 218 // SK_ColorGREEN from the child |
| 219 // SK_ColorMAGENTA from the child |
| 220 // SK_ColorCYAN from the parent |
| 221 test::Quad expected_quads[] = {{'C', SK_ColorBLUE}, |
| 222 {'C', SK_ColorGREEN}, |
| 223 {'C', SK_ColorMAGENTA}, |
| 224 {'C', SK_ColorCYAN}}; |
| 225 test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}}; |
| 226 AggregateAndVerify(expected_passes, arraysize(expected_passes)); |
| 227 } |
| 228 |
| 229 } // namespace |
| 230 } // namespace cc |
| OLD | NEW |