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