Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: ui/compositor/layer_unittest.cc

Issue 21052007: aura: Clean up compositor initialization/destruction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanupcompositor: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "cc/layers/layer.h" 15 #include "cc/layers/layer.h"
16 #include "cc/output/delegated_frame_data.h" 16 #include "cc/output/delegated_frame_data.h"
17 #include "cc/test/pixel_test_utils.h" 17 #include "cc/test/pixel_test_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/compositor/compositor_observer.h" 19 #include "ui/compositor/compositor_observer.h"
20 #include "ui/compositor/compositor_setup.h"
21 #include "ui/compositor/layer.h" 20 #include "ui/compositor/layer.h"
22 #include "ui/compositor/layer_animation_sequence.h" 21 #include "ui/compositor/layer_animation_sequence.h"
23 #include "ui/compositor/layer_animator.h" 22 #include "ui/compositor/layer_animator.h"
24 #include "ui/compositor/test/test_compositor_host.h" 23 #include "ui/compositor/test/test_compositor_host.h"
25 #include "ui/compositor/test/test_layers.h" 24 #include "ui/compositor/test/test_layers.h"
26 #include "ui/gfx/canvas.h" 25 #include "ui/gfx/canvas.h"
27 #include "ui/gfx/codec/png_codec.h" 26 #include "ui/gfx/codec/png_codec.h"
28 #include "ui/gfx/gfx_paths.h" 27 #include "ui/gfx/gfx_paths.h"
29 #include "ui/gfx/skia_util.h" 28 #include "ui/gfx/skia_util.h"
30 29
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { 74 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) {
76 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); 75 test_data_directory_ = test_data_directory_.AppendASCII("compositor");
77 } else { 76 } else {
78 LOG(ERROR) << "Could not open test data directory."; 77 LOG(ERROR) << "Could not open test data directory.";
79 } 78 }
80 } 79 }
81 virtual ~LayerWithRealCompositorTest() {} 80 virtual ~LayerWithRealCompositorTest() {}
82 81
83 // Overridden from testing::Test: 82 // Overridden from testing::Test:
84 virtual void SetUp() OVERRIDE { 83 virtual void SetUp() OVERRIDE {
85 DisableTestCompositor(); 84 bool allow_test_contexts = false;
85 Compositor::InitializeContextFactoryForTests(allow_test_contexts);
86 Compositor::Initialize();
87
86 const gfx::Rect host_bounds(10, 10, 500, 500); 88 const gfx::Rect host_bounds(10, 10, 500, 500);
87 window_.reset(TestCompositorHost::Create(host_bounds)); 89 window_.reset(TestCompositorHost::Create(host_bounds));
88 window_->Show(); 90 window_->Show();
89 } 91 }
90 92
91 virtual void TearDown() OVERRIDE { 93 virtual void TearDown() OVERRIDE {
94 window_.reset();
95 Compositor::Terminate();
92 } 96 }
93 97
94 Compositor* GetCompositor() { 98 Compositor* GetCompositor() {
95 return window_->GetCompositor(); 99 return window_->GetCompositor();
96 } 100 }
97 101
98 Layer* CreateLayer(LayerType type) { 102 Layer* CreateLayer(LayerType type) {
99 return new Layer(type); 103 return new Layer(type);
100 } 104 }
101 105
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 bool aborted_; 307 bool aborted_;
304 308
305 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); 309 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver);
306 }; 310 };
307 311
308 } // namespace 312 } // namespace
309 313
310 #if defined(OS_WIN) 314 #if defined(OS_WIN)
311 // These are disabled on windows as they don't run correctly on the buildbot. 315 // These are disabled on windows as they don't run correctly on the buildbot.
312 // Reenable once we move to the real compositor. 316 // Reenable once we move to the real compositor.
313 #define MAYBE_Delegate DISABLED_Delegate 317 #define MAYBE_Delegate Delegate
314 #define MAYBE_Draw DISABLED_Draw 318 #define MAYBE_Draw Draw
315 #define MAYBE_DrawTree DISABLED_DrawTree 319 #define MAYBE_DrawTree DrawTree
316 #define MAYBE_Hierarchy DISABLED_Hierarchy 320 #define MAYBE_Hierarchy Hierarchy
317 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture 321 #define MAYBE_HierarchyNoTexture HierarchyNoTexture
318 #define MAYBE_DrawPixels DISABLED_DrawPixels 322 #define MAYBE_DrawPixels DrawPixels
319 #define MAYBE_SetRootLayer DISABLED_SetRootLayer 323 #define MAYBE_SetRootLayer SetRootLayer
320 #define MAYBE_CompositorObservers DISABLED_CompositorObservers 324 #define MAYBE_CompositorObservers CompositorObservers
321 #define MAYBE_ModifyHierarchy DISABLED_ModifyHierarchy 325 #define MAYBE_ModifyHierarchy ModifyHierarchy
322 #define MAYBE_Opacity DISABLED_Opacity 326 #define MAYBE_Opacity Opacity
323 #define MAYBE_ScaleUpDown DISABLED_ScaleUpDown 327 #define MAYBE_ScaleUpDown ScaleUpDown
324 #define MAYBE_ScaleReparent DISABLED_ScaleReparent 328 #define MAYBE_ScaleReparent ScaleReparent
325 #define MAYBE_NoScaleCanvas DISABLED_NoScaleCanvas 329 #define MAYBE_NoScaleCanvas NoScaleCanvas
326 #define MAYBE_AddRemoveThreadedAnimations DISABLED_AddRemoveThreadedAnimations 330 #define MAYBE_AddRemoveThreadedAnimations AddRemoveThreadedAnimations
327 #define MAYBE_SwitchCCLayerAnimations DISABLED_SwitchCCLayerAnimations 331 #define MAYBE_SwitchCCLayerAnimations SwitchCCLayerAnimations
328 #else 332 #else
329 #define MAYBE_Delegate Delegate 333 #define MAYBE_Delegate Delegate
330 #define MAYBE_Draw Draw 334 #define MAYBE_Draw Draw
331 #define MAYBE_DrawTree DrawTree 335 #define MAYBE_DrawTree DrawTree
332 #define MAYBE_Hierarchy Hierarchy 336 #define MAYBE_Hierarchy Hierarchy
333 #define MAYBE_HierarchyNoTexture HierarchyNoTexture 337 #define MAYBE_HierarchyNoTexture HierarchyNoTexture
334 #define MAYBE_DrawPixels DrawPixels 338 #define MAYBE_DrawPixels DrawPixels
335 #define MAYBE_SetRootLayer SetRootLayer 339 #define MAYBE_SetRootLayer SetRootLayer
336 #define MAYBE_CompositorObservers CompositorObservers 340 #define MAYBE_CompositorObservers CompositorObservers
337 #define MAYBE_ModifyHierarchy ModifyHierarchy 341 #define MAYBE_ModifyHierarchy ModifyHierarchy
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 DrawTree(l1.get()); 376 DrawTree(l1.get());
373 } 377 }
374 378
375 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { 379 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate {
376 public: 380 public:
377 LayerWithDelegateTest() {} 381 LayerWithDelegateTest() {}
378 virtual ~LayerWithDelegateTest() {} 382 virtual ~LayerWithDelegateTest() {}
379 383
380 // Overridden from testing::Test: 384 // Overridden from testing::Test:
381 virtual void SetUp() OVERRIDE { 385 virtual void SetUp() OVERRIDE {
382 ui::SetupTestCompositor(); 386 bool allow_test_contexts = true;
387 Compositor::InitializeContextFactoryForTests(allow_test_contexts);
388 Compositor::Initialize();
383 compositor_.reset(new Compositor(this, gfx::kNullAcceleratedWidget)); 389 compositor_.reset(new Compositor(this, gfx::kNullAcceleratedWidget));
384 compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); 390 compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000));
385 } 391 }
386 392
387 virtual void TearDown() OVERRIDE { 393 virtual void TearDown() OVERRIDE {
394 compositor_.reset();
395 Compositor::Terminate();
388 } 396 }
389 397
390 Compositor* compositor() { return compositor_.get(); } 398 Compositor* compositor() { return compositor_.get(); }
391 399
392 virtual Layer* CreateLayer(LayerType type) { 400 virtual Layer* CreateLayer(LayerType type) {
393 return new Layer(type); 401 return new Layer(type);
394 } 402 }
395 403
396 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 404 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
397 Layer* layer = new ColoredLayer(color); 405 Layer* layer = new ColoredLayer(color);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 EXPECT_FALSE(d2.painted()); 591 EXPECT_FALSE(d2.painted());
584 // |d3| should have received a paint notification. 592 // |d3| should have received a paint notification.
585 EXPECT_TRUE(d3.painted()); 593 EXPECT_TRUE(d3.painted());
586 } 594 }
587 595
588 class LayerWithNullDelegateTest : public LayerWithDelegateTest { 596 class LayerWithNullDelegateTest : public LayerWithDelegateTest {
589 public: 597 public:
590 LayerWithNullDelegateTest() {} 598 LayerWithNullDelegateTest() {}
591 virtual ~LayerWithNullDelegateTest() {} 599 virtual ~LayerWithNullDelegateTest() {}
592 600
593 // Overridden from testing::Test:
594 virtual void SetUp() OVERRIDE { 601 virtual void SetUp() OVERRIDE {
595 LayerWithDelegateTest::SetUp(); 602 LayerWithDelegateTest::SetUp();
596 default_layer_delegate_.reset(new NullLayerDelegate()); 603 default_layer_delegate_.reset(new NullLayerDelegate());
597 } 604 }
598 605
599 virtual void TearDown() OVERRIDE {
600 }
601
602 virtual Layer* CreateLayer(LayerType type) OVERRIDE { 606 virtual Layer* CreateLayer(LayerType type) OVERRIDE {
603 Layer* layer = new Layer(type); 607 Layer* layer = new Layer(type);
604 layer->set_delegate(default_layer_delegate_.get()); 608 layer->set_delegate(default_layer_delegate_.get());
605 return layer; 609 return layer;
606 } 610 }
607 611
608 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { 612 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) {
609 Layer* layer = CreateTextureLayer(bounds); 613 Layer* layer = CreateTextureLayer(bounds);
610 compositor()->SetRootLayer(layer); 614 compositor()->SetRootLayer(layer);
611 return layer; 615 return layer;
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 l1->SetOpacity(0.5f); 1423 l1->SetOpacity(0.5f);
1420 1424
1421 // Change l1's cc::Layer. 1425 // Change l1's cc::Layer.
1422 l1->SwitchCCLayerForTest(); 1426 l1->SwitchCCLayerForTest();
1423 1427
1424 // Ensure that the opacity animation completed. 1428 // Ensure that the opacity animation completed.
1425 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); 1429 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f);
1426 } 1430 }
1427 1431
1428 } // namespace ui 1432 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698