[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] | 55a124d0 | 2012-10-22 03:07:13 | [diff] [blame] | 5 | #include "cc/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 <algorithm> |
| 8 | |
[email protected] | ad5d142 | 2012-10-19 13:40:29 | [diff] [blame] | 9 | #include "base/basictypes.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 10 | #include "base/debug/trace_event.h" |
[email protected] | aa0a9d3 | 2012-10-24 01:58:10 | [diff] [blame] | 11 | #include "cc/append_quads_data.h" |
| 12 | #include "cc/damage_tracker.h" |
| 13 | #include "cc/debug_rect_history.h" |
| 14 | #include "cc/delay_based_time_source.h" |
| 15 | #include "cc/font_atlas.h" |
| 16 | #include "cc/frame_rate_counter.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 17 | #include "cc/gl_renderer.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 18 | #include "cc/heads_up_display_layer_impl.h" |
| 19 | #include "cc/layer_iterator.h" |
| 20 | #include "cc/layer_tree_host.h" |
| 21 | #include "cc/layer_tree_host_common.h" |
[email protected] | 55a124d0 | 2012-10-22 03:07:13 | [diff] [blame] | 22 | #include "cc/math_util.h" |
| 23 | #include "cc/overdraw_metrics.h" |
| 24 | #include "cc/page_scale_animation.h" |
[email protected] | 3b10a30 | 2012-11-07 21:16:40 | [diff] [blame] | 25 | #include "cc/prioritized_resource_manager.h" |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 26 | #include "cc/quad_culler.h" |
[email protected] | 55a124d0 | 2012-10-22 03:07:13 | [diff] [blame] | 27 | #include "cc/render_pass_draw_quad.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 28 | #include "cc/rendering_stats.h" |
| 29 | #include "cc/scrollbar_animation_controller.h" |
| 30 | #include "cc/scrollbar_layer_impl.h" |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 31 | #include "cc/shared_quad_state.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 32 | #include "cc/single_thread_proxy.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 33 | #include "cc/software_renderer.h" |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 34 | #include "cc/solid_color_draw_quad.h" |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 35 | #include "cc/texture_uploader.h" |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 36 | #include "ui/gfx/size_conversions.h" |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 37 | #include "ui/gfx/vector2d_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 38 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 39 | namespace { |
| 40 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 41 | void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 42 | { |
| 43 | if (visible) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 44 | TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id, "LayerTreeHostImpl", id); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 45 | return; |
| 46 | } |
| 47 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 48 | TRACE_EVENT_ASYNC_END0("webkit", "LayerTreeHostImpl::setVisible", id); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace |
| 52 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 53 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 54 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 55 | PinchZoomViewport::PinchZoomViewport() |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 56 | : m_pageScaleFactor(1) |
| 57 | , m_pageScaleDelta(1) |
| 58 | , m_sentPageScaleDelta(1) |
| 59 | , m_minPageScaleFactor(0) |
| 60 | , m_maxPageScaleFactor(0) |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 61 | , m_deviceScaleFactor(1) |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 62 | { |
| 63 | } |
| 64 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 65 | float PinchZoomViewport::totalPageScaleFactor() const |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 66 | { |
| 67 | return m_pageScaleFactor * m_pageScaleDelta; |
| 68 | } |
| 69 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 70 | void PinchZoomViewport::setPageScaleDelta(float delta) |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 71 | { |
| 72 | // Clamp to the current min/max limits. |
| 73 | float totalPageScaleFactor = m_pageScaleFactor * delta; |
| 74 | if (m_minPageScaleFactor && totalPageScaleFactor < m_minPageScaleFactor) |
| 75 | delta = m_minPageScaleFactor / m_pageScaleFactor; |
| 76 | else if (m_maxPageScaleFactor && totalPageScaleFactor > m_maxPageScaleFactor) |
| 77 | delta = m_maxPageScaleFactor / m_pageScaleFactor; |
| 78 | |
| 79 | if (delta == m_pageScaleDelta) |
| 80 | return; |
| 81 | |
| 82 | m_pageScaleDelta = delta; |
| 83 | } |
| 84 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 85 | bool PinchZoomViewport::setPageScaleFactorAndLimits(float pageScaleFactor, float minPageScaleFactor, float maxPageScaleFactor) |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 86 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 87 | DCHECK(pageScaleFactor); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 88 | |
| 89 | if (m_sentPageScaleDelta == 1 && pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageScaleFactor && maxPageScaleFactor == m_maxPageScaleFactor) |
| 90 | return false; |
| 91 | |
| 92 | m_minPageScaleFactor = minPageScaleFactor; |
| 93 | m_maxPageScaleFactor = maxPageScaleFactor; |
| 94 | |
| 95 | m_pageScaleFactor = pageScaleFactor; |
| 96 | return true; |
| 97 | } |
| 98 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 99 | gfx::RectF PinchZoomViewport::bounds() const |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 100 | { |
[email protected] | 2e648601 | 2012-11-10 00:03:19 | [diff] [blame] | 101 | gfx::RectF bounds(gfx::PointF(), m_layoutViewportSize); |
| 102 | bounds.Scale(1 / totalPageScaleFactor()); |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 103 | bounds += m_zoomedViewportOffset; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 104 | return bounds; |
| 105 | } |
| 106 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 107 | gfx::Vector2dF PinchZoomViewport::applyScroll(const gfx::Vector2dF& delta) |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 108 | { |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 109 | gfx::Vector2dF overflow; |
[email protected] | 2e648601 | 2012-11-10 00:03:19 | [diff] [blame] | 110 | gfx::RectF pinchedBounds = bounds() + delta; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 111 | |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 112 | if (pinchedBounds.x() < 0) { |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 113 | overflow.set_x(pinchedBounds.x()); |
| 114 | pinchedBounds.set_x(0); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | if (pinchedBounds.y() < 0) { |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 118 | overflow.set_y(pinchedBounds.y()); |
| 119 | pinchedBounds.set_y(0); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 120 | } |
| 121 | |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 122 | if (pinchedBounds.right() > m_layoutViewportSize.width()) { |
| 123 | overflow.set_x(pinchedBounds.right() - m_layoutViewportSize.width()); |
[email protected] | 2e648601 | 2012-11-10 00:03:19 | [diff] [blame] | 124 | pinchedBounds += gfx::Vector2dF(m_layoutViewportSize.width() - pinchedBounds.right(), 0); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 125 | } |
| 126 | |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 127 | if (pinchedBounds.bottom() > m_layoutViewportSize.height()) { |
| 128 | overflow.set_y(pinchedBounds.bottom() - m_layoutViewportSize.height()); |
[email protected] | 2e648601 | 2012-11-10 00:03:19 | [diff] [blame] | 129 | pinchedBounds += gfx::Vector2dF(0, m_layoutViewportSize.height() - pinchedBounds.bottom()); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 130 | } |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 131 | m_zoomedViewportOffset = pinchedBounds.OffsetFromOrigin(); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 132 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 133 | return overflow; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 134 | } |
| 135 | |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 136 | gfx::Transform PinchZoomViewport::implTransform(bool pageScalePinchZoomEnabled) const |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 137 | { |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 138 | gfx::Transform transform; |
| 139 | transform.Scale(m_pageScaleDelta, m_pageScaleDelta); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 140 | |
| 141 | // If the pinch state is applied in the impl, then push it to the |
| 142 | // impl transform, otherwise the scale is handled by WebCore. |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 143 | if (pageScalePinchZoomEnabled) { |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 144 | transform.Scale(m_pageScaleFactor, m_pageScaleFactor); |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 145 | // The offset needs to be scaled by deviceScaleFactor as this transform |
| 146 | // needs to work with physical pixels. |
| 147 | gfx::Vector2dF zoomedDeviceViewportOffset = gfx::ScaleVector2d(m_zoomedViewportOffset, m_deviceScaleFactor); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 148 | transform.Translate(-zoomedDeviceViewportOffset.x(), -zoomedDeviceViewportOffset.y()); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | return transform; |
| 152 | } |
| 153 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 154 | class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 155 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 156 | static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> create(LayerTreeHostImpl* layerTreeHostImpl, scoped_refptr<DelayBasedTimeSource> timeSource) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 157 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 158 | return make_scoped_ptr(new LayerTreeHostImplTimeSourceAdapter(layerTreeHostImpl, timeSource)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 159 | } |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 160 | virtual ~LayerTreeHostImplTimeSourceAdapter() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 161 | { |
| 162 | m_timeSource->setClient(0); |
| 163 | m_timeSource->setActive(false); |
| 164 | } |
| 165 | |
| 166 | virtual void onTimerTick() OVERRIDE |
| 167 | { |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 168 | m_layerTreeHostImpl->animate(base::TimeTicks::Now(), base::Time::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void setActive(bool active) |
| 172 | { |
| 173 | if (active != m_timeSource->active()) |
| 174 | m_timeSource->setActive(active); |
| 175 | } |
| 176 | |
| 177 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 178 | LayerTreeHostImplTimeSourceAdapter(LayerTreeHostImpl* layerTreeHostImpl, scoped_refptr<DelayBasedTimeSource> timeSource) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 179 | : m_layerTreeHostImpl(layerTreeHostImpl) |
| 180 | , m_timeSource(timeSource) |
| 181 | { |
| 182 | m_timeSource->setClient(this); |
| 183 | } |
| 184 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 185 | LayerTreeHostImpl* m_layerTreeHostImpl; |
| 186 | scoped_refptr<DelayBasedTimeSource> m_timeSource; |
[email protected] | fd2d4f2 | 2012-09-28 22:57:20 | [diff] [blame] | 187 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 188 | DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 189 | }; |
| 190 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 191 | LayerTreeHostImpl::FrameData::FrameData() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 192 | { |
| 193 | } |
| 194 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 195 | LayerTreeHostImpl::FrameData::~FrameData() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 196 | { |
| 197 | } |
| 198 | |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 199 | scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::create(const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 200 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 201 | return make_scoped_ptr(new LayerTreeHostImpl(settings, client, proxy)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 202 | } |
| 203 | |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 204 | LayerTreeHostImpl::LayerTreeHostImpl(const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 205 | : m_client(client) |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 206 | , m_proxy(proxy) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 207 | , m_sourceFrameNumber(-1) |
| 208 | , m_rootScrollLayerImpl(0) |
| 209 | , m_currentlyScrollingLayerImpl(0) |
| 210 | , m_hudLayerImpl(0) |
| 211 | , m_scrollingLayerIdFromPreviousTree(-1) |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 212 | , m_scrollDeltaIsInViewportSpace(false) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 213 | , m_settings(settings) |
| 214 | , m_deviceScaleFactor(1) |
| 215 | , m_visible(true) |
| 216 | , m_contentsTexturesPurged(false) |
[email protected] | 3b10a30 | 2012-11-07 21:16:40 | [diff] [blame] | 217 | , m_managedMemoryPolicy(PrioritizedResourceManager::defaultMemoryAllocationLimit(), |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 218 | PriorityCalculator::allowEverythingCutoff(), |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 219 | 0, |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 220 | PriorityCalculator::allowNothingCutoff()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 221 | , m_backgroundColor(0) |
| 222 | , m_hasTransparentBackground(false) |
| 223 | , m_needsAnimateLayers(false) |
| 224 | , m_pinchGestureActive(false) |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 225 | , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread())) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 226 | , m_debugRectHistory(DebugRectHistory::create()) |
[email protected] | 5c6fe1f8 | 2012-10-03 18:00:27 | [diff] [blame] | 227 | , m_numImplThreadScrolls(0) |
| 228 | , m_numMainThreadScrolls(0) |
[email protected] | 9c2be6a | 2012-11-27 19:16:10 | [diff] [blame^] | 229 | , m_cumulativeNumLayersInLayerTree(0) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 230 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 231 | DCHECK(m_proxy->isImplThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 232 | didVisibilityChange(this, m_visible); |
| 233 | } |
| 234 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 235 | LayerTreeHostImpl::~LayerTreeHostImpl() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 236 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 237 | DCHECK(m_proxy->isImplThread()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 238 | TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 239 | |
| 240 | if (m_rootLayerImpl) |
| 241 | clearRenderSurfaces(); |
| 242 | } |
| 243 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 244 | void LayerTreeHostImpl::beginCommit() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 245 | { |
| 246 | } |
| 247 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 248 | void LayerTreeHostImpl::commitComplete() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 249 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 250 | TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 251 | // Recompute max scroll position; must be after layer content bounds are |
| 252 | // updated. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 253 | updateMaxScrollOffset(); |
[email protected] | 3d21e02 | 2012-10-25 20:03:08 | [diff] [blame] | 254 | m_client->sendManagedMemoryStats(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 255 | } |
| 256 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 257 | bool LayerTreeHostImpl::canDraw() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 258 | { |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 259 | // Note: If you are changing this function or any other function that might |
| 260 | // affect the result of canDraw, make sure to call m_client->onCanDrawStateChanged |
| 261 | // in the proper places and update the notifyIfCanDrawChanged test. |
| 262 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 263 | if (!m_rootLayerImpl) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 264 | TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::canDraw no root layer"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 265 | return false; |
| 266 | } |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 267 | if (deviceViewportSize().IsEmpty()) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 268 | TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::canDraw empty viewport"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 269 | return false; |
| 270 | } |
| 271 | if (!m_renderer) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 272 | TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::canDraw no renderer"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 273 | return false; |
| 274 | } |
| 275 | if (m_contentsTexturesPurged) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 276 | TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::canDraw contents textures purged"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 277 | return false; |
| 278 | } |
| 279 | return true; |
| 280 | } |
| 281 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 282 | GraphicsContext* LayerTreeHostImpl::context() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 283 | { |
| 284 | return m_context.get(); |
| 285 | } |
| 286 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 287 | void LayerTreeHostImpl::animate(base::TimeTicks monotonicTime, base::Time wallClockTime) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 288 | { |
| 289 | animatePageScale(monotonicTime); |
| 290 | animateLayers(monotonicTime, wallClockTime); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 291 | animateScrollbars(monotonicTime); |
| 292 | } |
| 293 | |
[email protected] | 69a2a5be | 2012-11-14 06:51:44 | [diff] [blame] | 294 | void LayerTreeHostImpl::startPageScaleAnimation(gfx::Vector2d targetOffset, bool anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta duration) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 295 | { |
| 296 | if (!m_rootScrollLayerImpl) |
| 297 | return; |
| 298 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 299 | gfx::Vector2dF scrollTotal = m_rootScrollLayerImpl->scrollOffset() + m_rootScrollLayerImpl->scrollDelta(); |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 300 | gfx::SizeF scaledContentSize = contentSize(); |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 301 | if (!m_settings.pageScalePinchZoomEnabled) { |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 302 | scrollTotal.Scale(1 / m_pinchZoomViewport.pageScaleFactor()); |
[email protected] | 01a15a7 | 2012-11-10 09:34:28 | [diff] [blame] | 303 | scaledContentSize.Scale(1 / m_pinchZoomViewport.pageScaleFactor()); |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 304 | } |
[email protected] | 01a15a7 | 2012-11-10 09:34:28 | [diff] [blame] | 305 | gfx::SizeF viewportSize = gfx::ScaleSize(m_deviceViewportSize, 1 / m_deviceScaleFactor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 306 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 307 | double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF(); |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 308 | m_pageScaleAnimation = PageScaleAnimation::create(scrollTotal, m_pinchZoomViewport.totalPageScaleFactor(), viewportSize, scaledContentSize, startTimeSeconds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 309 | |
| 310 | if (anchorPoint) { |
[email protected] | 69a2a5be | 2012-11-14 06:51:44 | [diff] [blame] | 311 | gfx::Vector2dF anchor(targetOffset); |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 312 | if (!m_settings.pageScalePinchZoomEnabled) |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 313 | anchor.Scale(1 / pageScale); |
| 314 | m_pageScaleAnimation->zoomWithAnchor(anchor, pageScale, duration.InSecondsF()); |
| 315 | } else { |
[email protected] | 69a2a5be | 2012-11-14 06:51:44 | [diff] [blame] | 316 | gfx::Vector2dF scaledTargetOffset = targetOffset; |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 317 | if (!m_settings.pageScalePinchZoomEnabled) |
[email protected] | 69a2a5be | 2012-11-14 06:51:44 | [diff] [blame] | 318 | scaledTargetOffset.Scale(1 / pageScale); |
| 319 | m_pageScaleAnimation->zoomTo(scaledTargetOffset, pageScale, duration.InSecondsF()); |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 320 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 321 | |
| 322 | m_client->setNeedsRedrawOnImplThread(); |
| 323 | m_client->setNeedsCommitOnImplThread(); |
| 324 | } |
| 325 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 326 | void LayerTreeHostImpl::scheduleAnimation() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 327 | { |
| 328 | m_client->setNeedsRedrawOnImplThread(); |
| 329 | } |
| 330 | |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 331 | bool LayerTreeHostImpl::haveTouchEventHandlersAt(const gfx::Point& viewportPoint) |
| 332 | { |
| 333 | |
| 334 | gfx::PointF deviceViewportPoint = gfx::ScalePoint(viewportPoint, m_deviceScaleFactor); |
| 335 | |
| 336 | // First find out which layer was hit from the saved list of visible layers |
| 337 | // in the most recent frame. |
| 338 | LayerImpl* layerImplHitByPointInTouchHandlerRegion = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRegion(deviceViewportPoint, m_renderSurfaceLayerList); |
| 339 | |
| 340 | if (layerImplHitByPointInTouchHandlerRegion) |
| 341 | return true; |
| 342 | |
| 343 | return false; |
| 344 | } |
| 345 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 346 | void LayerTreeHostImpl::trackDamageForAllSurfaces(LayerImpl* rootDrawLayer, const LayerList& renderSurfaceLayerList) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 347 | { |
| 348 | // For now, we use damage tracking to compute a global scissor. To do this, we must |
| 349 | // compute all damage tracking before drawing anything, so that we know the root |
| 350 | // damage rect. The root damage rect is then used to scissor each surface. |
| 351 | |
| 352 | for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 353 | LayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex]; |
| 354 | RenderSurfaceImpl* renderSurface = renderSurfaceLayer->renderSurface(); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 355 | DCHECK(renderSurface); |
[email protected] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 356 | renderSurface->damageTracker()->updateDamageTrackingState(renderSurface->layerList(), renderSurfaceLayer->id(), renderSurface->surfacePropertyChangedOnlyFromDescendant(), renderSurface->contentRect(), renderSurfaceLayer->maskLayer(), renderSurfaceLayer->filters(), renderSurfaceLayer->filter()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 360 | void LayerTreeHostImpl::updateRootScrollLayerImplTransform() |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 361 | { |
| 362 | if (m_rootScrollLayerImpl) { |
| 363 | m_rootScrollLayerImpl->setImplTransform(implTransform()); |
| 364 | } |
| 365 | } |
| 366 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 367 | void LayerTreeHostImpl::calculateRenderSurfaceLayerList(LayerList& renderSurfaceLayerList) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 368 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 369 | DCHECK(renderSurfaceLayerList.empty()); |
| 370 | DCHECK(m_rootLayerImpl); |
| 371 | DCHECK(m_renderer); // For maxTextureSize. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 372 | |
| 373 | { |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 374 | updateRootScrollLayerImplTransform(); |
| 375 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 376 | TRACE_EVENT0("cc", "LayerTreeHostImpl::calcDrawEtc"); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 377 | float pageScaleFactor = m_pinchZoomViewport.pageScaleFactor(); |
| 378 | LayerTreeHostCommon::calculateDrawTransforms(m_rootLayerImpl.get(), deviceViewportSize(), m_deviceScaleFactor, pageScaleFactor, &m_layerSorter, rendererCapabilities().maxTextureSize, renderSurfaceLayerList); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 379 | |
| 380 | trackDamageForAllSurfaces(m_rootLayerImpl.get(), renderSurfaceLayerList); |
| 381 | } |
| 382 | } |
| 383 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 384 | void LayerTreeHostImpl::FrameData::appendRenderPass(scoped_ptr<RenderPass> renderPass) |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 385 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 386 | RenderPass* pass = renderPass.get(); |
[email protected] | f8ad834 | 2012-09-27 20:07:02 | [diff] [blame] | 387 | renderPasses.push_back(pass); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 388 | renderPassesById.set(pass->id, renderPass.Pass()); |
| 389 | } |
| 390 | |
| 391 | static void appendQuadsForLayer(RenderPass* targetRenderPass, LayerImpl* layer, OcclusionTrackerImpl& occlusionTracker, AppendQuadsData& appendQuadsData) |
| 392 | { |
| 393 | bool forSurface = false; |
| 394 | QuadCuller quadCuller(targetRenderPass->quad_list, |
| 395 | targetRenderPass->shared_quad_state_list, |
| 396 | layer, |
| 397 | occlusionTracker, |
| 398 | layer->showDebugBorders(), |
| 399 | forSurface); |
| 400 | layer->appendQuads(quadCuller, appendQuadsData); |
| 401 | } |
| 402 | |
| 403 | static void appendQuadsForRenderSurfaceLayer(RenderPass* targetRenderPass, LayerImpl* layer, const RenderPass* contributingRenderPass, OcclusionTrackerImpl& occlusionTracker, AppendQuadsData& appendQuadsData) |
| 404 | { |
| 405 | bool forSurface = true; |
| 406 | QuadCuller quadCuller(targetRenderPass->quad_list, |
| 407 | targetRenderPass->shared_quad_state_list, |
| 408 | layer, |
| 409 | occlusionTracker, |
| 410 | layer->showDebugBorders(), |
| 411 | forSurface); |
| 412 | |
| 413 | bool isReplica = false; |
| 414 | layer->renderSurface()->appendQuads(quadCuller, |
| 415 | appendQuadsData, |
| 416 | isReplica, |
| 417 | contributingRenderPass->id); |
| 418 | |
| 419 | // Add replica after the surface so that it appears below the surface. |
| 420 | if (layer->hasReplica()) { |
| 421 | isReplica = true; |
| 422 | layer->renderSurface()->appendQuads(quadCuller, |
| 423 | appendQuadsData, |
| 424 | isReplica, |
| 425 | contributingRenderPass->id); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | static void appendQuadsToFillScreen(RenderPass* targetRenderPass, LayerImpl* rootLayer, SkColor screenBackgroundColor, const OcclusionTrackerImpl& occlusionTracker) |
| 430 | { |
| 431 | if (!rootLayer || !SkColorGetA(screenBackgroundColor)) |
| 432 | return; |
| 433 | |
| 434 | Region fillRegion = occlusionTracker.computeVisibleRegionInScreen(); |
| 435 | if (fillRegion.IsEmpty()) |
| 436 | return; |
| 437 | |
| 438 | bool forSurface = false; |
| 439 | QuadCuller quadCuller(targetRenderPass->quad_list, |
| 440 | targetRenderPass->shared_quad_state_list, |
| 441 | rootLayer, |
| 442 | occlusionTracker, |
| 443 | rootLayer->showDebugBorders(), |
| 444 | forSurface); |
| 445 | |
| 446 | // Manually create the quad state for the gutter quads, as the root layer |
| 447 | // doesn't have any bounds and so can't generate this itself. |
| 448 | // FIXME: Make the gutter quads generated by the solid color layer (make it smarter about generating quads to fill unoccluded areas). |
| 449 | |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 450 | DCHECK(rootLayer->screenSpaceTransform().IsInvertible()); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 451 | |
| 452 | gfx::Rect rootTargetRect = rootLayer->renderSurface()->contentRect(); |
| 453 | float opacity = 1; |
| 454 | SharedQuadState* sharedQuadState = quadCuller.useSharedQuadState(SharedQuadState::Create()); |
| 455 | sharedQuadState->SetAll(rootLayer->drawTransform(), |
| 456 | rootTargetRect, |
| 457 | rootTargetRect, |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 458 | rootTargetRect, |
| 459 | false, |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 460 | opacity); |
| 461 | |
| 462 | AppendQuadsData appendQuadsData; |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 463 | gfx::Transform transformToLayerSpace = MathUtil::inverse(rootLayer->screenSpaceTransform()); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 464 | for (Region::Iterator fillRects(fillRegion); fillRects.has_rect(); fillRects.next()) { |
| 465 | // The root layer transform is composed of translations and scales only, |
| 466 | // no perspective, so mapping is sufficient. |
| 467 | gfx::Rect layerRect = MathUtil::mapClippedRect(transformToLayerSpace, fillRects.rect()); |
| 468 | // Skip the quad culler and just append the quads directly to avoid |
| 469 | // occlusion checks. |
| 470 | scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); |
| 471 | quad->SetNew(sharedQuadState, layerRect, screenBackgroundColor); |
| 472 | quadCuller.append(quad.PassAs<DrawQuad>(), appendQuadsData); |
| 473 | } |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 474 | } |
| 475 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 476 | bool LayerTreeHostImpl::calculateRenderPasses(FrameData& frame) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 477 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 478 | DCHECK(frame.renderPasses.empty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 479 | |
| 480 | calculateRenderSurfaceLayerList(*frame.renderSurfaceLayerList); |
| 481 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 482 | TRACE_EVENT1("cc", "LayerTreeHostImpl::calculateRenderPasses", "renderSurfaceLayerList.size()", static_cast<long long unsigned>(frame.renderSurfaceLayerList->size())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 483 | |
| 484 | // Create the render passes in dependency order. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 485 | for (int surfaceIndex = frame.renderSurfaceLayerList->size() - 1; surfaceIndex >= 0 ; --surfaceIndex) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 486 | LayerImpl* renderSurfaceLayer = (*frame.renderSurfaceLayerList)[surfaceIndex]; |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 487 | renderSurfaceLayer->renderSurface()->appendRenderPasses(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 488 | } |
| 489 | |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 490 | bool recordMetricsForFrame = m_settings.showOverdrawInTracing && base::debug::TraceLog::GetInstance() && base::debug::TraceLog::GetInstance()->IsEnabled(); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 491 | OcclusionTrackerImpl occlusionTracker(m_rootLayerImpl->renderSurface()->contentRect(), recordMetricsForFrame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 492 | occlusionTracker.setMinimumTrackingSize(m_settings.minimumOcclusionTrackingSize); |
| 493 | |
| 494 | if (settings().showOccludingRects) |
| 495 | occlusionTracker.setOccludingScreenSpaceRectsContainer(&frame.occludingScreenSpaceRects); |
[email protected] | 4d8804e | 2012-11-15 01:51:10 | [diff] [blame] | 496 | if (settings().showNonOccludingRects) |
| 497 | occlusionTracker.setNonOccludingScreenSpaceRectsContainer(&frame.nonOccludingScreenSpaceRects); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 498 | |
| 499 | // Add quads to the Render passes in FrontToBack order to allow for testing occlusion and performing culling during the tree walk. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 500 | typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> LayerIteratorType; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 501 | |
| 502 | // Typically when we are missing a texture and use a checkerboard quad, we still draw the frame. However when the layer being |
| 503 | // checkerboarded is moving due to an impl-animation, we drop the frame to avoid flashing due to the texture suddenly appearing |
| 504 | // in the future. |
| 505 | bool drawFrame = true; |
| 506 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 507 | LayerIteratorType end = LayerIteratorType::end(frame.renderSurfaceLayerList); |
| 508 | for (LayerIteratorType it = LayerIteratorType::begin(frame.renderSurfaceLayerList); it != end; ++it) { |
| 509 | RenderPass::Id targetRenderPassId = it.targetRenderSurfaceLayer()->renderSurface()->renderPassId(); |
| 510 | RenderPass* targetRenderPass = frame.renderPassesById.get(targetRenderPassId); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 511 | |
| 512 | occlusionTracker.enterLayer(it); |
| 513 | |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 514 | AppendQuadsData appendQuadsData(targetRenderPass->id); |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 515 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 516 | if (it.representsContributingRenderSurface()) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 517 | RenderPass::Id contributingRenderPassId = it->renderSurface()->renderPassId(); |
| 518 | RenderPass* contributingRenderPass = frame.renderPassesById.get(contributingRenderPassId); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 519 | appendQuadsForRenderSurfaceLayer(targetRenderPass, *it, contributingRenderPass, occlusionTracker, appendQuadsData); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 520 | } else if (it.representsItself() && !it->visibleContentRect().IsEmpty()) { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 521 | bool hasOcclusionFromOutsideTargetSurface; |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 522 | bool implDrawTransformIsUnknown = false; |
| 523 | if (occlusionTracker.occluded(it->renderTarget(), it->visibleContentRect(), it->drawTransform(), implDrawTransformIsUnknown, it->drawableContentRect(), &hasOcclusionFromOutsideTargetSurface)) |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 524 | appendQuadsData.hadOcclusionFromOutsideTargetSurface |= hasOcclusionFromOutsideTargetSurface; |
| 525 | else { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 526 | it->willDraw(m_resourceProvider.get()); |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 527 | frame.willDrawLayers.push_back(*it); |
[email protected] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 528 | |
| 529 | if (it->hasContributingDelegatedRenderPasses()) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 530 | RenderPass::Id contributingRenderPassId = it->firstContributingRenderPassId(); |
[email protected] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 531 | while (frame.renderPassesById.contains(contributingRenderPassId)) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 532 | RenderPass* renderPass = frame.renderPassesById.get(contributingRenderPassId); |
[email protected] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 533 | |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 534 | AppendQuadsData appendQuadsData(renderPass->id); |
| 535 | appendQuadsForLayer(renderPass, *it, occlusionTracker, appendQuadsData); |
[email protected] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 536 | |
| 537 | contributingRenderPassId = it->nextContributingRenderPassId(contributingRenderPassId); |
| 538 | } |
| 539 | } |
| 540 | |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 541 | appendQuadsForLayer(targetRenderPass, *it, occlusionTracker, appendQuadsData); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 542 | } |
[email protected] | 9c2be6a | 2012-11-27 19:16:10 | [diff] [blame^] | 543 | |
| 544 | ++m_cumulativeNumLayersInLayerTree; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 545 | } |
| 546 | |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 547 | if (appendQuadsData.hadOcclusionFromOutsideTargetSurface) |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 548 | targetRenderPass->has_occlusion_from_outside_target_surface = true; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 549 | |
| 550 | if (appendQuadsData.hadMissingTiles) { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 551 | bool layerHasAnimatingTransform = it->screenSpaceTransformIsAnimating() || it->drawTransformIsAnimating(); |
[email protected] | 2261992 | 2012-11-14 17:58:10 | [diff] [blame] | 552 | if (layerHasAnimatingTransform) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 553 | drawFrame = false; |
| 554 | } |
| 555 | |
| 556 | occlusionTracker.leaveLayer(it); |
| 557 | } |
| 558 | |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 559 | #ifndef NDEBUG |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 560 | for (size_t i = 0; i < frame.renderPasses.size(); ++i) { |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 561 | for (size_t j = 0; j < frame.renderPasses[i]->quad_list.size(); ++j) |
| 562 | DCHECK(frame.renderPasses[i]->quad_list[j]->shared_quad_state); |
| 563 | DCHECK(frame.renderPassesById.contains(frame.renderPasses[i]->id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 564 | } |
| 565 | #endif |
| 566 | |
| 567 | if (!m_hasTransparentBackground) { |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 568 | frame.renderPasses.back()->has_transparent_background = false; |
| 569 | appendQuadsToFillScreen(frame.renderPasses.back(), m_rootLayerImpl.get(), m_backgroundColor, occlusionTracker); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | if (drawFrame) |
| 573 | occlusionTracker.overdrawMetrics().recordMetrics(this); |
| 574 | |
| 575 | removeRenderPasses(CullRenderPassesWithNoQuads(), frame); |
| 576 | m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses); |
| 577 | removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame); |
| 578 | |
| 579 | return drawFrame; |
| 580 | } |
| 581 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 582 | void LayerTreeHostImpl::animateLayersRecursive(LayerImpl* current, base::TimeTicks monotonicTime, base::Time wallClockTime, AnimationEventsVector* events, bool& didAnimate, bool& needsAnimateLayers) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 583 | { |
| 584 | bool subtreeNeedsAnimateLayers = false; |
| 585 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 586 | LayerAnimationController* currentController = current->layerAnimationController(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 587 | |
| 588 | bool hadActiveAnimation = currentController->hasActiveAnimation(); |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 589 | double monotonicTimeSeconds = (monotonicTime - base::TimeTicks()).InSecondsF(); |
| 590 | currentController->animate(monotonicTimeSeconds, events); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 591 | bool startedAnimation = events->size() > 0; |
| 592 | |
| 593 | // We animated if we either ticked a running animation, or started a new animation. |
| 594 | if (hadActiveAnimation || startedAnimation) |
| 595 | didAnimate = true; |
| 596 | |
| 597 | // If the current controller still has an active animation, we must continue animating layers. |
| 598 | if (currentController->hasActiveAnimation()) |
| 599 | subtreeNeedsAnimateLayers = true; |
| 600 | |
| 601 | for (size_t i = 0; i < current->children().size(); ++i) { |
| 602 | bool childNeedsAnimateLayers = false; |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 603 | animateLayersRecursive(current->children()[i], monotonicTime, wallClockTime, events, didAnimate, childNeedsAnimateLayers); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 604 | if (childNeedsAnimateLayers) |
| 605 | subtreeNeedsAnimateLayers = true; |
| 606 | } |
| 607 | |
| 608 | needsAnimateLayers = subtreeNeedsAnimateLayers; |
| 609 | } |
| 610 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 611 | void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 612 | { |
| 613 | // Lazily create the timeSource adapter so that we can vary the interval for testing. |
| 614 | if (!m_timeSourceClientAdapter) |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 615 | m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(this, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->currentThread())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 616 | |
| 617 | m_timeSourceClientAdapter->setActive(enabled); |
| 618 | } |
| 619 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 620 | gfx::Size LayerTreeHostImpl::contentSize() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 621 | { |
| 622 | // TODO(aelias): Hardcoding the first child here is weird. Think of |
| 623 | // a cleaner way to get the contentBounds on the Impl side. |
| 624 | if (!m_rootScrollLayerImpl || m_rootScrollLayerImpl->children().isEmpty()) |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 625 | return gfx::Size(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 626 | return m_rootScrollLayerImpl->children()[0]->contentBounds(); |
| 627 | } |
| 628 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 629 | static inline RenderPass* findRenderPassById(RenderPass::Id renderPassId, const LayerTreeHostImpl::FrameData& frame) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 630 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 631 | RenderPassIdHashMap::const_iterator it = frame.renderPassesById.find(renderPassId); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 632 | DCHECK(it != frame.renderPassesById.end()); |
[email protected] | 87cea537 | 2012-09-26 18:59:56 | [diff] [blame] | 633 | return it->second; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 634 | } |
| 635 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 636 | static void removeRenderPassesRecursive(RenderPass::Id removeRenderPassId, LayerTreeHostImpl::FrameData& frame) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 637 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 638 | RenderPass* removeRenderPass = findRenderPassById(removeRenderPassId, frame); |
| 639 | RenderPassList& renderPasses = frame.renderPasses; |
| 640 | RenderPassList::iterator toRemove = std::find(renderPasses.begin(), renderPasses.end(), removeRenderPass); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 641 | |
| 642 | // The pass was already removed by another quad - probably the original, and we are the replica. |
[email protected] | f8ad834 | 2012-09-27 20:07:02 | [diff] [blame] | 643 | if (toRemove == renderPasses.end()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 644 | return; |
| 645 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 646 | const RenderPass* removedPass = *toRemove; |
[email protected] | f8ad834 | 2012-09-27 20:07:02 | [diff] [blame] | 647 | frame.renderPasses.erase(toRemove); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 648 | |
| 649 | // Now follow up for all RenderPass quads and remove their RenderPasses recursively. |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 650 | const QuadList& quadList = removedPass->quad_list; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 651 | QuadList::constBackToFrontIterator quadListIterator = quadList.backToFrontBegin(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 652 | for (; quadListIterator != quadList.backToFrontEnd(); ++quadListIterator) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 653 | DrawQuad* currentQuad = (*quadListIterator); |
[email protected] | 1bc93f6 | 2012-11-17 19:29:50 | [diff] [blame] | 654 | if (currentQuad->material != DrawQuad::RENDER_PASS) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 655 | continue; |
| 656 | |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 657 | RenderPass::Id nextRemoveRenderPassId = RenderPassDrawQuad::MaterialCast(currentQuad)->render_pass_id; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 658 | removeRenderPassesRecursive(nextRemoveRenderPassId, frame); |
| 659 | } |
| 660 | } |
| 661 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 662 | bool LayerTreeHostImpl::CullRenderPassesWithCachedTextures::shouldRemoveRenderPass(const RenderPassDrawQuad& quad, const FrameData&) const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 663 | { |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 664 | return quad.contents_changed_since_last_frame.IsEmpty() && m_renderer.haveCachedResourcesForRenderPassId(quad.render_pass_id); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 665 | } |
| 666 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 667 | bool LayerTreeHostImpl::CullRenderPassesWithNoQuads::shouldRemoveRenderPass(const RenderPassDrawQuad& quad, const FrameData& frame) const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 668 | { |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 669 | const RenderPass* renderPass = findRenderPassById(quad.render_pass_id, frame); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 670 | const RenderPassList& renderPasses = frame.renderPasses; |
| 671 | RenderPassList::const_iterator foundPass = std::find(renderPasses.begin(), renderPasses.end(), renderPass); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 672 | |
[email protected] | f8ad834 | 2012-09-27 20:07:02 | [diff] [blame] | 673 | bool renderPassAlreadyRemoved = foundPass == renderPasses.end(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 674 | if (renderPassAlreadyRemoved) |
| 675 | return false; |
| 676 | |
| 677 | // If any quad or RenderPass draws into this RenderPass, then keep it. |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 678 | const QuadList& quadList = (*foundPass)->quad_list; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 679 | for (QuadList::constBackToFrontIterator quadListIterator = quadList.backToFrontBegin(); quadListIterator != quadList.backToFrontEnd(); ++quadListIterator) { |
| 680 | DrawQuad* currentQuad = *quadListIterator; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 681 | |
[email protected] | 1bc93f6 | 2012-11-17 19:29:50 | [diff] [blame] | 682 | if (currentQuad->material != DrawQuad::RENDER_PASS) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 683 | return false; |
| 684 | |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 685 | const RenderPass* contributingPass = findRenderPassById(RenderPassDrawQuad::MaterialCast(currentQuad)->render_pass_id, frame); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 686 | RenderPassList::const_iterator foundContributingPass = std::find(renderPasses.begin(), renderPasses.end(), contributingPass); |
[email protected] | f8ad834 | 2012-09-27 20:07:02 | [diff] [blame] | 687 | if (foundContributingPass != renderPasses.end()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 688 | return false; |
| 689 | } |
| 690 | return true; |
| 691 | } |
| 692 | |
| 693 | // Defined for linking tests. |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 694 | template CC_EXPORT void LayerTreeHostImpl::removeRenderPasses<LayerTreeHostImpl::CullRenderPassesWithCachedTextures>(CullRenderPassesWithCachedTextures, FrameData&); |
| 695 | template CC_EXPORT void LayerTreeHostImpl::removeRenderPasses<LayerTreeHostImpl::CullRenderPassesWithNoQuads>(CullRenderPassesWithNoQuads, FrameData&); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 696 | |
| 697 | // static |
| 698 | template<typename RenderPassCuller> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 699 | void LayerTreeHostImpl::removeRenderPasses(RenderPassCuller culler, FrameData& frame) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 700 | { |
| 701 | for (size_t it = culler.renderPassListBegin(frame.renderPasses); it != culler.renderPassListEnd(frame.renderPasses); it = culler.renderPassListNext(it)) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 702 | const RenderPass* currentPass = frame.renderPasses[it]; |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 703 | const QuadList& quadList = currentPass->quad_list; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 704 | QuadList::constBackToFrontIterator quadListIterator = quadList.backToFrontBegin(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 705 | |
| 706 | for (; quadListIterator != quadList.backToFrontEnd(); ++quadListIterator) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 707 | DrawQuad* currentQuad = *quadListIterator; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 708 | |
[email protected] | 1bc93f6 | 2012-11-17 19:29:50 | [diff] [blame] | 709 | if (currentQuad->material != DrawQuad::RENDER_PASS) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 710 | continue; |
| 711 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 712 | RenderPassDrawQuad* renderPassQuad = static_cast<RenderPassDrawQuad*>(currentQuad); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 713 | if (!culler.shouldRemoveRenderPass(*renderPassQuad, frame)) |
| 714 | continue; |
| 715 | |
| 716 | // We are changing the vector in the middle of iteration. Because we |
| 717 | // delete render passes that draw into the current pass, we are |
| 718 | // guaranteed that any data from the iterator to the end will not |
| 719 | // change. So, capture the iterator position from the end of the |
| 720 | // list, and restore it after the change. |
| 721 | int positionFromEnd = frame.renderPasses.size() - it; |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 722 | removeRenderPassesRecursive(renderPassQuad->render_pass_id, frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 723 | it = frame.renderPasses.size() - positionFromEnd; |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 724 | DCHECK(it >= 0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 729 | bool LayerTreeHostImpl::prepareToDraw(FrameData& frame) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 730 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 731 | TRACE_EVENT0("cc", "LayerTreeHostImpl::prepareToDraw"); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 732 | DCHECK(canDraw()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 733 | |
| 734 | frame.renderSurfaceLayerList = &m_renderSurfaceLayerList; |
| 735 | frame.renderPasses.clear(); |
| 736 | frame.renderPassesById.clear(); |
| 737 | frame.renderSurfaceLayerList->clear(); |
| 738 | frame.willDrawLayers.clear(); |
| 739 | |
| 740 | if (!calculateRenderPasses(frame)) |
| 741 | return false; |
| 742 | |
| 743 | // If we return true, then we expect drawLayers() to be called before this function is called again. |
| 744 | return true; |
| 745 | } |
| 746 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 747 | void LayerTreeHostImpl::enforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 748 | { |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 749 | bool evictedResources = m_client->reduceContentsTextureMemoryOnImplThread( |
| 750 | m_visible ? policy.bytesLimitWhenVisible : policy.bytesLimitWhenNotVisible, |
| 751 | m_visible ? policy.priorityCutoffWhenVisible : policy.priorityCutoffWhenNotVisible); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 752 | if (evictedResources) { |
| 753 | setContentsTexturesPurged(); |
| 754 | m_client->setNeedsCommitOnImplThread(); |
| 755 | m_client->onCanDrawStateChanged(canDraw()); |
| 756 | } |
[email protected] | 3d21e02 | 2012-10-25 20:03:08 | [diff] [blame] | 757 | m_client->sendManagedMemoryStats(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 758 | } |
| 759 | |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 760 | bool LayerTreeHostImpl::hasImplThread() const |
| 761 | { |
| 762 | return m_proxy->hasImplThread(); |
| 763 | } |
| 764 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 765 | void LayerTreeHostImpl::setManagedMemoryPolicy(const ManagedMemoryPolicy& policy) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 766 | { |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 767 | if (m_managedMemoryPolicy == policy) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 768 | return; |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 769 | |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 770 | m_managedMemoryPolicy = policy; |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 771 | if (!m_proxy->hasImplThread()) { |
| 772 | // FIXME: In single-thread mode, this can be called on the main thread |
| 773 | // by GLRenderer::onMemoryAllocationChanged. |
| 774 | DebugScopedSetImplThread implThread(m_proxy); |
| 775 | enforceManagedMemoryPolicy(m_managedMemoryPolicy); |
| 776 | } else { |
| 777 | DCHECK(m_proxy->isImplThread()); |
| 778 | enforceManagedMemoryPolicy(m_managedMemoryPolicy); |
| 779 | } |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 780 | // We always need to commit after changing the memory policy because the new |
| 781 | // limit can result in more or less content having texture allocated for it. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 782 | m_client->setNeedsCommitOnImplThread(); |
| 783 | } |
| 784 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 785 | void LayerTreeHostImpl::onVSyncParametersChanged(double monotonicTimebase, double intervalInSeconds) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 786 | { |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 787 | base::TimeTicks timebase = base::TimeTicks::FromInternalValue(monotonicTimebase * base::Time::kMicrosecondsPerSecond); |
| 788 | base::TimeDelta interval = base::TimeDelta::FromMicroseconds(intervalInSeconds * base::Time::kMicrosecondsPerSecond); |
| 789 | m_client->onVSyncParametersChanged(timebase, interval); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 790 | } |
| 791 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 792 | void LayerTreeHostImpl::drawLayers(const FrameData& frame) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 793 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 794 | TRACE_EVENT0("cc", "LayerTreeHostImpl::drawLayers"); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 795 | DCHECK(canDraw()); |
| 796 | DCHECK(!frame.renderPasses.empty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 797 | |
| 798 | // FIXME: use the frame begin time from the overall compositor scheduler. |
| 799 | // This value is currently inaccessible because it is up in Chromium's |
| 800 | // RenderWidget. |
[email protected] | 6bea87c | 2012-10-13 00:15:21 | [diff] [blame] | 801 | m_fpsCounter->markBeginningOfFrame(base::TimeTicks::Now()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 802 | |
| 803 | if (m_settings.showDebugRects()) |
[email protected] | 4d8804e | 2012-11-15 01:51:10 | [diff] [blame] | 804 | m_debugRectHistory->saveDebugRectsForCurrentFrame(m_rootLayerImpl.get(), *frame.renderSurfaceLayerList, frame.occludingScreenSpaceRects, frame.nonOccludingScreenSpaceRects, settings()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 805 | |
| 806 | // Because the contents of the HUD depend on everything else in the frame, the contents |
| 807 | // of its texture are updated as the last thing before the frame is drawn. |
| 808 | if (m_hudLayerImpl) |
| 809 | m_hudLayerImpl->updateHudTexture(m_resourceProvider.get()); |
| 810 | |
| 811 | m_renderer->drawFrame(frame.renderPasses, frame.renderPassesById); |
| 812 | |
| 813 | // Once a RenderPass has been drawn, its damage should be cleared in |
| 814 | // case the RenderPass will be reused next frame. |
| 815 | for (unsigned int i = 0; i < frame.renderPasses.size(); i++) |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 816 | frame.renderPasses[i]->damage_rect = gfx::RectF(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 817 | |
| 818 | // The next frame should start by assuming nothing has changed, and changes are noted as they occur. |
| 819 | for (unsigned int i = 0; i < frame.renderSurfaceLayerList->size(); i++) |
| 820 | (*frame.renderSurfaceLayerList)[i]->renderSurface()->damageTracker()->didDrawDamagedArea(); |
| 821 | m_rootLayerImpl->resetAllChangeTrackingForSubtree(); |
| 822 | } |
| 823 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 824 | void LayerTreeHostImpl::didDrawAllLayers(const FrameData& frame) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 825 | { |
| 826 | for (size_t i = 0; i < frame.willDrawLayers.size(); ++i) |
| 827 | frame.willDrawLayers[i]->didDraw(m_resourceProvider.get()); |
[email protected] | b914e10 | 2012-10-02 08:11:52 | [diff] [blame] | 828 | |
| 829 | // Once all layers have been drawn, pending texture uploads should no |
| 830 | // longer block future uploads. |
[email protected] | e224959 | 2012-10-19 06:59:09 | [diff] [blame] | 831 | m_resourceProvider->markPendingUploadsAsNonBlocking(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 832 | } |
| 833 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 834 | void LayerTreeHostImpl::finishAllRendering() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 835 | { |
| 836 | if (m_renderer) |
| 837 | m_renderer->finish(); |
| 838 | } |
| 839 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 840 | bool LayerTreeHostImpl::isContextLost() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 841 | { |
| 842 | return m_renderer && m_renderer->isContextLost(); |
| 843 | } |
| 844 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 845 | const RendererCapabilities& LayerTreeHostImpl::rendererCapabilities() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 846 | { |
| 847 | return m_renderer->capabilities(); |
| 848 | } |
| 849 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 850 | bool LayerTreeHostImpl::swapBuffers() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 851 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 852 | DCHECK(m_renderer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 853 | |
| 854 | m_fpsCounter->markEndOfFrame(); |
| 855 | return m_renderer->swapBuffers(); |
| 856 | } |
| 857 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 858 | const gfx::Size& LayerTreeHostImpl::deviceViewportSize() const |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 859 | { |
| 860 | return m_deviceViewportSize; |
| 861 | } |
| 862 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 863 | const LayerTreeSettings& LayerTreeHostImpl::settings() const |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 864 | { |
| 865 | return m_settings; |
| 866 | } |
| 867 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 868 | void LayerTreeHostImpl::didLoseContext() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 869 | { |
| 870 | m_client->didLoseContextOnImplThread(); |
| 871 | } |
| 872 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 873 | void LayerTreeHostImpl::onSwapBuffersComplete() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 874 | { |
| 875 | m_client->onSwapBuffersCompleteOnImplThread(); |
| 876 | } |
| 877 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 878 | void LayerTreeHostImpl::readback(void* pixels, const gfx::Rect& rect) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 879 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 880 | DCHECK(m_renderer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 881 | m_renderer->getFramebufferPixels(pixels, rect); |
| 882 | } |
| 883 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 884 | static LayerImpl* findRootScrollLayer(LayerImpl* layer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 885 | { |
| 886 | if (!layer) |
| 887 | return 0; |
| 888 | |
| 889 | if (layer->scrollable()) |
| 890 | return layer; |
| 891 | |
| 892 | for (size_t i = 0; i < layer->children().size(); ++i) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 893 | LayerImpl* found = findRootScrollLayer(layer->children()[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 894 | if (found) |
| 895 | return found; |
| 896 | } |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | // Content layers can be either directly scrollable or contained in an outer |
| 902 | // scrolling layer which applies the scroll transform. Given a content layer, |
| 903 | // this function returns the associated scroll layer if any. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 904 | static LayerImpl* findScrollLayerForContentLayer(LayerImpl* layerImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 905 | { |
| 906 | if (!layerImpl) |
| 907 | return 0; |
| 908 | |
| 909 | if (layerImpl->scrollable()) |
| 910 | return layerImpl; |
| 911 | |
| 912 | if (layerImpl->drawsContent() && layerImpl->parent() && layerImpl->parent()->scrollable()) |
| 913 | return layerImpl->parent(); |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 918 | void LayerTreeHostImpl::setRootLayer(scoped_ptr<LayerImpl> layer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 919 | { |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 920 | m_rootLayerImpl = layer.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 921 | m_rootScrollLayerImpl = findRootScrollLayer(m_rootLayerImpl.get()); |
| 922 | m_currentlyScrollingLayerImpl = 0; |
| 923 | |
| 924 | if (m_rootLayerImpl && m_scrollingLayerIdFromPreviousTree != -1) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 925 | m_currentlyScrollingLayerImpl = LayerTreeHostCommon::findLayerInSubtree(m_rootLayerImpl.get(), m_scrollingLayerIdFromPreviousTree); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 926 | |
| 927 | m_scrollingLayerIdFromPreviousTree = -1; |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 928 | |
| 929 | m_client->onCanDrawStateChanged(canDraw()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 930 | } |
| 931 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 932 | scoped_ptr<LayerImpl> LayerTreeHostImpl::detachLayerTree() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 933 | { |
| 934 | // Clear all data structures that have direct references to the layer tree. |
| 935 | m_scrollingLayerIdFromPreviousTree = m_currentlyScrollingLayerImpl ? m_currentlyScrollingLayerImpl->id() : -1; |
| 936 | m_currentlyScrollingLayerImpl = 0; |
| 937 | m_renderSurfaceLayerList.clear(); |
| 938 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 939 | return m_rootLayerImpl.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 940 | } |
| 941 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 942 | void LayerTreeHostImpl::setVisible(bool visible) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 943 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 944 | DCHECK(m_proxy->isImplThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 945 | |
| 946 | if (m_visible == visible) |
| 947 | return; |
| 948 | m_visible = visible; |
| 949 | didVisibilityChange(this, m_visible); |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 950 | enforceManagedMemoryPolicy(m_managedMemoryPolicy); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 951 | |
| 952 | if (!m_renderer) |
| 953 | return; |
| 954 | |
| 955 | m_renderer->setVisible(visible); |
| 956 | |
| 957 | setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers); |
| 958 | } |
| 959 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 960 | bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<GraphicsContext> context) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 961 | { |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 962 | // Since we will create a new resource provider, we cannot continue to use |
| 963 | // the old resources (i.e. renderSurfaces and texture IDs). Clear them |
| 964 | // before we destroy the old resource provider. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 965 | if (m_rootLayerImpl) { |
| 966 | clearRenderSurfaces(); |
| 967 | sendDidLoseContextRecursive(m_rootLayerImpl.get()); |
| 968 | } |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 969 | // Note: order is important here. |
[email protected] | 0704caf | 2012-10-16 03:39:47 | [diff] [blame] | 970 | m_renderer.reset(); |
[email protected] | a7aa556 | 2012-10-17 14:12:44 | [diff] [blame] | 971 | m_resourceProvider.reset(); |
[email protected] | e28efacd | 2012-10-06 17:07:49 | [diff] [blame] | 972 | m_context.reset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 973 | |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 974 | if (!context->bindToClient(this)) |
| 975 | return false; |
| 976 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 977 | scoped_ptr<ResourceProvider> resourceProvider = ResourceProvider::create(context.get()); |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 978 | if (!resourceProvider) |
| 979 | return false; |
| 980 | |
| 981 | if (context->context3D()) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 982 | m_renderer = GLRenderer::create(this, resourceProvider.get()); |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 983 | else if (context->softwareDevice()) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 984 | m_renderer = SoftwareRenderer::create(this, resourceProvider.get(), context->softwareDevice()); |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 985 | if (!m_renderer) |
| 986 | return false; |
| 987 | |
[email protected] | a7aa556 | 2012-10-17 14:12:44 | [diff] [blame] | 988 | m_resourceProvider = resourceProvider.Pass(); |
[email protected] | e28efacd | 2012-10-06 17:07:49 | [diff] [blame] | 989 | m_context = context.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 990 | |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 991 | if (!m_visible) |
| 992 | m_renderer->setVisible(m_visible); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 993 | |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 994 | m_client->onCanDrawStateChanged(canDraw()); |
| 995 | |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 996 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 997 | } |
| 998 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 999 | void LayerTreeHostImpl::setContentsTexturesPurged() |
[email protected] | e1fc8b3 | 2012-09-18 20:29:09 | [diff] [blame] | 1000 | { |
| 1001 | m_contentsTexturesPurged = true; |
| 1002 | m_client->onCanDrawStateChanged(canDraw()); |
| 1003 | } |
| 1004 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1005 | void LayerTreeHostImpl::resetContentsTexturesPurged() |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 1006 | { |
| 1007 | m_contentsTexturesPurged = false; |
| 1008 | m_client->onCanDrawStateChanged(canDraw()); |
| 1009 | } |
| 1010 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1011 | void LayerTreeHostImpl::setViewportSize(const gfx::Size& layoutViewportSize, const gfx::Size& deviceViewportSize) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1012 | { |
| 1013 | if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_deviceViewportSize) |
| 1014 | return; |
| 1015 | |
| 1016 | m_layoutViewportSize = layoutViewportSize; |
| 1017 | m_deviceViewportSize = deviceViewportSize; |
| 1018 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1019 | m_pinchZoomViewport.setLayoutViewportSize(layoutViewportSize); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1020 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1021 | updateMaxScrollOffset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1022 | |
| 1023 | if (m_renderer) |
| 1024 | m_renderer->viewportChanged(); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 1025 | |
| 1026 | m_client->onCanDrawStateChanged(canDraw()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1027 | } |
| 1028 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1029 | static void adjustScrollsForPageScaleChange(LayerImpl* layerImpl, float pageScaleChange) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1030 | { |
| 1031 | if (!layerImpl) |
| 1032 | return; |
| 1033 | |
| 1034 | if (layerImpl->scrollable()) { |
| 1035 | // We need to convert impl-side scroll deltas to pageScale space. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1036 | gfx::Vector2dF scrollDelta = layerImpl->scrollDelta(); |
| 1037 | scrollDelta.Scale(pageScaleChange); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1038 | layerImpl->setScrollDelta(scrollDelta); |
| 1039 | } |
| 1040 | |
| 1041 | for (size_t i = 0; i < layerImpl->children().size(); ++i) |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 1042 | adjustScrollsForPageScaleChange(layerImpl->children()[i], pageScaleChange); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1043 | } |
| 1044 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1045 | void LayerTreeHostImpl::setDeviceScaleFactor(float deviceScaleFactor) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1046 | { |
| 1047 | if (deviceScaleFactor == m_deviceScaleFactor) |
| 1048 | return; |
| 1049 | m_deviceScaleFactor = deviceScaleFactor; |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 1050 | m_pinchZoomViewport.setDeviceScaleFactor(m_deviceScaleFactor); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 1051 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1052 | updateMaxScrollOffset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1053 | } |
| 1054 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1055 | float LayerTreeHostImpl::pageScaleFactor() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1056 | { |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1057 | return m_pinchZoomViewport.pageScaleFactor(); |
| 1058 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1059 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1060 | void LayerTreeHostImpl::setPageScaleFactorAndLimits(float pageScaleFactor, float minPageScaleFactor, float maxPageScaleFactor) |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1061 | { |
| 1062 | if (!pageScaleFactor) |
| 1063 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1064 | |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1065 | float pageScaleChange = pageScaleFactor / m_pinchZoomViewport.pageScaleFactor(); |
| 1066 | m_pinchZoomViewport.setPageScaleFactorAndLimits(pageScaleFactor, minPageScaleFactor, maxPageScaleFactor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1067 | |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 1068 | if (!m_settings.pageScalePinchZoomEnabled) { |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1069 | if (pageScaleChange != 1) |
| 1070 | adjustScrollsForPageScaleChange(m_rootScrollLayerImpl, pageScaleChange); |
| 1071 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1072 | |
| 1073 | // Clamp delta to limits and refresh display matrix. |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1074 | setPageScaleDelta(m_pinchZoomViewport.pageScaleDelta() / m_pinchZoomViewport.sentPageScaleDelta()); |
| 1075 | m_pinchZoomViewport.setSentPageScaleDelta(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1076 | } |
| 1077 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1078 | void LayerTreeHostImpl::setPageScaleDelta(float delta) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1079 | { |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1080 | m_pinchZoomViewport.setPageScaleDelta(delta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1081 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1082 | updateMaxScrollOffset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1083 | } |
| 1084 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1085 | void LayerTreeHostImpl::updateMaxScrollOffset() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1086 | { |
| 1087 | if (!m_rootScrollLayerImpl || !m_rootScrollLayerImpl->children().size()) |
| 1088 | return; |
| 1089 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1090 | gfx::SizeF viewBounds = m_deviceViewportSize; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1091 | if (LayerImpl* clipLayer = m_rootScrollLayerImpl->parent()) { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1092 | // Compensate for non-overlay scrollbars. |
[email protected] | 01a15a7 | 2012-11-10 09:34:28 | [diff] [blame] | 1093 | if (clipLayer->masksToBounds()) |
| 1094 | viewBounds = gfx::ScaleSize(clipLayer->bounds(), m_deviceScaleFactor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1095 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1096 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1097 | gfx::Size contentBounds = contentSize(); |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 1098 | if (m_settings.pageScalePinchZoomEnabled) { |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1099 | // Pinch with pageScale scrolls entirely in layout space. contentSize |
| 1100 | // returns the bounds including the page scale factor, so calculate the |
| 1101 | // pre page-scale layout size here. |
| 1102 | float pageScaleFactor = m_pinchZoomViewport.pageScaleFactor(); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1103 | contentBounds.set_width(contentBounds.width() / pageScaleFactor); |
| 1104 | contentBounds.set_height(contentBounds.height() / pageScaleFactor); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1105 | } else { |
[email protected] | 01a15a7 | 2012-11-10 09:34:28 | [diff] [blame] | 1106 | viewBounds.Scale(1 / m_pinchZoomViewport.pageScaleDelta()); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1107 | } |
| 1108 | |
[email protected] | 0eef4b88 | 2012-11-20 20:28:07 | [diff] [blame] | 1109 | gfx::Vector2dF maxScroll = gfx::Rect(contentBounds).bottom_right() - gfx::RectF(viewBounds).bottom_right(); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1110 | maxScroll.Scale(1 / m_deviceScaleFactor); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1111 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1112 | // The viewport may be larger than the contents in some cases, such as |
| 1113 | // having a vertical scrollbar but no horizontal overflow. |
[email protected] | fe07b64 | 2012-11-10 00:07:59 | [diff] [blame] | 1114 | maxScroll.ClampToMin(gfx::Vector2dF()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1115 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1116 | m_rootScrollLayerImpl->setMaxScrollOffset(gfx::ToFlooredVector2d(maxScroll)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1117 | } |
| 1118 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1119 | void LayerTreeHostImpl::setNeedsRedraw() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1120 | { |
| 1121 | m_client->setNeedsRedrawOnImplThread(); |
| 1122 | } |
| 1123 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1124 | bool LayerTreeHostImpl::ensureRenderSurfaceLayerList() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1125 | { |
| 1126 | if (!m_rootLayerImpl) |
| 1127 | return false; |
| 1128 | if (!m_renderer) |
| 1129 | return false; |
| 1130 | |
| 1131 | // We need both a non-empty render surface layer list and a root render |
| 1132 | // surface to be able to iterate over the visible layers. |
| 1133 | if (m_renderSurfaceLayerList.size() && m_rootLayerImpl->renderSurface()) |
| 1134 | return true; |
| 1135 | |
| 1136 | // If we are called after setRootLayer() but before prepareToDraw(), we need |
| 1137 | // to recalculate the visible layers. This prevents being unable to scroll |
| 1138 | // during part of a commit. |
| 1139 | m_renderSurfaceLayerList.clear(); |
| 1140 | calculateRenderSurfaceLayerList(m_renderSurfaceLayerList); |
| 1141 | |
| 1142 | return m_renderSurfaceLayerList.size(); |
| 1143 | } |
| 1144 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1145 | InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(gfx::Point viewportPoint, InputHandlerClient::ScrollInputType type) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1146 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1147 | TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBegin"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1148 | |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 1149 | DCHECK(!m_currentlyScrollingLayerImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1150 | clearCurrentlyScrollingLayer(); |
| 1151 | |
| 1152 | if (!ensureRenderSurfaceLayerList()) |
| 1153 | return ScrollIgnored; |
| 1154 | |
[email protected] | faf5635 | 2012-11-09 21:44:13 | [diff] [blame] | 1155 | gfx::PointF deviceViewportPoint = gfx::ScalePoint(viewportPoint, m_deviceScaleFactor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1156 | |
| 1157 | // First find out which layer was hit from the saved list of visible layers |
| 1158 | // in the most recent frame. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1159 | LayerImpl* layerImpl = LayerTreeHostCommon::findLayerThatIsHitByPoint(deviceViewportPoint, m_renderSurfaceLayerList); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1160 | |
| 1161 | // Walk up the hierarchy and look for a scrollable layer. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1162 | LayerImpl* potentiallyScrollingLayerImpl = 0; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1163 | for (; layerImpl; layerImpl = layerImpl->parent()) { |
| 1164 | // The content layer can also block attempts to scroll outside the main thread. |
[email protected] | 5c6fe1f8 | 2012-10-03 18:00:27 | [diff] [blame] | 1165 | if (layerImpl->tryScroll(deviceViewportPoint, type) == ScrollOnMainThread) { |
| 1166 | m_numMainThreadScrolls++; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1167 | return ScrollOnMainThread; |
[email protected] | 5c6fe1f8 | 2012-10-03 18:00:27 | [diff] [blame] | 1168 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1169 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1170 | LayerImpl* scrollLayerImpl = findScrollLayerForContentLayer(layerImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1171 | if (!scrollLayerImpl) |
| 1172 | continue; |
| 1173 | |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1174 | ScrollStatus status = scrollLayerImpl->tryScroll(deviceViewportPoint, type); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1175 | |
| 1176 | // If any layer wants to divert the scroll event to the main thread, abort. |
[email protected] | 5c6fe1f8 | 2012-10-03 18:00:27 | [diff] [blame] | 1177 | if (status == ScrollOnMainThread) { |
| 1178 | m_numMainThreadScrolls++; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1179 | return ScrollOnMainThread; |
[email protected] | 5c6fe1f8 | 2012-10-03 18:00:27 | [diff] [blame] | 1180 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1181 | |
| 1182 | if (status == ScrollStarted && !potentiallyScrollingLayerImpl) |
| 1183 | potentiallyScrollingLayerImpl = scrollLayerImpl; |
| 1184 | } |
| 1185 | |
| 1186 | if (potentiallyScrollingLayerImpl) { |
| 1187 | m_currentlyScrollingLayerImpl = potentiallyScrollingLayerImpl; |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1188 | // Gesture events need to be transformed from viewport coordinates to local layer coordinates |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1189 | // so that the scrolling contents exactly follow the user's finger. In contrast, wheel |
| 1190 | // events are already in local layer coordinates so we can just apply them directly. |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1191 | m_scrollDeltaIsInViewportSpace = (type == Gesture); |
[email protected] | 5c6fe1f8 | 2012-10-03 18:00:27 | [diff] [blame] | 1192 | m_numImplThreadScrolls++; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1193 | return ScrollStarted; |
| 1194 | } |
| 1195 | return ScrollIgnored; |
| 1196 | } |
| 1197 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1198 | static gfx::Vector2dF scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewport, LayerImpl& layerImpl, float scaleFromViewportToScreenSpace, gfx::PointF viewportPoint, gfx::Vector2dF viewportDelta) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1199 | { |
| 1200 | // Layers with non-invertible screen space transforms should not have passed the scroll hit |
| 1201 | // test in the first place. |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1202 | DCHECK(layerImpl.screenSpaceTransform().IsInvertible()); |
| 1203 | gfx::Transform inverseScreenSpaceTransform = MathUtil::inverse(layerImpl.screenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1204 | |
[email protected] | faf5635 | 2012-11-09 21:44:13 | [diff] [blame] | 1205 | gfx::PointF screenSpacePoint = gfx::ScalePoint(viewportPoint, scaleFromViewportToScreenSpace); |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1206 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1207 | gfx::Vector2dF screenSpaceDelta = viewportDelta; |
| 1208 | screenSpaceDelta.Scale(scaleFromViewportToScreenSpace); |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1209 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1210 | // First project the scroll start and end points to local layer space to find the scroll delta |
| 1211 | // in layer coordinates. |
| 1212 | bool startClipped, endClipped; |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 1213 | gfx::PointF screenSpaceEndPoint = screenSpacePoint + screenSpaceDelta; |
| 1214 | gfx::PointF localStartPoint = MathUtil::projectPoint(inverseScreenSpaceTransform, screenSpacePoint, startClipped); |
| 1215 | gfx::PointF localEndPoint = MathUtil::projectPoint(inverseScreenSpaceTransform, screenSpaceEndPoint, endClipped); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1216 | |
| 1217 | // In general scroll point coordinates should not get clipped. |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 1218 | DCHECK(!startClipped); |
| 1219 | DCHECK(!endClipped); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1220 | if (startClipped || endClipped) |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1221 | return gfx::Vector2dF(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1222 | |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1223 | // localStartPoint and localEndPoint are in content space but we want to move them to layer space for scrolling. |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 1224 | float widthScale = 1 / layerImpl.contentsScaleX(); |
| 1225 | float heightScale = 1 / layerImpl.contentsScaleY(); |
[email protected] | faf5635 | 2012-11-09 21:44:13 | [diff] [blame] | 1226 | localStartPoint.Scale(widthScale, heightScale); |
| 1227 | localEndPoint.Scale(widthScale, heightScale); |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1228 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1229 | // Apply the scroll delta. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1230 | gfx::Vector2dF previousDelta = layerImpl.scrollDelta(); |
| 1231 | gfx::Vector2dF unscrolled = layerImpl.scrollBy(localEndPoint - localStartPoint); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1232 | |
[email protected] | aeaa50a | 2012-11-21 20:12:37 | [diff] [blame] | 1233 | gfx::Vector2dF viewportAppliedPan; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1234 | if (viewport) |
[email protected] | aeaa50a | 2012-11-21 20:12:37 | [diff] [blame] | 1235 | viewportAppliedPan = unscrolled - viewport->applyScroll(unscrolled); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1236 | |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1237 | // Get the end point in the layer's content space so we can apply its screenSpaceTransform. |
[email protected] | aeaa50a | 2012-11-21 20:12:37 | [diff] [blame] | 1238 | gfx::PointF actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta() + viewportAppliedPan - previousDelta; |
[email protected] | faf5635 | 2012-11-09 21:44:13 | [diff] [blame] | 1239 | gfx::PointF actualLocalContentEndPoint = gfx::ScalePoint(actualLocalEndPoint, 1 / widthScale, 1 / heightScale); |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1240 | |
| 1241 | // Calculate the applied scroll delta in viewport space coordinates. |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 1242 | gfx::PointF actualScreenSpaceEndPoint = MathUtil::mapPoint(layerImpl.screenSpaceTransform(), actualLocalContentEndPoint, endClipped); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 1243 | DCHECK(!endClipped); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1244 | if (endClipped) |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1245 | return gfx::Vector2dF(); |
[email protected] | faf5635 | 2012-11-09 21:44:13 | [diff] [blame] | 1246 | gfx::PointF actualViewportEndPoint = gfx::ScalePoint(actualScreenSpaceEndPoint, 1 / scaleFromViewportToScreenSpace); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1247 | return actualViewportEndPoint - viewportPoint; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1248 | } |
| 1249 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1250 | static gfx::Vector2dF scrollLayerWithLocalDelta(LayerImpl& layerImpl, gfx::Vector2dF localDelta) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1251 | { |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1252 | gfx::Vector2dF previousDelta(layerImpl.scrollDelta()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1253 | layerImpl.scrollBy(localDelta); |
| 1254 | return layerImpl.scrollDelta() - previousDelta; |
| 1255 | } |
| 1256 | |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 1257 | bool LayerTreeHostImpl::scrollBy(const gfx::Point& viewportPoint, |
| 1258 | const gfx::Vector2d& scrollDelta) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1259 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1260 | TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBy"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1261 | if (!m_currentlyScrollingLayerImpl) |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 1262 | return false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1263 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1264 | gfx::Vector2dF pendingDelta = scrollDelta; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1265 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1266 | for (LayerImpl* layerImpl = m_currentlyScrollingLayerImpl; layerImpl; layerImpl = layerImpl->parent()) { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1267 | if (!layerImpl->scrollable()) |
| 1268 | continue; |
| 1269 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1270 | PinchZoomViewport* viewport = layerImpl == m_rootScrollLayerImpl ? &m_pinchZoomViewport : 0; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1271 | gfx::Vector2dF appliedDelta; |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1272 | if (m_scrollDeltaIsInViewportSpace) { |
| 1273 | float scaleFromViewportToScreenSpace = m_deviceScaleFactor; |
| 1274 | appliedDelta = scrollLayerWithViewportSpaceDelta(viewport, *layerImpl, scaleFromViewportToScreenSpace, viewportPoint, pendingDelta); |
| 1275 | } else |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1276 | appliedDelta = scrollLayerWithLocalDelta(*layerImpl, pendingDelta); |
| 1277 | |
| 1278 | // If the layer wasn't able to move, try the next one in the hierarchy. |
[email protected] | 23bbb41 | 2012-08-30 20:03:38 | [diff] [blame] | 1279 | float moveThresholdSquared = 0.1f * 0.1f; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1280 | if (appliedDelta.LengthSquared() < moveThresholdSquared) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1281 | continue; |
| 1282 | |
| 1283 | // If the applied delta is within 45 degrees of the input delta, bail out to make it easier |
| 1284 | // to scroll just one layer in one direction without affecting any of its parents. |
| 1285 | float angleThreshold = 45; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1286 | if (MathUtil::smallestAngleBetweenVectors(appliedDelta, pendingDelta) < angleThreshold) { |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1287 | pendingDelta = gfx::Vector2d(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1288 | break; |
| 1289 | } |
| 1290 | |
| 1291 | // Allow further movement only on an axis perpendicular to the direction in which the layer |
| 1292 | // moved. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1293 | gfx::Vector2dF perpendicularAxis(-appliedDelta.y(), appliedDelta.x()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1294 | pendingDelta = MathUtil::projectVector(pendingDelta, perpendicularAxis); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1295 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1296 | if (gfx::ToFlooredVector2d(pendingDelta).IsZero()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1297 | break; |
| 1298 | } |
| 1299 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1300 | if (!scrollDelta.IsZero() && gfx::ToFlooredVector2d(pendingDelta).IsZero()) { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1301 | m_client->setNeedsCommitOnImplThread(); |
| 1302 | m_client->setNeedsRedrawOnImplThread(); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 1303 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1304 | } |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 1305 | return false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1306 | } |
| 1307 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1308 | void LayerTreeHostImpl::clearCurrentlyScrollingLayer() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1309 | { |
| 1310 | m_currentlyScrollingLayerImpl = 0; |
| 1311 | m_scrollingLayerIdFromPreviousTree = -1; |
| 1312 | } |
| 1313 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1314 | void LayerTreeHostImpl::scrollEnd() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1315 | { |
| 1316 | clearCurrentlyScrollingLayer(); |
| 1317 | } |
| 1318 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1319 | void LayerTreeHostImpl::pinchGestureBegin() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1320 | { |
| 1321 | m_pinchGestureActive = true; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1322 | m_previousPinchAnchor = gfx::Point(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1323 | |
| 1324 | if (m_rootScrollLayerImpl && m_rootScrollLayerImpl->scrollbarAnimationController()) |
| 1325 | m_rootScrollLayerImpl->scrollbarAnimationController()->didPinchGestureBegin(); |
| 1326 | } |
| 1327 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1328 | void LayerTreeHostImpl::pinchGestureUpdate(float magnifyDelta, gfx::Point anchor) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1329 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1330 | TRACE_EVENT0("cc", "LayerTreeHostImpl::pinchGestureUpdate"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1331 | |
| 1332 | if (!m_rootScrollLayerImpl) |
| 1333 | return; |
| 1334 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1335 | // Keep the center-of-pinch anchor specified by (x, y) in a stable |
| 1336 | // position over the course of the magnify. |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1337 | float pageScaleDelta = m_pinchZoomViewport.pageScaleDelta(); |
[email protected] | c77745d | 2012-11-20 04:11:57 | [diff] [blame] | 1338 | gfx::PointF previousScaleAnchor = gfx::ScalePoint(anchor, 1 / pageScaleDelta); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1339 | setPageScaleDelta(pageScaleDelta * magnifyDelta); |
| 1340 | pageScaleDelta = m_pinchZoomViewport.pageScaleDelta(); |
[email protected] | faf5635 | 2012-11-09 21:44:13 | [diff] [blame] | 1341 | gfx::PointF newScaleAnchor = gfx::ScalePoint(anchor, 1 / pageScaleDelta); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1342 | gfx::Vector2dF move = previousScaleAnchor - newScaleAnchor; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1343 | |
| 1344 | m_previousPinchAnchor = anchor; |
| 1345 | |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 1346 | if (m_settings.pageScalePinchZoomEnabled) { |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1347 | // Compute the application of the delta with respect to the current page zoom of the page. |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 1348 | move.Scale(1 / m_pinchZoomViewport.pageScaleFactor()); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1349 | } |
| 1350 | |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 1351 | gfx::Vector2dF scrollOverflow = m_settings.pageScalePinchZoomEnabled ? m_pinchZoomViewport.applyScroll(move) : move; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1352 | m_rootScrollLayerImpl->scrollBy(scrollOverflow); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1353 | |
| 1354 | if (m_rootScrollLayerImpl->scrollbarAnimationController()) |
| 1355 | m_rootScrollLayerImpl->scrollbarAnimationController()->didPinchGestureUpdate(); |
| 1356 | |
| 1357 | m_client->setNeedsCommitOnImplThread(); |
| 1358 | m_client->setNeedsRedrawOnImplThread(); |
| 1359 | } |
| 1360 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1361 | void LayerTreeHostImpl::pinchGestureEnd() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1362 | { |
| 1363 | m_pinchGestureActive = false; |
| 1364 | |
| 1365 | if (m_rootScrollLayerImpl && m_rootScrollLayerImpl->scrollbarAnimationController()) |
| 1366 | m_rootScrollLayerImpl->scrollbarAnimationController()->didPinchGestureEnd(); |
| 1367 | |
| 1368 | m_client->setNeedsCommitOnImplThread(); |
| 1369 | } |
| 1370 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1371 | void LayerTreeHostImpl::computeDoubleTapZoomDeltas(ScrollAndScaleSet* scrollInfo) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1372 | { |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 1373 | gfx::Vector2dF scaledScrollOffset = m_pageScaleAnimation->targetScrollOffset(); |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 1374 | if (!m_settings.pageScalePinchZoomEnabled) |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 1375 | scaledScrollOffset.Scale(m_pinchZoomViewport.pageScaleFactor()); |
| 1376 | makeScrollAndScaleSet(scrollInfo, ToFlooredVector2d(scaledScrollOffset), m_pageScaleAnimation->targetPageScaleFactor()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1377 | } |
| 1378 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1379 | void LayerTreeHostImpl::computePinchZoomDeltas(ScrollAndScaleSet* scrollInfo) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1380 | { |
| 1381 | if (!m_rootScrollLayerImpl) |
| 1382 | return; |
| 1383 | |
| 1384 | // Only send fake scroll/zoom deltas if we're pinch zooming out by a |
| 1385 | // significant amount. This also ensures only one fake delta set will be |
| 1386 | // sent. |
[email protected] | 23bbb41 | 2012-08-30 20:03:38 | [diff] [blame] | 1387 | const float pinchZoomOutSensitivity = 0.95f; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1388 | if (m_pinchZoomViewport.pageScaleDelta() > pinchZoomOutSensitivity) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1389 | return; |
| 1390 | |
| 1391 | // Compute where the scroll offset/page scale would be if fully pinch-zoomed |
| 1392 | // out from the anchor point. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1393 | gfx::Vector2dF scrollBegin = m_rootScrollLayerImpl->scrollOffset() + m_rootScrollLayerImpl->scrollDelta(); |
| 1394 | scrollBegin.Scale(m_pinchZoomViewport.pageScaleDelta()); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1395 | float scaleBegin = m_pinchZoomViewport.totalPageScaleFactor(); |
| 1396 | float pageScaleDeltaToSend = m_pinchZoomViewport.minPageScaleFactor() / m_pinchZoomViewport.pageScaleFactor(); |
[email protected] | 01a15a7 | 2012-11-10 09:34:28 | [diff] [blame] | 1397 | gfx::SizeF scaledContentsSize = gfx::ScaleSize(contentSize(), pageScaleDeltaToSend); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1398 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1399 | gfx::Vector2d anchorOffset = m_previousPinchAnchor.OffsetFromOrigin(); |
| 1400 | gfx::Vector2dF scrollEnd = scrollBegin + anchorOffset; |
| 1401 | scrollEnd.Scale(m_pinchZoomViewport.minPageScaleFactor() / scaleBegin); |
| 1402 | scrollEnd -= anchorOffset; |
[email protected] | 0eef4b88 | 2012-11-20 20:28:07 | [diff] [blame] | 1403 | scrollEnd.ClampToMax(gfx::RectF(scaledContentsSize).bottom_right() - gfx::Rect(m_deviceViewportSize).bottom_right()); |
[email protected] | fe07b64 | 2012-11-10 00:07:59 | [diff] [blame] | 1404 | scrollEnd.ClampToMin(gfx::Vector2d()); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1405 | scrollEnd.Scale(1 / pageScaleDeltaToSend); |
| 1406 | scrollEnd.Scale(m_deviceScaleFactor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1407 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1408 | makeScrollAndScaleSet(scrollInfo, gfx::ToRoundedVector2d(scrollEnd), m_pinchZoomViewport.minPageScaleFactor()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1409 | } |
| 1410 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1411 | void LayerTreeHostImpl::makeScrollAndScaleSet(ScrollAndScaleSet* scrollInfo, gfx::Vector2d scrollOffset, float pageScale) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1412 | { |
| 1413 | if (!m_rootScrollLayerImpl) |
| 1414 | return; |
| 1415 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1416 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1417 | scroll.layerId = m_rootScrollLayerImpl->id(); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1418 | scroll.scrollDelta = scrollOffset - m_rootScrollLayerImpl->scrollOffset(); |
[email protected] | 787465c | 2012-10-29 01:12:27 | [diff] [blame] | 1419 | scrollInfo->scrolls.push_back(scroll); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1420 | m_rootScrollLayerImpl->setSentScrollDelta(scroll.scrollDelta); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1421 | scrollInfo->pageScaleDelta = pageScale / m_pinchZoomViewport.pageScaleFactor(); |
| 1422 | m_pinchZoomViewport.setSentPageScaleDelta(scrollInfo->pageScaleDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1423 | } |
| 1424 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1425 | static void collectScrollDeltas(ScrollAndScaleSet* scrollInfo, LayerImpl* layerImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1426 | { |
| 1427 | if (!layerImpl) |
| 1428 | return; |
| 1429 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1430 | if (!layerImpl->scrollDelta().IsZero()) { |
| 1431 | gfx::Vector2d scrollDelta = gfx::ToFlooredVector2d(layerImpl->scrollDelta()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1432 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1433 | scroll.layerId = layerImpl->id(); |
| 1434 | scroll.scrollDelta = scrollDelta; |
[email protected] | 787465c | 2012-10-29 01:12:27 | [diff] [blame] | 1435 | scrollInfo->scrolls.push_back(scroll); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1436 | layerImpl->setSentScrollDelta(scrollDelta); |
| 1437 | } |
| 1438 | |
| 1439 | for (size_t i = 0; i < layerImpl->children().size(); ++i) |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 1440 | collectScrollDeltas(scrollInfo, layerImpl->children()[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1441 | } |
| 1442 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1443 | scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::processScrollDeltas() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1444 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1445 | scoped_ptr<ScrollAndScaleSet> scrollInfo(new ScrollAndScaleSet()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1446 | |
| 1447 | if (m_pinchGestureActive || m_pageScaleAnimation) { |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1448 | scrollInfo->pageScaleDelta = 1; |
| 1449 | m_pinchZoomViewport.setSentPageScaleDelta(1); |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 1450 | // FIXME(aelias): Make pinch-zoom painting optimization compatible with |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1451 | // compositor-side scaling. |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 1452 | if (!m_settings.pageScalePinchZoomEnabled && m_pinchGestureActive) |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 1453 | computePinchZoomDeltas(scrollInfo.get()); |
| 1454 | else if (m_pageScaleAnimation.get()) |
| 1455 | computeDoubleTapZoomDeltas(scrollInfo.get()); |
[email protected] | a9f4bf2 | 2012-10-11 23:39:21 | [diff] [blame] | 1456 | return scrollInfo.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | collectScrollDeltas(scrollInfo.get(), m_rootLayerImpl.get()); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1460 | scrollInfo->pageScaleDelta = m_pinchZoomViewport.pageScaleDelta(); |
| 1461 | m_pinchZoomViewport.setSentPageScaleDelta(scrollInfo->pageScaleDelta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1462 | |
[email protected] | a9f4bf2 | 2012-10-11 23:39:21 | [diff] [blame] | 1463 | return scrollInfo.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1464 | } |
| 1465 | |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 1466 | gfx::Transform LayerTreeHostImpl::implTransform() const |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1467 | { |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 1468 | return m_pinchZoomViewport.implTransform(m_settings.pageScalePinchZoomEnabled); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 1469 | } |
| 1470 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1471 | void LayerTreeHostImpl::setFullRootLayerDamage() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1472 | { |
| 1473 | if (m_rootLayerImpl) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1474 | RenderSurfaceImpl* renderSurface = m_rootLayerImpl->renderSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1475 | if (renderSurface) |
| 1476 | renderSurface->damageTracker()->forceFullDamageNextUpdate(); |
| 1477 | } |
| 1478 | } |
| 1479 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 1480 | void LayerTreeHostImpl::animatePageScale(base::TimeTicks time) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1481 | { |
| 1482 | if (!m_pageScaleAnimation || !m_rootScrollLayerImpl) |
| 1483 | return; |
| 1484 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 1485 | double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1486 | gfx::Vector2dF scrollTotal = m_rootScrollLayerImpl->scrollOffset() + m_rootScrollLayerImpl->scrollDelta(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1487 | |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 1488 | setPageScaleDelta(m_pageScaleAnimation->pageScaleFactorAtTime(monotonicTime) / m_pinchZoomViewport.pageScaleFactor()); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 1489 | gfx::Vector2dF nextScroll = m_pageScaleAnimation->scrollOffsetAtTime(monotonicTime); |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 1490 | |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 1491 | if (!m_settings.pageScalePinchZoomEnabled) |
[email protected] | f625074 | 2012-11-09 04:46:56 | [diff] [blame] | 1492 | nextScroll.Scale(m_pinchZoomViewport.pageScaleFactor()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1493 | m_rootScrollLayerImpl->scrollBy(nextScroll - scrollTotal); |
| 1494 | m_client->setNeedsRedrawOnImplThread(); |
| 1495 | |
| 1496 | if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { |
[email protected] | 0023e8b | 2012-10-15 12:52:45 | [diff] [blame] | 1497 | m_pageScaleAnimation.reset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1498 | m_client->setNeedsCommitOnImplThread(); |
| 1499 | } |
| 1500 | } |
| 1501 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 1502 | void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1503 | { |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 1504 | if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers || !m_rootLayerImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1505 | return; |
| 1506 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1507 | TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1508 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1509 | scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEventsVector)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1510 | |
| 1511 | bool didAnimate = false; |
| 1512 | animateLayersRecursive(m_rootLayerImpl.get(), monotonicTime, wallClockTime, events.get(), didAnimate, m_needsAnimateLayers); |
| 1513 | |
[email protected] | d3143c73 | 2012-10-05 19:17:59 | [diff] [blame] | 1514 | if (!events->empty()) |
[email protected] | ec1d6d5 | 2012-10-10 01:28:57 | [diff] [blame] | 1515 | m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wallClockTime); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1516 | |
| 1517 | if (didAnimate) |
| 1518 | m_client->setNeedsRedrawOnImplThread(); |
| 1519 | |
| 1520 | setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers); |
| 1521 | } |
| 1522 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1523 | base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1524 | { |
[email protected] | 4481ddb62 | 2012-09-20 16:33:47 | [diff] [blame] | 1525 | return base::TimeDelta::FromSeconds(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1526 | } |
| 1527 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1528 | void LayerTreeHostImpl::sendDidLoseContextRecursive(LayerImpl* current) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1529 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 1530 | DCHECK(current); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1531 | current->didLoseContext(); |
| 1532 | if (current->maskLayer()) |
| 1533 | sendDidLoseContextRecursive(current->maskLayer()); |
| 1534 | if (current->replicaLayer()) |
| 1535 | sendDidLoseContextRecursive(current->replicaLayer()); |
| 1536 | for (size_t i = 0; i < current->children().size(); ++i) |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 1537 | sendDidLoseContextRecursive(current->children()[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1538 | } |
| 1539 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1540 | static void clearRenderSurfacesOnLayerImplRecursive(LayerImpl* current) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1541 | { |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 1542 | DCHECK(current); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1543 | for (size_t i = 0; i < current->children().size(); ++i) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1544 | clearRenderSurfacesOnLayerImplRecursive(current->children()[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1545 | current->clearRenderSurface(); |
| 1546 | } |
| 1547 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1548 | void LayerTreeHostImpl::clearRenderSurfaces() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1549 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1550 | clearRenderSurfacesOnLayerImplRecursive(m_rootLayerImpl.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1551 | m_renderSurfaceLayerList.clear(); |
| 1552 | } |
| 1553 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1554 | std::string LayerTreeHostImpl::layerTreeAsText() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1555 | { |
[email protected] | 515e8d23 | 2012-09-10 19:15:27 | [diff] [blame] | 1556 | std::string str; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1557 | if (m_rootLayerImpl) { |
[email protected] | 515e8d23 | 2012-09-10 19:15:27 | [diff] [blame] | 1558 | str = m_rootLayerImpl->layerTreeAsText(); |
| 1559 | str += "RenderSurfaces:\n"; |
| 1560 | dumpRenderSurfaces(&str, 1, m_rootLayerImpl.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1561 | } |
[email protected] | 515e8d23 | 2012-09-10 19:15:27 | [diff] [blame] | 1562 | return str; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1563 | } |
| 1564 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1565 | void LayerTreeHostImpl::dumpRenderSurfaces(std::string* str, int indent, const LayerImpl* layer) const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1566 | { |
| 1567 | if (layer->renderSurface()) |
[email protected] | 515e8d23 | 2012-09-10 19:15:27 | [diff] [blame] | 1568 | layer->renderSurface()->dumpSurface(str, indent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1569 | |
| 1570 | for (size_t i = 0; i < layer->children().size(); ++i) |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 1571 | dumpRenderSurfaces(str, indent, layer->children()[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1572 | } |
| 1573 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1574 | int LayerTreeHostImpl::sourceAnimationFrameNumber() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1575 | { |
| 1576 | return fpsCounter()->currentFrameNumber(); |
| 1577 | } |
| 1578 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1579 | void LayerTreeHostImpl::renderingStats(RenderingStats* stats) const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1580 | { |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 1581 | stats->numFramesSentToScreen = fpsCounter()->currentFrameNumber(); |
| 1582 | stats->droppedFrameCount = fpsCounter()->droppedFrameCount(); |
[email protected] | 5c6fe1f8 | 2012-10-03 18:00:27 | [diff] [blame] | 1583 | stats->numImplThreadScrolls = m_numImplThreadScrolls; |
| 1584 | stats->numMainThreadScrolls = m_numMainThreadScrolls; |
[email protected] | 9c2be6a | 2012-11-27 19:16:10 | [diff] [blame^] | 1585 | stats->numLayersInLayerTree = m_cumulativeNumLayersInLayerTree; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1586 | } |
| 1587 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 1588 | void LayerTreeHostImpl::animateScrollbars(base::TimeTicks time) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1589 | { |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 1590 | animateScrollbarsRecursive(m_rootLayerImpl.get(), time); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1591 | } |
| 1592 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 1593 | void LayerTreeHostImpl::animateScrollbarsRecursive(LayerImpl* layer, base::TimeTicks time) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1594 | { |
| 1595 | if (!layer) |
| 1596 | return; |
| 1597 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1598 | ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimationController(); |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 1599 | double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1600 | if (scrollbarController && scrollbarController->animate(monotonicTime)) |
| 1601 | m_client->setNeedsRedrawOnImplThread(); |
| 1602 | |
| 1603 | for (size_t i = 0; i < layer->children().size(); ++i) |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 1604 | animateScrollbarsRecursive(layer->children()[i], time); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1605 | } |
| 1606 | |
[email protected] | d3143c73 | 2012-10-05 19:17:59 | [diff] [blame] | 1607 | } // namespace cc |