| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/layer_tree_host.h" | 7 #include "cc/layer_tree_host.h" |
| 8 | 8 |
| 9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 #include "cc/content_layer.h" | 10 #include "cc/content_layer.h" |
| 11 #include "cc/content_layer_client.h" | 11 #include "cc/content_layer_client.h" |
| 12 #include "cc/graphics_context.h" | 12 #include "cc/graphics_context.h" |
| 13 #include "cc/layer_tree_host_impl.h" | 13 #include "cc/layer_tree_host_impl.h" |
| 14 #include "cc/settings.h" | 14 #include "cc/settings.h" |
| 15 #include "cc/single_thread_proxy.h" | 15 #include "cc/single_thread_proxy.h" |
| 16 #include "cc/test/fake_web_compositor_output_surface.h" | 16 #include "cc/test/fake_web_compositor_output_surface.h" |
| 17 #include "cc/test/geometry_test_utils.h" | 17 #include "cc/test/geometry_test_utils.h" |
| 18 #include "cc/test/layer_tree_test_common.h" | 18 #include "cc/test/layer_tree_test_common.h" |
| 19 #include "cc/test/occlusion_tracker_test_common.h" | 19 #include "cc/test/occlusion_tracker_test_common.h" |
| 20 #include "cc/resource_update_queue.h" | 20 #include "cc/resource_update_queue.h" |
| 21 #include "cc/timing_function.h" | 21 #include "cc/timing_function.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "third_party/khronos/GLES2/gl2.h" | 23 #include "third_party/khronos/GLES2/gl2.h" |
| 24 #include "third_party/khronos/GLES2/gl2ext.h" | 24 #include "third_party/khronos/GLES2/gl2ext.h" |
| 25 #include <public/Platform.h> | |
| 26 #include <public/WebLayerScrollClient.h> | 25 #include <public/WebLayerScrollClient.h> |
| 27 #include <public/WebSize.h> | 26 #include <public/WebSize.h> |
| 28 | 27 |
| 29 using namespace cc; | 28 using namespace cc; |
| 30 using namespace WebKit; | 29 using namespace WebKit; |
| 31 using namespace WebKitTests; | 30 using namespace WebKitTests; |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 class LayerTreeHostTest : public ThreadedTest { }; | 34 class LayerTreeHostTest : public ThreadedTest { }; |
| (...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 } | 1072 } |
| 1074 | 1073 |
| 1075 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 1074 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 1076 { | 1075 { |
| 1077 impl->rootLayer()->setScrollable(true); | 1076 impl->rootLayer()->setScrollable(true); |
| 1078 impl->rootLayer()->setScrollPosition(IntPoint()); | 1077 impl->rootLayer()->setScrollPosition(IntPoint()); |
| 1079 impl->setPageScaleFactorAndLimits(impl->pageScaleFactor(), 0.5, 2); | 1078 impl->setPageScaleFactorAndLimits(impl->pageScaleFactor(), 0.5, 2); |
| 1080 | 1079 |
| 1081 // We request animation only once. | 1080 // We request animation only once. |
| 1082 if (!m_animationRequested) { | 1081 if (!m_animationRequested) { |
| 1083 m_mainThreadProxy->postTask(createThreadTask(this, &LayerTreeHostTes
tStartPageScaleAnimation::requestStartPageScaleAnimation)); | 1082 m_mainThreadProxy->postTask(FROM_HERE, base::Bind(&LayerTreeHostTest
StartPageScaleAnimation::requestStartPageScaleAnimation, base::Unretained(this))
); |
| 1084 m_animationRequested = true; | 1083 m_animationRequested = true; |
| 1085 } | 1084 } |
| 1086 } | 1085 } |
| 1087 | 1086 |
| 1088 virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale) OV
ERRIDE | 1087 virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale) OV
ERRIDE |
| 1089 { | 1088 { |
| 1090 IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition(); | 1089 IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition(); |
| 1091 m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta); | 1090 m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta); |
| 1092 m_layerTreeHost->setPageScaleFactorAndLimits(scale, 0.5, 2); | 1091 m_layerTreeHost->setPageScaleFactorAndLimits(scale, 0.5, 2); |
| 1093 } | 1092 } |
| (...skipping 1605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2699 { | 2698 { |
| 2700 m_layerTreeHost->setRootLayer(m_layer); | 2699 m_layerTreeHost->setRootLayer(m_layer); |
| 2701 m_layerTreeHost->setViewportSize(IntSize(10, 20), IntSize(10, 20)); | 2700 m_layerTreeHost->setViewportSize(IntSize(10, 20), IntSize(10, 20)); |
| 2702 | 2701 |
| 2703 WebTransformationMatrix identityMatrix; | 2702 WebTransformationMatrix identityMatrix; |
| 2704 setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, FloatPoin
t(0, 0), FloatPoint(0, 0), IntSize(10, 20), true); | 2703 setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, FloatPoin
t(0, 0), FloatPoint(0, 0), IntSize(10, 20), true); |
| 2705 | 2704 |
| 2706 postSetNeedsCommitToMainThread(); | 2705 postSetNeedsCommitToMainThread(); |
| 2707 } | 2706 } |
| 2708 | 2707 |
| 2709 class EvictTexturesTask : public WebKit::WebThread::Task { | |
| 2710 public: | |
| 2711 EvictTexturesTask(LayerTreeHostTestEvictTextures* test) : m_test(test) {
} | |
| 2712 virtual ~EvictTexturesTask() { } | |
| 2713 virtual void run() OVERRIDE | |
| 2714 { | |
| 2715 DCHECK(m_test->m_implForEvictTextures); | |
| 2716 m_test->m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMe
moryPolicy(0)); | |
| 2717 } | |
| 2718 | |
| 2719 private: | |
| 2720 LayerTreeHostTestEvictTextures* m_test; | |
| 2721 }; | |
| 2722 | |
| 2723 void postEvictTextures() | 2708 void postEvictTextures() |
| 2724 { | 2709 { |
| 2725 DCHECK(webThread()); | 2710 DCHECK(implThread()); |
| 2726 webThread()->postTask(new EvictTexturesTask(this)); | 2711 implThread()->postTask(base::Bind(&LayerTreeHostTestEvictTextures::evict
TexturesOnImplThread, |
| 2712 base::Unretained(this))); |
| 2713 } |
| 2714 |
| 2715 void evictTexturesOnImplThread() |
| 2716 { |
| 2717 DCHECK(m_implForEvictTextures); |
| 2718 m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0
)); |
| 2727 } | 2719 } |
| 2728 | 2720 |
| 2729 // Commit 1: Just commit and draw normally, then post an eviction at the end | 2721 // Commit 1: Just commit and draw normally, then post an eviction at the end |
| 2730 // that will trigger a commit. | 2722 // that will trigger a commit. |
| 2731 // Commit 2: Triggered by the eviction, let it go through and then set | 2723 // Commit 2: Triggered by the eviction, let it go through and then set |
| 2732 // needsCommit. | 2724 // needsCommit. |
| 2733 // Commit 3: Triggered by the setNeedsCommit. In layout(), post an eviction | 2725 // Commit 3: Triggered by the setNeedsCommit. In layout(), post an eviction |
| 2734 // task, which will be handled before the commit. Don't set needsCommit, it | 2726 // task, which will be handled before the commit. Don't set needsCommit, it |
| 2735 // should have been posted. A frame should not be drawn (note, | 2727 // should have been posted. A frame should not be drawn (note, |
| 2736 // didCommitAndDrawFrame may be called anyway). | 2728 // didCommitAndDrawFrame may be called anyway). |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2839 { | 2831 { |
| 2840 m_layerTreeHost->setRootLayer(m_layer); | 2832 m_layerTreeHost->setRootLayer(m_layer); |
| 2841 m_layerTreeHost->setViewportSize(IntSize(10, 20), IntSize(10, 20)); | 2833 m_layerTreeHost->setViewportSize(IntSize(10, 20), IntSize(10, 20)); |
| 2842 | 2834 |
| 2843 WebTransformationMatrix identityMatrix; | 2835 WebTransformationMatrix identityMatrix; |
| 2844 setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, FloatPoin
t(0, 0), FloatPoint(0, 0), IntSize(10, 20), true); | 2836 setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, FloatPoin
t(0, 0), FloatPoint(0, 0), IntSize(10, 20), true); |
| 2845 | 2837 |
| 2846 postSetNeedsCommitToMainThread(); | 2838 postSetNeedsCommitToMainThread(); |
| 2847 } | 2839 } |
| 2848 | 2840 |
| 2849 class EvictTexturesTask : public WebKit::WebThread::Task { | |
| 2850 public: | |
| 2851 EvictTexturesTask(LayerTreeHostTestLostContextAfterEvictTextures* test)
: m_test(test) { } | |
| 2852 virtual ~EvictTexturesTask() { } | |
| 2853 virtual void run() OVERRIDE | |
| 2854 { | |
| 2855 m_test->evictTexturesOnImplThread(); | |
| 2856 } | |
| 2857 | |
| 2858 private: | |
| 2859 LayerTreeHostTestLostContextAfterEvictTextures* m_test; | |
| 2860 }; | |
| 2861 | |
| 2862 void postEvictTextures() | 2841 void postEvictTextures() |
| 2863 { | 2842 { |
| 2864 if (webThread()) | 2843 if (implThread()) { |
| 2865 webThread()->postTask(new EvictTexturesTask(this)); | 2844 implThread()->postTask(base::Bind(&LayerTreeHostTestLostContextAfter
EvictTextures::evictTexturesOnImplThread, |
| 2866 else { | 2845 base::Unretained(this))); |
| 2846 } else { |
| 2867 DebugScopedSetImplThread impl; | 2847 DebugScopedSetImplThread impl; |
| 2868 evictTexturesOnImplThread(); | 2848 evictTexturesOnImplThread(); |
| 2869 } | 2849 } |
| 2870 } | 2850 } |
| 2871 | 2851 |
| 2872 void evictTexturesOnImplThread() | 2852 void evictTexturesOnImplThread() |
| 2873 { | 2853 { |
| 2874 DCHECK(m_implForEvictTextures); | 2854 DCHECK(m_implForEvictTextures); |
| 2875 m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0
)); | 2855 m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0
)); |
| 2876 } | 2856 } |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3227 int m_numCommitsDeferred; | 3207 int m_numCommitsDeferred; |
| 3228 int m_numCompleteCommits; | 3208 int m_numCompleteCommits; |
| 3229 }; | 3209 }; |
| 3230 | 3210 |
| 3231 TEST_F(LayerTreeHostTestDeferCommits, runMultiThread) | 3211 TEST_F(LayerTreeHostTestDeferCommits, runMultiThread) |
| 3232 { | 3212 { |
| 3233 runTest(true); | 3213 runTest(true); |
| 3234 } | 3214 } |
| 3235 | 3215 |
| 3236 } // namespace | 3216 } // namespace |
| OLD | NEW |