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