[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame^] | 5 | #include "cc/trees/layer_tree_host_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 7 | #include <cmath> |
| 8 | |
[email protected] | 59cb7b35 | 2012-10-30 06:45:48 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | 65bfd997 | 2012-10-19 03:39:37 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | c7278e5b | 2012-10-11 02:35:46 | [diff] [blame] | 11 | #include "base/hash_tables.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 12 | #include "cc/base/math_util.h" |
[email protected] | aa0a9d3 | 2012-10-24 01:58:10 | [diff] [blame] | 13 | #include "cc/delegated_renderer_layer_impl.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 14 | #include "cc/heads_up_display_layer_impl.h" |
[email protected] | 3052b10f | 2013-03-18 07:41:21 | [diff] [blame] | 15 | #include "cc/input/top_controls_manager.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 16 | #include "cc/io_surface_layer_impl.h" |
| 17 | #include "cc/layer_impl.h" |
| 18 | #include "cc/layer_tiling_data.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 19 | #include "cc/output/compositor_frame_metadata.h" |
| 20 | #include "cc/output/gl_renderer.h" |
[email protected] | 55a124d0 | 2012-10-22 03:07:13 | [diff] [blame] | 21 | #include "cc/quad_sink.h" |
[email protected] | 89e8267a | 2013-03-18 07:50:56 | [diff] [blame] | 22 | #include "cc/quads/render_pass_draw_quad.h" |
| 23 | #include "cc/quads/solid_color_draw_quad.h" |
| 24 | #include "cc/quads/texture_draw_quad.h" |
| 25 | #include "cc/quads/tile_draw_quad.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 26 | #include "cc/scrollbar_geometry_fixed_thumb.h" |
| 27 | #include "cc/scrollbar_layer_impl.h" |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 28 | #include "cc/solid_color_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 29 | #include "cc/test/animation_test_common.h" |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 30 | #include "cc/test/fake_output_surface.h" |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 31 | #include "cc/test/fake_proxy.h" |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 32 | #include "cc/test/fake_video_frame_provider.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 33 | #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
| 34 | #include "cc/test/geometry_test_utils.h" |
| 35 | #include "cc/test/layer_test_common.h" |
| 36 | #include "cc/test/render_pass_test_common.h" |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 37 | #include "cc/test/test_web_graphics_context_3d.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 38 | #include "cc/texture_layer_impl.h" |
[email protected] | da2c912 | 2012-10-20 23:13:06 | [diff] [blame] | 39 | #include "cc/tiled_layer_impl.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame^] | 40 | #include "cc/trees/layer_tree_impl.h" |
| 41 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | da2c912 | 2012-10-20 23:13:06 | [diff] [blame] | 42 | #include "cc/video_layer_impl.h" |
[email protected] | 59cb7b35 | 2012-10-30 06:45:48 | [diff] [blame] | 43 | #include "media/base/media.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 44 | #include "testing/gmock/include/gmock/gmock.h" |
| 45 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 46 | #include "ui/gfx/size_conversions.h" |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 47 | #include "ui/gfx/vector2d_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 49 | using ::testing::Mock; |
| 50 | using ::testing::Return; |
| 51 | using ::testing::AnyNumber; |
| 52 | using ::testing::AtLeast; |
| 53 | using ::testing::_; |
[email protected] | 568285b | 2013-01-07 23:19:19 | [diff] [blame] | 54 | using media::VideoFrame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 55 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 56 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 57 | namespace { |
| 58 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 59 | class LayerTreeHostImplTest : public testing::Test, |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 60 | public LayerTreeHostImplClient { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 61 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 62 | LayerTreeHostImplTest() |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 63 | : m_proxy(scoped_ptr<Thread>(NULL)) |
| 64 | , m_alwaysImplThread(&m_proxy) |
| 65 | , m_alwaysMainThreadBlocked(&m_proxy) |
| 66 | , m_onCanDrawStateChangedCalled(false) |
[email protected] | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 67 | , m_hasPendingTree(false) |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 68 | , m_didRequestCommit(false) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 69 | , m_didRequestRedraw(false) |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 70 | , m_didUploadVisibleTile(false) |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 71 | , m_reduceMemoryResult(true) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 72 | { |
[email protected] | 59cb7b35 | 2012-10-30 06:45:48 | [diff] [blame] | 73 | media::InitializeMediaLibraryForTesting(); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | virtual void SetUp() |
| 77 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 78 | LayerTreeSettings settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 79 | settings.minimumOcclusionTrackingSize = gfx::Size(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 80 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 81 | m_hostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
| 82 | m_hostImpl->InitializeRenderer(createOutputSurface()); |
| 83 | m_hostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 84 | } |
| 85 | |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 86 | virtual void TearDown() |
| 87 | { |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 88 | } |
| 89 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 90 | virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE { } |
| 91 | virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE { } |
| 92 | virtual void OnVSyncParametersChanged(base::TimeTicks, base::TimeDelta) OVERRIDE { } |
| 93 | virtual void OnCanDrawStateChanged(bool canDraw) OVERRIDE { m_onCanDrawStateChangedCalled = true; } |
| 94 | virtual void OnHasPendingTreeStateChanged(bool hasPendingTree) OVERRIDE { m_hasPendingTree = hasPendingTree; } |
| 95 | virtual void SetNeedsRedrawOnImplThread() OVERRIDE { m_didRequestRedraw = true; } |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 96 | virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE { m_didUploadVisibleTile = true; } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 97 | virtual void SetNeedsCommitOnImplThread() OVERRIDE { m_didRequestCommit = true; } |
| 98 | virtual void SetNeedsManageTilesOnImplThread() OVERRIDE { } |
| 99 | virtual void PostAnimationEventsToMainThreadOnImplThread(scoped_ptr<AnimationEventsVector>, base::Time wallClockTime) OVERRIDE { } |
| 100 | virtual bool ReduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff) OVERRIDE { return m_reduceMemoryResult; } |
| 101 | virtual void ReduceWastedContentsTextureMemoryOnImplThread() OVERRIDE { } |
| 102 | virtual void SendManagedMemoryStats() OVERRIDE { } |
| 103 | virtual bool IsInsideDraw() OVERRIDE { return false; } |
| 104 | virtual void RenewTreePriority() OVERRIDE { } |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 105 | virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) OVERRIDE { } |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 106 | |
| 107 | void setReduceMemoryResult(bool reduceMemoryResult) { m_reduceMemoryResult = reduceMemoryResult; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 108 | |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 109 | void createLayerTreeHost(bool partialSwap, scoped_ptr<OutputSurface> outputSurface) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 110 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 111 | LayerTreeSettings settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 112 | settings.minimumOcclusionTrackingSize = gfx::Size(); |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 113 | settings.partialSwapEnabled = partialSwap; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 114 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 115 | m_hostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 116 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 117 | m_hostImpl->InitializeRenderer(outputSurface.Pass()); |
| 118 | m_hostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 119 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 120 | |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 121 | void setupRootLayerImpl(scoped_ptr<LayerImpl> root) |
| 122 | { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 123 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 124 | root->SetPosition(gfx::PointF(0, 0)); |
| 125 | root->SetBounds(gfx::Size(10, 10)); |
| 126 | root->SetContentBounds(gfx::Size(10, 10)); |
| 127 | root->SetDrawsContent(true); |
| 128 | root->draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 129 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 130 | } |
| 131 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 132 | static void expectClearedScrollDeltasRecursive(LayerImpl* layer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 133 | { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 134 | ASSERT_EQ(layer->scroll_delta(), gfx::Vector2d()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 135 | for (size_t i = 0; i < layer->children().size(); ++i) |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 136 | expectClearedScrollDeltasRecursive(layer->children()[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 137 | } |
| 138 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 139 | static void expectContains(const ScrollAndScaleSet& scrollInfo, int id, const gfx::Vector2d& scrollDelta) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 140 | { |
| 141 | int timesEncountered = 0; |
| 142 | |
| 143 | for (size_t i = 0; i < scrollInfo.scrolls.size(); ++i) { |
| 144 | if (scrollInfo.scrolls[i].layerId != id) |
| 145 | continue; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 146 | EXPECT_VECTOR_EQ(scrollDelta, scrollInfo.scrolls[i].scrollDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 147 | timesEncountered++; |
| 148 | } |
| 149 | |
| 150 | ASSERT_EQ(timesEncountered, 1); |
| 151 | } |
| 152 | |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 153 | static void expectNone(const ScrollAndScaleSet& scrollInfo, int id) |
| 154 | { |
| 155 | int timesEncountered = 0; |
| 156 | |
| 157 | for (size_t i = 0; i < scrollInfo.scrolls.size(); ++i) { |
| 158 | if (scrollInfo.scrolls[i].layerId != id) |
| 159 | continue; |
| 160 | timesEncountered++; |
| 161 | } |
| 162 | |
| 163 | ASSERT_EQ(0, timesEncountered); |
| 164 | } |
| 165 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 166 | void setupScrollAndContentsLayers(const gfx::Size& contentSize) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 167 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 168 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 169 | root->SetScrollable(true); |
| 170 | root->SetScrollOffset(gfx::Vector2d(0, 0)); |
| 171 | root->SetMaxScrollOffset(gfx::Vector2d(contentSize.width(), contentSize.height())); |
| 172 | root->SetBounds(contentSize); |
| 173 | root->SetContentBounds(contentSize); |
| 174 | root->SetPosition(gfx::PointF(0, 0)); |
| 175 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 176 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 177 | scoped_ptr<LayerImpl> contents = LayerImpl::Create(m_hostImpl->active_tree(), 2); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 178 | contents->SetDrawsContent(true); |
| 179 | contents->SetBounds(contentSize); |
| 180 | contents->SetContentBounds(contentSize); |
| 181 | contents->SetPosition(gfx::PointF(0, 0)); |
| 182 | contents->SetAnchorPoint(gfx::PointF(0, 0)); |
| 183 | root->AddChild(contents.Pass()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 184 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 185 | m_hostImpl->active_tree()->DidBecomeActive(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 188 | scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size& size) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 189 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 190 | scoped_ptr<LayerImpl> layer = LayerImpl::Create(m_hostImpl->active_tree(), id); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 191 | layer->SetScrollable(true); |
| 192 | layer->SetDrawsContent(true); |
| 193 | layer->SetBounds(size); |
| 194 | layer->SetContentBounds(size); |
| 195 | layer->SetMaxScrollOffset(gfx::Vector2d(size.width() * 2, size.height() * 2)); |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 196 | return layer.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void initializeRendererAndDrawFrame() |
| 200 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 201 | m_hostImpl->InitializeRenderer(createOutputSurface()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 202 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 203 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 204 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 205 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 206 | } |
| 207 | |
[email protected] | aeaa50a | 2012-11-21 20:12:37 | [diff] [blame] | 208 | void pinchZoomPanViewportForcesCommitRedraw(const float deviceScaleFactor); |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 209 | void pinchZoomPanViewportTest(const float deviceScaleFactor); |
| 210 | void pinchZoomPanViewportAndScrollTest(const float deviceScaleFactor); |
| 211 | void pinchZoomPanViewportAndScrollBoundaryTest(const float deviceScaleFactor); |
[email protected] | aeaa50a | 2012-11-21 20:12:37 | [diff] [blame] | 212 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 213 | protected: |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 214 | virtual scoped_ptr<OutputSurface> createOutputSurface() { return createFakeOutputSurface(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 215 | |
[email protected] | 2d69299 | 2012-12-19 01:19:32 | [diff] [blame] | 216 | void drawOneFrame() { |
| 217 | LayerTreeHostImpl::FrameData frameData; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 218 | m_hostImpl->PrepareToDraw(&frameData); |
| 219 | m_hostImpl->DidDrawAllLayers(frameData); |
[email protected] | 2d69299 | 2012-12-19 01:19:32 | [diff] [blame] | 220 | } |
| 221 | |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 222 | FakeProxy m_proxy; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 223 | DebugScopedSetImplThread m_alwaysImplThread; |
| 224 | DebugScopedSetMainThreadBlocked m_alwaysMainThreadBlocked; |
| 225 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 226 | scoped_ptr<LayerTreeHostImpl> m_hostImpl; |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 227 | bool m_onCanDrawStateChangedCalled; |
[email protected] | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 228 | bool m_hasPendingTree; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 229 | bool m_didRequestCommit; |
| 230 | bool m_didRequestRedraw; |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 231 | bool m_didUploadVisibleTile; |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 232 | bool m_reduceMemoryResult; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 233 | }; |
| 234 | |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 235 | class TestWebGraphicsContext3DMakeCurrentFails : public TestWebGraphicsContext3D { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 236 | public: |
| 237 | virtual bool makeContextCurrent() { return false; } |
| 238 | }; |
| 239 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 240 | TEST_F(LayerTreeHostImplTest, notifyIfCanDrawChanged) |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 241 | { |
| 242 | // Note: It is not possible to disable the renderer once it has been set, |
| 243 | // so we do not need to test that disabling the renderer notifies us |
| 244 | // that canDraw changed. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 245 | EXPECT_FALSE(m_hostImpl->CanDraw()); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 246 | m_onCanDrawStateChangedCalled = false; |
| 247 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 248 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 249 | EXPECT_TRUE(m_hostImpl->CanDraw()); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 250 | EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 251 | m_onCanDrawStateChangedCalled = false; |
| 252 | |
| 253 | // Toggle the root layer to make sure it toggles canDraw |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 254 | m_hostImpl->active_tree()->SetRootLayer(scoped_ptr<LayerImpl>()); |
| 255 | EXPECT_FALSE(m_hostImpl->CanDraw()); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 256 | EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 257 | m_onCanDrawStateChangedCalled = false; |
| 258 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 259 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 260 | EXPECT_TRUE(m_hostImpl->CanDraw()); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 261 | EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 262 | m_onCanDrawStateChangedCalled = false; |
| 263 | |
| 264 | // Toggle the device viewport size to make sure it toggles canDraw. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 265 | m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(0, 0)); |
| 266 | EXPECT_FALSE(m_hostImpl->CanDraw()); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 267 | EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 268 | m_onCanDrawStateChangedCalled = false; |
| 269 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 270 | m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); |
| 271 | EXPECT_TRUE(m_hostImpl->CanDraw()); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 272 | EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 273 | m_onCanDrawStateChangedCalled = false; |
| 274 | |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 275 | // Toggle contents textures purged without causing any evictions, |
| 276 | // and make sure that it does not change canDraw. |
| 277 | setReduceMemoryResult(false); |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 278 | m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 279 | m_hostImpl->memory_allocation_limit_bytes() - 1)); |
| 280 | EXPECT_TRUE(m_hostImpl->CanDraw()); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 281 | EXPECT_FALSE(m_onCanDrawStateChangedCalled); |
| 282 | m_onCanDrawStateChangedCalled = false; |
| 283 | |
| 284 | // Toggle contents textures purged to make sure it toggles canDraw. |
| 285 | setReduceMemoryResult(true); |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 286 | m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 287 | m_hostImpl->memory_allocation_limit_bytes() - 1)); |
| 288 | EXPECT_FALSE(m_hostImpl->CanDraw()); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 289 | EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 290 | m_onCanDrawStateChangedCalled = false; |
| 291 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 292 | m_hostImpl->active_tree()->ResetContentsTexturesPurged(); |
| 293 | EXPECT_TRUE(m_hostImpl->CanDraw()); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 294 | EXPECT_TRUE(m_onCanDrawStateChangedCalled); |
| 295 | m_onCanDrawStateChangedCalled = false; |
| 296 | } |
| 297 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 298 | TEST_F(LayerTreeHostImplTest, scrollDeltaNoLayers) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 299 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 300 | ASSERT_FALSE(m_hostImpl->active_tree()->root_layer()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 301 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 302 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 303 | ASSERT_EQ(scrollInfo->scrolls.size(), 0u); |
| 304 | } |
| 305 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 306 | TEST_F(LayerTreeHostImplTest, scrollDeltaTreeButNoChanges) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 307 | { |
| 308 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 309 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
| 310 | root->AddChild(LayerImpl::Create(m_hostImpl->active_tree(), 2)); |
| 311 | root->AddChild(LayerImpl::Create(m_hostImpl->active_tree(), 3)); |
| 312 | root->children()[1]->AddChild(LayerImpl::Create(m_hostImpl->active_tree(), 4)); |
| 313 | root->children()[1]->AddChild(LayerImpl::Create(m_hostImpl->active_tree(), 5)); |
| 314 | root->children()[1]->children()[0]->AddChild(LayerImpl::Create(m_hostImpl->active_tree(), 6)); |
| 315 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 316 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 317 | LayerImpl* root = m_hostImpl->active_tree()->root_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 318 | |
| 319 | expectClearedScrollDeltasRecursive(root); |
| 320 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 321 | scoped_ptr<ScrollAndScaleSet> scrollInfo; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 322 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 323 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 324 | ASSERT_EQ(scrollInfo->scrolls.size(), 0u); |
| 325 | expectClearedScrollDeltasRecursive(root); |
| 326 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 327 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 328 | ASSERT_EQ(scrollInfo->scrolls.size(), 0u); |
| 329 | expectClearedScrollDeltasRecursive(root); |
| 330 | } |
| 331 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 332 | TEST_F(LayerTreeHostImplTest, scrollDeltaRepeatedScrolls) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 333 | { |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 334 | gfx::Vector2d scrollOffset(20, 30); |
| 335 | gfx::Vector2d scrollDelta(11, -15); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 336 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 337 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 338 | root->SetScrollOffset(scrollOffset); |
| 339 | root->SetScrollable(true); |
| 340 | root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 341 | root->ScrollBy(scrollDelta); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 342 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 343 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 344 | LayerImpl* root = m_hostImpl->active_tree()->root_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 345 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 346 | scoped_ptr<ScrollAndScaleSet> scrollInfo; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 347 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 348 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 349 | ASSERT_EQ(scrollInfo->scrolls.size(), 1u); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 350 | EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scrollDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 351 | expectContains(*scrollInfo, root->id(), scrollDelta); |
| 352 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 353 | gfx::Vector2d scrollDelta2(-5, 27); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 354 | root->ScrollBy(scrollDelta2); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 355 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 356 | ASSERT_EQ(scrollInfo->scrolls.size(), 1u); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 357 | EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scrollDelta + scrollDelta2); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 358 | expectContains(*scrollInfo, root->id(), scrollDelta + scrollDelta2); |
| 359 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 360 | root->ScrollBy(gfx::Vector2d()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 361 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 362 | EXPECT_EQ(root->sent_scroll_delta(), scrollDelta + scrollDelta2); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 363 | } |
| 364 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 365 | TEST_F(LayerTreeHostImplTest, scrollRootCallsCommitAndRedraw) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 366 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 367 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 368 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 369 | initializeRendererAndDrawFrame(); |
| 370 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 371 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 372 | m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 373 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 374 | EXPECT_TRUE(m_didRequestRedraw); |
| 375 | EXPECT_TRUE(m_didRequestCommit); |
| 376 | } |
| 377 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 378 | TEST_F(LayerTreeHostImplTest, scrollWithoutRootLayer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 379 | { |
| 380 | // We should not crash when trying to scroll an empty layer tree. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 381 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollIgnored); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 382 | } |
| 383 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 384 | TEST_F(LayerTreeHostImplTest, scrollWithoutRenderer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 385 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 386 | LayerTreeSettings settings; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 387 | m_hostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 388 | |
| 389 | // Initialization will fail here. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 390 | m_hostImpl->InitializeRenderer(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new TestWebGraphicsContext3DMakeCurrentFails)).PassAs<OutputSurface>()); |
| 391 | m_hostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 392 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 393 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 394 | |
| 395 | // We should not crash when trying to scroll after the renderer initialization fails. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 396 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollIgnored); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 397 | } |
| 398 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 399 | TEST_F(LayerTreeHostImplTest, replaceTreeWhileScrolling) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 400 | { |
| 401 | const int scrollLayerId = 1; |
| 402 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 403 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 404 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 405 | initializeRendererAndDrawFrame(); |
| 406 | |
| 407 | // We should not crash if the tree is replaced while we are scrolling. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 408 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 409 | m_hostImpl->active_tree()->DetachLayerTree(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 410 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 411 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 412 | |
| 413 | // We should still be scrolling, because the scrolled layer also exists in the new tree. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 414 | gfx::Vector2d scrollDelta(0, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 415 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 416 | m_hostImpl->ScrollEnd(); |
| 417 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 418 | expectContains(*scrollInfo, scrollLayerId, scrollDelta); |
| 419 | } |
| 420 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 421 | TEST_F(LayerTreeHostImplTest, clearRootRenderSurfaceAndScroll) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 422 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 423 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 424 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 425 | initializeRendererAndDrawFrame(); |
| 426 | |
| 427 | // We should be able to scroll even if the root layer loses its render surface after the most |
| 428 | // recent render. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 429 | m_hostImpl->active_tree()->root_layer()->ClearRenderSurface(); |
| 430 | m_hostImpl->active_tree()->set_needs_update_draw_properties(); |
[email protected] | 0ede3bb | 2012-12-09 09:14:39 | [diff] [blame] | 431 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 432 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 433 | } |
| 434 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 435 | TEST_F(LayerTreeHostImplTest, wheelEventHandlers) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 436 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 437 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 438 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 439 | initializeRendererAndDrawFrame(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 440 | LayerImpl* root = m_hostImpl->active_tree()->root_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 441 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 442 | root->SetHaveWheelEventHandlers(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 443 | |
| 444 | // With registered event handlers, wheel scrolls have to go to the main thread. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 445 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollOnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 446 | |
| 447 | // But gesture scrolls can still be handled. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 448 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture), InputHandlerClient::ScrollStarted); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 449 | } |
| 450 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 451 | TEST_F(LayerTreeHostImplTest, shouldScrollOnMainThread) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 452 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 453 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 454 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 455 | initializeRendererAndDrawFrame(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 456 | LayerImpl* root = m_hostImpl->active_tree()->root_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 457 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 458 | root->SetShouldScrollOnMainThread(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 459 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 460 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollOnMainThread); |
| 461 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture), InputHandlerClient::ScrollOnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 462 | } |
| 463 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 464 | TEST_F(LayerTreeHostImplTest, nonFastScrollableRegionBasic) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 465 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 466 | setupScrollAndContentsLayers(gfx::Size(200, 200)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 467 | m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 468 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 469 | LayerImpl* root = m_hostImpl->active_tree()->root_layer(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 470 | root->SetContentsScale(2, 2); |
| 471 | root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 472 | |
[email protected] | a90aa70 | 2012-11-07 04:48:24 | [diff] [blame] | 473 | initializeRendererAndDrawFrame(); |
| 474 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 475 | // All scroll types inside the non-fast scrollable region should fail. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 476 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(25, 25), InputHandlerClient::Wheel), InputHandlerClient::ScrollOnMainThread); |
| 477 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(25, 25), InputHandlerClient::Gesture), InputHandlerClient::ScrollOnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 478 | |
| 479 | // All scroll types outside this region should succeed. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 480 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(75, 75), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 481 | m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 482 | m_hostImpl->ScrollEnd(); |
| 483 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(75, 75), InputHandlerClient::Gesture), InputHandlerClient::ScrollStarted); |
| 484 | m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 485 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 486 | } |
| 487 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 488 | TEST_F(LayerTreeHostImplTest, nonFastScrollableRegionWithOffset) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 489 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 490 | setupScrollAndContentsLayers(gfx::Size(200, 200)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 491 | m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 492 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 493 | LayerImpl* root = m_hostImpl->active_tree()->root_layer(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 494 | root->SetContentsScale(2, 2); |
| 495 | root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 496 | root->SetPosition(gfx::PointF(-25, 0)); |
[email protected] | a90aa70 | 2012-11-07 04:48:24 | [diff] [blame] | 497 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 498 | initializeRendererAndDrawFrame(); |
| 499 | |
| 500 | // This point would fall into the non-fast scrollable region except that we've moved the layer down by 25 pixels. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 501 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(40, 10), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 502 | m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 1)); |
| 503 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 504 | |
| 505 | // This point is still inside the non-fast region. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 506 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(10, 10), InputHandlerClient::Wheel), InputHandlerClient::ScrollOnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 507 | } |
| 508 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 509 | TEST_F(LayerTreeHostImplTest, scrollByReturnsCorrectValue) |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 510 | { |
| 511 | setupScrollAndContentsLayers(gfx::Size(200, 200)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 512 | m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 513 | |
| 514 | initializeRendererAndDrawFrame(); |
| 515 | |
| 516 | EXPECT_EQ(InputHandlerClient::ScrollStarted, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 517 | m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture)); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 518 | |
| 519 | // Trying to scroll to the left/top will not succeed. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 520 | EXPECT_FALSE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); |
| 521 | EXPECT_FALSE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10))); |
| 522 | EXPECT_FALSE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, -10))); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 523 | |
| 524 | // Scrolling to the right/bottom will succeed. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 525 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0))); |
| 526 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10))); |
| 527 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(10, 10))); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 528 | |
| 529 | // Scrolling to left/top will now succeed. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 530 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); |
| 531 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10))); |
| 532 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, -10))); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 533 | |
[email protected] | 1ca52a3a | 2012-12-04 22:47:10 | [diff] [blame] | 534 | // Scrolling diagonally against an edge will succeed. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 535 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(10, -10))); |
| 536 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); |
| 537 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 10))); |
[email protected] | 1ca52a3a | 2012-12-04 22:47:10 | [diff] [blame] | 538 | |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 539 | // Trying to scroll more than the available space will also succeed. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 540 | EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(5000, 5000))); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 541 | } |
| 542 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 543 | TEST_F(LayerTreeHostImplTest, clearRootRenderSurfaceAndHitTestTouchHandlerRegion) |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 544 | { |
| 545 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 546 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 547 | initializeRendererAndDrawFrame(); |
| 548 | |
| 549 | // We should be able to hit test for touch event handlers even if the root layer loses |
| 550 | // its render surface after the most recent render. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 551 | m_hostImpl->active_tree()->root_layer()->ClearRenderSurface(); |
| 552 | m_hostImpl->active_tree()->set_needs_update_draw_properties(); |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 553 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 554 | EXPECT_EQ(m_hostImpl->HaveTouchEventHandlersAt(gfx::Point(0, 0)), false); |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 555 | } |
| 556 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 557 | TEST_F(LayerTreeHostImplTest, implPinchZoom) |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 558 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 559 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 560 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 561 | initializeRendererAndDrawFrame(); |
| 562 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 563 | LayerImpl* scrollLayer = m_hostImpl->RootScrollLayer(); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 564 | DCHECK(scrollLayer); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 565 | |
| 566 | const float minPageScale = 1, maxPageScale = 4; |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 567 | const gfx::Transform identityScaleTransform; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 568 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 569 | // The impl-based pinch zoom should adjust the max scroll position. |
| 570 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 571 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 572 | m_hostImpl->active_tree()->SetPageScaleDelta(1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 573 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 574 | scrollLayer->SetScrollDelta(gfx::Vector2d()); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 575 | |
| 576 | float pageScaleDelta = 2; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 577 | m_hostImpl->PinchGestureBegin(); |
| 578 | m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); |
| 579 | m_hostImpl->PinchGestureEnd(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 580 | EXPECT_TRUE(m_didRequestRedraw); |
| 581 | EXPECT_TRUE(m_didRequestCommit); |
| 582 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 583 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 584 | EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 585 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 586 | EXPECT_EQ(gfx::Vector2d(75, 75), m_hostImpl->active_tree()->root_layer()->max_scroll_offset()); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 587 | } |
| 588 | |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 589 | // Scrolling after a pinch gesture should always be in local space. The scroll deltas do not |
| 590 | // have the page scale factor applied. |
| 591 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 592 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
| 593 | m_hostImpl->active_tree()->SetPageScaleDelta(1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 594 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 595 | scrollLayer->SetScrollDelta(gfx::Vector2d()); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 596 | |
| 597 | float pageScaleDelta = 2; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 598 | m_hostImpl->PinchGestureBegin(); |
| 599 | m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0)); |
| 600 | m_hostImpl->PinchGestureEnd(); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 601 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 602 | gfx::Vector2d scrollDelta(0, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 603 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 604 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 605 | m_hostImpl->ScrollEnd(); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 606 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 607 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
| 608 | expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->id(), scrollDelta); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 612 | TEST_F(LayerTreeHostImplTest, pinchGesture) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 613 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 614 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 615 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 616 | initializeRendererAndDrawFrame(); |
| 617 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 618 | LayerImpl* scrollLayer = m_hostImpl->RootScrollLayer(); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 619 | DCHECK(scrollLayer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 620 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 621 | const float minPageScale = 1; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 622 | const float maxPageScale = 4; |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 623 | const gfx::Transform identityScaleTransform; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 624 | |
| 625 | // Basic pinch zoom in gesture |
| 626 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 627 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 628 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 629 | scrollLayer->SetScrollDelta(gfx::Vector2d()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 630 | |
| 631 | float pageScaleDelta = 2; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 632 | m_hostImpl->PinchGestureBegin(); |
| 633 | m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); |
| 634 | m_hostImpl->PinchGestureEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 635 | EXPECT_TRUE(m_didRequestRedraw); |
| 636 | EXPECT_TRUE(m_didRequestCommit); |
| 637 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 638 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 639 | EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
| 640 | } |
| 641 | |
| 642 | // Zoom-in clamping |
| 643 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 644 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 645 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 646 | scrollLayer->SetScrollDelta(gfx::Vector2d()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 647 | float pageScaleDelta = 10; |
| 648 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 649 | m_hostImpl->PinchGestureBegin(); |
| 650 | m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); |
| 651 | m_hostImpl->PinchGestureEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 652 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 653 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 654 | EXPECT_EQ(scrollInfo->pageScaleDelta, maxPageScale); |
| 655 | } |
| 656 | |
| 657 | // Zoom-out clamping |
| 658 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 659 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 660 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 661 | scrollLayer->SetScrollDelta(gfx::Vector2d()); |
| 662 | scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 663 | |
| 664 | float pageScaleDelta = 0.1f; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 665 | m_hostImpl->PinchGestureBegin(); |
| 666 | m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0)); |
| 667 | m_hostImpl->PinchGestureEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 668 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 669 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 670 | EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 671 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 672 | EXPECT_TRUE(scrollInfo->scrolls.empty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 673 | } |
| 674 | |
[email protected] | c77745d | 2012-11-20 04:11:57 | [diff] [blame] | 675 | // Two-finger panning should not happen based on pinch events only |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 676 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 677 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 678 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 679 | scrollLayer->SetScrollDelta(gfx::Vector2d()); |
| 680 | scrollLayer->SetScrollOffset(gfx::Vector2d(20, 20)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 681 | |
| 682 | float pageScaleDelta = 1; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 683 | m_hostImpl->PinchGestureBegin(); |
| 684 | m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(10, 10)); |
| 685 | m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(20, 20)); |
| 686 | m_hostImpl->PinchGestureEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 687 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 688 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 689 | EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
[email protected] | c77745d | 2012-11-20 04:11:57 | [diff] [blame] | 690 | EXPECT_TRUE(scrollInfo->scrolls.empty()); |
| 691 | } |
| 692 | |
| 693 | // Two-finger panning should work with interleaved scroll events |
| 694 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 695 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 696 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 697 | scrollLayer->SetScrollDelta(gfx::Vector2d()); |
| 698 | scrollLayer->SetScrollOffset(gfx::Vector2d(20, 20)); |
[email protected] | c77745d | 2012-11-20 04:11:57 | [diff] [blame] | 699 | |
| 700 | float pageScaleDelta = 1; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 701 | m_hostImpl->ScrollBegin(gfx::Point(10, 10), InputHandlerClient::Wheel); |
| 702 | m_hostImpl->PinchGestureBegin(); |
| 703 | m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(10, 10)); |
| 704 | m_hostImpl->ScrollBy(gfx::Point(10, 10), gfx::Vector2d(-10, -10)); |
| 705 | m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(20, 20)); |
| 706 | m_hostImpl->PinchGestureEnd(); |
| 707 | m_hostImpl->ScrollEnd(); |
[email protected] | c77745d | 2012-11-20 04:11:57 | [diff] [blame] | 708 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 709 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | c77745d | 2012-11-20 04:11:57 | [diff] [blame] | 710 | EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 711 | expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-10, -10)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 715 | TEST_F(LayerTreeHostImplTest, pageScaleAnimation) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 716 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 717 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 718 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 719 | initializeRendererAndDrawFrame(); |
| 720 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 721 | LayerImpl* scrollLayer = m_hostImpl->RootScrollLayer(); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 722 | DCHECK(scrollLayer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 723 | |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 724 | const float minPageScale = 0.5; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 725 | const float maxPageScale = 4; |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 726 | const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromSeconds(1); |
| 727 | const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 728 | const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2; |
| 729 | const base::TimeTicks endTime = startTime + duration; |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 730 | const gfx::Transform identityScaleTransform; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 731 | |
| 732 | // Non-anchor zoom-in |
| 733 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 734 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 735 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 736 | scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 737 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 738 | m_hostImpl->StartPageScaleAnimation(gfx::Vector2d(0, 0), false, 2, startTime, duration); |
| 739 | m_hostImpl->Animate(halfwayThroughAnimation, base::Time()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 740 | EXPECT_TRUE(m_didRequestRedraw); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 741 | m_hostImpl->Animate(endTime, base::Time()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 742 | EXPECT_TRUE(m_didRequestCommit); |
| 743 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 744 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 745 | EXPECT_EQ(scrollInfo->pageScaleDelta, 2); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 746 | expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | // Anchor zoom-out |
| 750 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 751 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 752 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 753 | scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 754 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 755 | m_hostImpl->StartPageScaleAnimation(gfx::Vector2d(25, 25), true, minPageScale, startTime, duration); |
| 756 | m_hostImpl->Animate(endTime, base::Time()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 757 | EXPECT_TRUE(m_didRequestRedraw); |
| 758 | EXPECT_TRUE(m_didRequestCommit); |
| 759 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 760 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 761 | EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); |
| 762 | // Pushed to (0,0) via clamping against contents layer size. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 763 | expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 767 | TEST_F(LayerTreeHostImplTest, pageScaleAnimationNoOp) |
[email protected] | f350449c | 2013-01-31 21:20:36 | [diff] [blame] | 768 | { |
| 769 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 770 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
[email protected] | f350449c | 2013-01-31 21:20:36 | [diff] [blame] | 771 | initializeRendererAndDrawFrame(); |
| 772 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 773 | LayerImpl* scrollLayer = m_hostImpl->RootScrollLayer(); |
[email protected] | f350449c | 2013-01-31 21:20:36 | [diff] [blame] | 774 | DCHECK(scrollLayer); |
| 775 | |
| 776 | const float minPageScale = 0.5; |
| 777 | const float maxPageScale = 4; |
| 778 | const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromSeconds(1); |
| 779 | const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 780 | const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2; |
| 781 | const base::TimeTicks endTime = startTime + duration; |
| 782 | const gfx::Transform identityScaleTransform; |
| 783 | |
| 784 | // Anchor zoom with unchanged page scale should not change scroll or scale. |
| 785 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 786 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 787 | scrollLayer->SetImplTransform(identityScaleTransform); |
| 788 | scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50)); |
[email protected] | f350449c | 2013-01-31 21:20:36 | [diff] [blame] | 789 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 790 | m_hostImpl->StartPageScaleAnimation(gfx::Vector2d(0, 0), true, 1, startTime, duration); |
| 791 | m_hostImpl->Animate(halfwayThroughAnimation, base::Time()); |
[email protected] | f350449c | 2013-01-31 21:20:36 | [diff] [blame] | 792 | EXPECT_TRUE(m_didRequestRedraw); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 793 | m_hostImpl->Animate(endTime, base::Time()); |
[email protected] | f350449c | 2013-01-31 21:20:36 | [diff] [blame] | 794 | EXPECT_TRUE(m_didRequestCommit); |
| 795 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 796 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | f350449c | 2013-01-31 21:20:36 | [diff] [blame] | 797 | EXPECT_EQ(scrollInfo->pageScaleDelta, 1); |
| 798 | expectNone(*scrollInfo, scrollLayer->id()); |
| 799 | } |
| 800 | } |
| 801 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 802 | TEST_F(LayerTreeHostImplTest, compositorFrameMetadata) |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 803 | { |
| 804 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 805 | m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); |
| 806 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1.0f, 0.5f, 4.0f); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 807 | initializeRendererAndDrawFrame(); |
| 808 | |
| 809 | { |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 810 | CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetadata(); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 811 | EXPECT_EQ(gfx::Vector2dF(0.0f, 0.0f), metadata.root_scroll_offset); |
| 812 | EXPECT_EQ(1.0f, metadata.page_scale_factor); |
| 813 | EXPECT_EQ(gfx::SizeF(50.0f, 50.0f), metadata.viewport_size); |
| 814 | EXPECT_EQ(gfx::SizeF(100.0f, 100.0f), metadata.root_layer_size); |
| 815 | EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
| 816 | EXPECT_EQ(4.0f, metadata.max_page_scale_factor); |
| 817 | } |
| 818 | |
| 819 | // Scrolling should update metadata immediately. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 820 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 821 | m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 822 | { |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 823 | CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetadata(); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 824 | EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset); |
| 825 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 826 | m_hostImpl->ScrollEnd(); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 827 | |
| 828 | { |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 829 | CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetadata(); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 830 | EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset); |
| 831 | } |
| 832 | |
| 833 | // Page scale should update metadata correctly (shrinking only the viewport). |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 834 | m_hostImpl->PinchGestureBegin(); |
| 835 | m_hostImpl->PinchGestureUpdate(2.0f, gfx::Point(0, 0)); |
| 836 | m_hostImpl->PinchGestureEnd(); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 837 | |
| 838 | { |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 839 | CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetadata(); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 840 | EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset); |
| 841 | EXPECT_EQ(2, metadata.page_scale_factor); |
| 842 | EXPECT_EQ(gfx::SizeF(25.0f, 25.0f), metadata.viewport_size); |
| 843 | EXPECT_EQ(gfx::SizeF(100.0f, 100.0f), metadata.root_layer_size); |
| 844 | EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
| 845 | EXPECT_EQ(4.0f, metadata.max_page_scale_factor); |
| 846 | } |
| 847 | |
| 848 | // Likewise if set from the main thread. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 849 | m_hostImpl->ProcessScrollDeltas(); |
| 850 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(4.0f, 0.5f, 4.0f); |
| 851 | m_hostImpl->active_tree()->SetPageScaleDelta(1.0f); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 852 | { |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 853 | CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetadata(); |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 854 | EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset); |
| 855 | EXPECT_EQ(4.0f, metadata.page_scale_factor); |
| 856 | EXPECT_EQ(gfx::SizeF(12.5f, 12.5f), metadata.viewport_size); |
| 857 | EXPECT_EQ(gfx::SizeF(100.0f, 100.0f), metadata.root_layer_size); |
| 858 | EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
| 859 | EXPECT_EQ(4.0f, metadata.max_page_scale_factor); |
| 860 | } |
| 861 | } |
| 862 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 863 | class DidDrawCheckLayer : public TiledLayerImpl { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 864 | public: |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 865 | static scoped_ptr<LayerImpl> Create(LayerTreeImpl* treeImpl, int id) { return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(treeImpl, id)); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 866 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 867 | virtual void DidDraw(ResourceProvider*) OVERRIDE |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 868 | { |
| 869 | m_didDrawCalled = true; |
| 870 | } |
| 871 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 872 | virtual void WillDraw(ResourceProvider*) OVERRIDE |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 873 | { |
| 874 | m_willDrawCalled = true; |
| 875 | } |
| 876 | |
| 877 | bool didDrawCalled() const { return m_didDrawCalled; } |
| 878 | bool willDrawCalled() const { return m_willDrawCalled; } |
| 879 | |
| 880 | void clearDidDrawCheck() |
| 881 | { |
| 882 | m_didDrawCalled = false; |
| 883 | m_willDrawCalled = false; |
| 884 | } |
| 885 | |
| 886 | protected: |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 887 | DidDrawCheckLayer(LayerTreeImpl* treeImpl, int id) |
| 888 | : TiledLayerImpl(treeImpl, id) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 889 | , m_didDrawCalled(false) |
| 890 | , m_willDrawCalled(false) |
| 891 | { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 892 | SetAnchorPoint(gfx::PointF(0, 0)); |
| 893 | SetBounds(gfx::Size(10, 10)); |
| 894 | SetContentBounds(gfx::Size(10, 10)); |
| 895 | SetDrawsContent(true); |
[email protected] | fa4b57f | 2013-03-17 21:39:09 | [diff] [blame] | 896 | set_skips_draw(false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 897 | draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 898 | |
[email protected] | 32eee89 | 2013-03-18 06:41:13 | [diff] [blame] | 899 | scoped_ptr<LayerTilingData> tiler = LayerTilingData::Create(gfx::Size(100, 100), LayerTilingData::HAS_BORDER_TEXELS); |
| 900 | tiler->SetBounds(content_bounds()); |
[email protected] | fa4b57f | 2013-03-17 21:39:09 | [diff] [blame] | 901 | SetTilingData(*tiler.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | private: |
| 905 | bool m_didDrawCalled; |
| 906 | bool m_willDrawCalled; |
| 907 | }; |
| 908 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 909 | TEST_F(LayerTreeHostImplTest, didDrawNotCalledOnHiddenLayer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 910 | { |
| 911 | // The root layer is always drawn, so run this test on a child layer that |
| 912 | // will be masked out by the root layer's bounds. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 913 | m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 1)); |
| 914 | DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 915 | root->SetMasksToBounds(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 916 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 917 | root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 2)); |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 918 | DidDrawCheckLayer* layer = static_cast<DidDrawCheckLayer*>(root->children()[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 919 | // Ensure visibleContentRect for layer is empty |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 920 | layer->SetPosition(gfx::PointF(100, 100)); |
| 921 | layer->SetBounds(gfx::Size(10, 10)); |
| 922 | layer->SetContentBounds(gfx::Size(10, 10)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 923 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 924 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 925 | |
| 926 | EXPECT_FALSE(layer->willDrawCalled()); |
| 927 | EXPECT_FALSE(layer->didDrawCalled()); |
| 928 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 929 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 930 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 931 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 932 | |
| 933 | EXPECT_FALSE(layer->willDrawCalled()); |
| 934 | EXPECT_FALSE(layer->didDrawCalled()); |
| 935 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 936 | EXPECT_TRUE(layer->visible_content_rect().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 937 | |
| 938 | // Ensure visibleContentRect for layer layer is not empty |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 939 | layer->SetPosition(gfx::PointF(0, 0)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 940 | |
| 941 | EXPECT_FALSE(layer->willDrawCalled()); |
| 942 | EXPECT_FALSE(layer->didDrawCalled()); |
| 943 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 944 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 945 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 946 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 947 | |
| 948 | EXPECT_TRUE(layer->willDrawCalled()); |
| 949 | EXPECT_TRUE(layer->didDrawCalled()); |
| 950 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 951 | EXPECT_FALSE(layer->visible_content_rect().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 952 | } |
| 953 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 954 | TEST_F(LayerTreeHostImplTest, willDrawNotCalledOnOccludedLayer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 955 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 956 | gfx::Size bigSize(1000, 1000); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 957 | m_hostImpl->SetViewportSize(bigSize, bigSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 958 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 959 | m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 1)); |
| 960 | DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 961 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 962 | root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 2)); |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 963 | DidDrawCheckLayer* occludedLayer = static_cast<DidDrawCheckLayer*>(root->children()[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 964 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 965 | root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 3)); |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 966 | DidDrawCheckLayer* topLayer = static_cast<DidDrawCheckLayer*>(root->children()[1]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 967 | // This layer covers the occludedLayer above. Make this layer large so it can occlude. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 968 | topLayer->SetBounds(bigSize); |
| 969 | topLayer->SetContentBounds(bigSize); |
| 970 | topLayer->SetContentsOpaque(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 971 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 972 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 973 | |
| 974 | EXPECT_FALSE(occludedLayer->willDrawCalled()); |
| 975 | EXPECT_FALSE(occludedLayer->didDrawCalled()); |
| 976 | EXPECT_FALSE(topLayer->willDrawCalled()); |
| 977 | EXPECT_FALSE(topLayer->didDrawCalled()); |
| 978 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 979 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 980 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 981 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 982 | |
| 983 | EXPECT_FALSE(occludedLayer->willDrawCalled()); |
| 984 | EXPECT_FALSE(occludedLayer->didDrawCalled()); |
| 985 | EXPECT_TRUE(topLayer->willDrawCalled()); |
| 986 | EXPECT_TRUE(topLayer->didDrawCalled()); |
| 987 | } |
| 988 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 989 | TEST_F(LayerTreeHostImplTest, didDrawCalledOnAllLayers) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 990 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 991 | m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 1)); |
| 992 | DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 993 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 994 | root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 2)); |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 995 | DidDrawCheckLayer* layer1 = static_cast<DidDrawCheckLayer*>(root->children()[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 996 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 997 | layer1->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 3)); |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 998 | DidDrawCheckLayer* layer2 = static_cast<DidDrawCheckLayer*>(layer1->children()[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 999 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1000 | layer1->SetOpacity(0.3f); |
| 1001 | layer1->SetPreserves3d(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1002 | |
| 1003 | EXPECT_FALSE(root->didDrawCalled()); |
| 1004 | EXPECT_FALSE(layer1->didDrawCalled()); |
| 1005 | EXPECT_FALSE(layer2->didDrawCalled()); |
| 1006 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1007 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1008 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1009 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1010 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1011 | |
| 1012 | EXPECT_TRUE(root->didDrawCalled()); |
| 1013 | EXPECT_TRUE(layer1->didDrawCalled()); |
| 1014 | EXPECT_TRUE(layer2->didDrawCalled()); |
| 1015 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1016 | EXPECT_NE(root->render_surface(), layer1->render_surface()); |
| 1017 | EXPECT_TRUE(!!layer1->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | class MissingTextureAnimatingLayer : public DidDrawCheckLayer { |
| 1021 | public: |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1022 | static scoped_ptr<LayerImpl> Create(LayerTreeImpl* treeImpl, int id, bool tileMissing, bool skipsDraw, bool animating, ResourceProvider* resourceProvider) |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 1023 | { |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 1024 | return scoped_ptr<LayerImpl>(new MissingTextureAnimatingLayer(treeImpl, id, tileMissing, skipsDraw, animating, resourceProvider)); |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 1025 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1026 | |
| 1027 | private: |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 1028 | MissingTextureAnimatingLayer(LayerTreeImpl* treeImpl, int id, bool tileMissing, bool skipsDraw, bool animating, ResourceProvider* resourceProvider) |
| 1029 | : DidDrawCheckLayer(treeImpl, id) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1030 | { |
[email protected] | 32eee89 | 2013-03-18 06:41:13 | [diff] [blame] | 1031 | scoped_ptr<LayerTilingData> tilingData = LayerTilingData::Create(gfx::Size(10, 10), LayerTilingData::NO_BORDER_TEXELS); |
| 1032 | tilingData->SetBounds(bounds()); |
[email protected] | fa4b57f | 2013-03-17 21:39:09 | [diff] [blame] | 1033 | SetTilingData(*tilingData.get()); |
| 1034 | set_skips_draw(skipsDraw); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1035 | if (!tileMissing) { |
[email protected] | f53da397 | 2013-03-07 08:38:41 | [diff] [blame] | 1036 | ResourceProvider::ResourceId resource = resourceProvider->CreateResource(gfx::Size(), GL_RGBA, ResourceProvider::TextureUsageAny); |
| 1037 | resourceProvider->AllocateForTesting(resource); |
[email protected] | fa4b57f | 2013-03-17 21:39:09 | [diff] [blame] | 1038 | PushTileProperties(0, 0, resource, gfx::Rect(), false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1039 | } |
| 1040 | if (animating) |
| 1041 | addAnimatedTransformToLayer(*this, 10, 3, 0); |
| 1042 | } |
| 1043 | }; |
| 1044 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1045 | TEST_F(LayerTreeHostImplTest, prepareToDrawFailsWhenAnimationUsesCheckerboard) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1046 | { |
| 1047 | // When the texture is not missing, we draw as usual. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1048 | m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 1)); |
| 1049 | DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer()); |
| 1050 | root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->active_tree(), 2, false, false, true, m_hostImpl->resource_provider())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1051 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1052 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1053 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1054 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1055 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1056 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1057 | |
| 1058 | // When a texture is missing and we're not animating, we draw as usual with checkerboarding. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1059 | m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 3)); |
| 1060 | root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer()); |
| 1061 | root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->active_tree(), 4, true, false, false, m_hostImpl->resource_provider())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1062 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1063 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1064 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1065 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1066 | |
| 1067 | // When a texture is missing and we're animating, we don't want to draw anything. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1068 | m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 5)); |
| 1069 | root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer()); |
| 1070 | root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->active_tree(), 6, true, false, true, m_hostImpl->resource_provider())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1071 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1072 | EXPECT_FALSE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1073 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1074 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1075 | |
| 1076 | // When the layer skips draw and we're animating, we still draw the frame. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1077 | m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 7)); |
| 1078 | root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer()); |
| 1079 | root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->active_tree(), 8, false, true, true, m_hostImpl->resource_provider())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1080 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1081 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1082 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1083 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1084 | } |
| 1085 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1086 | TEST_F(LayerTreeHostImplTest, scrollRootIgnored) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1087 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1088 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1089 | root->SetScrollable(false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1090 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1091 | initializeRendererAndDrawFrame(); |
| 1092 | |
| 1093 | // Scroll event is ignored because layer is not scrollable. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1094 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollIgnored); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1095 | EXPECT_FALSE(m_didRequestRedraw); |
| 1096 | EXPECT_FALSE(m_didRequestCommit); |
| 1097 | } |
| 1098 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1099 | TEST_F(LayerTreeHostImplTest, scrollNonScrollableRootWithTopControls) |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 1100 | { |
| 1101 | LayerTreeSettings settings; |
| 1102 | settings.calculateTopControlsPosition = true; |
| 1103 | settings.topControlsHeight = 50; |
| 1104 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1105 | m_hostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
| 1106 | m_hostImpl->InitializeRenderer(createOutputSurface()); |
| 1107 | m_hostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 1108 | |
| 1109 | gfx::Size layerSize(5, 5); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1110 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1111 | root->SetScrollable(true); |
| 1112 | root->SetMaxScrollOffset(gfx::Vector2d(layerSize.width(), layerSize.height())); |
| 1113 | root->SetBounds(layerSize); |
| 1114 | root->SetContentBounds(layerSize); |
| 1115 | root->SetPosition(gfx::PointF(0, 0)); |
| 1116 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1117 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 1118 | m_hostImpl->active_tree()->FindRootScrollLayer(); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 1119 | initializeRendererAndDrawFrame(); |
| 1120 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1121 | EXPECT_EQ(InputHandlerClient::ScrollIgnored, m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture)); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 1122 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1123 | m_hostImpl->top_controls_manager()->ScrollBegin(); |
| 1124 | m_hostImpl->top_controls_manager()->ScrollBy(gfx::Vector2dF(0, 50)); |
| 1125 | m_hostImpl->top_controls_manager()->ScrollEnd(); |
| 1126 | EXPECT_EQ(m_hostImpl->top_controls_manager()->content_top_offset(), 0.f); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 1127 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1128 | EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture)); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 1129 | } |
| 1130 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1131 | TEST_F(LayerTreeHostImplTest, scrollNonCompositedRoot) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1132 | { |
| 1133 | // Test the configuration where a non-composited root layer is embedded in a |
| 1134 | // scrollable outer layer. |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1135 | gfx::Size surfaceSize(10, 10); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1136 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1137 | scoped_ptr<LayerImpl> contentLayer = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1138 | contentLayer->SetDrawsContent(true); |
| 1139 | contentLayer->SetPosition(gfx::PointF(0, 0)); |
| 1140 | contentLayer->SetAnchorPoint(gfx::PointF(0, 0)); |
| 1141 | contentLayer->SetBounds(surfaceSize); |
| 1142 | contentLayer->SetContentBounds(gfx::Size(surfaceSize.width() * 2, surfaceSize.height() * 2)); |
| 1143 | contentLayer->SetContentsScale(2, 2); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1144 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1145 | scoped_ptr<LayerImpl> scrollLayer = LayerImpl::Create(m_hostImpl->active_tree(), 2); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1146 | scrollLayer->SetScrollable(true); |
| 1147 | scrollLayer->SetMaxScrollOffset(gfx::Vector2d(surfaceSize.width(), surfaceSize.height())); |
| 1148 | scrollLayer->SetBounds(surfaceSize); |
| 1149 | scrollLayer->SetContentBounds(surfaceSize); |
| 1150 | scrollLayer->SetPosition(gfx::PointF(0, 0)); |
| 1151 | scrollLayer->SetAnchorPoint(gfx::PointF(0, 0)); |
| 1152 | scrollLayer->AddChild(contentLayer.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1153 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1154 | m_hostImpl->active_tree()->SetRootLayer(scrollLayer.Pass()); |
| 1155 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1156 | initializeRendererAndDrawFrame(); |
| 1157 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1158 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 1159 | m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 1160 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1161 | EXPECT_TRUE(m_didRequestRedraw); |
| 1162 | EXPECT_TRUE(m_didRequestCommit); |
| 1163 | } |
| 1164 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1165 | TEST_F(LayerTreeHostImplTest, scrollChildCallsCommitAndRedraw) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1166 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1167 | gfx::Size surfaceSize(10, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1168 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1169 | root->SetBounds(surfaceSize); |
| 1170 | root->SetContentBounds(surfaceSize); |
| 1171 | root->AddChild(createScrollableLayer(2, surfaceSize)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1172 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 1173 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1174 | initializeRendererAndDrawFrame(); |
| 1175 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1176 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 1177 | m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 1178 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1179 | EXPECT_TRUE(m_didRequestRedraw); |
| 1180 | EXPECT_TRUE(m_didRequestCommit); |
| 1181 | } |
| 1182 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1183 | TEST_F(LayerTreeHostImplTest, scrollMissesChild) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1184 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1185 | gfx::Size surfaceSize(10, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1186 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1187 | root->AddChild(createScrollableLayer(2, surfaceSize)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1188 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 1189 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1190 | initializeRendererAndDrawFrame(); |
| 1191 | |
| 1192 | // Scroll event is ignored because the input coordinate is outside the layer boundaries. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1193 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(15, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollIgnored); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1194 | EXPECT_FALSE(m_didRequestRedraw); |
| 1195 | EXPECT_FALSE(m_didRequestCommit); |
| 1196 | } |
| 1197 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1198 | TEST_F(LayerTreeHostImplTest, scrollMissesBackfacingChild) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1199 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1200 | gfx::Size surfaceSize(10, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1201 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1202 | scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1203 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1204 | |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1205 | gfx::Transform matrix; |
[email protected] | 78634b0c | 2013-01-15 07:49:40 | [diff] [blame] | 1206 | matrix.RotateAboutXAxis(180); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1207 | child->SetTransform(matrix); |
| 1208 | child->SetDoubleSided(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1209 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1210 | root->AddChild(child.Pass()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1211 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1212 | initializeRendererAndDrawFrame(); |
| 1213 | |
| 1214 | // Scroll event is ignored because the scrollable layer is not facing the viewer and there is |
| 1215 | // nothing scrollable behind it. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1216 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollIgnored); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1217 | EXPECT_FALSE(m_didRequestRedraw); |
| 1218 | EXPECT_FALSE(m_didRequestCommit); |
| 1219 | } |
| 1220 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1221 | TEST_F(LayerTreeHostImplTest, scrollBlockedByContentLayer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1222 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1223 | gfx::Size surfaceSize(10, 10); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1224 | scoped_ptr<LayerImpl> contentLayer = createScrollableLayer(1, surfaceSize); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1225 | contentLayer->SetShouldScrollOnMainThread(true); |
| 1226 | contentLayer->SetScrollable(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1227 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1228 | scoped_ptr<LayerImpl> scrollLayer = createScrollableLayer(2, surfaceSize); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1229 | scrollLayer->AddChild(contentLayer.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1230 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1231 | m_hostImpl->active_tree()->SetRootLayer(scrollLayer.Pass()); |
| 1232 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1233 | initializeRendererAndDrawFrame(); |
| 1234 | |
| 1235 | // Scrolling fails because the content layer is asking to be scrolled on the main thread. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1236 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollOnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1237 | } |
| 1238 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1239 | TEST_F(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnMainThread) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1240 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1241 | gfx::Size surfaceSize(10, 10); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1242 | float pageScale = 2; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1243 | scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1244 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 1245 | m_hostImpl->active_tree()->DidBecomeActive(); |
| 1246 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1247 | initializeRendererAndDrawFrame(); |
| 1248 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1249 | gfx::Vector2d scrollDelta(0, 10); |
| 1250 | gfx::Vector2d expectedScrollDelta(scrollDelta); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1251 | gfx::Vector2d expectedMaxScroll(m_hostImpl->active_tree()->root_layer()->max_scroll_offset()); |
| 1252 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 1253 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1254 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1255 | |
| 1256 | // Set new page scale from main thread. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1257 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(pageScale, pageScale, pageScale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1258 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1259 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
| 1260 | expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->id(), expectedScrollDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1261 | |
| 1262 | // The scroll range should also have been updated. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1263 | EXPECT_EQ(m_hostImpl->active_tree()->root_layer()->max_scroll_offset(), expectedMaxScroll); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1264 | |
| 1265 | // The page scale delta remains constant because the impl thread did not scale. |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1266 | // TODO: If possible, use gfx::Transform() or Skia equality functions. At |
| 1267 | // the moment we avoid that because skia does exact bit-wise equality |
| 1268 | // checking that does not consider -0 == +0. |
| 1269 | // http://code.google.com/p/chromium/issues/detail?id=162747 |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1270 | EXPECT_EQ(1.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(0, 0)); |
| 1271 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(0, 1)); |
| 1272 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(0, 2)); |
| 1273 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(0, 3)); |
| 1274 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(1, 0)); |
| 1275 | EXPECT_EQ(1.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(1, 1)); |
| 1276 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(1, 2)); |
| 1277 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(1, 3)); |
| 1278 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(2, 0)); |
| 1279 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(2, 1)); |
| 1280 | EXPECT_EQ(1.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(2, 2)); |
| 1281 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(2, 3)); |
| 1282 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(3, 0)); |
| 1283 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(3, 1)); |
| 1284 | EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(3, 2)); |
| 1285 | EXPECT_EQ(1.0, m_hostImpl->active_tree()->root_layer()->impl_transform().matrix().getDouble(3, 3)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1286 | } |
| 1287 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1288 | TEST_F(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1289 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1290 | gfx::Size surfaceSize(10, 10); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1291 | float pageScale = 2; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1292 | scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1293 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 1294 | m_hostImpl->active_tree()->DidBecomeActive(); |
| 1295 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
| 1296 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, 1, pageScale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1297 | initializeRendererAndDrawFrame(); |
| 1298 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1299 | gfx::Vector2d scrollDelta(0, 10); |
| 1300 | gfx::Vector2d expectedScrollDelta(scrollDelta); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1301 | gfx::Vector2d expectedMaxScroll(m_hostImpl->active_tree()->root_layer()->max_scroll_offset()); |
| 1302 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 1303 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1304 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1305 | |
| 1306 | // Set new page scale on impl thread by pinching. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1307 | m_hostImpl->PinchGestureBegin(); |
| 1308 | m_hostImpl->PinchGestureUpdate(pageScale, gfx::Point()); |
| 1309 | m_hostImpl->PinchGestureEnd(); |
[email protected] | 2d69299 | 2012-12-19 01:19:32 | [diff] [blame] | 1310 | drawOneFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1311 | |
| 1312 | // The scroll delta is not scaled because the main thread did not scale. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1313 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
| 1314 | expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->id(), expectedScrollDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1315 | |
| 1316 | // The scroll range should also have been updated. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1317 | EXPECT_EQ(m_hostImpl->active_tree()->root_layer()->max_scroll_offset(), expectedMaxScroll); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1318 | |
| 1319 | // The page scale delta should match the new scale on the impl side. |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1320 | gfx::Transform expectedScale; |
| 1321 | expectedScale.Scale(pageScale, pageScale); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1322 | EXPECT_EQ(m_hostImpl->active_tree()->root_layer()->impl_transform(), expectedScale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1323 | } |
| 1324 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1325 | TEST_F(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1326 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1327 | gfx::Size surfaceSize(10, 10); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1328 | float defaultPageScale = 1; |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1329 | gfx::Transform defaultPageScaleMatrix; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1330 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1331 | float newPageScale = 2; |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1332 | gfx::Transform newPageScaleMatrix; |
| 1333 | newPageScaleMatrix.Scale(newPageScale, newPageScale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1334 | |
| 1335 | // Create a normal scrollable root layer and another scrollable child layer. |
| 1336 | setupScrollAndContentsLayers(surfaceSize); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1337 | LayerImpl* root = m_hostImpl->active_tree()->root_layer(); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1338 | LayerImpl* child = root->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1339 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1340 | scoped_ptr<LayerImpl> scrollableChild = createScrollableLayer(3, surfaceSize); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1341 | child->AddChild(scrollableChild.Pass()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1342 | LayerImpl* grandChild = child->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1343 | |
| 1344 | // Set new page scale on impl thread by pinching. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1345 | m_hostImpl->PinchGestureBegin(); |
| 1346 | m_hostImpl->PinchGestureUpdate(newPageScale, gfx::Point()); |
| 1347 | m_hostImpl->PinchGestureEnd(); |
[email protected] | 2d69299 | 2012-12-19 01:19:32 | [diff] [blame] | 1348 | drawOneFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1349 | |
| 1350 | // The page scale delta should only be applied to the scrollable root layer. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1351 | EXPECT_EQ(root->impl_transform(), newPageScaleMatrix); |
| 1352 | EXPECT_EQ(child->impl_transform(), defaultPageScaleMatrix); |
| 1353 | EXPECT_EQ(grandChild->impl_transform(), defaultPageScaleMatrix); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1354 | |
| 1355 | // Make sure all the layers are drawn with the page scale delta applied, i.e., the page scale |
| 1356 | // delta on the root layer is applied hierarchically. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1357 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1358 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1359 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1360 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1361 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1362 | EXPECT_EQ(root->draw_transform().matrix().getDouble(0, 0), newPageScale); |
| 1363 | EXPECT_EQ(root->draw_transform().matrix().getDouble(1, 1), newPageScale); |
| 1364 | EXPECT_EQ(child->draw_transform().matrix().getDouble(0, 0), newPageScale); |
| 1365 | EXPECT_EQ(child->draw_transform().matrix().getDouble(1, 1), newPageScale); |
| 1366 | EXPECT_EQ(grandChild->draw_transform().matrix().getDouble(0, 0), newPageScale); |
| 1367 | EXPECT_EQ(grandChild->draw_transform().matrix().getDouble(1, 1), newPageScale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1368 | } |
| 1369 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1370 | TEST_F(LayerTreeHostImplTest, scrollChildAndChangePageScaleOnMainThread) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1371 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1372 | gfx::Size surfaceSize(10, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1373 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1374 | root->SetBounds(surfaceSize); |
| 1375 | root->SetContentBounds(surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1376 | // Also mark the root scrollable so it becomes the root scroll layer. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1377 | root->SetScrollable(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1378 | int scrollLayerId = 2; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1379 | root->AddChild(createScrollableLayer(scrollLayerId, surfaceSize)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1380 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 1381 | m_hostImpl->active_tree()->DidBecomeActive(); |
| 1382 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1383 | initializeRendererAndDrawFrame(); |
| 1384 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1385 | LayerImpl* child = m_hostImpl->active_tree()->root_layer()->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1386 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1387 | gfx::Vector2d scrollDelta(0, 10); |
| 1388 | gfx::Vector2d expectedScrollDelta(scrollDelta); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1389 | gfx::Vector2d expectedMaxScroll(child->max_scroll_offset()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1390 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 1391 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1392 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1393 | |
| 1394 | float pageScale = 2; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1395 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(pageScale, 1, pageScale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1396 | |
[email protected] | 2d69299 | 2012-12-19 01:19:32 | [diff] [blame] | 1397 | drawOneFrame(); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1398 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1399 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1400 | expectContains(*scrollInfo.get(), scrollLayerId, expectedScrollDelta); |
| 1401 | |
| 1402 | // The scroll range should not have changed. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1403 | EXPECT_EQ(child->max_scroll_offset(), expectedMaxScroll); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1404 | |
| 1405 | // The page scale delta remains constant because the impl thread did not scale. |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1406 | gfx::Transform identityTransform; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1407 | EXPECT_EQ(child->impl_transform(), gfx::Transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1408 | } |
| 1409 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1410 | TEST_F(LayerTreeHostImplTest, scrollChildBeyondLimit) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1411 | { |
| 1412 | // Scroll a child layer beyond its maximum scroll range and make sure the |
| 1413 | // parent layer is scrolled on the axis on which the child was unable to |
| 1414 | // scroll. |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1415 | gfx::Size surfaceSize(10, 10); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1416 | scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1417 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1418 | scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1419 | grandChild->SetScrollOffset(gfx::Vector2d(0, 5)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1420 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1421 | scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1422 | child->SetScrollOffset(gfx::Vector2d(3, 0)); |
| 1423 | child->AddChild(grandChild.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1424 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1425 | root->AddChild(child.Pass()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1426 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 1427 | m_hostImpl->active_tree()->DidBecomeActive(); |
| 1428 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1429 | initializeRendererAndDrawFrame(); |
| 1430 | { |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1431 | gfx::Vector2d scrollDelta(-8, -7); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1432 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 1433 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1434 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1435 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1436 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1437 | |
| 1438 | // The grand child should have scrolled up to its limit. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1439 | LayerImpl* child = m_hostImpl->active_tree()->root_layer()->children()[0]; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1440 | LayerImpl* grandChild = child->children()[0]; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1441 | expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -5)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1442 | |
| 1443 | // The child should have only scrolled on the other axis. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1444 | expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(-3, 0)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1445 | } |
| 1446 | } |
| 1447 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1448 | TEST_F(LayerTreeHostImplTest, scrollWithoutBubbling) |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1449 | { |
| 1450 | // Scroll a child layer beyond its maximum scroll range and make sure the |
| 1451 | // the scroll doesn't bubble up to the parent layer. |
| 1452 | gfx::Size surfaceSize(10, 10); |
| 1453 | scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); |
| 1454 | |
| 1455 | scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1456 | grandChild->SetScrollOffset(gfx::Vector2d(0, 2)); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1457 | |
| 1458 | scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1459 | child->SetScrollOffset(gfx::Vector2d(0, 3)); |
| 1460 | child->AddChild(grandChild.Pass()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1461 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1462 | root->AddChild(child.Pass()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1463 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 1464 | m_hostImpl->active_tree()->DidBecomeActive(); |
| 1465 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1466 | initializeRendererAndDrawFrame(); |
| 1467 | { |
| 1468 | gfx::Vector2d scrollDelta(0, -10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1469 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::NonBubblingGesture), InputHandlerClient::ScrollStarted); |
| 1470 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1471 | m_hostImpl->ScrollEnd(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1472 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1473 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1474 | |
| 1475 | // The grand child should have scrolled up to its limit. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1476 | LayerImpl* child = m_hostImpl->active_tree()->root_layer()->children()[0]; |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1477 | LayerImpl* grandChild = child->children()[0]; |
| 1478 | expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2)); |
| 1479 | |
| 1480 | // The child should not have scrolled. |
| 1481 | expectNone(*scrollInfo.get(), child->id()); |
| 1482 | |
| 1483 | // The next time we scroll we should only scroll the parent. |
| 1484 | scrollDelta = gfx::Vector2d(0, -3); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1485 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::NonBubblingGesture), InputHandlerClient::ScrollStarted); |
| 1486 | EXPECT_EQ(m_hostImpl->CurrentlyScrollingLayer(), grandChild); |
| 1487 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1488 | EXPECT_EQ(m_hostImpl->CurrentlyScrollingLayer(), child); |
| 1489 | m_hostImpl->ScrollEnd(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1490 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1491 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1492 | |
| 1493 | // The child should have scrolled up to its limit. |
| 1494 | expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3)); |
| 1495 | |
| 1496 | // The grand child should not have scrolled. |
| 1497 | expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2)); |
| 1498 | |
| 1499 | // After scrolling the parent, another scroll on the opposite direction |
| 1500 | // should still scroll the child. |
| 1501 | scrollDelta = gfx::Vector2d(0, 7); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1502 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::NonBubblingGesture), InputHandlerClient::ScrollStarted); |
| 1503 | EXPECT_EQ(m_hostImpl->CurrentlyScrollingLayer(), grandChild); |
| 1504 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1505 | EXPECT_EQ(m_hostImpl->CurrentlyScrollingLayer(), grandChild); |
| 1506 | m_hostImpl->ScrollEnd(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1507 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1508 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1509 | |
| 1510 | // The grand child should have scrolled. |
| 1511 | expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, 5)); |
| 1512 | |
| 1513 | // The child should not have scrolled. |
| 1514 | expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3)); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 1515 | |
| 1516 | |
| 1517 | // Scrolling should be adjusted from viewport space. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1518 | m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(2, 2, 2); |
| 1519 | m_hostImpl->active_tree()->SetPageScaleDelta(1); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 1520 | gfx::Transform scaleTransform; |
| 1521 | scaleTransform.Scale(2, 2); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1522 | m_hostImpl->active_tree()->root_layer()->SetImplTransform(scaleTransform); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 1523 | |
| 1524 | scrollDelta = gfx::Vector2d(0, -2); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1525 | EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->ScrollBegin(gfx::Point(1, 1), InputHandlerClient::NonBubblingGesture)); |
| 1526 | EXPECT_EQ(grandChild, m_hostImpl->CurrentlyScrollingLayer()); |
| 1527 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1528 | m_hostImpl->ScrollEnd(); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 1529 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1530 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 1531 | |
| 1532 | // Should have scrolled by half the amount in layer space (5 - 2/2) |
| 1533 | expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, 4)); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 1534 | } |
| 1535 | } |
| 1536 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1537 | TEST_F(LayerTreeHostImplTest, scrollEventBubbling) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1538 | { |
| 1539 | // When we try to scroll a non-scrollable child layer, the scroll delta |
| 1540 | // should be applied to one of its ancestors if possible. |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1541 | gfx::Size surfaceSize(10, 10); |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 1542 | gfx::Size contentSize(20, 20); |
| 1543 | scoped_ptr<LayerImpl> root = createScrollableLayer(1, contentSize); |
| 1544 | scoped_ptr<LayerImpl> child = createScrollableLayer(2, contentSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1545 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1546 | child->SetScrollable(false); |
| 1547 | root->AddChild(child.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1548 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1549 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
| 1550 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 1551 | m_hostImpl->active_tree()->DidBecomeActive(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1552 | initializeRendererAndDrawFrame(); |
| 1553 | { |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1554 | gfx::Vector2d scrollDelta(0, 4); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1555 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 1556 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1557 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1558 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1559 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1560 | |
| 1561 | // Only the root should have scrolled. |
| 1562 | ASSERT_EQ(scrollInfo->scrolls.size(), 1u); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1563 | expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->id(), scrollDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1564 | } |
| 1565 | } |
| 1566 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1567 | TEST_F(LayerTreeHostImplTest, scrollBeforeRedraw) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1568 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1569 | gfx::Size surfaceSize(10, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1570 | m_hostImpl->active_tree()->SetRootLayer(createScrollableLayer(1, surfaceSize)); |
| 1571 | m_hostImpl->active_tree()->DidBecomeActive(); |
| 1572 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1573 | |
| 1574 | // Draw one frame and then immediately rebuild the layer tree to mimic a tree synchronization. |
| 1575 | initializeRendererAndDrawFrame(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1576 | m_hostImpl->active_tree()->DetachLayerTree(); |
| 1577 | m_hostImpl->active_tree()->SetRootLayer(createScrollableLayer(2, surfaceSize)); |
| 1578 | m_hostImpl->active_tree()->DidBecomeActive(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1579 | |
| 1580 | // Scrolling should still work even though we did not draw yet. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1581 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1582 | } |
| 1583 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1584 | TEST_F(LayerTreeHostImplTest, scrollAxisAlignedRotatedLayer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1585 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1586 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1587 | |
| 1588 | // Rotate the root layer 90 degrees counter-clockwise about its center. |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1589 | gfx::Transform rotateTransform; |
| 1590 | rotateTransform.Rotate(-90); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1591 | m_hostImpl->active_tree()->root_layer()->SetTransform(rotateTransform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1592 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1593 | gfx::Size surfaceSize(50, 50); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1594 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1595 | initializeRendererAndDrawFrame(); |
| 1596 | |
| 1597 | // Scroll to the right in screen coordinates with a gesture. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1598 | gfx::Vector2d gestureScrollDelta(10, 0); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1599 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture), InputHandlerClient::ScrollStarted); |
| 1600 | m_hostImpl->ScrollBy(gfx::Point(), gestureScrollDelta); |
| 1601 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1602 | |
| 1603 | // The layer should have scrolled down in its local coordinates. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1604 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
| 1605 | expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->id(), gfx::Vector2d(0, gestureScrollDelta.x())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1606 | |
| 1607 | // Reset and scroll down with the wheel. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1608 | m_hostImpl->active_tree()->root_layer()->SetScrollDelta(gfx::Vector2dF()); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1609 | gfx::Vector2d wheelScrollDelta(0, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1610 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 1611 | m_hostImpl->ScrollBy(gfx::Point(), wheelScrollDelta); |
| 1612 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1613 | |
| 1614 | // The layer should have scrolled down in its local coordinates. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1615 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
| 1616 | expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->id(), wheelScrollDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1617 | } |
| 1618 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1619 | TEST_F(LayerTreeHostImplTest, scrollNonAxisAlignedRotatedLayer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1620 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1621 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1622 | int childLayerId = 3; |
| 1623 | float childLayerAngle = -20; |
| 1624 | |
| 1625 | // Create a child layer that is rotated to a non-axis-aligned angle. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1626 | scoped_ptr<LayerImpl> child = createScrollableLayer(childLayerId, m_hostImpl->active_tree()->root_layer()->content_bounds()); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1627 | gfx::Transform rotateTransform; |
| 1628 | rotateTransform.Translate(-50, -50); |
| 1629 | rotateTransform.Rotate(childLayerAngle); |
| 1630 | rotateTransform.Translate(50, 50); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1631 | child->SetTransform(rotateTransform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1632 | |
| 1633 | // Only allow vertical scrolling. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1634 | child->SetMaxScrollOffset(gfx::Vector2d(0, child->content_bounds().height())); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1635 | m_hostImpl->active_tree()->root_layer()->AddChild(child.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1636 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1637 | gfx::Size surfaceSize(50, 50); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1638 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1639 | initializeRendererAndDrawFrame(); |
| 1640 | |
| 1641 | { |
| 1642 | // Scroll down in screen coordinates with a gesture. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1643 | gfx::Vector2d gestureScrollDelta(0, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1644 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture), InputHandlerClient::ScrollStarted); |
| 1645 | m_hostImpl->ScrollBy(gfx::Point(), gestureScrollDelta); |
| 1646 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1647 | |
| 1648 | // The child layer should have scrolled down in its local coordinates an amount proportional to |
| 1649 | // the angle between it and the input scroll delta. |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 1650 | gfx::Vector2d expectedScrollDelta(0, gestureScrollDelta.y() * std::cos(MathUtil::Deg2Rad(childLayerAngle))); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1651 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1652 | expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); |
| 1653 | |
| 1654 | // The root layer should not have scrolled, because the input delta was close to the layer's |
| 1655 | // axis of movement. |
| 1656 | EXPECT_EQ(scrollInfo->scrolls.size(), 1u); |
| 1657 | } |
| 1658 | |
| 1659 | { |
| 1660 | // Now reset and scroll the same amount horizontally. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1661 | m_hostImpl->active_tree()->root_layer()->children()[1]->SetScrollDelta(gfx::Vector2dF()); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1662 | gfx::Vector2d gestureScrollDelta(10, 0); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1663 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture), InputHandlerClient::ScrollStarted); |
| 1664 | m_hostImpl->ScrollBy(gfx::Point(), gestureScrollDelta); |
| 1665 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1666 | |
| 1667 | // The child layer should have scrolled down in its local coordinates an amount proportional to |
| 1668 | // the angle between it and the input scroll delta. |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 1669 | gfx::Vector2d expectedScrollDelta(0, -gestureScrollDelta.x() * std::sin(MathUtil::Deg2Rad(childLayerAngle))); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1670 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1671 | expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); |
| 1672 | |
| 1673 | // The root layer should have scrolled more, since the input scroll delta was mostly |
| 1674 | // orthogonal to the child layer's vertical scroll axis. |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 1675 | gfx::Vector2d expectedRootScrollDelta(gestureScrollDelta.x() * std::pow(std::cos(MathUtil::Deg2Rad(childLayerAngle)), 2), 0); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1676 | expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->id(), expectedRootScrollDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1680 | TEST_F(LayerTreeHostImplTest, scrollScaledLayer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1681 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1682 | setupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1683 | |
| 1684 | // Scale the layer to twice its normal size. |
| 1685 | int scale = 2; |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1686 | gfx::Transform scaleTransform; |
| 1687 | scaleTransform.Scale(scale, scale); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1688 | m_hostImpl->active_tree()->root_layer()->SetTransform(scaleTransform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1689 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1690 | gfx::Size surfaceSize(50, 50); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1691 | m_hostImpl->SetViewportSize(surfaceSize, surfaceSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1692 | initializeRendererAndDrawFrame(); |
| 1693 | |
| 1694 | // Scroll down in screen coordinates with a gesture. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1695 | gfx::Vector2d scrollDelta(0, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1696 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture), InputHandlerClient::ScrollStarted); |
| 1697 | m_hostImpl->ScrollBy(gfx::Point(), scrollDelta); |
| 1698 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1699 | |
| 1700 | // The layer should have scrolled down in its local coordinates, but half he amount. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1701 | scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
| 1702 | expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->id(), gfx::Vector2d(0, scrollDelta.y() / scale)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1703 | |
| 1704 | // Reset and scroll down with the wheel. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1705 | m_hostImpl->active_tree()->root_layer()->SetScrollDelta(gfx::Vector2dF()); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1706 | gfx::Vector2d wheelScrollDelta(0, 10); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1707 | EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Wheel), InputHandlerClient::ScrollStarted); |
| 1708 | m_hostImpl->ScrollBy(gfx::Point(), wheelScrollDelta); |
| 1709 | m_hostImpl->ScrollEnd(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1710 | |
| 1711 | // The scale should not have been applied to the scroll delta. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1712 | scrollInfo = m_hostImpl->ProcessScrollDeltas(); |
| 1713 | expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->id(), wheelScrollDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1714 | } |
| 1715 | |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 1716 | class BlendStateTrackerContext: public TestWebGraphicsContext3D { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1717 | public: |
| 1718 | BlendStateTrackerContext() : m_blend(false) { } |
| 1719 | |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 1720 | virtual void enable(WebKit::WGC3Denum cap) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1721 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 1722 | if (cap == GL_BLEND) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1723 | m_blend = true; |
| 1724 | } |
| 1725 | |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 1726 | virtual void disable(WebKit::WGC3Denum cap) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1727 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 1728 | if (cap == GL_BLEND) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1729 | m_blend = false; |
| 1730 | } |
| 1731 | |
| 1732 | bool blend() const { return m_blend; } |
| 1733 | |
| 1734 | private: |
| 1735 | bool m_blend; |
| 1736 | }; |
| 1737 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1738 | class BlendStateCheckLayer : public LayerImpl { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1739 | public: |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1740 | static scoped_ptr<LayerImpl> Create(LayerTreeImpl* treeImpl, int id, ResourceProvider* resourceProvider) { return scoped_ptr<LayerImpl>(new BlendStateCheckLayer(treeImpl, id, resourceProvider)); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1741 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1742 | virtual void AppendQuads(QuadSink* quadSink, AppendQuadsData* appendQuadsData) OVERRIDE |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1743 | { |
| 1744 | m_quadsAppended = true; |
| 1745 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1746 | gfx::Rect opaqueRect; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1747 | if (contents_opaque()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1748 | opaqueRect = m_quadRect; |
| 1749 | else |
| 1750 | opaqueRect = m_opaqueContentRect; |
| 1751 | |
[email protected] | c7e95b4 | 2013-03-18 01:13:49 | [diff] [blame] | 1752 | SharedQuadState* sharedQuadState = quadSink->UseSharedQuadState(CreateSharedQuadState()); |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 1753 | scoped_ptr<TileDrawQuad> testBlendingDrawQuad = TileDrawQuad::Create(); |
[email protected] | f902bf9 | 2013-03-04 18:33:27 | [diff] [blame] | 1754 | testBlendingDrawQuad->SetNew(sharedQuadState, m_quadRect, opaqueRect, m_resourceId, gfx::RectF(0, 0, 1, 1), gfx::Size(1, 1), false); |
[email protected] | 1bc93f6 | 2012-11-17 19:29:50 | [diff] [blame] | 1755 | testBlendingDrawQuad->visible_rect = m_quadVisibleRect; |
[email protected] | 9cd20a3 | 2012-11-17 14:11:27 | [diff] [blame] | 1756 | EXPECT_EQ(m_blend, testBlendingDrawQuad->ShouldDrawWithBlending()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1757 | EXPECT_EQ(m_hasRenderSurface, !!render_surface()); |
[email protected] | c7e95b4 | 2013-03-18 01:13:49 | [diff] [blame] | 1758 | quadSink->Append(testBlendingDrawQuad.PassAs<DrawQuad>(), appendQuadsData); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void setExpectation(bool blend, bool hasRenderSurface) |
| 1762 | { |
| 1763 | m_blend = blend; |
| 1764 | m_hasRenderSurface = hasRenderSurface; |
| 1765 | m_quadsAppended = false; |
| 1766 | } |
| 1767 | |
| 1768 | bool quadsAppended() const { return m_quadsAppended; } |
| 1769 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1770 | void setQuadRect(const gfx::Rect& rect) { m_quadRect = rect; } |
| 1771 | void setQuadVisibleRect(const gfx::Rect& rect) { m_quadVisibleRect = rect; } |
| 1772 | void setOpaqueContentRect(const gfx::Rect& rect) { m_opaqueContentRect = rect; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1773 | |
| 1774 | private: |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 1775 | BlendStateCheckLayer(LayerTreeImpl* treeImpl, int id, ResourceProvider* resourceProvider) |
| 1776 | : LayerImpl(treeImpl, id) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1777 | , m_blend(false) |
| 1778 | , m_hasRenderSurface(false) |
| 1779 | , m_quadsAppended(false) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1780 | , m_quadRect(5, 5, 5, 5) |
| 1781 | , m_quadVisibleRect(5, 5, 5, 5) |
[email protected] | f53da397 | 2013-03-07 08:38:41 | [diff] [blame] | 1782 | , m_resourceId(resourceProvider->CreateResource(gfx::Size(1, 1), GL_RGBA, ResourceProvider::TextureUsageAny)) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1783 | { |
[email protected] | f53da397 | 2013-03-07 08:38:41 | [diff] [blame] | 1784 | resourceProvider->AllocateForTesting(m_resourceId); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1785 | SetAnchorPoint(gfx::PointF(0, 0)); |
| 1786 | SetBounds(gfx::Size(10, 10)); |
| 1787 | SetContentBounds(gfx::Size(10, 10)); |
| 1788 | SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | bool m_blend; |
| 1792 | bool m_hasRenderSurface; |
| 1793 | bool m_quadsAppended; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1794 | gfx::Rect m_quadRect; |
| 1795 | gfx::Rect m_opaqueContentRect; |
| 1796 | gfx::Rect m_quadVisibleRect; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1797 | ResourceProvider::ResourceId m_resourceId; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1798 | }; |
| 1799 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1800 | TEST_F(LayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1801 | { |
| 1802 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1803 | scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1804 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 1805 | root->SetBounds(gfx::Size(10, 10)); |
| 1806 | root->SetContentBounds(root->bounds()); |
| 1807 | root->SetDrawsContent(false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1808 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1809 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1810 | LayerImpl* root = m_hostImpl->active_tree()->root_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1811 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1812 | root->AddChild(BlendStateCheckLayer::Create(m_hostImpl->active_tree(), 2, m_hostImpl->resource_provider())); |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 1813 | BlendStateCheckLayer* layer1 = static_cast<BlendStateCheckLayer*>(root->children()[0]); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1814 | layer1->SetPosition(gfx::PointF(2, 2)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1815 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1816 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1817 | |
| 1818 | // Opaque layer, drawn without blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1819 | layer1->SetContentsOpaque(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1820 | layer1->setExpectation(false, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1821 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1822 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1823 | EXPECT_TRUE(layer1->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1824 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1825 | |
| 1826 | // Layer with translucent content and painting, so drawn with blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1827 | layer1->SetContentsOpaque(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1828 | layer1->setExpectation(true, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1829 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1830 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1831 | EXPECT_TRUE(layer1->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1832 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1833 | |
| 1834 | // Layer with translucent opacity, drawn with blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1835 | layer1->SetContentsOpaque(true); |
| 1836 | layer1->SetOpacity(0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1837 | layer1->setExpectation(true, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1838 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1839 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1840 | EXPECT_TRUE(layer1->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1841 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1842 | |
| 1843 | // Layer with translucent opacity and painting, drawn with blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1844 | layer1->SetContentsOpaque(true); |
| 1845 | layer1->SetOpacity(0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1846 | layer1->setExpectation(true, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1847 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1848 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1849 | EXPECT_TRUE(layer1->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1850 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1851 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1852 | layer1->AddChild(BlendStateCheckLayer::Create(m_hostImpl->active_tree(), 3, m_hostImpl->resource_provider())); |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 1853 | BlendStateCheckLayer* layer2 = static_cast<BlendStateCheckLayer*>(layer1->children()[0]); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1854 | layer2->SetPosition(gfx::PointF(4, 4)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1855 | |
| 1856 | // 2 opaque layers, drawn without blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1857 | layer1->SetContentsOpaque(true); |
| 1858 | layer1->SetOpacity(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1859 | layer1->setExpectation(false, false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1860 | layer2->SetContentsOpaque(true); |
| 1861 | layer2->SetOpacity(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1862 | layer2->setExpectation(false, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1863 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1864 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1865 | EXPECT_TRUE(layer1->quadsAppended()); |
| 1866 | EXPECT_TRUE(layer2->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1867 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1868 | |
| 1869 | // Parent layer with translucent content, drawn with blending. |
| 1870 | // Child layer with opaque content, drawn without blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1871 | layer1->SetContentsOpaque(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1872 | layer1->setExpectation(true, false); |
| 1873 | layer2->setExpectation(false, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1874 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1875 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1876 | EXPECT_TRUE(layer1->quadsAppended()); |
| 1877 | EXPECT_TRUE(layer2->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1878 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1879 | |
| 1880 | // Parent layer with translucent content but opaque painting, drawn without blending. |
| 1881 | // Child layer with opaque content, drawn without blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1882 | layer1->SetContentsOpaque(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1883 | layer1->setExpectation(false, false); |
| 1884 | layer2->setExpectation(false, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1885 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1886 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1887 | EXPECT_TRUE(layer1->quadsAppended()); |
| 1888 | EXPECT_TRUE(layer2->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1889 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1890 | |
| 1891 | // Parent layer with translucent opacity and opaque content. Since it has a |
| 1892 | // drawing child, it's drawn to a render surface which carries the opacity, |
| 1893 | // so it's itself drawn without blending. |
| 1894 | // Child layer with opaque content, drawn without blending (parent surface |
| 1895 | // carries the inherited opacity). |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1896 | layer1->SetContentsOpaque(true); |
| 1897 | layer1->SetOpacity(0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1898 | layer1->setExpectation(false, true); |
| 1899 | layer2->setExpectation(false, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1900 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1901 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1902 | EXPECT_TRUE(layer1->quadsAppended()); |
| 1903 | EXPECT_TRUE(layer2->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1904 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1905 | |
| 1906 | // Draw again, but with child non-opaque, to make sure |
| 1907 | // layer1 not culled. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1908 | layer1->SetContentsOpaque(true); |
| 1909 | layer1->SetOpacity(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1910 | layer1->setExpectation(false, false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1911 | layer2->SetContentsOpaque(true); |
| 1912 | layer2->SetOpacity(0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1913 | layer2->setExpectation(true, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1914 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1915 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1916 | EXPECT_TRUE(layer1->quadsAppended()); |
| 1917 | EXPECT_TRUE(layer2->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1918 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1919 | |
| 1920 | // A second way of making the child non-opaque. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1921 | layer1->SetContentsOpaque(true); |
| 1922 | layer1->SetOpacity(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1923 | layer1->setExpectation(false, false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1924 | layer2->SetContentsOpaque(false); |
| 1925 | layer2->SetOpacity(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1926 | layer2->setExpectation(true, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1927 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1928 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1929 | EXPECT_TRUE(layer1->quadsAppended()); |
| 1930 | EXPECT_TRUE(layer2->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1931 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1932 | |
| 1933 | // And when the layer says its not opaque but is painted opaque, it is not blended. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1934 | layer1->SetContentsOpaque(true); |
| 1935 | layer1->SetOpacity(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1936 | layer1->setExpectation(false, false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1937 | layer2->SetContentsOpaque(true); |
| 1938 | layer2->SetOpacity(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1939 | layer2->setExpectation(false, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1940 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1941 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1942 | EXPECT_TRUE(layer1->quadsAppended()); |
| 1943 | EXPECT_TRUE(layer2->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1944 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1945 | |
| 1946 | // Layer with partially opaque contents, drawn with blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1947 | layer1->SetContentsOpaque(false); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1948 | layer1->setQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 1949 | layer1->setQuadVisibleRect(gfx::Rect(5, 5, 5, 5)); |
| 1950 | layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1951 | layer1->setExpectation(true, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1952 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1953 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1954 | EXPECT_TRUE(layer1->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1955 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1956 | |
| 1957 | // Layer with partially opaque contents partially culled, drawn with blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1958 | layer1->SetContentsOpaque(false); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1959 | layer1->setQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 1960 | layer1->setQuadVisibleRect(gfx::Rect(5, 5, 5, 2)); |
| 1961 | layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1962 | layer1->setExpectation(true, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1963 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1964 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1965 | EXPECT_TRUE(layer1->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1966 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1967 | |
| 1968 | // Layer with partially opaque contents culled, drawn with blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1969 | layer1->SetContentsOpaque(false); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1970 | layer1->setQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 1971 | layer1->setQuadVisibleRect(gfx::Rect(7, 5, 3, 5)); |
| 1972 | layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1973 | layer1->setExpectation(true, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1974 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1975 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1976 | EXPECT_TRUE(layer1->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1977 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1978 | |
| 1979 | // Layer with partially opaque contents and translucent contents culled, drawn without blending. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1980 | layer1->SetContentsOpaque(false); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1981 | layer1->setQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 1982 | layer1->setQuadVisibleRect(gfx::Rect(5, 5, 2, 5)); |
| 1983 | layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1984 | layer1->setExpectation(false, false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1985 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1986 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1987 | EXPECT_TRUE(layer1->quadsAppended()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1988 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1989 | |
| 1990 | } |
| 1991 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 1992 | TEST_F(LayerTreeHostImplTest, viewportCovered) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1993 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1994 | m_hostImpl->InitializeRenderer(createOutputSurface()); |
| 1995 | m_hostImpl->active_tree()->set_background_color(SK_ColorGRAY); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1996 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1997 | gfx::Size viewportSize(1000, 1000); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1998 | m_hostImpl->SetViewportSize(viewportSize, viewportSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1999 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2000 | m_hostImpl->active_tree()->SetRootLayer(LayerImpl::Create(m_hostImpl->active_tree(), 1)); |
| 2001 | m_hostImpl->active_tree()->root_layer()->AddChild(BlendStateCheckLayer::Create(m_hostImpl->active_tree(), 2, m_hostImpl->resource_provider())); |
| 2002 | BlendStateCheckLayer* child = static_cast<BlendStateCheckLayer*>(m_hostImpl->active_tree()->root_layer()->children()[0]); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 2003 | child->setExpectation(false, false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2004 | child->SetContentsOpaque(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2005 | |
| 2006 | // No gutter rects |
| 2007 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2008 | gfx::Rect layerRect(0, 0, 1000, 1000); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2009 | child->SetPosition(layerRect.origin()); |
| 2010 | child->SetBounds(layerRect.size()); |
| 2011 | child->SetContentBounds(layerRect.size()); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2012 | child->setQuadRect(gfx::Rect(gfx::Point(), layerRect.size())); |
| 2013 | child->setQuadVisibleRect(gfx::Rect(gfx::Point(), layerRect.size())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2014 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2015 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2016 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
| 2017 | ASSERT_EQ(1u, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2018 | |
| 2019 | size_t numGutterQuads = 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2020 | for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i) |
| 2021 | numGutterQuads += (frame.render_passes[0]->quad_list[i]->material == DrawQuad::SOLID_COLOR) ? 1 : 0; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2022 | EXPECT_EQ(0u, numGutterQuads); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2023 | EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2024 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2025 | LayerTestCommon::verifyQuadsExactlyCoverRect(frame.render_passes[0]->quad_list, gfx::Rect(gfx::Point(), viewportSize)); |
| 2026 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | // Empty visible content area (fullscreen gutter rect) |
| 2030 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2031 | gfx::Rect layerRect(0, 0, 0, 0); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2032 | child->SetPosition(layerRect.origin()); |
| 2033 | child->SetBounds(layerRect.size()); |
| 2034 | child->SetContentBounds(layerRect.size()); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2035 | child->setQuadRect(gfx::Rect(gfx::Point(), layerRect.size())); |
| 2036 | child->setQuadVisibleRect(gfx::Rect(gfx::Point(), layerRect.size())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2037 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2038 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2039 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
| 2040 | ASSERT_EQ(1u, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2041 | |
| 2042 | size_t numGutterQuads = 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2043 | for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i) |
| 2044 | numGutterQuads += (frame.render_passes[0]->quad_list[i]->material == DrawQuad::SOLID_COLOR) ? 1 : 0; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2045 | EXPECT_EQ(1u, numGutterQuads); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2046 | EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2047 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2048 | LayerTestCommon::verifyQuadsExactlyCoverRect(frame.render_passes[0]->quad_list, gfx::Rect(gfx::Point(), viewportSize)); |
| 2049 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | // Content area in middle of clip rect (four surrounding gutter rects) |
| 2053 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2054 | gfx::Rect layerRect(500, 500, 200, 200); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2055 | child->SetPosition(layerRect.origin()); |
| 2056 | child->SetBounds(layerRect.size()); |
| 2057 | child->SetContentBounds(layerRect.size()); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2058 | child->setQuadRect(gfx::Rect(gfx::Point(), layerRect.size())); |
| 2059 | child->setQuadVisibleRect(gfx::Rect(gfx::Point(), layerRect.size())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2060 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2061 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2062 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
| 2063 | ASSERT_EQ(1u, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2064 | |
| 2065 | size_t numGutterQuads = 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2066 | for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i) |
| 2067 | numGutterQuads += (frame.render_passes[0]->quad_list[i]->material == DrawQuad::SOLID_COLOR) ? 1 : 0; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2068 | EXPECT_EQ(4u, numGutterQuads); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2069 | EXPECT_EQ(5u, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2070 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2071 | LayerTestCommon::verifyQuadsExactlyCoverRect(frame.render_passes[0]->quad_list, gfx::Rect(gfx::Point(), viewportSize)); |
| 2072 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | } |
| 2076 | |
| 2077 | |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 2078 | class ReshapeTrackerContext: public TestWebGraphicsContext3D { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2079 | public: |
| 2080 | ReshapeTrackerContext() : m_reshapeCalled(false) { } |
| 2081 | |
| 2082 | virtual void reshape(int width, int height) |
| 2083 | { |
| 2084 | m_reshapeCalled = true; |
| 2085 | } |
| 2086 | |
| 2087 | bool reshapeCalled() const { return m_reshapeCalled; } |
| 2088 | |
| 2089 | private: |
| 2090 | bool m_reshapeCalled; |
| 2091 | }; |
| 2092 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2093 | class FakeDrawableLayerImpl: public LayerImpl { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2094 | public: |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2095 | static scoped_ptr<LayerImpl> Create(LayerTreeImpl* treeImpl, int id) { return scoped_ptr<LayerImpl>(new FakeDrawableLayerImpl(treeImpl, id)); } |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 2096 | protected: |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 2097 | FakeDrawableLayerImpl(LayerTreeImpl* treeImpl, int id) : LayerImpl(treeImpl, id) { } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2098 | }; |
| 2099 | |
| 2100 | // Only reshape when we know we are going to draw. Otherwise, the reshape |
| 2101 | // can leave the window at the wrong size if we never draw and the proper |
| 2102 | // viewport size is never set. |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2103 | TEST_F(LayerTreeHostImplTest, reshapeNotCalledUntilDraw) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2104 | { |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 2105 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new ReshapeTrackerContext)).PassAs<OutputSurface>(); |
[email protected] | 79a1be5 | 2013-02-13 23:59:50 | [diff] [blame] | 2106 | ReshapeTrackerContext* reshapeTracker = static_cast<ReshapeTrackerContext*>(outputSurface->context3d()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2107 | m_hostImpl->InitializeRenderer(outputSurface.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2108 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2109 | scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2110 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2111 | root->SetBounds(gfx::Size(10, 10)); |
| 2112 | root->SetDrawsContent(true); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2113 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2114 | EXPECT_FALSE(reshapeTracker->reshapeCalled()); |
| 2115 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2116 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2117 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2118 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2119 | EXPECT_TRUE(reshapeTracker->reshapeCalled()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2120 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2121 | } |
| 2122 | |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 2123 | class PartialSwapTrackerContext : public TestWebGraphicsContext3D { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2124 | public: |
| 2125 | virtual void postSubBufferCHROMIUM(int x, int y, int width, int height) |
| 2126 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2127 | m_partialSwapRect = gfx::Rect(x, y, width, height); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2128 | } |
| 2129 | |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2130 | virtual WebKit::WebString getString(WebKit::WGC3Denum name) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2131 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 2132 | if (name == GL_EXTENSIONS) |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2133 | return WebKit::WebString("GL_CHROMIUM_post_sub_buffer GL_CHROMIUM_set_visibility"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2134 | |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2135 | return WebKit::WebString(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2136 | } |
| 2137 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2138 | gfx::Rect partialSwapRect() const { return m_partialSwapRect; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2139 | |
| 2140 | private: |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2141 | gfx::Rect m_partialSwapRect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2142 | }; |
| 2143 | |
| 2144 | // Make sure damage tracking propagates all the way to the graphics context, |
| 2145 | // where it should request to swap only the subBuffer that is damaged. |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2146 | TEST_F(LayerTreeHostImplTest, partialSwapReceivesDamageRect) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2147 | { |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 2148 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapTrackerContext)).PassAs<OutputSurface>(); |
[email protected] | 79a1be5 | 2013-02-13 23:59:50 | [diff] [blame] | 2149 | PartialSwapTrackerContext* partialSwapTracker = static_cast<PartialSwapTrackerContext*>(outputSurface->context3d()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2150 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2151 | // This test creates its own LayerTreeHostImpl, so |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2152 | // that we can force partial swap enabled. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2153 | LayerTreeSettings settings; |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 2154 | settings.partialSwapEnabled = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2155 | scoped_ptr<LayerTreeHostImpl> layerTreeHostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
| 2156 | layerTreeHostImpl->InitializeRenderer(outputSurface.Pass()); |
| 2157 | layerTreeHostImpl->SetViewportSize(gfx::Size(500, 500), gfx::Size(500, 500)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2158 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2159 | scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::Create(layerTreeHostImpl->active_tree(), 1); |
| 2160 | scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::Create(layerTreeHostImpl->active_tree(), 2); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2161 | child->SetPosition(gfx::PointF(12, 13)); |
| 2162 | child->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2163 | child->SetBounds(gfx::Size(14, 15)); |
| 2164 | child->SetContentBounds(gfx::Size(14, 15)); |
| 2165 | child->SetDrawsContent(true); |
| 2166 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2167 | root->SetBounds(gfx::Size(500, 500)); |
| 2168 | root->SetContentBounds(gfx::Size(500, 500)); |
| 2169 | root->SetDrawsContent(true); |
| 2170 | root->AddChild(child.Pass()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2171 | layerTreeHostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2172 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2173 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2174 | |
| 2175 | // First frame, the entire screen should get swapped. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2176 | EXPECT_TRUE(layerTreeHostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2177 | layerTreeHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2178 | layerTreeHostImpl->DidDrawAllLayers(frame); |
| 2179 | layerTreeHostImpl->SwapBuffers(); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2180 | gfx::Rect actualSwapRect = partialSwapTracker->partialSwapRect(); |
| 2181 | gfx::Rect expectedSwapRect = gfx::Rect(gfx::Point(), gfx::Size(500, 500)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2182 | EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); |
| 2183 | EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); |
| 2184 | EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width()); |
| 2185 | EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height()); |
| 2186 | |
| 2187 | // Second frame, only the damaged area should get swapped. Damage should be the union |
| 2188 | // of old and new child rects. |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2189 | // expected damage rect: gfx::Rect(gfx::Point(), gfx::Size(26, 28)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2190 | // expected swap rect: vertically flipped, with origin at bottom left corner. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2191 | layerTreeHostImpl->active_tree()->root_layer()->children()[0]->SetPosition(gfx::PointF(0, 0)); |
| 2192 | EXPECT_TRUE(layerTreeHostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2193 | layerTreeHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2194 | m_hostImpl->DidDrawAllLayers(frame); |
| 2195 | layerTreeHostImpl->SwapBuffers(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2196 | actualSwapRect = partialSwapTracker->partialSwapRect(); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2197 | expectedSwapRect = gfx::Rect(gfx::Point(0, 500-28), gfx::Size(26, 28)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2198 | EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); |
| 2199 | EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); |
| 2200 | EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width()); |
| 2201 | EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height()); |
| 2202 | |
| 2203 | // Make sure that partial swap is constrained to the viewport dimensions |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2204 | // expected damage rect: gfx::Rect(gfx::Point(), gfx::Size(500, 500)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2205 | // expected swap rect: flipped damage rect, but also clamped to viewport |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2206 | layerTreeHostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
| 2207 | layerTreeHostImpl->active_tree()->root_layer()->SetOpacity(0.7f); // this will damage everything |
| 2208 | EXPECT_TRUE(layerTreeHostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2209 | layerTreeHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2210 | m_hostImpl->DidDrawAllLayers(frame); |
| 2211 | layerTreeHostImpl->SwapBuffers(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2212 | actualSwapRect = partialSwapTracker->partialSwapRect(); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2213 | expectedSwapRect = gfx::Rect(gfx::Point(), gfx::Size(10, 10)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2214 | EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); |
| 2215 | EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); |
| 2216 | EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width()); |
| 2217 | EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height()); |
| 2218 | } |
| 2219 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2220 | TEST_F(LayerTreeHostImplTest, rootLayerDoesntCreateExtraSurface) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2221 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2222 | scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::Create(m_hostImpl->active_tree(), 1); |
| 2223 | scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::Create(m_hostImpl->active_tree(), 2); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2224 | child->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2225 | child->SetBounds(gfx::Size(10, 10)); |
| 2226 | child->SetContentBounds(gfx::Size(10, 10)); |
| 2227 | child->SetDrawsContent(true); |
| 2228 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2229 | root->SetBounds(gfx::Size(10, 10)); |
| 2230 | root->SetContentBounds(gfx::Size(10, 10)); |
| 2231 | root->SetDrawsContent(true); |
| 2232 | root->SetOpacity(0.7f); |
| 2233 | root->AddChild(child.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2234 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2235 | m_hostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2236 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2237 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2238 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2239 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
| 2240 | EXPECT_EQ(1u, frame.render_surface_layer_list->size()); |
| 2241 | EXPECT_EQ(1u, frame.render_passes.size()); |
| 2242 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2243 | } |
| 2244 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2245 | class FakeLayerWithQuads : public LayerImpl { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2246 | public: |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2247 | static scoped_ptr<LayerImpl> Create(LayerTreeImpl* treeImpl, int id) { return scoped_ptr<LayerImpl>(new FakeLayerWithQuads(treeImpl, id)); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2248 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2249 | virtual void AppendQuads(QuadSink* quadSink, AppendQuadsData* appendQuadsData) OVERRIDE |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2250 | { |
[email protected] | c7e95b4 | 2013-03-18 01:13:49 | [diff] [blame] | 2251 | SharedQuadState* sharedQuadState = quadSink->UseSharedQuadState(CreateSharedQuadState()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2252 | |
| 2253 | SkColor gray = SkColorSetRGB(100, 100, 100); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2254 | gfx::Rect quadRect(gfx::Point(0, 0), content_bounds()); |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 2255 | scoped_ptr<SolidColorDrawQuad> myQuad = SolidColorDrawQuad::Create(); |
| 2256 | myQuad->SetNew(sharedQuadState, quadRect, gray); |
[email protected] | c7e95b4 | 2013-03-18 01:13:49 | [diff] [blame] | 2257 | quadSink->Append(myQuad.PassAs<DrawQuad>(), appendQuadsData); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | private: |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 2261 | FakeLayerWithQuads(LayerTreeImpl* treeImpl, int id) |
| 2262 | : LayerImpl(treeImpl, id) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2263 | { |
| 2264 | } |
| 2265 | }; |
| 2266 | |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 2267 | class MockContext : public TestWebGraphicsContext3D { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2268 | public: |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2269 | MOCK_METHOD1(useProgram, void(WebKit::WebGLId program)); |
| 2270 | MOCK_METHOD5(uniform4f, void(WebKit::WGC3Dint location, WebKit::WGC3Dfloat x, WebKit::WGC3Dfloat y, WebKit::WGC3Dfloat z, WebKit::WGC3Dfloat w)); |
| 2271 | MOCK_METHOD4(uniformMatrix4fv, void(WebKit::WGC3Dint location, WebKit::WGC3Dsizei count, WebKit::WGC3Dboolean transpose, const WebKit::WGC3Dfloat* value)); |
| 2272 | MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, WebKit::WGC3Dsizei count, WebKit::WGC3Denum type, WebKit::WGC3Dintptr offset)); |
| 2273 | MOCK_METHOD1(getString, WebKit::WebString(WebKit::WGC3Denum name)); |
| 2274 | MOCK_METHOD0(getRequestableExtensionsCHROMIUM, WebKit::WebString()); |
| 2275 | MOCK_METHOD1(enable, void(WebKit::WGC3Denum cap)); |
| 2276 | MOCK_METHOD1(disable, void(WebKit::WGC3Denum cap)); |
| 2277 | MOCK_METHOD4(scissor, void(WebKit::WGC3Dint x, WebKit::WGC3Dint y, WebKit::WGC3Dsizei width, WebKit::WGC3Dsizei height)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2278 | }; |
| 2279 | |
| 2280 | class MockContextHarness { |
| 2281 | private: |
| 2282 | MockContext* m_context; |
| 2283 | public: |
| 2284 | MockContextHarness(MockContext* context) |
| 2285 | : m_context(context) |
| 2286 | { |
| 2287 | // Catch "uninteresting" calls |
| 2288 | EXPECT_CALL(*m_context, useProgram(_)) |
| 2289 | .Times(0); |
| 2290 | |
| 2291 | EXPECT_CALL(*m_context, drawElements(_, _, _, _)) |
| 2292 | .Times(0); |
| 2293 | |
| 2294 | // These are not asserted |
| 2295 | EXPECT_CALL(*m_context, uniformMatrix4fv(_, _, _, _)) |
| 2296 | .WillRepeatedly(Return()); |
| 2297 | |
| 2298 | EXPECT_CALL(*m_context, uniform4f(_, _, _, _, _)) |
| 2299 | .WillRepeatedly(Return()); |
| 2300 | |
| 2301 | // Any other strings are empty |
| 2302 | EXPECT_CALL(*m_context, getString(_)) |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2303 | .WillRepeatedly(Return(WebKit::WebString())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2304 | |
| 2305 | // Support for partial swap, if needed |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 2306 | EXPECT_CALL(*m_context, getString(GL_EXTENSIONS)) |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2307 | .WillRepeatedly(Return(WebKit::WebString("GL_CHROMIUM_post_sub_buffer"))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2308 | |
| 2309 | EXPECT_CALL(*m_context, getRequestableExtensionsCHROMIUM()) |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2310 | .WillRepeatedly(Return(WebKit::WebString("GL_CHROMIUM_post_sub_buffer"))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2311 | |
| 2312 | // Any un-sanctioned calls to enable() are OK |
| 2313 | EXPECT_CALL(*m_context, enable(_)) |
| 2314 | .WillRepeatedly(Return()); |
| 2315 | |
| 2316 | // Any un-sanctioned calls to disable() are OK |
| 2317 | EXPECT_CALL(*m_context, disable(_)) |
| 2318 | .WillRepeatedly(Return()); |
| 2319 | } |
| 2320 | |
| 2321 | void mustDrawSolidQuad() |
| 2322 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 2323 | EXPECT_CALL(*m_context, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2324 | .WillOnce(Return()) |
| 2325 | .RetiresOnSaturation(); |
| 2326 | |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2327 | EXPECT_CALL(*m_context, useProgram(_)) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2328 | .WillOnce(Return()) |
| 2329 | .RetiresOnSaturation(); |
| 2330 | |
| 2331 | } |
| 2332 | |
| 2333 | void mustSetScissor(int x, int y, int width, int height) |
| 2334 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 2335 | EXPECT_CALL(*m_context, enable(GL_SCISSOR_TEST)) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2336 | .WillRepeatedly(Return()); |
| 2337 | |
| 2338 | EXPECT_CALL(*m_context, scissor(x, y, width, height)) |
| 2339 | .Times(AtLeast(1)) |
| 2340 | .WillRepeatedly(Return()); |
| 2341 | } |
| 2342 | |
| 2343 | void mustSetNoScissor() |
| 2344 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 2345 | EXPECT_CALL(*m_context, disable(GL_SCISSOR_TEST)) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2346 | .WillRepeatedly(Return()); |
| 2347 | |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 2348 | EXPECT_CALL(*m_context, enable(GL_SCISSOR_TEST)) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2349 | .Times(0); |
| 2350 | |
| 2351 | EXPECT_CALL(*m_context, scissor(_, _, _, _)) |
| 2352 | .Times(0); |
| 2353 | } |
| 2354 | }; |
| 2355 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2356 | TEST_F(LayerTreeHostImplTest, noPartialSwap) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2357 | { |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2358 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<OutputSurface>(); |
[email protected] | 79a1be5 | 2013-02-13 23:59:50 | [diff] [blame] | 2359 | MockContext* mockContext = static_cast<MockContext*>(outputSurface->context3d()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2360 | MockContextHarness harness(mockContext); |
| 2361 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2362 | // Run test case |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 2363 | createLayerTreeHost(false, outputSurface.Pass()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2364 | setupRootLayerImpl(FakeLayerWithQuads::Create(m_hostImpl->active_tree(), 1)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2365 | |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 2366 | // without partial swap, and no clipping, no scissor is set. |
| 2367 | harness.mustDrawSolidQuad(); |
| 2368 | harness.mustSetNoScissor(); |
| 2369 | { |
| 2370 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2371 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2372 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2373 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 2374 | } |
| 2375 | Mock::VerifyAndClearExpectations(&mockContext); |
| 2376 | |
| 2377 | // without partial swap, but a layer does clip its subtree, one scissor is set. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2378 | m_hostImpl->active_tree()->root_layer()->SetMasksToBounds(true); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 2379 | harness.mustDrawSolidQuad(); |
| 2380 | harness.mustSetScissor(0, 0, 10, 10); |
| 2381 | { |
| 2382 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2383 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2384 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2385 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 2386 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2387 | Mock::VerifyAndClearExpectations(&mockContext); |
| 2388 | } |
| 2389 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2390 | TEST_F(LayerTreeHostImplTest, partialSwap) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2391 | { |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 2392 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<OutputSurface>(); |
[email protected] | 79a1be5 | 2013-02-13 23:59:50 | [diff] [blame] | 2393 | MockContext* mockContext = static_cast<MockContext*>(outputSurface->context3d()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2394 | MockContextHarness harness(mockContext); |
| 2395 | |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 2396 | createLayerTreeHost(true, outputSurface.Pass()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2397 | setupRootLayerImpl(FakeLayerWithQuads::Create(m_hostImpl->active_tree(), 1)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2398 | |
| 2399 | // The first frame is not a partially-swapped one. |
| 2400 | harness.mustSetScissor(0, 0, 10, 10); |
| 2401 | harness.mustDrawSolidQuad(); |
| 2402 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2403 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2404 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2405 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2406 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2407 | } |
| 2408 | Mock::VerifyAndClearExpectations(&mockContext); |
| 2409 | |
| 2410 | // Damage a portion of the frame. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2411 | m_hostImpl->active_tree()->root_layer()->set_update_rect(gfx::Rect(0, 0, 2, 3)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2412 | |
| 2413 | // The second frame will be partially-swapped (the y coordinates are flipped). |
| 2414 | harness.mustSetScissor(0, 7, 2, 3); |
| 2415 | harness.mustDrawSolidQuad(); |
| 2416 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2417 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2418 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2419 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2420 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2421 | } |
| 2422 | Mock::VerifyAndClearExpectations(&mockContext); |
| 2423 | } |
| 2424 | |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 2425 | class PartialSwapContext : public TestWebGraphicsContext3D { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2426 | public: |
[email protected] | 9f93027 | 2013-02-06 09:51:55 | [diff] [blame] | 2427 | virtual WebKit::WebString getString(WebKit::WGC3Denum name) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2428 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 2429 | if (name == GL_EXTENSIONS) |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2430 | return WebKit::WebString("GL_CHROMIUM_post_sub_buffer"); |
| 2431 | return WebKit::WebString(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2432 | } |
| 2433 | |
[email protected] | 9f93027 | 2013-02-06 09:51:55 | [diff] [blame] | 2434 | virtual WebKit::WebString getRequestableExtensionsCHROMIUM() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2435 | { |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2436 | return WebKit::WebString("GL_CHROMIUM_post_sub_buffer"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | // Unlimited texture size. |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2440 | virtual void getIntegerv(WebKit::WGC3Denum pname, WebKit::WGC3Dint* value) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2441 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 2442 | if (pname == GL_MAX_TEXTURE_SIZE) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2443 | *value = 8192; |
| 2444 | } |
| 2445 | }; |
| 2446 | |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 2447 | static scoped_ptr<LayerTreeHostImpl> setupLayersForOpacity(bool partialSwap, LayerTreeHostImplClient* client, Proxy* proxy) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2448 | { |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 2449 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2450 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2451 | LayerTreeSettings settings; |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 2452 | settings.partialSwapEnabled = partialSwap; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2453 | scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(settings, client, proxy); |
| 2454 | myHostImpl->InitializeRenderer(outputSurface.Pass()); |
| 2455 | myHostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2456 | |
| 2457 | /* |
| 2458 | Layers are created as follows: |
| 2459 | |
| 2460 | +--------------------+ |
| 2461 | | 1 | |
| 2462 | | +-----------+ | |
| 2463 | | | 2 | | |
| 2464 | | | +-------------------+ |
| 2465 | | | | 3 | |
| 2466 | | | +-------------------+ |
| 2467 | | | | | |
| 2468 | | +-----------+ | |
| 2469 | | | |
| 2470 | | | |
| 2471 | +--------------------+ |
| 2472 | |
| 2473 | Layers 1, 2 have render surfaces |
| 2474 | */ |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2475 | scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1); |
| 2476 | scoped_ptr<LayerImpl> child = LayerImpl::Create(myHostImpl->active_tree(), 2); |
| 2477 | scoped_ptr<LayerImpl> grandChild = FakeLayerWithQuads::Create(myHostImpl->active_tree(), 3); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2478 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2479 | gfx::Rect rootRect(0, 0, 100, 100); |
| 2480 | gfx::Rect childRect(10, 10, 50, 50); |
| 2481 | gfx::Rect grandChildRect(5, 5, 150, 150); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2482 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2483 | root->CreateRenderSurface(); |
| 2484 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2485 | root->SetPosition(gfx::PointF(rootRect.x(), rootRect.y())); |
| 2486 | root->SetBounds(gfx::Size(rootRect.width(), rootRect.height())); |
| 2487 | root->SetContentBounds(root->bounds()); |
| 2488 | root->draw_properties().visible_content_rect = rootRect; |
| 2489 | root->SetDrawsContent(false); |
| 2490 | root->render_surface()->SetContentRect(gfx::Rect(gfx::Point(), gfx::Size(rootRect.width(), rootRect.height()))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2491 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2492 | child->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2493 | child->SetPosition(gfx::PointF(childRect.x(), childRect.y())); |
| 2494 | child->SetOpacity(0.5f); |
| 2495 | child->SetBounds(gfx::Size(childRect.width(), childRect.height())); |
| 2496 | child->SetContentBounds(child->bounds()); |
| 2497 | child->draw_properties().visible_content_rect = childRect; |
| 2498 | child->SetDrawsContent(false); |
| 2499 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2500 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2501 | grandChild->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2502 | grandChild->SetPosition(gfx::Point(grandChildRect.x(), grandChildRect.y())); |
| 2503 | grandChild->SetBounds(gfx::Size(grandChildRect.width(), grandChildRect.height())); |
| 2504 | grandChild->SetContentBounds(grandChild->bounds()); |
| 2505 | grandChild->draw_properties().visible_content_rect = grandChildRect; |
| 2506 | grandChild->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2507 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2508 | child->AddChild(grandChild.Pass()); |
| 2509 | root->AddChild(child.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2510 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2511 | myHostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 51928176 | 2012-10-06 20:06:39 | [diff] [blame] | 2512 | return myHostImpl.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2513 | } |
| 2514 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2515 | TEST_F(LayerTreeHostImplTest, contributingLayerEmptyScissorPartialSwap) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2516 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 2517 | scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(true, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2518 | |
| 2519 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2520 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2521 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2522 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2523 | // Verify all quads have been computed |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2524 | ASSERT_EQ(2U, frame.render_passes.size()); |
| 2525 | ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 2526 | ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
| 2527 | EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.render_passes[0]->quad_list[0]->material); |
| 2528 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->material); |
[email protected] | 85167c7 | 2012-12-04 03:56:07 | [diff] [blame] | 2529 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2530 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2531 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2532 | } |
| 2533 | } |
| 2534 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2535 | TEST_F(LayerTreeHostImplTest, contributingLayerEmptyScissorNoPartialSwap) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2536 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 2537 | scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(false, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2538 | |
| 2539 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2540 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2541 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2542 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2543 | // Verify all quads have been computed |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2544 | ASSERT_EQ(2U, frame.render_passes.size()); |
| 2545 | ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 2546 | ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
| 2547 | EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.render_passes[0]->quad_list[0]->material); |
| 2548 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->material); |
[email protected] | 85167c7 | 2012-12-04 03:56:07 | [diff] [blame] | 2549 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2550 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2551 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2552 | } |
| 2553 | } |
| 2554 | |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2555 | // Fake WebKit::WebGraphicsContext3D that tracks the number of textures in use. |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 2556 | class TrackingWebGraphicsContext3D : public TestWebGraphicsContext3D { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2557 | public: |
| 2558 | TrackingWebGraphicsContext3D() |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 2559 | : TestWebGraphicsContext3D() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2560 | , m_numTextures(0) |
| 2561 | { } |
| 2562 | |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2563 | virtual WebKit::WebGLId createTexture() OVERRIDE |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2564 | { |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 2565 | WebKit::WebGLId id = TestWebGraphicsContext3D::createTexture(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2566 | |
[email protected] | 357b517 | 2012-10-18 17:39:33 | [diff] [blame] | 2567 | m_textures[id] = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2568 | ++m_numTextures; |
| 2569 | return id; |
| 2570 | } |
| 2571 | |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2572 | virtual void deleteTexture(WebKit::WebGLId id) OVERRIDE |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2573 | { |
[email protected] | 357b517 | 2012-10-18 17:39:33 | [diff] [blame] | 2574 | if (m_textures.find(id) == m_textures.end()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2575 | return; |
| 2576 | |
[email protected] | 357b517 | 2012-10-18 17:39:33 | [diff] [blame] | 2577 | m_textures[id] = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2578 | --m_numTextures; |
| 2579 | } |
| 2580 | |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2581 | virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2582 | { |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 2583 | if (name == GL_EXTENSIONS) |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2584 | return WebKit::WebString("GL_CHROMIUM_iosurface GL_ARB_texture_rectangle"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2585 | |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2586 | return WebKit::WebString(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | unsigned numTextures() const { return m_numTextures; } |
| 2590 | |
| 2591 | private: |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2592 | base::hash_map<WebKit::WebGLId, bool> m_textures; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2593 | unsigned m_numTextures; |
| 2594 | }; |
| 2595 | |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2596 | static unsigned createResourceId(ResourceProvider* resourceProvider) |
| 2597 | { |
[email protected] | f53da397 | 2013-03-07 08:38:41 | [diff] [blame] | 2598 | return resourceProvider->CreateResource( |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2599 | gfx::Size(20, 12), |
[email protected] | f53da397 | 2013-03-07 08:38:41 | [diff] [blame] | 2600 | resourceProvider->best_texture_format(), |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2601 | ResourceProvider::TextureUsageAny); |
| 2602 | } |
| 2603 | |
| 2604 | static unsigned createTextureId(ResourceProvider* resourceProvider) |
| 2605 | { |
| 2606 | return ResourceProvider::ScopedReadLockGL( |
[email protected] | f53da397 | 2013-03-07 08:38:41 | [diff] [blame] | 2607 | resourceProvider, createResourceId(resourceProvider)).texture_id(); |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2608 | } |
| 2609 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2610 | TEST_F(LayerTreeHostImplTest, layersFreeTextures) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2611 | { |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 2612 | scoped_ptr<TestWebGraphicsContext3D> context = |
| 2613 | TestWebGraphicsContext3D::Create(); |
| 2614 | TestWebGraphicsContext3D* context3d = context.get(); |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2615 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d( |
| 2616 | context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2617 | m_hostImpl->InitializeRenderer(outputSurface.Pass()); |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2618 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2619 | scoped_ptr<LayerImpl> rootLayer(LayerImpl::Create(m_hostImpl->active_tree(), 1)); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2620 | rootLayer->SetBounds(gfx::Size(10, 10)); |
| 2621 | rootLayer->SetAnchorPoint(gfx::PointF()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2622 | |
[email protected] | 568285b | 2013-01-07 23:19:19 | [diff] [blame] | 2623 | scoped_refptr<VideoFrame> softwareFrame(media::VideoFrame::CreateColorFrame( |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2624 | gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2625 | FakeVideoFrameProvider provider; |
[email protected] | 568285b | 2013-01-07 23:19:19 | [diff] [blame] | 2626 | provider.set_frame(softwareFrame); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2627 | scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::Create(m_hostImpl->active_tree(), 4, &provider); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2628 | videoLayer->SetBounds(gfx::Size(10, 10)); |
| 2629 | videoLayer->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2630 | videoLayer->SetContentBounds(gfx::Size(10, 10)); |
| 2631 | videoLayer->SetDrawsContent(true); |
| 2632 | rootLayer->AddChild(videoLayer.PassAs<LayerImpl>()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2633 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2634 | scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::Create(m_hostImpl->active_tree(), 5); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2635 | ioSurfaceLayer->SetBounds(gfx::Size(10, 10)); |
| 2636 | ioSurfaceLayer->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2637 | ioSurfaceLayer->SetContentBounds(gfx::Size(10, 10)); |
| 2638 | ioSurfaceLayer->SetDrawsContent(true); |
[email protected] | 844a963 | 2013-03-17 21:01:25 | [diff] [blame] | 2639 | ioSurfaceLayer->SetIOSurfaceProperties(1, gfx::Size(10, 10)); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2640 | rootLayer->AddChild(ioSurfaceLayer.PassAs<LayerImpl>()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2641 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2642 | m_hostImpl->active_tree()->SetRootLayer(rootLayer.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2643 | |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2644 | EXPECT_EQ(0u, context3d->NumTextures()); |
| 2645 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2646 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2647 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2648 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2649 | m_hostImpl->DidDrawAllLayers(frame); |
| 2650 | m_hostImpl->SwapBuffers(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2651 | |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2652 | EXPECT_GT(context3d->NumTextures(), 0u); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2653 | |
| 2654 | // Kill the layer tree. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2655 | m_hostImpl->active_tree()->SetRootLayer(LayerImpl::Create(m_hostImpl->active_tree(), 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2656 | // There should be no textures left in use after. |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 2657 | EXPECT_EQ(0u, context3d->NumTextures()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2658 | } |
| 2659 | |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 2660 | class MockDrawQuadsToFillScreenContext : public TestWebGraphicsContext3D { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2661 | public: |
[email protected] | 009dc07 | 2012-12-16 20:32:13 | [diff] [blame] | 2662 | MOCK_METHOD1(useProgram, void(WebKit::WebGLId program)); |
| 2663 | MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, WebKit::WGC3Dsizei count, WebKit::WGC3Denum type, WebKit::WGC3Dintptr offset)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2664 | }; |
| 2665 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2666 | TEST_F(LayerTreeHostImplTest, hasTransparentBackground) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2667 | { |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 2668 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockDrawQuadsToFillScreenContext)).PassAs<OutputSurface>(); |
[email protected] | 79a1be5 | 2013-02-13 23:59:50 | [diff] [blame] | 2669 | MockDrawQuadsToFillScreenContext* mockContext = static_cast<MockDrawQuadsToFillScreenContext*>(outputSurface->context3d()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2670 | |
| 2671 | // Run test case |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 2672 | createLayerTreeHost(false, outputSurface.Pass()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2673 | setupRootLayerImpl(LayerImpl::Create(m_hostImpl->active_tree(), 1)); |
| 2674 | m_hostImpl->active_tree()->set_background_color(SK_ColorWHITE); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2675 | |
| 2676 | // Verify one quad is drawn when transparent background set is not set. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2677 | m_hostImpl->active_tree()->set_has_transparent_background(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2678 | EXPECT_CALL(*mockContext, useProgram(_)) |
| 2679 | .Times(1); |
| 2680 | EXPECT_CALL(*mockContext, drawElements(_, _, _, _)) |
| 2681 | .Times(1); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2682 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2683 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2684 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2685 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2686 | Mock::VerifyAndClearExpectations(&mockContext); |
| 2687 | |
| 2688 | // Verify no quads are drawn when transparent background is set. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2689 | m_hostImpl->active_tree()->set_has_transparent_background(true); |
| 2690 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2691 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2692 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2693 | Mock::VerifyAndClearExpectations(&mockContext); |
| 2694 | } |
| 2695 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2696 | static void addDrawingLayerTo(LayerImpl* parent, int id, const gfx::Rect& layerRect, LayerImpl** result) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2697 | { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2698 | scoped_ptr<LayerImpl> layer = FakeLayerWithQuads::Create(parent->layer_tree_impl(), id); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2699 | LayerImpl* layerPtr = layer.get(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2700 | layerPtr->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2701 | layerPtr->SetPosition(gfx::PointF(layerRect.origin())); |
| 2702 | layerPtr->SetBounds(layerRect.size()); |
| 2703 | layerPtr->SetContentBounds(layerRect.size()); |
| 2704 | layerPtr->SetDrawsContent(true); // only children draw content |
| 2705 | layerPtr->SetContentsOpaque(true); |
| 2706 | parent->AddChild(layer.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2707 | if (result) |
| 2708 | *result = layerPtr; |
| 2709 | } |
| 2710 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2711 | static void setupLayersForTextureCaching(LayerTreeHostImpl* layerTreeHostImpl, LayerImpl*& rootPtr, LayerImpl*& intermediateLayerPtr, LayerImpl*& surfaceLayerPtr, LayerImpl*& childPtr, const gfx::Size& rootSize) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2712 | { |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 2713 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2714 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2715 | layerTreeHostImpl->InitializeRenderer(outputSurface.Pass()); |
| 2716 | layerTreeHostImpl->SetViewportSize(rootSize, rootSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2717 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2718 | scoped_ptr<LayerImpl> root = LayerImpl::Create(layerTreeHostImpl->active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2719 | rootPtr = root.get(); |
| 2720 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2721 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2722 | root->SetPosition(gfx::PointF(0, 0)); |
| 2723 | root->SetBounds(rootSize); |
| 2724 | root->SetContentBounds(rootSize); |
| 2725 | root->SetDrawsContent(true); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2726 | layerTreeHostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2727 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2728 | addDrawingLayerTo(rootPtr, 2, gfx::Rect(10, 10, rootSize.width(), rootSize.height()), &intermediateLayerPtr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2729 | intermediateLayerPtr->SetDrawsContent(false); // only children draw content |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2730 | |
| 2731 | // Surface layer is the layer that changes its opacity |
| 2732 | // It will contain other layers that draw content. |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2733 | addDrawingLayerTo(intermediateLayerPtr, 3, gfx::Rect(10, 10, rootSize.width(), rootSize.height()), &surfaceLayerPtr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2734 | surfaceLayerPtr->SetDrawsContent(false); // only children draw content |
| 2735 | surfaceLayerPtr->SetOpacity(0.5f); |
| 2736 | surfaceLayerPtr->SetForceRenderSurface(true); // This will cause it to have a surface |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2737 | |
| 2738 | // Child of the surface layer will produce some quads |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2739 | addDrawingLayerTo(surfaceLayerPtr, 4, gfx::Rect(5, 5, rootSize.width() - 25, rootSize.height() - 25), &childPtr); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2740 | } |
| 2741 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2742 | class GLRendererWithReleaseTextures : public GLRenderer { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2743 | public: |
[email protected] | faa48f3 | 2013-03-13 11:10:47 | [diff] [blame] | 2744 | using GLRenderer::ReleaseRenderPassTextures; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2745 | }; |
| 2746 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2747 | TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusion) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2748 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2749 | LayerTreeSettings settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2750 | settings.minimumOcclusionTrackingSize = gfx::Size(); |
[email protected] | 09dc0d4b | 2013-02-13 06:17:20 | [diff] [blame] | 2751 | settings.cacheRenderPassContents = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2752 | scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2753 | |
| 2754 | // Layers are structure as follows: |
| 2755 | // |
| 2756 | // R +-- S1 +- L10 (owning) |
| 2757 | // | +- L11 |
| 2758 | // | +- L12 |
| 2759 | // | |
| 2760 | // +-- S2 +- L20 (owning) |
| 2761 | // +- L21 |
| 2762 | // |
| 2763 | // Occlusion: |
| 2764 | // L12 occludes L11 (internal) |
| 2765 | // L20 occludes L10 (external) |
| 2766 | // L21 occludes L20 (internal) |
| 2767 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2768 | LayerImpl* rootPtr; |
| 2769 | LayerImpl* layerS1Ptr; |
| 2770 | LayerImpl* layerS2Ptr; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2771 | |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 2772 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2773 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2774 | gfx::Size rootSize(1000, 1000); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2775 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2776 | myHostImpl->InitializeRenderer(outputSurface.Pass()); |
| 2777 | myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2778 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2779 | scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2780 | rootPtr = root.get(); |
| 2781 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2782 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2783 | root->SetPosition(gfx::PointF(0, 0)); |
| 2784 | root->SetBounds(rootSize); |
| 2785 | root->SetContentBounds(rootSize); |
| 2786 | root->SetDrawsContent(true); |
| 2787 | root->SetMasksToBounds(true); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2788 | myHostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2789 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2790 | addDrawingLayerTo(rootPtr, 2, gfx::Rect(300, 300, 300, 300), &layerS1Ptr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2791 | layerS1Ptr->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2792 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2793 | addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(10, 10, 10, 10), 0); // L11 |
| 2794 | addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12 |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2795 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2796 | addDrawingLayerTo(rootPtr, 5, gfx::Rect(550, 250, 300, 400), &layerS2Ptr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2797 | layerS2Ptr->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2798 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2799 | addDrawingLayerTo(layerS2Ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21 |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2800 | |
| 2801 | // Initial draw - must receive all quads |
| 2802 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2803 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2804 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2805 | |
| 2806 | // Must receive 3 render passes. |
| 2807 | // For Root, there are 2 quads; for S1, there are 2 quads (1 is occluded); for S2, there is 2 quads. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2808 | ASSERT_EQ(3U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2809 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2810 | EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); |
| 2811 | EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); |
| 2812 | EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2813 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2814 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2815 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | // "Unocclude" surface S1 and repeat draw. |
| 2819 | // Must remove S2's render pass since it's cached; |
| 2820 | // Must keep S1 quads because texture contained external occlusion. |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 2821 | gfx::Transform transform = layerS2Ptr->transform(); |
| 2822 | transform.Translate(150, 150); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2823 | layerS2Ptr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2824 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2825 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2826 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2827 | |
| 2828 | // Must receive 2 render passes. |
| 2829 | // For Root, there are 2 quads |
| 2830 | // For S1, the number of quads depends on what got unoccluded, so not asserted beyond being positive. |
| 2831 | // For S2, there is no render pass |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2832 | ASSERT_EQ(2U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2833 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2834 | EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U); |
| 2835 | EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2836 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2837 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2838 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | // "Re-occlude" surface S1 and repeat draw. |
| 2842 | // Must remove S1's render pass since it is now available in full. |
| 2843 | // S2 has no change so must also be removed. |
| 2844 | transform = layerS2Ptr->transform(); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 2845 | transform.Translate(-15, -15); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2846 | layerS2Ptr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2847 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2848 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2849 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2850 | |
| 2851 | // Must receive 1 render pass - for the root. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2852 | ASSERT_EQ(1U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2853 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2854 | EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2855 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2856 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2857 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | } |
| 2861 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2862 | TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionEarlyOut) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2863 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2864 | LayerTreeSettings settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2865 | settings.minimumOcclusionTrackingSize = gfx::Size(); |
[email protected] | 09dc0d4b | 2013-02-13 06:17:20 | [diff] [blame] | 2866 | settings.cacheRenderPassContents = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2867 | scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2868 | |
| 2869 | // Layers are structure as follows: |
| 2870 | // |
| 2871 | // R +-- S1 +- L10 (owning, non drawing) |
| 2872 | // | +- L11 (corner, unoccluded) |
| 2873 | // | +- L12 (corner, unoccluded) |
| 2874 | // | +- L13 (corner, unoccluded) |
| 2875 | // | +- L14 (corner, entirely occluded) |
| 2876 | // | |
| 2877 | // +-- S2 +- L20 (owning, drawing) |
| 2878 | // |
| 2879 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2880 | LayerImpl* rootPtr; |
| 2881 | LayerImpl* layerS1Ptr; |
| 2882 | LayerImpl* layerS2Ptr; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2883 | |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 2884 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2885 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2886 | gfx::Size rootSize(1000, 1000); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2887 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2888 | myHostImpl->InitializeRenderer(outputSurface.Pass()); |
| 2889 | myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2890 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2891 | scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2892 | rootPtr = root.get(); |
| 2893 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2894 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 2895 | root->SetPosition(gfx::PointF(0, 0)); |
| 2896 | root->SetBounds(rootSize); |
| 2897 | root->SetContentBounds(rootSize); |
| 2898 | root->SetDrawsContent(true); |
| 2899 | root->SetMasksToBounds(true); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2900 | myHostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2901 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2902 | addDrawingLayerTo(rootPtr, 2, gfx::Rect(0, 0, 800, 800), &layerS1Ptr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2903 | layerS1Ptr->SetForceRenderSurface(true); |
| 2904 | layerS1Ptr->SetDrawsContent(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2905 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2906 | addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(0, 0, 300, 300), 0); // L11 |
| 2907 | addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(0, 500, 300, 300), 0); // L12 |
| 2908 | addDrawingLayerTo(layerS1Ptr, 5, gfx::Rect(500, 0, 300, 300), 0); // L13 |
| 2909 | addDrawingLayerTo(layerS1Ptr, 6, gfx::Rect(500, 500, 300, 300), 0); // L14 |
| 2910 | addDrawingLayerTo(layerS1Ptr, 9, gfx::Rect(500, 500, 300, 300), 0); // L14 |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2911 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2912 | addDrawingLayerTo(rootPtr, 7, gfx::Rect(450, 450, 450, 450), &layerS2Ptr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2913 | layerS2Ptr->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2914 | |
| 2915 | // Initial draw - must receive all quads |
| 2916 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2917 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2918 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2919 | |
| 2920 | // Must receive 3 render passes. |
| 2921 | // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is 1 quad. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2922 | ASSERT_EQ(3U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2923 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2924 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2925 | |
| 2926 | // L14 is culled, so only 3 quads. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2927 | EXPECT_EQ(3U, frame.render_passes[1]->quad_list.size()); |
| 2928 | EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2929 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2930 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2931 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | // "Unocclude" surface S1 and repeat draw. |
| 2935 | // Must remove S2's render pass since it's cached; |
| 2936 | // Must keep S1 quads because texture contained external occlusion. |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 2937 | gfx::Transform transform = layerS2Ptr->transform(); |
| 2938 | transform.Translate(100, 100); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2939 | layerS2Ptr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2940 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2941 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2942 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2943 | |
| 2944 | // Must receive 2 render passes. |
| 2945 | // For Root, there are 2 quads |
| 2946 | // For S1, the number of quads depends on what got unoccluded, so not asserted beyond being positive. |
| 2947 | // For S2, there is no render pass |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2948 | ASSERT_EQ(2U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2949 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2950 | EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U); |
| 2951 | EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2952 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2953 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2954 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | // "Re-occlude" surface S1 and repeat draw. |
| 2958 | // Must remove S1's render pass since it is now available in full. |
| 2959 | // S2 has no change so must also be removed. |
| 2960 | transform = layerS2Ptr->transform(); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 2961 | transform.Translate(-15, -15); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 2962 | layerS2Ptr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2963 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2964 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2965 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2966 | |
| 2967 | // Must receive 1 render pass - for the root. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2968 | ASSERT_EQ(1U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2969 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2970 | EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2971 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 2972 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2973 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2974 | } |
| 2975 | } |
| 2976 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 2977 | TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionExternalOverInternal) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2978 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2979 | LayerTreeSettings settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2980 | settings.minimumOcclusionTrackingSize = gfx::Size(); |
[email protected] | 09dc0d4b | 2013-02-13 06:17:20 | [diff] [blame] | 2981 | settings.cacheRenderPassContents = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2982 | scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2983 | |
| 2984 | // Layers are structured as follows: |
| 2985 | // |
| 2986 | // R +-- S1 +- L10 (owning, drawing) |
| 2987 | // | +- L11 (corner, occluded by L12) |
| 2988 | // | +- L12 (opposite corner) |
| 2989 | // | |
| 2990 | // +-- S2 +- L20 (owning, drawing) |
| 2991 | // |
| 2992 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2993 | LayerImpl* rootPtr; |
| 2994 | LayerImpl* layerS1Ptr; |
| 2995 | LayerImpl* layerS2Ptr; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2996 | |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 2997 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2998 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 2999 | gfx::Size rootSize(1000, 1000); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3000 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3001 | myHostImpl->InitializeRenderer(outputSurface.Pass()); |
| 3002 | myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3003 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3004 | scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3005 | rootPtr = root.get(); |
| 3006 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3007 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 3008 | root->SetPosition(gfx::PointF(0, 0)); |
| 3009 | root->SetBounds(rootSize); |
| 3010 | root->SetContentBounds(rootSize); |
| 3011 | root->SetDrawsContent(true); |
| 3012 | root->SetMasksToBounds(true); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3013 | myHostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3014 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3015 | addDrawingLayerTo(rootPtr, 2, gfx::Rect(0, 0, 400, 400), &layerS1Ptr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3016 | layerS1Ptr->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3017 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3018 | addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(0, 0, 300, 300), 0); // L11 |
| 3019 | addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(100, 0, 300, 300), 0); // L12 |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3020 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3021 | addDrawingLayerTo(rootPtr, 7, gfx::Rect(200, 0, 300, 300), &layerS2Ptr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3022 | layerS2Ptr->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3023 | |
| 3024 | // Initial draw - must receive all quads |
| 3025 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3026 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3027 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3028 | |
| 3029 | // Must receive 3 render passes. |
| 3030 | // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is 1 quad. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3031 | ASSERT_EQ(3U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3032 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3033 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3034 | EXPECT_EQ(3U, frame.render_passes[1]->quad_list.size()); |
| 3035 | EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3036 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3037 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3038 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3039 | } |
| 3040 | |
| 3041 | // "Unocclude" surface S1 and repeat draw. |
| 3042 | // Must remove S2's render pass since it's cached; |
| 3043 | // Must keep S1 quads because texture contained external occlusion. |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 3044 | gfx::Transform transform = layerS2Ptr->transform(); |
| 3045 | transform.Translate(300, 0); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3046 | layerS2Ptr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3047 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3048 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3049 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3050 | |
| 3051 | // Must receive 2 render passes. |
| 3052 | // For Root, there are 2 quads |
| 3053 | // For S1, the number of quads depends on what got unoccluded, so not asserted beyond being positive. |
| 3054 | // For S2, there is no render pass |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3055 | ASSERT_EQ(2U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3056 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3057 | EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U); |
| 3058 | EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3059 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3060 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3061 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 3065 | TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionExternalNotAligned) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3066 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3067 | LayerTreeSettings settings; |
[email protected] | 09dc0d4b | 2013-02-13 06:17:20 | [diff] [blame] | 3068 | settings.cacheRenderPassContents = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3069 | scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3070 | |
| 3071 | // Layers are structured as follows: |
| 3072 | // |
| 3073 | // R +-- S1 +- L10 (rotated, drawing) |
| 3074 | // +- L11 (occupies half surface) |
| 3075 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3076 | LayerImpl* rootPtr; |
| 3077 | LayerImpl* layerS1Ptr; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3078 | |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 3079 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3080 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3081 | gfx::Size rootSize(1000, 1000); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3082 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3083 | myHostImpl->InitializeRenderer(outputSurface.Pass()); |
| 3084 | myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3085 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3086 | scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3087 | rootPtr = root.get(); |
| 3088 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3089 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 3090 | root->SetPosition(gfx::PointF(0, 0)); |
| 3091 | root->SetBounds(rootSize); |
| 3092 | root->SetContentBounds(rootSize); |
| 3093 | root->SetDrawsContent(true); |
| 3094 | root->SetMasksToBounds(true); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3095 | myHostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3096 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3097 | addDrawingLayerTo(rootPtr, 2, gfx::Rect(0, 0, 400, 400), &layerS1Ptr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3098 | layerS1Ptr->SetForceRenderSurface(true); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 3099 | gfx::Transform transform = layerS1Ptr->transform(); |
| 3100 | transform.Translate(200, 200); |
| 3101 | transform.Rotate(45); |
| 3102 | transform.Translate(-200, -200); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3103 | layerS1Ptr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3104 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3105 | addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(200, 0, 200, 400), 0); // L11 |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3106 | |
| 3107 | // Initial draw - must receive all quads |
| 3108 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3109 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3110 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3111 | |
| 3112 | // Must receive 2 render passes. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3113 | ASSERT_EQ(2U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3114 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3115 | EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); |
| 3116 | EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3117 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3118 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3119 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | // Change opacity and draw. Verify we used cached texture. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3123 | layerS1Ptr->SetOpacity(0.2f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3124 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3125 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3126 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3127 | |
| 3128 | // One render pass must be gone due to cached texture. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3129 | ASSERT_EQ(1U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3130 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3131 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3132 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3133 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3134 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3135 | } |
| 3136 | } |
| 3137 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 3138 | TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionPartialSwap) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3139 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3140 | LayerTreeSettings settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3141 | settings.minimumOcclusionTrackingSize = gfx::Size(); |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 3142 | settings.partialSwapEnabled = true; |
[email protected] | 09dc0d4b | 2013-02-13 06:17:20 | [diff] [blame] | 3143 | settings.cacheRenderPassContents = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3144 | scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3145 | |
| 3146 | // Layers are structure as follows: |
| 3147 | // |
| 3148 | // R +-- S1 +- L10 (owning) |
| 3149 | // | +- L11 |
| 3150 | // | +- L12 |
| 3151 | // | |
| 3152 | // +-- S2 +- L20 (owning) |
| 3153 | // +- L21 |
| 3154 | // |
| 3155 | // Occlusion: |
| 3156 | // L12 occludes L11 (internal) |
| 3157 | // L20 occludes L10 (external) |
| 3158 | // L21 occludes L20 (internal) |
| 3159 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3160 | LayerImpl* rootPtr; |
| 3161 | LayerImpl* layerS1Ptr; |
| 3162 | LayerImpl* layerS2Ptr; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3163 | |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 3164 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3165 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3166 | gfx::Size rootSize(1000, 1000); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3167 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3168 | myHostImpl->InitializeRenderer(outputSurface.Pass()); |
| 3169 | myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3170 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3171 | scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3172 | rootPtr = root.get(); |
| 3173 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3174 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 3175 | root->SetPosition(gfx::PointF(0, 0)); |
| 3176 | root->SetBounds(rootSize); |
| 3177 | root->SetContentBounds(rootSize); |
| 3178 | root->SetDrawsContent(true); |
| 3179 | root->SetMasksToBounds(true); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3180 | myHostImpl->active_tree()->SetRootLayer(root.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3181 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3182 | addDrawingLayerTo(rootPtr, 2, gfx::Rect(300, 300, 300, 300), &layerS1Ptr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3183 | layerS1Ptr->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3184 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3185 | addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(10, 10, 10, 10), 0); // L11 |
| 3186 | addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12 |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3187 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3188 | addDrawingLayerTo(rootPtr, 5, gfx::Rect(550, 250, 300, 400), &layerS2Ptr); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3189 | layerS2Ptr->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3190 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3191 | addDrawingLayerTo(layerS2Ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21 |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3192 | |
| 3193 | // Initial draw - must receive all quads |
| 3194 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3195 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3196 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3197 | |
| 3198 | // Must receive 3 render passes. |
| 3199 | // For Root, there are 2 quads; for S1, there are 2 quads (one is occluded); for S2, there is 2 quads. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3200 | ASSERT_EQ(3U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3201 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3202 | EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); |
| 3203 | EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); |
| 3204 | EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3205 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3206 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3207 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | // "Unocclude" surface S1 and repeat draw. |
| 3211 | // Must remove S2's render pass since it's cached; |
| 3212 | // Must keep S1 quads because texture contained external occlusion. |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 3213 | gfx::Transform transform = layerS2Ptr->transform(); |
| 3214 | transform.Translate(150, 150); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3215 | layerS2Ptr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3216 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3217 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3218 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3219 | |
| 3220 | // Must receive 2 render passes. |
| 3221 | // For Root, there are 2 quads. |
| 3222 | // For S1, there are 2 quads. |
| 3223 | // For S2, there is no render pass |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3224 | ASSERT_EQ(2U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3225 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3226 | EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); |
| 3227 | EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3228 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3229 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3230 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | // "Re-occlude" surface S1 and repeat draw. |
| 3234 | // Must remove S1's render pass since it is now available in full. |
| 3235 | // S2 has no change so must also be removed. |
| 3236 | transform = layerS2Ptr->transform(); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 3237 | transform.Translate(-15, -15); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3238 | layerS2Ptr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3239 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3240 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3241 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3242 | |
| 3243 | // Root render pass only. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3244 | ASSERT_EQ(1U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3245 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3246 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3247 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3248 | } |
| 3249 | } |
| 3250 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 3251 | TEST_F(LayerTreeHostImplTest, textureCachingWithScissor) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3252 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3253 | LayerTreeSettings settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3254 | settings.minimumOcclusionTrackingSize = gfx::Size(); |
[email protected] | 09dc0d4b | 2013-02-13 06:17:20 | [diff] [blame] | 3255 | settings.cacheRenderPassContents = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3256 | scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3257 | |
| 3258 | /* |
| 3259 | Layers are created as follows: |
| 3260 | |
| 3261 | +--------------------+ |
| 3262 | | 1 | |
| 3263 | | +-----------+ | |
| 3264 | | | 2 | | |
| 3265 | | | +-------------------+ |
| 3266 | | | | 3 | |
| 3267 | | | +-------------------+ |
| 3268 | | | | | |
| 3269 | | +-----------+ | |
| 3270 | | | |
| 3271 | | | |
| 3272 | +--------------------+ |
| 3273 | |
| 3274 | Layers 1, 2 have render surfaces |
| 3275 | */ |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3276 | scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1); |
| 3277 | scoped_ptr<TiledLayerImpl> child = TiledLayerImpl::Create(myHostImpl->active_tree(), 2); |
| 3278 | scoped_ptr<LayerImpl> grandChild = LayerImpl::Create(myHostImpl->active_tree(), 3); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3279 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3280 | gfx::Rect rootRect(0, 0, 100, 100); |
| 3281 | gfx::Rect childRect(10, 10, 50, 50); |
| 3282 | gfx::Rect grandChildRect(5, 5, 150, 150); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3283 | |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 3284 | scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface>(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3285 | myHostImpl->InitializeRenderer(outputSurface.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3286 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3287 | root->SetAnchorPoint(gfx::PointF(0, 0)); |
| 3288 | root->SetPosition(gfx::PointF(rootRect.x(), rootRect.y())); |
| 3289 | root->SetBounds(gfx::Size(rootRect.width(), rootRect.height())); |
| 3290 | root->SetContentBounds(root->bounds()); |
| 3291 | root->SetDrawsContent(true); |
| 3292 | root->SetMasksToBounds(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3293 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3294 | child->SetAnchorPoint(gfx::PointF(0, 0)); |
| 3295 | child->SetPosition(gfx::PointF(childRect.x(), childRect.y())); |
| 3296 | child->SetOpacity(0.5); |
| 3297 | child->SetBounds(gfx::Size(childRect.width(), childRect.height())); |
| 3298 | child->SetContentBounds(child->bounds()); |
| 3299 | child->SetDrawsContent(true); |
[email protected] | fa4b57f | 2013-03-17 21:39:09 | [diff] [blame] | 3300 | child->set_skips_draw(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3301 | |
| 3302 | // child layer has 10x10 tiles. |
[email protected] | 32eee89 | 2013-03-18 06:41:13 | [diff] [blame] | 3303 | scoped_ptr<LayerTilingData> tiler = LayerTilingData::Create(gfx::Size(10, 10), LayerTilingData::HAS_BORDER_TEXELS); |
| 3304 | tiler->SetBounds(child->content_bounds()); |
[email protected] | fa4b57f | 2013-03-17 21:39:09 | [diff] [blame] | 3305 | child->SetTilingData(*tiler.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3306 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3307 | grandChild->SetAnchorPoint(gfx::PointF(0, 0)); |
| 3308 | grandChild->SetPosition(gfx::Point(grandChildRect.x(), grandChildRect.y())); |
| 3309 | grandChild->SetBounds(gfx::Size(grandChildRect.width(), grandChildRect.height())); |
| 3310 | grandChild->SetContentBounds(grandChild->bounds()); |
| 3311 | grandChild->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3312 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3313 | TiledLayerImpl* childPtr = child.get(); |
| 3314 | RenderPass::Id childPassId(childPtr->id(), 0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3315 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3316 | child->AddChild(grandChild.Pass()); |
| 3317 | root->AddChild(child.PassAs<LayerImpl>()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3318 | myHostImpl->active_tree()->SetRootLayer(root.Pass()); |
| 3319 | myHostImpl->SetViewportSize(rootRect.size(), rootRect.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3320 | |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3321 | EXPECT_FALSE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(childPassId)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3322 | |
| 3323 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3324 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3325 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3326 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3327 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | // We should have cached textures for surface 2. |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3331 | EXPECT_TRUE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(childPassId)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3332 | |
| 3333 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3334 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3335 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3336 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3337 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | // We should still have cached textures for surface 2 after drawing with no damage. |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3341 | EXPECT_TRUE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(childPassId)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3342 | |
| 3343 | // Damage a single tile of surface 2. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3344 | childPtr->set_update_rect(gfx::Rect(10, 10, 10, 10)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3345 | |
| 3346 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3347 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3348 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3349 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3350 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | // We should have a cached texture for surface 2 again even though it was damaged. |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3354 | EXPECT_TRUE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(childPassId)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3355 | } |
| 3356 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 3357 | TEST_F(LayerTreeHostImplTest, surfaceTextureCaching) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3358 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3359 | LayerTreeSettings settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3360 | settings.minimumOcclusionTrackingSize = gfx::Size(); |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 3361 | settings.partialSwapEnabled = true; |
[email protected] | 09dc0d4b | 2013-02-13 06:17:20 | [diff] [blame] | 3362 | settings.cacheRenderPassContents = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3363 | scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3364 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3365 | LayerImpl* rootPtr; |
| 3366 | LayerImpl* intermediateLayerPtr; |
| 3367 | LayerImpl* surfaceLayerPtr; |
| 3368 | LayerImpl* childPtr; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3369 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3370 | setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr, surfaceLayerPtr, childPtr, gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3371 | |
| 3372 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3373 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3374 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3375 | |
| 3376 | // Must receive two render passes, each with one quad |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3377 | ASSERT_EQ(2U, frame.render_passes.size()); |
| 3378 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3379 | EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3380 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3381 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->material); |
| 3382 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); |
| 3383 | RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id]; |
[email protected] | 2006204 | 2012-12-21 22:16:36 | [diff] [blame] | 3384 | ASSERT_TRUE(targetPass); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3385 | EXPECT_FALSE(targetPass->damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3386 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3387 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3388 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | // Draw without any change |
| 3392 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3393 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3394 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3395 | |
| 3396 | // Must receive one render pass, as the other one should be culled |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3397 | ASSERT_EQ(1U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3398 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3399 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3400 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 3401 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
| 3402 | EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == frame.render_passes_by_id.end()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3403 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3404 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3405 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | // Change opacity and draw |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3409 | surfaceLayerPtr->SetOpacity(0.6f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3410 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3411 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3412 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3413 | |
| 3414 | // Must receive one render pass, as the other one should be culled |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3415 | ASSERT_EQ(1U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3416 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3417 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3418 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 3419 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
| 3420 | EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == frame.render_passes_by_id.end()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3421 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3422 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3423 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | // Change less benign property and draw - should have contents changed flag |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3427 | surfaceLayerPtr->SetStackingOrderChanged(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3428 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3429 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3430 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3431 | |
| 3432 | // Must receive two render passes, each with one quad |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3433 | ASSERT_EQ(2U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3434 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3435 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3436 | EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.render_passes[0]->quad_list[0]->material); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3437 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3438 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->material); |
| 3439 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); |
| 3440 | RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id]; |
[email protected] | 2006204 | 2012-12-21 22:16:36 | [diff] [blame] | 3441 | ASSERT_TRUE(targetPass); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3442 | EXPECT_FALSE(targetPass->damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3443 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3444 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3445 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3446 | } |
| 3447 | |
| 3448 | // Change opacity again, and evict the cached surface texture. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3449 | surfaceLayerPtr->SetOpacity(0.5f); |
[email protected] | faa48f3 | 2013-03-13 11:10:47 | [diff] [blame] | 3450 | static_cast<GLRendererWithReleaseTextures*>(myHostImpl->renderer())->ReleaseRenderPassTextures(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3451 | |
| 3452 | // Change opacity and draw |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3453 | surfaceLayerPtr->SetOpacity(0.6f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3454 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3455 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3456 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3457 | |
| 3458 | // Must receive two render passes |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3459 | ASSERT_EQ(2U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3460 | |
| 3461 | // Even though not enough properties changed, the entire thing must be |
| 3462 | // redrawn as we don't have cached textures |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3463 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3464 | EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3465 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3466 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->material); |
| 3467 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); |
| 3468 | RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id]; |
[email protected] | 2006204 | 2012-12-21 22:16:36 | [diff] [blame] | 3469 | ASSERT_TRUE(targetPass); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3470 | EXPECT_TRUE(targetPass->damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3471 | |
| 3472 | // Was our surface evicted? |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3473 | EXPECT_FALSE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(targetPass->id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3474 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3475 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3476 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | // Draw without any change, to make sure the state is clear |
| 3480 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3481 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3482 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3483 | |
| 3484 | // Must receive one render pass, as the other one should be culled |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3485 | ASSERT_EQ(1U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3486 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3487 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3488 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 3489 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
| 3490 | EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == frame.render_passes_by_id.end()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3491 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3492 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3493 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3494 | } |
| 3495 | |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 3496 | // Change location of the intermediate layer |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 3497 | gfx::Transform transform = intermediateLayerPtr->transform(); |
| 3498 | transform.matrix().setDouble(0, 3, 1.0001); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3499 | intermediateLayerPtr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3500 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3501 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3502 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3503 | |
| 3504 | // Must receive one render pass, as the other one should be culled. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3505 | ASSERT_EQ(1U, frame.render_passes.size()); |
| 3506 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3507 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3508 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 3509 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
| 3510 | EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == frame.render_passes_by_id.end()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3511 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3512 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3513 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 3517 | TEST_F(LayerTreeHostImplTest, surfaceTextureCachingNoPartialSwap) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3518 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3519 | LayerTreeSettings settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3520 | settings.minimumOcclusionTrackingSize = gfx::Size(); |
[email protected] | 09dc0d4b | 2013-02-13 06:17:20 | [diff] [blame] | 3521 | settings.cacheRenderPassContents = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3522 | scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3523 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3524 | LayerImpl* rootPtr; |
| 3525 | LayerImpl* intermediateLayerPtr; |
| 3526 | LayerImpl* surfaceLayerPtr; |
| 3527 | LayerImpl* childPtr; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3528 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3529 | setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr, surfaceLayerPtr, childPtr, gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3530 | |
| 3531 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3532 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3533 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3534 | |
| 3535 | // Must receive two render passes, each with one quad |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3536 | ASSERT_EQ(2U, frame.render_passes.size()); |
| 3537 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3538 | EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3539 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3540 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->material); |
| 3541 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); |
| 3542 | RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id]; |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3543 | EXPECT_FALSE(targetPass->damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3544 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3545 | EXPECT_FALSE(frame.render_passes[0]->damage_rect.IsEmpty()); |
| 3546 | EXPECT_FALSE(frame.render_passes[1]->damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3547 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3548 | EXPECT_FALSE(frame.render_passes[0]->has_occlusion_from_outside_target_surface); |
| 3549 | EXPECT_FALSE(frame.render_passes[1]->has_occlusion_from_outside_target_surface); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3550 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3551 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3552 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | // Draw without any change |
| 3556 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3557 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3558 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3559 | |
| 3560 | // Even though there was no change, we set the damage to entire viewport. |
| 3561 | // One of the passes should be culled as a result, since contents didn't change |
| 3562 | // and we have cached texture. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3563 | ASSERT_EQ(1U, frame.render_passes.size()); |
| 3564 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3565 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3566 | EXPECT_TRUE(frame.render_passes[0]->damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3567 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3568 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3569 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | // Change opacity and draw |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3573 | surfaceLayerPtr->SetOpacity(0.6f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3574 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3575 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3576 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3577 | |
| 3578 | // Must receive one render pass, as the other one should be culled |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3579 | ASSERT_EQ(1U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3580 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3581 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3582 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 3583 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
| 3584 | EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == frame.render_passes_by_id.end()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3585 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3586 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3587 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | // Change less benign property and draw - should have contents changed flag |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3591 | surfaceLayerPtr->SetStackingOrderChanged(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3592 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3593 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3594 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3595 | |
| 3596 | // Must receive two render passes, each with one quad |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3597 | ASSERT_EQ(2U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3598 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3599 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3600 | EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.render_passes[0]->quad_list[0]->material); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3601 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3602 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->material); |
| 3603 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); |
| 3604 | RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id]; |
[email protected] | 2006204 | 2012-12-21 22:16:36 | [diff] [blame] | 3605 | ASSERT_TRUE(targetPass); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3606 | EXPECT_FALSE(targetPass->damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3607 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3608 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3609 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | // Change opacity again, and evict the cached surface texture. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3613 | surfaceLayerPtr->SetOpacity(0.5f); |
[email protected] | faa48f3 | 2013-03-13 11:10:47 | [diff] [blame] | 3614 | static_cast<GLRendererWithReleaseTextures*>(myHostImpl->renderer())->ReleaseRenderPassTextures(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3615 | |
| 3616 | // Change opacity and draw |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3617 | surfaceLayerPtr->SetOpacity(0.6f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3618 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3619 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3620 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3621 | |
| 3622 | // Must receive two render passes |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3623 | ASSERT_EQ(2U, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3624 | |
| 3625 | // Even though not enough properties changed, the entire thing must be |
| 3626 | // redrawn as we don't have cached textures |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3627 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 3628 | EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3629 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3630 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->material); |
| 3631 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); |
| 3632 | RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id]; |
[email protected] | 2006204 | 2012-12-21 22:16:36 | [diff] [blame] | 3633 | ASSERT_TRUE(targetPass); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3634 | EXPECT_TRUE(targetPass->damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3635 | |
| 3636 | // Was our surface evicted? |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3637 | EXPECT_FALSE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(targetPass->id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3638 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3639 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3640 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | // Draw without any change, to make sure the state is clear |
| 3644 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3645 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3646 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3647 | |
| 3648 | // Even though there was no change, we set the damage to entire viewport. |
| 3649 | // One of the passes should be culled as a result, since contents didn't change |
| 3650 | // and we have cached texture. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3651 | ASSERT_EQ(1U, frame.render_passes.size()); |
| 3652 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3653 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3654 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3655 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3656 | } |
| 3657 | |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 3658 | // Change location of the intermediate layer |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 3659 | gfx::Transform transform = intermediateLayerPtr->transform(); |
| 3660 | transform.matrix().setDouble(0, 3, 1.0001); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3661 | intermediateLayerPtr->SetTransform(transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3662 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3663 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3664 | EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3665 | |
| 3666 | // Must receive one render pass, as the other one should be culled. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3667 | ASSERT_EQ(1U, frame.render_passes.size()); |
| 3668 | EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3669 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3670 | EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 3671 | const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
| 3672 | EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == frame.render_passes_by_id.end()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3673 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 3674 | myHostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3675 | myHostImpl->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3676 | } |
| 3677 | } |
| 3678 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 3679 | TEST_F(LayerTreeHostImplTest, releaseContentsTextureShouldTriggerCommit) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3680 | { |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 3681 | setReduceMemoryResult(false); |
| 3682 | |
| 3683 | // Even if changing the memory limit didn't result in anything being |
| 3684 | // evicted, we need to re-commit because the new value may result in us |
| 3685 | // drawing something different than before. |
| 3686 | setReduceMemoryResult(false); |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3687 | m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3688 | m_hostImpl->memory_allocation_limit_bytes() - 1)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3689 | EXPECT_TRUE(m_didRequestCommit); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 3690 | m_didRequestCommit = false; |
| 3691 | |
| 3692 | // Especially if changing the memory limit caused evictions, we need |
| 3693 | // to re-commit. |
| 3694 | setReduceMemoryResult(true); |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3695 | m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3696 | m_hostImpl->memory_allocation_limit_bytes() - 1)); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 3697 | EXPECT_TRUE(m_didRequestCommit); |
| 3698 | m_didRequestCommit = false; |
| 3699 | |
| 3700 | // But if we set it to the same value that it was before, we shouldn't |
| 3701 | // re-commit. |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3702 | m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3703 | m_hostImpl->memory_allocation_limit_bytes())); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 3704 | EXPECT_FALSE(m_didRequestCommit); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3705 | } |
| 3706 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3707 | struct RenderPassRemovalTestData : public LayerTreeHostImpl::FrameData { |
[email protected] | 1044a25 | 2012-10-23 18:51:32 | [diff] [blame] | 3708 | ScopedPtrHashMap<RenderPass::Id, TestRenderPass> renderPassCache; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3709 | scoped_ptr<SharedQuadState> sharedQuadState; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3710 | }; |
| 3711 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3712 | class TestRenderer : public GLRenderer, public RendererClient { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3713 | public: |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 3714 | static scoped_ptr<TestRenderer> Create(ResourceProvider* resourceProvider, OutputSurface* outputSurface, Proxy* proxy) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3715 | { |
[email protected] | bf189f6 | 2012-12-18 03:42:11 | [diff] [blame] | 3716 | scoped_ptr<TestRenderer> renderer(new TestRenderer(resourceProvider, outputSurface, proxy)); |
[email protected] | faa48f3 | 2013-03-13 11:10:47 | [diff] [blame] | 3717 | if (!renderer->Initialize()) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3718 | return scoped_ptr<TestRenderer>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3719 | |
[email protected] | a7aa556 | 2012-10-17 14:12:44 | [diff] [blame] | 3720 | return renderer.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | void clearCachedTextures() { m_textures.clear(); } |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3724 | void setHaveCachedResourcesForRenderPassId(RenderPass::Id id) { m_textures.insert(id); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3725 | |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3726 | virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id) const OVERRIDE { return m_textures.count(id); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3727 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3728 | // RendererClient implementation. |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 3729 | virtual gfx::Size DeviceViewportSize() const OVERRIDE { return m_viewportSize; } |
| 3730 | virtual const LayerTreeSettings& Settings() const OVERRIDE { return m_settings; } |
| 3731 | virtual void DidLoseOutputSurface() OVERRIDE { } |
| 3732 | virtual void OnSwapBuffersComplete() OVERRIDE { } |
| 3733 | virtual void SetFullRootLayerDamage() OVERRIDE { } |
| 3734 | virtual void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE { } |
| 3735 | virtual void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE { } |
| 3736 | virtual bool HasImplThread() const OVERRIDE { return false; } |
| 3737 | virtual bool ShouldClearRootRenderPass() const OVERRIDE { return true; } |
| 3738 | virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const |
[email protected] | bf189f6 | 2012-12-18 03:42:11 | [diff] [blame] | 3739 | OVERRIDE { return CompositorFrameMetadata(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3740 | |
| 3741 | protected: |
[email protected] | bf189f6 | 2012-12-18 03:42:11 | [diff] [blame] | 3742 | TestRenderer(ResourceProvider* resourceProvider, OutputSurface* outputSurface, Proxy* proxy) : GLRenderer(this, outputSurface, resourceProvider) { } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3743 | |
| 3744 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3745 | LayerTreeSettings m_settings; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3746 | gfx::Size m_viewportSize; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3747 | base::hash_set<RenderPass::Id> m_textures; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3748 | }; |
| 3749 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3750 | static void configureRenderPassTestData(const char* testScript, RenderPassRemovalTestData& testData, TestRenderer* renderer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3751 | { |
| 3752 | renderer->clearCachedTextures(); |
| 3753 | |
| 3754 | // One shared state for all quads - we don't need the correct details |
[email protected] | cb7af74 | 2012-11-21 04:02:24 | [diff] [blame] | 3755 | testData.sharedQuadState = SharedQuadState::Create(); |
[email protected] | f902bf9 | 2013-03-04 18:33:27 | [diff] [blame] | 3756 | testData.sharedQuadState->SetAll(gfx::Transform(), gfx::Size(), gfx::Rect(), gfx::Rect(), false, 1.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3757 | |
| 3758 | const char* currentChar = testScript; |
| 3759 | |
| 3760 | // Pre-create root pass |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3761 | RenderPass::Id rootRenderPassId = RenderPass::Id(testScript[0], testScript[1]); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3762 | scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 3763 | pass->SetNew(rootRenderPassId, gfx::Rect(), gfx::Rect(), gfx::Transform()); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3764 | testData.renderPassCache.add(rootRenderPassId, pass.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3765 | while (*currentChar) { |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3766 | int layerId = *currentChar; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3767 | currentChar++; |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3768 | ASSERT_TRUE(currentChar); |
| 3769 | int index = *currentChar; |
| 3770 | currentChar++; |
| 3771 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3772 | RenderPass::Id renderPassId = RenderPass::Id(layerId, index); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3773 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3774 | bool isReplica = false; |
[email protected] | 87cea537 | 2012-09-26 18:59:56 | [diff] [blame] | 3775 | if (!testData.renderPassCache.contains(renderPassId)) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3776 | isReplica = true; |
| 3777 | |
[email protected] | 1044a25 | 2012-10-23 18:51:32 | [diff] [blame] | 3778 | scoped_ptr<TestRenderPass> renderPass = testData.renderPassCache.take(renderPassId); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3779 | |
| 3780 | // Cycle through quad data and create all quads |
| 3781 | while (*currentChar && *currentChar != '\n') { |
| 3782 | if (*currentChar == 's') { |
| 3783 | // Solid color draw quad |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 3784 | scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); |
| 3785 | quad->SetNew(testData.sharedQuadState.get(), gfx::Rect(0, 0, 10, 10), SK_ColorWHITE); |
[email protected] | 4c91aec | 2012-12-15 20:17:18 | [diff] [blame] | 3786 | |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3787 | renderPass->AppendQuad(quad.PassAs<DrawQuad>()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3788 | currentChar++; |
| 3789 | } else if ((*currentChar >= 'A') && (*currentChar <= 'Z')) { |
| 3790 | // RenderPass draw quad |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3791 | int layerId = *currentChar; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3792 | currentChar++; |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3793 | ASSERT_TRUE(currentChar); |
| 3794 | int index = *currentChar; |
| 3795 | currentChar++; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3796 | RenderPass::Id newRenderPassId = RenderPass::Id(layerId, index); |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3797 | ASSERT_NE(rootRenderPassId, newRenderPassId); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3798 | bool hasTexture = false; |
| 3799 | bool contentsChanged = true; |
[email protected] | 4c91aec | 2012-12-15 20:17:18 | [diff] [blame] | 3800 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3801 | if (*currentChar == '[') { |
| 3802 | currentChar++; |
| 3803 | while (*currentChar && *currentChar != ']') { |
| 3804 | switch (*currentChar) { |
| 3805 | case 'c': |
| 3806 | contentsChanged = false; |
| 3807 | break; |
| 3808 | case 't': |
| 3809 | hasTexture = true; |
| 3810 | break; |
| 3811 | } |
| 3812 | currentChar++; |
| 3813 | } |
| 3814 | if (*currentChar == ']') |
| 3815 | currentChar++; |
| 3816 | } |
| 3817 | |
| 3818 | if (testData.renderPassCache.find(newRenderPassId) == testData.renderPassCache.end()) { |
| 3819 | if (hasTexture) |
| 3820 | renderer->setHaveCachedResourcesForRenderPassId(newRenderPassId); |
| 3821 | |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3822 | scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 3823 | pass->SetNew(newRenderPassId, gfx::Rect(), gfx::Rect(), gfx::Transform()); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3824 | testData.renderPassCache.add(newRenderPassId, pass.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3825 | } |
| 3826 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 3827 | gfx::Rect quadRect = gfx::Rect(0, 0, 1, 1); |
| 3828 | gfx::Rect contentsChangedRect = contentsChanged ? quadRect : gfx::Rect(); |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 3829 | scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create(); |
[email protected] | 2006204 | 2012-12-21 22:16:36 | [diff] [blame] | 3830 | quad->SetNew(testData.sharedQuadState.get(), quadRect, newRenderPassId, isReplica, 1, contentsChangedRect, gfx::RectF(0, 0, 1, 1), WebKit::WebFilterOperations(), skia::RefPtr<SkImageFilter>(), WebKit::WebFilterOperations()); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3831 | renderPass->AppendQuad(quad.PassAs<DrawQuad>()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3832 | } |
| 3833 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3834 | testData.render_passes_by_id[renderPassId] = renderPass.get(); |
| 3835 | testData.render_passes.insert(testData.render_passes.begin(), renderPass.PassAs<RenderPass>()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3836 | if (*currentChar) |
| 3837 | currentChar++; |
| 3838 | } |
| 3839 | } |
| 3840 | |
| 3841 | void dumpRenderPassTestData(const RenderPassRemovalTestData& testData, char* buffer) |
| 3842 | { |
| 3843 | char* pos = buffer; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 3844 | for (RenderPassList::const_reverse_iterator it = testData.render_passes.rbegin(); it != testData.render_passes.rend(); ++it) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3845 | const RenderPass* currentPass = *it; |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3846 | *pos = currentPass->id.layer_id; |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3847 | pos++; |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3848 | *pos = currentPass->id.index; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3849 | pos++; |
| 3850 | |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3851 | QuadList::const_iterator quadListIterator = currentPass->quad_list.begin(); |
| 3852 | while (quadListIterator != currentPass->quad_list.end()) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3853 | DrawQuad* currentQuad = *quadListIterator; |
[email protected] | 1bc93f6 | 2012-11-17 19:29:50 | [diff] [blame] | 3854 | switch (currentQuad->material) { |
[email protected] | e48727e | 2012-11-16 22:10:02 | [diff] [blame] | 3855 | case DrawQuad::SOLID_COLOR: |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3856 | *pos = 's'; |
| 3857 | pos++; |
| 3858 | break; |
[email protected] | e48727e | 2012-11-16 22:10:02 | [diff] [blame] | 3859 | case DrawQuad::RENDER_PASS: |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 3860 | *pos = RenderPassDrawQuad::MaterialCast(currentQuad)->render_pass_id.layer_id; |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3861 | pos++; |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 3862 | *pos = RenderPassDrawQuad::MaterialCast(currentQuad)->render_pass_id.index; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3863 | pos++; |
| 3864 | break; |
| 3865 | default: |
| 3866 | *pos = 'x'; |
| 3867 | pos++; |
| 3868 | break; |
| 3869 | } |
[email protected] | 4c91aec | 2012-12-15 20:17:18 | [diff] [blame] | 3870 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3871 | quadListIterator++; |
| 3872 | } |
| 3873 | *pos = '\n'; |
| 3874 | pos++; |
| 3875 | } |
| 3876 | *pos = '\0'; |
| 3877 | } |
| 3878 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3879 | // Each RenderPassList is represented by a string which describes the configuration. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3880 | // The syntax of the string is as follows: |
| 3881 | // |
| 3882 | // RsssssX[c]ssYsssZ[t]ssW[ct] |
| 3883 | // Identifies the render pass---------------------------^ ^^^ ^ ^ ^ ^ ^ |
| 3884 | // These are solid color quads-----------------------------+ | | | | | |
| 3885 | // Identifies RenderPassDrawQuad's RenderPass-----------------+ | | | | |
| 3886 | // This quad's contents didn't change---------------------------+ | | | |
| 3887 | // This quad's contents changed and it has no texture---------------+ | | |
| 3888 | // This quad has texture but its contents changed-------------------------+ | |
| 3889 | // This quad's contents didn't change and it has texture - will be removed------+ |
| 3890 | // |
| 3891 | // Expected results have exactly the same syntax, except they do not use square brackets, |
| 3892 | // since we only check the structure, not attributes. |
| 3893 | // |
| 3894 | // Test case configuration consists of initialization script and expected results, |
| 3895 | // all in the same format. |
| 3896 | struct TestCase { |
| 3897 | const char* name; |
| 3898 | const char* initScript; |
| 3899 | const char* expectedResult; |
| 3900 | }; |
| 3901 | |
| 3902 | TestCase removeRenderPassesCases[] = |
| 3903 | { |
| 3904 | { |
| 3905 | "Single root pass", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3906 | "R0ssss\n", |
| 3907 | "R0ssss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3908 | }, { |
| 3909 | "Single pass - no quads", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3910 | "R0\n", |
| 3911 | "R0\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3912 | }, { |
| 3913 | "Two passes, no removal", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3914 | "R0ssssA0sss\n" |
| 3915 | "A0ssss\n", |
| 3916 | "R0ssssA0sss\n" |
| 3917 | "A0ssss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3918 | }, { |
| 3919 | "Two passes, remove last", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3920 | "R0ssssA0[ct]sss\n" |
| 3921 | "A0ssss\n", |
| 3922 | "R0ssssA0sss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3923 | }, { |
| 3924 | "Have texture but contents changed - leave pass", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3925 | "R0ssssA0[t]sss\n" |
| 3926 | "A0ssss\n", |
| 3927 | "R0ssssA0sss\n" |
| 3928 | "A0ssss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3929 | }, { |
| 3930 | "Contents didn't change but no texture - leave pass", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3931 | "R0ssssA0[c]sss\n" |
| 3932 | "A0ssss\n", |
| 3933 | "R0ssssA0sss\n" |
| 3934 | "A0ssss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3935 | }, { |
| 3936 | "Replica: two quads reference the same pass; remove", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3937 | "R0ssssA0[ct]A0[ct]sss\n" |
| 3938 | "A0ssss\n", |
| 3939 | "R0ssssA0A0sss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3940 | }, { |
| 3941 | "Replica: two quads reference the same pass; leave", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3942 | "R0ssssA0[c]A0[c]sss\n" |
| 3943 | "A0ssss\n", |
| 3944 | "R0ssssA0A0sss\n" |
| 3945 | "A0ssss\n", |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3946 | }, { |
| 3947 | "Many passes, remove all", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3948 | "R0ssssA0[ct]sss\n" |
| 3949 | "A0sssB0[ct]C0[ct]s\n" |
| 3950 | "B0sssD0[ct]ssE0[ct]F0[ct]\n" |
| 3951 | "E0ssssss\n" |
| 3952 | "C0G0[ct]\n" |
| 3953 | "D0sssssss\n" |
| 3954 | "F0sssssss\n" |
| 3955 | "G0sss\n", |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3956 | |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3957 | "R0ssssA0sss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3958 | }, { |
| 3959 | "Deep recursion, remove all", |
| 3960 | |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3961 | "R0sssssA0[ct]ssss\n" |
| 3962 | "A0ssssB0sss\n" |
| 3963 | "B0C0\n" |
| 3964 | "C0D0\n" |
| 3965 | "D0E0\n" |
| 3966 | "E0F0\n" |
| 3967 | "F0G0\n" |
| 3968 | "G0H0\n" |
| 3969 | "H0sssI0sss\n" |
| 3970 | "I0J0\n" |
| 3971 | "J0ssss\n", |
[email protected] | 4c91aec | 2012-12-15 20:17:18 | [diff] [blame] | 3972 | |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3973 | "R0sssssA0ssss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3974 | }, { |
| 3975 | "Wide recursion, remove all", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3976 | "R0A0[ct]B0[ct]C0[ct]D0[ct]E0[ct]F0[ct]G0[ct]H0[ct]I0[ct]J0[ct]\n" |
| 3977 | "A0s\n" |
| 3978 | "B0s\n" |
| 3979 | "C0ssss\n" |
| 3980 | "D0ssss\n" |
| 3981 | "E0s\n" |
| 3982 | "F0\n" |
| 3983 | "G0s\n" |
| 3984 | "H0s\n" |
| 3985 | "I0s\n" |
| 3986 | "J0ssss\n", |
[email protected] | 4c91aec | 2012-12-15 20:17:18 | [diff] [blame] | 3987 | |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3988 | "R0A0B0C0D0E0F0G0H0I0J0\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3989 | }, { |
| 3990 | "Remove passes regardless of cache state", |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 3991 | "R0ssssA0[ct]sss\n" |
| 3992 | "A0sssB0C0s\n" |
| 3993 | "B0sssD0[c]ssE0[t]F0\n" |
| 3994 | "E0ssssss\n" |
| 3995 | "C0G0\n" |
| 3996 | "D0sssssss\n" |
| 3997 | "F0sssssss\n" |
| 3998 | "G0sss\n", |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3999 | |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 4000 | "R0ssssA0sss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4001 | }, { |
| 4002 | "Leave some passes, remove others", |
| 4003 | |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 4004 | "R0ssssA0[c]sss\n" |
| 4005 | "A0sssB0[t]C0[ct]s\n" |
| 4006 | "B0sssD0[c]ss\n" |
| 4007 | "C0G0\n" |
| 4008 | "D0sssssss\n" |
| 4009 | "G0sss\n", |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4010 | |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 4011 | "R0ssssA0sss\n" |
| 4012 | "A0sssB0C0s\n" |
| 4013 | "B0sssD0ss\n" |
| 4014 | "D0sssssss\n" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4015 | }, { |
| 4016 | 0, 0, 0 |
| 4017 | } |
| 4018 | }; |
| 4019 | |
| 4020 | static void verifyRenderPassTestData(TestCase& testCase, RenderPassRemovalTestData& testData) |
| 4021 | { |
| 4022 | char actualResult[1024]; |
| 4023 | dumpRenderPassTestData(testData, actualResult); |
| 4024 | EXPECT_STREQ(testCase.expectedResult, actualResult) << "In test case: " << testCase.name; |
| 4025 | } |
| 4026 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 4027 | TEST_F(LayerTreeHostImplTest, testRemoveRenderPasses) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4028 | { |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 4029 | scoped_ptr<OutputSurface> outputSurface(createOutputSurface()); |
[email protected] | 79a1be5 | 2013-02-13 23:59:50 | [diff] [blame] | 4030 | ASSERT_TRUE(outputSurface->context3d()); |
[email protected] | f53da397 | 2013-03-07 08:38:41 | [diff] [blame] | 4031 | scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::Create(outputSurface.get())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4032 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4033 | scoped_ptr<TestRenderer> renderer(TestRenderer::Create(resourceProvider.get(), outputSurface.get(), &m_proxy)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4034 | |
| 4035 | int testCaseIndex = 0; |
| 4036 | while (removeRenderPassesCases[testCaseIndex].name) { |
| 4037 | RenderPassRemovalTestData testData; |
| 4038 | configureRenderPassTestData(removeRenderPassesCases[testCaseIndex].initScript, testData, renderer.get()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4039 | LayerTreeHostImpl::RemoveRenderPasses(LayerTreeHostImpl::CullRenderPassesWithCachedTextures(*renderer), &testData); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4040 | verifyRenderPassTestData(removeRenderPassesCases[testCaseIndex], testData); |
| 4041 | testCaseIndex++; |
| 4042 | } |
| 4043 | } |
| 4044 | |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4045 | class LayerTreeHostImplTestWithDelegatingRenderer : public LayerTreeHostImplTest { |
| 4046 | protected: |
[email protected] | 9f93027 | 2013-02-06 09:51:55 | [diff] [blame] | 4047 | virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4048 | { |
| 4049 | // Creates an output surface with a parent to use a delegating renderer. |
| 4050 | WebKit::WebGraphicsContext3D::Attributes attrs; |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 4051 | return FakeOutputSurface::CreateDelegating3d(TestWebGraphicsContext3D::Create(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | void drawFrameAndTestDamage(const gfx::RectF& expectedDamage) { |
| 4055 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4056 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
| 4057 | ASSERT_EQ(1u, frame.render_passes.size()); |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4058 | |
| 4059 | // Verify the damage rect for the root render pass. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4060 | const RenderPass* rootRenderPass = frame.render_passes.back(); |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4061 | EXPECT_RECT_EQ(expectedDamage, rootRenderPass->damage_rect); |
| 4062 | |
| 4063 | // Verify the root layer's quad is generated and not being culled. |
| 4064 | ASSERT_EQ(1u, rootRenderPass->quad_list.size()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4065 | gfx::Rect expectedVisibleRect(m_hostImpl->active_tree()->root_layer()->content_bounds()); |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4066 | EXPECT_RECT_EQ(expectedVisibleRect, rootRenderPass->quad_list[0]->visible_rect); |
| 4067 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 4068 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4069 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4070 | } |
| 4071 | }; |
| 4072 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 4073 | TEST_F(LayerTreeHostImplTestWithDelegatingRenderer, FrameIncludesDamageRect) |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4074 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4075 | scoped_ptr<SolidColorLayerImpl> root = SolidColorLayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4076 | root->SetAnchorPoint(gfx::PointF(0.f, 0.f)); |
| 4077 | root->SetPosition(gfx::PointF(0.f, 0.f)); |
| 4078 | root->SetBounds(gfx::Size(10, 10)); |
| 4079 | root->SetContentBounds(gfx::Size(10, 10)); |
| 4080 | root->SetDrawsContent(true); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4081 | m_hostImpl->active_tree()->SetRootLayer(root.PassAs<LayerImpl>()); |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 4082 | |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4083 | // Draw a frame. In the first frame, the entire viewport should be damaged. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4084 | gfx::Rect fullFrameDamage = gfx::Rect(m_hostImpl->device_viewport_size()); |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4085 | drawFrameAndTestDamage(fullFrameDamage); |
| 4086 | |
| 4087 | // The second frame should have no damage, but the quads should still be generated. |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 4088 | gfx::Rect noDamage = gfx::Rect(); |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 4089 | drawFrameAndTestDamage(noDamage); |
| 4090 | } |
| 4091 | |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4092 | class FakeMaskLayerImpl : public LayerImpl { |
| 4093 | public: |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4094 | static scoped_ptr<FakeMaskLayerImpl> Create(LayerTreeImpl* treeImpl, int id) |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4095 | { |
| 4096 | return make_scoped_ptr(new FakeMaskLayerImpl(treeImpl, id)); |
| 4097 | } |
| 4098 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4099 | virtual ResourceProvider::ResourceId ContentsResourceId() const OVERRIDE { return 0; } |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4100 | |
| 4101 | private: |
| 4102 | FakeMaskLayerImpl(LayerTreeImpl* treeImpl, int id) : LayerImpl(treeImpl, id) { } |
| 4103 | }; |
| 4104 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 4105 | TEST_F(LayerTreeHostImplTest, maskLayerWithScaling) |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4106 | { |
| 4107 | // Root |
| 4108 | // | |
| 4109 | // +-- Scaling Layer (adds a 2x scale) |
| 4110 | // | |
| 4111 | // +-- Content Layer |
| 4112 | // +--Mask |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4113 | scoped_ptr<LayerImpl> scopedRoot = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4114 | LayerImpl* root = scopedRoot.get(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4115 | m_hostImpl->active_tree()->SetRootLayer(scopedRoot.Pass()); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4116 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4117 | scoped_ptr<LayerImpl> scopedScalingLayer = LayerImpl::Create(m_hostImpl->active_tree(), 2); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4118 | LayerImpl* scalingLayer = scopedScalingLayer.get(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4119 | root->AddChild(scopedScalingLayer.Pass()); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4120 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4121 | scoped_ptr<LayerImpl> scopedContentLayer = LayerImpl::Create(m_hostImpl->active_tree(), 3); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4122 | LayerImpl* contentLayer = scopedContentLayer.get(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4123 | scalingLayer->AddChild(scopedContentLayer.Pass()); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4124 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4125 | scoped_ptr<FakeMaskLayerImpl> scopedMaskLayer = FakeMaskLayerImpl::Create(m_hostImpl->active_tree(), 4); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4126 | FakeMaskLayerImpl* maskLayer = scopedMaskLayer.get(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4127 | contentLayer->SetMaskLayer(scopedMaskLayer.PassAs<LayerImpl>()); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4128 | |
| 4129 | gfx::Size rootSize(100, 100); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4130 | root->SetBounds(rootSize); |
| 4131 | root->SetContentBounds(rootSize); |
| 4132 | root->SetPosition(gfx::PointF()); |
| 4133 | root->SetAnchorPoint(gfx::PointF()); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4134 | |
| 4135 | gfx::Size scalingLayerSize(50, 50); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4136 | scalingLayer->SetBounds(scalingLayerSize); |
| 4137 | scalingLayer->SetContentBounds(scalingLayerSize); |
| 4138 | scalingLayer->SetPosition(gfx::PointF()); |
| 4139 | scalingLayer->SetAnchorPoint(gfx::PointF()); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4140 | gfx::Transform scale; |
| 4141 | scale.Scale(2.0, 2.0); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4142 | scalingLayer->SetTransform(scale); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4143 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4144 | contentLayer->SetBounds(scalingLayerSize); |
| 4145 | contentLayer->SetContentBounds(scalingLayerSize); |
| 4146 | contentLayer->SetPosition(gfx::PointF()); |
| 4147 | contentLayer->SetAnchorPoint(gfx::PointF()); |
| 4148 | contentLayer->SetDrawsContent(true); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4149 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4150 | maskLayer->SetBounds(scalingLayerSize); |
| 4151 | maskLayer->SetContentBounds(scalingLayerSize); |
| 4152 | maskLayer->SetPosition(gfx::PointF()); |
| 4153 | maskLayer->SetAnchorPoint(gfx::PointF()); |
| 4154 | maskLayer->SetDrawsContent(true); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4155 | |
| 4156 | |
| 4157 | // Check that the tree scaling is correctly taken into account for the mask, |
| 4158 | // that should fully map onto the quad. |
| 4159 | float deviceScaleFactor = 1.f; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4160 | m_hostImpl->SetViewportSize(rootSize, rootSize); |
| 4161 | m_hostImpl->SetDeviceScaleFactor(deviceScaleFactor); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4162 | { |
| 4163 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4164 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4165 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4166 | ASSERT_EQ(1u, frame.render_passes.size()); |
| 4167 | ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
| 4168 | ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 4169 | const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4170 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToString()); |
| 4171 | EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mask_uv_rect.ToString()); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4172 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 4173 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4174 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | |
| 4178 | // Applying a DSF should change the render surface size, but won't affect |
| 4179 | // which part of the mask is used. |
| 4180 | deviceScaleFactor = 2.f; |
| 4181 | gfx::Size deviceViewport(gfx::ToFlooredSize(gfx::ScaleSize(rootSize, deviceScaleFactor))); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4182 | m_hostImpl->SetViewportSize(rootSize, deviceViewport); |
| 4183 | m_hostImpl->SetDeviceScaleFactor(deviceScaleFactor); |
| 4184 | m_hostImpl->active_tree()->set_needs_update_draw_properties(); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4185 | { |
| 4186 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4187 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4188 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4189 | ASSERT_EQ(1u, frame.render_passes.size()); |
| 4190 | ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
| 4191 | ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 4192 | const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4193 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), renderPassQuad->rect.ToString()); |
| 4194 | EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mask_uv_rect.ToString()); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4195 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 4196 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4197 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | |
| 4201 | // Applying an equivalent content scale on the content layer and the mask |
| 4202 | // should still result in the same part of the mask being used. |
| 4203 | gfx::Size contentsBounds(gfx::ToRoundedSize(gfx::ScaleSize(scalingLayerSize, deviceScaleFactor))); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4204 | contentLayer->SetContentBounds(contentsBounds); |
| 4205 | contentLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); |
| 4206 | maskLayer->SetContentBounds(contentsBounds); |
| 4207 | maskLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4208 | m_hostImpl->active_tree()->set_needs_update_draw_properties(); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4209 | { |
| 4210 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4211 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4212 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4213 | ASSERT_EQ(1u, frame.render_passes.size()); |
| 4214 | ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
| 4215 | ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 4216 | const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4217 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), renderPassQuad->rect.ToString()); |
| 4218 | EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mask_uv_rect.ToString()); |
| 4219 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 4220 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4221 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4222 | } |
| 4223 | } |
| 4224 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 4225 | TEST_F(LayerTreeHostImplTest, maskLayerWithDifferentBounds) |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4226 | { |
| 4227 | // The mask layer has bounds 100x100 but is attached to a layer with bounds 50x50. |
| 4228 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4229 | scoped_ptr<LayerImpl> scopedRoot = LayerImpl::Create(m_hostImpl->active_tree(), 1); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4230 | LayerImpl* root = scopedRoot.get(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4231 | m_hostImpl->active_tree()->SetRootLayer(scopedRoot.Pass()); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4232 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4233 | scoped_ptr<LayerImpl> scopedContentLayer = LayerImpl::Create(m_hostImpl->active_tree(), 3); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4234 | LayerImpl* contentLayer = scopedContentLayer.get(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4235 | root->AddChild(scopedContentLayer.Pass()); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4236 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4237 | scoped_ptr<FakeMaskLayerImpl> scopedMaskLayer = FakeMaskLayerImpl::Create(m_hostImpl->active_tree(), 4); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4238 | FakeMaskLayerImpl* maskLayer = scopedMaskLayer.get(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4239 | contentLayer->SetMaskLayer(scopedMaskLayer.PassAs<LayerImpl>()); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4240 | |
| 4241 | gfx::Size rootSize(100, 100); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4242 | root->SetBounds(rootSize); |
| 4243 | root->SetContentBounds(rootSize); |
| 4244 | root->SetPosition(gfx::PointF()); |
| 4245 | root->SetAnchorPoint(gfx::PointF()); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4246 | |
| 4247 | gfx::Size layerSize(50, 50); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4248 | contentLayer->SetBounds(layerSize); |
| 4249 | contentLayer->SetContentBounds(layerSize); |
| 4250 | contentLayer->SetPosition(gfx::PointF()); |
| 4251 | contentLayer->SetAnchorPoint(gfx::PointF()); |
| 4252 | contentLayer->SetDrawsContent(true); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4253 | |
| 4254 | gfx::Size maskSize(100, 100); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4255 | maskLayer->SetBounds(maskSize); |
| 4256 | maskLayer->SetContentBounds(maskSize); |
| 4257 | maskLayer->SetPosition(gfx::PointF()); |
| 4258 | maskLayer->SetAnchorPoint(gfx::PointF()); |
| 4259 | maskLayer->SetDrawsContent(true); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4260 | |
| 4261 | |
| 4262 | // Check that the mask fills the surface. |
| 4263 | float deviceScaleFactor = 1.f; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4264 | m_hostImpl->SetViewportSize(rootSize, rootSize); |
| 4265 | m_hostImpl->SetDeviceScaleFactor(deviceScaleFactor); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4266 | { |
| 4267 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4268 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4269 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4270 | ASSERT_EQ(1u, frame.render_passes.size()); |
| 4271 | ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
| 4272 | ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 4273 | const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4274 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), renderPassQuad->rect.ToString()); |
| 4275 | EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mask_uv_rect.ToString()); |
| 4276 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 4277 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4278 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4279 | } |
| 4280 | |
| 4281 | |
| 4282 | // Applying a DSF should change the render surface size, but won't affect |
| 4283 | // which part of the mask is used. |
| 4284 | deviceScaleFactor = 2.f; |
| 4285 | gfx::Size deviceViewport(gfx::ToFlooredSize(gfx::ScaleSize(rootSize, deviceScaleFactor))); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4286 | m_hostImpl->SetViewportSize(rootSize, deviceViewport); |
| 4287 | m_hostImpl->SetDeviceScaleFactor(deviceScaleFactor); |
| 4288 | m_hostImpl->active_tree()->set_needs_update_draw_properties(); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4289 | { |
| 4290 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4291 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4292 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4293 | ASSERT_EQ(1u, frame.render_passes.size()); |
| 4294 | ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
| 4295 | ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 4296 | const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4297 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToString()); |
| 4298 | EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mask_uv_rect.ToString()); |
| 4299 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 4300 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4301 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | |
| 4305 | // Applying an equivalent content scale on the content layer and the mask |
| 4306 | // should still result in the same part of the mask being used. |
| 4307 | gfx::Size layerSizeLarge(gfx::ToRoundedSize(gfx::ScaleSize(layerSize, deviceScaleFactor))); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4308 | contentLayer->SetContentBounds(layerSizeLarge); |
| 4309 | contentLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4310 | gfx::Size maskSizeLarge(gfx::ToRoundedSize(gfx::ScaleSize(maskSize, deviceScaleFactor))); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4311 | maskLayer->SetContentBounds(maskSizeLarge); |
| 4312 | maskLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4313 | m_hostImpl->active_tree()->set_needs_update_draw_properties(); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4314 | { |
| 4315 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4316 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4317 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4318 | ASSERT_EQ(1u, frame.render_passes.size()); |
| 4319 | ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
| 4320 | ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 4321 | const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4322 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToString()); |
| 4323 | EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mask_uv_rect.ToString()); |
| 4324 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 4325 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4326 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | // Applying a different contents scale to the mask layer will still result |
| 4330 | // in the mask covering the owning layer. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4331 | maskLayer->SetContentBounds(maskSize); |
| 4332 | maskLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4333 | m_hostImpl->active_tree()->set_needs_update_draw_properties(); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4334 | { |
| 4335 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4336 | EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame)); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4337 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4338 | ASSERT_EQ(1u, frame.render_passes.size()); |
| 4339 | ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
| 4340 | ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->material); |
| 4341 | const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); |
[email protected] | 8611f01 | 2013-01-17 03:44:55 | [diff] [blame] | 4342 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToString()); |
| 4343 | EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mask_uv_rect.ToString()); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4344 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 4345 | m_hostImpl->DrawLayers(&frame, base::TimeTicks::Now()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 4346 | m_hostImpl->DidDrawAllLayers(frame); |
[email protected] | 05dea30 | 2013-01-15 08:30:41 | [diff] [blame] | 4347 | } |
| 4348 | } |
| 4349 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 4350 | } // namespace |
| 4351 | } // namespace cc |