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