| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/canvas_skia.h" | 9 #include "ui/gfx/canvas_skia.h" |
| 10 #include "ui/gfx/compositor/compositor_observer.h" | 10 #include "ui/gfx/compositor/compositor_observer.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 virtual ~NullLayerDelegate() {} | 166 virtual ~NullLayerDelegate() {} |
| 167 | 167 |
| 168 private: | 168 private: |
| 169 // Overridden from LayerDelegate: | 169 // Overridden from LayerDelegate: |
| 170 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 170 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
| 171 } | 171 } |
| 172 | 172 |
| 173 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); | 173 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 // Remembers if it has been notified. |
| 177 class TestCompositorObserver : public CompositorObserver { |
| 178 public: |
| 179 TestCompositorObserver() : notified_(false) {} |
| 180 |
| 181 bool notified() const { return notified_; } |
| 182 |
| 183 void Reset() { notified_ = false; } |
| 184 |
| 185 private: |
| 186 virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE { |
| 187 notified_ = true; |
| 188 } |
| 189 |
| 190 bool notified_; |
| 191 |
| 192 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); |
| 193 }; |
| 194 |
| 176 } | 195 } |
| 177 | 196 |
| 178 #if defined(OS_WIN) | 197 #if defined(OS_WIN) |
| 179 // These are disabled on windows as they don't run correctly on the buildbot. | 198 // These are disabled on windows as they don't run correctly on the buildbot. |
| 180 // Reenable once we move to the real compositor. | 199 // Reenable once we move to the real compositor. |
| 181 #define MAYBE_Delegate DISABLED_Delegate | 200 #define MAYBE_Delegate DISABLED_Delegate |
| 182 #define MAYBE_Draw DISABLED_Draw | 201 #define MAYBE_Draw DISABLED_Draw |
| 183 #define MAYBE_DrawTree DISABLED_DrawTree | 202 #define MAYBE_DrawTree DISABLED_DrawTree |
| 184 #define MAYBE_Hierarchy DISABLED_Hierarchy | 203 #define MAYBE_Hierarchy DISABLED_Hierarchy |
| 185 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture | 204 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture |
| 186 #define MAYBE_DrawPixels DISABLED_DrawPixels | 205 #define MAYBE_DrawPixels DISABLED_DrawPixels |
| 206 #define MAYBE_CompositorObservers DISABLED_CompositorObservers |
| 187 #else | 207 #else |
| 188 #define MAYBE_Delegate Delegate | 208 #define MAYBE_Delegate Delegate |
| 189 #define MAYBE_Draw Draw | 209 #define MAYBE_Draw Draw |
| 190 #define MAYBE_DrawTree DrawTree | 210 #define MAYBE_DrawTree DrawTree |
| 191 #define MAYBE_Hierarchy Hierarchy | 211 #define MAYBE_Hierarchy Hierarchy |
| 192 #define MAYBE_HierarchyNoTexture HierarchyNoTexture | 212 #define MAYBE_HierarchyNoTexture HierarchyNoTexture |
| 193 #define MAYBE_DrawPixels DrawPixels | 213 #define MAYBE_DrawPixels DrawPixels |
| 214 #define MAYBE_CompositorObservers CompositorObservers |
| 194 #endif | 215 #endif |
| 195 | 216 |
| 196 TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) { | 217 TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) { |
| 197 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, | 218 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, |
| 198 gfx::Rect(20, 20, 50, 50))); | 219 gfx::Rect(20, 20, 50, 50))); |
| 199 DrawTree(layer.get()); | 220 DrawTree(layer.get()); |
| 200 } | 221 } |
| 201 | 222 |
| 202 // Create this hierarchy: | 223 // Create this hierarchy: |
| 203 // L1 - red | 224 // L1 - red |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 | 818 |
| 798 SkAutoLockPixels lock(bitmap); | 819 SkAutoLockPixels lock(bitmap); |
| 799 bool is_all_red = true; | 820 bool is_all_red = true; |
| 800 for (int x = 0; is_all_red && x < 500; x++) | 821 for (int x = 0; is_all_red && x < 500; x++) |
| 801 for (int y = 0; is_all_red && y < 500; y++) | 822 for (int y = 0; is_all_red && y < 500; y++) |
| 802 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); | 823 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); |
| 803 | 824 |
| 804 EXPECT_TRUE(is_all_red); | 825 EXPECT_TRUE(is_all_red); |
| 805 } | 826 } |
| 806 | 827 |
| 828 // Checks that compositor observers are notified when: |
| 829 // - DrawTree is called, |
| 830 // - After ScheduleDraw is called, or |
| 831 // - Whenever SetBounds, SetOpacity or SetTransform are called. |
| 832 // TODO(vollick): could be reorganized into compositor_unittest.cc |
| 833 TEST_F(LayerWithRealCompositorTest, MAYBE_CompositorObservers) { |
| 834 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
| 835 gfx::Rect(20, 20, 400, 400))); |
| 836 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
| 837 gfx::Rect(10, 10, 350, 350))); |
| 838 l1->Add(l2.get()); |
| 839 TestCompositorObserver observer; |
| 840 GetCompositor()->AddObserver(&observer); |
| 841 |
| 842 // Explicitly called DrawTree should cause the observers to be notified. |
| 843 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer. |
| 844 DrawTree(l1.get()); |
| 845 RunPendingMessages(); |
| 846 EXPECT_TRUE(observer.notified()); |
| 847 |
| 848 // As should scheduling a draw and waiting. |
| 849 observer.Reset(); |
| 850 l1->ScheduleDraw(); |
| 851 RunPendingMessages(); |
| 852 EXPECT_TRUE(observer.notified()); |
| 853 |
| 854 // Moving, but not resizing, a layer should alert the observers. |
| 855 observer.Reset(); |
| 856 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); |
| 857 RunPendingMessages(); |
| 858 EXPECT_TRUE(observer.notified()); |
| 859 |
| 860 // So should resizing a layer. |
| 861 observer.Reset(); |
| 862 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); |
| 863 RunPendingMessages(); |
| 864 EXPECT_TRUE(observer.notified()); |
| 865 |
| 866 // Opacity changes should alert the observers. |
| 867 observer.Reset(); |
| 868 l2->SetOpacity(0.5f); |
| 869 RunPendingMessages(); |
| 870 EXPECT_TRUE(observer.notified()); |
| 871 |
| 872 // So should setting the opacity back. |
| 873 observer.Reset(); |
| 874 l2->SetOpacity(1.0f); |
| 875 RunPendingMessages(); |
| 876 EXPECT_TRUE(observer.notified()); |
| 877 |
| 878 // Setting the transform of a layer should alert the observers. |
| 879 observer.Reset(); |
| 880 Transform transform; |
| 881 transform.ConcatTranslate(-200, -200); |
| 882 transform.ConcatRotate(90.0f); |
| 883 transform.ConcatTranslate(200, 200); |
| 884 l2->SetTransform(transform); |
| 885 RunPendingMessages(); |
| 886 EXPECT_TRUE(observer.notified()); |
| 887 |
| 888 GetCompositor()->RemoveObserver(&observer); |
| 889 |
| 890 // Opacity changes should no longer alert the removed observer. |
| 891 observer.Reset(); |
| 892 l2->SetOpacity(0.5f); |
| 893 RunPendingMessages(); |
| 894 EXPECT_FALSE(observer.notified()); |
| 895 } |
| 896 |
| 807 } // namespace ui | 897 } // namespace ui |
| OLD | NEW |