| Index: cc/surfaces/surface_aggregator_unittest.cc
|
| diff --git a/cc/surfaces/surface_aggregator_unittest.cc b/cc/surfaces/surface_aggregator_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..84f8a63891ab0f2d5831d2e9fa0ed32cc9886142
|
| --- /dev/null
|
| +++ b/cc/surfaces/surface_aggregator_unittest.cc
|
| @@ -0,0 +1,230 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "cc/output/compositor_frame.h"
|
| +#include "cc/output/delegated_frame_data.h"
|
| +#include "cc/quads/render_pass.h"
|
| +#include "cc/quads/solid_color_draw_quad.h"
|
| +#include "cc/quads/surface_draw_quad.h"
|
| +#include "cc/surfaces/surface.h"
|
| +#include "cc/surfaces/surface_aggregator.h"
|
| +#include "cc/surfaces/surface_aggregator_test_helpers.h"
|
| +#include "cc/surfaces/surface_manager.h"
|
| +#include "cc/test/render_pass_test_common.h"
|
| +#include "cc/test/render_pass_test_utils.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "third_party/skia/include/core/SkColor.h"
|
| +
|
| +namespace cc {
|
| +namespace {
|
| +const int kInvalidSurfaceId = -1;
|
| +
|
| +class SurfaceAggregatorTest : public testing::Test {
|
| + public:
|
| + SurfaceAggregatorTest() : aggregator_(&manager_) {}
|
| +
|
| + protected:
|
| + SurfaceManager manager_;
|
| + SurfaceAggregator aggregator_;
|
| +};
|
| +
|
| +TEST_F(SurfaceAggregatorTest, InvalidSurfaceId) {
|
| + scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(kInvalidSurfaceId);
|
| + EXPECT_FALSE(frame);
|
| +}
|
| +
|
| +TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) {
|
| + Surface one(&manager_, NULL, gfx::Size(5, 5));
|
| + scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(one.surface_id());
|
| + EXPECT_FALSE(frame);
|
| +}
|
| +
|
| +class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest {
|
| + public:
|
| + SurfaceAggregatorValidSurfaceTest()
|
| + : root_surface_(&manager_, NULL, gfx::Size(5, 5)) {}
|
| +
|
| + void AggregateAndVerify(test::Pass* expected_passes,
|
| + size_t expected_pass_count) {
|
| + scoped_ptr<CompositorFrame> aggregated_frame =
|
| + aggregator_.Aggregate(root_surface_.surface_id());
|
| +
|
| + ASSERT_TRUE(aggregated_frame);
|
| + ASSERT_TRUE(aggregated_frame->delegated_frame_data);
|
| +
|
| + DelegatedFrameData* frame_data =
|
| + aggregated_frame->delegated_frame_data.get();
|
| +
|
| + TestPassesMatchExpectations(
|
| + &frame_data->render_pass_list, expected_passes, expected_pass_count);
|
| + }
|
| +
|
| + protected:
|
| + Surface root_surface_;
|
| +};
|
| +
|
| +// Tests that a very simple frame containing only two solid color quads makes it
|
| +// through the aggregator correctly.
|
| +TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleFrame) {
|
| + test::Quad quads[] = {{'C', SK_ColorRED}, {'C', SK_ColorBLUE}};
|
| + test::Pass passes[] = {{quads, arraysize(quads)}};
|
| +
|
| + SubmitFrame(passes, arraysize(passes), &root_surface_);
|
| +
|
| + AggregateAndVerify(passes, arraysize(passes));
|
| +}
|
| +
|
| +TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSimpleFrame) {
|
| + test::Quad quads[][2] = {{{'C', SK_ColorWHITE}, {'C', SK_ColorLTGRAY}},
|
| + {{'C', SK_ColorGRAY}, {'C', SK_ColorDKGRAY}}};
|
| + test::Pass passes[] = {{quads[0], arraysize(quads[0])},
|
| + {quads[1], arraysize(quads[1])}};
|
| +
|
| + SubmitFrame(passes, arraysize(passes), &root_surface_);
|
| +
|
| + AggregateAndVerify(passes, arraysize(passes));
|
| +}
|
| +
|
| +// This tests very simple embedding. root_surface has a frame containing only a
|
| +// surface quad referencing embedded_surface. embedded_surface has a frame
|
| +// containing only a solid color quad. The solid color quad should be aggregated
|
| +// into the final frame.
|
| +TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleSurfaceReference) {
|
| + gfx::Size surface_size(5, 5);
|
| +
|
| + Surface embedded_surface(&manager_, NULL, surface_size);
|
| +
|
| + test::Quad embedded_quads[] = {{'C', SK_ColorGREEN}};
|
| + test::Pass embedded_passes[] = {{embedded_quads, arraysize(embedded_quads)}};
|
| +
|
| + SubmitFrame(embedded_passes, arraysize(embedded_passes), &embedded_surface);
|
| +
|
| + test::Quad root_quads[] = {{'S', embedded_surface.surface_id()}};
|
| + test::Pass root_passes[] = {{root_quads, arraysize(root_quads)}};
|
| +
|
| + SubmitFrame(root_passes, arraysize(root_passes), &root_surface_);
|
| +
|
| + test::Quad expected_quads[] = {{'C', SK_ColorGREEN}};
|
| + test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}};
|
| + AggregateAndVerify(expected_passes, arraysize(expected_passes));
|
| +}
|
| +
|
| +// This tests referencing a surface that has multiple render passes.
|
| +TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) {
|
| + gfx::Size surface_size(5, 5);
|
| +
|
| + Surface embedded_surface(&manager_, NULL, surface_size);
|
| +
|
| + test::Quad embedded_quads[][1] = {
|
| + {{'C', SK_ColorBLUE}}, {{'C', SK_ColorGREEN}}, {{'C', SK_ColorYELLOW}}};
|
| + test::Pass embedded_passes[] = {
|
| + {embedded_quads[0], arraysize(embedded_quads[0])},
|
| + {embedded_quads[1], arraysize(embedded_quads[1])},
|
| + {embedded_quads[2], arraysize(embedded_quads[2])}};
|
| +
|
| + SubmitFrame(embedded_passes, arraysize(embedded_passes), &embedded_surface);
|
| +
|
| + test::Quad root_quads[][1] = {{{'C', SK_ColorCYAN}},
|
| + {{'S', embedded_surface.surface_id()}},
|
| + {{'C', SK_ColorMAGENTA}}};
|
| + test::Pass root_passes[] = {{root_quads[0], arraysize(root_quads[0])},
|
| + {root_quads[1], arraysize(root_quads[1])},
|
| + {root_quads[2], arraysize(root_quads[2])}};
|
| +
|
| + SubmitFrame(root_passes, arraysize(root_passes), &root_surface_);
|
| +
|
| + test::Quad expected_quads[][1] = {{{'C', SK_ColorCYAN}},
|
| + {{'C', SK_ColorBLUE}},
|
| + {{'C', SK_ColorGREEN}},
|
| + {{'C', SK_ColorYELLOW}},
|
| + {{'C', SK_ColorMAGENTA}}};
|
| + test::Pass expected_passes[] = {
|
| + {expected_quads[0], arraysize(expected_quads[0])},
|
| + {expected_quads[1], arraysize(expected_quads[1])},
|
| + {expected_quads[2], arraysize(expected_quads[2])},
|
| + {expected_quads[3], arraysize(expected_quads[3])},
|
| + {expected_quads[4], arraysize(expected_quads[4])}};
|
| + AggregateAndVerify(expected_passes, arraysize(expected_passes));
|
| +}
|
| +
|
| +// Tests an invalid surface reference in a frame. The surface quad should just
|
| +// be dropped.
|
| +TEST_F(SurfaceAggregatorValidSurfaceTest, InvalidSurfaceReference) {
|
| + test::Quad quads[] = {{'C', SK_ColorGREEN}, {'S', kInvalidSurfaceId},
|
| + {'C', SK_ColorBLUE}};
|
| + test::Pass passes[] = {{quads, arraysize(quads)}};
|
| +
|
| + SubmitFrame(passes, arraysize(passes), &root_surface_);
|
| +
|
| + test::Quad expected_quads[] = {{'C', SK_ColorGREEN}, {'C', SK_ColorBLUE}};
|
| + test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}};
|
| + AggregateAndVerify(expected_passes, arraysize(expected_passes));
|
| +}
|
| +
|
| +// Tests a reference to a valid surface with no submitted frame. This quad
|
| +// should also just be dropped.
|
| +TEST_F(SurfaceAggregatorValidSurfaceTest, ValidSurfaceReferenceWithNoFrame) {
|
| + Surface surface_with_no_frame(&manager_, NULL, gfx::Size(5, 5));
|
| + test::Quad quads[] = {{'C', SK_ColorGREEN},
|
| + {'S', surface_with_no_frame.surface_id()},
|
| + {'C', SK_ColorBLUE}};
|
| + test::Pass passes[] = {{quads, arraysize(quads)}};
|
| +
|
| + SubmitFrame(passes, arraysize(passes), &root_surface_);
|
| +
|
| + test::Quad expected_quads[] = {{'C', SK_ColorGREEN}, {'C', SK_ColorBLUE}};
|
| + test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}};
|
| + AggregateAndVerify(expected_passes, arraysize(expected_passes));
|
| +}
|
| +
|
| +// Tests a surface quad referencing itself, generating a trivial cycle.
|
| +// The quad creating the cycle should be dropped from the final frame.
|
| +TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleCyclicalReference) {
|
| + test::Quad quads[] = {{'S', root_surface_.surface_id()},
|
| + {'C', SK_ColorYELLOW}};
|
| + test::Pass passes[] = {{quads, arraysize(quads)}};
|
| +
|
| + SubmitFrame(passes, arraysize(passes), &root_surface_);
|
| +
|
| + test::Quad expected_quads[] = {{'C', SK_ColorYELLOW}};
|
| + test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}};
|
| + AggregateAndVerify(expected_passes, arraysize(expected_passes));
|
| +}
|
| +
|
| +// Tests a more complex cycle with one intermediate surface.
|
| +TEST_F(SurfaceAggregatorValidSurfaceTest, TwoSurfaceCyclicalReference) {
|
| + gfx::Size surface_size(5, 5);
|
| +
|
| + Surface child_surface(&manager_, NULL, surface_size);
|
| +
|
| + test::Quad parent_quads[] = {{'C', SK_ColorBLUE},
|
| + {'S', child_surface.surface_id()},
|
| + {'C', SK_ColorCYAN}};
|
| + test::Pass parent_passes[] = {{parent_quads, arraysize(parent_quads)}};
|
| +
|
| + SubmitFrame(parent_passes, arraysize(parent_passes), &root_surface_);
|
| +
|
| + test::Quad child_quads[] = {{'C', SK_ColorGREEN},
|
| + {'S', root_surface_.surface_id()},
|
| + {'C', SK_ColorMAGENTA}};
|
| + test::Pass child_passes[] = {{child_quads, arraysize(child_quads)}};
|
| +
|
| + SubmitFrame(child_passes, arraysize(child_passes), &child_surface);
|
| +
|
| + // The child surface's reference to the root_surface_ will be dropped, so
|
| + // we'll end up with:
|
| + // SK_ColorBLUE from the parent
|
| + // SK_ColorGREEN from the child
|
| + // SK_ColorMAGENTA from the child
|
| + // SK_ColorCYAN from the parent
|
| + test::Quad expected_quads[] = {{'C', SK_ColorBLUE},
|
| + {'C', SK_ColorGREEN},
|
| + {'C', SK_ColorMAGENTA},
|
| + {'C', SK_ColorCYAN}};
|
| + test::Pass expected_passes[] = {{expected_quads, arraysize(expected_quads)}};
|
| + AggregateAndVerify(expected_passes, arraysize(expected_passes));
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace cc
|
|
|