Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / layers / render_surface_unittest.cc
blob929407c4fe594f050f6d6a181ad7a9c0d0aff89b
1 // Copyright 2011 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/base/scoped_ptr_vector.h"
6 #include "cc/layers/append_quads_data.h"
7 #include "cc/layers/layer_impl.h"
8 #include "cc/layers/render_pass_sink.h"
9 #include "cc/layers/render_surface_impl.h"
10 #include "cc/quads/shared_quad_state.h"
11 #include "cc/test/fake_impl_proxy.h"
12 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/geometry_test_utils.h"
14 #include "cc/test/mock_occlusion_tracker.h"
15 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "cc/trees/single_thread_proxy.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gfx/transform.h"
21 namespace cc {
22 namespace {
24 #define EXECUTE_AND_VERIFY_SURFACE_CHANGED(code_to_test) \
25 render_surface->ResetPropertyChangedFlag(); \
26 code_to_test; \
27 EXPECT_TRUE(render_surface->SurfacePropertyChanged())
29 #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(code_to_test) \
30 render_surface->ResetPropertyChangedFlag(); \
31 code_to_test; \
32 EXPECT_FALSE(render_surface->SurfacePropertyChanged())
34 TEST(RenderSurfaceTest, VerifySurfaceChangesAreTrackedProperly) {
36 // This test checks that SurfacePropertyChanged() has the correct behavior.
39 FakeImplProxy proxy;
40 TestSharedBitmapManager shared_bitmap_manager;
41 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
42 scoped_ptr<LayerImpl> owning_layer =
43 LayerImpl::Create(host_impl.active_tree(), 1);
44 owning_layer->SetHasRenderSurface(true);
45 ASSERT_TRUE(owning_layer->render_surface());
46 RenderSurfaceImpl* render_surface = owning_layer->render_surface();
47 gfx::Rect test_rect(3, 4, 5, 6);
48 owning_layer->ResetAllChangeTrackingForSubtree();
50 // Currently, the content_rect, clip_rect, and
51 // owning_layer->layerPropertyChanged() are the only sources of change.
52 EXECUTE_AND_VERIFY_SURFACE_CHANGED(render_surface->SetClipRect(test_rect));
53 EXECUTE_AND_VERIFY_SURFACE_CHANGED(render_surface->SetContentRect(test_rect));
55 owning_layer->SetOpacity(0.5f);
56 EXPECT_TRUE(render_surface->SurfacePropertyChanged());
57 owning_layer->ResetAllChangeTrackingForSubtree();
59 // Setting the surface properties to the same values again should not be
60 // considered "change".
61 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(
62 render_surface->SetClipRect(test_rect));
63 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(
64 render_surface->SetContentRect(test_rect));
66 scoped_ptr<LayerImpl> dummy_mask =
67 LayerImpl::Create(host_impl.active_tree(), 2);
68 gfx::Transform dummy_matrix;
69 dummy_matrix.Translate(1.0, 2.0);
71 // The rest of the surface properties are either internal and should not cause
72 // change, or they are already accounted for by the
73 // owninglayer->layerPropertyChanged().
74 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(
75 render_surface->SetDrawOpacity(0.5f));
76 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(
77 render_surface->SetDrawTransform(dummy_matrix));
78 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(
79 render_surface->SetReplicaDrawTransform(dummy_matrix));
80 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(render_surface->ClearLayerLists());
83 TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectSharedQuadState) {
84 FakeImplProxy proxy;
85 TestSharedBitmapManager shared_bitmap_manager;
86 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
87 scoped_ptr<LayerImpl> root_layer =
88 LayerImpl::Create(host_impl.active_tree(), 1);
90 scoped_ptr<LayerImpl> owning_layer =
91 LayerImpl::Create(host_impl.active_tree(), 2);
92 owning_layer->SetHasRenderSurface(true);
93 ASSERT_TRUE(owning_layer->render_surface());
94 owning_layer->draw_properties().render_target = owning_layer.get();
96 SkXfermode::Mode blend_mode = SkXfermode::kSoftLight_Mode;
97 owning_layer->SetBlendMode(blend_mode);
98 RenderSurfaceImpl* render_surface = owning_layer->render_surface();
100 root_layer->AddChild(owning_layer.Pass());
102 gfx::Rect content_rect(0, 0, 50, 50);
103 gfx::Rect clip_rect(5, 5, 40, 40);
104 gfx::Transform origin;
105 origin.Translate(30, 40);
107 render_surface->SetContentRect(content_rect);
108 render_surface->SetClipRect(clip_rect);
109 render_surface->SetDrawOpacity(1.f);
111 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
112 AppendQuadsData append_quads_data;
114 render_surface->AppendQuads(render_pass.get(), origin, Occlusion(),
115 SK_ColorBLACK, 1.f, nullptr, &append_quads_data,
116 RenderPassId(2, 0));
118 ASSERT_EQ(1u, render_pass->shared_quad_state_list.size());
119 SharedQuadState* shared_quad_state =
120 render_pass->shared_quad_state_list.front();
122 EXPECT_EQ(
123 30.0,
124 shared_quad_state->content_to_target_transform.matrix().getDouble(0, 3));
125 EXPECT_EQ(
126 40.0,
127 shared_quad_state->content_to_target_transform.matrix().getDouble(1, 3));
128 EXPECT_EQ(content_rect, gfx::Rect(shared_quad_state->visible_content_rect));
129 EXPECT_EQ(1.f, shared_quad_state->opacity);
130 EXPECT_EQ(blend_mode, shared_quad_state->blend_mode);
133 class TestRenderPassSink : public RenderPassSink {
134 public:
135 void AppendRenderPass(scoped_ptr<RenderPass> render_pass) override {
136 render_passes_.push_back(render_pass.Pass());
139 const RenderPassList& RenderPasses() const {
140 return render_passes_;
143 private:
144 RenderPassList render_passes_;
147 TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectRenderPass) {
148 FakeImplProxy proxy;
149 TestSharedBitmapManager shared_bitmap_manager;
150 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
151 scoped_ptr<LayerImpl> root_layer =
152 LayerImpl::Create(host_impl.active_tree(), 1);
154 scoped_ptr<LayerImpl> owning_layer =
155 LayerImpl::Create(host_impl.active_tree(), 2);
156 owning_layer->SetHasRenderSurface(true);
157 ASSERT_TRUE(owning_layer->render_surface());
158 owning_layer->draw_properties().render_target = owning_layer.get();
159 RenderSurfaceImpl* render_surface = owning_layer->render_surface();
161 root_layer->AddChild(owning_layer.Pass());
163 gfx::Rect content_rect(0, 0, 50, 50);
164 gfx::Transform origin;
165 origin.Translate(30.0, 40.0);
167 render_surface->SetScreenSpaceTransform(origin);
168 render_surface->SetContentRect(content_rect);
170 TestRenderPassSink pass_sink;
172 render_surface->AppendRenderPasses(&pass_sink);
174 ASSERT_EQ(1u, pass_sink.RenderPasses().size());
175 RenderPass* pass = pass_sink.RenderPasses()[0];
177 EXPECT_EQ(RenderPassId(2, 0), pass->id);
178 EXPECT_EQ(content_rect, pass->output_rect);
179 EXPECT_EQ(origin, pass->transform_to_root_target);
182 } // namespace
183 } // namespace cc