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