| 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 "CCLayerTreeHostImpl.h" | 7 #include "CCLayerTreeHostImpl.h" |
| 8 | 8 |
| 9 #include "CCDelegatedRendererLayerImpl.h" | 9 #include "CCDelegatedRendererLayerImpl.h" |
| 10 #include "CCHeadsUpDisplayLayerImpl.h" | 10 #include "CCHeadsUpDisplayLayerImpl.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "cc/test/geometry_test_utils.h" | 32 #include "cc/test/geometry_test_utils.h" |
| 33 #include "cc/test/layer_test_common.h" | 33 #include "cc/test/layer_test_common.h" |
| 34 #include "cc/test/render_pass_test_common.h" | 34 #include "cc/test/render_pass_test_common.h" |
| 35 #include "cc/test/test_common.h" | 35 #include "cc/test/test_common.h" |
| 36 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 38 #include <public/WebVideoFrame.h> | 38 #include <public/WebVideoFrame.h> |
| 39 #include <public/WebVideoFrameProvider.h> | 39 #include <public/WebVideoFrameProvider.h> |
| 40 | 40 |
| 41 using namespace cc; | 41 using namespace cc; |
| 42 using namespace CCLayerTestCommon; | 42 using namespace LayerTestCommon; |
| 43 using namespace WebKit; | 43 using namespace WebKit; |
| 44 using namespace WebKitTests; | 44 using namespace WebKitTests; |
| 45 | 45 |
| 46 using ::testing::Mock; | 46 using ::testing::Mock; |
| 47 using ::testing::Return; | 47 using ::testing::Return; |
| 48 using ::testing::AnyNumber; | 48 using ::testing::AnyNumber; |
| 49 using ::testing::AtLeast; | 49 using ::testing::AtLeast; |
| 50 using ::testing::_; | 50 using ::testing::_; |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 // This test is parametrized to run all tests with the | 54 // This test is parametrized to run all tests with the |
| 55 // CCSettings::pageScalePinchZoomEnabled field enabled and disabled. | 55 // Settings::pageScalePinchZoomEnabled field enabled and disabled. |
| 56 class CCLayerTreeHostImplTest : public testing::TestWithParam<bool>, | 56 class LayerTreeHostImplTest : public testing::TestWithParam<bool>, |
| 57 public CCLayerTreeHostImplClient { | 57 public LayerTreeHostImplClient { |
| 58 public: | 58 public: |
| 59 CCLayerTreeHostImplTest() | 59 LayerTreeHostImplTest() |
| 60 : m_onCanDrawStateChangedCalled(false) | 60 : m_onCanDrawStateChangedCalled(false) |
| 61 , m_didRequestCommit(false) | 61 , m_didRequestCommit(false) |
| 62 , m_didRequestRedraw(false) | 62 , m_didRequestRedraw(false) |
| 63 , m_reduceMemoryResult(true) | 63 , m_reduceMemoryResult(true) |
| 64 { | 64 { |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual void SetUp() | 67 virtual void SetUp() |
| 68 { | 68 { |
| 69 CCSettings::setPageScalePinchZoomEnabled(GetParam()); | 69 Settings::setPageScalePinchZoomEnabled(GetParam()); |
| 70 CCLayerTreeSettings settings; | 70 LayerTreeSettings settings; |
| 71 settings.minimumOcclusionTrackingSize = IntSize(); | 71 settings.minimumOcclusionTrackingSize = IntSize(); |
| 72 | 72 |
| 73 m_hostImpl = CCLayerTreeHostImpl::create(settings, this); | 73 m_hostImpl = LayerTreeHostImpl::create(settings, this); |
| 74 m_hostImpl->initializeRenderer(createContext()); | 74 m_hostImpl->initializeRenderer(createContext()); |
| 75 m_hostImpl->setViewportSize(IntSize(10, 10), IntSize(10, 10)); | 75 m_hostImpl->setViewportSize(IntSize(10, 10), IntSize(10, 10)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 virtual void TearDown() | 78 virtual void TearDown() |
| 79 { | 79 { |
| 80 CCSettings::reset(); | 80 Settings::reset(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 virtual void didLoseContextOnImplThread() OVERRIDE { } | 83 virtual void didLoseContextOnImplThread() OVERRIDE { } |
| 84 virtual void onSwapBuffersCompleteOnImplThread() OVERRIDE { } | 84 virtual void onSwapBuffersCompleteOnImplThread() OVERRIDE { } |
| 85 virtual void onVSyncParametersChanged(double, double) OVERRIDE { } | 85 virtual void onVSyncParametersChanged(double, double) OVERRIDE { } |
| 86 virtual void onCanDrawStateChanged(bool canDraw) OVERRIDE { m_onCanDrawState
ChangedCalled = true; } | 86 virtual void onCanDrawStateChanged(bool canDraw) OVERRIDE { m_onCanDrawState
ChangedCalled = true; } |
| 87 virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_didRequestRedraw = tr
ue; } | 87 virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_didRequestRedraw = tr
ue; } |
| 88 virtual void setNeedsCommitOnImplThread() OVERRIDE { m_didRequestCommit = tr
ue; } | 88 virtual void setNeedsCommitOnImplThread() OVERRIDE { m_didRequestCommit = tr
ue; } |
| 89 virtual void postAnimationEventsToMainThreadOnImplThread(scoped_ptr<CCAnimat
ionEventsVector>, double wallClockTime) OVERRIDE { } | 89 virtual void postAnimationEventsToMainThreadOnImplThread(scoped_ptr<Animatio
nEventsVector>, double wallClockTime) OVERRIDE { } |
| 90 virtual bool reduceContentsTextureMemoryOnImplThread(size_t limitBytes) OVER
RIDE { return m_reduceMemoryResult; } | 90 virtual bool reduceContentsTextureMemoryOnImplThread(size_t limitBytes) OVER
RIDE { return m_reduceMemoryResult; } |
| 91 | 91 |
| 92 void setReduceMemoryResult(bool reduceMemoryResult) { m_reduceMemoryResult =
reduceMemoryResult; } | 92 void setReduceMemoryResult(bool reduceMemoryResult) { m_reduceMemoryResult =
reduceMemoryResult; } |
| 93 | 93 |
| 94 scoped_ptr<CCLayerTreeHostImpl> createLayerTreeHost(bool partialSwap, scoped
_ptr<CCGraphicsContext> graphicsContext, scoped_ptr<CCLayerImpl> root) | 94 scoped_ptr<LayerTreeHostImpl> createLayerTreeHost(bool partialSwap, scoped_p
tr<GraphicsContext> graphicsContext, scoped_ptr<LayerImpl> root) |
| 95 { | 95 { |
| 96 CCSettings::setPartialSwapEnabled(partialSwap); | 96 Settings::setPartialSwapEnabled(partialSwap); |
| 97 | 97 |
| 98 CCLayerTreeSettings settings; | 98 LayerTreeSettings settings; |
| 99 settings.minimumOcclusionTrackingSize = IntSize(); | 99 settings.minimumOcclusionTrackingSize = IntSize(); |
| 100 | 100 |
| 101 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create
(settings, this); | 101 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(set
tings, this); |
| 102 | 102 |
| 103 myHostImpl->initializeRenderer(graphicsContext.Pass()); | 103 myHostImpl->initializeRenderer(graphicsContext.Pass()); |
| 104 myHostImpl->setViewportSize(IntSize(10, 10), IntSize(10, 10)); | 104 myHostImpl->setViewportSize(IntSize(10, 10), IntSize(10, 10)); |
| 105 | 105 |
| 106 root->setAnchorPoint(FloatPoint(0, 0)); | 106 root->setAnchorPoint(FloatPoint(0, 0)); |
| 107 root->setPosition(FloatPoint(0, 0)); | 107 root->setPosition(FloatPoint(0, 0)); |
| 108 root->setBounds(IntSize(10, 10)); | 108 root->setBounds(IntSize(10, 10)); |
| 109 root->setContentBounds(IntSize(10, 10)); | 109 root->setContentBounds(IntSize(10, 10)); |
| 110 root->setVisibleContentRect(IntRect(0, 0, 10, 10)); | 110 root->setVisibleContentRect(IntRect(0, 0, 10, 10)); |
| 111 root->setDrawsContent(true); | 111 root->setDrawsContent(true); |
| 112 myHostImpl->setRootLayer(root.Pass()); | 112 myHostImpl->setRootLayer(root.Pass()); |
| 113 return myHostImpl.Pass(); | 113 return myHostImpl.Pass(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 static void expectClearedScrollDeltasRecursive(CCLayerImpl* layer) | 116 static void expectClearedScrollDeltasRecursive(LayerImpl* layer) |
| 117 { | 117 { |
| 118 ASSERT_EQ(layer->scrollDelta(), IntSize()); | 118 ASSERT_EQ(layer->scrollDelta(), IntSize()); |
| 119 for (size_t i = 0; i < layer->children().size(); ++i) | 119 for (size_t i = 0; i < layer->children().size(); ++i) |
| 120 expectClearedScrollDeltasRecursive(layer->children()[i]); | 120 expectClearedScrollDeltasRecursive(layer->children()[i]); |
| 121 } | 121 } |
| 122 | 122 |
| 123 static void expectContains(const CCScrollAndScaleSet& scrollInfo, int id, co
nst IntSize& scrollDelta) | 123 static void expectContains(const ScrollAndScaleSet& scrollInfo, int id, cons
t IntSize& scrollDelta) |
| 124 { | 124 { |
| 125 int timesEncountered = 0; | 125 int timesEncountered = 0; |
| 126 | 126 |
| 127 for (size_t i = 0; i < scrollInfo.scrolls.size(); ++i) { | 127 for (size_t i = 0; i < scrollInfo.scrolls.size(); ++i) { |
| 128 if (scrollInfo.scrolls[i].layerId != id) | 128 if (scrollInfo.scrolls[i].layerId != id) |
| 129 continue; | 129 continue; |
| 130 EXPECT_EQ(scrollDelta.width(), scrollInfo.scrolls[i].scrollDelta.wid
th()); | 130 EXPECT_EQ(scrollDelta.width(), scrollInfo.scrolls[i].scrollDelta.wid
th()); |
| 131 EXPECT_EQ(scrollDelta.height(), scrollInfo.scrolls[i].scrollDelta.he
ight()); | 131 EXPECT_EQ(scrollDelta.height(), scrollInfo.scrolls[i].scrollDelta.he
ight()); |
| 132 timesEncountered++; | 132 timesEncountered++; |
| 133 } | 133 } |
| 134 | 134 |
| 135 ASSERT_EQ(timesEncountered, 1); | 135 ASSERT_EQ(timesEncountered, 1); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void setupScrollAndContentsLayers(const IntSize& contentSize) | 138 void setupScrollAndContentsLayers(const IntSize& contentSize) |
| 139 { | 139 { |
| 140 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 140 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 141 root->setScrollable(true); | 141 root->setScrollable(true); |
| 142 root->setScrollPosition(IntPoint(0, 0)); | 142 root->setScrollPosition(IntPoint(0, 0)); |
| 143 root->setMaxScrollPosition(contentSize); | 143 root->setMaxScrollPosition(contentSize); |
| 144 root->setBounds(contentSize); | 144 root->setBounds(contentSize); |
| 145 root->setContentBounds(contentSize); | 145 root->setContentBounds(contentSize); |
| 146 root->setPosition(FloatPoint(0, 0)); | 146 root->setPosition(FloatPoint(0, 0)); |
| 147 root->setAnchorPoint(FloatPoint(0, 0)); | 147 root->setAnchorPoint(FloatPoint(0, 0)); |
| 148 | 148 |
| 149 scoped_ptr<CCLayerImpl> contents = CCLayerImpl::create(2); | 149 scoped_ptr<LayerImpl> contents = LayerImpl::create(2); |
| 150 contents->setDrawsContent(true); | 150 contents->setDrawsContent(true); |
| 151 contents->setBounds(contentSize); | 151 contents->setBounds(contentSize); |
| 152 contents->setContentBounds(contentSize); | 152 contents->setContentBounds(contentSize); |
| 153 contents->setPosition(FloatPoint(0, 0)); | 153 contents->setPosition(FloatPoint(0, 0)); |
| 154 contents->setAnchorPoint(FloatPoint(0, 0)); | 154 contents->setAnchorPoint(FloatPoint(0, 0)); |
| 155 root->addChild(contents.Pass()); | 155 root->addChild(contents.Pass()); |
| 156 m_hostImpl->setRootLayer(root.Pass()); | 156 m_hostImpl->setRootLayer(root.Pass()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 static scoped_ptr<CCLayerImpl> createScrollableLayer(int id, const IntSize&
size) | 159 static scoped_ptr<LayerImpl> createScrollableLayer(int id, const IntSize& si
ze) |
| 160 { | 160 { |
| 161 scoped_ptr<CCLayerImpl> layer = CCLayerImpl::create(id); | 161 scoped_ptr<LayerImpl> layer = LayerImpl::create(id); |
| 162 layer->setScrollable(true); | 162 layer->setScrollable(true); |
| 163 layer->setDrawsContent(true); | 163 layer->setDrawsContent(true); |
| 164 layer->setBounds(size); | 164 layer->setBounds(size); |
| 165 layer->setContentBounds(size); | 165 layer->setContentBounds(size); |
| 166 layer->setMaxScrollPosition(IntSize(size.width() * 2, size.height() * 2)
); | 166 layer->setMaxScrollPosition(IntSize(size.width() * 2, size.height() * 2)
); |
| 167 return layer.Pass(); | 167 return layer.Pass(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void initializeRendererAndDrawFrame() | 170 void initializeRendererAndDrawFrame() |
| 171 { | 171 { |
| 172 m_hostImpl->initializeRenderer(createContext()); | 172 m_hostImpl->initializeRenderer(createContext()); |
| 173 CCLayerTreeHostImpl::FrameData frame; | 173 LayerTreeHostImpl::FrameData frame; |
| 174 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 174 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 175 m_hostImpl->drawLayers(frame); | 175 m_hostImpl->drawLayers(frame); |
| 176 m_hostImpl->didDrawAllLayers(frame); | 176 m_hostImpl->didDrawAllLayers(frame); |
| 177 } | 177 } |
| 178 | 178 |
| 179 protected: | 179 protected: |
| 180 scoped_ptr<CCGraphicsContext> createContext() | 180 scoped_ptr<GraphicsContext> createContext() |
| 181 { | 181 { |
| 182 return FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGrap
hicsContext3D>(new FakeWebGraphicsContext3D)).PassAs<CCGraphicsContext>(); | 182 return FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGrap
hicsContext3D>(new FakeWebGraphicsContext3D)).PassAs<GraphicsContext>(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 DebugScopedSetImplThread m_alwaysImplThread; | 185 DebugScopedSetImplThread m_alwaysImplThread; |
| 186 DebugScopedSetMainThreadBlocked m_alwaysMainThreadBlocked; | 186 DebugScopedSetMainThreadBlocked m_alwaysMainThreadBlocked; |
| 187 | 187 |
| 188 scoped_ptr<CCLayerTreeHostImpl> m_hostImpl; | 188 scoped_ptr<LayerTreeHostImpl> m_hostImpl; |
| 189 bool m_onCanDrawStateChangedCalled; | 189 bool m_onCanDrawStateChangedCalled; |
| 190 bool m_didRequestCommit; | 190 bool m_didRequestCommit; |
| 191 bool m_didRequestRedraw; | 191 bool m_didRequestRedraw; |
| 192 bool m_reduceMemoryResult; | 192 bool m_reduceMemoryResult; |
| 193 CCScopedSettings m_scopedSettings; | 193 ScopedSettings m_scopedSettings; |
| 194 }; | 194 }; |
| 195 | 195 |
| 196 class FakeWebGraphicsContext3DMakeCurrentFails : public FakeWebGraphicsContext3D
{ | 196 class FakeWebGraphicsContext3DMakeCurrentFails : public FakeWebGraphicsContext3D
{ |
| 197 public: | 197 public: |
| 198 virtual bool makeContextCurrent() { return false; } | 198 virtual bool makeContextCurrent() { return false; } |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 TEST_P(CCLayerTreeHostImplTest, notifyIfCanDrawChanged) | 201 TEST_P(LayerTreeHostImplTest, notifyIfCanDrawChanged) |
| 202 { | 202 { |
| 203 // Note: It is not possible to disable the renderer once it has been set, | 203 // Note: It is not possible to disable the renderer once it has been set, |
| 204 // so we do not need to test that disabling the renderer notifies us | 204 // so we do not need to test that disabling the renderer notifies us |
| 205 // that canDraw changed. | 205 // that canDraw changed. |
| 206 EXPECT_FALSE(m_hostImpl->canDraw()); | 206 EXPECT_FALSE(m_hostImpl->canDraw()); |
| 207 m_onCanDrawStateChangedCalled = false; | 207 m_onCanDrawStateChangedCalled = false; |
| 208 | 208 |
| 209 setupScrollAndContentsLayers(IntSize(100, 100)); | 209 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 210 EXPECT_TRUE(m_hostImpl->canDraw()); | 210 EXPECT_TRUE(m_hostImpl->canDraw()); |
| 211 EXPECT_TRUE(m_onCanDrawStateChangedCalled); | 211 EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 212 m_onCanDrawStateChangedCalled = false; | 212 m_onCanDrawStateChangedCalled = false; |
| 213 | 213 |
| 214 // Toggle the root layer to make sure it toggles canDraw | 214 // Toggle the root layer to make sure it toggles canDraw |
| 215 m_hostImpl->setRootLayer(scoped_ptr<CCLayerImpl>()); | 215 m_hostImpl->setRootLayer(scoped_ptr<LayerImpl>()); |
| 216 EXPECT_FALSE(m_hostImpl->canDraw()); | 216 EXPECT_FALSE(m_hostImpl->canDraw()); |
| 217 EXPECT_TRUE(m_onCanDrawStateChangedCalled); | 217 EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 218 m_onCanDrawStateChangedCalled = false; | 218 m_onCanDrawStateChangedCalled = false; |
| 219 | 219 |
| 220 setupScrollAndContentsLayers(IntSize(100, 100)); | 220 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 221 EXPECT_TRUE(m_hostImpl->canDraw()); | 221 EXPECT_TRUE(m_hostImpl->canDraw()); |
| 222 EXPECT_TRUE(m_onCanDrawStateChangedCalled); | 222 EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 223 m_onCanDrawStateChangedCalled = false; | 223 m_onCanDrawStateChangedCalled = false; |
| 224 | 224 |
| 225 // Toggle the device viewport size to make sure it toggles canDraw. | 225 // Toggle the device viewport size to make sure it toggles canDraw. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 249 EXPECT_FALSE(m_hostImpl->canDraw()); | 249 EXPECT_FALSE(m_hostImpl->canDraw()); |
| 250 EXPECT_TRUE(m_onCanDrawStateChangedCalled); | 250 EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 251 m_onCanDrawStateChangedCalled = false; | 251 m_onCanDrawStateChangedCalled = false; |
| 252 | 252 |
| 253 m_hostImpl->resetContentsTexturesPurged(); | 253 m_hostImpl->resetContentsTexturesPurged(); |
| 254 EXPECT_TRUE(m_hostImpl->canDraw()); | 254 EXPECT_TRUE(m_hostImpl->canDraw()); |
| 255 EXPECT_TRUE(m_onCanDrawStateChangedCalled); | 255 EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 256 m_onCanDrawStateChangedCalled = false; | 256 m_onCanDrawStateChangedCalled = false; |
| 257 } | 257 } |
| 258 | 258 |
| 259 TEST_P(CCLayerTreeHostImplTest, scrollDeltaNoLayers) | 259 TEST_P(LayerTreeHostImplTest, scrollDeltaNoLayers) |
| 260 { | 260 { |
| 261 ASSERT_FALSE(m_hostImpl->rootLayer()); | 261 ASSERT_FALSE(m_hostImpl->rootLayer()); |
| 262 | 262 |
| 263 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas
(); | 263 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 264 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); | 264 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); |
| 265 } | 265 } |
| 266 | 266 |
| 267 TEST_P(CCLayerTreeHostImplTest, scrollDeltaTreeButNoChanges) | 267 TEST_P(LayerTreeHostImplTest, scrollDeltaTreeButNoChanges) |
| 268 { | 268 { |
| 269 { | 269 { |
| 270 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 270 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 271 root->addChild(CCLayerImpl::create(2)); | 271 root->addChild(LayerImpl::create(2)); |
| 272 root->addChild(CCLayerImpl::create(3)); | 272 root->addChild(LayerImpl::create(3)); |
| 273 root->children()[1]->addChild(CCLayerImpl::create(4)); | 273 root->children()[1]->addChild(LayerImpl::create(4)); |
| 274 root->children()[1]->addChild(CCLayerImpl::create(5)); | 274 root->children()[1]->addChild(LayerImpl::create(5)); |
| 275 root->children()[1]->children()[0]->addChild(CCLayerImpl::create(6)); | 275 root->children()[1]->children()[0]->addChild(LayerImpl::create(6)); |
| 276 m_hostImpl->setRootLayer(root.Pass()); | 276 m_hostImpl->setRootLayer(root.Pass()); |
| 277 } | 277 } |
| 278 CCLayerImpl* root = m_hostImpl->rootLayer(); | 278 LayerImpl* root = m_hostImpl->rootLayer(); |
| 279 | 279 |
| 280 expectClearedScrollDeltasRecursive(root); | 280 expectClearedScrollDeltasRecursive(root); |
| 281 | 281 |
| 282 scoped_ptr<CCScrollAndScaleSet> scrollInfo; | 282 scoped_ptr<ScrollAndScaleSet> scrollInfo; |
| 283 | 283 |
| 284 scrollInfo = m_hostImpl->processScrollDeltas(); | 284 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 285 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); | 285 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); |
| 286 expectClearedScrollDeltasRecursive(root); | 286 expectClearedScrollDeltasRecursive(root); |
| 287 | 287 |
| 288 scrollInfo = m_hostImpl->processScrollDeltas(); | 288 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 289 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); | 289 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); |
| 290 expectClearedScrollDeltasRecursive(root); | 290 expectClearedScrollDeltasRecursive(root); |
| 291 } | 291 } |
| 292 | 292 |
| 293 TEST_P(CCLayerTreeHostImplTest, scrollDeltaRepeatedScrolls) | 293 TEST_P(LayerTreeHostImplTest, scrollDeltaRepeatedScrolls) |
| 294 { | 294 { |
| 295 IntPoint scrollPosition(20, 30); | 295 IntPoint scrollPosition(20, 30); |
| 296 IntSize scrollDelta(11, -15); | 296 IntSize scrollDelta(11, -15); |
| 297 { | 297 { |
| 298 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 298 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 299 root->setScrollPosition(scrollPosition); | 299 root->setScrollPosition(scrollPosition); |
| 300 root->setScrollable(true); | 300 root->setScrollable(true); |
| 301 root->setMaxScrollPosition(IntSize(100, 100)); | 301 root->setMaxScrollPosition(IntSize(100, 100)); |
| 302 root->scrollBy(scrollDelta); | 302 root->scrollBy(scrollDelta); |
| 303 m_hostImpl->setRootLayer(root.Pass()); | 303 m_hostImpl->setRootLayer(root.Pass()); |
| 304 } | 304 } |
| 305 CCLayerImpl* root = m_hostImpl->rootLayer(); | 305 LayerImpl* root = m_hostImpl->rootLayer(); |
| 306 | 306 |
| 307 scoped_ptr<CCScrollAndScaleSet> scrollInfo; | 307 scoped_ptr<ScrollAndScaleSet> scrollInfo; |
| 308 | 308 |
| 309 scrollInfo = m_hostImpl->processScrollDeltas(); | 309 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 310 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); | 310 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); |
| 311 EXPECT_EQ(root->sentScrollDelta(), scrollDelta); | 311 EXPECT_EQ(root->sentScrollDelta(), scrollDelta); |
| 312 expectContains(*scrollInfo, root->id(), scrollDelta); | 312 expectContains(*scrollInfo, root->id(), scrollDelta); |
| 313 | 313 |
| 314 IntSize scrollDelta2(-5, 27); | 314 IntSize scrollDelta2(-5, 27); |
| 315 root->scrollBy(scrollDelta2); | 315 root->scrollBy(scrollDelta2); |
| 316 scrollInfo = m_hostImpl->processScrollDeltas(); | 316 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 317 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); | 317 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); |
| 318 EXPECT_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2); | 318 EXPECT_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2); |
| 319 expectContains(*scrollInfo, root->id(), scrollDelta + scrollDelta2); | 319 expectContains(*scrollInfo, root->id(), scrollDelta + scrollDelta2); |
| 320 | 320 |
| 321 root->scrollBy(IntSize()); | 321 root->scrollBy(IntSize()); |
| 322 scrollInfo = m_hostImpl->processScrollDeltas(); | 322 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 323 EXPECT_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2); | 323 EXPECT_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2); |
| 324 } | 324 } |
| 325 | 325 |
| 326 TEST_P(CCLayerTreeHostImplTest, scrollRootCallsCommitAndRedraw) | 326 TEST_P(LayerTreeHostImplTest, scrollRootCallsCommitAndRedraw) |
| 327 { | 327 { |
| 328 setupScrollAndContentsLayers(IntSize(100, 100)); | 328 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 329 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 329 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 330 initializeRendererAndDrawFrame(); | 330 initializeRendererAndDrawFrame(); |
| 331 | 331 |
| 332 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 332 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 333 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); | 333 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); |
| 334 m_hostImpl->scrollEnd(); | 334 m_hostImpl->scrollEnd(); |
| 335 EXPECT_TRUE(m_didRequestRedraw); | 335 EXPECT_TRUE(m_didRequestRedraw); |
| 336 EXPECT_TRUE(m_didRequestCommit); | 336 EXPECT_TRUE(m_didRequestCommit); |
| 337 } | 337 } |
| 338 | 338 |
| 339 TEST_P(CCLayerTreeHostImplTest, scrollWithoutRootLayer) | 339 TEST_P(LayerTreeHostImplTest, scrollWithoutRootLayer) |
| 340 { | 340 { |
| 341 // We should not crash when trying to scroll an empty layer tree. | 341 // We should not crash when trying to scroll an empty layer tree. |
| 342 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollIgnored); | 342 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollIgnored); |
| 343 } | 343 } |
| 344 | 344 |
| 345 TEST_P(CCLayerTreeHostImplTest, scrollWithoutRenderer) | 345 TEST_P(LayerTreeHostImplTest, scrollWithoutRenderer) |
| 346 { | 346 { |
| 347 CCLayerTreeSettings settings; | 347 LayerTreeSettings settings; |
| 348 m_hostImpl = CCLayerTreeHostImpl::create(settings, this); | 348 m_hostImpl = LayerTreeHostImpl::create(settings, this); |
| 349 | 349 |
| 350 // Initialization will fail here. | 350 // Initialization will fail here. |
| 351 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrentFails)
).PassAs<CCGraphicsContext>()); | 351 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrentFails)
).PassAs<GraphicsContext>()); |
| 352 m_hostImpl->setViewportSize(IntSize(10, 10), IntSize(10, 10)); | 352 m_hostImpl->setViewportSize(IntSize(10, 10), IntSize(10, 10)); |
| 353 | 353 |
| 354 setupScrollAndContentsLayers(IntSize(100, 100)); | 354 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 355 | 355 |
| 356 // We should not crash when trying to scroll after the renderer initializati
on fails. | 356 // We should not crash when trying to scroll after the renderer initializati
on fails. |
| 357 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollIgnored); | 357 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollIgnored); |
| 358 } | 358 } |
| 359 | 359 |
| 360 TEST_P(CCLayerTreeHostImplTest, replaceTreeWhileScrolling) | 360 TEST_P(LayerTreeHostImplTest, replaceTreeWhileScrolling) |
| 361 { | 361 { |
| 362 const int scrollLayerId = 1; | 362 const int scrollLayerId = 1; |
| 363 | 363 |
| 364 setupScrollAndContentsLayers(IntSize(100, 100)); | 364 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 365 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 365 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 366 initializeRendererAndDrawFrame(); | 366 initializeRendererAndDrawFrame(); |
| 367 | 367 |
| 368 // We should not crash if the tree is replaced while we are scrolling. | 368 // We should not crash if the tree is replaced while we are scrolling. |
| 369 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 369 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 370 m_hostImpl->detachLayerTree(); | 370 m_hostImpl->detachLayerTree(); |
| 371 | 371 |
| 372 setupScrollAndContentsLayers(IntSize(100, 100)); | 372 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 373 | 373 |
| 374 // We should still be scrolling, because the scrolled layer also exists in t
he new tree. | 374 // We should still be scrolling, because the scrolled layer also exists in t
he new tree. |
| 375 IntSize scrollDelta(0, 10); | 375 IntSize scrollDelta(0, 10); |
| 376 m_hostImpl->scrollBy(IntPoint(), scrollDelta); | 376 m_hostImpl->scrollBy(IntPoint(), scrollDelta); |
| 377 m_hostImpl->scrollEnd(); | 377 m_hostImpl->scrollEnd(); |
| 378 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas
(); | 378 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 379 expectContains(*scrollInfo, scrollLayerId, scrollDelta); | 379 expectContains(*scrollInfo, scrollLayerId, scrollDelta); |
| 380 } | 380 } |
| 381 | 381 |
| 382 TEST_P(CCLayerTreeHostImplTest, clearRootRenderSurfaceAndScroll) | 382 TEST_P(LayerTreeHostImplTest, clearRootRenderSurfaceAndScroll) |
| 383 { | 383 { |
| 384 setupScrollAndContentsLayers(IntSize(100, 100)); | 384 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 385 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 385 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 386 initializeRendererAndDrawFrame(); | 386 initializeRendererAndDrawFrame(); |
| 387 | 387 |
| 388 // We should be able to scroll even if the root layer loses its render surfa
ce after the most | 388 // We should be able to scroll even if the root layer loses its render surfa
ce after the most |
| 389 // recent render. | 389 // recent render. |
| 390 m_hostImpl->rootLayer()->clearRenderSurface(); | 390 m_hostImpl->rootLayer()->clearRenderSurface(); |
| 391 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 391 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 392 } | 392 } |
| 393 | 393 |
| 394 TEST_P(CCLayerTreeHostImplTest, wheelEventHandlers) | 394 TEST_P(LayerTreeHostImplTest, wheelEventHandlers) |
| 395 { | 395 { |
| 396 setupScrollAndContentsLayers(IntSize(100, 100)); | 396 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 397 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 397 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 398 initializeRendererAndDrawFrame(); | 398 initializeRendererAndDrawFrame(); |
| 399 CCLayerImpl* root = m_hostImpl->rootLayer(); | 399 LayerImpl* root = m_hostImpl->rootLayer(); |
| 400 | 400 |
| 401 root->setHaveWheelEventHandlers(true); | 401 root->setHaveWheelEventHandlers(true); |
| 402 | 402 |
| 403 // With registered event handlers, wheel scrolls have to go to the main thre
ad. | 403 // With registered event handlers, wheel scrolls have to go to the main thre
ad. |
| 404 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollOnMainThread); | 404 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollOnMainThread); |
| 405 | 405 |
| 406 // But gesture scrolls can still be handled. | 406 // But gesture scrolls can still be handled. |
| 407 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Gest
ure), CCInputHandlerClient::ScrollStarted); | 407 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Gestur
e), InputHandlerClient::ScrollStarted); |
| 408 } | 408 } |
| 409 | 409 |
| 410 TEST_P(CCLayerTreeHostImplTest, shouldScrollOnMainThread) | 410 TEST_P(LayerTreeHostImplTest, shouldScrollOnMainThread) |
| 411 { | 411 { |
| 412 setupScrollAndContentsLayers(IntSize(100, 100)); | 412 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 413 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 413 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 414 initializeRendererAndDrawFrame(); | 414 initializeRendererAndDrawFrame(); |
| 415 CCLayerImpl* root = m_hostImpl->rootLayer(); | 415 LayerImpl* root = m_hostImpl->rootLayer(); |
| 416 | 416 |
| 417 root->setShouldScrollOnMainThread(true); | 417 root->setShouldScrollOnMainThread(true); |
| 418 | 418 |
| 419 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollOnMainThread); | 419 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollOnMainThread); |
| 420 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Gest
ure), CCInputHandlerClient::ScrollOnMainThread); | 420 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Gestur
e), InputHandlerClient::ScrollOnMainThread); |
| 421 } | 421 } |
| 422 | 422 |
| 423 TEST_P(CCLayerTreeHostImplTest, nonFastScrollableRegionBasic) | 423 TEST_P(LayerTreeHostImplTest, nonFastScrollableRegionBasic) |
| 424 { | 424 { |
| 425 setupScrollAndContentsLayers(IntSize(200, 200)); | 425 setupScrollAndContentsLayers(IntSize(200, 200)); |
| 426 m_hostImpl->setViewportSize(IntSize(100, 100), IntSize(100, 100)); | 426 m_hostImpl->setViewportSize(IntSize(100, 100), IntSize(100, 100)); |
| 427 initializeRendererAndDrawFrame(); | 427 initializeRendererAndDrawFrame(); |
| 428 CCLayerImpl* root = m_hostImpl->rootLayer(); | 428 LayerImpl* root = m_hostImpl->rootLayer(); |
| 429 | 429 |
| 430 root->setNonFastScrollableRegion(IntRect(0, 0, 50, 50)); | 430 root->setNonFastScrollableRegion(IntRect(0, 0, 50, 50)); |
| 431 | 431 |
| 432 // All scroll types inside the non-fast scrollable region should fail. | 432 // All scroll types inside the non-fast scrollable region should fail. |
| 433 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(25, 25), CCInputHandlerClient::Wh
eel), CCInputHandlerClient::ScrollOnMainThread); | 433 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(25, 25), InputHandlerClient::Whee
l), InputHandlerClient::ScrollOnMainThread); |
| 434 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(25, 25), CCInputHandlerClient::Ge
sture), CCInputHandlerClient::ScrollOnMainThread); | 434 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(25, 25), InputHandlerClient::Gest
ure), InputHandlerClient::ScrollOnMainThread); |
| 435 | 435 |
| 436 // All scroll types outside this region should succeed. | 436 // All scroll types outside this region should succeed. |
| 437 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(75, 75), CCInputHandlerClient::Wh
eel), CCInputHandlerClient::ScrollStarted); | 437 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(75, 75), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 438 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); | 438 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); |
| 439 m_hostImpl->scrollEnd(); | 439 m_hostImpl->scrollEnd(); |
| 440 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(75, 75), CCInputHandlerClient::Ge
sture), CCInputHandlerClient::ScrollStarted); | 440 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(75, 75), InputHandlerClient::Gest
ure), InputHandlerClient::ScrollStarted); |
| 441 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); | 441 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); |
| 442 m_hostImpl->scrollEnd(); | 442 m_hostImpl->scrollEnd(); |
| 443 } | 443 } |
| 444 | 444 |
| 445 TEST_P(CCLayerTreeHostImplTest, nonFastScrollableRegionWithOffset) | 445 TEST_P(LayerTreeHostImplTest, nonFastScrollableRegionWithOffset) |
| 446 { | 446 { |
| 447 setupScrollAndContentsLayers(IntSize(200, 200)); | 447 setupScrollAndContentsLayers(IntSize(200, 200)); |
| 448 m_hostImpl->setViewportSize(IntSize(100, 100), IntSize(100, 100)); | 448 m_hostImpl->setViewportSize(IntSize(100, 100), IntSize(100, 100)); |
| 449 CCLayerImpl* root = m_hostImpl->rootLayer(); | 449 LayerImpl* root = m_hostImpl->rootLayer(); |
| 450 | 450 |
| 451 root->setNonFastScrollableRegion(IntRect(0, 0, 50, 50)); | 451 root->setNonFastScrollableRegion(IntRect(0, 0, 50, 50)); |
| 452 root->setPosition(FloatPoint(-25, 0)); | 452 root->setPosition(FloatPoint(-25, 0)); |
| 453 initializeRendererAndDrawFrame(); | 453 initializeRendererAndDrawFrame(); |
| 454 | 454 |
| 455 // This point would fall into the non-fast scrollable region except that we'
ve moved the layer down by 25 pixels. | 455 // This point would fall into the non-fast scrollable region except that we'
ve moved the layer down by 25 pixels. |
| 456 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(40, 10), CCInputHandlerClient::Wh
eel), CCInputHandlerClient::ScrollStarted); | 456 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(40, 10), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 457 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 1)); | 457 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 1)); |
| 458 m_hostImpl->scrollEnd(); | 458 m_hostImpl->scrollEnd(); |
| 459 | 459 |
| 460 // This point is still inside the non-fast region. | 460 // This point is still inside the non-fast region. |
| 461 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(10, 10), CCInputHandlerClient::Wh
eel), CCInputHandlerClient::ScrollOnMainThread); | 461 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(10, 10), InputHandlerClient::Whee
l), InputHandlerClient::ScrollOnMainThread); |
| 462 } | 462 } |
| 463 | 463 |
| 464 TEST_P(CCLayerTreeHostImplTest, maxScrollPositionChangedByDeviceScaleFactor) | 464 TEST_P(LayerTreeHostImplTest, maxScrollPositionChangedByDeviceScaleFactor) |
| 465 { | 465 { |
| 466 setupScrollAndContentsLayers(IntSize(100, 100)); | 466 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 467 | 467 |
| 468 float deviceScaleFactor = 2; | 468 float deviceScaleFactor = 2; |
| 469 IntSize layoutViewport(25, 25); | 469 IntSize layoutViewport(25, 25); |
| 470 IntSize deviceViewport(layoutViewport); | 470 IntSize deviceViewport(layoutViewport); |
| 471 deviceViewport.scale(deviceScaleFactor); | 471 deviceViewport.scale(deviceScaleFactor); |
| 472 m_hostImpl->setViewportSize(layoutViewport, deviceViewport); | 472 m_hostImpl->setViewportSize(layoutViewport, deviceViewport); |
| 473 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | 473 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); |
| 474 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), IntSize(25, 25)); | 474 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), IntSize(25, 25)); |
| 475 | 475 |
| 476 deviceScaleFactor = 1; | 476 deviceScaleFactor = 1; |
| 477 m_hostImpl->setViewportSize(layoutViewport, layoutViewport); | 477 m_hostImpl->setViewportSize(layoutViewport, layoutViewport); |
| 478 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); | 478 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); |
| 479 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), IntSize(75, 75)); | 479 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), IntSize(75, 75)); |
| 480 } | 480 } |
| 481 | 481 |
| 482 TEST_P(CCLayerTreeHostImplTest, implPinchZoom) | 482 TEST_P(LayerTreeHostImplTest, implPinchZoom) |
| 483 { | 483 { |
| 484 // This test is specific to the page-scale based pinch zoom. | 484 // This test is specific to the page-scale based pinch zoom. |
| 485 if (!CCSettings::pageScalePinchZoomEnabled()) | 485 if (!Settings::pageScalePinchZoomEnabled()) |
| 486 return; | 486 return; |
| 487 | 487 |
| 488 setupScrollAndContentsLayers(IntSize(100, 100)); | 488 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 489 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 489 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 490 initializeRendererAndDrawFrame(); | 490 initializeRendererAndDrawFrame(); |
| 491 | 491 |
| 492 CCLayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 492 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 493 ASSERT(scrollLayer); | 493 ASSERT(scrollLayer); |
| 494 | 494 |
| 495 const float minPageScale = 1, maxPageScale = 4; | 495 const float minPageScale = 1, maxPageScale = 4; |
| 496 const WebTransformationMatrix identityScaleTransform; | 496 const WebTransformationMatrix identityScaleTransform; |
| 497 | 497 |
| 498 // The impl-based pinch zoome should not adjust the max scroll position. | 498 // The impl-based pinch zoome should not adjust the max scroll position. |
| 499 { | 499 { |
| 500 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 500 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 501 scrollLayer->setImplTransform(identityScaleTransform); | 501 scrollLayer->setImplTransform(identityScaleTransform); |
| 502 scrollLayer->setScrollDelta(IntSize()); | 502 scrollLayer->setScrollDelta(IntSize()); |
| 503 | 503 |
| 504 float pageScaleDelta = 2; | 504 float pageScaleDelta = 2; |
| 505 m_hostImpl->pinchGestureBegin(); | 505 m_hostImpl->pinchGestureBegin(); |
| 506 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(50, 50)); | 506 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(50, 50)); |
| 507 m_hostImpl->pinchGestureEnd(); | 507 m_hostImpl->pinchGestureEnd(); |
| 508 EXPECT_TRUE(m_didRequestRedraw); | 508 EXPECT_TRUE(m_didRequestRedraw); |
| 509 EXPECT_TRUE(m_didRequestCommit); | 509 EXPECT_TRUE(m_didRequestCommit); |
| 510 | 510 |
| 511 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 511 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 512 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 512 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 513 | 513 |
| 514 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), IntSize(50, 50))
; | 514 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), IntSize(50, 50))
; |
| 515 } | 515 } |
| 516 | 516 |
| 517 // Scrolling after a pinch gesture should always be in local space. The scr
oll deltas do not | 517 // Scrolling after a pinch gesture should always be in local space. The scr
oll deltas do not |
| 518 // have the page scale factor applied. | 518 // have the page scale factor applied. |
| 519 { | 519 { |
| 520 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 520 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 521 scrollLayer->setImplTransform(identityScaleTransform); | 521 scrollLayer->setImplTransform(identityScaleTransform); |
| 522 scrollLayer->setScrollDelta(IntSize()); | 522 scrollLayer->setScrollDelta(IntSize()); |
| 523 | 523 |
| 524 float pageScaleDelta = 2; | 524 float pageScaleDelta = 2; |
| 525 m_hostImpl->pinchGestureBegin(); | 525 m_hostImpl->pinchGestureBegin(); |
| 526 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(0, 0)); | 526 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(0, 0)); |
| 527 m_hostImpl->pinchGestureEnd(); | 527 m_hostImpl->pinchGestureEnd(); |
| 528 | 528 |
| 529 IntSize scrollDelta(0, 10); | 529 IntSize scrollDelta(0, 10); |
| 530 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::
Wheel), CCInputHandlerClient::ScrollStarted); | 530 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); |
| 531 m_hostImpl->scrollBy(IntPoint(), scrollDelta); | 531 m_hostImpl->scrollBy(IntPoint(), scrollDelta); |
| 532 m_hostImpl->scrollEnd(); | 532 m_hostImpl->scrollEnd(); |
| 533 | 533 |
| 534 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 534 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 535 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD
elta); | 535 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD
elta); |
| 536 } | 536 } |
| 537 } | 537 } |
| 538 | 538 |
| 539 TEST_P(CCLayerTreeHostImplTest, pinchGesture) | 539 TEST_P(LayerTreeHostImplTest, pinchGesture) |
| 540 { | 540 { |
| 541 setupScrollAndContentsLayers(IntSize(100, 100)); | 541 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 542 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 542 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 543 initializeRendererAndDrawFrame(); | 543 initializeRendererAndDrawFrame(); |
| 544 | 544 |
| 545 CCLayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 545 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 546 ASSERT(scrollLayer); | 546 ASSERT(scrollLayer); |
| 547 | 547 |
| 548 const float minPageScale = CCSettings::pageScalePinchZoomEnabled() ? 1 : 0.5
; | 548 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; |
| 549 const float maxPageScale = 4; | 549 const float maxPageScale = 4; |
| 550 const WebTransformationMatrix identityScaleTransform; | 550 const WebTransformationMatrix identityScaleTransform; |
| 551 | 551 |
| 552 // Basic pinch zoom in gesture | 552 // Basic pinch zoom in gesture |
| 553 { | 553 { |
| 554 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 554 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 555 scrollLayer->setImplTransform(identityScaleTransform); | 555 scrollLayer->setImplTransform(identityScaleTransform); |
| 556 scrollLayer->setScrollDelta(IntSize()); | 556 scrollLayer->setScrollDelta(IntSize()); |
| 557 | 557 |
| 558 float pageScaleDelta = 2; | 558 float pageScaleDelta = 2; |
| 559 m_hostImpl->pinchGestureBegin(); | 559 m_hostImpl->pinchGestureBegin(); |
| 560 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(50, 50)); | 560 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(50, 50)); |
| 561 m_hostImpl->pinchGestureEnd(); | 561 m_hostImpl->pinchGestureEnd(); |
| 562 EXPECT_TRUE(m_didRequestRedraw); | 562 EXPECT_TRUE(m_didRequestRedraw); |
| 563 EXPECT_TRUE(m_didRequestCommit); | 563 EXPECT_TRUE(m_didRequestCommit); |
| 564 | 564 |
| 565 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 565 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 566 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 566 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 567 } | 567 } |
| 568 | 568 |
| 569 // Zoom-in clamping | 569 // Zoom-in clamping |
| 570 { | 570 { |
| 571 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 571 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 572 scrollLayer->setImplTransform(identityScaleTransform); | 572 scrollLayer->setImplTransform(identityScaleTransform); |
| 573 scrollLayer->setScrollDelta(IntSize()); | 573 scrollLayer->setScrollDelta(IntSize()); |
| 574 float pageScaleDelta = 10; | 574 float pageScaleDelta = 10; |
| 575 | 575 |
| 576 m_hostImpl->pinchGestureBegin(); | 576 m_hostImpl->pinchGestureBegin(); |
| 577 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(50, 50)); | 577 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(50, 50)); |
| 578 m_hostImpl->pinchGestureEnd(); | 578 m_hostImpl->pinchGestureEnd(); |
| 579 | 579 |
| 580 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 580 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 581 EXPECT_EQ(scrollInfo->pageScaleDelta, maxPageScale); | 581 EXPECT_EQ(scrollInfo->pageScaleDelta, maxPageScale); |
| 582 } | 582 } |
| 583 | 583 |
| 584 // Zoom-out clamping | 584 // Zoom-out clamping |
| 585 { | 585 { |
| 586 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 586 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 587 scrollLayer->setImplTransform(identityScaleTransform); | 587 scrollLayer->setImplTransform(identityScaleTransform); |
| 588 scrollLayer->setScrollDelta(IntSize()); | 588 scrollLayer->setScrollDelta(IntSize()); |
| 589 scrollLayer->setScrollPosition(IntPoint(50, 50)); | 589 scrollLayer->setScrollPosition(IntPoint(50, 50)); |
| 590 | 590 |
| 591 float pageScaleDelta = 0.1f; | 591 float pageScaleDelta = 0.1f; |
| 592 m_hostImpl->pinchGestureBegin(); | 592 m_hostImpl->pinchGestureBegin(); |
| 593 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(0, 0)); | 593 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(0, 0)); |
| 594 m_hostImpl->pinchGestureEnd(); | 594 m_hostImpl->pinchGestureEnd(); |
| 595 | 595 |
| 596 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 596 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 597 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | 597 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 598 | 598 |
| 599 if (!CCSettings::pageScalePinchZoomEnabled()) { | 599 if (!Settings::pageScalePinchZoomEnabled()) { |
| 600 // Pushed to (0,0) via clamping against contents layer size. | 600 // Pushed to (0,0) via clamping against contents layer size. |
| 601 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-50, -50)); | 601 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-50, -50)); |
| 602 } else { | 602 } else { |
| 603 EXPECT_TRUE(scrollInfo->scrolls.isEmpty()); | 603 EXPECT_TRUE(scrollInfo->scrolls.isEmpty()); |
| 604 } | 604 } |
| 605 } | 605 } |
| 606 | 606 |
| 607 // Two-finger panning | 607 // Two-finger panning |
| 608 { | 608 { |
| 609 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 609 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 610 scrollLayer->setImplTransform(identityScaleTransform); | 610 scrollLayer->setImplTransform(identityScaleTransform); |
| 611 scrollLayer->setScrollDelta(IntSize()); | 611 scrollLayer->setScrollDelta(IntSize()); |
| 612 scrollLayer->setScrollPosition(IntPoint(20, 20)); | 612 scrollLayer->setScrollPosition(IntPoint(20, 20)); |
| 613 | 613 |
| 614 float pageScaleDelta = 1; | 614 float pageScaleDelta = 1; |
| 615 m_hostImpl->pinchGestureBegin(); | 615 m_hostImpl->pinchGestureBegin(); |
| 616 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(10, 10)); | 616 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(10, 10)); |
| 617 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(20, 20)); | 617 m_hostImpl->pinchGestureUpdate(pageScaleDelta, IntPoint(20, 20)); |
| 618 m_hostImpl->pinchGestureEnd(); | 618 m_hostImpl->pinchGestureEnd(); |
| 619 | 619 |
| 620 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 620 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 621 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 621 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 622 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-10, -10)); | 622 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-10, -10)); |
| 623 } | 623 } |
| 624 } | 624 } |
| 625 | 625 |
| 626 TEST_P(CCLayerTreeHostImplTest, pageScaleAnimation) | 626 TEST_P(LayerTreeHostImplTest, pageScaleAnimation) |
| 627 { | 627 { |
| 628 setupScrollAndContentsLayers(IntSize(100, 100)); | 628 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 629 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 629 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 630 initializeRendererAndDrawFrame(); | 630 initializeRendererAndDrawFrame(); |
| 631 | 631 |
| 632 CCLayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 632 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 633 ASSERT(scrollLayer); | 633 ASSERT(scrollLayer); |
| 634 | 634 |
| 635 const float minPageScale = CCSettings::pageScalePinchZoomEnabled() ? 1 : 0.5
; | 635 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; |
| 636 const float maxPageScale = 4; | 636 const float maxPageScale = 4; |
| 637 const double startTime = 1; | 637 const double startTime = 1; |
| 638 const double duration = 0.1; | 638 const double duration = 0.1; |
| 639 const double halfwayThroughAnimation = startTime + duration / 2; | 639 const double halfwayThroughAnimation = startTime + duration / 2; |
| 640 const double endTime = startTime + duration; | 640 const double endTime = startTime + duration; |
| 641 const WebTransformationMatrix identityScaleTransform; | 641 const WebTransformationMatrix identityScaleTransform; |
| 642 | 642 |
| 643 // Non-anchor zoom-in | 643 // Non-anchor zoom-in |
| 644 { | 644 { |
| 645 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 645 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 646 scrollLayer->setImplTransform(identityScaleTransform); | 646 scrollLayer->setImplTransform(identityScaleTransform); |
| 647 scrollLayer->setScrollPosition(IntPoint(50, 50)); | 647 scrollLayer->setScrollPosition(IntPoint(50, 50)); |
| 648 | 648 |
| 649 m_hostImpl->startPageScaleAnimation(IntSize(0, 0), false, 2, startTime,
duration); | 649 m_hostImpl->startPageScaleAnimation(IntSize(0, 0), false, 2, startTime,
duration); |
| 650 m_hostImpl->animate(halfwayThroughAnimation, halfwayThroughAnimation); | 650 m_hostImpl->animate(halfwayThroughAnimation, halfwayThroughAnimation); |
| 651 EXPECT_TRUE(m_didRequestRedraw); | 651 EXPECT_TRUE(m_didRequestRedraw); |
| 652 m_hostImpl->animate(endTime, endTime); | 652 m_hostImpl->animate(endTime, endTime); |
| 653 EXPECT_TRUE(m_didRequestCommit); | 653 EXPECT_TRUE(m_didRequestCommit); |
| 654 | 654 |
| 655 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 655 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 656 EXPECT_EQ(scrollInfo->pageScaleDelta, 2); | 656 EXPECT_EQ(scrollInfo->pageScaleDelta, 2); |
| 657 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-50, -50)); | 657 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-50, -50)); |
| 658 } | 658 } |
| 659 | 659 |
| 660 // Anchor zoom-out | 660 // Anchor zoom-out |
| 661 { | 661 { |
| 662 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 662 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 663 scrollLayer->setImplTransform(identityScaleTransform); | 663 scrollLayer->setImplTransform(identityScaleTransform); |
| 664 scrollLayer->setScrollPosition(IntPoint(50, 50)); | 664 scrollLayer->setScrollPosition(IntPoint(50, 50)); |
| 665 | 665 |
| 666 m_hostImpl->startPageScaleAnimation(IntSize(25, 25), true, minPageScale,
startTime, duration); | 666 m_hostImpl->startPageScaleAnimation(IntSize(25, 25), true, minPageScale,
startTime, duration); |
| 667 m_hostImpl->animate(endTime, endTime); | 667 m_hostImpl->animate(endTime, endTime); |
| 668 EXPECT_TRUE(m_didRequestRedraw); | 668 EXPECT_TRUE(m_didRequestRedraw); |
| 669 EXPECT_TRUE(m_didRequestCommit); | 669 EXPECT_TRUE(m_didRequestCommit); |
| 670 | 670 |
| 671 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 671 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 672 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | 672 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 673 // Pushed to (0,0) via clamping against contents layer size. | 673 // Pushed to (0,0) via clamping against contents layer size. |
| 674 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-50, -50)); | 674 expectContains(*scrollInfo, scrollLayer->id(), IntSize(-50, -50)); |
| 675 } | 675 } |
| 676 } | 676 } |
| 677 | 677 |
| 678 TEST_P(CCLayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhilePinchZoomin
g) | 678 TEST_P(LayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhilePinchZooming) |
| 679 { | 679 { |
| 680 setupScrollAndContentsLayers(IntSize(100, 100)); | 680 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 681 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 681 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 682 initializeRendererAndDrawFrame(); | 682 initializeRendererAndDrawFrame(); |
| 683 | 683 |
| 684 CCLayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 684 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 685 ASSERT(scrollLayer); | 685 ASSERT(scrollLayer); |
| 686 | 686 |
| 687 const float minPageScale = CCSettings::pageScalePinchZoomEnabled() ? 1 : 0.5
; | 687 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; |
| 688 const float maxPageScale = 4; | 688 const float maxPageScale = 4; |
| 689 | 689 |
| 690 // Pinch zoom in. | 690 // Pinch zoom in. |
| 691 { | 691 { |
| 692 // Start a pinch in gesture at the bottom right corner of the viewport. | 692 // Start a pinch in gesture at the bottom right corner of the viewport. |
| 693 const float zoomInDelta = 2; | 693 const float zoomInDelta = 2; |
| 694 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 694 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 695 m_hostImpl->pinchGestureBegin(); | 695 m_hostImpl->pinchGestureBegin(); |
| 696 m_hostImpl->pinchGestureUpdate(zoomInDelta, IntPoint(50, 50)); | 696 m_hostImpl->pinchGestureUpdate(zoomInDelta, IntPoint(50, 50)); |
| 697 | 697 |
| 698 // Because we are pinch zooming in, we shouldn't get any scroll or page | 698 // Because we are pinch zooming in, we shouldn't get any scroll or page |
| 699 // scale deltas. | 699 // scale deltas. |
| 700 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 700 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 701 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); | 701 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); |
| 702 EXPECT_EQ(scrollInfo->scrolls.size(), 0u); | 702 EXPECT_EQ(scrollInfo->scrolls.size(), 0u); |
| 703 | 703 |
| 704 // Once the gesture ends, we get the final scroll and page scale values. | 704 // Once the gesture ends, we get the final scroll and page scale values. |
| 705 m_hostImpl->pinchGestureEnd(); | 705 m_hostImpl->pinchGestureEnd(); |
| 706 scrollInfo = m_hostImpl->processScrollDeltas(); | 706 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 707 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomInDelta); | 707 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomInDelta); |
| 708 if (!CCSettings::pageScalePinchZoomEnabled()) { | 708 if (!Settings::pageScalePinchZoomEnabled()) { |
| 709 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); | 709 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); |
| 710 } else { | 710 } else { |
| 711 EXPECT_TRUE(scrollInfo->scrolls.isEmpty()); | 711 EXPECT_TRUE(scrollInfo->scrolls.isEmpty()); |
| 712 } | 712 } |
| 713 } | 713 } |
| 714 | 714 |
| 715 // Pinch zoom out. | 715 // Pinch zoom out. |
| 716 { | 716 { |
| 717 // Start a pinch out gesture at the bottom right corner of the viewport. | 717 // Start a pinch out gesture at the bottom right corner of the viewport. |
| 718 const float zoomOutDelta = 0.75; | 718 const float zoomOutDelta = 0.75; |
| 719 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 719 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 720 m_hostImpl->pinchGestureBegin(); | 720 m_hostImpl->pinchGestureBegin(); |
| 721 m_hostImpl->pinchGestureUpdate(zoomOutDelta, IntPoint(50, 50)); | 721 m_hostImpl->pinchGestureUpdate(zoomOutDelta, IntPoint(50, 50)); |
| 722 | 722 |
| 723 // Since we are pinch zooming out, we should get an update to zoom all | 723 // Since we are pinch zooming out, we should get an update to zoom all |
| 724 // the way out to the minimum page scale. | 724 // the way out to the minimum page scale. |
| 725 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 725 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 726 if (!CCSettings::pageScalePinchZoomEnabled()) { | 726 if (!Settings::pageScalePinchZoomEnabled()) { |
| 727 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | 727 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 728 expectContains(*scrollInfo, scrollLayer->id(), IntSize(0, 0)); | 728 expectContains(*scrollInfo, scrollLayer->id(), IntSize(0, 0)); |
| 729 } else { | 729 } else { |
| 730 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); | 730 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); |
| 731 EXPECT_TRUE(scrollInfo->scrolls.isEmpty()); | 731 EXPECT_TRUE(scrollInfo->scrolls.isEmpty()); |
| 732 } | 732 } |
| 733 | 733 |
| 734 // Once the gesture ends, we get the final scroll and page scale values. | 734 // Once the gesture ends, we get the final scroll and page scale values. |
| 735 m_hostImpl->pinchGestureEnd(); | 735 m_hostImpl->pinchGestureEnd(); |
| 736 scrollInfo = m_hostImpl->processScrollDeltas(); | 736 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 737 if (CCSettings::pageScalePinchZoomEnabled()) { | 737 if (Settings::pageScalePinchZoomEnabled()) { |
| 738 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); | 738 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 739 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); | 739 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); |
| 740 } else { | 740 } else { |
| 741 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomOutDelta); | 741 EXPECT_EQ(scrollInfo->pageScaleDelta, zoomOutDelta); |
| 742 expectContains(*scrollInfo, scrollLayer->id(), IntSize(8, 8)); | 742 expectContains(*scrollInfo, scrollLayer->id(), IntSize(8, 8)); |
| 743 } | 743 } |
| 744 } | 744 } |
| 745 } | 745 } |
| 746 | 746 |
| 747 TEST_P(CCLayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhileAnimatingPa
geScale) | 747 TEST_P(LayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhileAnimatingPage
Scale) |
| 748 { | 748 { |
| 749 setupScrollAndContentsLayers(IntSize(100, 100)); | 749 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 750 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); | 750 m_hostImpl->setViewportSize(IntSize(50, 50), IntSize(50, 50)); |
| 751 initializeRendererAndDrawFrame(); | 751 initializeRendererAndDrawFrame(); |
| 752 | 752 |
| 753 CCLayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); | 753 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); |
| 754 ASSERT(scrollLayer); | 754 ASSERT(scrollLayer); |
| 755 | 755 |
| 756 const float minPageScale = CCSettings::pageScalePinchZoomEnabled() ? 1 : 0.5
; | 756 const float minPageScale = Settings::pageScalePinchZoomEnabled() ? 1 : 0.5; |
| 757 const float maxPageScale = 4; | 757 const float maxPageScale = 4; |
| 758 const double startTime = 1; | 758 const double startTime = 1; |
| 759 const double duration = 0.1; | 759 const double duration = 0.1; |
| 760 const double halfwayThroughAnimation = startTime + duration / 2; | 760 const double halfwayThroughAnimation = startTime + duration / 2; |
| 761 const double endTime = startTime + duration; | 761 const double endTime = startTime + duration; |
| 762 | 762 |
| 763 // Start a page scale animation. | 763 // Start a page scale animation. |
| 764 const float pageScaleDelta = 2; | 764 const float pageScaleDelta = 2; |
| 765 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); | 765 m_hostImpl->setPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 766 m_hostImpl->startPageScaleAnimation(IntSize(50, 50), false, pageScaleDelta,
startTime, duration); | 766 m_hostImpl->startPageScaleAnimation(IntSize(50, 50), false, pageScaleDelta,
startTime, duration); |
| 767 | 767 |
| 768 // We should immediately get the final zoom and scroll values for the | 768 // We should immediately get the final zoom and scroll values for the |
| 769 // animation. | 769 // animation. |
| 770 m_hostImpl->animate(halfwayThroughAnimation, halfwayThroughAnimation); | 770 m_hostImpl->animate(halfwayThroughAnimation, halfwayThroughAnimation); |
| 771 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas
(); | 771 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 772 | 772 |
| 773 if (!CCSettings::pageScalePinchZoomEnabled()) { | 773 if (!Settings::pageScalePinchZoomEnabled()) { |
| 774 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 774 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 775 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); | 775 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); |
| 776 } else { | 776 } else { |
| 777 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); | 777 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); |
| 778 EXPECT_TRUE(scrollInfo->scrolls.isEmpty()); | 778 EXPECT_TRUE(scrollInfo->scrolls.isEmpty()); |
| 779 } | 779 } |
| 780 | 780 |
| 781 // Scrolling during the animation is ignored. | 781 // Scrolling during the animation is ignored. |
| 782 const IntSize scrollDelta(0, 10); | 782 const IntSize scrollDelta(0, 10); |
| 783 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(25, 25), CCInputHandlerClient::Wh
eel), CCInputHandlerClient::ScrollStarted); | 783 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(25, 25), InputHandlerClient::Whee
l), InputHandlerClient::ScrollStarted); |
| 784 m_hostImpl->scrollBy(IntPoint(), scrollDelta); | 784 m_hostImpl->scrollBy(IntPoint(), scrollDelta); |
| 785 m_hostImpl->scrollEnd(); | 785 m_hostImpl->scrollEnd(); |
| 786 | 786 |
| 787 // The final page scale and scroll deltas should match what we got | 787 // The final page scale and scroll deltas should match what we got |
| 788 // earlier. | 788 // earlier. |
| 789 m_hostImpl->animate(endTime, endTime); | 789 m_hostImpl->animate(endTime, endTime); |
| 790 scrollInfo = m_hostImpl->processScrollDeltas(); | 790 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 791 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); | 791 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 792 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); | 792 expectContains(*scrollInfo, scrollLayer->id(), IntSize(25, 25)); |
| 793 } | 793 } |
| 794 | 794 |
| 795 class DidDrawCheckLayer : public CCTiledLayerImpl { | 795 class DidDrawCheckLayer : public TiledLayerImpl { |
| 796 public: | 796 public: |
| 797 static scoped_ptr<CCLayerImpl> create(int id) { return scoped_ptr<CCLayerImp
l>(new DidDrawCheckLayer(id)); } | 797 static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(n
ew DidDrawCheckLayer(id)); } |
| 798 | 798 |
| 799 virtual void didDraw(CCResourceProvider*) OVERRIDE | 799 virtual void didDraw(ResourceProvider*) OVERRIDE |
| 800 { | 800 { |
| 801 m_didDrawCalled = true; | 801 m_didDrawCalled = true; |
| 802 } | 802 } |
| 803 | 803 |
| 804 virtual void willDraw(CCResourceProvider*) OVERRIDE | 804 virtual void willDraw(ResourceProvider*) OVERRIDE |
| 805 { | 805 { |
| 806 m_willDrawCalled = true; | 806 m_willDrawCalled = true; |
| 807 } | 807 } |
| 808 | 808 |
| 809 bool didDrawCalled() const { return m_didDrawCalled; } | 809 bool didDrawCalled() const { return m_didDrawCalled; } |
| 810 bool willDrawCalled() const { return m_willDrawCalled; } | 810 bool willDrawCalled() const { return m_willDrawCalled; } |
| 811 | 811 |
| 812 void clearDidDrawCheck() | 812 void clearDidDrawCheck() |
| 813 { | 813 { |
| 814 m_didDrawCalled = false; | 814 m_didDrawCalled = false; |
| 815 m_willDrawCalled = false; | 815 m_willDrawCalled = false; |
| 816 } | 816 } |
| 817 | 817 |
| 818 protected: | 818 protected: |
| 819 explicit DidDrawCheckLayer(int id) | 819 explicit DidDrawCheckLayer(int id) |
| 820 : CCTiledLayerImpl(id) | 820 : TiledLayerImpl(id) |
| 821 , m_didDrawCalled(false) | 821 , m_didDrawCalled(false) |
| 822 , m_willDrawCalled(false) | 822 , m_willDrawCalled(false) |
| 823 { | 823 { |
| 824 setAnchorPoint(FloatPoint(0, 0)); | 824 setAnchorPoint(FloatPoint(0, 0)); |
| 825 setBounds(IntSize(10, 10)); | 825 setBounds(IntSize(10, 10)); |
| 826 setContentBounds(IntSize(10, 10)); | 826 setContentBounds(IntSize(10, 10)); |
| 827 setDrawsContent(true); | 827 setDrawsContent(true); |
| 828 setSkipsDraw(false); | 828 setSkipsDraw(false); |
| 829 setVisibleContentRect(IntRect(0, 0, 10, 10)); | 829 setVisibleContentRect(IntRect(0, 0, 10, 10)); |
| 830 | 830 |
| 831 scoped_ptr<CCLayerTilingData> tiler = CCLayerTilingData::create(IntSize(
100, 100), CCLayerTilingData::HasBorderTexels); | 831 scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(IntSize(100,
100), LayerTilingData::HasBorderTexels); |
| 832 tiler->setBounds(contentBounds()); | 832 tiler->setBounds(contentBounds()); |
| 833 setTilingData(*tiler.get()); | 833 setTilingData(*tiler.get()); |
| 834 } | 834 } |
| 835 | 835 |
| 836 private: | 836 private: |
| 837 bool m_didDrawCalled; | 837 bool m_didDrawCalled; |
| 838 bool m_willDrawCalled; | 838 bool m_willDrawCalled; |
| 839 }; | 839 }; |
| 840 | 840 |
| 841 TEST_P(CCLayerTreeHostImplTest, didDrawNotCalledOnHiddenLayer) | 841 TEST_P(LayerTreeHostImplTest, didDrawNotCalledOnHiddenLayer) |
| 842 { | 842 { |
| 843 // The root layer is always drawn, so run this test on a child layer that | 843 // The root layer is always drawn, so run this test on a child layer that |
| 844 // will be masked out by the root layer's bounds. | 844 // will be masked out by the root layer's bounds. |
| 845 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); | 845 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); |
| 846 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa
yer()); | 846 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa
yer()); |
| 847 root->setMasksToBounds(true); | 847 root->setMasksToBounds(true); |
| 848 | 848 |
| 849 root->addChild(DidDrawCheckLayer::create(2)); | 849 root->addChild(DidDrawCheckLayer::create(2)); |
| 850 DidDrawCheckLayer* layer = static_cast<DidDrawCheckLayer*>(root->children()[
0]); | 850 DidDrawCheckLayer* layer = static_cast<DidDrawCheckLayer*>(root->children()[
0]); |
| 851 // Ensure visibleContentRect for layer is empty | 851 // Ensure visibleContentRect for layer is empty |
| 852 layer->setPosition(FloatPoint(100, 100)); | 852 layer->setPosition(FloatPoint(100, 100)); |
| 853 layer->setBounds(IntSize(10, 10)); | 853 layer->setBounds(IntSize(10, 10)); |
| 854 layer->setContentBounds(IntSize(10, 10)); | 854 layer->setContentBounds(IntSize(10, 10)); |
| 855 | 855 |
| 856 CCLayerTreeHostImpl::FrameData frame; | 856 LayerTreeHostImpl::FrameData frame; |
| 857 | 857 |
| 858 EXPECT_FALSE(layer->willDrawCalled()); | 858 EXPECT_FALSE(layer->willDrawCalled()); |
| 859 EXPECT_FALSE(layer->didDrawCalled()); | 859 EXPECT_FALSE(layer->didDrawCalled()); |
| 860 | 860 |
| 861 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 861 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 862 m_hostImpl->drawLayers(frame); | 862 m_hostImpl->drawLayers(frame); |
| 863 m_hostImpl->didDrawAllLayers(frame); | 863 m_hostImpl->didDrawAllLayers(frame); |
| 864 | 864 |
| 865 EXPECT_FALSE(layer->willDrawCalled()); | 865 EXPECT_FALSE(layer->willDrawCalled()); |
| 866 EXPECT_FALSE(layer->didDrawCalled()); | 866 EXPECT_FALSE(layer->didDrawCalled()); |
| 867 | 867 |
| 868 EXPECT_TRUE(layer->visibleContentRect().isEmpty()); | 868 EXPECT_TRUE(layer->visibleContentRect().isEmpty()); |
| 869 | 869 |
| 870 // Ensure visibleContentRect for layer layer is not empty | 870 // Ensure visibleContentRect for layer layer is not empty |
| 871 layer->setPosition(FloatPoint(0, 0)); | 871 layer->setPosition(FloatPoint(0, 0)); |
| 872 | 872 |
| 873 EXPECT_FALSE(layer->willDrawCalled()); | 873 EXPECT_FALSE(layer->willDrawCalled()); |
| 874 EXPECT_FALSE(layer->didDrawCalled()); | 874 EXPECT_FALSE(layer->didDrawCalled()); |
| 875 | 875 |
| 876 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 876 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 877 m_hostImpl->drawLayers(frame); | 877 m_hostImpl->drawLayers(frame); |
| 878 m_hostImpl->didDrawAllLayers(frame); | 878 m_hostImpl->didDrawAllLayers(frame); |
| 879 | 879 |
| 880 EXPECT_TRUE(layer->willDrawCalled()); | 880 EXPECT_TRUE(layer->willDrawCalled()); |
| 881 EXPECT_TRUE(layer->didDrawCalled()); | 881 EXPECT_TRUE(layer->didDrawCalled()); |
| 882 | 882 |
| 883 EXPECT_FALSE(layer->visibleContentRect().isEmpty()); | 883 EXPECT_FALSE(layer->visibleContentRect().isEmpty()); |
| 884 } | 884 } |
| 885 | 885 |
| 886 TEST_P(CCLayerTreeHostImplTest, willDrawNotCalledOnOccludedLayer) | 886 TEST_P(LayerTreeHostImplTest, willDrawNotCalledOnOccludedLayer) |
| 887 { | 887 { |
| 888 IntSize bigSize(1000, 1000); | 888 IntSize bigSize(1000, 1000); |
| 889 m_hostImpl->setViewportSize(bigSize, bigSize); | 889 m_hostImpl->setViewportSize(bigSize, bigSize); |
| 890 | 890 |
| 891 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); | 891 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); |
| 892 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa
yer()); | 892 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa
yer()); |
| 893 | 893 |
| 894 root->addChild(DidDrawCheckLayer::create(2)); | 894 root->addChild(DidDrawCheckLayer::create(2)); |
| 895 DidDrawCheckLayer* occludedLayer = static_cast<DidDrawCheckLayer*>(root->chi
ldren()[0]); | 895 DidDrawCheckLayer* occludedLayer = static_cast<DidDrawCheckLayer*>(root->chi
ldren()[0]); |
| 896 | 896 |
| 897 root->addChild(DidDrawCheckLayer::create(3)); | 897 root->addChild(DidDrawCheckLayer::create(3)); |
| 898 DidDrawCheckLayer* topLayer = static_cast<DidDrawCheckLayer*>(root->children
()[1]); | 898 DidDrawCheckLayer* topLayer = static_cast<DidDrawCheckLayer*>(root->children
()[1]); |
| 899 // This layer covers the occludedLayer above. Make this layer large so it ca
n occlude. | 899 // This layer covers the occludedLayer above. Make this layer large so it ca
n occlude. |
| 900 topLayer->setBounds(bigSize); | 900 topLayer->setBounds(bigSize); |
| 901 topLayer->setContentBounds(bigSize); | 901 topLayer->setContentBounds(bigSize); |
| 902 topLayer->setContentsOpaque(true); | 902 topLayer->setContentsOpaque(true); |
| 903 | 903 |
| 904 CCLayerTreeHostImpl::FrameData frame; | 904 LayerTreeHostImpl::FrameData frame; |
| 905 | 905 |
| 906 EXPECT_FALSE(occludedLayer->willDrawCalled()); | 906 EXPECT_FALSE(occludedLayer->willDrawCalled()); |
| 907 EXPECT_FALSE(occludedLayer->didDrawCalled()); | 907 EXPECT_FALSE(occludedLayer->didDrawCalled()); |
| 908 EXPECT_FALSE(topLayer->willDrawCalled()); | 908 EXPECT_FALSE(topLayer->willDrawCalled()); |
| 909 EXPECT_FALSE(topLayer->didDrawCalled()); | 909 EXPECT_FALSE(topLayer->didDrawCalled()); |
| 910 | 910 |
| 911 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 911 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 912 m_hostImpl->drawLayers(frame); | 912 m_hostImpl->drawLayers(frame); |
| 913 m_hostImpl->didDrawAllLayers(frame); | 913 m_hostImpl->didDrawAllLayers(frame); |
| 914 | 914 |
| 915 EXPECT_FALSE(occludedLayer->willDrawCalled()); | 915 EXPECT_FALSE(occludedLayer->willDrawCalled()); |
| 916 EXPECT_FALSE(occludedLayer->didDrawCalled()); | 916 EXPECT_FALSE(occludedLayer->didDrawCalled()); |
| 917 EXPECT_TRUE(topLayer->willDrawCalled()); | 917 EXPECT_TRUE(topLayer->willDrawCalled()); |
| 918 EXPECT_TRUE(topLayer->didDrawCalled()); | 918 EXPECT_TRUE(topLayer->didDrawCalled()); |
| 919 } | 919 } |
| 920 | 920 |
| 921 TEST_P(CCLayerTreeHostImplTest, didDrawCalledOnAllLayers) | 921 TEST_P(LayerTreeHostImplTest, didDrawCalledOnAllLayers) |
| 922 { | 922 { |
| 923 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); | 923 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); |
| 924 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa
yer()); | 924 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa
yer()); |
| 925 | 925 |
| 926 root->addChild(DidDrawCheckLayer::create(2)); | 926 root->addChild(DidDrawCheckLayer::create(2)); |
| 927 DidDrawCheckLayer* layer1 = static_cast<DidDrawCheckLayer*>(root->children()
[0]); | 927 DidDrawCheckLayer* layer1 = static_cast<DidDrawCheckLayer*>(root->children()
[0]); |
| 928 | 928 |
| 929 layer1->addChild(DidDrawCheckLayer::create(3)); | 929 layer1->addChild(DidDrawCheckLayer::create(3)); |
| 930 DidDrawCheckLayer* layer2 = static_cast<DidDrawCheckLayer*>(layer1->children
()[0]); | 930 DidDrawCheckLayer* layer2 = static_cast<DidDrawCheckLayer*>(layer1->children
()[0]); |
| 931 | 931 |
| 932 layer1->setOpacity(0.3f); | 932 layer1->setOpacity(0.3f); |
| 933 layer1->setPreserves3D(false); | 933 layer1->setPreserves3D(false); |
| 934 | 934 |
| 935 EXPECT_FALSE(root->didDrawCalled()); | 935 EXPECT_FALSE(root->didDrawCalled()); |
| 936 EXPECT_FALSE(layer1->didDrawCalled()); | 936 EXPECT_FALSE(layer1->didDrawCalled()); |
| 937 EXPECT_FALSE(layer2->didDrawCalled()); | 937 EXPECT_FALSE(layer2->didDrawCalled()); |
| 938 | 938 |
| 939 CCLayerTreeHostImpl::FrameData frame; | 939 LayerTreeHostImpl::FrameData frame; |
| 940 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 940 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 941 m_hostImpl->drawLayers(frame); | 941 m_hostImpl->drawLayers(frame); |
| 942 m_hostImpl->didDrawAllLayers(frame); | 942 m_hostImpl->didDrawAllLayers(frame); |
| 943 | 943 |
| 944 EXPECT_TRUE(root->didDrawCalled()); | 944 EXPECT_TRUE(root->didDrawCalled()); |
| 945 EXPECT_TRUE(layer1->didDrawCalled()); | 945 EXPECT_TRUE(layer1->didDrawCalled()); |
| 946 EXPECT_TRUE(layer2->didDrawCalled()); | 946 EXPECT_TRUE(layer2->didDrawCalled()); |
| 947 | 947 |
| 948 EXPECT_NE(root->renderSurface(), layer1->renderSurface()); | 948 EXPECT_NE(root->renderSurface(), layer1->renderSurface()); |
| 949 EXPECT_TRUE(!!layer1->renderSurface()); | 949 EXPECT_TRUE(!!layer1->renderSurface()); |
| 950 } | 950 } |
| 951 | 951 |
| 952 class MissingTextureAnimatingLayer : public DidDrawCheckLayer { | 952 class MissingTextureAnimatingLayer : public DidDrawCheckLayer { |
| 953 public: | 953 public: |
| 954 static scoped_ptr<CCLayerImpl> create(int id, bool tileMissing, bool skipsDr
aw, bool animating, CCResourceProvider* resourceProvider) | 954 static scoped_ptr<LayerImpl> create(int id, bool tileMissing, bool skipsDraw
, bool animating, ResourceProvider* resourceProvider) |
| 955 { | 955 { |
| 956 return scoped_ptr<CCLayerImpl>(new MissingTextureAnimatingLayer(id, tile
Missing, skipsDraw, animating, resourceProvider)); | 956 return scoped_ptr<LayerImpl>(new MissingTextureAnimatingLayer(id, tileMi
ssing, skipsDraw, animating, resourceProvider)); |
| 957 } | 957 } |
| 958 | 958 |
| 959 private: | 959 private: |
| 960 explicit MissingTextureAnimatingLayer(int id, bool tileMissing, bool skipsDr
aw, bool animating, CCResourceProvider* resourceProvider) | 960 explicit MissingTextureAnimatingLayer(int id, bool tileMissing, bool skipsDr
aw, bool animating, ResourceProvider* resourceProvider) |
| 961 : DidDrawCheckLayer(id) | 961 : DidDrawCheckLayer(id) |
| 962 { | 962 { |
| 963 scoped_ptr<CCLayerTilingData> tilingData = CCLayerTilingData::create(Int
Size(10, 10), CCLayerTilingData::NoBorderTexels); | 963 scoped_ptr<LayerTilingData> tilingData = LayerTilingData::create(IntSize
(10, 10), LayerTilingData::NoBorderTexels); |
| 964 tilingData->setBounds(bounds()); | 964 tilingData->setBounds(bounds()); |
| 965 setTilingData(*tilingData.get()); | 965 setTilingData(*tilingData.get()); |
| 966 setSkipsDraw(skipsDraw); | 966 setSkipsDraw(skipsDraw); |
| 967 if (!tileMissing) { | 967 if (!tileMissing) { |
| 968 CCResourceProvider::ResourceId resource = resourceProvider->createRe
source(CCRenderer::ContentPool, IntSize(), GraphicsContext3D::RGBA, CCResourcePr
ovider::TextureUsageAny); | 968 ResourceProvider::ResourceId resource = resourceProvider->createReso
urce(Renderer::ContentPool, IntSize(), GraphicsContext3D::RGBA, ResourceProvider
::TextureUsageAny); |
| 969 pushTileProperties(0, 0, resource, IntRect()); | 969 pushTileProperties(0, 0, resource, IntRect()); |
| 970 } | 970 } |
| 971 if (animating) | 971 if (animating) |
| 972 addAnimatedTransformToLayer(*this, 10, 3, 0); | 972 addAnimatedTransformToLayer(*this, 10, 3, 0); |
| 973 } | 973 } |
| 974 }; | 974 }; |
| 975 | 975 |
| 976 TEST_P(CCLayerTreeHostImplTest, prepareToDrawFailsWhenAnimationUsesCheckerboard) | 976 TEST_P(LayerTreeHostImplTest, prepareToDrawFailsWhenAnimationUsesCheckerboard) |
| 977 { | 977 { |
| 978 // When the texture is not missing, we draw as usual. | 978 // When the texture is not missing, we draw as usual. |
| 979 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); | 979 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); |
| 980 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa
yer()); | 980 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa
yer()); |
| 981 root->addChild(MissingTextureAnimatingLayer::create(2, false, false, true, m
_hostImpl->resourceProvider())); | 981 root->addChild(MissingTextureAnimatingLayer::create(2, false, false, true, m
_hostImpl->resourceProvider())); |
| 982 | 982 |
| 983 CCLayerTreeHostImpl::FrameData frame; | 983 LayerTreeHostImpl::FrameData frame; |
| 984 | 984 |
| 985 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 985 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 986 m_hostImpl->drawLayers(frame); | 986 m_hostImpl->drawLayers(frame); |
| 987 m_hostImpl->didDrawAllLayers(frame); | 987 m_hostImpl->didDrawAllLayers(frame); |
| 988 | 988 |
| 989 // When a texture is missing and we're not animating, we draw as usual with
checkerboarding. | 989 // When a texture is missing and we're not animating, we draw as usual with
checkerboarding. |
| 990 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); | 990 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); |
| 991 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); | 991 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); |
| 992 root->addChild(MissingTextureAnimatingLayer::create(2, true, false, false, m
_hostImpl->resourceProvider())); | 992 root->addChild(MissingTextureAnimatingLayer::create(2, true, false, false, m
_hostImpl->resourceProvider())); |
| 993 | 993 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1007 // When the layer skips draw and we're animating, we still draw the frame. | 1007 // When the layer skips draw and we're animating, we still draw the frame. |
| 1008 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); | 1008 m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); |
| 1009 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); | 1009 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); |
| 1010 root->addChild(MissingTextureAnimatingLayer::create(2, false, true, true, m_
hostImpl->resourceProvider())); | 1010 root->addChild(MissingTextureAnimatingLayer::create(2, false, true, true, m_
hostImpl->resourceProvider())); |
| 1011 | 1011 |
| 1012 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 1012 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1013 m_hostImpl->drawLayers(frame); | 1013 m_hostImpl->drawLayers(frame); |
| 1014 m_hostImpl->didDrawAllLayers(frame); | 1014 m_hostImpl->didDrawAllLayers(frame); |
| 1015 } | 1015 } |
| 1016 | 1016 |
| 1017 TEST_P(CCLayerTreeHostImplTest, scrollRootIgnored) | 1017 TEST_P(LayerTreeHostImplTest, scrollRootIgnored) |
| 1018 { | 1018 { |
| 1019 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 1019 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 1020 root->setScrollable(false); | 1020 root->setScrollable(false); |
| 1021 m_hostImpl->setRootLayer(root.Pass()); | 1021 m_hostImpl->setRootLayer(root.Pass()); |
| 1022 initializeRendererAndDrawFrame(); | 1022 initializeRendererAndDrawFrame(); |
| 1023 | 1023 |
| 1024 // Scroll event is ignored because layer is not scrollable. | 1024 // Scroll event is ignored because layer is not scrollable. |
| 1025 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollIgnored); | 1025 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollIgnored); |
| 1026 EXPECT_FALSE(m_didRequestRedraw); | 1026 EXPECT_FALSE(m_didRequestRedraw); |
| 1027 EXPECT_FALSE(m_didRequestCommit); | 1027 EXPECT_FALSE(m_didRequestCommit); |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 TEST_P(CCLayerTreeHostImplTest, scrollNonCompositedRoot) | 1030 TEST_P(LayerTreeHostImplTest, scrollNonCompositedRoot) |
| 1031 { | 1031 { |
| 1032 // Test the configuration where a non-composited root layer is embedded in a | 1032 // Test the configuration where a non-composited root layer is embedded in a |
| 1033 // scrollable outer layer. | 1033 // scrollable outer layer. |
| 1034 IntSize surfaceSize(10, 10); | 1034 IntSize surfaceSize(10, 10); |
| 1035 | 1035 |
| 1036 scoped_ptr<CCLayerImpl> contentLayer = CCLayerImpl::create(1); | 1036 scoped_ptr<LayerImpl> contentLayer = LayerImpl::create(1); |
| 1037 contentLayer->setUseLCDText(true); | 1037 contentLayer->setUseLCDText(true); |
| 1038 contentLayer->setDrawsContent(true); | 1038 contentLayer->setDrawsContent(true); |
| 1039 contentLayer->setPosition(FloatPoint(0, 0)); | 1039 contentLayer->setPosition(FloatPoint(0, 0)); |
| 1040 contentLayer->setAnchorPoint(FloatPoint(0, 0)); | 1040 contentLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 1041 contentLayer->setBounds(surfaceSize); | 1041 contentLayer->setBounds(surfaceSize); |
| 1042 contentLayer->setContentBounds(IntSize(surfaceSize.width() * 2, surfaceSize.
height() * 2)); | 1042 contentLayer->setContentBounds(IntSize(surfaceSize.width() * 2, surfaceSize.
height() * 2)); |
| 1043 | 1043 |
| 1044 scoped_ptr<CCLayerImpl> scrollLayer = CCLayerImpl::create(2); | 1044 scoped_ptr<LayerImpl> scrollLayer = LayerImpl::create(2); |
| 1045 scrollLayer->setScrollable(true); | 1045 scrollLayer->setScrollable(true); |
| 1046 scrollLayer->setMaxScrollPosition(surfaceSize); | 1046 scrollLayer->setMaxScrollPosition(surfaceSize); |
| 1047 scrollLayer->setBounds(surfaceSize); | 1047 scrollLayer->setBounds(surfaceSize); |
| 1048 scrollLayer->setContentBounds(surfaceSize); | 1048 scrollLayer->setContentBounds(surfaceSize); |
| 1049 scrollLayer->setPosition(FloatPoint(0, 0)); | 1049 scrollLayer->setPosition(FloatPoint(0, 0)); |
| 1050 scrollLayer->setAnchorPoint(FloatPoint(0, 0)); | 1050 scrollLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 1051 scrollLayer->addChild(contentLayer.Pass()); | 1051 scrollLayer->addChild(contentLayer.Pass()); |
| 1052 | 1052 |
| 1053 m_hostImpl->setRootLayer(scrollLayer.Pass()); | 1053 m_hostImpl->setRootLayer(scrollLayer.Pass()); |
| 1054 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1054 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1055 initializeRendererAndDrawFrame(); | 1055 initializeRendererAndDrawFrame(); |
| 1056 | 1056 |
| 1057 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 1057 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 1058 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); | 1058 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); |
| 1059 m_hostImpl->scrollEnd(); | 1059 m_hostImpl->scrollEnd(); |
| 1060 EXPECT_TRUE(m_didRequestRedraw); | 1060 EXPECT_TRUE(m_didRequestRedraw); |
| 1061 EXPECT_TRUE(m_didRequestCommit); | 1061 EXPECT_TRUE(m_didRequestCommit); |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 TEST_P(CCLayerTreeHostImplTest, scrollChildCallsCommitAndRedraw) | 1064 TEST_P(LayerTreeHostImplTest, scrollChildCallsCommitAndRedraw) |
| 1065 { | 1065 { |
| 1066 IntSize surfaceSize(10, 10); | 1066 IntSize surfaceSize(10, 10); |
| 1067 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 1067 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 1068 root->setBounds(surfaceSize); | 1068 root->setBounds(surfaceSize); |
| 1069 root->setContentBounds(surfaceSize); | 1069 root->setContentBounds(surfaceSize); |
| 1070 root->addChild(createScrollableLayer(2, surfaceSize)); | 1070 root->addChild(createScrollableLayer(2, surfaceSize)); |
| 1071 m_hostImpl->setRootLayer(root.Pass()); | 1071 m_hostImpl->setRootLayer(root.Pass()); |
| 1072 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1072 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1073 initializeRendererAndDrawFrame(); | 1073 initializeRendererAndDrawFrame(); |
| 1074 | 1074 |
| 1075 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 1075 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 1076 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); | 1076 m_hostImpl->scrollBy(IntPoint(), IntSize(0, 10)); |
| 1077 m_hostImpl->scrollEnd(); | 1077 m_hostImpl->scrollEnd(); |
| 1078 EXPECT_TRUE(m_didRequestRedraw); | 1078 EXPECT_TRUE(m_didRequestRedraw); |
| 1079 EXPECT_TRUE(m_didRequestCommit); | 1079 EXPECT_TRUE(m_didRequestCommit); |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 TEST_P(CCLayerTreeHostImplTest, scrollMissesChild) | 1082 TEST_P(LayerTreeHostImplTest, scrollMissesChild) |
| 1083 { | 1083 { |
| 1084 IntSize surfaceSize(10, 10); | 1084 IntSize surfaceSize(10, 10); |
| 1085 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 1085 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 1086 root->addChild(createScrollableLayer(2, surfaceSize)); | 1086 root->addChild(createScrollableLayer(2, surfaceSize)); |
| 1087 m_hostImpl->setRootLayer(root.Pass()); | 1087 m_hostImpl->setRootLayer(root.Pass()); |
| 1088 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1088 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1089 initializeRendererAndDrawFrame(); | 1089 initializeRendererAndDrawFrame(); |
| 1090 | 1090 |
| 1091 // Scroll event is ignored because the input coordinate is outside the layer
boundaries. | 1091 // Scroll event is ignored because the input coordinate is outside the layer
boundaries. |
| 1092 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(15, 5), CCInputHandlerClient::Whe
el), CCInputHandlerClient::ScrollIgnored); | 1092 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(15, 5), InputHandlerClient::Wheel
), InputHandlerClient::ScrollIgnored); |
| 1093 EXPECT_FALSE(m_didRequestRedraw); | 1093 EXPECT_FALSE(m_didRequestRedraw); |
| 1094 EXPECT_FALSE(m_didRequestCommit); | 1094 EXPECT_FALSE(m_didRequestCommit); |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 TEST_P(CCLayerTreeHostImplTest, scrollMissesBackfacingChild) | 1097 TEST_P(LayerTreeHostImplTest, scrollMissesBackfacingChild) |
| 1098 { | 1098 { |
| 1099 IntSize surfaceSize(10, 10); | 1099 IntSize surfaceSize(10, 10); |
| 1100 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 1100 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 1101 scoped_ptr<CCLayerImpl> child = createScrollableLayer(2, surfaceSize); | 1101 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
| 1102 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1102 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1103 | 1103 |
| 1104 WebTransformationMatrix matrix; | 1104 WebTransformationMatrix matrix; |
| 1105 matrix.rotate3d(180, 0, 0); | 1105 matrix.rotate3d(180, 0, 0); |
| 1106 child->setTransform(matrix); | 1106 child->setTransform(matrix); |
| 1107 child->setDoubleSided(false); | 1107 child->setDoubleSided(false); |
| 1108 | 1108 |
| 1109 root->addChild(child.Pass()); | 1109 root->addChild(child.Pass()); |
| 1110 m_hostImpl->setRootLayer(root.Pass()); | 1110 m_hostImpl->setRootLayer(root.Pass()); |
| 1111 initializeRendererAndDrawFrame(); | 1111 initializeRendererAndDrawFrame(); |
| 1112 | 1112 |
| 1113 // Scroll event is ignored because the scrollable layer is not facing the vi
ewer and there is | 1113 // Scroll event is ignored because the scrollable layer is not facing the vi
ewer and there is |
| 1114 // nothing scrollable behind it. | 1114 // nothing scrollable behind it. |
| 1115 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollIgnored); | 1115 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollIgnored); |
| 1116 EXPECT_FALSE(m_didRequestRedraw); | 1116 EXPECT_FALSE(m_didRequestRedraw); |
| 1117 EXPECT_FALSE(m_didRequestCommit); | 1117 EXPECT_FALSE(m_didRequestCommit); |
| 1118 } | 1118 } |
| 1119 | 1119 |
| 1120 TEST_P(CCLayerTreeHostImplTest, scrollBlockedByContentLayer) | 1120 TEST_P(LayerTreeHostImplTest, scrollBlockedByContentLayer) |
| 1121 { | 1121 { |
| 1122 IntSize surfaceSize(10, 10); | 1122 IntSize surfaceSize(10, 10); |
| 1123 scoped_ptr<CCLayerImpl> contentLayer = createScrollableLayer(1, surfaceSize)
; | 1123 scoped_ptr<LayerImpl> contentLayer = createScrollableLayer(1, surfaceSize); |
| 1124 contentLayer->setShouldScrollOnMainThread(true); | 1124 contentLayer->setShouldScrollOnMainThread(true); |
| 1125 contentLayer->setScrollable(false); | 1125 contentLayer->setScrollable(false); |
| 1126 | 1126 |
| 1127 scoped_ptr<CCLayerImpl> scrollLayer = createScrollableLayer(2, surfaceSize); | 1127 scoped_ptr<LayerImpl> scrollLayer = createScrollableLayer(2, surfaceSize); |
| 1128 scrollLayer->addChild(contentLayer.Pass()); | 1128 scrollLayer->addChild(contentLayer.Pass()); |
| 1129 | 1129 |
| 1130 m_hostImpl->setRootLayer(scrollLayer.Pass()); | 1130 m_hostImpl->setRootLayer(scrollLayer.Pass()); |
| 1131 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1131 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1132 initializeRendererAndDrawFrame(); | 1132 initializeRendererAndDrawFrame(); |
| 1133 | 1133 |
| 1134 // Scrolling fails because the content layer is asking to be scrolled on the
main thread. | 1134 // Scrolling fails because the content layer is asking to be scrolled on the
main thread. |
| 1135 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollOnMainThread); | 1135 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollOnMainThread); |
| 1136 } | 1136 } |
| 1137 | 1137 |
| 1138 TEST_P(CCLayerTreeHostImplTest, scrollRootAndChangePageScaleOnMainThread) | 1138 TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnMainThread) |
| 1139 { | 1139 { |
| 1140 IntSize surfaceSize(10, 10); | 1140 IntSize surfaceSize(10, 10); |
| 1141 float pageScale = 2; | 1141 float pageScale = 2; |
| 1142 scoped_ptr<CCLayerImpl> root = createScrollableLayer(1, surfaceSize); | 1142 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1143 m_hostImpl->setRootLayer(root.Pass()); | 1143 m_hostImpl->setRootLayer(root.Pass()); |
| 1144 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1144 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1145 initializeRendererAndDrawFrame(); | 1145 initializeRendererAndDrawFrame(); |
| 1146 | 1146 |
| 1147 IntSize scrollDelta(0, 10); | 1147 IntSize scrollDelta(0, 10); |
| 1148 IntSize expectedScrollDelta(scrollDelta); | 1148 IntSize expectedScrollDelta(scrollDelta); |
| 1149 IntSize expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollPosition()); | 1149 IntSize expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollPosition()); |
| 1150 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 1150 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 1151 m_hostImpl->scrollBy(IntPoint(), scrollDelta); | 1151 m_hostImpl->scrollBy(IntPoint(), scrollDelta); |
| 1152 m_hostImpl->scrollEnd(); | 1152 m_hostImpl->scrollEnd(); |
| 1153 | 1153 |
| 1154 // Set new page scale from main thread. | 1154 // Set new page scale from main thread. |
| 1155 m_hostImpl->setPageScaleFactorAndLimits(pageScale, pageScale, pageScale); | 1155 m_hostImpl->setPageScaleFactorAndLimits(pageScale, pageScale, pageScale); |
| 1156 | 1156 |
| 1157 if (!CCSettings::pageScalePinchZoomEnabled()) { | 1157 if (!Settings::pageScalePinchZoomEnabled()) { |
| 1158 // The scale should apply to the scroll delta. | 1158 // The scale should apply to the scroll delta. |
| 1159 expectedScrollDelta.scale(pageScale); | 1159 expectedScrollDelta.scale(pageScale); |
| 1160 } | 1160 } |
| 1161 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas
(); | 1161 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1162 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 1162 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); |
| 1163 | 1163 |
| 1164 // The scroll range should also have been updated. | 1164 // The scroll range should also have been updated. |
| 1165 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), expectedMaxScroll); | 1165 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), expectedMaxScroll); |
| 1166 | 1166 |
| 1167 // The page scale delta remains constant because the impl thread did not sca
le. | 1167 // The page scale delta remains constant because the impl thread did not sca
le. |
| 1168 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), WebTransformationMatrix(
)); | 1168 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), WebTransformationMatrix(
)); |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 TEST_P(CCLayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) | 1171 TEST_P(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) |
| 1172 { | 1172 { |
| 1173 IntSize surfaceSize(10, 10); | 1173 IntSize surfaceSize(10, 10); |
| 1174 float pageScale = 2; | 1174 float pageScale = 2; |
| 1175 scoped_ptr<CCLayerImpl> root = createScrollableLayer(1, surfaceSize); | 1175 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1176 m_hostImpl->setRootLayer(root.Pass()); | 1176 m_hostImpl->setRootLayer(root.Pass()); |
| 1177 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1177 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1178 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); | 1178 m_hostImpl->setPageScaleFactorAndLimits(1, 1, pageScale); |
| 1179 initializeRendererAndDrawFrame(); | 1179 initializeRendererAndDrawFrame(); |
| 1180 | 1180 |
| 1181 IntSize scrollDelta(0, 10); | 1181 IntSize scrollDelta(0, 10); |
| 1182 IntSize expectedScrollDelta(scrollDelta); | 1182 IntSize expectedScrollDelta(scrollDelta); |
| 1183 IntSize expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollPosition()); | 1183 IntSize expectedMaxScroll(m_hostImpl->rootLayer()->maxScrollPosition()); |
| 1184 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 1184 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 1185 m_hostImpl->scrollBy(IntPoint(), scrollDelta); | 1185 m_hostImpl->scrollBy(IntPoint(), scrollDelta); |
| 1186 m_hostImpl->scrollEnd(); | 1186 m_hostImpl->scrollEnd(); |
| 1187 | 1187 |
| 1188 // Set new page scale on impl thread by pinching. | 1188 // Set new page scale on impl thread by pinching. |
| 1189 m_hostImpl->pinchGestureBegin(); | 1189 m_hostImpl->pinchGestureBegin(); |
| 1190 m_hostImpl->pinchGestureUpdate(pageScale, IntPoint()); | 1190 m_hostImpl->pinchGestureUpdate(pageScale, IntPoint()); |
| 1191 m_hostImpl->pinchGestureEnd(); | 1191 m_hostImpl->pinchGestureEnd(); |
| 1192 m_hostImpl->updateRootScrollLayerImplTransform(); | 1192 m_hostImpl->updateRootScrollLayerImplTransform(); |
| 1193 | 1193 |
| 1194 // The scroll delta is not scaled because the main thread did not scale. | 1194 // The scroll delta is not scaled because the main thread did not scale. |
| 1195 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas
(); | 1195 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1196 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); | 1196 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr
ollDelta); |
| 1197 | 1197 |
| 1198 // The scroll range should also have been updated. | 1198 // The scroll range should also have been updated. |
| 1199 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), expectedMaxScroll); | 1199 EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollPosition(), expectedMaxScroll); |
| 1200 | 1200 |
| 1201 // The page scale delta should match the new scale on the impl side. | 1201 // The page scale delta should match the new scale on the impl side. |
| 1202 WebTransformationMatrix expectedScale; | 1202 WebTransformationMatrix expectedScale; |
| 1203 expectedScale.scale(pageScale); | 1203 expectedScale.scale(pageScale); |
| 1204 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedScale); | 1204 EXPECT_EQ(m_hostImpl->rootLayer()->implTransform(), expectedScale); |
| 1205 } | 1205 } |
| 1206 | 1206 |
| 1207 TEST_P(CCLayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) | 1207 TEST_P(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) |
| 1208 { | 1208 { |
| 1209 IntSize surfaceSize(10, 10); | 1209 IntSize surfaceSize(10, 10); |
| 1210 float defaultPageScale = 1; | 1210 float defaultPageScale = 1; |
| 1211 WebTransformationMatrix defaultPageScaleMatrix; | 1211 WebTransformationMatrix defaultPageScaleMatrix; |
| 1212 | 1212 |
| 1213 float newPageScale = 2; | 1213 float newPageScale = 2; |
| 1214 WebTransformationMatrix newPageScaleMatrix; | 1214 WebTransformationMatrix newPageScaleMatrix; |
| 1215 newPageScaleMatrix.scale(newPageScale); | 1215 newPageScaleMatrix.scale(newPageScale); |
| 1216 | 1216 |
| 1217 // Create a normal scrollable root layer and another scrollable child layer. | 1217 // Create a normal scrollable root layer and another scrollable child layer. |
| 1218 setupScrollAndContentsLayers(surfaceSize); | 1218 setupScrollAndContentsLayers(surfaceSize); |
| 1219 CCLayerImpl* root = m_hostImpl->rootLayer(); | 1219 LayerImpl* root = m_hostImpl->rootLayer(); |
| 1220 CCLayerImpl* child = root->children()[0]; | 1220 LayerImpl* child = root->children()[0]; |
| 1221 | 1221 |
| 1222 scoped_ptr<CCLayerImpl> scrollableChild = createScrollableLayer(3, surfaceSi
ze); | 1222 scoped_ptr<LayerImpl> scrollableChild = createScrollableLayer(3, surfaceSize
); |
| 1223 child->addChild(scrollableChild.Pass()); | 1223 child->addChild(scrollableChild.Pass()); |
| 1224 CCLayerImpl* grandChild = child->children()[0]; | 1224 LayerImpl* grandChild = child->children()[0]; |
| 1225 | 1225 |
| 1226 // Set new page scale on impl thread by pinching. | 1226 // Set new page scale on impl thread by pinching. |
| 1227 m_hostImpl->pinchGestureBegin(); | 1227 m_hostImpl->pinchGestureBegin(); |
| 1228 m_hostImpl->pinchGestureUpdate(newPageScale, IntPoint()); | 1228 m_hostImpl->pinchGestureUpdate(newPageScale, IntPoint()); |
| 1229 m_hostImpl->pinchGestureEnd(); | 1229 m_hostImpl->pinchGestureEnd(); |
| 1230 m_hostImpl->updateRootScrollLayerImplTransform(); | 1230 m_hostImpl->updateRootScrollLayerImplTransform(); |
| 1231 | 1231 |
| 1232 // The page scale delta should only be applied to the scrollable root layer. | 1232 // The page scale delta should only be applied to the scrollable root layer. |
| 1233 EXPECT_EQ(root->implTransform(), newPageScaleMatrix); | 1233 EXPECT_EQ(root->implTransform(), newPageScaleMatrix); |
| 1234 EXPECT_EQ(child->implTransform(), defaultPageScaleMatrix); | 1234 EXPECT_EQ(child->implTransform(), defaultPageScaleMatrix); |
| 1235 EXPECT_EQ(grandChild->implTransform(), defaultPageScaleMatrix); | 1235 EXPECT_EQ(grandChild->implTransform(), defaultPageScaleMatrix); |
| 1236 | 1236 |
| 1237 // Make sure all the layers are drawn with the page scale delta applied, i.e
., the page scale | 1237 // Make sure all the layers are drawn with the page scale delta applied, i.e
., the page scale |
| 1238 // delta on the root layer is applied hierarchically. | 1238 // delta on the root layer is applied hierarchically. |
| 1239 CCLayerTreeHostImpl::FrameData frame; | 1239 LayerTreeHostImpl::FrameData frame; |
| 1240 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 1240 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1241 m_hostImpl->drawLayers(frame); | 1241 m_hostImpl->drawLayers(frame); |
| 1242 m_hostImpl->didDrawAllLayers(frame); | 1242 m_hostImpl->didDrawAllLayers(frame); |
| 1243 | 1243 |
| 1244 EXPECT_EQ(root->drawTransform().m11(), newPageScale); | 1244 EXPECT_EQ(root->drawTransform().m11(), newPageScale); |
| 1245 EXPECT_EQ(root->drawTransform().m22(), newPageScale); | 1245 EXPECT_EQ(root->drawTransform().m22(), newPageScale); |
| 1246 EXPECT_EQ(child->drawTransform().m11(), newPageScale); | 1246 EXPECT_EQ(child->drawTransform().m11(), newPageScale); |
| 1247 EXPECT_EQ(child->drawTransform().m22(), newPageScale); | 1247 EXPECT_EQ(child->drawTransform().m22(), newPageScale); |
| 1248 EXPECT_EQ(grandChild->drawTransform().m11(), newPageScale); | 1248 EXPECT_EQ(grandChild->drawTransform().m11(), newPageScale); |
| 1249 EXPECT_EQ(grandChild->drawTransform().m22(), newPageScale); | 1249 EXPECT_EQ(grandChild->drawTransform().m22(), newPageScale); |
| 1250 } | 1250 } |
| 1251 | 1251 |
| 1252 TEST_P(CCLayerTreeHostImplTest, scrollChildAndChangePageScaleOnMainThread) | 1252 TEST_P(LayerTreeHostImplTest, scrollChildAndChangePageScaleOnMainThread) |
| 1253 { | 1253 { |
| 1254 IntSize surfaceSize(10, 10); | 1254 IntSize surfaceSize(10, 10); |
| 1255 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 1255 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 1256 root->setBounds(surfaceSize); | 1256 root->setBounds(surfaceSize); |
| 1257 root->setContentBounds(surfaceSize); | 1257 root->setContentBounds(surfaceSize); |
| 1258 // Also mark the root scrollable so it becomes the root scroll layer. | 1258 // Also mark the root scrollable so it becomes the root scroll layer. |
| 1259 root->setScrollable(true); | 1259 root->setScrollable(true); |
| 1260 int scrollLayerId = 2; | 1260 int scrollLayerId = 2; |
| 1261 root->addChild(createScrollableLayer(scrollLayerId, surfaceSize)); | 1261 root->addChild(createScrollableLayer(scrollLayerId, surfaceSize)); |
| 1262 m_hostImpl->setRootLayer(root.Pass()); | 1262 m_hostImpl->setRootLayer(root.Pass()); |
| 1263 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1263 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1264 initializeRendererAndDrawFrame(); | 1264 initializeRendererAndDrawFrame(); |
| 1265 | 1265 |
| 1266 CCLayerImpl* child = m_hostImpl->rootLayer()->children()[0]; | 1266 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
| 1267 | 1267 |
| 1268 IntSize scrollDelta(0, 10); | 1268 IntSize scrollDelta(0, 10); |
| 1269 IntSize expectedScrollDelta(scrollDelta); | 1269 IntSize expectedScrollDelta(scrollDelta); |
| 1270 IntSize expectedMaxScroll(child->maxScrollPosition()); | 1270 IntSize expectedMaxScroll(child->maxScrollPosition()); |
| 1271 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 1271 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 1272 m_hostImpl->scrollBy(IntPoint(), scrollDelta); | 1272 m_hostImpl->scrollBy(IntPoint(), scrollDelta); |
| 1273 m_hostImpl->scrollEnd(); | 1273 m_hostImpl->scrollEnd(); |
| 1274 | 1274 |
| 1275 float pageScale = 2; | 1275 float pageScale = 2; |
| 1276 m_hostImpl->setPageScaleFactorAndLimits(pageScale, 1, pageScale); | 1276 m_hostImpl->setPageScaleFactorAndLimits(pageScale, 1, pageScale); |
| 1277 | 1277 |
| 1278 m_hostImpl->updateRootScrollLayerImplTransform(); | 1278 m_hostImpl->updateRootScrollLayerImplTransform(); |
| 1279 | 1279 |
| 1280 if (!CCSettings::pageScalePinchZoomEnabled()) { | 1280 if (!Settings::pageScalePinchZoomEnabled()) { |
| 1281 // The scale should apply to the scroll delta. | 1281 // The scale should apply to the scroll delta. |
| 1282 expectedScrollDelta.scale(pageScale); | 1282 expectedScrollDelta.scale(pageScale); |
| 1283 } | 1283 } |
| 1284 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas
(); | 1284 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1285 expectContains(*scrollInfo.get(), scrollLayerId, expectedScrollDelta); | 1285 expectContains(*scrollInfo.get(), scrollLayerId, expectedScrollDelta); |
| 1286 | 1286 |
| 1287 // The scroll range should not have changed. | 1287 // The scroll range should not have changed. |
| 1288 EXPECT_EQ(child->maxScrollPosition(), expectedMaxScroll); | 1288 EXPECT_EQ(child->maxScrollPosition(), expectedMaxScroll); |
| 1289 | 1289 |
| 1290 // The page scale delta remains constant because the impl thread did not sca
le. | 1290 // The page scale delta remains constant because the impl thread did not sca
le. |
| 1291 WebTransformationMatrix identityTransform; | 1291 WebTransformationMatrix identityTransform; |
| 1292 EXPECT_EQ(child->implTransform(), WebTransformationMatrix()); | 1292 EXPECT_EQ(child->implTransform(), WebTransformationMatrix()); |
| 1293 } | 1293 } |
| 1294 | 1294 |
| 1295 TEST_P(CCLayerTreeHostImplTest, scrollChildBeyondLimit) | 1295 TEST_P(LayerTreeHostImplTest, scrollChildBeyondLimit) |
| 1296 { | 1296 { |
| 1297 // Scroll a child layer beyond its maximum scroll range and make sure the | 1297 // Scroll a child layer beyond its maximum scroll range and make sure the |
| 1298 // parent layer is scrolled on the axis on which the child was unable to | 1298 // parent layer is scrolled on the axis on which the child was unable to |
| 1299 // scroll. | 1299 // scroll. |
| 1300 IntSize surfaceSize(10, 10); | 1300 IntSize surfaceSize(10, 10); |
| 1301 scoped_ptr<CCLayerImpl> root = createScrollableLayer(1, surfaceSize); | 1301 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1302 | 1302 |
| 1303 scoped_ptr<CCLayerImpl> grandChild = createScrollableLayer(3, surfaceSize); | 1303 scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize); |
| 1304 grandChild->setScrollPosition(IntPoint(0, 5)); | 1304 grandChild->setScrollPosition(IntPoint(0, 5)); |
| 1305 | 1305 |
| 1306 scoped_ptr<CCLayerImpl> child = createScrollableLayer(2, surfaceSize); | 1306 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
| 1307 child->setScrollPosition(IntPoint(3, 0)); | 1307 child->setScrollPosition(IntPoint(3, 0)); |
| 1308 child->addChild(grandChild.Pass()); | 1308 child->addChild(grandChild.Pass()); |
| 1309 | 1309 |
| 1310 root->addChild(child.Pass()); | 1310 root->addChild(child.Pass()); |
| 1311 m_hostImpl->setRootLayer(root.Pass()); | 1311 m_hostImpl->setRootLayer(root.Pass()); |
| 1312 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1312 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1313 initializeRendererAndDrawFrame(); | 1313 initializeRendererAndDrawFrame(); |
| 1314 { | 1314 { |
| 1315 IntSize scrollDelta(-8, -7); | 1315 IntSize scrollDelta(-8, -7); |
| 1316 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::
Wheel), CCInputHandlerClient::ScrollStarted); | 1316 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); |
| 1317 m_hostImpl->scrollBy(IntPoint(), scrollDelta); | 1317 m_hostImpl->scrollBy(IntPoint(), scrollDelta); |
| 1318 m_hostImpl->scrollEnd(); | 1318 m_hostImpl->scrollEnd(); |
| 1319 | 1319 |
| 1320 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 1320 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1321 | 1321 |
| 1322 // The grand child should have scrolled up to its limit. | 1322 // The grand child should have scrolled up to its limit. |
| 1323 CCLayerImpl* child = m_hostImpl->rootLayer()->children()[0]; | 1323 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; |
| 1324 CCLayerImpl* grandChild = child->children()[0]; | 1324 LayerImpl* grandChild = child->children()[0]; |
| 1325 expectContains(*scrollInfo.get(), grandChild->id(), IntSize(0, -5)); | 1325 expectContains(*scrollInfo.get(), grandChild->id(), IntSize(0, -5)); |
| 1326 | 1326 |
| 1327 // The child should have only scrolled on the other axis. | 1327 // The child should have only scrolled on the other axis. |
| 1328 expectContains(*scrollInfo.get(), child->id(), IntSize(-3, 0)); | 1328 expectContains(*scrollInfo.get(), child->id(), IntSize(-3, 0)); |
| 1329 } | 1329 } |
| 1330 } | 1330 } |
| 1331 | 1331 |
| 1332 TEST_P(CCLayerTreeHostImplTest, scrollEventBubbling) | 1332 TEST_P(LayerTreeHostImplTest, scrollEventBubbling) |
| 1333 { | 1333 { |
| 1334 // When we try to scroll a non-scrollable child layer, the scroll delta | 1334 // When we try to scroll a non-scrollable child layer, the scroll delta |
| 1335 // should be applied to one of its ancestors if possible. | 1335 // should be applied to one of its ancestors if possible. |
| 1336 IntSize surfaceSize(10, 10); | 1336 IntSize surfaceSize(10, 10); |
| 1337 scoped_ptr<CCLayerImpl> root = createScrollableLayer(1, surfaceSize); | 1337 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1338 scoped_ptr<CCLayerImpl> child = createScrollableLayer(2, surfaceSize); | 1338 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
| 1339 | 1339 |
| 1340 child->setScrollable(false); | 1340 child->setScrollable(false); |
| 1341 root->addChild(child.Pass()); | 1341 root->addChild(child.Pass()); |
| 1342 | 1342 |
| 1343 m_hostImpl->setRootLayer(root.Pass()); | 1343 m_hostImpl->setRootLayer(root.Pass()); |
| 1344 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1344 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1345 initializeRendererAndDrawFrame(); | 1345 initializeRendererAndDrawFrame(); |
| 1346 { | 1346 { |
| 1347 IntSize scrollDelta(0, 4); | 1347 IntSize scrollDelta(0, 4); |
| 1348 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::
Wheel), CCInputHandlerClient::ScrollStarted); | 1348 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wh
eel), InputHandlerClient::ScrollStarted); |
| 1349 m_hostImpl->scrollBy(IntPoint(), scrollDelta); | 1349 m_hostImpl->scrollBy(IntPoint(), scrollDelta); |
| 1350 m_hostImpl->scrollEnd(); | 1350 m_hostImpl->scrollEnd(); |
| 1351 | 1351 |
| 1352 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 1352 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1353 | 1353 |
| 1354 // Only the root should have scrolled. | 1354 // Only the root should have scrolled. |
| 1355 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); | 1355 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); |
| 1356 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD
elta); | 1356 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD
elta); |
| 1357 } | 1357 } |
| 1358 } | 1358 } |
| 1359 | 1359 |
| 1360 TEST_P(CCLayerTreeHostImplTest, scrollBeforeRedraw) | 1360 TEST_P(LayerTreeHostImplTest, scrollBeforeRedraw) |
| 1361 { | 1361 { |
| 1362 IntSize surfaceSize(10, 10); | 1362 IntSize surfaceSize(10, 10); |
| 1363 m_hostImpl->setRootLayer(createScrollableLayer(1, surfaceSize)); | 1363 m_hostImpl->setRootLayer(createScrollableLayer(1, surfaceSize)); |
| 1364 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1364 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1365 | 1365 |
| 1366 // Draw one frame and then immediately rebuild the layer tree to mimic a tre
e synchronization. | 1366 // Draw one frame and then immediately rebuild the layer tree to mimic a tre
e synchronization. |
| 1367 initializeRendererAndDrawFrame(); | 1367 initializeRendererAndDrawFrame(); |
| 1368 m_hostImpl->detachLayerTree(); | 1368 m_hostImpl->detachLayerTree(); |
| 1369 m_hostImpl->setRootLayer(createScrollableLayer(2, surfaceSize)); | 1369 m_hostImpl->setRootLayer(createScrollableLayer(2, surfaceSize)); |
| 1370 | 1370 |
| 1371 // Scrolling should still work even though we did not draw yet. | 1371 // Scrolling should still work even though we did not draw yet. |
| 1372 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 1372 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 1373 } | 1373 } |
| 1374 | 1374 |
| 1375 TEST_P(CCLayerTreeHostImplTest, scrollAxisAlignedRotatedLayer) | 1375 TEST_P(LayerTreeHostImplTest, scrollAxisAlignedRotatedLayer) |
| 1376 { | 1376 { |
| 1377 setupScrollAndContentsLayers(IntSize(100, 100)); | 1377 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 1378 | 1378 |
| 1379 // Rotate the root layer 90 degrees counter-clockwise about its center. | 1379 // Rotate the root layer 90 degrees counter-clockwise about its center. |
| 1380 WebTransformationMatrix rotateTransform; | 1380 WebTransformationMatrix rotateTransform; |
| 1381 rotateTransform.rotate(-90); | 1381 rotateTransform.rotate(-90); |
| 1382 m_hostImpl->rootLayer()->setTransform(rotateTransform); | 1382 m_hostImpl->rootLayer()->setTransform(rotateTransform); |
| 1383 | 1383 |
| 1384 IntSize surfaceSize(50, 50); | 1384 IntSize surfaceSize(50, 50); |
| 1385 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1385 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1386 initializeRendererAndDrawFrame(); | 1386 initializeRendererAndDrawFrame(); |
| 1387 | 1387 |
| 1388 // Scroll to the right in screen coordinates with a gesture. | 1388 // Scroll to the right in screen coordinates with a gesture. |
| 1389 IntSize gestureScrollDelta(10, 0); | 1389 IntSize gestureScrollDelta(10, 0); |
| 1390 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Gest
ure), CCInputHandlerClient::ScrollStarted); | 1390 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Gestur
e), InputHandlerClient::ScrollStarted); |
| 1391 m_hostImpl->scrollBy(IntPoint(), gestureScrollDelta); | 1391 m_hostImpl->scrollBy(IntPoint(), gestureScrollDelta); |
| 1392 m_hostImpl->scrollEnd(); | 1392 m_hostImpl->scrollEnd(); |
| 1393 | 1393 |
| 1394 // The layer should have scrolled down in its local coordinates. | 1394 // The layer should have scrolled down in its local coordinates. |
| 1395 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas
(); | 1395 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1396 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), IntSize(0,
gestureScrollDelta.width())); | 1396 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), IntSize(0,
gestureScrollDelta.width())); |
| 1397 | 1397 |
| 1398 // Reset and scroll down with the wheel. | 1398 // Reset and scroll down with the wheel. |
| 1399 m_hostImpl->rootLayer()->setScrollDelta(FloatSize()); | 1399 m_hostImpl->rootLayer()->setScrollDelta(FloatSize()); |
| 1400 IntSize wheelScrollDelta(0, 10); | 1400 IntSize wheelScrollDelta(0, 10); |
| 1401 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 1401 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 1402 m_hostImpl->scrollBy(IntPoint(), wheelScrollDelta); | 1402 m_hostImpl->scrollBy(IntPoint(), wheelScrollDelta); |
| 1403 m_hostImpl->scrollEnd(); | 1403 m_hostImpl->scrollEnd(); |
| 1404 | 1404 |
| 1405 // The layer should have scrolled down in its local coordinates. | 1405 // The layer should have scrolled down in its local coordinates. |
| 1406 scrollInfo = m_hostImpl->processScrollDeltas(); | 1406 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 1407 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll
Delta); | 1407 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll
Delta); |
| 1408 } | 1408 } |
| 1409 | 1409 |
| 1410 TEST_P(CCLayerTreeHostImplTest, scrollNonAxisAlignedRotatedLayer) | 1410 TEST_P(LayerTreeHostImplTest, scrollNonAxisAlignedRotatedLayer) |
| 1411 { | 1411 { |
| 1412 setupScrollAndContentsLayers(IntSize(100, 100)); | 1412 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 1413 int childLayerId = 3; | 1413 int childLayerId = 3; |
| 1414 float childLayerAngle = -20; | 1414 float childLayerAngle = -20; |
| 1415 | 1415 |
| 1416 // Create a child layer that is rotated to a non-axis-aligned angle. | 1416 // Create a child layer that is rotated to a non-axis-aligned angle. |
| 1417 scoped_ptr<CCLayerImpl> child = createScrollableLayer(childLayerId, m_hostIm
pl->rootLayer()->contentBounds()); | 1417 scoped_ptr<LayerImpl> child = createScrollableLayer(childLayerId, m_hostImpl
->rootLayer()->contentBounds()); |
| 1418 WebTransformationMatrix rotateTransform; | 1418 WebTransformationMatrix rotateTransform; |
| 1419 rotateTransform.translate(-50, -50); | 1419 rotateTransform.translate(-50, -50); |
| 1420 rotateTransform.rotate(childLayerAngle); | 1420 rotateTransform.rotate(childLayerAngle); |
| 1421 rotateTransform.translate(50, 50); | 1421 rotateTransform.translate(50, 50); |
| 1422 child->setTransform(rotateTransform); | 1422 child->setTransform(rotateTransform); |
| 1423 | 1423 |
| 1424 // Only allow vertical scrolling. | 1424 // Only allow vertical scrolling. |
| 1425 child->setMaxScrollPosition(IntSize(0, child->contentBounds().height())); | 1425 child->setMaxScrollPosition(IntSize(0, child->contentBounds().height())); |
| 1426 m_hostImpl->rootLayer()->addChild(child.Pass()); | 1426 m_hostImpl->rootLayer()->addChild(child.Pass()); |
| 1427 | 1427 |
| 1428 IntSize surfaceSize(50, 50); | 1428 IntSize surfaceSize(50, 50); |
| 1429 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1429 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1430 initializeRendererAndDrawFrame(); | 1430 initializeRendererAndDrawFrame(); |
| 1431 | 1431 |
| 1432 { | 1432 { |
| 1433 // Scroll down in screen coordinates with a gesture. | 1433 // Scroll down in screen coordinates with a gesture. |
| 1434 IntSize gestureScrollDelta(0, 10); | 1434 IntSize gestureScrollDelta(0, 10); |
| 1435 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::
Gesture), CCInputHandlerClient::ScrollStarted); | 1435 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollStarted); |
| 1436 m_hostImpl->scrollBy(IntPoint(), gestureScrollDelta); | 1436 m_hostImpl->scrollBy(IntPoint(), gestureScrollDelta); |
| 1437 m_hostImpl->scrollEnd(); | 1437 m_hostImpl->scrollEnd(); |
| 1438 | 1438 |
| 1439 // The child layer should have scrolled down in its local coordinates an
amount proportional to | 1439 // The child layer should have scrolled down in its local coordinates an
amount proportional to |
| 1440 // the angle between it and the input scroll delta. | 1440 // the angle between it and the input scroll delta. |
| 1441 IntSize expectedScrollDelta(0, gestureScrollDelta.height() * cosf(deg2ra
d(childLayerAngle))); | 1441 IntSize expectedScrollDelta(0, gestureScrollDelta.height() * cosf(deg2ra
d(childLayerAngle))); |
| 1442 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 1442 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1443 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); | 1443 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); |
| 1444 | 1444 |
| 1445 // The root layer should not have scrolled, because the input delta was
close to the layer's | 1445 // The root layer should not have scrolled, because the input delta was
close to the layer's |
| 1446 // axis of movement. | 1446 // axis of movement. |
| 1447 EXPECT_EQ(scrollInfo->scrolls.size(), 1u); | 1447 EXPECT_EQ(scrollInfo->scrolls.size(), 1u); |
| 1448 } | 1448 } |
| 1449 | 1449 |
| 1450 { | 1450 { |
| 1451 // Now reset and scroll the same amount horizontally. | 1451 // Now reset and scroll the same amount horizontally. |
| 1452 m_hostImpl->rootLayer()->children()[1]->setScrollDelta(FloatSize()); | 1452 m_hostImpl->rootLayer()->children()[1]->setScrollDelta(FloatSize()); |
| 1453 IntSize gestureScrollDelta(10, 0); | 1453 IntSize gestureScrollDelta(10, 0); |
| 1454 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::
Gesture), CCInputHandlerClient::ScrollStarted); | 1454 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Ge
sture), InputHandlerClient::ScrollStarted); |
| 1455 m_hostImpl->scrollBy(IntPoint(), gestureScrollDelta); | 1455 m_hostImpl->scrollBy(IntPoint(), gestureScrollDelta); |
| 1456 m_hostImpl->scrollEnd(); | 1456 m_hostImpl->scrollEnd(); |
| 1457 | 1457 |
| 1458 // The child layer should have scrolled down in its local coordinates an
amount proportional to | 1458 // The child layer should have scrolled down in its local coordinates an
amount proportional to |
| 1459 // the angle between it and the input scroll delta. | 1459 // the angle between it and the input scroll delta. |
| 1460 IntSize expectedScrollDelta(0, -gestureScrollDelta.width() * sinf(deg2ra
d(childLayerAngle))); | 1460 IntSize expectedScrollDelta(0, -gestureScrollDelta.width() * sinf(deg2ra
d(childLayerAngle))); |
| 1461 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDe
ltas(); | 1461 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt
as(); |
| 1462 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); | 1462 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); |
| 1463 | 1463 |
| 1464 // The root layer should have scrolled more, since the input scroll delt
a was mostly | 1464 // The root layer should have scrolled more, since the input scroll delt
a was mostly |
| 1465 // orthogonal to the child layer's vertical scroll axis. | 1465 // orthogonal to the child layer's vertical scroll axis. |
| 1466 IntSize expectedRootScrollDelta(gestureScrollDelta.width() * pow(cosf(de
g2rad(childLayerAngle)), 2), 0); | 1466 IntSize expectedRootScrollDelta(gestureScrollDelta.width() * pow(cosf(de
g2rad(childLayerAngle)), 2), 0); |
| 1467 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expecte
dRootScrollDelta); | 1467 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expecte
dRootScrollDelta); |
| 1468 } | 1468 } |
| 1469 } | 1469 } |
| 1470 | 1470 |
| 1471 TEST_P(CCLayerTreeHostImplTest, scrollScaledLayer) | 1471 TEST_P(LayerTreeHostImplTest, scrollScaledLayer) |
| 1472 { | 1472 { |
| 1473 setupScrollAndContentsLayers(IntSize(100, 100)); | 1473 setupScrollAndContentsLayers(IntSize(100, 100)); |
| 1474 | 1474 |
| 1475 // Scale the layer to twice its normal size. | 1475 // Scale the layer to twice its normal size. |
| 1476 int scale = 2; | 1476 int scale = 2; |
| 1477 WebTransformationMatrix scaleTransform; | 1477 WebTransformationMatrix scaleTransform; |
| 1478 scaleTransform.scale(scale); | 1478 scaleTransform.scale(scale); |
| 1479 m_hostImpl->rootLayer()->setTransform(scaleTransform); | 1479 m_hostImpl->rootLayer()->setTransform(scaleTransform); |
| 1480 | 1480 |
| 1481 IntSize surfaceSize(50, 50); | 1481 IntSize surfaceSize(50, 50); |
| 1482 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); | 1482 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); |
| 1483 initializeRendererAndDrawFrame(); | 1483 initializeRendererAndDrawFrame(); |
| 1484 | 1484 |
| 1485 // Scroll down in screen coordinates with a gesture. | 1485 // Scroll down in screen coordinates with a gesture. |
| 1486 IntSize scrollDelta(0, 10); | 1486 IntSize scrollDelta(0, 10); |
| 1487 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Gest
ure), CCInputHandlerClient::ScrollStarted); | 1487 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Gestur
e), InputHandlerClient::ScrollStarted); |
| 1488 m_hostImpl->scrollBy(IntPoint(), scrollDelta); | 1488 m_hostImpl->scrollBy(IntPoint(), scrollDelta); |
| 1489 m_hostImpl->scrollEnd(); | 1489 m_hostImpl->scrollEnd(); |
| 1490 | 1490 |
| 1491 // The layer should have scrolled down in its local coordinates, but half he
amount. | 1491 // The layer should have scrolled down in its local coordinates, but half he
amount. |
| 1492 scoped_ptr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas
(); | 1492 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas()
; |
| 1493 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), IntSize(0,
scrollDelta.height() / scale)); | 1493 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), IntSize(0,
scrollDelta.height() / scale)); |
| 1494 | 1494 |
| 1495 // Reset and scroll down with the wheel. | 1495 // Reset and scroll down with the wheel. |
| 1496 m_hostImpl->rootLayer()->setScrollDelta(FloatSize()); | 1496 m_hostImpl->rootLayer()->setScrollDelta(FloatSize()); |
| 1497 IntSize wheelScrollDelta(0, 10); | 1497 IntSize wheelScrollDelta(0, 10); |
| 1498 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Whee
l), CCInputHandlerClient::ScrollStarted); | 1498 EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), InputHandlerClient::Wheel)
, InputHandlerClient::ScrollStarted); |
| 1499 m_hostImpl->scrollBy(IntPoint(), wheelScrollDelta); | 1499 m_hostImpl->scrollBy(IntPoint(), wheelScrollDelta); |
| 1500 m_hostImpl->scrollEnd(); | 1500 m_hostImpl->scrollEnd(); |
| 1501 | 1501 |
| 1502 // The scale should not have been applied to the scroll delta. | 1502 // The scale should not have been applied to the scroll delta. |
| 1503 scrollInfo = m_hostImpl->processScrollDeltas(); | 1503 scrollInfo = m_hostImpl->processScrollDeltas(); |
| 1504 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll
Delta); | 1504 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll
Delta); |
| 1505 } | 1505 } |
| 1506 | 1506 |
| 1507 class BlendStateTrackerContext: public FakeWebGraphicsContext3D { | 1507 class BlendStateTrackerContext: public FakeWebGraphicsContext3D { |
| 1508 public: | 1508 public: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1519 if (cap == GraphicsContext3D::BLEND) | 1519 if (cap == GraphicsContext3D::BLEND) |
| 1520 m_blend = false; | 1520 m_blend = false; |
| 1521 } | 1521 } |
| 1522 | 1522 |
| 1523 bool blend() const { return m_blend; } | 1523 bool blend() const { return m_blend; } |
| 1524 | 1524 |
| 1525 private: | 1525 private: |
| 1526 bool m_blend; | 1526 bool m_blend; |
| 1527 }; | 1527 }; |
| 1528 | 1528 |
| 1529 class BlendStateCheckLayer : public CCLayerImpl { | 1529 class BlendStateCheckLayer : public LayerImpl { |
| 1530 public: | 1530 public: |
| 1531 static scoped_ptr<CCLayerImpl> create(int id, CCResourceProvider* resourcePr
ovider) { return scoped_ptr<CCLayerImpl>(new BlendStateCheckLayer(id, resourcePr
ovider)); } | 1531 static scoped_ptr<LayerImpl> create(int id, ResourceProvider* resourceProvid
er) { return scoped_ptr<LayerImpl>(new BlendStateCheckLayer(id, resourceProvider
)); } |
| 1532 | 1532 |
| 1533 virtual void appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appendQuad
sData) OVERRIDE | 1533 virtual void appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsDat
a) OVERRIDE |
| 1534 { | 1534 { |
| 1535 m_quadsAppended = true; | 1535 m_quadsAppended = true; |
| 1536 | 1536 |
| 1537 IntRect opaqueRect; | 1537 IntRect opaqueRect; |
| 1538 if (contentsOpaque()) | 1538 if (contentsOpaque()) |
| 1539 opaqueRect = m_quadRect; | 1539 opaqueRect = m_quadRect; |
| 1540 else | 1540 else |
| 1541 opaqueRect = m_opaqueContentRect; | 1541 opaqueRect = m_opaqueContentRect; |
| 1542 | 1542 |
| 1543 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createS
haredQuadState()); | 1543 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSha
redQuadState()); |
| 1544 scoped_ptr<CCTileDrawQuad> testBlendingDrawQuad = CCTileDrawQuad::create
(sharedQuadState, m_quadRect, opaqueRect, m_resourceId, IntPoint(), IntSize(1, 1
), 0, false, false, false, false, false); | 1544 scoped_ptr<TileDrawQuad> testBlendingDrawQuad = TileDrawQuad::create(sha
redQuadState, m_quadRect, opaqueRect, m_resourceId, IntPoint(), IntSize(1, 1), 0
, false, false, false, false, false); |
| 1545 testBlendingDrawQuad->setQuadVisibleRect(m_quadVisibleRect); | 1545 testBlendingDrawQuad->setQuadVisibleRect(m_quadVisibleRect); |
| 1546 EXPECT_EQ(m_blend, testBlendingDrawQuad->needsBlending()); | 1546 EXPECT_EQ(m_blend, testBlendingDrawQuad->needsBlending()); |
| 1547 EXPECT_EQ(m_hasRenderSurface, !!renderSurface()); | 1547 EXPECT_EQ(m_hasRenderSurface, !!renderSurface()); |
| 1548 quadSink.append(testBlendingDrawQuad.PassAs<CCDrawQuad>(), appendQuadsDa
ta); | 1548 quadSink.append(testBlendingDrawQuad.PassAs<DrawQuad>(), appendQuadsData
); |
| 1549 } | 1549 } |
| 1550 | 1550 |
| 1551 void setExpectation(bool blend, bool hasRenderSurface) | 1551 void setExpectation(bool blend, bool hasRenderSurface) |
| 1552 { | 1552 { |
| 1553 m_blend = blend; | 1553 m_blend = blend; |
| 1554 m_hasRenderSurface = hasRenderSurface; | 1554 m_hasRenderSurface = hasRenderSurface; |
| 1555 m_quadsAppended = false; | 1555 m_quadsAppended = false; |
| 1556 } | 1556 } |
| 1557 | 1557 |
| 1558 bool quadsAppended() const { return m_quadsAppended; } | 1558 bool quadsAppended() const { return m_quadsAppended; } |
| 1559 | 1559 |
| 1560 void setQuadRect(const IntRect& rect) { m_quadRect = rect; } | 1560 void setQuadRect(const IntRect& rect) { m_quadRect = rect; } |
| 1561 void setQuadVisibleRect(const IntRect& rect) { m_quadVisibleRect = rect; } | 1561 void setQuadVisibleRect(const IntRect& rect) { m_quadVisibleRect = rect; } |
| 1562 void setOpaqueContentRect(const IntRect& rect) { m_opaqueContentRect = rect;
} | 1562 void setOpaqueContentRect(const IntRect& rect) { m_opaqueContentRect = rect;
} |
| 1563 | 1563 |
| 1564 private: | 1564 private: |
| 1565 explicit BlendStateCheckLayer(int id, CCResourceProvider* resourceProvider) | 1565 explicit BlendStateCheckLayer(int id, ResourceProvider* resourceProvider) |
| 1566 : CCLayerImpl(id) | 1566 : LayerImpl(id) |
| 1567 , m_blend(false) | 1567 , m_blend(false) |
| 1568 , m_hasRenderSurface(false) | 1568 , m_hasRenderSurface(false) |
| 1569 , m_quadsAppended(false) | 1569 , m_quadsAppended(false) |
| 1570 , m_quadRect(5, 5, 5, 5) | 1570 , m_quadRect(5, 5, 5, 5) |
| 1571 , m_quadVisibleRect(5, 5, 5, 5) | 1571 , m_quadVisibleRect(5, 5, 5, 5) |
| 1572 , m_resourceId(resourceProvider->createResource(CCRenderer::ContentPool,
IntSize(1, 1), GraphicsContext3D::RGBA, CCResourceProvider::TextureUsageAny)) | 1572 , m_resourceId(resourceProvider->createResource(Renderer::ContentPool, I
ntSize(1, 1), GraphicsContext3D::RGBA, ResourceProvider::TextureUsageAny)) |
| 1573 { | 1573 { |
| 1574 setAnchorPoint(FloatPoint(0, 0)); | 1574 setAnchorPoint(FloatPoint(0, 0)); |
| 1575 setBounds(IntSize(10, 10)); | 1575 setBounds(IntSize(10, 10)); |
| 1576 setContentBounds(IntSize(10, 10)); | 1576 setContentBounds(IntSize(10, 10)); |
| 1577 setDrawsContent(true); | 1577 setDrawsContent(true); |
| 1578 } | 1578 } |
| 1579 | 1579 |
| 1580 bool m_blend; | 1580 bool m_blend; |
| 1581 bool m_hasRenderSurface; | 1581 bool m_hasRenderSurface; |
| 1582 bool m_quadsAppended; | 1582 bool m_quadsAppended; |
| 1583 IntRect m_quadRect; | 1583 IntRect m_quadRect; |
| 1584 IntRect m_opaqueContentRect; | 1584 IntRect m_opaqueContentRect; |
| 1585 IntRect m_quadVisibleRect; | 1585 IntRect m_quadVisibleRect; |
| 1586 CCResourceProvider::ResourceId m_resourceId; | 1586 ResourceProvider::ResourceId m_resourceId; |
| 1587 }; | 1587 }; |
| 1588 | 1588 |
| 1589 TEST_P(CCLayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers) | 1589 TEST_P(LayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers) |
| 1590 { | 1590 { |
| 1591 { | 1591 { |
| 1592 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 1592 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 1593 root->setAnchorPoint(FloatPoint(0, 0)); | 1593 root->setAnchorPoint(FloatPoint(0, 0)); |
| 1594 root->setBounds(IntSize(10, 10)); | 1594 root->setBounds(IntSize(10, 10)); |
| 1595 root->setContentBounds(root->bounds()); | 1595 root->setContentBounds(root->bounds()); |
| 1596 root->setDrawsContent(false); | 1596 root->setDrawsContent(false); |
| 1597 m_hostImpl->setRootLayer(root.Pass()); | 1597 m_hostImpl->setRootLayer(root.Pass()); |
| 1598 } | 1598 } |
| 1599 CCLayerImpl* root = m_hostImpl->rootLayer(); | 1599 LayerImpl* root = m_hostImpl->rootLayer(); |
| 1600 | 1600 |
| 1601 root->addChild(BlendStateCheckLayer::create(2, m_hostImpl->resourceProvider(
))); | 1601 root->addChild(BlendStateCheckLayer::create(2, m_hostImpl->resourceProvider(
))); |
| 1602 BlendStateCheckLayer* layer1 = static_cast<BlendStateCheckLayer*>(root->chil
dren()[0]); | 1602 BlendStateCheckLayer* layer1 = static_cast<BlendStateCheckLayer*>(root->chil
dren()[0]); |
| 1603 layer1->setPosition(FloatPoint(2, 2)); | 1603 layer1->setPosition(FloatPoint(2, 2)); |
| 1604 | 1604 |
| 1605 CCLayerTreeHostImpl::FrameData frame; | 1605 LayerTreeHostImpl::FrameData frame; |
| 1606 | 1606 |
| 1607 // Opaque layer, drawn without blending. | 1607 // Opaque layer, drawn without blending. |
| 1608 layer1->setContentsOpaque(true); | 1608 layer1->setContentsOpaque(true); |
| 1609 layer1->setExpectation(false, false); | 1609 layer1->setExpectation(false, false); |
| 1610 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 1610 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1611 m_hostImpl->drawLayers(frame); | 1611 m_hostImpl->drawLayers(frame); |
| 1612 EXPECT_TRUE(layer1->quadsAppended()); | 1612 EXPECT_TRUE(layer1->quadsAppended()); |
| 1613 m_hostImpl->didDrawAllLayers(frame); | 1613 m_hostImpl->didDrawAllLayers(frame); |
| 1614 | 1614 |
| 1615 // Layer with translucent content and painting, so drawn with blending. | 1615 // Layer with translucent content and painting, so drawn with blending. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 layer1->setQuadVisibleRect(IntRect(5, 5, 2, 5)); | 1771 layer1->setQuadVisibleRect(IntRect(5, 5, 2, 5)); |
| 1772 layer1->setOpaqueContentRect(IntRect(5, 5, 2, 5)); | 1772 layer1->setOpaqueContentRect(IntRect(5, 5, 2, 5)); |
| 1773 layer1->setExpectation(false, false); | 1773 layer1->setExpectation(false, false); |
| 1774 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 1774 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1775 m_hostImpl->drawLayers(frame); | 1775 m_hostImpl->drawLayers(frame); |
| 1776 EXPECT_TRUE(layer1->quadsAppended()); | 1776 EXPECT_TRUE(layer1->quadsAppended()); |
| 1777 m_hostImpl->didDrawAllLayers(frame); | 1777 m_hostImpl->didDrawAllLayers(frame); |
| 1778 | 1778 |
| 1779 } | 1779 } |
| 1780 | 1780 |
| 1781 TEST_P(CCLayerTreeHostImplTest, viewportCovered) | 1781 TEST_P(LayerTreeHostImplTest, viewportCovered) |
| 1782 { | 1782 { |
| 1783 m_hostImpl->initializeRenderer(createContext()); | 1783 m_hostImpl->initializeRenderer(createContext()); |
| 1784 m_hostImpl->setBackgroundColor(SK_ColorGRAY); | 1784 m_hostImpl->setBackgroundColor(SK_ColorGRAY); |
| 1785 | 1785 |
| 1786 IntSize viewportSize(1000, 1000); | 1786 IntSize viewportSize(1000, 1000); |
| 1787 m_hostImpl->setViewportSize(viewportSize, viewportSize); | 1787 m_hostImpl->setViewportSize(viewportSize, viewportSize); |
| 1788 | 1788 |
| 1789 m_hostImpl->setRootLayer(BlendStateCheckLayer::create(1, m_hostImpl->resourc
eProvider())); | 1789 m_hostImpl->setRootLayer(BlendStateCheckLayer::create(1, m_hostImpl->resourc
eProvider())); |
| 1790 BlendStateCheckLayer* root = static_cast<BlendStateCheckLayer*>(m_hostImpl->
rootLayer()); | 1790 BlendStateCheckLayer* root = static_cast<BlendStateCheckLayer*>(m_hostImpl->
rootLayer()); |
| 1791 root->setExpectation(false, true); | 1791 root->setExpectation(false, true); |
| 1792 root->setContentsOpaque(true); | 1792 root->setContentsOpaque(true); |
| 1793 | 1793 |
| 1794 // No gutter rects | 1794 // No gutter rects |
| 1795 { | 1795 { |
| 1796 IntRect layerRect(0, 0, 1000, 1000); | 1796 IntRect layerRect(0, 0, 1000, 1000); |
| 1797 root->setPosition(layerRect.location()); | 1797 root->setPosition(layerRect.location()); |
| 1798 root->setBounds(layerRect.size()); | 1798 root->setBounds(layerRect.size()); |
| 1799 root->setContentBounds(layerRect.size()); | 1799 root->setContentBounds(layerRect.size()); |
| 1800 root->setQuadRect(IntRect(IntPoint(), layerRect.size())); | 1800 root->setQuadRect(IntRect(IntPoint(), layerRect.size())); |
| 1801 root->setQuadVisibleRect(IntRect(IntPoint(), layerRect.size())); | 1801 root->setQuadVisibleRect(IntRect(IntPoint(), layerRect.size())); |
| 1802 | 1802 |
| 1803 CCLayerTreeHostImpl::FrameData frame; | 1803 LayerTreeHostImpl::FrameData frame; |
| 1804 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 1804 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1805 ASSERT_EQ(1u, frame.renderPasses.size()); | 1805 ASSERT_EQ(1u, frame.renderPasses.size()); |
| 1806 | 1806 |
| 1807 size_t numGutterQuads = 0; | 1807 size_t numGutterQuads = 0; |
| 1808 for (size_t i = 0; i < frame.renderPasses[0]->quadList().size(); ++i) | 1808 for (size_t i = 0; i < frame.renderPasses[0]->quadList().size(); ++i) |
| 1809 numGutterQuads += (frame.renderPasses[0]->quadList()[i]->material()
== CCDrawQuad::SolidColor) ? 1 : 0; | 1809 numGutterQuads += (frame.renderPasses[0]->quadList()[i]->material()
== DrawQuad::SolidColor) ? 1 : 0; |
| 1810 EXPECT_EQ(0u, numGutterQuads); | 1810 EXPECT_EQ(0u, numGutterQuads); |
| 1811 EXPECT_EQ(1u, frame.renderPasses[0]->quadList().size()); | 1811 EXPECT_EQ(1u, frame.renderPasses[0]->quadList().size()); |
| 1812 | 1812 |
| 1813 verifyQuadsExactlyCoverRect(frame.renderPasses[0]->quadList(), IntRect(-
layerRect.location(), viewportSize)); | 1813 verifyQuadsExactlyCoverRect(frame.renderPasses[0]->quadList(), IntRect(-
layerRect.location(), viewportSize)); |
| 1814 m_hostImpl->didDrawAllLayers(frame); | 1814 m_hostImpl->didDrawAllLayers(frame); |
| 1815 } | 1815 } |
| 1816 | 1816 |
| 1817 // Empty visible content area (fullscreen gutter rect) | 1817 // Empty visible content area (fullscreen gutter rect) |
| 1818 { | 1818 { |
| 1819 IntRect layerRect(0, 0, 0, 0); | 1819 IntRect layerRect(0, 0, 0, 0); |
| 1820 root->setPosition(layerRect.location()); | 1820 root->setPosition(layerRect.location()); |
| 1821 root->setBounds(layerRect.size()); | 1821 root->setBounds(layerRect.size()); |
| 1822 root->setContentBounds(layerRect.size()); | 1822 root->setContentBounds(layerRect.size()); |
| 1823 root->setQuadRect(IntRect(IntPoint(), layerRect.size())); | 1823 root->setQuadRect(IntRect(IntPoint(), layerRect.size())); |
| 1824 root->setQuadVisibleRect(IntRect(IntPoint(), layerRect.size())); | 1824 root->setQuadVisibleRect(IntRect(IntPoint(), layerRect.size())); |
| 1825 | 1825 |
| 1826 CCLayerTreeHostImpl::FrameData frame; | 1826 LayerTreeHostImpl::FrameData frame; |
| 1827 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 1827 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1828 ASSERT_EQ(1u, frame.renderPasses.size()); | 1828 ASSERT_EQ(1u, frame.renderPasses.size()); |
| 1829 m_hostImpl->didDrawAllLayers(frame); | 1829 m_hostImpl->didDrawAllLayers(frame); |
| 1830 | 1830 |
| 1831 size_t numGutterQuads = 0; | 1831 size_t numGutterQuads = 0; |
| 1832 for (size_t i = 0; i < frame.renderPasses[0]->quadList().size(); ++i) | 1832 for (size_t i = 0; i < frame.renderPasses[0]->quadList().size(); ++i) |
| 1833 numGutterQuads += (frame.renderPasses[0]->quadList()[i]->material()
== CCDrawQuad::SolidColor) ? 1 : 0; | 1833 numGutterQuads += (frame.renderPasses[0]->quadList()[i]->material()
== DrawQuad::SolidColor) ? 1 : 0; |
| 1834 EXPECT_EQ(1u, numGutterQuads); | 1834 EXPECT_EQ(1u, numGutterQuads); |
| 1835 EXPECT_EQ(1u, frame.renderPasses[0]->quadList().size()); | 1835 EXPECT_EQ(1u, frame.renderPasses[0]->quadList().size()); |
| 1836 | 1836 |
| 1837 verifyQuadsExactlyCoverRect(frame.renderPasses[0]->quadList(), IntRect(-
layerRect.location(), viewportSize)); | 1837 verifyQuadsExactlyCoverRect(frame.renderPasses[0]->quadList(), IntRect(-
layerRect.location(), viewportSize)); |
| 1838 m_hostImpl->didDrawAllLayers(frame); | 1838 m_hostImpl->didDrawAllLayers(frame); |
| 1839 } | 1839 } |
| 1840 | 1840 |
| 1841 // Content area in middle of clip rect (four surrounding gutter rects) | 1841 // Content area in middle of clip rect (four surrounding gutter rects) |
| 1842 { | 1842 { |
| 1843 IntRect layerRect(500, 500, 200, 200); | 1843 IntRect layerRect(500, 500, 200, 200); |
| 1844 root->setPosition(layerRect.location()); | 1844 root->setPosition(layerRect.location()); |
| 1845 root->setBounds(layerRect.size()); | 1845 root->setBounds(layerRect.size()); |
| 1846 root->setContentBounds(layerRect.size()); | 1846 root->setContentBounds(layerRect.size()); |
| 1847 root->setQuadRect(IntRect(IntPoint(), layerRect.size())); | 1847 root->setQuadRect(IntRect(IntPoint(), layerRect.size())); |
| 1848 root->setQuadVisibleRect(IntRect(IntPoint(), layerRect.size())); | 1848 root->setQuadVisibleRect(IntRect(IntPoint(), layerRect.size())); |
| 1849 | 1849 |
| 1850 CCLayerTreeHostImpl::FrameData frame; | 1850 LayerTreeHostImpl::FrameData frame; |
| 1851 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 1851 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1852 ASSERT_EQ(1u, frame.renderPasses.size()); | 1852 ASSERT_EQ(1u, frame.renderPasses.size()); |
| 1853 | 1853 |
| 1854 size_t numGutterQuads = 0; | 1854 size_t numGutterQuads = 0; |
| 1855 for (size_t i = 0; i < frame.renderPasses[0]->quadList().size(); ++i) | 1855 for (size_t i = 0; i < frame.renderPasses[0]->quadList().size(); ++i) |
| 1856 numGutterQuads += (frame.renderPasses[0]->quadList()[i]->material()
== CCDrawQuad::SolidColor) ? 1 : 0; | 1856 numGutterQuads += (frame.renderPasses[0]->quadList()[i]->material()
== DrawQuad::SolidColor) ? 1 : 0; |
| 1857 EXPECT_EQ(4u, numGutterQuads); | 1857 EXPECT_EQ(4u, numGutterQuads); |
| 1858 EXPECT_EQ(5u, frame.renderPasses[0]->quadList().size()); | 1858 EXPECT_EQ(5u, frame.renderPasses[0]->quadList().size()); |
| 1859 | 1859 |
| 1860 verifyQuadsExactlyCoverRect(frame.renderPasses[0]->quadList(), IntRect(-
layerRect.location(), viewportSize)); | 1860 verifyQuadsExactlyCoverRect(frame.renderPasses[0]->quadList(), IntRect(-
layerRect.location(), viewportSize)); |
| 1861 m_hostImpl->didDrawAllLayers(frame); | 1861 m_hostImpl->didDrawAllLayers(frame); |
| 1862 } | 1862 } |
| 1863 | 1863 |
| 1864 } | 1864 } |
| 1865 | 1865 |
| 1866 | 1866 |
| 1867 class ReshapeTrackerContext: public FakeWebGraphicsContext3D { | 1867 class ReshapeTrackerContext: public FakeWebGraphicsContext3D { |
| 1868 public: | 1868 public: |
| 1869 ReshapeTrackerContext() : m_reshapeCalled(false) { } | 1869 ReshapeTrackerContext() : m_reshapeCalled(false) { } |
| 1870 | 1870 |
| 1871 virtual void reshape(int width, int height) | 1871 virtual void reshape(int width, int height) |
| 1872 { | 1872 { |
| 1873 m_reshapeCalled = true; | 1873 m_reshapeCalled = true; |
| 1874 } | 1874 } |
| 1875 | 1875 |
| 1876 bool reshapeCalled() const { return m_reshapeCalled; } | 1876 bool reshapeCalled() const { return m_reshapeCalled; } |
| 1877 | 1877 |
| 1878 private: | 1878 private: |
| 1879 bool m_reshapeCalled; | 1879 bool m_reshapeCalled; |
| 1880 }; | 1880 }; |
| 1881 | 1881 |
| 1882 class FakeDrawableCCLayerImpl: public CCLayerImpl { | 1882 class FakeDrawableLayerImpl: public LayerImpl { |
| 1883 public: | 1883 public: |
| 1884 static scoped_ptr<CCLayerImpl> create(int id) { return scoped_ptr<CCLayerImp
l>(new FakeDrawableCCLayerImpl(id)); } | 1884 static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(n
ew FakeDrawableLayerImpl(id)); } |
| 1885 protected: | 1885 protected: |
| 1886 explicit FakeDrawableCCLayerImpl(int id) : CCLayerImpl(id) { } | 1886 explicit FakeDrawableLayerImpl(int id) : LayerImpl(id) { } |
| 1887 }; | 1887 }; |
| 1888 | 1888 |
| 1889 // Only reshape when we know we are going to draw. Otherwise, the reshape | 1889 // Only reshape when we know we are going to draw. Otherwise, the reshape |
| 1890 // can leave the window at the wrong size if we never draw and the proper | 1890 // can leave the window at the wrong size if we never draw and the proper |
| 1891 // viewport size is never set. | 1891 // viewport size is never set. |
| 1892 TEST_P(CCLayerTreeHostImplTest, reshapeNotCalledUntilDraw) | 1892 TEST_P(LayerTreeHostImplTest, reshapeNotCalledUntilDraw) |
| 1893 { | 1893 { |
| 1894 scoped_ptr<CCGraphicsContext> ccContext = FakeWebCompositorOutputSurface::cr
eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new ReshapeTrackerContext)).PassAs
<CCGraphicsContext>(); | 1894 scoped_ptr<GraphicsContext> outputSurface = FakeWebCompositorOutputSurface::
create(scoped_ptr<WebKit::WebGraphicsContext3D>(new ReshapeTrackerContext)).Pass
As<GraphicsContext>(); |
| 1895 ReshapeTrackerContext* reshapeTracker = static_cast<ReshapeTrackerContext*>(
ccContext->context3D()); | 1895 ReshapeTrackerContext* reshapeTracker = static_cast<ReshapeTrackerContext*>(
outputSurface->context3D()); |
| 1896 m_hostImpl->initializeRenderer(ccContext.Pass()); | 1896 m_hostImpl->initializeRenderer(outputSurface.Pass()); |
| 1897 | 1897 |
| 1898 scoped_ptr<CCLayerImpl> root = FakeDrawableCCLayerImpl::create(1); | 1898 scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(1); |
| 1899 root->setAnchorPoint(FloatPoint(0, 0)); | 1899 root->setAnchorPoint(FloatPoint(0, 0)); |
| 1900 root->setBounds(IntSize(10, 10)); | 1900 root->setBounds(IntSize(10, 10)); |
| 1901 root->setDrawsContent(true); | 1901 root->setDrawsContent(true); |
| 1902 m_hostImpl->setRootLayer(root.Pass()); | 1902 m_hostImpl->setRootLayer(root.Pass()); |
| 1903 EXPECT_FALSE(reshapeTracker->reshapeCalled()); | 1903 EXPECT_FALSE(reshapeTracker->reshapeCalled()); |
| 1904 | 1904 |
| 1905 CCLayerTreeHostImpl::FrameData frame; | 1905 LayerTreeHostImpl::FrameData frame; |
| 1906 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 1906 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1907 m_hostImpl->drawLayers(frame); | 1907 m_hostImpl->drawLayers(frame); |
| 1908 EXPECT_TRUE(reshapeTracker->reshapeCalled()); | 1908 EXPECT_TRUE(reshapeTracker->reshapeCalled()); |
| 1909 m_hostImpl->didDrawAllLayers(frame); | 1909 m_hostImpl->didDrawAllLayers(frame); |
| 1910 } | 1910 } |
| 1911 | 1911 |
| 1912 class PartialSwapTrackerContext : public FakeWebGraphicsContext3D { | 1912 class PartialSwapTrackerContext : public FakeWebGraphicsContext3D { |
| 1913 public: | 1913 public: |
| 1914 virtual void postSubBufferCHROMIUM(int x, int y, int width, int height) | 1914 virtual void postSubBufferCHROMIUM(int x, int y, int width, int height) |
| 1915 { | 1915 { |
| 1916 m_partialSwapRect = IntRect(x, y, width, height); | 1916 m_partialSwapRect = IntRect(x, y, width, height); |
| 1917 } | 1917 } |
| 1918 | 1918 |
| 1919 virtual WebString getString(WGC3Denum name) | 1919 virtual WebString getString(WGC3Denum name) |
| 1920 { | 1920 { |
| 1921 if (name == GraphicsContext3D::EXTENSIONS) | 1921 if (name == GraphicsContext3D::EXTENSIONS) |
| 1922 return WebString("GL_CHROMIUM_post_sub_buffer GL_CHROMIUM_set_visibi
lity"); | 1922 return WebString("GL_CHROMIUM_post_sub_buffer GL_CHROMIUM_set_visibi
lity"); |
| 1923 | 1923 |
| 1924 return WebString(); | 1924 return WebString(); |
| 1925 } | 1925 } |
| 1926 | 1926 |
| 1927 IntRect partialSwapRect() const { return m_partialSwapRect; } | 1927 IntRect partialSwapRect() const { return m_partialSwapRect; } |
| 1928 | 1928 |
| 1929 private: | 1929 private: |
| 1930 IntRect m_partialSwapRect; | 1930 IntRect m_partialSwapRect; |
| 1931 }; | 1931 }; |
| 1932 | 1932 |
| 1933 // Make sure damage tracking propagates all the way to the graphics context, | 1933 // Make sure damage tracking propagates all the way to the graphics context, |
| 1934 // where it should request to swap only the subBuffer that is damaged. | 1934 // where it should request to swap only the subBuffer that is damaged. |
| 1935 TEST_P(CCLayerTreeHostImplTest, partialSwapReceivesDamageRect) | 1935 TEST_P(LayerTreeHostImplTest, partialSwapReceivesDamageRect) |
| 1936 { | 1936 { |
| 1937 scoped_ptr<CCGraphicsContext> ccContext = FakeWebCompositorOutputSurface::cr
eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapTrackerContext)).Pa
ssAs<CCGraphicsContext>(); | 1937 scoped_ptr<GraphicsContext> outputSurface = FakeWebCompositorOutputSurface::
create(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapTrackerContext)).
PassAs<GraphicsContext>(); |
| 1938 PartialSwapTrackerContext* partialSwapTracker = static_cast<PartialSwapTrack
erContext*>(ccContext->context3D()); | 1938 PartialSwapTrackerContext* partialSwapTracker = static_cast<PartialSwapTrack
erContext*>(outputSurface->context3D()); |
| 1939 | 1939 |
| 1940 // This test creates its own CCLayerTreeHostImpl, so | 1940 // This test creates its own LayerTreeHostImpl, so |
| 1941 // that we can force partial swap enabled. | 1941 // that we can force partial swap enabled. |
| 1942 CCLayerTreeSettings settings; | 1942 LayerTreeSettings settings; |
| 1943 CCSettings::setPartialSwapEnabled(true); | 1943 Settings::setPartialSwapEnabled(true); |
| 1944 scoped_ptr<CCLayerTreeHostImpl> layerTreeHostImpl = CCLayerTreeHostImpl::cre
ate(settings, this); | 1944 scoped_ptr<LayerTreeHostImpl> layerTreeHostImpl = LayerTreeHostImpl::create(
settings, this); |
| 1945 layerTreeHostImpl->initializeRenderer(ccContext.Pass()); | 1945 layerTreeHostImpl->initializeRenderer(outputSurface.Pass()); |
| 1946 layerTreeHostImpl->setViewportSize(IntSize(500, 500), IntSize(500, 500)); | 1946 layerTreeHostImpl->setViewportSize(IntSize(500, 500), IntSize(500, 500)); |
| 1947 | 1947 |
| 1948 scoped_ptr<CCLayerImpl> root = FakeDrawableCCLayerImpl::create(1); | 1948 scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(1); |
| 1949 scoped_ptr<CCLayerImpl> child = FakeDrawableCCLayerImpl::create(2); | 1949 scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::create(2); |
| 1950 child->setPosition(FloatPoint(12, 13)); | 1950 child->setPosition(FloatPoint(12, 13)); |
| 1951 child->setAnchorPoint(FloatPoint(0, 0)); | 1951 child->setAnchorPoint(FloatPoint(0, 0)); |
| 1952 child->setBounds(IntSize(14, 15)); | 1952 child->setBounds(IntSize(14, 15)); |
| 1953 child->setContentBounds(IntSize(14, 15)); | 1953 child->setContentBounds(IntSize(14, 15)); |
| 1954 child->setDrawsContent(true); | 1954 child->setDrawsContent(true); |
| 1955 root->setAnchorPoint(FloatPoint(0, 0)); | 1955 root->setAnchorPoint(FloatPoint(0, 0)); |
| 1956 root->setBounds(IntSize(500, 500)); | 1956 root->setBounds(IntSize(500, 500)); |
| 1957 root->setContentBounds(IntSize(500, 500)); | 1957 root->setContentBounds(IntSize(500, 500)); |
| 1958 root->setDrawsContent(true); | 1958 root->setDrawsContent(true); |
| 1959 root->addChild(child.Pass()); | 1959 root->addChild(child.Pass()); |
| 1960 layerTreeHostImpl->setRootLayer(root.Pass()); | 1960 layerTreeHostImpl->setRootLayer(root.Pass()); |
| 1961 | 1961 |
| 1962 CCLayerTreeHostImpl::FrameData frame; | 1962 LayerTreeHostImpl::FrameData frame; |
| 1963 | 1963 |
| 1964 // First frame, the entire screen should get swapped. | 1964 // First frame, the entire screen should get swapped. |
| 1965 EXPECT_TRUE(layerTreeHostImpl->prepareToDraw(frame)); | 1965 EXPECT_TRUE(layerTreeHostImpl->prepareToDraw(frame)); |
| 1966 layerTreeHostImpl->drawLayers(frame); | 1966 layerTreeHostImpl->drawLayers(frame); |
| 1967 layerTreeHostImpl->didDrawAllLayers(frame); | 1967 layerTreeHostImpl->didDrawAllLayers(frame); |
| 1968 layerTreeHostImpl->swapBuffers(); | 1968 layerTreeHostImpl->swapBuffers(); |
| 1969 IntRect actualSwapRect = partialSwapTracker->partialSwapRect(); | 1969 IntRect actualSwapRect = partialSwapTracker->partialSwapRect(); |
| 1970 IntRect expectedSwapRect = IntRect(IntPoint::zero(), IntSize(500, 500)); | 1970 IntRect expectedSwapRect = IntRect(IntPoint::zero(), IntSize(500, 500)); |
| 1971 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); | 1971 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); |
| 1972 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); | 1972 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1999 m_hostImpl->didDrawAllLayers(frame); | 1999 m_hostImpl->didDrawAllLayers(frame); |
| 2000 layerTreeHostImpl->swapBuffers(); | 2000 layerTreeHostImpl->swapBuffers(); |
| 2001 actualSwapRect = partialSwapTracker->partialSwapRect(); | 2001 actualSwapRect = partialSwapTracker->partialSwapRect(); |
| 2002 expectedSwapRect = IntRect(IntPoint::zero(), IntSize(10, 10)); | 2002 expectedSwapRect = IntRect(IntPoint::zero(), IntSize(10, 10)); |
| 2003 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); | 2003 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); |
| 2004 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); | 2004 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); |
| 2005 EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width()); | 2005 EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width()); |
| 2006 EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height()); | 2006 EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height()); |
| 2007 } | 2007 } |
| 2008 | 2008 |
| 2009 TEST_P(CCLayerTreeHostImplTest, rootLayerDoesntCreateExtraSurface) | 2009 TEST_P(LayerTreeHostImplTest, rootLayerDoesntCreateExtraSurface) |
| 2010 { | 2010 { |
| 2011 scoped_ptr<CCLayerImpl> root = FakeDrawableCCLayerImpl::create(1); | 2011 scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(1); |
| 2012 scoped_ptr<CCLayerImpl> child = FakeDrawableCCLayerImpl::create(2); | 2012 scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::create(2); |
| 2013 child->setAnchorPoint(FloatPoint(0, 0)); | 2013 child->setAnchorPoint(FloatPoint(0, 0)); |
| 2014 child->setBounds(IntSize(10, 10)); | 2014 child->setBounds(IntSize(10, 10)); |
| 2015 child->setContentBounds(IntSize(10, 10)); | 2015 child->setContentBounds(IntSize(10, 10)); |
| 2016 child->setDrawsContent(true); | 2016 child->setDrawsContent(true); |
| 2017 root->setAnchorPoint(FloatPoint(0, 0)); | 2017 root->setAnchorPoint(FloatPoint(0, 0)); |
| 2018 root->setBounds(IntSize(10, 10)); | 2018 root->setBounds(IntSize(10, 10)); |
| 2019 root->setContentBounds(IntSize(10, 10)); | 2019 root->setContentBounds(IntSize(10, 10)); |
| 2020 root->setDrawsContent(true); | 2020 root->setDrawsContent(true); |
| 2021 root->setOpacity(0.7f); | 2021 root->setOpacity(0.7f); |
| 2022 root->addChild(child.Pass()); | 2022 root->addChild(child.Pass()); |
| 2023 | 2023 |
| 2024 m_hostImpl->setRootLayer(root.Pass()); | 2024 m_hostImpl->setRootLayer(root.Pass()); |
| 2025 | 2025 |
| 2026 CCLayerTreeHostImpl::FrameData frame; | 2026 LayerTreeHostImpl::FrameData frame; |
| 2027 | 2027 |
| 2028 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 2028 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 2029 EXPECT_EQ(1u, frame.renderSurfaceLayerList->size()); | 2029 EXPECT_EQ(1u, frame.renderSurfaceLayerList->size()); |
| 2030 EXPECT_EQ(1u, frame.renderPasses.size()); | 2030 EXPECT_EQ(1u, frame.renderPasses.size()); |
| 2031 m_hostImpl->didDrawAllLayers(frame); | 2031 m_hostImpl->didDrawAllLayers(frame); |
| 2032 } | 2032 } |
| 2033 | 2033 |
| 2034 } // namespace | 2034 } // namespace |
| 2035 | 2035 |
| 2036 class FakeLayerWithQuads : public CCLayerImpl { | 2036 class FakeLayerWithQuads : public LayerImpl { |
| 2037 public: | 2037 public: |
| 2038 static scoped_ptr<CCLayerImpl> create(int id) { return scoped_ptr<CCLayerImp
l>(new FakeLayerWithQuads(id)); } | 2038 static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(n
ew FakeLayerWithQuads(id)); } |
| 2039 | 2039 |
| 2040 virtual void appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appendQuad
sData) OVERRIDE | 2040 virtual void appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsDat
a) OVERRIDE |
| 2041 { | 2041 { |
| 2042 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createS
haredQuadState()); | 2042 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSha
redQuadState()); |
| 2043 | 2043 |
| 2044 SkColor gray = SkColorSetRGB(100, 100, 100); | 2044 SkColor gray = SkColorSetRGB(100, 100, 100); |
| 2045 IntRect quadRect(IntPoint(0, 0), contentBounds()); | 2045 IntRect quadRect(IntPoint(0, 0), contentBounds()); |
| 2046 scoped_ptr<CCSolidColorDrawQuad> myQuad = CCSolidColorDrawQuad::create(s
haredQuadState, quadRect, gray); | 2046 scoped_ptr<SolidColorDrawQuad> myQuad = SolidColorDrawQuad::create(share
dQuadState, quadRect, gray); |
| 2047 quadSink.append(myQuad.PassAs<CCDrawQuad>(), appendQuadsData); | 2047 quadSink.append(myQuad.PassAs<DrawQuad>(), appendQuadsData); |
| 2048 } | 2048 } |
| 2049 | 2049 |
| 2050 private: | 2050 private: |
| 2051 FakeLayerWithQuads(int id) | 2051 FakeLayerWithQuads(int id) |
| 2052 : CCLayerImpl(id) | 2052 : LayerImpl(id) |
| 2053 { | 2053 { |
| 2054 } | 2054 } |
| 2055 }; | 2055 }; |
| 2056 | 2056 |
| 2057 namespace { | 2057 namespace { |
| 2058 | 2058 |
| 2059 class MockContext : public FakeWebGraphicsContext3D { | 2059 class MockContext : public FakeWebGraphicsContext3D { |
| 2060 public: | 2060 public: |
| 2061 MOCK_METHOD1(useProgram, void(WebGLId program)); | 2061 MOCK_METHOD1(useProgram, void(WebGLId program)); |
| 2062 MOCK_METHOD5(uniform4f, void(WGC3Dint location, WGC3Dfloat x, WGC3Dfloat y,
WGC3Dfloat z, WGC3Dfloat w)); | 2062 MOCK_METHOD5(uniform4f, void(WGC3Dint location, WGC3Dfloat x, WGC3Dfloat y,
WGC3Dfloat z, WGC3Dfloat w)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2139 .WillRepeatedly(Return()); | 2139 .WillRepeatedly(Return()); |
| 2140 | 2140 |
| 2141 EXPECT_CALL(*m_context, enable(GraphicsContext3D::SCISSOR_TEST)) | 2141 EXPECT_CALL(*m_context, enable(GraphicsContext3D::SCISSOR_TEST)) |
| 2142 .Times(0); | 2142 .Times(0); |
| 2143 | 2143 |
| 2144 EXPECT_CALL(*m_context, scissor(_, _, _, _)) | 2144 EXPECT_CALL(*m_context, scissor(_, _, _, _)) |
| 2145 .Times(0); | 2145 .Times(0); |
| 2146 } | 2146 } |
| 2147 }; | 2147 }; |
| 2148 | 2148 |
| 2149 TEST_P(CCLayerTreeHostImplTest, noPartialSwap) | 2149 TEST_P(LayerTreeHostImplTest, noPartialSwap) |
| 2150 { | 2150 { |
| 2151 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebGraphicsContext3D>(new MockContext)).PassAs<CCGraphicsContext>(
); | 2151 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebGraphicsContext3D>(new MockContext)).PassAs<GraphicsContext>(); |
| 2152 MockContext* mockContext = static_cast<MockContext*>(context->context3D()); | 2152 MockContext* mockContext = static_cast<MockContext*>(context->context3D()); |
| 2153 MockContextHarness harness(mockContext); | 2153 MockContextHarness harness(mockContext); |
| 2154 | 2154 |
| 2155 harness.mustDrawSolidQuad(); | 2155 harness.mustDrawSolidQuad(); |
| 2156 harness.mustSetScissor(0, 0, 10, 10); | 2156 harness.mustSetScissor(0, 0, 10, 10); |
| 2157 | 2157 |
| 2158 // Run test case | 2158 // Run test case |
| 2159 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = createLayerTreeHost(false, cont
ext.Pass(), FakeLayerWithQuads::create(1)); | 2159 scoped_ptr<LayerTreeHostImpl> myHostImpl = createLayerTreeHost(false, contex
t.Pass(), FakeLayerWithQuads::create(1)); |
| 2160 | 2160 |
| 2161 CCLayerTreeHostImpl::FrameData frame; | 2161 LayerTreeHostImpl::FrameData frame; |
| 2162 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 2162 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 2163 myHostImpl->drawLayers(frame); | 2163 myHostImpl->drawLayers(frame); |
| 2164 myHostImpl->didDrawAllLayers(frame); | 2164 myHostImpl->didDrawAllLayers(frame); |
| 2165 Mock::VerifyAndClearExpectations(&mockContext); | 2165 Mock::VerifyAndClearExpectations(&mockContext); |
| 2166 } | 2166 } |
| 2167 | 2167 |
| 2168 TEST_P(CCLayerTreeHostImplTest, partialSwap) | 2168 TEST_P(LayerTreeHostImplTest, partialSwap) |
| 2169 { | 2169 { |
| 2170 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<CCGraphicsC
ontext>(); | 2170 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<GraphicsConte
xt>(); |
| 2171 MockContext* mockContext = static_cast<MockContext*>(context->context3D()); | 2171 MockContext* mockContext = static_cast<MockContext*>(context->context3D()); |
| 2172 MockContextHarness harness(mockContext); | 2172 MockContextHarness harness(mockContext); |
| 2173 | 2173 |
| 2174 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = createLayerTreeHost(true, conte
xt.Pass(), FakeLayerWithQuads::create(1)); | 2174 scoped_ptr<LayerTreeHostImpl> myHostImpl = createLayerTreeHost(true, context
.Pass(), FakeLayerWithQuads::create(1)); |
| 2175 | 2175 |
| 2176 // The first frame is not a partially-swapped one. | 2176 // The first frame is not a partially-swapped one. |
| 2177 harness.mustSetScissor(0, 0, 10, 10); | 2177 harness.mustSetScissor(0, 0, 10, 10); |
| 2178 harness.mustDrawSolidQuad(); | 2178 harness.mustDrawSolidQuad(); |
| 2179 { | 2179 { |
| 2180 CCLayerTreeHostImpl::FrameData frame; | 2180 LayerTreeHostImpl::FrameData frame; |
| 2181 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 2181 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 2182 myHostImpl->drawLayers(frame); | 2182 myHostImpl->drawLayers(frame); |
| 2183 myHostImpl->didDrawAllLayers(frame); | 2183 myHostImpl->didDrawAllLayers(frame); |
| 2184 } | 2184 } |
| 2185 Mock::VerifyAndClearExpectations(&mockContext); | 2185 Mock::VerifyAndClearExpectations(&mockContext); |
| 2186 | 2186 |
| 2187 // Damage a portion of the frame. | 2187 // Damage a portion of the frame. |
| 2188 myHostImpl->rootLayer()->setUpdateRect(IntRect(0, 0, 2, 3)); | 2188 myHostImpl->rootLayer()->setUpdateRect(IntRect(0, 0, 2, 3)); |
| 2189 | 2189 |
| 2190 // The second frame will be partially-swapped (the y coordinates are flipped
). | 2190 // The second frame will be partially-swapped (the y coordinates are flipped
). |
| 2191 harness.mustSetScissor(0, 7, 2, 3); | 2191 harness.mustSetScissor(0, 7, 2, 3); |
| 2192 harness.mustDrawSolidQuad(); | 2192 harness.mustDrawSolidQuad(); |
| 2193 { | 2193 { |
| 2194 CCLayerTreeHostImpl::FrameData frame; | 2194 LayerTreeHostImpl::FrameData frame; |
| 2195 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 2195 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 2196 myHostImpl->drawLayers(frame); | 2196 myHostImpl->drawLayers(frame); |
| 2197 myHostImpl->didDrawAllLayers(frame); | 2197 myHostImpl->didDrawAllLayers(frame); |
| 2198 } | 2198 } |
| 2199 Mock::VerifyAndClearExpectations(&mockContext); | 2199 Mock::VerifyAndClearExpectations(&mockContext); |
| 2200 } | 2200 } |
| 2201 | 2201 |
| 2202 class PartialSwapContext : public FakeWebGraphicsContext3D { | 2202 class PartialSwapContext : public FakeWebGraphicsContext3D { |
| 2203 public: | 2203 public: |
| 2204 WebString getString(WGC3Denum name) | 2204 WebString getString(WGC3Denum name) |
| 2205 { | 2205 { |
| 2206 if (name == GraphicsContext3D::EXTENSIONS) | 2206 if (name == GraphicsContext3D::EXTENSIONS) |
| 2207 return WebString("GL_CHROMIUM_post_sub_buffer"); | 2207 return WebString("GL_CHROMIUM_post_sub_buffer"); |
| 2208 return WebString(); | 2208 return WebString(); |
| 2209 } | 2209 } |
| 2210 | 2210 |
| 2211 WebString getRequestableExtensionsCHROMIUM() | 2211 WebString getRequestableExtensionsCHROMIUM() |
| 2212 { | 2212 { |
| 2213 return WebString("GL_CHROMIUM_post_sub_buffer"); | 2213 return WebString("GL_CHROMIUM_post_sub_buffer"); |
| 2214 } | 2214 } |
| 2215 | 2215 |
| 2216 // Unlimited texture size. | 2216 // Unlimited texture size. |
| 2217 virtual void getIntegerv(WGC3Denum pname, WGC3Dint* value) | 2217 virtual void getIntegerv(WGC3Denum pname, WGC3Dint* value) |
| 2218 { | 2218 { |
| 2219 if (pname == cc::GraphicsContext3D::MAX_TEXTURE_SIZE) | 2219 if (pname == cc::GraphicsContext3D::MAX_TEXTURE_SIZE) |
| 2220 *value = 8192; | 2220 *value = 8192; |
| 2221 } | 2221 } |
| 2222 }; | 2222 }; |
| 2223 | 2223 |
| 2224 static scoped_ptr<CCLayerTreeHostImpl> setupLayersForOpacity(bool partialSwap, C
CLayerTreeHostImplClient* client) | 2224 static scoped_ptr<LayerTreeHostImpl> setupLayersForOpacity(bool partialSwap, Lay
erTreeHostImplClient* client) |
| 2225 { | 2225 { |
| 2226 CCSettings::setPartialSwapEnabled(partialSwap); | 2226 Settings::setPartialSwapEnabled(partialSwap); |
| 2227 | 2227 |
| 2228 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<CCGr
aphicsContext>(); | 2228 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<Graphi
csContext>(); |
| 2229 | 2229 |
| 2230 CCLayerTreeSettings settings; | 2230 LayerTreeSettings settings; |
| 2231 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, client); | 2231 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, client); |
| 2232 myHostImpl->initializeRenderer(context.Pass()); | 2232 myHostImpl->initializeRenderer(context.Pass()); |
| 2233 myHostImpl->setViewportSize(IntSize(100, 100), IntSize(100, 100)); | 2233 myHostImpl->setViewportSize(IntSize(100, 100), IntSize(100, 100)); |
| 2234 | 2234 |
| 2235 /* | 2235 /* |
| 2236 Layers are created as follows: | 2236 Layers are created as follows: |
| 2237 | 2237 |
| 2238 +--------------------+ | 2238 +--------------------+ |
| 2239 | 1 | | 2239 | 1 | |
| 2240 | +-----------+ | | 2240 | +-----------+ | |
| 2241 | | 2 | | | 2241 | | 2 | | |
| 2242 | | +-------------------+ | 2242 | | +-------------------+ |
| 2243 | | | 3 | | 2243 | | | 3 | |
| 2244 | | +-------------------+ | 2244 | | +-------------------+ |
| 2245 | | | | | 2245 | | | | |
| 2246 | +-----------+ | | 2246 | +-----------+ | |
| 2247 | | | 2247 | | |
| 2248 | | | 2248 | | |
| 2249 +--------------------+ | 2249 +--------------------+ |
| 2250 | 2250 |
| 2251 Layers 1, 2 have render surfaces | 2251 Layers 1, 2 have render surfaces |
| 2252 */ | 2252 */ |
| 2253 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 2253 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 2254 scoped_ptr<CCLayerImpl> child = CCLayerImpl::create(2); | 2254 scoped_ptr<LayerImpl> child = LayerImpl::create(2); |
| 2255 scoped_ptr<CCLayerImpl> grandChild = FakeLayerWithQuads::create(3); | 2255 scoped_ptr<LayerImpl> grandChild = FakeLayerWithQuads::create(3); |
| 2256 | 2256 |
| 2257 IntRect rootRect(0, 0, 100, 100); | 2257 IntRect rootRect(0, 0, 100, 100); |
| 2258 IntRect childRect(10, 10, 50, 50); | 2258 IntRect childRect(10, 10, 50, 50); |
| 2259 IntRect grandChildRect(5, 5, 150, 150); | 2259 IntRect grandChildRect(5, 5, 150, 150); |
| 2260 | 2260 |
| 2261 root->createRenderSurface(); | 2261 root->createRenderSurface(); |
| 2262 root->setAnchorPoint(FloatPoint(0, 0)); | 2262 root->setAnchorPoint(FloatPoint(0, 0)); |
| 2263 root->setPosition(FloatPoint(rootRect.x(), rootRect.y())); | 2263 root->setPosition(FloatPoint(rootRect.x(), rootRect.y())); |
| 2264 root->setBounds(IntSize(rootRect.width(), rootRect.height())); | 2264 root->setBounds(IntSize(rootRect.width(), rootRect.height())); |
| 2265 root->setContentBounds(root->bounds()); | 2265 root->setContentBounds(root->bounds()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2282 grandChild->setVisibleContentRect(grandChildRect); | 2282 grandChild->setVisibleContentRect(grandChildRect); |
| 2283 grandChild->setDrawsContent(true); | 2283 grandChild->setDrawsContent(true); |
| 2284 | 2284 |
| 2285 child->addChild(grandChild.Pass()); | 2285 child->addChild(grandChild.Pass()); |
| 2286 root->addChild(child.Pass()); | 2286 root->addChild(child.Pass()); |
| 2287 | 2287 |
| 2288 myHostImpl->setRootLayer(root.Pass()); | 2288 myHostImpl->setRootLayer(root.Pass()); |
| 2289 return myHostImpl.Pass(); | 2289 return myHostImpl.Pass(); |
| 2290 } | 2290 } |
| 2291 | 2291 |
| 2292 TEST_P(CCLayerTreeHostImplTest, contributingLayerEmptyScissorPartialSwap) | 2292 TEST_P(LayerTreeHostImplTest, contributingLayerEmptyScissorPartialSwap) |
| 2293 { | 2293 { |
| 2294 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = setupLayersForOpacity(true, thi
s); | 2294 scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(true, this)
; |
| 2295 | 2295 |
| 2296 { | 2296 { |
| 2297 CCLayerTreeHostImpl::FrameData frame; | 2297 LayerTreeHostImpl::FrameData frame; |
| 2298 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 2298 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 2299 | 2299 |
| 2300 // Just for consistency, the most interesting stuff already happened | 2300 // Just for consistency, the most interesting stuff already happened |
| 2301 myHostImpl->drawLayers(frame); | 2301 myHostImpl->drawLayers(frame); |
| 2302 myHostImpl->didDrawAllLayers(frame); | 2302 myHostImpl->didDrawAllLayers(frame); |
| 2303 | 2303 |
| 2304 // Verify all quads have been computed | 2304 // Verify all quads have been computed |
| 2305 ASSERT_EQ(2U, frame.renderPasses.size()); | 2305 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 2306 ASSERT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 2306 ASSERT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 2307 ASSERT_EQ(1U, frame.renderPasses[1]->quadList().size()); | 2307 ASSERT_EQ(1U, frame.renderPasses[1]->quadList().size()); |
| 2308 EXPECT_EQ(CCDrawQuad::SolidColor, frame.renderPasses[0]->quadList()[0]->
material()); | 2308 EXPECT_EQ(DrawQuad::SolidColor, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 2309 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->
material()); | 2309 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->ma
terial()); |
| 2310 } | 2310 } |
| 2311 } | 2311 } |
| 2312 | 2312 |
| 2313 TEST_P(CCLayerTreeHostImplTest, contributingLayerEmptyScissorNoPartialSwap) | 2313 TEST_P(LayerTreeHostImplTest, contributingLayerEmptyScissorNoPartialSwap) |
| 2314 { | 2314 { |
| 2315 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = setupLayersForOpacity(false, th
is); | 2315 scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(false, this
); |
| 2316 | 2316 |
| 2317 { | 2317 { |
| 2318 CCLayerTreeHostImpl::FrameData frame; | 2318 LayerTreeHostImpl::FrameData frame; |
| 2319 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 2319 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 2320 | 2320 |
| 2321 // Just for consistency, the most interesting stuff already happened | 2321 // Just for consistency, the most interesting stuff already happened |
| 2322 myHostImpl->drawLayers(frame); | 2322 myHostImpl->drawLayers(frame); |
| 2323 myHostImpl->didDrawAllLayers(frame); | 2323 myHostImpl->didDrawAllLayers(frame); |
| 2324 | 2324 |
| 2325 // Verify all quads have been computed | 2325 // Verify all quads have been computed |
| 2326 ASSERT_EQ(2U, frame.renderPasses.size()); | 2326 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 2327 ASSERT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 2327 ASSERT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 2328 ASSERT_EQ(1U, frame.renderPasses[1]->quadList().size()); | 2328 ASSERT_EQ(1U, frame.renderPasses[1]->quadList().size()); |
| 2329 EXPECT_EQ(CCDrawQuad::SolidColor, frame.renderPasses[0]->quadList()[0]->
material()); | 2329 EXPECT_EQ(DrawQuad::SolidColor, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 2330 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->
material()); | 2330 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->ma
terial()); |
| 2331 } | 2331 } |
| 2332 } | 2332 } |
| 2333 | 2333 |
| 2334 // Make sure that context lost notifications are propagated through the tree. | 2334 // Make sure that context lost notifications are propagated through the tree. |
| 2335 class ContextLostNotificationCheckLayer : public CCLayerImpl { | 2335 class ContextLostNotificationCheckLayer : public LayerImpl { |
| 2336 public: | 2336 public: |
| 2337 static scoped_ptr<CCLayerImpl> create(int id) { return scoped_ptr<CCLayerImp
l>(new ContextLostNotificationCheckLayer(id)); } | 2337 static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(n
ew ContextLostNotificationCheckLayer(id)); } |
| 2338 | 2338 |
| 2339 virtual void didLoseContext() OVERRIDE | 2339 virtual void didLoseContext() OVERRIDE |
| 2340 { | 2340 { |
| 2341 m_didLoseContextCalled = true; | 2341 m_didLoseContextCalled = true; |
| 2342 } | 2342 } |
| 2343 | 2343 |
| 2344 bool didLoseContextCalled() const { return m_didLoseContextCalled; } | 2344 bool didLoseContextCalled() const { return m_didLoseContextCalled; } |
| 2345 | 2345 |
| 2346 private: | 2346 private: |
| 2347 explicit ContextLostNotificationCheckLayer(int id) | 2347 explicit ContextLostNotificationCheckLayer(int id) |
| 2348 : CCLayerImpl(id) | 2348 : LayerImpl(id) |
| 2349 , m_didLoseContextCalled(false) | 2349 , m_didLoseContextCalled(false) |
| 2350 { | 2350 { |
| 2351 } | 2351 } |
| 2352 | 2352 |
| 2353 bool m_didLoseContextCalled; | 2353 bool m_didLoseContextCalled; |
| 2354 }; | 2354 }; |
| 2355 | 2355 |
| 2356 TEST_P(CCLayerTreeHostImplTest, contextLostAndRestoredNotificationSentToAllLayer
s) | 2356 TEST_P(LayerTreeHostImplTest, contextLostAndRestoredNotificationSentToAllLayers) |
| 2357 { | 2357 { |
| 2358 m_hostImpl->setRootLayer(ContextLostNotificationCheckLayer::create(1)); | 2358 m_hostImpl->setRootLayer(ContextLostNotificationCheckLayer::create(1)); |
| 2359 ContextLostNotificationCheckLayer* root = static_cast<ContextLostNotificatio
nCheckLayer*>(m_hostImpl->rootLayer()); | 2359 ContextLostNotificationCheckLayer* root = static_cast<ContextLostNotificatio
nCheckLayer*>(m_hostImpl->rootLayer()); |
| 2360 | 2360 |
| 2361 root->addChild(ContextLostNotificationCheckLayer::create(1)); | 2361 root->addChild(ContextLostNotificationCheckLayer::create(1)); |
| 2362 ContextLostNotificationCheckLayer* layer1 = static_cast<ContextLostNotificat
ionCheckLayer*>(root->children()[0]); | 2362 ContextLostNotificationCheckLayer* layer1 = static_cast<ContextLostNotificat
ionCheckLayer*>(root->children()[0]); |
| 2363 | 2363 |
| 2364 layer1->addChild(ContextLostNotificationCheckLayer::create(2)); | 2364 layer1->addChild(ContextLostNotificationCheckLayer::create(2)); |
| 2365 ContextLostNotificationCheckLayer* layer2 = static_cast<ContextLostNotificat
ionCheckLayer*>(layer1->children()[0]); | 2365 ContextLostNotificationCheckLayer* layer2 = static_cast<ContextLostNotificat
ionCheckLayer*>(layer1->children()[0]); |
| 2366 | 2366 |
| 2367 EXPECT_FALSE(root->didLoseContextCalled()); | 2367 EXPECT_FALSE(root->didLoseContextCalled()); |
| 2368 EXPECT_FALSE(layer1->didLoseContextCalled()); | 2368 EXPECT_FALSE(layer1->didLoseContextCalled()); |
| 2369 EXPECT_FALSE(layer2->didLoseContextCalled()); | 2369 EXPECT_FALSE(layer2->didLoseContextCalled()); |
| 2370 | 2370 |
| 2371 m_hostImpl->initializeRenderer(createContext()); | 2371 m_hostImpl->initializeRenderer(createContext()); |
| 2372 | 2372 |
| 2373 EXPECT_TRUE(root->didLoseContextCalled()); | 2373 EXPECT_TRUE(root->didLoseContextCalled()); |
| 2374 EXPECT_TRUE(layer1->didLoseContextCalled()); | 2374 EXPECT_TRUE(layer1->didLoseContextCalled()); |
| 2375 EXPECT_TRUE(layer2->didLoseContextCalled()); | 2375 EXPECT_TRUE(layer2->didLoseContextCalled()); |
| 2376 } | 2376 } |
| 2377 | 2377 |
| 2378 TEST_P(CCLayerTreeHostImplTest, finishAllRenderingAfterContextLost) | 2378 TEST_P(LayerTreeHostImplTest, finishAllRenderingAfterContextLost) |
| 2379 { | 2379 { |
| 2380 CCLayerTreeSettings settings; | 2380 LayerTreeSettings settings; |
| 2381 m_hostImpl = CCLayerTreeHostImpl::create(settings, this); | 2381 m_hostImpl = LayerTreeHostImpl::create(settings, this); |
| 2382 | 2382 |
| 2383 // The context initialization will fail, but we should still be able to call
finishAllRendering() without any ill effects. | 2383 // The context initialization will fail, but we should still be able to call
finishAllRendering() without any ill effects. |
| 2384 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrentFails)
).PassAs<CCGraphicsContext>()); | 2384 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrentFails)
).PassAs<GraphicsContext>()); |
| 2385 m_hostImpl->finishAllRendering(); | 2385 m_hostImpl->finishAllRendering(); |
| 2386 } | 2386 } |
| 2387 | 2387 |
| 2388 class FakeWebGraphicsContext3DMakeCurrentFailsEventually : public FakeWebGraphic
sContext3D { | 2388 class FakeWebGraphicsContext3DMakeCurrentFailsEventually : public FakeWebGraphic
sContext3D { |
| 2389 public: | 2389 public: |
| 2390 explicit FakeWebGraphicsContext3DMakeCurrentFailsEventually(unsigned succeed
Count) : m_succeedCount(succeedCount) { } | 2390 explicit FakeWebGraphicsContext3DMakeCurrentFailsEventually(unsigned succeed
Count) : m_succeedCount(succeedCount) { } |
| 2391 virtual bool makeContextCurrent() { | 2391 virtual bool makeContextCurrent() { |
| 2392 if (!m_succeedCount) | 2392 if (!m_succeedCount) |
| 2393 return false; | 2393 return false; |
| 2394 --m_succeedCount; | 2394 --m_succeedCount; |
| 2395 return true; | 2395 return true; |
| 2396 } | 2396 } |
| 2397 | 2397 |
| 2398 private: | 2398 private: |
| 2399 unsigned m_succeedCount; | 2399 unsigned m_succeedCount; |
| 2400 }; | 2400 }; |
| 2401 | 2401 |
| 2402 TEST_P(CCLayerTreeHostImplTest, contextLostDuringInitialize) | 2402 TEST_P(LayerTreeHostImplTest, contextLostDuringInitialize) |
| 2403 { | 2403 { |
| 2404 CCLayerTreeSettings settings; | 2404 LayerTreeSettings settings; |
| 2405 m_hostImpl = CCLayerTreeHostImpl::create(settings, this); | 2405 m_hostImpl = LayerTreeHostImpl::create(settings, this); |
| 2406 | 2406 |
| 2407 // Initialize into a known successful state. | 2407 // Initialize into a known successful state. |
| 2408 EXPECT_TRUE(m_hostImpl->initializeRenderer(createContext())); | 2408 EXPECT_TRUE(m_hostImpl->initializeRenderer(createContext())); |
| 2409 EXPECT_TRUE(m_hostImpl->context()); | 2409 EXPECT_TRUE(m_hostImpl->context()); |
| 2410 EXPECT_TRUE(m_hostImpl->renderer()); | 2410 EXPECT_TRUE(m_hostImpl->renderer()); |
| 2411 EXPECT_TRUE(m_hostImpl->resourceProvider()); | 2411 EXPECT_TRUE(m_hostImpl->resourceProvider()); |
| 2412 | 2412 |
| 2413 // We will make the context get lost after a numer of makeContextCurrent | 2413 // We will make the context get lost after a numer of makeContextCurrent |
| 2414 // calls. The exact number of calls to make it succeed is dependent on the | 2414 // calls. The exact number of calls to make it succeed is dependent on the |
| 2415 // implementation and doesn't really matter (i.e. can be changed to make the | 2415 // implementation and doesn't really matter (i.e. can be changed to make the |
| 2416 // tests pass after some refactoring). | 2416 // tests pass after some refactoring). |
| 2417 const unsigned kMakeCurrentSuccessesNeededForSuccessfulInitialization = 3; | 2417 const unsigned kMakeCurrentSuccessesNeededForSuccessfulInitialization = 3; |
| 2418 | 2418 |
| 2419 for (unsigned i = 0; i < kMakeCurrentSuccessesNeededForSuccessfulInitializat
ion; ++i) { | 2419 for (unsigned i = 0; i < kMakeCurrentSuccessesNeededForSuccessfulInitializat
ion; ++i) { |
| 2420 // The context will get lost during initialization, we shouldn't crash.
We | 2420 // The context will get lost during initialization, we shouldn't crash.
We |
| 2421 // should also be in a consistent state. | 2421 // should also be in a consistent state. |
| 2422 EXPECT_FALSE(m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurfa
ce::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3D
MakeCurrentFailsEventually(i))).PassAs<CCGraphicsContext>())); | 2422 EXPECT_FALSE(m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurfa
ce::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3D
MakeCurrentFailsEventually(i))).PassAs<GraphicsContext>())); |
| 2423 EXPECT_EQ(0, m_hostImpl->context()); | 2423 EXPECT_EQ(0, m_hostImpl->context()); |
| 2424 EXPECT_EQ(0, m_hostImpl->renderer()); | 2424 EXPECT_EQ(0, m_hostImpl->renderer()); |
| 2425 EXPECT_EQ(0, m_hostImpl->resourceProvider()); | 2425 EXPECT_EQ(0, m_hostImpl->resourceProvider()); |
| 2426 EXPECT_TRUE(m_hostImpl->initializeRenderer(createContext())); | 2426 EXPECT_TRUE(m_hostImpl->initializeRenderer(createContext())); |
| 2427 } | 2427 } |
| 2428 | 2428 |
| 2429 EXPECT_TRUE(m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::c
reate(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeC
urrentFailsEventually(kMakeCurrentSuccessesNeededForSuccessfulInitialization))).
PassAs<CCGraphicsContext>())); | 2429 EXPECT_TRUE(m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::c
reate(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeC
urrentFailsEventually(kMakeCurrentSuccessesNeededForSuccessfulInitialization))).
PassAs<GraphicsContext>())); |
| 2430 EXPECT_TRUE(m_hostImpl->context()); | 2430 EXPECT_TRUE(m_hostImpl->context()); |
| 2431 EXPECT_TRUE(m_hostImpl->renderer()); | 2431 EXPECT_TRUE(m_hostImpl->renderer()); |
| 2432 EXPECT_TRUE(m_hostImpl->resourceProvider()); | 2432 EXPECT_TRUE(m_hostImpl->resourceProvider()); |
| 2433 } | 2433 } |
| 2434 | 2434 |
| 2435 // Fake WebGraphicsContext3D that will cause a failure if trying to use a | 2435 // Fake WebGraphicsContext3D that will cause a failure if trying to use a |
| 2436 // resource that wasn't created by it (resources created by | 2436 // resource that wasn't created by it (resources created by |
| 2437 // FakeWebGraphicsContext3D have an id of 1). | 2437 // FakeWebGraphicsContext3D have an id of 1). |
| 2438 class StrictWebGraphicsContext3D : public FakeWebGraphicsContext3D { | 2438 class StrictWebGraphicsContext3D : public FakeWebGraphicsContext3D { |
| 2439 public: | 2439 public: |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2600 virtual WebRect trackRect(WebScrollbar*) OVERRIDE { return WebRect(0, 0, 10,
10); } | 2600 virtual WebRect trackRect(WebScrollbar*) OVERRIDE { return WebRect(0, 0, 10,
10); } |
| 2601 virtual WebRect thumbRect(WebScrollbar*) OVERRIDE { return WebRect(0, 5, 5,
2); } | 2601 virtual WebRect thumbRect(WebScrollbar*) OVERRIDE { return WebRect(0, 5, 5,
2); } |
| 2602 virtual void splitTrack(WebScrollbar*, const WebRect& track, WebRect& startT
rack, WebRect& thumb, WebRect& endTrack) OVERRIDE | 2602 virtual void splitTrack(WebScrollbar*, const WebRect& track, WebRect& startT
rack, WebRect& thumb, WebRect& endTrack) OVERRIDE |
| 2603 { | 2603 { |
| 2604 thumb = WebRect(0, 5, 5, 2); | 2604 thumb = WebRect(0, 5, 5, 2); |
| 2605 startTrack = WebRect(0, 5, 0, 5); | 2605 startTrack = WebRect(0, 5, 0, 5); |
| 2606 endTrack = WebRect(0, 0, 0, 5); | 2606 endTrack = WebRect(0, 0, 0, 5); |
| 2607 } | 2607 } |
| 2608 }; | 2608 }; |
| 2609 | 2609 |
| 2610 class FakeScrollbarLayerImpl : public CCScrollbarLayerImpl { | 2610 class FakeScrollbarLayerImpl : public ScrollbarLayerImpl { |
| 2611 public: | 2611 public: |
| 2612 static scoped_ptr<FakeScrollbarLayerImpl> create(int id) | 2612 static scoped_ptr<FakeScrollbarLayerImpl> create(int id) |
| 2613 { | 2613 { |
| 2614 return make_scoped_ptr(new FakeScrollbarLayerImpl(id)); | 2614 return make_scoped_ptr(new FakeScrollbarLayerImpl(id)); |
| 2615 } | 2615 } |
| 2616 | 2616 |
| 2617 void createResources(CCResourceProvider* provider) | 2617 void createResources(ResourceProvider* provider) |
| 2618 { | 2618 { |
| 2619 ASSERT(provider); | 2619 ASSERT(provider); |
| 2620 int pool = 0; | 2620 int pool = 0; |
| 2621 IntSize size(10, 10); | 2621 IntSize size(10, 10); |
| 2622 GC3Denum format = GraphicsContext3D::RGBA; | 2622 GC3Denum format = GraphicsContext3D::RGBA; |
| 2623 CCResourceProvider::TextureUsageHint hint = CCResourceProvider::TextureU
sageAny; | 2623 ResourceProvider::TextureUsageHint hint = ResourceProvider::TextureUsage
Any; |
| 2624 setScrollbarGeometry(CCScrollbarGeometryFixedThumb::create(FakeWebScroll
barThemeGeometryNonEmpty::create())); | 2624 setScrollbarGeometry(ScrollbarGeometryFixedThumb::create(FakeWebScrollba
rThemeGeometryNonEmpty::create())); |
| 2625 | 2625 |
| 2626 setBackTrackResourceId(provider->createResource(pool, size, format, hint
)); | 2626 setBackTrackResourceId(provider->createResource(pool, size, format, hint
)); |
| 2627 setForeTrackResourceId(provider->createResource(pool, size, format, hint
)); | 2627 setForeTrackResourceId(provider->createResource(pool, size, format, hint
)); |
| 2628 setThumbResourceId(provider->createResource(pool, size, format, hint)); | 2628 setThumbResourceId(provider->createResource(pool, size, format, hint)); |
| 2629 } | 2629 } |
| 2630 | 2630 |
| 2631 protected: | 2631 protected: |
| 2632 explicit FakeScrollbarLayerImpl(int id) | 2632 explicit FakeScrollbarLayerImpl(int id) |
| 2633 : CCScrollbarLayerImpl(id) | 2633 : ScrollbarLayerImpl(id) |
| 2634 { | 2634 { |
| 2635 } | 2635 } |
| 2636 }; | 2636 }; |
| 2637 | 2637 |
| 2638 static inline scoped_ptr<CCRenderPass> createRenderPassWithResource(CCResourcePr
ovider* provider) | 2638 static inline scoped_ptr<RenderPass> createRenderPassWithResource(ResourceProvid
er* provider) |
| 2639 { | 2639 { |
| 2640 CCResourceProvider::ResourceId resourceId = provider->createResource(0, IntS
ize(1, 1), GraphicsContext3D::RGBA, CCResourceProvider::TextureUsageAny); | 2640 ResourceProvider::ResourceId resourceId = provider->createResource(0, IntSiz
e(1, 1), GraphicsContext3D::RGBA, ResourceProvider::TextureUsageAny); |
| 2641 | 2641 |
| 2642 scoped_ptr<CCRenderPass> pass = CCRenderPass::create(CCRenderPass::Id(1, 1),
IntRect(0, 0, 1, 1), WebTransformationMatrix()); | 2642 scoped_ptr<RenderPass> pass = RenderPass::create(RenderPass::Id(1, 1), IntRe
ct(0, 0, 1, 1), WebTransformationMatrix()); |
| 2643 scoped_ptr<CCSharedQuadState> sharedState = CCSharedQuadState::create(WebTra
nsformationMatrix(), IntRect(0, 0, 1, 1), IntRect(0, 0, 1, 1), 1, false); | 2643 scoped_ptr<SharedQuadState> sharedState = SharedQuadState::create(WebTransfo
rmationMatrix(), IntRect(0, 0, 1, 1), IntRect(0, 0, 1, 1), 1, false); |
| 2644 scoped_ptr<CCTextureDrawQuad> quad = CCTextureDrawQuad::create(sharedState.g
et(), IntRect(0, 0, 1, 1), resourceId, false, FloatRect(0, 0, 1, 1), false); | 2644 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::create(sharedState.get()
, IntRect(0, 0, 1, 1), resourceId, false, FloatRect(0, 0, 1, 1), false); |
| 2645 | 2645 |
| 2646 static_cast<CCTestRenderPass*>(pass.get())->appendSharedQuadState(sharedStat
e.Pass()); | 2646 static_cast<TestRenderPass*>(pass.get())->appendSharedQuadState(sharedState.
Pass()); |
| 2647 static_cast<CCTestRenderPass*>(pass.get())->appendQuad(quad.PassAs<CCDrawQua
d>()); | 2647 static_cast<TestRenderPass*>(pass.get())->appendQuad(quad.PassAs<DrawQuad>()
); |
| 2648 | 2648 |
| 2649 return pass.Pass(); | 2649 return pass.Pass(); |
| 2650 } | 2650 } |
| 2651 | 2651 |
| 2652 TEST_P(CCLayerTreeHostImplTest, dontUseOldResourcesAfterLostContext) | 2652 TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostContext) |
| 2653 { | 2653 { |
| 2654 int layerId = 1; | 2654 int layerId = 1; |
| 2655 | 2655 |
| 2656 scoped_ptr<CCLayerImpl> rootLayer(CCLayerImpl::create(layerId++)); | 2656 scoped_ptr<LayerImpl> rootLayer(LayerImpl::create(layerId++)); |
| 2657 rootLayer->setBounds(IntSize(10, 10)); | 2657 rootLayer->setBounds(IntSize(10, 10)); |
| 2658 rootLayer->setAnchorPoint(FloatPoint(0, 0)); | 2658 rootLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2659 | 2659 |
| 2660 scoped_ptr<CCTiledLayerImpl> tileLayer = CCTiledLayerImpl::create(layerId++)
; | 2660 scoped_ptr<TiledLayerImpl> tileLayer = TiledLayerImpl::create(layerId++); |
| 2661 tileLayer->setBounds(IntSize(10, 10)); | 2661 tileLayer->setBounds(IntSize(10, 10)); |
| 2662 tileLayer->setAnchorPoint(FloatPoint(0, 0)); | 2662 tileLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2663 tileLayer->setContentBounds(IntSize(10, 10)); | 2663 tileLayer->setContentBounds(IntSize(10, 10)); |
| 2664 tileLayer->setDrawsContent(true); | 2664 tileLayer->setDrawsContent(true); |
| 2665 tileLayer->setSkipsDraw(false); | 2665 tileLayer->setSkipsDraw(false); |
| 2666 scoped_ptr<CCLayerTilingData> tilingData(CCLayerTilingData::create(IntSize(1
0, 10), CCLayerTilingData::NoBorderTexels)); | 2666 scoped_ptr<LayerTilingData> tilingData(LayerTilingData::create(IntSize(10, 1
0), LayerTilingData::NoBorderTexels)); |
| 2667 tilingData->setBounds(IntSize(10, 10)); | 2667 tilingData->setBounds(IntSize(10, 10)); |
| 2668 tileLayer->setTilingData(*tilingData); | 2668 tileLayer->setTilingData(*tilingData); |
| 2669 tileLayer->pushTileProperties(0, 0, 1, IntRect(0, 0, 10, 10)); | 2669 tileLayer->pushTileProperties(0, 0, 1, IntRect(0, 0, 10, 10)); |
| 2670 rootLayer->addChild(tileLayer.PassAs<CCLayerImpl>()); | 2670 rootLayer->addChild(tileLayer.PassAs<LayerImpl>()); |
| 2671 | 2671 |
| 2672 scoped_ptr<CCTextureLayerImpl> textureLayer = CCTextureLayerImpl::create(lay
erId++); | 2672 scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(layerId
++); |
| 2673 textureLayer->setBounds(IntSize(10, 10)); | 2673 textureLayer->setBounds(IntSize(10, 10)); |
| 2674 textureLayer->setAnchorPoint(FloatPoint(0, 0)); | 2674 textureLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2675 textureLayer->setContentBounds(IntSize(10, 10)); | 2675 textureLayer->setContentBounds(IntSize(10, 10)); |
| 2676 textureLayer->setDrawsContent(true); | 2676 textureLayer->setDrawsContent(true); |
| 2677 textureLayer->setTextureId(1); | 2677 textureLayer->setTextureId(1); |
| 2678 rootLayer->addChild(textureLayer.PassAs<CCLayerImpl>()); | 2678 rootLayer->addChild(textureLayer.PassAs<LayerImpl>()); |
| 2679 | 2679 |
| 2680 scoped_ptr<CCTiledLayerImpl> maskLayer = CCTiledLayerImpl::create(layerId++)
; | 2680 scoped_ptr<TiledLayerImpl> maskLayer = TiledLayerImpl::create(layerId++); |
| 2681 maskLayer->setBounds(IntSize(10, 10)); | 2681 maskLayer->setBounds(IntSize(10, 10)); |
| 2682 maskLayer->setAnchorPoint(FloatPoint(0, 0)); | 2682 maskLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2683 maskLayer->setContentBounds(IntSize(10, 10)); | 2683 maskLayer->setContentBounds(IntSize(10, 10)); |
| 2684 maskLayer->setDrawsContent(true); | 2684 maskLayer->setDrawsContent(true); |
| 2685 maskLayer->setSkipsDraw(false); | 2685 maskLayer->setSkipsDraw(false); |
| 2686 maskLayer->setTilingData(*tilingData); | 2686 maskLayer->setTilingData(*tilingData); |
| 2687 maskLayer->pushTileProperties(0, 0, 1, IntRect(0, 0, 10, 10)); | 2687 maskLayer->pushTileProperties(0, 0, 1, IntRect(0, 0, 10, 10)); |
| 2688 | 2688 |
| 2689 scoped_ptr<CCTextureLayerImpl> textureLayerWithMask = CCTextureLayerImpl::cr
eate(layerId++); | 2689 scoped_ptr<TextureLayerImpl> textureLayerWithMask = TextureLayerImpl::create
(layerId++); |
| 2690 textureLayerWithMask->setBounds(IntSize(10, 10)); | 2690 textureLayerWithMask->setBounds(IntSize(10, 10)); |
| 2691 textureLayerWithMask->setAnchorPoint(FloatPoint(0, 0)); | 2691 textureLayerWithMask->setAnchorPoint(FloatPoint(0, 0)); |
| 2692 textureLayerWithMask->setContentBounds(IntSize(10, 10)); | 2692 textureLayerWithMask->setContentBounds(IntSize(10, 10)); |
| 2693 textureLayerWithMask->setDrawsContent(true); | 2693 textureLayerWithMask->setDrawsContent(true); |
| 2694 textureLayerWithMask->setTextureId(1); | 2694 textureLayerWithMask->setTextureId(1); |
| 2695 textureLayerWithMask->setMaskLayer(maskLayer.PassAs<CCLayerImpl>()); | 2695 textureLayerWithMask->setMaskLayer(maskLayer.PassAs<LayerImpl>()); |
| 2696 rootLayer->addChild(textureLayerWithMask.PassAs<CCLayerImpl>()); | 2696 rootLayer->addChild(textureLayerWithMask.PassAs<LayerImpl>()); |
| 2697 | 2697 |
| 2698 FakeVideoFrame videoFrame; | 2698 FakeVideoFrame videoFrame; |
| 2699 FakeVideoFrameProvider provider; | 2699 FakeVideoFrameProvider provider; |
| 2700 provider.setFrame(&videoFrame); | 2700 provider.setFrame(&videoFrame); |
| 2701 scoped_ptr<CCVideoLayerImpl> videoLayer = CCVideoLayerImpl::create(layerId++
, &provider); | 2701 scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(layerId++, &p
rovider); |
| 2702 videoLayer->setBounds(IntSize(10, 10)); | 2702 videoLayer->setBounds(IntSize(10, 10)); |
| 2703 videoLayer->setAnchorPoint(FloatPoint(0, 0)); | 2703 videoLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2704 videoLayer->setContentBounds(IntSize(10, 10)); | 2704 videoLayer->setContentBounds(IntSize(10, 10)); |
| 2705 videoLayer->setDrawsContent(true); | 2705 videoLayer->setDrawsContent(true); |
| 2706 videoLayer->setLayerTreeHostImpl(m_hostImpl.get()); | 2706 videoLayer->setLayerTreeHostImpl(m_hostImpl.get()); |
| 2707 rootLayer->addChild(videoLayer.PassAs<CCLayerImpl>()); | 2707 rootLayer->addChild(videoLayer.PassAs<LayerImpl>()); |
| 2708 | 2708 |
| 2709 FakeVideoFrame hwVideoFrame; | 2709 FakeVideoFrame hwVideoFrame; |
| 2710 FakeVideoFrameProvider hwProvider; | 2710 FakeVideoFrameProvider hwProvider; |
| 2711 hwProvider.setFrame(&hwVideoFrame); | 2711 hwProvider.setFrame(&hwVideoFrame); |
| 2712 scoped_ptr<CCVideoLayerImpl> hwVideoLayer = CCVideoLayerImpl::create(layerId
++, &hwProvider); | 2712 scoped_ptr<VideoLayerImpl> hwVideoLayer = VideoLayerImpl::create(layerId++,
&hwProvider); |
| 2713 hwVideoLayer->setBounds(IntSize(10, 10)); | 2713 hwVideoLayer->setBounds(IntSize(10, 10)); |
| 2714 hwVideoLayer->setAnchorPoint(FloatPoint(0, 0)); | 2714 hwVideoLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2715 hwVideoLayer->setContentBounds(IntSize(10, 10)); | 2715 hwVideoLayer->setContentBounds(IntSize(10, 10)); |
| 2716 hwVideoLayer->setDrawsContent(true); | 2716 hwVideoLayer->setDrawsContent(true); |
| 2717 hwVideoLayer->setLayerTreeHostImpl(m_hostImpl.get()); | 2717 hwVideoLayer->setLayerTreeHostImpl(m_hostImpl.get()); |
| 2718 rootLayer->addChild(hwVideoLayer.PassAs<CCLayerImpl>()); | 2718 rootLayer->addChild(hwVideoLayer.PassAs<LayerImpl>()); |
| 2719 | 2719 |
| 2720 scoped_ptr<CCIOSurfaceLayerImpl> ioSurfaceLayer = CCIOSurfaceLayerImpl::crea
te(layerId++); | 2720 scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::create(l
ayerId++); |
| 2721 ioSurfaceLayer->setBounds(IntSize(10, 10)); | 2721 ioSurfaceLayer->setBounds(IntSize(10, 10)); |
| 2722 ioSurfaceLayer->setAnchorPoint(FloatPoint(0, 0)); | 2722 ioSurfaceLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2723 ioSurfaceLayer->setContentBounds(IntSize(10, 10)); | 2723 ioSurfaceLayer->setContentBounds(IntSize(10, 10)); |
| 2724 ioSurfaceLayer->setDrawsContent(true); | 2724 ioSurfaceLayer->setDrawsContent(true); |
| 2725 ioSurfaceLayer->setIOSurfaceProperties(1, IntSize(10, 10)); | 2725 ioSurfaceLayer->setIOSurfaceProperties(1, IntSize(10, 10)); |
| 2726 ioSurfaceLayer->setLayerTreeHostImpl(m_hostImpl.get()); | 2726 ioSurfaceLayer->setLayerTreeHostImpl(m_hostImpl.get()); |
| 2727 rootLayer->addChild(ioSurfaceLayer.PassAs<CCLayerImpl>()); | 2727 rootLayer->addChild(ioSurfaceLayer.PassAs<LayerImpl>()); |
| 2728 | 2728 |
| 2729 scoped_ptr<CCHeadsUpDisplayLayerImpl> hudLayer = CCHeadsUpDisplayLayerImpl::
create(layerId++); | 2729 scoped_ptr<HeadsUpDisplayLayerImpl> hudLayer = HeadsUpDisplayLayerImpl::crea
te(layerId++); |
| 2730 hudLayer->setBounds(IntSize(10, 10)); | 2730 hudLayer->setBounds(IntSize(10, 10)); |
| 2731 hudLayer->setAnchorPoint(FloatPoint(0, 0)); | 2731 hudLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2732 hudLayer->setContentBounds(IntSize(10, 10)); | 2732 hudLayer->setContentBounds(IntSize(10, 10)); |
| 2733 hudLayer->setDrawsContent(true); | 2733 hudLayer->setDrawsContent(true); |
| 2734 hudLayer->setLayerTreeHostImpl(m_hostImpl.get()); | 2734 hudLayer->setLayerTreeHostImpl(m_hostImpl.get()); |
| 2735 rootLayer->addChild(hudLayer.PassAs<CCLayerImpl>()); | 2735 rootLayer->addChild(hudLayer.PassAs<LayerImpl>()); |
| 2736 | 2736 |
| 2737 scoped_ptr<FakeScrollbarLayerImpl> scrollbarLayer(FakeScrollbarLayerImpl::cr
eate(layerId++)); | 2737 scoped_ptr<FakeScrollbarLayerImpl> scrollbarLayer(FakeScrollbarLayerImpl::cr
eate(layerId++)); |
| 2738 scrollbarLayer->setBounds(IntSize(10, 10)); | 2738 scrollbarLayer->setBounds(IntSize(10, 10)); |
| 2739 scrollbarLayer->setContentBounds(IntSize(10, 10)); | 2739 scrollbarLayer->setContentBounds(IntSize(10, 10)); |
| 2740 scrollbarLayer->setDrawsContent(true); | 2740 scrollbarLayer->setDrawsContent(true); |
| 2741 scrollbarLayer->setLayerTreeHostImpl(m_hostImpl.get()); | 2741 scrollbarLayer->setLayerTreeHostImpl(m_hostImpl.get()); |
| 2742 scrollbarLayer->createResources(m_hostImpl->resourceProvider()); | 2742 scrollbarLayer->createResources(m_hostImpl->resourceProvider()); |
| 2743 rootLayer->addChild(scrollbarLayer.PassAs<CCLayerImpl>()); | 2743 rootLayer->addChild(scrollbarLayer.PassAs<LayerImpl>()); |
| 2744 | 2744 |
| 2745 scoped_ptr<CCDelegatedRendererLayerImpl> delegatedRendererLayer(CCDelegatedR
endererLayerImpl::create(layerId++)); | 2745 scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer(DelegatedRende
rerLayerImpl::create(layerId++)); |
| 2746 delegatedRendererLayer->setBounds(IntSize(10, 10)); | 2746 delegatedRendererLayer->setBounds(IntSize(10, 10)); |
| 2747 delegatedRendererLayer->setContentBounds(IntSize(10, 10)); | 2747 delegatedRendererLayer->setContentBounds(IntSize(10, 10)); |
| 2748 delegatedRendererLayer->setDrawsContent(true); | 2748 delegatedRendererLayer->setDrawsContent(true); |
| 2749 delegatedRendererLayer->setLayerTreeHostImpl(m_hostImpl.get()); | 2749 delegatedRendererLayer->setLayerTreeHostImpl(m_hostImpl.get()); |
| 2750 ScopedPtrVector<CCRenderPass> passList; | 2750 ScopedPtrVector<RenderPass> passList; |
| 2751 passList.append(createRenderPassWithResource(m_hostImpl->resourceProvider())
); | 2751 passList.append(createRenderPassWithResource(m_hostImpl->resourceProvider())
); |
| 2752 delegatedRendererLayer->setRenderPasses(passList); | 2752 delegatedRendererLayer->setRenderPasses(passList); |
| 2753 EXPECT_TRUE(passList.isEmpty()); | 2753 EXPECT_TRUE(passList.isEmpty()); |
| 2754 rootLayer->addChild(delegatedRendererLayer.PassAs<CCLayerImpl>()); | 2754 rootLayer->addChild(delegatedRendererLayer.PassAs<LayerImpl>()); |
| 2755 | 2755 |
| 2756 // Use a context that supports IOSurfaces | 2756 // Use a context that supports IOSurfaces |
| 2757 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DWithIOSurface)).P
assAs<CCGraphicsContext>()); | 2757 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DWithIOSurface)).P
assAs<GraphicsContext>()); |
| 2758 | 2758 |
| 2759 hwVideoFrame.setTextureId(m_hostImpl->resourceProvider()->graphicsContext3D(
)->createTexture()); | 2759 hwVideoFrame.setTextureId(m_hostImpl->resourceProvider()->graphicsContext3D(
)->createTexture()); |
| 2760 | 2760 |
| 2761 m_hostImpl->setRootLayer(rootLayer.Pass()); | 2761 m_hostImpl->setRootLayer(rootLayer.Pass()); |
| 2762 | 2762 |
| 2763 CCLayerTreeHostImpl::FrameData frame; | 2763 LayerTreeHostImpl::FrameData frame; |
| 2764 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 2764 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 2765 m_hostImpl->drawLayers(frame); | 2765 m_hostImpl->drawLayers(frame); |
| 2766 m_hostImpl->didDrawAllLayers(frame); | 2766 m_hostImpl->didDrawAllLayers(frame); |
| 2767 m_hostImpl->swapBuffers(); | 2767 m_hostImpl->swapBuffers(); |
| 2768 | 2768 |
| 2769 unsigned numResources = m_hostImpl->resourceProvider()->numResources(); | 2769 unsigned numResources = m_hostImpl->resourceProvider()->numResources(); |
| 2770 | 2770 |
| 2771 // Lose the context, replacing it with a StrictWebGraphicsContext3DWithIOSur
face, | 2771 // Lose the context, replacing it with a StrictWebGraphicsContext3DWithIOSur
face, |
| 2772 // that will warn if any resource from the previous context gets used. | 2772 // that will warn if any resource from the previous context gets used. |
| 2773 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new StrictWebGraphicsContext3DWithIOSurface))
.PassAs<CCGraphicsContext>()); | 2773 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new StrictWebGraphicsContext3DWithIOSurface))
.PassAs<GraphicsContext>()); |
| 2774 | 2774 |
| 2775 // Create dummy resources so that looking up an old resource will get an | 2775 // Create dummy resources so that looking up an old resource will get an |
| 2776 // invalid texture id mapping. | 2776 // invalid texture id mapping. |
| 2777 for (unsigned i = 0; i < numResources; ++i) | 2777 for (unsigned i = 0; i < numResources; ++i) |
| 2778 m_hostImpl->resourceProvider()->createResourceFromExternalTexture(1); | 2778 m_hostImpl->resourceProvider()->createResourceFromExternalTexture(1); |
| 2779 | 2779 |
| 2780 // The WebVideoFrameProvider is expected to recreate its textures after a | 2780 // The WebVideoFrameProvider is expected to recreate its textures after a |
| 2781 // lost context (or not serve a frame). | 2781 // lost context (or not serve a frame). |
| 2782 hwProvider.setFrame(0); | 2782 hwProvider.setFrame(0); |
| 2783 | 2783 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2829 return WebString(); | 2829 return WebString(); |
| 2830 } | 2830 } |
| 2831 | 2831 |
| 2832 unsigned numTextures() const { return m_numTextures; } | 2832 unsigned numTextures() const { return m_numTextures; } |
| 2833 | 2833 |
| 2834 private: | 2834 private: |
| 2835 base::hash_map<WebGLId, bool> m_textures; | 2835 base::hash_map<WebGLId, bool> m_textures; |
| 2836 unsigned m_numTextures; | 2836 unsigned m_numTextures; |
| 2837 }; | 2837 }; |
| 2838 | 2838 |
| 2839 TEST_P(CCLayerTreeHostImplTest, layersFreeTextures) | 2839 TEST_P(LayerTreeHostImplTest, layersFreeTextures) |
| 2840 { | 2840 { |
| 2841 scoped_ptr<CCLayerImpl> rootLayer(CCLayerImpl::create(1)); | 2841 scoped_ptr<LayerImpl> rootLayer(LayerImpl::create(1)); |
| 2842 rootLayer->setBounds(IntSize(10, 10)); | 2842 rootLayer->setBounds(IntSize(10, 10)); |
| 2843 rootLayer->setAnchorPoint(FloatPoint(0, 0)); | 2843 rootLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2844 | 2844 |
| 2845 scoped_ptr<CCTiledLayerImpl> tileLayer = CCTiledLayerImpl::create(2); | 2845 scoped_ptr<TiledLayerImpl> tileLayer = TiledLayerImpl::create(2); |
| 2846 tileLayer->setBounds(IntSize(10, 10)); | 2846 tileLayer->setBounds(IntSize(10, 10)); |
| 2847 tileLayer->setAnchorPoint(FloatPoint(0, 0)); | 2847 tileLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2848 tileLayer->setContentBounds(IntSize(10, 10)); | 2848 tileLayer->setContentBounds(IntSize(10, 10)); |
| 2849 tileLayer->setDrawsContent(true); | 2849 tileLayer->setDrawsContent(true); |
| 2850 tileLayer->setSkipsDraw(false); | 2850 tileLayer->setSkipsDraw(false); |
| 2851 scoped_ptr<CCLayerTilingData> tilingData(CCLayerTilingData::create(IntSize(1
0, 10), CCLayerTilingData::NoBorderTexels)); | 2851 scoped_ptr<LayerTilingData> tilingData(LayerTilingData::create(IntSize(10, 1
0), LayerTilingData::NoBorderTexels)); |
| 2852 tilingData->setBounds(IntSize(10, 10)); | 2852 tilingData->setBounds(IntSize(10, 10)); |
| 2853 tileLayer->setTilingData(*tilingData); | 2853 tileLayer->setTilingData(*tilingData); |
| 2854 tileLayer->pushTileProperties(0, 0, 1, IntRect(0, 0, 10, 10)); | 2854 tileLayer->pushTileProperties(0, 0, 1, IntRect(0, 0, 10, 10)); |
| 2855 rootLayer->addChild(tileLayer.PassAs<CCLayerImpl>()); | 2855 rootLayer->addChild(tileLayer.PassAs<LayerImpl>()); |
| 2856 | 2856 |
| 2857 scoped_ptr<CCTextureLayerImpl> textureLayer = CCTextureLayerImpl::create(3); | 2857 scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(3); |
| 2858 textureLayer->setBounds(IntSize(10, 10)); | 2858 textureLayer->setBounds(IntSize(10, 10)); |
| 2859 textureLayer->setAnchorPoint(FloatPoint(0, 0)); | 2859 textureLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2860 textureLayer->setContentBounds(IntSize(10, 10)); | 2860 textureLayer->setContentBounds(IntSize(10, 10)); |
| 2861 textureLayer->setDrawsContent(true); | 2861 textureLayer->setDrawsContent(true); |
| 2862 textureLayer->setTextureId(1); | 2862 textureLayer->setTextureId(1); |
| 2863 rootLayer->addChild(textureLayer.PassAs<CCLayerImpl>()); | 2863 rootLayer->addChild(textureLayer.PassAs<LayerImpl>()); |
| 2864 | 2864 |
| 2865 FakeVideoFrameProvider provider; | 2865 FakeVideoFrameProvider provider; |
| 2866 scoped_ptr<CCVideoLayerImpl> videoLayer = CCVideoLayerImpl::create(4, &provi
der); | 2866 scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(4, &provider)
; |
| 2867 videoLayer->setBounds(IntSize(10, 10)); | 2867 videoLayer->setBounds(IntSize(10, 10)); |
| 2868 videoLayer->setAnchorPoint(FloatPoint(0, 0)); | 2868 videoLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2869 videoLayer->setContentBounds(IntSize(10, 10)); | 2869 videoLayer->setContentBounds(IntSize(10, 10)); |
| 2870 videoLayer->setDrawsContent(true); | 2870 videoLayer->setDrawsContent(true); |
| 2871 videoLayer->setLayerTreeHostImpl(m_hostImpl.get()); | 2871 videoLayer->setLayerTreeHostImpl(m_hostImpl.get()); |
| 2872 rootLayer->addChild(videoLayer.PassAs<CCLayerImpl>()); | 2872 rootLayer->addChild(videoLayer.PassAs<LayerImpl>()); |
| 2873 | 2873 |
| 2874 scoped_ptr<CCIOSurfaceLayerImpl> ioSurfaceLayer = CCIOSurfaceLayerImpl::crea
te(5); | 2874 scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::create(5
); |
| 2875 ioSurfaceLayer->setBounds(IntSize(10, 10)); | 2875 ioSurfaceLayer->setBounds(IntSize(10, 10)); |
| 2876 ioSurfaceLayer->setAnchorPoint(FloatPoint(0, 0)); | 2876 ioSurfaceLayer->setAnchorPoint(FloatPoint(0, 0)); |
| 2877 ioSurfaceLayer->setContentBounds(IntSize(10, 10)); | 2877 ioSurfaceLayer->setContentBounds(IntSize(10, 10)); |
| 2878 ioSurfaceLayer->setDrawsContent(true); | 2878 ioSurfaceLayer->setDrawsContent(true); |
| 2879 ioSurfaceLayer->setIOSurfaceProperties(1, IntSize(10, 10)); | 2879 ioSurfaceLayer->setIOSurfaceProperties(1, IntSize(10, 10)); |
| 2880 ioSurfaceLayer->setLayerTreeHostImpl(m_hostImpl.get()); | 2880 ioSurfaceLayer->setLayerTreeHostImpl(m_hostImpl.get()); |
| 2881 rootLayer->addChild(ioSurfaceLayer.PassAs<CCLayerImpl>()); | 2881 rootLayer->addChild(ioSurfaceLayer.PassAs<LayerImpl>()); |
| 2882 | 2882 |
| 2883 // Lose the context, replacing it with a TrackingWebGraphicsContext3D (which
the CCLayerTreeHostImpl takes ownership of). | 2883 // Lose the context, replacing it with a TrackingWebGraphicsContext3D (which
the LayerTreeHostImpl takes ownership of). |
| 2884 scoped_ptr<CCGraphicsContext> ccContext(FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new TrackingWebGraphicsContext3D))); | 2884 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr
eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new TrackingWebGraphicsContext3D))
); |
| 2885 TrackingWebGraphicsContext3D* trackingWebGraphicsContext = static_cast<Track
ingWebGraphicsContext3D*>(ccContext->context3D()); | 2885 TrackingWebGraphicsContext3D* trackingWebGraphicsContext = static_cast<Track
ingWebGraphicsContext3D*>(outputSurface->context3D()); |
| 2886 m_hostImpl->initializeRenderer(ccContext.Pass()); | 2886 m_hostImpl->initializeRenderer(outputSurface.Pass()); |
| 2887 | 2887 |
| 2888 m_hostImpl->setRootLayer(rootLayer.Pass()); | 2888 m_hostImpl->setRootLayer(rootLayer.Pass()); |
| 2889 | 2889 |
| 2890 CCLayerTreeHostImpl::FrameData frame; | 2890 LayerTreeHostImpl::FrameData frame; |
| 2891 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 2891 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 2892 m_hostImpl->drawLayers(frame); | 2892 m_hostImpl->drawLayers(frame); |
| 2893 m_hostImpl->didDrawAllLayers(frame); | 2893 m_hostImpl->didDrawAllLayers(frame); |
| 2894 m_hostImpl->swapBuffers(); | 2894 m_hostImpl->swapBuffers(); |
| 2895 | 2895 |
| 2896 EXPECT_GT(trackingWebGraphicsContext->numTextures(), 0u); | 2896 EXPECT_GT(trackingWebGraphicsContext->numTextures(), 0u); |
| 2897 | 2897 |
| 2898 // Kill the layer tree. | 2898 // Kill the layer tree. |
| 2899 m_hostImpl->setRootLayer(CCLayerImpl::create(100)); | 2899 m_hostImpl->setRootLayer(LayerImpl::create(100)); |
| 2900 // There should be no textures left in use after. | 2900 // There should be no textures left in use after. |
| 2901 EXPECT_EQ(0u, trackingWebGraphicsContext->numTextures()); | 2901 EXPECT_EQ(0u, trackingWebGraphicsContext->numTextures()); |
| 2902 } | 2902 } |
| 2903 | 2903 |
| 2904 class MockDrawQuadsToFillScreenContext : public FakeWebGraphicsContext3D { | 2904 class MockDrawQuadsToFillScreenContext : public FakeWebGraphicsContext3D { |
| 2905 public: | 2905 public: |
| 2906 MOCK_METHOD1(useProgram, void(WebGLId program)); | 2906 MOCK_METHOD1(useProgram, void(WebGLId program)); |
| 2907 MOCK_METHOD4(drawElements, void(WGC3Denum mode, WGC3Dsizei count, WGC3Denum
type, WGC3Dintptr offset)); | 2907 MOCK_METHOD4(drawElements, void(WGC3Denum mode, WGC3Dsizei count, WGC3Denum
type, WGC3Dintptr offset)); |
| 2908 }; | 2908 }; |
| 2909 | 2909 |
| 2910 TEST_P(CCLayerTreeHostImplTest, hasTransparentBackground) | 2910 TEST_P(LayerTreeHostImplTest, hasTransparentBackground) |
| 2911 { | 2911 { |
| 2912 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockDrawQuadsToFillScreenContext
)).PassAs<CCGraphicsContext>(); | 2912 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockDrawQuadsToFillScreenContext))
.PassAs<GraphicsContext>(); |
| 2913 MockDrawQuadsToFillScreenContext* mockContext = static_cast<MockDrawQuadsToF
illScreenContext*>(context->context3D()); | 2913 MockDrawQuadsToFillScreenContext* mockContext = static_cast<MockDrawQuadsToF
illScreenContext*>(context->context3D()); |
| 2914 | 2914 |
| 2915 // Run test case | 2915 // Run test case |
| 2916 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = createLayerTreeHost(false, cont
ext.Pass(), CCLayerImpl::create(1)); | 2916 scoped_ptr<LayerTreeHostImpl> myHostImpl = createLayerTreeHost(false, contex
t.Pass(), LayerImpl::create(1)); |
| 2917 myHostImpl->setBackgroundColor(SK_ColorWHITE); | 2917 myHostImpl->setBackgroundColor(SK_ColorWHITE); |
| 2918 | 2918 |
| 2919 // Verify one quad is drawn when transparent background set is not set. | 2919 // Verify one quad is drawn when transparent background set is not set. |
| 2920 myHostImpl->setHasTransparentBackground(false); | 2920 myHostImpl->setHasTransparentBackground(false); |
| 2921 EXPECT_CALL(*mockContext, useProgram(_)) | 2921 EXPECT_CALL(*mockContext, useProgram(_)) |
| 2922 .Times(1); | 2922 .Times(1); |
| 2923 EXPECT_CALL(*mockContext, drawElements(_, _, _, _)) | 2923 EXPECT_CALL(*mockContext, drawElements(_, _, _, _)) |
| 2924 .Times(1); | 2924 .Times(1); |
| 2925 CCLayerTreeHostImpl::FrameData frame; | 2925 LayerTreeHostImpl::FrameData frame; |
| 2926 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 2926 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 2927 myHostImpl->drawLayers(frame); | 2927 myHostImpl->drawLayers(frame); |
| 2928 myHostImpl->didDrawAllLayers(frame); | 2928 myHostImpl->didDrawAllLayers(frame); |
| 2929 Mock::VerifyAndClearExpectations(&mockContext); | 2929 Mock::VerifyAndClearExpectations(&mockContext); |
| 2930 | 2930 |
| 2931 // Verify no quads are drawn when transparent background is set. | 2931 // Verify no quads are drawn when transparent background is set. |
| 2932 myHostImpl->setHasTransparentBackground(true); | 2932 myHostImpl->setHasTransparentBackground(true); |
| 2933 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 2933 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 2934 myHostImpl->drawLayers(frame); | 2934 myHostImpl->drawLayers(frame); |
| 2935 myHostImpl->didDrawAllLayers(frame); | 2935 myHostImpl->didDrawAllLayers(frame); |
| 2936 Mock::VerifyAndClearExpectations(&mockContext); | 2936 Mock::VerifyAndClearExpectations(&mockContext); |
| 2937 } | 2937 } |
| 2938 | 2938 |
| 2939 static void addDrawingLayerTo(CCLayerImpl* parent, int id, const IntRect& layerR
ect, CCLayerImpl** result) | 2939 static void addDrawingLayerTo(LayerImpl* parent, int id, const IntRect& layerRec
t, LayerImpl** result) |
| 2940 { | 2940 { |
| 2941 scoped_ptr<CCLayerImpl> layer = FakeLayerWithQuads::create(id); | 2941 scoped_ptr<LayerImpl> layer = FakeLayerWithQuads::create(id); |
| 2942 CCLayerImpl* layerPtr = layer.get(); | 2942 LayerImpl* layerPtr = layer.get(); |
| 2943 layerPtr->setAnchorPoint(FloatPoint(0, 0)); | 2943 layerPtr->setAnchorPoint(FloatPoint(0, 0)); |
| 2944 layerPtr->setPosition(FloatPoint(layerRect.location())); | 2944 layerPtr->setPosition(FloatPoint(layerRect.location())); |
| 2945 layerPtr->setBounds(layerRect.size()); | 2945 layerPtr->setBounds(layerRect.size()); |
| 2946 layerPtr->setContentBounds(layerRect.size()); | 2946 layerPtr->setContentBounds(layerRect.size()); |
| 2947 layerPtr->setDrawsContent(true); // only children draw content | 2947 layerPtr->setDrawsContent(true); // only children draw content |
| 2948 layerPtr->setContentsOpaque(true); | 2948 layerPtr->setContentsOpaque(true); |
| 2949 parent->addChild(layer.Pass()); | 2949 parent->addChild(layer.Pass()); |
| 2950 if (result) | 2950 if (result) |
| 2951 *result = layerPtr; | 2951 *result = layerPtr; |
| 2952 } | 2952 } |
| 2953 | 2953 |
| 2954 static void setupLayersForTextureCaching(CCLayerTreeHostImpl* layerTreeHostImpl,
CCLayerImpl*& rootPtr, CCLayerImpl*& intermediateLayerPtr, CCLayerImpl*& surfac
eLayerPtr, CCLayerImpl*& childPtr, const IntSize& rootSize) | 2954 static void setupLayersForTextureCaching(LayerTreeHostImpl* layerTreeHostImpl, L
ayerImpl*& rootPtr, LayerImpl*& intermediateLayerPtr, LayerImpl*& surfaceLayerPt
r, LayerImpl*& childPtr, const IntSize& rootSize) |
| 2955 { | 2955 { |
| 2956 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<CCGr
aphicsContext>(); | 2956 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<Graphi
csContext>(); |
| 2957 | 2957 |
| 2958 layerTreeHostImpl->initializeRenderer(context.Pass()); | 2958 layerTreeHostImpl->initializeRenderer(context.Pass()); |
| 2959 layerTreeHostImpl->setViewportSize(rootSize, rootSize); | 2959 layerTreeHostImpl->setViewportSize(rootSize, rootSize); |
| 2960 | 2960 |
| 2961 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 2961 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 2962 rootPtr = root.get(); | 2962 rootPtr = root.get(); |
| 2963 | 2963 |
| 2964 root->setAnchorPoint(FloatPoint(0, 0)); | 2964 root->setAnchorPoint(FloatPoint(0, 0)); |
| 2965 root->setPosition(FloatPoint(0, 0)); | 2965 root->setPosition(FloatPoint(0, 0)); |
| 2966 root->setBounds(rootSize); | 2966 root->setBounds(rootSize); |
| 2967 root->setContentBounds(rootSize); | 2967 root->setContentBounds(rootSize); |
| 2968 root->setDrawsContent(true); | 2968 root->setDrawsContent(true); |
| 2969 layerTreeHostImpl->setRootLayer(root.Pass()); | 2969 layerTreeHostImpl->setRootLayer(root.Pass()); |
| 2970 | 2970 |
| 2971 addDrawingLayerTo(rootPtr, 2, IntRect(10, 10, rootSize.width(), rootSize.hei
ght()), &intermediateLayerPtr); | 2971 addDrawingLayerTo(rootPtr, 2, IntRect(10, 10, rootSize.width(), rootSize.hei
ght()), &intermediateLayerPtr); |
| 2972 intermediateLayerPtr->setDrawsContent(false); // only children draw content | 2972 intermediateLayerPtr->setDrawsContent(false); // only children draw content |
| 2973 | 2973 |
| 2974 // Surface layer is the layer that changes its opacity | 2974 // Surface layer is the layer that changes its opacity |
| 2975 // It will contain other layers that draw content. | 2975 // It will contain other layers that draw content. |
| 2976 addDrawingLayerTo(intermediateLayerPtr, 3, IntRect(10, 10, rootSize.width(),
rootSize.height()), &surfaceLayerPtr); | 2976 addDrawingLayerTo(intermediateLayerPtr, 3, IntRect(10, 10, rootSize.width(),
rootSize.height()), &surfaceLayerPtr); |
| 2977 surfaceLayerPtr->setDrawsContent(false); // only children draw content | 2977 surfaceLayerPtr->setDrawsContent(false); // only children draw content |
| 2978 surfaceLayerPtr->setOpacity(0.5f); // This will cause it to have a surface | 2978 surfaceLayerPtr->setOpacity(0.5f); // This will cause it to have a surface |
| 2979 | 2979 |
| 2980 // Child of the surface layer will produce some quads | 2980 // Child of the surface layer will produce some quads |
| 2981 addDrawingLayerTo(surfaceLayerPtr, 4, IntRect(5, 5, rootSize.width() - 25, r
ootSize.height() - 25), &childPtr); | 2981 addDrawingLayerTo(surfaceLayerPtr, 4, IntRect(5, 5, rootSize.width() - 25, r
ootSize.height() - 25), &childPtr); |
| 2982 } | 2982 } |
| 2983 | 2983 |
| 2984 class CCRendererGLWithReleaseTextures : public CCRendererGL { | 2984 class GLRendererWithReleaseTextures : public GLRenderer { |
| 2985 public: | 2985 public: |
| 2986 using CCRendererGL::releaseRenderPassTextures; | 2986 using GLRenderer::releaseRenderPassTextures; |
| 2987 }; | 2987 }; |
| 2988 | 2988 |
| 2989 TEST_P(CCLayerTreeHostImplTest, textureCachingWithClipping) | 2989 TEST_P(LayerTreeHostImplTest, textureCachingWithClipping) |
| 2990 { | 2990 { |
| 2991 CCSettings::setPartialSwapEnabled(true); | 2991 Settings::setPartialSwapEnabled(true); |
| 2992 | 2992 |
| 2993 CCLayerTreeSettings settings; | 2993 LayerTreeSettings settings; |
| 2994 settings.minimumOcclusionTrackingSize = IntSize(); | 2994 settings.minimumOcclusionTrackingSize = IntSize(); |
| 2995 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, this); | 2995 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this); |
| 2996 | 2996 |
| 2997 CCLayerImpl* rootPtr; | 2997 LayerImpl* rootPtr; |
| 2998 CCLayerImpl* surfaceLayerPtr; | 2998 LayerImpl* surfaceLayerPtr; |
| 2999 | 2999 |
| 3000 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<CCGr
aphicsContext>(); | 3000 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<Graphi
csContext>(); |
| 3001 | 3001 |
| 3002 IntSize rootSize(100, 100); | 3002 IntSize rootSize(100, 100); |
| 3003 | 3003 |
| 3004 myHostImpl->initializeRenderer(context.Pass()); | 3004 myHostImpl->initializeRenderer(context.Pass()); |
| 3005 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); | 3005 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); |
| 3006 | 3006 |
| 3007 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 3007 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 3008 rootPtr = root.get(); | 3008 rootPtr = root.get(); |
| 3009 | 3009 |
| 3010 root->setAnchorPoint(FloatPoint(0, 0)); | 3010 root->setAnchorPoint(FloatPoint(0, 0)); |
| 3011 root->setPosition(FloatPoint(0, 0)); | 3011 root->setPosition(FloatPoint(0, 0)); |
| 3012 root->setBounds(rootSize); | 3012 root->setBounds(rootSize); |
| 3013 root->setContentBounds(rootSize); | 3013 root->setContentBounds(rootSize); |
| 3014 root->setDrawsContent(true); | 3014 root->setDrawsContent(true); |
| 3015 root->setMasksToBounds(true); | 3015 root->setMasksToBounds(true); |
| 3016 myHostImpl->setRootLayer(root.Pass()); | 3016 myHostImpl->setRootLayer(root.Pass()); |
| 3017 | 3017 |
| 3018 addDrawingLayerTo(rootPtr, 3, IntRect(0, 0, rootSize.width(), rootSize.heigh
t()), &surfaceLayerPtr); | 3018 addDrawingLayerTo(rootPtr, 3, IntRect(0, 0, rootSize.width(), rootSize.heigh
t()), &surfaceLayerPtr); |
| 3019 surfaceLayerPtr->setDrawsContent(false); | 3019 surfaceLayerPtr->setDrawsContent(false); |
| 3020 | 3020 |
| 3021 // Surface layer is the layer that changes its opacity | 3021 // Surface layer is the layer that changes its opacity |
| 3022 // It will contain other layers that draw content. | 3022 // It will contain other layers that draw content. |
| 3023 surfaceLayerPtr->setOpacity(0.5f); // This will cause it to have a surface | 3023 surfaceLayerPtr->setOpacity(0.5f); // This will cause it to have a surface |
| 3024 | 3024 |
| 3025 addDrawingLayerTo(surfaceLayerPtr, 4, IntRect(0, 0, 100, 3), 0); | 3025 addDrawingLayerTo(surfaceLayerPtr, 4, IntRect(0, 0, 100, 3), 0); |
| 3026 addDrawingLayerTo(surfaceLayerPtr, 5, IntRect(0, 97, 100, 3), 0); | 3026 addDrawingLayerTo(surfaceLayerPtr, 5, IntRect(0, 97, 100, 3), 0); |
| 3027 | 3027 |
| 3028 // Rotation will put part of the child ouside the bounds of the root layer. | 3028 // Rotation will put part of the child ouside the bounds of the root layer. |
| 3029 // Nevertheless, the child layers should be drawn. | 3029 // Nevertheless, the child layers should be drawn. |
| 3030 WebTransformationMatrix transform = surfaceLayerPtr->transform(); | 3030 WebTransformationMatrix transform = surfaceLayerPtr->transform(); |
| 3031 transform.translate(50, 50); | 3031 transform.translate(50, 50); |
| 3032 transform.rotate(35); | 3032 transform.rotate(35); |
| 3033 transform.translate(-50, -50); | 3033 transform.translate(-50, -50); |
| 3034 surfaceLayerPtr->setTransform(transform); | 3034 surfaceLayerPtr->setTransform(transform); |
| 3035 | 3035 |
| 3036 { | 3036 { |
| 3037 CCLayerTreeHostImpl::FrameData frame; | 3037 LayerTreeHostImpl::FrameData frame; |
| 3038 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3038 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3039 | 3039 |
| 3040 // Must receive two render passes, each with one quad | 3040 // Must receive two render passes, each with one quad |
| 3041 ASSERT_EQ(2U, frame.renderPasses.size()); | 3041 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3042 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); | 3042 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); |
| 3043 ASSERT_EQ(1U, frame.renderPasses[1]->quadList().size()); | 3043 ASSERT_EQ(1U, frame.renderPasses[1]->quadList().size()); |
| 3044 | 3044 |
| 3045 // Verify that the child layers are being clipped. | 3045 // Verify that the child layers are being clipped. |
| 3046 IntRect quadVisibleRect = frame.renderPasses[0]->quadList()[0]->quadVisi
bleRect(); | 3046 IntRect quadVisibleRect = frame.renderPasses[0]->quadList()[0]->quadVisi
bleRect(); |
| 3047 EXPECT_LT(quadVisibleRect.width(), 100); | 3047 EXPECT_LT(quadVisibleRect.width(), 100); |
| 3048 | 3048 |
| 3049 quadVisibleRect = frame.renderPasses[0]->quadList()[1]->quadVisibleRect(
); | 3049 quadVisibleRect = frame.renderPasses[0]->quadList()[1]->quadVisibleRect(
); |
| 3050 EXPECT_LT(quadVisibleRect.width(), 100); | 3050 EXPECT_LT(quadVisibleRect.width(), 100); |
| 3051 | 3051 |
| 3052 // Verify that the render surface texture is *not* clipped. | 3052 // Verify that the render surface texture is *not* clipped. |
| 3053 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), frame.renderPasses[0]->outputRec
t()); | 3053 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), frame.renderPasses[0]->outputRec
t()); |
| 3054 | 3054 |
| 3055 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->
material()); | 3055 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->ma
terial()); |
| 3056 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[1]->quadList()[0]); | 3056 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[1]->quadList()[0]); |
| 3057 EXPECT_FALSE(quad->contentsChangedSinceLastFrame().isEmpty()); | 3057 EXPECT_FALSE(quad->contentsChangedSinceLastFrame().isEmpty()); |
| 3058 | 3058 |
| 3059 myHostImpl->drawLayers(frame); | 3059 myHostImpl->drawLayers(frame); |
| 3060 myHostImpl->didDrawAllLayers(frame); | 3060 myHostImpl->didDrawAllLayers(frame); |
| 3061 } | 3061 } |
| 3062 | 3062 |
| 3063 transform = surfaceLayerPtr->transform(); | 3063 transform = surfaceLayerPtr->transform(); |
| 3064 transform.translate(50, 50); | 3064 transform.translate(50, 50); |
| 3065 transform.rotate(-35); | 3065 transform.rotate(-35); |
| 3066 transform.translate(-50, -50); | 3066 transform.translate(-50, -50); |
| 3067 surfaceLayerPtr->setTransform(transform); | 3067 surfaceLayerPtr->setTransform(transform); |
| 3068 | 3068 |
| 3069 // The surface is now aligned again, and the clipped parts are exposed. | 3069 // The surface is now aligned again, and the clipped parts are exposed. |
| 3070 // Since the layers were clipped, even though the render surface size | 3070 // Since the layers were clipped, even though the render surface size |
| 3071 // was not changed, the texture should not be saved. | 3071 // was not changed, the texture should not be saved. |
| 3072 { | 3072 { |
| 3073 CCLayerTreeHostImpl::FrameData frame; | 3073 LayerTreeHostImpl::FrameData frame; |
| 3074 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3074 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3075 | 3075 |
| 3076 // Must receive two render passes, each with one quad | 3076 // Must receive two render passes, each with one quad |
| 3077 ASSERT_EQ(2U, frame.renderPasses.size()); | 3077 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3078 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); | 3078 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); |
| 3079 ASSERT_EQ(1U, frame.renderPasses[1]->quadList().size()); | 3079 ASSERT_EQ(1U, frame.renderPasses[1]->quadList().size()); |
| 3080 | 3080 |
| 3081 myHostImpl->drawLayers(frame); | 3081 myHostImpl->drawLayers(frame); |
| 3082 myHostImpl->didDrawAllLayers(frame); | 3082 myHostImpl->didDrawAllLayers(frame); |
| 3083 } | 3083 } |
| 3084 } | 3084 } |
| 3085 | 3085 |
| 3086 TEST_P(CCLayerTreeHostImplTest, textureCachingWithOcclusion) | 3086 TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusion) |
| 3087 { | 3087 { |
| 3088 CCSettings::setPartialSwapEnabled(false); | 3088 Settings::setPartialSwapEnabled(false); |
| 3089 | 3089 |
| 3090 CCLayerTreeSettings settings; | 3090 LayerTreeSettings settings; |
| 3091 settings.minimumOcclusionTrackingSize = IntSize(); | 3091 settings.minimumOcclusionTrackingSize = IntSize(); |
| 3092 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, this); | 3092 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this); |
| 3093 | 3093 |
| 3094 // Layers are structure as follows: | 3094 // Layers are structure as follows: |
| 3095 // | 3095 // |
| 3096 // R +-- S1 +- L10 (owning) | 3096 // R +-- S1 +- L10 (owning) |
| 3097 // | +- L11 | 3097 // | +- L11 |
| 3098 // | +- L12 | 3098 // | +- L12 |
| 3099 // | | 3099 // | |
| 3100 // +-- S2 +- L20 (owning) | 3100 // +-- S2 +- L20 (owning) |
| 3101 // +- L21 | 3101 // +- L21 |
| 3102 // | 3102 // |
| 3103 // Occlusion: | 3103 // Occlusion: |
| 3104 // L12 occludes L11 (internal) | 3104 // L12 occludes L11 (internal) |
| 3105 // L20 occludes L10 (external) | 3105 // L20 occludes L10 (external) |
| 3106 // L21 occludes L20 (internal) | 3106 // L21 occludes L20 (internal) |
| 3107 | 3107 |
| 3108 CCLayerImpl* rootPtr; | 3108 LayerImpl* rootPtr; |
| 3109 CCLayerImpl* layerS1Ptr; | 3109 LayerImpl* layerS1Ptr; |
| 3110 CCLayerImpl* layerS2Ptr; | 3110 LayerImpl* layerS2Ptr; |
| 3111 | 3111 |
| 3112 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<CCGr
aphicsContext>(); | 3112 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<Graphi
csContext>(); |
| 3113 | 3113 |
| 3114 IntSize rootSize(1000, 1000); | 3114 IntSize rootSize(1000, 1000); |
| 3115 | 3115 |
| 3116 myHostImpl->initializeRenderer(context.Pass()); | 3116 myHostImpl->initializeRenderer(context.Pass()); |
| 3117 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); | 3117 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); |
| 3118 | 3118 |
| 3119 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 3119 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 3120 rootPtr = root.get(); | 3120 rootPtr = root.get(); |
| 3121 | 3121 |
| 3122 root->setAnchorPoint(FloatPoint(0, 0)); | 3122 root->setAnchorPoint(FloatPoint(0, 0)); |
| 3123 root->setPosition(FloatPoint(0, 0)); | 3123 root->setPosition(FloatPoint(0, 0)); |
| 3124 root->setBounds(rootSize); | 3124 root->setBounds(rootSize); |
| 3125 root->setContentBounds(rootSize); | 3125 root->setContentBounds(rootSize); |
| 3126 root->setDrawsContent(true); | 3126 root->setDrawsContent(true); |
| 3127 root->setMasksToBounds(true); | 3127 root->setMasksToBounds(true); |
| 3128 myHostImpl->setRootLayer(root.Pass()); | 3128 myHostImpl->setRootLayer(root.Pass()); |
| 3129 | 3129 |
| 3130 addDrawingLayerTo(rootPtr, 2, IntRect(300, 300, 300, 300), &layerS1Ptr); | 3130 addDrawingLayerTo(rootPtr, 2, IntRect(300, 300, 300, 300), &layerS1Ptr); |
| 3131 layerS1Ptr->setForceRenderSurface(true); | 3131 layerS1Ptr->setForceRenderSurface(true); |
| 3132 | 3132 |
| 3133 addDrawingLayerTo(layerS1Ptr, 3, IntRect(10, 10, 10, 10), 0); // L11 | 3133 addDrawingLayerTo(layerS1Ptr, 3, IntRect(10, 10, 10, 10), 0); // L11 |
| 3134 addDrawingLayerTo(layerS1Ptr, 4, IntRect(0, 0, 30, 30), 0); // L12 | 3134 addDrawingLayerTo(layerS1Ptr, 4, IntRect(0, 0, 30, 30), 0); // L12 |
| 3135 | 3135 |
| 3136 addDrawingLayerTo(rootPtr, 5, IntRect(550, 250, 300, 400), &layerS2Ptr); | 3136 addDrawingLayerTo(rootPtr, 5, IntRect(550, 250, 300, 400), &layerS2Ptr); |
| 3137 layerS2Ptr->setForceRenderSurface(true); | 3137 layerS2Ptr->setForceRenderSurface(true); |
| 3138 | 3138 |
| 3139 addDrawingLayerTo(layerS2Ptr, 6, IntRect(20, 20, 5, 5), 0); // L21 | 3139 addDrawingLayerTo(layerS2Ptr, 6, IntRect(20, 20, 5, 5), 0); // L21 |
| 3140 | 3140 |
| 3141 // Initial draw - must receive all quads | 3141 // Initial draw - must receive all quads |
| 3142 { | 3142 { |
| 3143 CCLayerTreeHostImpl::FrameData frame; | 3143 LayerTreeHostImpl::FrameData frame; |
| 3144 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3144 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3145 | 3145 |
| 3146 // Must receive 3 render passes. | 3146 // Must receive 3 render passes. |
| 3147 // For Root, there are 2 quads; for S1, there are 2 quads (1 is occluded
); for S2, there is 2 quads. | 3147 // For Root, there are 2 quads; for S1, there are 2 quads (1 is occluded
); for S2, there is 2 quads. |
| 3148 ASSERT_EQ(3U, frame.renderPasses.size()); | 3148 ASSERT_EQ(3U, frame.renderPasses.size()); |
| 3149 | 3149 |
| 3150 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); | 3150 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); |
| 3151 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); | 3151 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); |
| 3152 EXPECT_EQ(2U, frame.renderPasses[2]->quadList().size()); | 3152 EXPECT_EQ(2U, frame.renderPasses[2]->quadList().size()); |
| 3153 | 3153 |
| 3154 myHostImpl->drawLayers(frame); | 3154 myHostImpl->drawLayers(frame); |
| 3155 myHostImpl->didDrawAllLayers(frame); | 3155 myHostImpl->didDrawAllLayers(frame); |
| 3156 } | 3156 } |
| 3157 | 3157 |
| 3158 // "Unocclude" surface S1 and repeat draw. | 3158 // "Unocclude" surface S1 and repeat draw. |
| 3159 // Must remove S2's render pass since it's cached; | 3159 // Must remove S2's render pass since it's cached; |
| 3160 // Must keep S1 quads because texture contained external occlusion. | 3160 // Must keep S1 quads because texture contained external occlusion. |
| 3161 WebTransformationMatrix transform = layerS2Ptr->transform(); | 3161 WebTransformationMatrix transform = layerS2Ptr->transform(); |
| 3162 transform.translate(150, 150); | 3162 transform.translate(150, 150); |
| 3163 layerS2Ptr->setTransform(transform); | 3163 layerS2Ptr->setTransform(transform); |
| 3164 { | 3164 { |
| 3165 CCLayerTreeHostImpl::FrameData frame; | 3165 LayerTreeHostImpl::FrameData frame; |
| 3166 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3166 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3167 | 3167 |
| 3168 // Must receive 2 render passes. | 3168 // Must receive 2 render passes. |
| 3169 // For Root, there are 2 quads | 3169 // For Root, there are 2 quads |
| 3170 // For S1, the number of quads depends on what got unoccluded, so not as
serted beyond being positive. | 3170 // For S1, the number of quads depends on what got unoccluded, so not as
serted beyond being positive. |
| 3171 // For S2, there is no render pass | 3171 // For S2, there is no render pass |
| 3172 ASSERT_EQ(2U, frame.renderPasses.size()); | 3172 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3173 | 3173 |
| 3174 EXPECT_GT(frame.renderPasses[0]->quadList().size(), 0U); | 3174 EXPECT_GT(frame.renderPasses[0]->quadList().size(), 0U); |
| 3175 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); | 3175 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); |
| 3176 | 3176 |
| 3177 myHostImpl->drawLayers(frame); | 3177 myHostImpl->drawLayers(frame); |
| 3178 myHostImpl->didDrawAllLayers(frame); | 3178 myHostImpl->didDrawAllLayers(frame); |
| 3179 } | 3179 } |
| 3180 | 3180 |
| 3181 // "Re-occlude" surface S1 and repeat draw. | 3181 // "Re-occlude" surface S1 and repeat draw. |
| 3182 // Must remove S1's render pass since it is now available in full. | 3182 // Must remove S1's render pass since it is now available in full. |
| 3183 // S2 has no change so must also be removed. | 3183 // S2 has no change so must also be removed. |
| 3184 transform = layerS2Ptr->transform(); | 3184 transform = layerS2Ptr->transform(); |
| 3185 transform.translate(-15, -15); | 3185 transform.translate(-15, -15); |
| 3186 layerS2Ptr->setTransform(transform); | 3186 layerS2Ptr->setTransform(transform); |
| 3187 { | 3187 { |
| 3188 CCLayerTreeHostImpl::FrameData frame; | 3188 LayerTreeHostImpl::FrameData frame; |
| 3189 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3189 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3190 | 3190 |
| 3191 // Must receive 1 render pass - for the root. | 3191 // Must receive 1 render pass - for the root. |
| 3192 ASSERT_EQ(1U, frame.renderPasses.size()); | 3192 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3193 | 3193 |
| 3194 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); | 3194 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); |
| 3195 | 3195 |
| 3196 myHostImpl->drawLayers(frame); | 3196 myHostImpl->drawLayers(frame); |
| 3197 myHostImpl->didDrawAllLayers(frame); | 3197 myHostImpl->didDrawAllLayers(frame); |
| 3198 } | 3198 } |
| 3199 | 3199 |
| 3200 } | 3200 } |
| 3201 | 3201 |
| 3202 TEST_P(CCLayerTreeHostImplTest, textureCachingWithOcclusionEarlyOut) | 3202 TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionEarlyOut) |
| 3203 { | 3203 { |
| 3204 CCSettings::setPartialSwapEnabled(false); | 3204 Settings::setPartialSwapEnabled(false); |
| 3205 | 3205 |
| 3206 CCLayerTreeSettings settings; | 3206 LayerTreeSettings settings; |
| 3207 settings.minimumOcclusionTrackingSize = IntSize(); | 3207 settings.minimumOcclusionTrackingSize = IntSize(); |
| 3208 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, this); | 3208 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this); |
| 3209 | 3209 |
| 3210 // Layers are structure as follows: | 3210 // Layers are structure as follows: |
| 3211 // | 3211 // |
| 3212 // R +-- S1 +- L10 (owning, non drawing) | 3212 // R +-- S1 +- L10 (owning, non drawing) |
| 3213 // | +- L11 (corner, unoccluded) | 3213 // | +- L11 (corner, unoccluded) |
| 3214 // | +- L12 (corner, unoccluded) | 3214 // | +- L12 (corner, unoccluded) |
| 3215 // | +- L13 (corner, unoccluded) | 3215 // | +- L13 (corner, unoccluded) |
| 3216 // | +- L14 (corner, entirely occluded) | 3216 // | +- L14 (corner, entirely occluded) |
| 3217 // | | 3217 // | |
| 3218 // +-- S2 +- L20 (owning, drawing) | 3218 // +-- S2 +- L20 (owning, drawing) |
| 3219 // | 3219 // |
| 3220 | 3220 |
| 3221 CCLayerImpl* rootPtr; | 3221 LayerImpl* rootPtr; |
| 3222 CCLayerImpl* layerS1Ptr; | 3222 LayerImpl* layerS1Ptr; |
| 3223 CCLayerImpl* layerS2Ptr; | 3223 LayerImpl* layerS2Ptr; |
| 3224 | 3224 |
| 3225 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<CCGr
aphicsContext>(); | 3225 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<Graphi
csContext>(); |
| 3226 | 3226 |
| 3227 IntSize rootSize(1000, 1000); | 3227 IntSize rootSize(1000, 1000); |
| 3228 | 3228 |
| 3229 myHostImpl->initializeRenderer(context.Pass()); | 3229 myHostImpl->initializeRenderer(context.Pass()); |
| 3230 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); | 3230 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); |
| 3231 | 3231 |
| 3232 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 3232 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 3233 rootPtr = root.get(); | 3233 rootPtr = root.get(); |
| 3234 | 3234 |
| 3235 root->setAnchorPoint(FloatPoint(0, 0)); | 3235 root->setAnchorPoint(FloatPoint(0, 0)); |
| 3236 root->setPosition(FloatPoint(0, 0)); | 3236 root->setPosition(FloatPoint(0, 0)); |
| 3237 root->setBounds(rootSize); | 3237 root->setBounds(rootSize); |
| 3238 root->setContentBounds(rootSize); | 3238 root->setContentBounds(rootSize); |
| 3239 root->setDrawsContent(true); | 3239 root->setDrawsContent(true); |
| 3240 root->setMasksToBounds(true); | 3240 root->setMasksToBounds(true); |
| 3241 myHostImpl->setRootLayer(root.Pass()); | 3241 myHostImpl->setRootLayer(root.Pass()); |
| 3242 | 3242 |
| 3243 addDrawingLayerTo(rootPtr, 2, IntRect(0, 0, 800, 800), &layerS1Ptr); | 3243 addDrawingLayerTo(rootPtr, 2, IntRect(0, 0, 800, 800), &layerS1Ptr); |
| 3244 layerS1Ptr->setForceRenderSurface(true); | 3244 layerS1Ptr->setForceRenderSurface(true); |
| 3245 layerS1Ptr->setDrawsContent(false); | 3245 layerS1Ptr->setDrawsContent(false); |
| 3246 | 3246 |
| 3247 addDrawingLayerTo(layerS1Ptr, 3, IntRect(0, 0, 300, 300), 0); // L11 | 3247 addDrawingLayerTo(layerS1Ptr, 3, IntRect(0, 0, 300, 300), 0); // L11 |
| 3248 addDrawingLayerTo(layerS1Ptr, 4, IntRect(0, 500, 300, 300), 0); // L12 | 3248 addDrawingLayerTo(layerS1Ptr, 4, IntRect(0, 500, 300, 300), 0); // L12 |
| 3249 addDrawingLayerTo(layerS1Ptr, 5, IntRect(500, 0, 300, 300), 0); // L13 | 3249 addDrawingLayerTo(layerS1Ptr, 5, IntRect(500, 0, 300, 300), 0); // L13 |
| 3250 addDrawingLayerTo(layerS1Ptr, 6, IntRect(500, 500, 300, 300), 0); // L14 | 3250 addDrawingLayerTo(layerS1Ptr, 6, IntRect(500, 500, 300, 300), 0); // L14 |
| 3251 addDrawingLayerTo(layerS1Ptr, 9, IntRect(500, 500, 300, 300), 0); // L14 | 3251 addDrawingLayerTo(layerS1Ptr, 9, IntRect(500, 500, 300, 300), 0); // L14 |
| 3252 | 3252 |
| 3253 addDrawingLayerTo(rootPtr, 7, IntRect(450, 450, 450, 450), &layerS2Ptr); | 3253 addDrawingLayerTo(rootPtr, 7, IntRect(450, 450, 450, 450), &layerS2Ptr); |
| 3254 layerS2Ptr->setForceRenderSurface(true); | 3254 layerS2Ptr->setForceRenderSurface(true); |
| 3255 | 3255 |
| 3256 // Initial draw - must receive all quads | 3256 // Initial draw - must receive all quads |
| 3257 { | 3257 { |
| 3258 CCLayerTreeHostImpl::FrameData frame; | 3258 LayerTreeHostImpl::FrameData frame; |
| 3259 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3259 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3260 | 3260 |
| 3261 // Must receive 3 render passes. | 3261 // Must receive 3 render passes. |
| 3262 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there
is 1 quad. | 3262 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there
is 1 quad. |
| 3263 ASSERT_EQ(3U, frame.renderPasses.size()); | 3263 ASSERT_EQ(3U, frame.renderPasses.size()); |
| 3264 | 3264 |
| 3265 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3265 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3266 | 3266 |
| 3267 // L14 is culled, so only 3 quads. | 3267 // L14 is culled, so only 3 quads. |
| 3268 EXPECT_EQ(3U, frame.renderPasses[1]->quadList().size()); | 3268 EXPECT_EQ(3U, frame.renderPasses[1]->quadList().size()); |
| 3269 EXPECT_EQ(2U, frame.renderPasses[2]->quadList().size()); | 3269 EXPECT_EQ(2U, frame.renderPasses[2]->quadList().size()); |
| 3270 | 3270 |
| 3271 myHostImpl->drawLayers(frame); | 3271 myHostImpl->drawLayers(frame); |
| 3272 myHostImpl->didDrawAllLayers(frame); | 3272 myHostImpl->didDrawAllLayers(frame); |
| 3273 } | 3273 } |
| 3274 | 3274 |
| 3275 // "Unocclude" surface S1 and repeat draw. | 3275 // "Unocclude" surface S1 and repeat draw. |
| 3276 // Must remove S2's render pass since it's cached; | 3276 // Must remove S2's render pass since it's cached; |
| 3277 // Must keep S1 quads because texture contained external occlusion. | 3277 // Must keep S1 quads because texture contained external occlusion. |
| 3278 WebTransformationMatrix transform = layerS2Ptr->transform(); | 3278 WebTransformationMatrix transform = layerS2Ptr->transform(); |
| 3279 transform.translate(100, 100); | 3279 transform.translate(100, 100); |
| 3280 layerS2Ptr->setTransform(transform); | 3280 layerS2Ptr->setTransform(transform); |
| 3281 { | 3281 { |
| 3282 CCLayerTreeHostImpl::FrameData frame; | 3282 LayerTreeHostImpl::FrameData frame; |
| 3283 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3283 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3284 | 3284 |
| 3285 // Must receive 2 render passes. | 3285 // Must receive 2 render passes. |
| 3286 // For Root, there are 2 quads | 3286 // For Root, there are 2 quads |
| 3287 // For S1, the number of quads depends on what got unoccluded, so not as
serted beyond being positive. | 3287 // For S1, the number of quads depends on what got unoccluded, so not as
serted beyond being positive. |
| 3288 // For S2, there is no render pass | 3288 // For S2, there is no render pass |
| 3289 ASSERT_EQ(2U, frame.renderPasses.size()); | 3289 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3290 | 3290 |
| 3291 EXPECT_GT(frame.renderPasses[0]->quadList().size(), 0U); | 3291 EXPECT_GT(frame.renderPasses[0]->quadList().size(), 0U); |
| 3292 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); | 3292 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); |
| 3293 | 3293 |
| 3294 myHostImpl->drawLayers(frame); | 3294 myHostImpl->drawLayers(frame); |
| 3295 myHostImpl->didDrawAllLayers(frame); | 3295 myHostImpl->didDrawAllLayers(frame); |
| 3296 } | 3296 } |
| 3297 | 3297 |
| 3298 // "Re-occlude" surface S1 and repeat draw. | 3298 // "Re-occlude" surface S1 and repeat draw. |
| 3299 // Must remove S1's render pass since it is now available in full. | 3299 // Must remove S1's render pass since it is now available in full. |
| 3300 // S2 has no change so must also be removed. | 3300 // S2 has no change so must also be removed. |
| 3301 transform = layerS2Ptr->transform(); | 3301 transform = layerS2Ptr->transform(); |
| 3302 transform.translate(-15, -15); | 3302 transform.translate(-15, -15); |
| 3303 layerS2Ptr->setTransform(transform); | 3303 layerS2Ptr->setTransform(transform); |
| 3304 { | 3304 { |
| 3305 CCLayerTreeHostImpl::FrameData frame; | 3305 LayerTreeHostImpl::FrameData frame; |
| 3306 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3306 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3307 | 3307 |
| 3308 // Must receive 1 render pass - for the root. | 3308 // Must receive 1 render pass - for the root. |
| 3309 ASSERT_EQ(1U, frame.renderPasses.size()); | 3309 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3310 | 3310 |
| 3311 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); | 3311 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); |
| 3312 | 3312 |
| 3313 myHostImpl->drawLayers(frame); | 3313 myHostImpl->drawLayers(frame); |
| 3314 myHostImpl->didDrawAllLayers(frame); | 3314 myHostImpl->didDrawAllLayers(frame); |
| 3315 } | 3315 } |
| 3316 } | 3316 } |
| 3317 | 3317 |
| 3318 TEST_P(CCLayerTreeHostImplTest, textureCachingWithOcclusionExternalOverInternal) | 3318 TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionExternalOverInternal) |
| 3319 { | 3319 { |
| 3320 CCSettings::setPartialSwapEnabled(false); | 3320 Settings::setPartialSwapEnabled(false); |
| 3321 | 3321 |
| 3322 CCLayerTreeSettings settings; | 3322 LayerTreeSettings settings; |
| 3323 settings.minimumOcclusionTrackingSize = IntSize(); | 3323 settings.minimumOcclusionTrackingSize = IntSize(); |
| 3324 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, this); | 3324 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this); |
| 3325 | 3325 |
| 3326 // Layers are structured as follows: | 3326 // Layers are structured as follows: |
| 3327 // | 3327 // |
| 3328 // R +-- S1 +- L10 (owning, drawing) | 3328 // R +-- S1 +- L10 (owning, drawing) |
| 3329 // | +- L11 (corner, occluded by L12) | 3329 // | +- L11 (corner, occluded by L12) |
| 3330 // | +- L12 (opposite corner) | 3330 // | +- L12 (opposite corner) |
| 3331 // | | 3331 // | |
| 3332 // +-- S2 +- L20 (owning, drawing) | 3332 // +-- S2 +- L20 (owning, drawing) |
| 3333 // | 3333 // |
| 3334 | 3334 |
| 3335 CCLayerImpl* rootPtr; | 3335 LayerImpl* rootPtr; |
| 3336 CCLayerImpl* layerS1Ptr; | 3336 LayerImpl* layerS1Ptr; |
| 3337 CCLayerImpl* layerS2Ptr; | 3337 LayerImpl* layerS2Ptr; |
| 3338 | 3338 |
| 3339 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<CCGr
aphicsContext>(); | 3339 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<Graphi
csContext>(); |
| 3340 | 3340 |
| 3341 IntSize rootSize(1000, 1000); | 3341 IntSize rootSize(1000, 1000); |
| 3342 | 3342 |
| 3343 myHostImpl->initializeRenderer(context.Pass()); | 3343 myHostImpl->initializeRenderer(context.Pass()); |
| 3344 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); | 3344 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); |
| 3345 | 3345 |
| 3346 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 3346 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 3347 rootPtr = root.get(); | 3347 rootPtr = root.get(); |
| 3348 | 3348 |
| 3349 root->setAnchorPoint(FloatPoint(0, 0)); | 3349 root->setAnchorPoint(FloatPoint(0, 0)); |
| 3350 root->setPosition(FloatPoint(0, 0)); | 3350 root->setPosition(FloatPoint(0, 0)); |
| 3351 root->setBounds(rootSize); | 3351 root->setBounds(rootSize); |
| 3352 root->setContentBounds(rootSize); | 3352 root->setContentBounds(rootSize); |
| 3353 root->setDrawsContent(true); | 3353 root->setDrawsContent(true); |
| 3354 root->setMasksToBounds(true); | 3354 root->setMasksToBounds(true); |
| 3355 myHostImpl->setRootLayer(root.Pass()); | 3355 myHostImpl->setRootLayer(root.Pass()); |
| 3356 | 3356 |
| 3357 addDrawingLayerTo(rootPtr, 2, IntRect(0, 0, 400, 400), &layerS1Ptr); | 3357 addDrawingLayerTo(rootPtr, 2, IntRect(0, 0, 400, 400), &layerS1Ptr); |
| 3358 layerS1Ptr->setForceRenderSurface(true); | 3358 layerS1Ptr->setForceRenderSurface(true); |
| 3359 | 3359 |
| 3360 addDrawingLayerTo(layerS1Ptr, 3, IntRect(0, 0, 300, 300), 0); // L11 | 3360 addDrawingLayerTo(layerS1Ptr, 3, IntRect(0, 0, 300, 300), 0); // L11 |
| 3361 addDrawingLayerTo(layerS1Ptr, 4, IntRect(100, 0, 300, 300), 0); // L12 | 3361 addDrawingLayerTo(layerS1Ptr, 4, IntRect(100, 0, 300, 300), 0); // L12 |
| 3362 | 3362 |
| 3363 addDrawingLayerTo(rootPtr, 7, IntRect(200, 0, 300, 300), &layerS2Ptr); | 3363 addDrawingLayerTo(rootPtr, 7, IntRect(200, 0, 300, 300), &layerS2Ptr); |
| 3364 layerS2Ptr->setForceRenderSurface(true); | 3364 layerS2Ptr->setForceRenderSurface(true); |
| 3365 | 3365 |
| 3366 // Initial draw - must receive all quads | 3366 // Initial draw - must receive all quads |
| 3367 { | 3367 { |
| 3368 CCLayerTreeHostImpl::FrameData frame; | 3368 LayerTreeHostImpl::FrameData frame; |
| 3369 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3369 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3370 | 3370 |
| 3371 // Must receive 3 render passes. | 3371 // Must receive 3 render passes. |
| 3372 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there
is 1 quad. | 3372 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there
is 1 quad. |
| 3373 ASSERT_EQ(3U, frame.renderPasses.size()); | 3373 ASSERT_EQ(3U, frame.renderPasses.size()); |
| 3374 | 3374 |
| 3375 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3375 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3376 EXPECT_EQ(3U, frame.renderPasses[1]->quadList().size()); | 3376 EXPECT_EQ(3U, frame.renderPasses[1]->quadList().size()); |
| 3377 EXPECT_EQ(2U, frame.renderPasses[2]->quadList().size()); | 3377 EXPECT_EQ(2U, frame.renderPasses[2]->quadList().size()); |
| 3378 | 3378 |
| 3379 myHostImpl->drawLayers(frame); | 3379 myHostImpl->drawLayers(frame); |
| 3380 myHostImpl->didDrawAllLayers(frame); | 3380 myHostImpl->didDrawAllLayers(frame); |
| 3381 } | 3381 } |
| 3382 | 3382 |
| 3383 // "Unocclude" surface S1 and repeat draw. | 3383 // "Unocclude" surface S1 and repeat draw. |
| 3384 // Must remove S2's render pass since it's cached; | 3384 // Must remove S2's render pass since it's cached; |
| 3385 // Must keep S1 quads because texture contained external occlusion. | 3385 // Must keep S1 quads because texture contained external occlusion. |
| 3386 WebTransformationMatrix transform = layerS2Ptr->transform(); | 3386 WebTransformationMatrix transform = layerS2Ptr->transform(); |
| 3387 transform.translate(300, 0); | 3387 transform.translate(300, 0); |
| 3388 layerS2Ptr->setTransform(transform); | 3388 layerS2Ptr->setTransform(transform); |
| 3389 { | 3389 { |
| 3390 CCLayerTreeHostImpl::FrameData frame; | 3390 LayerTreeHostImpl::FrameData frame; |
| 3391 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3391 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3392 | 3392 |
| 3393 // Must receive 2 render passes. | 3393 // Must receive 2 render passes. |
| 3394 // For Root, there are 2 quads | 3394 // For Root, there are 2 quads |
| 3395 // For S1, the number of quads depends on what got unoccluded, so not as
serted beyond being positive. | 3395 // For S1, the number of quads depends on what got unoccluded, so not as
serted beyond being positive. |
| 3396 // For S2, there is no render pass | 3396 // For S2, there is no render pass |
| 3397 ASSERT_EQ(2U, frame.renderPasses.size()); | 3397 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3398 | 3398 |
| 3399 EXPECT_GT(frame.renderPasses[0]->quadList().size(), 0U); | 3399 EXPECT_GT(frame.renderPasses[0]->quadList().size(), 0U); |
| 3400 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); | 3400 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); |
| 3401 | 3401 |
| 3402 myHostImpl->drawLayers(frame); | 3402 myHostImpl->drawLayers(frame); |
| 3403 myHostImpl->didDrawAllLayers(frame); | 3403 myHostImpl->didDrawAllLayers(frame); |
| 3404 } | 3404 } |
| 3405 } | 3405 } |
| 3406 | 3406 |
| 3407 TEST_P(CCLayerTreeHostImplTest, textureCachingWithOcclusionExternalNotAligned) | 3407 TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionExternalNotAligned) |
| 3408 { | 3408 { |
| 3409 CCSettings::setPartialSwapEnabled(false); | 3409 Settings::setPartialSwapEnabled(false); |
| 3410 | 3410 |
| 3411 CCLayerTreeSettings settings; | 3411 LayerTreeSettings settings; |
| 3412 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, this); | 3412 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this); |
| 3413 | 3413 |
| 3414 // Layers are structured as follows: | 3414 // Layers are structured as follows: |
| 3415 // | 3415 // |
| 3416 // R +-- S1 +- L10 (rotated, drawing) | 3416 // R +-- S1 +- L10 (rotated, drawing) |
| 3417 // +- L11 (occupies half surface) | 3417 // +- L11 (occupies half surface) |
| 3418 | 3418 |
| 3419 CCLayerImpl* rootPtr; | 3419 LayerImpl* rootPtr; |
| 3420 CCLayerImpl* layerS1Ptr; | 3420 LayerImpl* layerS1Ptr; |
| 3421 | 3421 |
| 3422 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<CCGr
aphicsContext>(); | 3422 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<Graphi
csContext>(); |
| 3423 | 3423 |
| 3424 IntSize rootSize(1000, 1000); | 3424 IntSize rootSize(1000, 1000); |
| 3425 | 3425 |
| 3426 myHostImpl->initializeRenderer(context.Pass()); | 3426 myHostImpl->initializeRenderer(context.Pass()); |
| 3427 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); | 3427 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); |
| 3428 | 3428 |
| 3429 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 3429 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 3430 rootPtr = root.get(); | 3430 rootPtr = root.get(); |
| 3431 | 3431 |
| 3432 root->setAnchorPoint(FloatPoint(0, 0)); | 3432 root->setAnchorPoint(FloatPoint(0, 0)); |
| 3433 root->setPosition(FloatPoint(0, 0)); | 3433 root->setPosition(FloatPoint(0, 0)); |
| 3434 root->setBounds(rootSize); | 3434 root->setBounds(rootSize); |
| 3435 root->setContentBounds(rootSize); | 3435 root->setContentBounds(rootSize); |
| 3436 root->setDrawsContent(true); | 3436 root->setDrawsContent(true); |
| 3437 root->setMasksToBounds(true); | 3437 root->setMasksToBounds(true); |
| 3438 myHostImpl->setRootLayer(root.Pass()); | 3438 myHostImpl->setRootLayer(root.Pass()); |
| 3439 | 3439 |
| 3440 addDrawingLayerTo(rootPtr, 2, IntRect(0, 0, 400, 400), &layerS1Ptr); | 3440 addDrawingLayerTo(rootPtr, 2, IntRect(0, 0, 400, 400), &layerS1Ptr); |
| 3441 layerS1Ptr->setForceRenderSurface(true); | 3441 layerS1Ptr->setForceRenderSurface(true); |
| 3442 WebTransformationMatrix transform = layerS1Ptr->transform(); | 3442 WebTransformationMatrix transform = layerS1Ptr->transform(); |
| 3443 transform.translate(200, 200); | 3443 transform.translate(200, 200); |
| 3444 transform.rotate(45); | 3444 transform.rotate(45); |
| 3445 transform.translate(-200, -200); | 3445 transform.translate(-200, -200); |
| 3446 layerS1Ptr->setTransform(transform); | 3446 layerS1Ptr->setTransform(transform); |
| 3447 | 3447 |
| 3448 addDrawingLayerTo(layerS1Ptr, 3, IntRect(200, 0, 200, 400), 0); // L11 | 3448 addDrawingLayerTo(layerS1Ptr, 3, IntRect(200, 0, 200, 400), 0); // L11 |
| 3449 | 3449 |
| 3450 // Initial draw - must receive all quads | 3450 // Initial draw - must receive all quads |
| 3451 { | 3451 { |
| 3452 CCLayerTreeHostImpl::FrameData frame; | 3452 LayerTreeHostImpl::FrameData frame; |
| 3453 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3453 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3454 | 3454 |
| 3455 // Must receive 2 render passes. | 3455 // Must receive 2 render passes. |
| 3456 ASSERT_EQ(2U, frame.renderPasses.size()); | 3456 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3457 | 3457 |
| 3458 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); | 3458 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); |
| 3459 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); | 3459 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); |
| 3460 | 3460 |
| 3461 myHostImpl->drawLayers(frame); | 3461 myHostImpl->drawLayers(frame); |
| 3462 myHostImpl->didDrawAllLayers(frame); | 3462 myHostImpl->didDrawAllLayers(frame); |
| 3463 } | 3463 } |
| 3464 | 3464 |
| 3465 // Change opacity and draw. Verify we used cached texture. | 3465 // Change opacity and draw. Verify we used cached texture. |
| 3466 layerS1Ptr->setOpacity(0.2f); | 3466 layerS1Ptr->setOpacity(0.2f); |
| 3467 { | 3467 { |
| 3468 CCLayerTreeHostImpl::FrameData frame; | 3468 LayerTreeHostImpl::FrameData frame; |
| 3469 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3469 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3470 | 3470 |
| 3471 // One render pass must be gone due to cached texture. | 3471 // One render pass must be gone due to cached texture. |
| 3472 ASSERT_EQ(1U, frame.renderPasses.size()); | 3472 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3473 | 3473 |
| 3474 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3474 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3475 | 3475 |
| 3476 myHostImpl->drawLayers(frame); | 3476 myHostImpl->drawLayers(frame); |
| 3477 myHostImpl->didDrawAllLayers(frame); | 3477 myHostImpl->didDrawAllLayers(frame); |
| 3478 } | 3478 } |
| 3479 } | 3479 } |
| 3480 | 3480 |
| 3481 TEST_P(CCLayerTreeHostImplTest, textureCachingWithOcclusionPartialSwap) | 3481 TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionPartialSwap) |
| 3482 { | 3482 { |
| 3483 CCSettings::setPartialSwapEnabled(true); | 3483 Settings::setPartialSwapEnabled(true); |
| 3484 | 3484 |
| 3485 CCLayerTreeSettings settings; | 3485 LayerTreeSettings settings; |
| 3486 settings.minimumOcclusionTrackingSize = IntSize(); | 3486 settings.minimumOcclusionTrackingSize = IntSize(); |
| 3487 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, this); | 3487 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this); |
| 3488 | 3488 |
| 3489 // Layers are structure as follows: | 3489 // Layers are structure as follows: |
| 3490 // | 3490 // |
| 3491 // R +-- S1 +- L10 (owning) | 3491 // R +-- S1 +- L10 (owning) |
| 3492 // | +- L11 | 3492 // | +- L11 |
| 3493 // | +- L12 | 3493 // | +- L12 |
| 3494 // | | 3494 // | |
| 3495 // +-- S2 +- L20 (owning) | 3495 // +-- S2 +- L20 (owning) |
| 3496 // +- L21 | 3496 // +- L21 |
| 3497 // | 3497 // |
| 3498 // Occlusion: | 3498 // Occlusion: |
| 3499 // L12 occludes L11 (internal) | 3499 // L12 occludes L11 (internal) |
| 3500 // L20 occludes L10 (external) | 3500 // L20 occludes L10 (external) |
| 3501 // L21 occludes L20 (internal) | 3501 // L21 occludes L20 (internal) |
| 3502 | 3502 |
| 3503 CCLayerImpl* rootPtr; | 3503 LayerImpl* rootPtr; |
| 3504 CCLayerImpl* layerS1Ptr; | 3504 LayerImpl* layerS1Ptr; |
| 3505 CCLayerImpl* layerS2Ptr; | 3505 LayerImpl* layerS2Ptr; |
| 3506 | 3506 |
| 3507 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<CCGr
aphicsContext>(); | 3507 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<Graphi
csContext>(); |
| 3508 | 3508 |
| 3509 IntSize rootSize(1000, 1000); | 3509 IntSize rootSize(1000, 1000); |
| 3510 | 3510 |
| 3511 myHostImpl->initializeRenderer(context.Pass()); | 3511 myHostImpl->initializeRenderer(context.Pass()); |
| 3512 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); | 3512 myHostImpl->setViewportSize(IntSize(rootSize.width(), rootSize.height()), In
tSize(rootSize.width(), rootSize.height())); |
| 3513 | 3513 |
| 3514 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 3514 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 3515 rootPtr = root.get(); | 3515 rootPtr = root.get(); |
| 3516 | 3516 |
| 3517 root->setAnchorPoint(FloatPoint(0, 0)); | 3517 root->setAnchorPoint(FloatPoint(0, 0)); |
| 3518 root->setPosition(FloatPoint(0, 0)); | 3518 root->setPosition(FloatPoint(0, 0)); |
| 3519 root->setBounds(rootSize); | 3519 root->setBounds(rootSize); |
| 3520 root->setContentBounds(rootSize); | 3520 root->setContentBounds(rootSize); |
| 3521 root->setDrawsContent(true); | 3521 root->setDrawsContent(true); |
| 3522 root->setMasksToBounds(true); | 3522 root->setMasksToBounds(true); |
| 3523 myHostImpl->setRootLayer(root.Pass()); | 3523 myHostImpl->setRootLayer(root.Pass()); |
| 3524 | 3524 |
| 3525 addDrawingLayerTo(rootPtr, 2, IntRect(300, 300, 300, 300), &layerS1Ptr); | 3525 addDrawingLayerTo(rootPtr, 2, IntRect(300, 300, 300, 300), &layerS1Ptr); |
| 3526 layerS1Ptr->setForceRenderSurface(true); | 3526 layerS1Ptr->setForceRenderSurface(true); |
| 3527 | 3527 |
| 3528 addDrawingLayerTo(layerS1Ptr, 3, IntRect(10, 10, 10, 10), 0); // L11 | 3528 addDrawingLayerTo(layerS1Ptr, 3, IntRect(10, 10, 10, 10), 0); // L11 |
| 3529 addDrawingLayerTo(layerS1Ptr, 4, IntRect(0, 0, 30, 30), 0); // L12 | 3529 addDrawingLayerTo(layerS1Ptr, 4, IntRect(0, 0, 30, 30), 0); // L12 |
| 3530 | 3530 |
| 3531 addDrawingLayerTo(rootPtr, 5, IntRect(550, 250, 300, 400), &layerS2Ptr); | 3531 addDrawingLayerTo(rootPtr, 5, IntRect(550, 250, 300, 400), &layerS2Ptr); |
| 3532 layerS2Ptr->setForceRenderSurface(true); | 3532 layerS2Ptr->setForceRenderSurface(true); |
| 3533 | 3533 |
| 3534 addDrawingLayerTo(layerS2Ptr, 6, IntRect(20, 20, 5, 5), 0); // L21 | 3534 addDrawingLayerTo(layerS2Ptr, 6, IntRect(20, 20, 5, 5), 0); // L21 |
| 3535 | 3535 |
| 3536 // Initial draw - must receive all quads | 3536 // Initial draw - must receive all quads |
| 3537 { | 3537 { |
| 3538 CCLayerTreeHostImpl::FrameData frame; | 3538 LayerTreeHostImpl::FrameData frame; |
| 3539 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3539 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3540 | 3540 |
| 3541 // Must receive 3 render passes. | 3541 // Must receive 3 render passes. |
| 3542 // For Root, there are 2 quads; for S1, there are 2 quads (one is occlud
ed); for S2, there is 2 quads. | 3542 // For Root, there are 2 quads; for S1, there are 2 quads (one is occlud
ed); for S2, there is 2 quads. |
| 3543 ASSERT_EQ(3U, frame.renderPasses.size()); | 3543 ASSERT_EQ(3U, frame.renderPasses.size()); |
| 3544 | 3544 |
| 3545 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); | 3545 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); |
| 3546 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); | 3546 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); |
| 3547 EXPECT_EQ(2U, frame.renderPasses[2]->quadList().size()); | 3547 EXPECT_EQ(2U, frame.renderPasses[2]->quadList().size()); |
| 3548 | 3548 |
| 3549 myHostImpl->drawLayers(frame); | 3549 myHostImpl->drawLayers(frame); |
| 3550 myHostImpl->didDrawAllLayers(frame); | 3550 myHostImpl->didDrawAllLayers(frame); |
| 3551 } | 3551 } |
| 3552 | 3552 |
| 3553 // "Unocclude" surface S1 and repeat draw. | 3553 // "Unocclude" surface S1 and repeat draw. |
| 3554 // Must remove S2's render pass since it's cached; | 3554 // Must remove S2's render pass since it's cached; |
| 3555 // Must keep S1 quads because texture contained external occlusion. | 3555 // Must keep S1 quads because texture contained external occlusion. |
| 3556 WebTransformationMatrix transform = layerS2Ptr->transform(); | 3556 WebTransformationMatrix transform = layerS2Ptr->transform(); |
| 3557 transform.translate(150, 150); | 3557 transform.translate(150, 150); |
| 3558 layerS2Ptr->setTransform(transform); | 3558 layerS2Ptr->setTransform(transform); |
| 3559 { | 3559 { |
| 3560 CCLayerTreeHostImpl::FrameData frame; | 3560 LayerTreeHostImpl::FrameData frame; |
| 3561 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3561 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3562 | 3562 |
| 3563 // Must receive 2 render passes. | 3563 // Must receive 2 render passes. |
| 3564 // For Root, there are 2 quads. | 3564 // For Root, there are 2 quads. |
| 3565 // For S1, there are 2 quads. | 3565 // For S1, there are 2 quads. |
| 3566 // For S2, there is no render pass | 3566 // For S2, there is no render pass |
| 3567 ASSERT_EQ(2U, frame.renderPasses.size()); | 3567 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3568 | 3568 |
| 3569 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); | 3569 EXPECT_EQ(2U, frame.renderPasses[0]->quadList().size()); |
| 3570 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); | 3570 EXPECT_EQ(2U, frame.renderPasses[1]->quadList().size()); |
| 3571 | 3571 |
| 3572 myHostImpl->drawLayers(frame); | 3572 myHostImpl->drawLayers(frame); |
| 3573 myHostImpl->didDrawAllLayers(frame); | 3573 myHostImpl->didDrawAllLayers(frame); |
| 3574 } | 3574 } |
| 3575 | 3575 |
| 3576 // "Re-occlude" surface S1 and repeat draw. | 3576 // "Re-occlude" surface S1 and repeat draw. |
| 3577 // Must remove S1's render pass since it is now available in full. | 3577 // Must remove S1's render pass since it is now available in full. |
| 3578 // S2 has no change so must also be removed. | 3578 // S2 has no change so must also be removed. |
| 3579 transform = layerS2Ptr->transform(); | 3579 transform = layerS2Ptr->transform(); |
| 3580 transform.translate(-15, -15); | 3580 transform.translate(-15, -15); |
| 3581 layerS2Ptr->setTransform(transform); | 3581 layerS2Ptr->setTransform(transform); |
| 3582 { | 3582 { |
| 3583 CCLayerTreeHostImpl::FrameData frame; | 3583 LayerTreeHostImpl::FrameData frame; |
| 3584 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3584 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3585 | 3585 |
| 3586 // Root render pass only. | 3586 // Root render pass only. |
| 3587 ASSERT_EQ(1U, frame.renderPasses.size()); | 3587 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3588 | 3588 |
| 3589 myHostImpl->drawLayers(frame); | 3589 myHostImpl->drawLayers(frame); |
| 3590 myHostImpl->didDrawAllLayers(frame); | 3590 myHostImpl->didDrawAllLayers(frame); |
| 3591 } | 3591 } |
| 3592 } | 3592 } |
| 3593 | 3593 |
| 3594 TEST_P(CCLayerTreeHostImplTest, textureCachingWithScissor) | 3594 TEST_P(LayerTreeHostImplTest, textureCachingWithScissor) |
| 3595 { | 3595 { |
| 3596 CCSettings::setPartialSwapEnabled(false); | 3596 Settings::setPartialSwapEnabled(false); |
| 3597 | 3597 |
| 3598 CCLayerTreeSettings settings; | 3598 LayerTreeSettings settings; |
| 3599 settings.minimumOcclusionTrackingSize = IntSize(); | 3599 settings.minimumOcclusionTrackingSize = IntSize(); |
| 3600 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, this); | 3600 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this); |
| 3601 | 3601 |
| 3602 /* | 3602 /* |
| 3603 Layers are created as follows: | 3603 Layers are created as follows: |
| 3604 | 3604 |
| 3605 +--------------------+ | 3605 +--------------------+ |
| 3606 | 1 | | 3606 | 1 | |
| 3607 | +-----------+ | | 3607 | +-----------+ | |
| 3608 | | 2 | | | 3608 | | 2 | | |
| 3609 | | +-------------------+ | 3609 | | +-------------------+ |
| 3610 | | | 3 | | 3610 | | | 3 | |
| 3611 | | +-------------------+ | 3611 | | +-------------------+ |
| 3612 | | | | | 3612 | | | | |
| 3613 | +-----------+ | | 3613 | +-----------+ | |
| 3614 | | | 3614 | | |
| 3615 | | | 3615 | | |
| 3616 +--------------------+ | 3616 +--------------------+ |
| 3617 | 3617 |
| 3618 Layers 1, 2 have render surfaces | 3618 Layers 1, 2 have render surfaces |
| 3619 */ | 3619 */ |
| 3620 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 3620 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 3621 scoped_ptr<CCTiledLayerImpl> child = CCTiledLayerImpl::create(2); | 3621 scoped_ptr<TiledLayerImpl> child = TiledLayerImpl::create(2); |
| 3622 scoped_ptr<CCLayerImpl> grandChild = CCLayerImpl::create(3); | 3622 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(3); |
| 3623 | 3623 |
| 3624 IntRect rootRect(0, 0, 100, 100); | 3624 IntRect rootRect(0, 0, 100, 100); |
| 3625 IntRect childRect(10, 10, 50, 50); | 3625 IntRect childRect(10, 10, 50, 50); |
| 3626 IntRect grandChildRect(5, 5, 150, 150); | 3626 IntRect grandChildRect(5, 5, 150, 150); |
| 3627 | 3627 |
| 3628 scoped_ptr<CCGraphicsContext> context = FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<CCGr
aphicsContext>(); | 3628 scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create
(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<Graphi
csContext>(); |
| 3629 myHostImpl->initializeRenderer(context.Pass()); | 3629 myHostImpl->initializeRenderer(context.Pass()); |
| 3630 | 3630 |
| 3631 root->setAnchorPoint(FloatPoint(0, 0)); | 3631 root->setAnchorPoint(FloatPoint(0, 0)); |
| 3632 root->setPosition(FloatPoint(rootRect.x(), rootRect.y())); | 3632 root->setPosition(FloatPoint(rootRect.x(), rootRect.y())); |
| 3633 root->setBounds(IntSize(rootRect.width(), rootRect.height())); | 3633 root->setBounds(IntSize(rootRect.width(), rootRect.height())); |
| 3634 root->setContentBounds(root->bounds()); | 3634 root->setContentBounds(root->bounds()); |
| 3635 root->setDrawsContent(true); | 3635 root->setDrawsContent(true); |
| 3636 root->setMasksToBounds(true); | 3636 root->setMasksToBounds(true); |
| 3637 | 3637 |
| 3638 child->setAnchorPoint(FloatPoint(0, 0)); | 3638 child->setAnchorPoint(FloatPoint(0, 0)); |
| 3639 child->setPosition(FloatPoint(childRect.x(), childRect.y())); | 3639 child->setPosition(FloatPoint(childRect.x(), childRect.y())); |
| 3640 child->setOpacity(0.5); | 3640 child->setOpacity(0.5); |
| 3641 child->setBounds(IntSize(childRect.width(), childRect.height())); | 3641 child->setBounds(IntSize(childRect.width(), childRect.height())); |
| 3642 child->setContentBounds(child->bounds()); | 3642 child->setContentBounds(child->bounds()); |
| 3643 child->setDrawsContent(true); | 3643 child->setDrawsContent(true); |
| 3644 child->setSkipsDraw(false); | 3644 child->setSkipsDraw(false); |
| 3645 | 3645 |
| 3646 // child layer has 10x10 tiles. | 3646 // child layer has 10x10 tiles. |
| 3647 scoped_ptr<CCLayerTilingData> tiler = CCLayerTilingData::create(IntSize(10,
10), CCLayerTilingData::HasBorderTexels); | 3647 scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(IntSize(10, 10),
LayerTilingData::HasBorderTexels); |
| 3648 tiler->setBounds(child->contentBounds()); | 3648 tiler->setBounds(child->contentBounds()); |
| 3649 child->setTilingData(*tiler.get()); | 3649 child->setTilingData(*tiler.get()); |
| 3650 | 3650 |
| 3651 grandChild->setAnchorPoint(FloatPoint(0, 0)); | 3651 grandChild->setAnchorPoint(FloatPoint(0, 0)); |
| 3652 grandChild->setPosition(IntPoint(grandChildRect.x(), grandChildRect.y())); | 3652 grandChild->setPosition(IntPoint(grandChildRect.x(), grandChildRect.y())); |
| 3653 grandChild->setBounds(IntSize(grandChildRect.width(), grandChildRect.height(
))); | 3653 grandChild->setBounds(IntSize(grandChildRect.width(), grandChildRect.height(
))); |
| 3654 grandChild->setContentBounds(grandChild->bounds()); | 3654 grandChild->setContentBounds(grandChild->bounds()); |
| 3655 grandChild->setDrawsContent(true); | 3655 grandChild->setDrawsContent(true); |
| 3656 | 3656 |
| 3657 CCTiledLayerImpl* childPtr = child.get(); | 3657 TiledLayerImpl* childPtr = child.get(); |
| 3658 CCRenderPass::Id childPassId(childPtr->id(), 0); | 3658 RenderPass::Id childPassId(childPtr->id(), 0); |
| 3659 | 3659 |
| 3660 child->addChild(grandChild.Pass()); | 3660 child->addChild(grandChild.Pass()); |
| 3661 root->addChild(child.PassAs<CCLayerImpl>()); | 3661 root->addChild(child.PassAs<LayerImpl>()); |
| 3662 myHostImpl->setRootLayer(root.Pass()); | 3662 myHostImpl->setRootLayer(root.Pass()); |
| 3663 myHostImpl->setViewportSize(rootRect.size(), rootRect.size()); | 3663 myHostImpl->setViewportSize(rootRect.size(), rootRect.size()); |
| 3664 | 3664 |
| 3665 EXPECT_FALSE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(chil
dPassId)); | 3665 EXPECT_FALSE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(chil
dPassId)); |
| 3666 | 3666 |
| 3667 { | 3667 { |
| 3668 CCLayerTreeHostImpl::FrameData frame; | 3668 LayerTreeHostImpl::FrameData frame; |
| 3669 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3669 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3670 myHostImpl->drawLayers(frame); | 3670 myHostImpl->drawLayers(frame); |
| 3671 myHostImpl->didDrawAllLayers(frame); | 3671 myHostImpl->didDrawAllLayers(frame); |
| 3672 } | 3672 } |
| 3673 | 3673 |
| 3674 // We should have cached textures for surface 2. | 3674 // We should have cached textures for surface 2. |
| 3675 EXPECT_TRUE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(child
PassId)); | 3675 EXPECT_TRUE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(child
PassId)); |
| 3676 | 3676 |
| 3677 { | 3677 { |
| 3678 CCLayerTreeHostImpl::FrameData frame; | 3678 LayerTreeHostImpl::FrameData frame; |
| 3679 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3679 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3680 myHostImpl->drawLayers(frame); | 3680 myHostImpl->drawLayers(frame); |
| 3681 myHostImpl->didDrawAllLayers(frame); | 3681 myHostImpl->didDrawAllLayers(frame); |
| 3682 } | 3682 } |
| 3683 | 3683 |
| 3684 // We should still have cached textures for surface 2 after drawing with no
damage. | 3684 // We should still have cached textures for surface 2 after drawing with no
damage. |
| 3685 EXPECT_TRUE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(child
PassId)); | 3685 EXPECT_TRUE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(child
PassId)); |
| 3686 | 3686 |
| 3687 // Damage a single tile of surface 2. | 3687 // Damage a single tile of surface 2. |
| 3688 childPtr->setUpdateRect(IntRect(10, 10, 10, 10)); | 3688 childPtr->setUpdateRect(IntRect(10, 10, 10, 10)); |
| 3689 | 3689 |
| 3690 { | 3690 { |
| 3691 CCLayerTreeHostImpl::FrameData frame; | 3691 LayerTreeHostImpl::FrameData frame; |
| 3692 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3692 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3693 myHostImpl->drawLayers(frame); | 3693 myHostImpl->drawLayers(frame); |
| 3694 myHostImpl->didDrawAllLayers(frame); | 3694 myHostImpl->didDrawAllLayers(frame); |
| 3695 } | 3695 } |
| 3696 | 3696 |
| 3697 // We should have a cached texture for surface 2 again even though it was da
maged. | 3697 // We should have a cached texture for surface 2 again even though it was da
maged. |
| 3698 EXPECT_TRUE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(child
PassId)); | 3698 EXPECT_TRUE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(child
PassId)); |
| 3699 } | 3699 } |
| 3700 | 3700 |
| 3701 TEST_P(CCLayerTreeHostImplTest, surfaceTextureCaching) | 3701 TEST_P(LayerTreeHostImplTest, surfaceTextureCaching) |
| 3702 { | 3702 { |
| 3703 CCSettings::setPartialSwapEnabled(true); | 3703 Settings::setPartialSwapEnabled(true); |
| 3704 | 3704 |
| 3705 CCLayerTreeSettings settings; | 3705 LayerTreeSettings settings; |
| 3706 settings.minimumOcclusionTrackingSize = IntSize(); | 3706 settings.minimumOcclusionTrackingSize = IntSize(); |
| 3707 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, this); | 3707 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this); |
| 3708 | 3708 |
| 3709 CCLayerImpl* rootPtr; | 3709 LayerImpl* rootPtr; |
| 3710 CCLayerImpl* intermediateLayerPtr; | 3710 LayerImpl* intermediateLayerPtr; |
| 3711 CCLayerImpl* surfaceLayerPtr; | 3711 LayerImpl* surfaceLayerPtr; |
| 3712 CCLayerImpl* childPtr; | 3712 LayerImpl* childPtr; |
| 3713 | 3713 |
| 3714 setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr
, surfaceLayerPtr, childPtr, IntSize(100, 100)); | 3714 setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr
, surfaceLayerPtr, childPtr, IntSize(100, 100)); |
| 3715 | 3715 |
| 3716 { | 3716 { |
| 3717 CCLayerTreeHostImpl::FrameData frame; | 3717 LayerTreeHostImpl::FrameData frame; |
| 3718 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3718 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3719 | 3719 |
| 3720 // Must receive two render passes, each with one quad | 3720 // Must receive two render passes, each with one quad |
| 3721 ASSERT_EQ(2U, frame.renderPasses.size()); | 3721 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3722 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3722 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3723 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); | 3723 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); |
| 3724 | 3724 |
| 3725 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->
material()); | 3725 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->ma
terial()); |
| 3726 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[1]->quadList()[0]); | 3726 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[1]->quadList()[0]); |
| 3727 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3727 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3728 EXPECT_FALSE(targetPass->damageRect().isEmpty()); | 3728 EXPECT_FALSE(targetPass->damageRect().isEmpty()); |
| 3729 | 3729 |
| 3730 myHostImpl->drawLayers(frame); | 3730 myHostImpl->drawLayers(frame); |
| 3731 myHostImpl->didDrawAllLayers(frame); | 3731 myHostImpl->didDrawAllLayers(frame); |
| 3732 } | 3732 } |
| 3733 | 3733 |
| 3734 // Draw without any change | 3734 // Draw without any change |
| 3735 { | 3735 { |
| 3736 CCLayerTreeHostImpl::FrameData frame; | 3736 LayerTreeHostImpl::FrameData frame; |
| 3737 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3737 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3738 | 3738 |
| 3739 // Must receive one render pass, as the other one should be culled | 3739 // Must receive one render pass, as the other one should be culled |
| 3740 ASSERT_EQ(1U, frame.renderPasses.size()); | 3740 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3741 | 3741 |
| 3742 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3742 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3743 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->
material()); | 3743 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 3744 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[0]->quadList()[0]); | 3744 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[0]->quadList()[0]); |
| 3745 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3745 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3746 EXPECT_TRUE(targetPass->damageRect().isEmpty()); | 3746 EXPECT_TRUE(targetPass->damageRect().isEmpty()); |
| 3747 | 3747 |
| 3748 myHostImpl->drawLayers(frame); | 3748 myHostImpl->drawLayers(frame); |
| 3749 myHostImpl->didDrawAllLayers(frame); | 3749 myHostImpl->didDrawAllLayers(frame); |
| 3750 } | 3750 } |
| 3751 | 3751 |
| 3752 // Change opacity and draw | 3752 // Change opacity and draw |
| 3753 surfaceLayerPtr->setOpacity(0.6f); | 3753 surfaceLayerPtr->setOpacity(0.6f); |
| 3754 { | 3754 { |
| 3755 CCLayerTreeHostImpl::FrameData frame; | 3755 LayerTreeHostImpl::FrameData frame; |
| 3756 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3756 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3757 | 3757 |
| 3758 // Must receive one render pass, as the other one should be culled | 3758 // Must receive one render pass, as the other one should be culled |
| 3759 ASSERT_EQ(1U, frame.renderPasses.size()); | 3759 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3760 | 3760 |
| 3761 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3761 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3762 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->
material()); | 3762 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 3763 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[0]->quadList()[0]); | 3763 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[0]->quadList()[0]); |
| 3764 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3764 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3765 EXPECT_TRUE(targetPass->damageRect().isEmpty()); | 3765 EXPECT_TRUE(targetPass->damageRect().isEmpty()); |
| 3766 | 3766 |
| 3767 myHostImpl->drawLayers(frame); | 3767 myHostImpl->drawLayers(frame); |
| 3768 myHostImpl->didDrawAllLayers(frame); | 3768 myHostImpl->didDrawAllLayers(frame); |
| 3769 } | 3769 } |
| 3770 | 3770 |
| 3771 // Change less benign property and draw - should have contents changed flag | 3771 // Change less benign property and draw - should have contents changed flag |
| 3772 surfaceLayerPtr->setStackingOrderChanged(true); | 3772 surfaceLayerPtr->setStackingOrderChanged(true); |
| 3773 { | 3773 { |
| 3774 CCLayerTreeHostImpl::FrameData frame; | 3774 LayerTreeHostImpl::FrameData frame; |
| 3775 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3775 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3776 | 3776 |
| 3777 // Must receive two render passes, each with one quad | 3777 // Must receive two render passes, each with one quad |
| 3778 ASSERT_EQ(2U, frame.renderPasses.size()); | 3778 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3779 | 3779 |
| 3780 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3780 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3781 EXPECT_EQ(CCDrawQuad::SolidColor, frame.renderPasses[0]->quadList()[0]->
material()); | 3781 EXPECT_EQ(DrawQuad::SolidColor, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 3782 | 3782 |
| 3783 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->
material()); | 3783 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->ma
terial()); |
| 3784 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[1]->quadList()[0]); | 3784 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[1]->quadList()[0]); |
| 3785 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3785 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3786 EXPECT_FALSE(targetPass->damageRect().isEmpty()); | 3786 EXPECT_FALSE(targetPass->damageRect().isEmpty()); |
| 3787 | 3787 |
| 3788 myHostImpl->drawLayers(frame); | 3788 myHostImpl->drawLayers(frame); |
| 3789 myHostImpl->didDrawAllLayers(frame); | 3789 myHostImpl->didDrawAllLayers(frame); |
| 3790 } | 3790 } |
| 3791 | 3791 |
| 3792 // Change opacity again, and evict the cached surface texture. | 3792 // Change opacity again, and evict the cached surface texture. |
| 3793 surfaceLayerPtr->setOpacity(0.5f); | 3793 surfaceLayerPtr->setOpacity(0.5f); |
| 3794 static_cast<CCRendererGLWithReleaseTextures*>(myHostImpl->renderer())->relea
seRenderPassTextures(); | 3794 static_cast<GLRendererWithReleaseTextures*>(myHostImpl->renderer())->release
RenderPassTextures(); |
| 3795 | 3795 |
| 3796 // Change opacity and draw | 3796 // Change opacity and draw |
| 3797 surfaceLayerPtr->setOpacity(0.6f); | 3797 surfaceLayerPtr->setOpacity(0.6f); |
| 3798 { | 3798 { |
| 3799 CCLayerTreeHostImpl::FrameData frame; | 3799 LayerTreeHostImpl::FrameData frame; |
| 3800 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3800 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3801 | 3801 |
| 3802 // Must receive two render passes | 3802 // Must receive two render passes |
| 3803 ASSERT_EQ(2U, frame.renderPasses.size()); | 3803 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3804 | 3804 |
| 3805 // Even though not enough properties changed, the entire thing must be | 3805 // Even though not enough properties changed, the entire thing must be |
| 3806 // redrawn as we don't have cached textures | 3806 // redrawn as we don't have cached textures |
| 3807 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3807 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3808 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); | 3808 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); |
| 3809 | 3809 |
| 3810 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->
material()); | 3810 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->ma
terial()); |
| 3811 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[1]->quadList()[0]); | 3811 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[1]->quadList()[0]); |
| 3812 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3812 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3813 EXPECT_TRUE(targetPass->damageRect().isEmpty()); | 3813 EXPECT_TRUE(targetPass->damageRect().isEmpty()); |
| 3814 | 3814 |
| 3815 // Was our surface evicted? | 3815 // Was our surface evicted? |
| 3816 EXPECT_FALSE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(
targetPass->id())); | 3816 EXPECT_FALSE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(
targetPass->id())); |
| 3817 | 3817 |
| 3818 myHostImpl->drawLayers(frame); | 3818 myHostImpl->drawLayers(frame); |
| 3819 myHostImpl->didDrawAllLayers(frame); | 3819 myHostImpl->didDrawAllLayers(frame); |
| 3820 } | 3820 } |
| 3821 | 3821 |
| 3822 // Draw without any change, to make sure the state is clear | 3822 // Draw without any change, to make sure the state is clear |
| 3823 { | 3823 { |
| 3824 CCLayerTreeHostImpl::FrameData frame; | 3824 LayerTreeHostImpl::FrameData frame; |
| 3825 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3825 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3826 | 3826 |
| 3827 // Must receive one render pass, as the other one should be culled | 3827 // Must receive one render pass, as the other one should be culled |
| 3828 ASSERT_EQ(1U, frame.renderPasses.size()); | 3828 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3829 | 3829 |
| 3830 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3830 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3831 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->
material()); | 3831 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 3832 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[0]->quadList()[0]); | 3832 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[0]->quadList()[0]); |
| 3833 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3833 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3834 EXPECT_TRUE(targetPass->damageRect().isEmpty()); | 3834 EXPECT_TRUE(targetPass->damageRect().isEmpty()); |
| 3835 | 3835 |
| 3836 myHostImpl->drawLayers(frame); | 3836 myHostImpl->drawLayers(frame); |
| 3837 myHostImpl->didDrawAllLayers(frame); | 3837 myHostImpl->didDrawAllLayers(frame); |
| 3838 } | 3838 } |
| 3839 | 3839 |
| 3840 // Change opacity on the intermediate layer | 3840 // Change opacity on the intermediate layer |
| 3841 WebTransformationMatrix transform = intermediateLayerPtr->transform(); | 3841 WebTransformationMatrix transform = intermediateLayerPtr->transform(); |
| 3842 transform.setM11(1.0001); | 3842 transform.setM11(1.0001); |
| 3843 intermediateLayerPtr->setTransform(transform); | 3843 intermediateLayerPtr->setTransform(transform); |
| 3844 { | 3844 { |
| 3845 CCLayerTreeHostImpl::FrameData frame; | 3845 LayerTreeHostImpl::FrameData frame; |
| 3846 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3846 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3847 | 3847 |
| 3848 // Must receive one render pass, as the other one should be culled. | 3848 // Must receive one render pass, as the other one should be culled. |
| 3849 ASSERT_EQ(1U, frame.renderPasses.size()); | 3849 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3850 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3850 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3851 | 3851 |
| 3852 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->
material()); | 3852 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 3853 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[0]->quadList()[0]); | 3853 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[0]->quadList()[0]); |
| 3854 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3854 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3855 EXPECT_TRUE(targetPass->damageRect().isEmpty()); | 3855 EXPECT_TRUE(targetPass->damageRect().isEmpty()); |
| 3856 | 3856 |
| 3857 myHostImpl->drawLayers(frame); | 3857 myHostImpl->drawLayers(frame); |
| 3858 myHostImpl->didDrawAllLayers(frame); | 3858 myHostImpl->didDrawAllLayers(frame); |
| 3859 } | 3859 } |
| 3860 } | 3860 } |
| 3861 | 3861 |
| 3862 TEST_P(CCLayerTreeHostImplTest, surfaceTextureCachingNoPartialSwap) | 3862 TEST_P(LayerTreeHostImplTest, surfaceTextureCachingNoPartialSwap) |
| 3863 { | 3863 { |
| 3864 CCSettings::setPartialSwapEnabled(false); | 3864 Settings::setPartialSwapEnabled(false); |
| 3865 | 3865 |
| 3866 CCLayerTreeSettings settings; | 3866 LayerTreeSettings settings; |
| 3867 settings.minimumOcclusionTrackingSize = IntSize(); | 3867 settings.minimumOcclusionTrackingSize = IntSize(); |
| 3868 scoped_ptr<CCLayerTreeHostImpl> myHostImpl = CCLayerTreeHostImpl::create(set
tings, this); | 3868 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this); |
| 3869 | 3869 |
| 3870 CCLayerImpl* rootPtr; | 3870 LayerImpl* rootPtr; |
| 3871 CCLayerImpl* intermediateLayerPtr; | 3871 LayerImpl* intermediateLayerPtr; |
| 3872 CCLayerImpl* surfaceLayerPtr; | 3872 LayerImpl* surfaceLayerPtr; |
| 3873 CCLayerImpl* childPtr; | 3873 LayerImpl* childPtr; |
| 3874 | 3874 |
| 3875 setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr
, surfaceLayerPtr, childPtr, IntSize(100, 100)); | 3875 setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr
, surfaceLayerPtr, childPtr, IntSize(100, 100)); |
| 3876 | 3876 |
| 3877 { | 3877 { |
| 3878 CCLayerTreeHostImpl::FrameData frame; | 3878 LayerTreeHostImpl::FrameData frame; |
| 3879 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3879 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3880 | 3880 |
| 3881 // Must receive two render passes, each with one quad | 3881 // Must receive two render passes, each with one quad |
| 3882 ASSERT_EQ(2U, frame.renderPasses.size()); | 3882 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3883 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3883 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3884 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); | 3884 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); |
| 3885 | 3885 |
| 3886 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->
material()); | 3886 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->ma
terial()); |
| 3887 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[1]->quadList()[0]); | 3887 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[1]->quadList()[0]); |
| 3888 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3888 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3889 EXPECT_FALSE(targetPass->damageRect().isEmpty()); | 3889 EXPECT_FALSE(targetPass->damageRect().isEmpty()); |
| 3890 | 3890 |
| 3891 EXPECT_FALSE(frame.renderPasses[0]->damageRect().isEmpty()); | 3891 EXPECT_FALSE(frame.renderPasses[0]->damageRect().isEmpty()); |
| 3892 EXPECT_FALSE(frame.renderPasses[1]->damageRect().isEmpty()); | 3892 EXPECT_FALSE(frame.renderPasses[1]->damageRect().isEmpty()); |
| 3893 | 3893 |
| 3894 EXPECT_FALSE(frame.renderPasses[0]->hasOcclusionFromOutsideTargetSurface
()); | 3894 EXPECT_FALSE(frame.renderPasses[0]->hasOcclusionFromOutsideTargetSurface
()); |
| 3895 EXPECT_FALSE(frame.renderPasses[1]->hasOcclusionFromOutsideTargetSurface
()); | 3895 EXPECT_FALSE(frame.renderPasses[1]->hasOcclusionFromOutsideTargetSurface
()); |
| 3896 | 3896 |
| 3897 myHostImpl->drawLayers(frame); | 3897 myHostImpl->drawLayers(frame); |
| 3898 myHostImpl->didDrawAllLayers(frame); | 3898 myHostImpl->didDrawAllLayers(frame); |
| 3899 } | 3899 } |
| 3900 | 3900 |
| 3901 // Draw without any change | 3901 // Draw without any change |
| 3902 { | 3902 { |
| 3903 CCLayerTreeHostImpl::FrameData frame; | 3903 LayerTreeHostImpl::FrameData frame; |
| 3904 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3904 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3905 | 3905 |
| 3906 // Even though there was no change, we set the damage to entire viewport
. | 3906 // Even though there was no change, we set the damage to entire viewport
. |
| 3907 // One of the passes should be culled as a result, since contents didn't
change | 3907 // One of the passes should be culled as a result, since contents didn't
change |
| 3908 // and we have cached texture. | 3908 // and we have cached texture. |
| 3909 ASSERT_EQ(1U, frame.renderPasses.size()); | 3909 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3910 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3910 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3911 | 3911 |
| 3912 EXPECT_TRUE(frame.renderPasses[0]->damageRect().isEmpty()); | 3912 EXPECT_TRUE(frame.renderPasses[0]->damageRect().isEmpty()); |
| 3913 | 3913 |
| 3914 myHostImpl->drawLayers(frame); | 3914 myHostImpl->drawLayers(frame); |
| 3915 myHostImpl->didDrawAllLayers(frame); | 3915 myHostImpl->didDrawAllLayers(frame); |
| 3916 } | 3916 } |
| 3917 | 3917 |
| 3918 // Change opacity and draw | 3918 // Change opacity and draw |
| 3919 surfaceLayerPtr->setOpacity(0.6f); | 3919 surfaceLayerPtr->setOpacity(0.6f); |
| 3920 { | 3920 { |
| 3921 CCLayerTreeHostImpl::FrameData frame; | 3921 LayerTreeHostImpl::FrameData frame; |
| 3922 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3922 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3923 | 3923 |
| 3924 // Must receive one render pass, as the other one should be culled | 3924 // Must receive one render pass, as the other one should be culled |
| 3925 ASSERT_EQ(1U, frame.renderPasses.size()); | 3925 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3926 | 3926 |
| 3927 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3927 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3928 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->
material()); | 3928 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 3929 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[0]->quadList()[0]); | 3929 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[0]->quadList()[0]); |
| 3930 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3930 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3931 EXPECT_TRUE(targetPass->damageRect().isEmpty()); | 3931 EXPECT_TRUE(targetPass->damageRect().isEmpty()); |
| 3932 | 3932 |
| 3933 myHostImpl->drawLayers(frame); | 3933 myHostImpl->drawLayers(frame); |
| 3934 myHostImpl->didDrawAllLayers(frame); | 3934 myHostImpl->didDrawAllLayers(frame); |
| 3935 } | 3935 } |
| 3936 | 3936 |
| 3937 // Change less benign property and draw - should have contents changed flag | 3937 // Change less benign property and draw - should have contents changed flag |
| 3938 surfaceLayerPtr->setStackingOrderChanged(true); | 3938 surfaceLayerPtr->setStackingOrderChanged(true); |
| 3939 { | 3939 { |
| 3940 CCLayerTreeHostImpl::FrameData frame; | 3940 LayerTreeHostImpl::FrameData frame; |
| 3941 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3941 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3942 | 3942 |
| 3943 // Must receive two render passes, each with one quad | 3943 // Must receive two render passes, each with one quad |
| 3944 ASSERT_EQ(2U, frame.renderPasses.size()); | 3944 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3945 | 3945 |
| 3946 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3946 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3947 EXPECT_EQ(CCDrawQuad::SolidColor, frame.renderPasses[0]->quadList()[0]->
material()); | 3947 EXPECT_EQ(DrawQuad::SolidColor, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 3948 | 3948 |
| 3949 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->
material()); | 3949 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->ma
terial()); |
| 3950 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[1]->quadList()[0]); | 3950 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[1]->quadList()[0]); |
| 3951 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3951 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3952 EXPECT_FALSE(targetPass->damageRect().isEmpty()); | 3952 EXPECT_FALSE(targetPass->damageRect().isEmpty()); |
| 3953 | 3953 |
| 3954 myHostImpl->drawLayers(frame); | 3954 myHostImpl->drawLayers(frame); |
| 3955 myHostImpl->didDrawAllLayers(frame); | 3955 myHostImpl->didDrawAllLayers(frame); |
| 3956 } | 3956 } |
| 3957 | 3957 |
| 3958 // Change opacity again, and evict the cached surface texture. | 3958 // Change opacity again, and evict the cached surface texture. |
| 3959 surfaceLayerPtr->setOpacity(0.5f); | 3959 surfaceLayerPtr->setOpacity(0.5f); |
| 3960 static_cast<CCRendererGLWithReleaseTextures*>(myHostImpl->renderer())->relea
seRenderPassTextures(); | 3960 static_cast<GLRendererWithReleaseTextures*>(myHostImpl->renderer())->release
RenderPassTextures(); |
| 3961 | 3961 |
| 3962 // Change opacity and draw | 3962 // Change opacity and draw |
| 3963 surfaceLayerPtr->setOpacity(0.6f); | 3963 surfaceLayerPtr->setOpacity(0.6f); |
| 3964 { | 3964 { |
| 3965 CCLayerTreeHostImpl::FrameData frame; | 3965 LayerTreeHostImpl::FrameData frame; |
| 3966 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3966 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3967 | 3967 |
| 3968 // Must receive two render passes | 3968 // Must receive two render passes |
| 3969 ASSERT_EQ(2U, frame.renderPasses.size()); | 3969 ASSERT_EQ(2U, frame.renderPasses.size()); |
| 3970 | 3970 |
| 3971 // Even though not enough properties changed, the entire thing must be | 3971 // Even though not enough properties changed, the entire thing must be |
| 3972 // redrawn as we don't have cached textures | 3972 // redrawn as we don't have cached textures |
| 3973 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3973 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3974 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); | 3974 EXPECT_EQ(1U, frame.renderPasses[1]->quadList().size()); |
| 3975 | 3975 |
| 3976 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->
material()); | 3976 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[1]->quadList()[0]->ma
terial()); |
| 3977 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[1]->quadList()[0]); | 3977 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[1]->quadList()[0]); |
| 3978 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 3978 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 3979 EXPECT_TRUE(targetPass->damageRect().isEmpty()); | 3979 EXPECT_TRUE(targetPass->damageRect().isEmpty()); |
| 3980 | 3980 |
| 3981 // Was our surface evicted? | 3981 // Was our surface evicted? |
| 3982 EXPECT_FALSE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(
targetPass->id())); | 3982 EXPECT_FALSE(myHostImpl->renderer()->haveCachedResourcesForRenderPassId(
targetPass->id())); |
| 3983 | 3983 |
| 3984 myHostImpl->drawLayers(frame); | 3984 myHostImpl->drawLayers(frame); |
| 3985 myHostImpl->didDrawAllLayers(frame); | 3985 myHostImpl->didDrawAllLayers(frame); |
| 3986 } | 3986 } |
| 3987 | 3987 |
| 3988 // Draw without any change, to make sure the state is clear | 3988 // Draw without any change, to make sure the state is clear |
| 3989 { | 3989 { |
| 3990 CCLayerTreeHostImpl::FrameData frame; | 3990 LayerTreeHostImpl::FrameData frame; |
| 3991 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 3991 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 3992 | 3992 |
| 3993 // Even though there was no change, we set the damage to entire viewport
. | 3993 // Even though there was no change, we set the damage to entire viewport
. |
| 3994 // One of the passes should be culled as a result, since contents didn't
change | 3994 // One of the passes should be culled as a result, since contents didn't
change |
| 3995 // and we have cached texture. | 3995 // and we have cached texture. |
| 3996 ASSERT_EQ(1U, frame.renderPasses.size()); | 3996 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 3997 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 3997 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 3998 | 3998 |
| 3999 myHostImpl->drawLayers(frame); | 3999 myHostImpl->drawLayers(frame); |
| 4000 myHostImpl->didDrawAllLayers(frame); | 4000 myHostImpl->didDrawAllLayers(frame); |
| 4001 } | 4001 } |
| 4002 | 4002 |
| 4003 // Change opacity on the intermediate layer | 4003 // Change opacity on the intermediate layer |
| 4004 WebTransformationMatrix transform = intermediateLayerPtr->transform(); | 4004 WebTransformationMatrix transform = intermediateLayerPtr->transform(); |
| 4005 transform.setM11(1.0001); | 4005 transform.setM11(1.0001); |
| 4006 intermediateLayerPtr->setTransform(transform); | 4006 intermediateLayerPtr->setTransform(transform); |
| 4007 { | 4007 { |
| 4008 CCLayerTreeHostImpl::FrameData frame; | 4008 LayerTreeHostImpl::FrameData frame; |
| 4009 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | 4009 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); |
| 4010 | 4010 |
| 4011 // Must receive one render pass, as the other one should be culled. | 4011 // Must receive one render pass, as the other one should be culled. |
| 4012 ASSERT_EQ(1U, frame.renderPasses.size()); | 4012 ASSERT_EQ(1U, frame.renderPasses.size()); |
| 4013 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); | 4013 EXPECT_EQ(1U, frame.renderPasses[0]->quadList().size()); |
| 4014 | 4014 |
| 4015 EXPECT_EQ(CCDrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->
material()); | 4015 EXPECT_EQ(DrawQuad::RenderPass, frame.renderPasses[0]->quadList()[0]->ma
terial()); |
| 4016 CCRenderPassDrawQuad* quad = static_cast<CCRenderPassDrawQuad*>(frame.re
nderPasses[0]->quadList()[0]); | 4016 RenderPassDrawQuad* quad = static_cast<RenderPassDrawQuad*>(frame.render
Passes[0]->quadList()[0]); |
| 4017 CCRenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId
()); | 4017 RenderPass* targetPass = frame.renderPassesById.get(quad->renderPassId()
); |
| 4018 EXPECT_TRUE(targetPass->damageRect().isEmpty()); | 4018 EXPECT_TRUE(targetPass->damageRect().isEmpty()); |
| 4019 | 4019 |
| 4020 myHostImpl->drawLayers(frame); | 4020 myHostImpl->drawLayers(frame); |
| 4021 myHostImpl->didDrawAllLayers(frame); | 4021 myHostImpl->didDrawAllLayers(frame); |
| 4022 } | 4022 } |
| 4023 } | 4023 } |
| 4024 | 4024 |
| 4025 TEST_P(CCLayerTreeHostImplTest, releaseContentsTextureShouldTriggerCommit) | 4025 TEST_P(LayerTreeHostImplTest, releaseContentsTextureShouldTriggerCommit) |
| 4026 { | 4026 { |
| 4027 setReduceMemoryResult(false); | 4027 setReduceMemoryResult(false); |
| 4028 | 4028 |
| 4029 // Even if changing the memory limit didn't result in anything being | 4029 // Even if changing the memory limit didn't result in anything being |
| 4030 // evicted, we need to re-commit because the new value may result in us | 4030 // evicted, we need to re-commit because the new value may result in us |
| 4031 // drawing something different than before. | 4031 // drawing something different than before. |
| 4032 setReduceMemoryResult(false); | 4032 setReduceMemoryResult(false); |
| 4033 m_hostImpl->setMemoryAllocationLimitBytes( | 4033 m_hostImpl->setMemoryAllocationLimitBytes( |
| 4034 m_hostImpl->memoryAllocationLimitBytes() - 1); | 4034 m_hostImpl->memoryAllocationLimitBytes() - 1); |
| 4035 EXPECT_TRUE(m_didRequestCommit); | 4035 EXPECT_TRUE(m_didRequestCommit); |
| 4036 m_didRequestCommit = false; | 4036 m_didRequestCommit = false; |
| 4037 | 4037 |
| 4038 // Especially if changing the memory limit caused evictions, we need | 4038 // Especially if changing the memory limit caused evictions, we need |
| 4039 // to re-commit. | 4039 // to re-commit. |
| 4040 setReduceMemoryResult(true); | 4040 setReduceMemoryResult(true); |
| 4041 m_hostImpl->setMemoryAllocationLimitBytes( | 4041 m_hostImpl->setMemoryAllocationLimitBytes( |
| 4042 m_hostImpl->memoryAllocationLimitBytes() - 1); | 4042 m_hostImpl->memoryAllocationLimitBytes() - 1); |
| 4043 EXPECT_TRUE(m_didRequestCommit); | 4043 EXPECT_TRUE(m_didRequestCommit); |
| 4044 m_didRequestCommit = false; | 4044 m_didRequestCommit = false; |
| 4045 | 4045 |
| 4046 // But if we set it to the same value that it was before, we shouldn't | 4046 // But if we set it to the same value that it was before, we shouldn't |
| 4047 // re-commit. | 4047 // re-commit. |
| 4048 m_hostImpl->setMemoryAllocationLimitBytes( | 4048 m_hostImpl->setMemoryAllocationLimitBytes( |
| 4049 m_hostImpl->memoryAllocationLimitBytes()); | 4049 m_hostImpl->memoryAllocationLimitBytes()); |
| 4050 EXPECT_FALSE(m_didRequestCommit); | 4050 EXPECT_FALSE(m_didRequestCommit); |
| 4051 } | 4051 } |
| 4052 | 4052 |
| 4053 struct RenderPassRemovalTestData : public CCLayerTreeHostImpl::FrameData { | 4053 struct RenderPassRemovalTestData : public LayerTreeHostImpl::FrameData { |
| 4054 ScopedPtrHashMap<CCRenderPass::Id, CCRenderPass> renderPassCache; | 4054 ScopedPtrHashMap<RenderPass::Id, RenderPass> renderPassCache; |
| 4055 scoped_ptr<CCSharedQuadState> sharedQuadState; | 4055 scoped_ptr<SharedQuadState> sharedQuadState; |
| 4056 }; | 4056 }; |
| 4057 | 4057 |
| 4058 class CCTestRenderer : public CCRendererGL, public CCRendererClient { | 4058 class TestRenderer : public GLRenderer, public RendererClient { |
| 4059 public: | 4059 public: |
| 4060 static scoped_ptr<CCTestRenderer> create(CCResourceProvider* resourceProvide
r) | 4060 static scoped_ptr<TestRenderer> create(ResourceProvider* resourceProvider) |
| 4061 { | 4061 { |
| 4062 scoped_ptr<CCTestRenderer> renderer(new CCTestRenderer(resourceProvider)
); | 4062 scoped_ptr<TestRenderer> renderer(new TestRenderer(resourceProvider)); |
| 4063 if (!renderer->initialize()) | 4063 if (!renderer->initialize()) |
| 4064 return scoped_ptr<CCTestRenderer>(); | 4064 return scoped_ptr<TestRenderer>(); |
| 4065 | 4065 |
| 4066 return renderer.Pass(); | 4066 return renderer.Pass(); |
| 4067 } | 4067 } |
| 4068 | 4068 |
| 4069 void clearCachedTextures() { m_textures.clear(); } | 4069 void clearCachedTextures() { m_textures.clear(); } |
| 4070 void setHaveCachedResourcesForRenderPassId(CCRenderPass::Id id) { m_textures
.insert(id); } | 4070 void setHaveCachedResourcesForRenderPassId(RenderPass::Id id) { m_textures.i
nsert(id); } |
| 4071 | 4071 |
| 4072 virtual bool haveCachedResourcesForRenderPassId(CCRenderPass::Id id) const O
VERRIDE { return m_textures.count(id); } | 4072 virtual bool haveCachedResourcesForRenderPassId(RenderPass::Id id) const OVE
RRIDE { return m_textures.count(id); } |
| 4073 | 4073 |
| 4074 // CCRendererClient implementation. | 4074 // RendererClient implementation. |
| 4075 virtual const IntSize& deviceViewportSize() const OVERRIDE { return m_viewpo
rtSize; } | 4075 virtual const IntSize& deviceViewportSize() const OVERRIDE { return m_viewpo
rtSize; } |
| 4076 virtual const CCLayerTreeSettings& settings() const OVERRIDE { return m_sett
ings; } | 4076 virtual const LayerTreeSettings& settings() const OVERRIDE { return m_settin
gs; } |
| 4077 virtual void didLoseContext() OVERRIDE { } | 4077 virtual void didLoseContext() OVERRIDE { } |
| 4078 virtual void onSwapBuffersComplete() OVERRIDE { } | 4078 virtual void onSwapBuffersComplete() OVERRIDE { } |
| 4079 virtual void setFullRootLayerDamage() OVERRIDE { } | 4079 virtual void setFullRootLayerDamage() OVERRIDE { } |
| 4080 virtual void setMemoryAllocationLimitBytes(size_t) OVERRIDE { } | 4080 virtual void setMemoryAllocationLimitBytes(size_t) OVERRIDE { } |
| 4081 | 4081 |
| 4082 protected: | 4082 protected: |
| 4083 CCTestRenderer(CCResourceProvider* resourceProvider) : CCRendererGL(this, re
sourceProvider) { } | 4083 TestRenderer(ResourceProvider* resourceProvider) : GLRenderer(this, resource
Provider) { } |
| 4084 | 4084 |
| 4085 private: | 4085 private: |
| 4086 CCLayerTreeSettings m_settings; | 4086 LayerTreeSettings m_settings; |
| 4087 IntSize m_viewportSize; | 4087 IntSize m_viewportSize; |
| 4088 base::hash_set<CCRenderPass::Id> m_textures; | 4088 base::hash_set<RenderPass::Id> m_textures; |
| 4089 }; | 4089 }; |
| 4090 | 4090 |
| 4091 static void configureRenderPassTestData(const char* testScript, RenderPassRemova
lTestData& testData, CCTestRenderer* renderer) | 4091 static void configureRenderPassTestData(const char* testScript, RenderPassRemova
lTestData& testData, TestRenderer* renderer) |
| 4092 { | 4092 { |
| 4093 renderer->clearCachedTextures(); | 4093 renderer->clearCachedTextures(); |
| 4094 | 4094 |
| 4095 // One shared state for all quads - we don't need the correct details | 4095 // One shared state for all quads - we don't need the correct details |
| 4096 testData.sharedQuadState = CCSharedQuadState::create(WebTransformationMatrix
(), IntRect(), IntRect(), 1.0, true); | 4096 testData.sharedQuadState = SharedQuadState::create(WebTransformationMatrix()
, IntRect(), IntRect(), 1.0, true); |
| 4097 | 4097 |
| 4098 const char* currentChar = testScript; | 4098 const char* currentChar = testScript; |
| 4099 | 4099 |
| 4100 // Pre-create root pass | 4100 // Pre-create root pass |
| 4101 CCRenderPass::Id rootRenderPassId = CCRenderPass::Id(testScript[0], testScri
pt[1]); | 4101 RenderPass::Id rootRenderPassId = RenderPass::Id(testScript[0], testScript[1
]); |
| 4102 testData.renderPassCache.add(rootRenderPassId, CCRenderPass::create(rootRend
erPassId, IntRect(), WebTransformationMatrix())); | 4102 testData.renderPassCache.add(rootRenderPassId, RenderPass::create(rootRender
PassId, IntRect(), WebTransformationMatrix())); |
| 4103 while (*currentChar) { | 4103 while (*currentChar) { |
| 4104 int layerId = *currentChar; | 4104 int layerId = *currentChar; |
| 4105 currentChar++; | 4105 currentChar++; |
| 4106 ASSERT_TRUE(currentChar); | 4106 ASSERT_TRUE(currentChar); |
| 4107 int index = *currentChar; | 4107 int index = *currentChar; |
| 4108 currentChar++; | 4108 currentChar++; |
| 4109 | 4109 |
| 4110 CCRenderPass::Id renderPassId = CCRenderPass::Id(layerId, index); | 4110 RenderPass::Id renderPassId = RenderPass::Id(layerId, index); |
| 4111 | 4111 |
| 4112 bool isReplica = false; | 4112 bool isReplica = false; |
| 4113 if (!testData.renderPassCache.contains(renderPassId)) | 4113 if (!testData.renderPassCache.contains(renderPassId)) |
| 4114 isReplica = true; | 4114 isReplica = true; |
| 4115 | 4115 |
| 4116 scoped_ptr<CCRenderPass> renderPass = testData.renderPassCache.take(rend
erPassId); | 4116 scoped_ptr<RenderPass> renderPass = testData.renderPassCache.take(render
PassId); |
| 4117 | 4117 |
| 4118 // Cycle through quad data and create all quads | 4118 // Cycle through quad data and create all quads |
| 4119 while (*currentChar && *currentChar != '\n') { | 4119 while (*currentChar && *currentChar != '\n') { |
| 4120 if (*currentChar == 's') { | 4120 if (*currentChar == 's') { |
| 4121 // Solid color draw quad | 4121 // Solid color draw quad |
| 4122 scoped_ptr<CCSolidColorDrawQuad> quad = CCSolidColorDrawQuad::cr
eate(testData.sharedQuadState.get(), IntRect(0, 0, 10, 10), SK_ColorWHITE); | 4122 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::create
(testData.sharedQuadState.get(), IntRect(0, 0, 10, 10), SK_ColorWHITE); |
| 4123 | 4123 |
| 4124 static_cast<CCTestRenderPass*>(renderPass.get())->appendQuad(qua
d.PassAs<CCDrawQuad>()); | 4124 static_cast<TestRenderPass*>(renderPass.get())->appendQuad(quad.
PassAs<DrawQuad>()); |
| 4125 currentChar++; | 4125 currentChar++; |
| 4126 } else if ((*currentChar >= 'A') && (*currentChar <= 'Z')) { | 4126 } else if ((*currentChar >= 'A') && (*currentChar <= 'Z')) { |
| 4127 // RenderPass draw quad | 4127 // RenderPass draw quad |
| 4128 int layerId = *currentChar; | 4128 int layerId = *currentChar; |
| 4129 currentChar++; | 4129 currentChar++; |
| 4130 ASSERT_TRUE(currentChar); | 4130 ASSERT_TRUE(currentChar); |
| 4131 int index = *currentChar; | 4131 int index = *currentChar; |
| 4132 currentChar++; | 4132 currentChar++; |
| 4133 CCRenderPass::Id newRenderPassId = CCRenderPass::Id(layerId, ind
ex); | 4133 RenderPass::Id newRenderPassId = RenderPass::Id(layerId, index); |
| 4134 ASSERT_NE(rootRenderPassId, newRenderPassId); | 4134 ASSERT_NE(rootRenderPassId, newRenderPassId); |
| 4135 bool hasTexture = false; | 4135 bool hasTexture = false; |
| 4136 bool contentsChanged = true; | 4136 bool contentsChanged = true; |
| 4137 | 4137 |
| 4138 if (*currentChar == '[') { | 4138 if (*currentChar == '[') { |
| 4139 currentChar++; | 4139 currentChar++; |
| 4140 while (*currentChar && *currentChar != ']') { | 4140 while (*currentChar && *currentChar != ']') { |
| 4141 switch (*currentChar) { | 4141 switch (*currentChar) { |
| 4142 case 'c': | 4142 case 'c': |
| 4143 contentsChanged = false; | 4143 contentsChanged = false; |
| 4144 break; | 4144 break; |
| 4145 case 't': | 4145 case 't': |
| 4146 hasTexture = true; | 4146 hasTexture = true; |
| 4147 break; | 4147 break; |
| 4148 } | 4148 } |
| 4149 currentChar++; | 4149 currentChar++; |
| 4150 } | 4150 } |
| 4151 if (*currentChar == ']') | 4151 if (*currentChar == ']') |
| 4152 currentChar++; | 4152 currentChar++; |
| 4153 } | 4153 } |
| 4154 | 4154 |
| 4155 if (testData.renderPassCache.find(newRenderPassId) == testData.r
enderPassCache.end()) { | 4155 if (testData.renderPassCache.find(newRenderPassId) == testData.r
enderPassCache.end()) { |
| 4156 if (hasTexture) | 4156 if (hasTexture) |
| 4157 renderer->setHaveCachedResourcesForRenderPassId(newRende
rPassId); | 4157 renderer->setHaveCachedResourcesForRenderPassId(newRende
rPassId); |
| 4158 | 4158 |
| 4159 testData.renderPassCache.add(newRenderPassId, CCTestRenderPa
ss::create(newRenderPassId, IntRect(), WebTransformationMatrix())); | 4159 testData.renderPassCache.add(newRenderPassId, TestRenderPass
::create(newRenderPassId, IntRect(), WebTransformationMatrix())); |
| 4160 } | 4160 } |
| 4161 | 4161 |
| 4162 IntRect quadRect = IntRect(0, 0, 1, 1); | 4162 IntRect quadRect = IntRect(0, 0, 1, 1); |
| 4163 IntRect contentsChangedRect = contentsChanged ? quadRect : IntRe
ct(); | 4163 IntRect contentsChangedRect = contentsChanged ? quadRect : IntRe
ct(); |
| 4164 scoped_ptr<CCRenderPassDrawQuad> quad = CCRenderPassDrawQuad::cr
eate(testData.sharedQuadState.get(), quadRect, newRenderPassId, isReplica, 1, co
ntentsChangedRect, 1, 1, 0, 0); | 4164 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::create
(testData.sharedQuadState.get(), quadRect, newRenderPassId, isReplica, 1, conten
tsChangedRect, 1, 1, 0, 0); |
| 4165 static_cast<CCTestRenderPass*>(renderPass.get())->appendQuad(qua
d.PassAs<CCDrawQuad>()); | 4165 static_cast<TestRenderPass*>(renderPass.get())->appendQuad(quad.
PassAs<DrawQuad>()); |
| 4166 } | 4166 } |
| 4167 } | 4167 } |
| 4168 testData.renderPasses.insert(testData.renderPasses.begin(), renderPass.g
et()); | 4168 testData.renderPasses.insert(testData.renderPasses.begin(), renderPass.g
et()); |
| 4169 testData.renderPassesById.add(renderPassId, renderPass.Pass()); | 4169 testData.renderPassesById.add(renderPassId, renderPass.Pass()); |
| 4170 if (*currentChar) | 4170 if (*currentChar) |
| 4171 currentChar++; | 4171 currentChar++; |
| 4172 } | 4172 } |
| 4173 } | 4173 } |
| 4174 | 4174 |
| 4175 void dumpRenderPassTestData(const RenderPassRemovalTestData& testData, char* buf
fer) | 4175 void dumpRenderPassTestData(const RenderPassRemovalTestData& testData, char* buf
fer) |
| 4176 { | 4176 { |
| 4177 char* pos = buffer; | 4177 char* pos = buffer; |
| 4178 for (CCRenderPassList::const_reverse_iterator it = testData.renderPasses.rbe
gin(); it != testData.renderPasses.rend(); ++it) { | 4178 for (RenderPassList::const_reverse_iterator it = testData.renderPasses.rbegi
n(); it != testData.renderPasses.rend(); ++it) { |
| 4179 const CCRenderPass* currentPass = *it; | 4179 const RenderPass* currentPass = *it; |
| 4180 *pos = currentPass->id().layerId; | 4180 *pos = currentPass->id().layerId; |
| 4181 pos++; | 4181 pos++; |
| 4182 *pos = currentPass->id().index; | 4182 *pos = currentPass->id().index; |
| 4183 pos++; | 4183 pos++; |
| 4184 | 4184 |
| 4185 CCQuadList::const_iterator quadListIterator = currentPass->quadList().be
gin(); | 4185 QuadList::const_iterator quadListIterator = currentPass->quadList().begi
n(); |
| 4186 while (quadListIterator != currentPass->quadList().end()) { | 4186 while (quadListIterator != currentPass->quadList().end()) { |
| 4187 CCDrawQuad* currentQuad = *quadListIterator; | 4187 DrawQuad* currentQuad = *quadListIterator; |
| 4188 switch (currentQuad->material()) { | 4188 switch (currentQuad->material()) { |
| 4189 case CCDrawQuad::SolidColor: | 4189 case DrawQuad::SolidColor: |
| 4190 *pos = 's'; | 4190 *pos = 's'; |
| 4191 pos++; | 4191 pos++; |
| 4192 break; | 4192 break; |
| 4193 case CCDrawQuad::RenderPass: | 4193 case DrawQuad::RenderPass: |
| 4194 *pos = CCRenderPassDrawQuad::materialCast(currentQuad)->renderPa
ssId().layerId; | 4194 *pos = RenderPassDrawQuad::materialCast(currentQuad)->renderPass
Id().layerId; |
| 4195 pos++; | 4195 pos++; |
| 4196 *pos = CCRenderPassDrawQuad::materialCast(currentQuad)->renderPa
ssId().index; | 4196 *pos = RenderPassDrawQuad::materialCast(currentQuad)->renderPass
Id().index; |
| 4197 pos++; | 4197 pos++; |
| 4198 break; | 4198 break; |
| 4199 default: | 4199 default: |
| 4200 *pos = 'x'; | 4200 *pos = 'x'; |
| 4201 pos++; | 4201 pos++; |
| 4202 break; | 4202 break; |
| 4203 } | 4203 } |
| 4204 | 4204 |
| 4205 quadListIterator++; | 4205 quadListIterator++; |
| 4206 } | 4206 } |
| 4207 *pos = '\n'; | 4207 *pos = '\n'; |
| 4208 pos++; | 4208 pos++; |
| 4209 } | 4209 } |
| 4210 *pos = '\0'; | 4210 *pos = '\0'; |
| 4211 } | 4211 } |
| 4212 | 4212 |
| 4213 // Each CCRenderPassList is represented by a string which describes the configur
ation. | 4213 // Each RenderPassList is represented by a string which describes the configurat
ion. |
| 4214 // The syntax of the string is as follows: | 4214 // The syntax of the string is as follows: |
| 4215 // | 4215 // |
| 4216 // RsssssX[c]ssYsssZ[t]ssW[
ct] | 4216 // RsssssX[c]ssYsssZ[t]ssW[
ct] |
| 4217 // Identifies the render pass---------------------------^ ^^^ ^ ^ ^ ^
^ | 4217 // Identifies the render pass---------------------------^ ^^^ ^ ^ ^ ^
^ |
| 4218 // These are solid color quads-----------------------------+ | | | |
| | 4218 // These are solid color quads-----------------------------+ | | | |
| |
| 4219 // Identifies RenderPassDrawQuad's RenderPass-----------------+ | | |
| | 4219 // Identifies RenderPassDrawQuad's RenderPass-----------------+ | | |
| |
| 4220 // This quad's contents didn't change---------------------------+ | |
| | 4220 // This quad's contents didn't change---------------------------+ | |
| |
| 4221 // This quad's contents changed and it has no texture---------------+ |
| | 4221 // This quad's contents changed and it has no texture---------------+ |
| |
| 4222 // This quad has texture but its contents changed-------------------------+
| | 4222 // This quad has texture but its contents changed-------------------------+
| |
| 4223 // This quad's contents didn't change and it has texture - will be removed------
+ | 4223 // This quad's contents didn't change and it has texture - will be removed------
+ |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4351 } | 4351 } |
| 4352 }; | 4352 }; |
| 4353 | 4353 |
| 4354 static void verifyRenderPassTestData(TestCase& testCase, RenderPassRemovalTestDa
ta& testData) | 4354 static void verifyRenderPassTestData(TestCase& testCase, RenderPassRemovalTestDa
ta& testData) |
| 4355 { | 4355 { |
| 4356 char actualResult[1024]; | 4356 char actualResult[1024]; |
| 4357 dumpRenderPassTestData(testData, actualResult); | 4357 dumpRenderPassTestData(testData, actualResult); |
| 4358 EXPECT_STREQ(testCase.expectedResult, actualResult) << "In test case: " << t
estCase.name; | 4358 EXPECT_STREQ(testCase.expectedResult, actualResult) << "In test case: " << t
estCase.name; |
| 4359 } | 4359 } |
| 4360 | 4360 |
| 4361 TEST_P(CCLayerTreeHostImplTest, testRemoveRenderPasses) | 4361 TEST_P(LayerTreeHostImplTest, testRemoveRenderPasses) |
| 4362 { | 4362 { |
| 4363 scoped_ptr<CCGraphicsContext> context(createContext()); | 4363 scoped_ptr<GraphicsContext> context(createContext()); |
| 4364 ASSERT_TRUE(context->context3D()); | 4364 ASSERT_TRUE(context->context3D()); |
| 4365 scoped_ptr<CCResourceProvider> resourceProvider(CCResourceProvider::create(c
ontext.get())); | 4365 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte
xt.get())); |
| 4366 | 4366 |
| 4367 scoped_ptr<CCTestRenderer> renderer(CCTestRenderer::create(resourceProvider.
get())); | 4367 scoped_ptr<TestRenderer> renderer(TestRenderer::create(resourceProvider.get(
))); |
| 4368 | 4368 |
| 4369 int testCaseIndex = 0; | 4369 int testCaseIndex = 0; |
| 4370 while (removeRenderPassesCases[testCaseIndex].name) { | 4370 while (removeRenderPassesCases[testCaseIndex].name) { |
| 4371 RenderPassRemovalTestData testData; | 4371 RenderPassRemovalTestData testData; |
| 4372 configureRenderPassTestData(removeRenderPassesCases[testCaseIndex].initS
cript, testData, renderer.get()); | 4372 configureRenderPassTestData(removeRenderPassesCases[testCaseIndex].initS
cript, testData, renderer.get()); |
| 4373 CCLayerTreeHostImpl::removeRenderPasses(CCLayerTreeHostImpl::CullRenderP
assesWithCachedTextures(*renderer), testData); | 4373 LayerTreeHostImpl::removeRenderPasses(LayerTreeHostImpl::CullRenderPasse
sWithCachedTextures(*renderer), testData); |
| 4374 verifyRenderPassTestData(removeRenderPassesCases[testCaseIndex], testDat
a); | 4374 verifyRenderPassTestData(removeRenderPassesCases[testCaseIndex], testDat
a); |
| 4375 testCaseIndex++; | 4375 testCaseIndex++; |
| 4376 } | 4376 } |
| 4377 } | 4377 } |
| 4378 | 4378 |
| 4379 INSTANTIATE_TEST_CASE_P(CCLayerTreeHostImplTests, | 4379 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, |
| 4380 CCLayerTreeHostImplTest, | 4380 LayerTreeHostImplTest, |
| 4381 ::testing::Values(false, true)); | 4381 ::testing::Values(false, true)); |
| 4382 | 4382 |
| 4383 } // namespace | 4383 } // namespace |
| OLD | NEW |