[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0fb2500 | 2012-10-12 07:20:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 4 | |
[email protected] | 8fcbaa37 | 2012-11-05 04:12:41 | [diff] [blame] | 5 | #ifndef CC_LAYER_TREE_HOST_IMPL_H_ |
| 6 | #define CC_LAYER_TREE_HOST_IMPL_H_ |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 7 | |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 8 | #include "base/basictypes.h" |
| 9 | #include "base/memory/scoped_ptr.h" |
| 10 | #include "base/time.h" |
[email protected] | aa0a9d3 | 2012-10-24 01:58:10 | [diff] [blame] | 11 | #include "cc/animation_events.h" |
[email protected] | 0a9fd4d | 2012-12-07 07:37:08 | [diff] [blame] | 12 | #include "cc/animation_registrar.h" |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 13 | #include "cc/cc_export.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 14 | #include "cc/input_handler.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 15 | #include "cc/layer_tree_impl.h" |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 16 | #include "cc/output_surface_client.h" |
[email protected] | 55a124d0 | 2012-10-22 03:07:13 | [diff] [blame] | 17 | #include "cc/render_pass.h" |
| 18 | #include "cc/render_pass_sink.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 19 | #include "cc/renderer.h" |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 20 | #include "cc/tile_manager.h" |
[email protected] | ddf9df8 | 2012-10-16 06:52:46 | [diff] [blame] | 21 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | 167ed9d5 | 2012-10-31 20:47:58 | [diff] [blame] | 22 | #include "ui/gfx/rect.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 23 | |
| 24 | namespace cc { |
| 25 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 26 | class CompletionEvent; |
| 27 | class DebugRectHistory; |
| 28 | class FrameRateCounter; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 29 | class LayerImpl; |
| 30 | class LayerTreeHostImplTimeSourceAdapter; |
| 31 | class PageScaleAnimation; |
| 32 | class RenderPassDrawQuad; |
| 33 | class ResourceProvider; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 34 | struct RendererCapabilities; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 35 | struct RenderingStats; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 36 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 37 | // LayerTreeHost->Proxy callback interface. |
| 38 | class LayerTreeHostImplClient { |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 39 | public: |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 40 | virtual void didLoseOutputSurfaceOnImplThread() = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 41 | virtual void onSwapBuffersCompleteOnImplThread() = 0; |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 42 | virtual void onVSyncParametersChanged(base::TimeTicks timebase, base::TimeDelta interval) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 43 | virtual void onCanDrawStateChanged(bool canDraw) = 0; |
| 44 | virtual void setNeedsRedrawOnImplThread() = 0; |
| 45 | virtual void setNeedsCommitOnImplThread() = 0; |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 46 | virtual void setNeedsManageTilesOnImplThread() = 0; |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 47 | virtual void postAnimationEventsToMainThreadOnImplThread(scoped_ptr<AnimationEventsVector>, base::Time wallClockTime) = 0; |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 48 | // Returns true if resources were deleted by this call. |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 49 | virtual bool reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff) = 0; |
[email protected] | 3d21e02 | 2012-10-25 20:03:08 | [diff] [blame] | 50 | virtual void sendManagedMemoryStats() = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 51 | }; |
| 52 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 53 | // PinchZoomViewport models the bounds and offset of the viewport that is used during a pinch-zoom operation. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 54 | // It tracks the layout-space dimensions of the viewport before any applied scale, and then tracks the layout-space |
| 55 | // coordinates of the viewport respecting the pinch settings. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 56 | class PinchZoomViewport { |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 57 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 58 | PinchZoomViewport(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 59 | |
| 60 | float totalPageScaleFactor() const; |
| 61 | |
| 62 | void setPageScaleFactor(float factor) { m_pageScaleFactor = factor; } |
| 63 | float pageScaleFactor() const { return m_pageScaleFactor; } |
| 64 | |
| 65 | void setPageScaleDelta(float delta); |
| 66 | float pageScaleDelta() const { return m_pageScaleDelta; } |
| 67 | |
| 68 | float minPageScaleFactor() const { return m_minPageScaleFactor; } |
| 69 | float maxPageScaleFactor() const { return m_maxPageScaleFactor; } |
| 70 | |
| 71 | void setSentPageScaleDelta(float delta) { m_sentPageScaleDelta = delta; } |
| 72 | float sentPageScaleDelta() const { return m_sentPageScaleDelta; } |
| 73 | |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 74 | void setDeviceScaleFactor(float factor) { m_deviceScaleFactor = factor; } |
| 75 | float deviceScaleFactor() const { return m_deviceScaleFactor; } |
| 76 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 77 | // Returns true if the passed parameters were different from those previously |
| 78 | // cached. |
| 79 | bool setPageScaleFactorAndLimits(float pageScaleFactor, |
| 80 | float minPageScaleFactor, |
| 81 | float maxPageScaleFactor); |
| 82 | |
| 83 | // Returns the bounds and offset of the scaled and translated viewport to use for pinch-zoom. |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 84 | gfx::RectF bounds() const; |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 85 | const gfx::Vector2dF& zoomedViewportOffset() const { return m_zoomedViewportOffset; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 86 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 87 | void setLayoutViewportSize(const gfx::SizeF& size) { m_layoutViewportSize = size; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 88 | |
| 89 | // Apply the scroll offset in layout space to the offset of the pinch-zoom viewport. The viewport cannot be |
| 90 | // scrolled outside of the layout viewport bounds. Returns the component of the scroll that is un-applied due to |
| 91 | // this constraint. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 92 | gfx::Vector2dF applyScroll(const gfx::Vector2dF&); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 93 | |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 94 | // The implTransform goes from the origin of the unzoomedDeviceViewport to the |
| 95 | // origin of the zoomedDeviceViewport. |
| 96 | // |
| 97 | // implTransform = S[pageScale] * Tr[-zoomedDeviceViewportOffset] |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 98 | gfx::Transform implTransform(bool pageScalePinchZoomEnabled) const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 99 | |
| 100 | private: |
| 101 | float m_pageScaleFactor; |
| 102 | float m_pageScaleDelta; |
| 103 | float m_sentPageScaleDelta; |
| 104 | float m_maxPageScaleFactor; |
| 105 | float m_minPageScaleFactor; |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 106 | float m_deviceScaleFactor; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 107 | |
[email protected] | e39bf21 | 2012-11-22 21:04:03 | [diff] [blame] | 108 | gfx::Vector2dF m_zoomedViewportOffset; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 109 | gfx::SizeF m_layoutViewportSize; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 110 | }; |
| 111 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 112 | // LayerTreeHostImpl owns the LayerImpl tree as well as associated rendering state |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 113 | class CC_EXPORT LayerTreeHostImpl : public InputHandlerClient, |
| 114 | public RendererClient, |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 115 | public TileManagerClient, |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 116 | public LayerTreeImplClient, |
[email protected] | 0a9fd4d | 2012-12-07 07:37:08 | [diff] [blame] | 117 | public AnimationRegistrar, |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 118 | public OutputSurfaceClient { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 119 | typedef std::vector<LayerImpl*> LayerList; |
[email protected] | 0a9fd4d | 2012-12-07 07:37:08 | [diff] [blame] | 120 | typedef base::hash_set<LayerAnimationController*> AnimationControllerSet; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 121 | |
| 122 | public: |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 123 | static scoped_ptr<LayerTreeHostImpl> create(const LayerTreeSettings&, LayerTreeHostImplClient*, Proxy*); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 124 | virtual ~LayerTreeHostImpl(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 125 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 126 | // InputHandlerClient implementation |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 127 | virtual InputHandlerClient::ScrollStatus scrollBegin(gfx::Point, InputHandlerClient::ScrollInputType) OVERRIDE; |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 128 | virtual bool scrollBy(const gfx::Point&, const gfx::Vector2d&) OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 129 | virtual void scrollEnd() OVERRIDE; |
| 130 | virtual void pinchGestureBegin() OVERRIDE; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 131 | virtual void pinchGestureUpdate(float, gfx::Point) OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 132 | virtual void pinchGestureEnd() OVERRIDE; |
[email protected] | 69a2a5be | 2012-11-14 06:51:44 | [diff] [blame] | 133 | virtual void startPageScaleAnimation(gfx::Vector2d targetOffset, bool anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta duration) OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 134 | virtual void scheduleAnimation() OVERRIDE; |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 135 | virtual bool haveTouchEventHandlersAt(const gfx::Point&) OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 136 | |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 137 | struct CC_EXPORT FrameData : public RenderPassSink { |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 138 | FrameData(); |
| 139 | ~FrameData(); |
| 140 | |
[email protected] | 167ed9d5 | 2012-10-31 20:47:58 | [diff] [blame] | 141 | std::vector<gfx::Rect> occludingScreenSpaceRects; |
[email protected] | 4d8804e | 2012-11-15 01:51:10 | [diff] [blame] | 142 | std::vector<gfx::Rect> nonOccludingScreenSpaceRects; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 143 | RenderPassList renderPasses; |
| 144 | RenderPassIdHashMap renderPassesById; |
| 145 | LayerList* renderSurfaceLayerList; |
| 146 | LayerList willDrawLayers; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 147 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 148 | // RenderPassSink implementation. |
| 149 | virtual void appendRenderPass(scoped_ptr<RenderPass>) OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | // Virtual for testing. |
| 153 | virtual void beginCommit(); |
| 154 | virtual void commitComplete(); |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 155 | virtual void animate(base::TimeTicks monotonicTime, base::Time wallClockTime); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 156 | |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 157 | void manageTiles(); |
| 158 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 159 | // Returns false if problems occured preparing the frame, and we should try |
| 160 | // to avoid displaying the frame. If prepareToDraw is called, |
| 161 | // didDrawAllLayers must also be called, regardless of whether drawLayers is |
| 162 | // called between the two. |
| 163 | virtual bool prepareToDraw(FrameData&); |
[email protected] | 85167c7 | 2012-12-04 03:56:07 | [diff] [blame] | 164 | virtual void drawLayers(FrameData&); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 165 | // Must be called if and only if prepareToDraw was called. |
| 166 | void didDrawAllLayers(const FrameData&); |
| 167 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 168 | // RendererClient implementation |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 169 | virtual const gfx::Size& deviceViewportSize() const OVERRIDE; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 170 | virtual const LayerTreeSettings& settings() const OVERRIDE; |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 171 | virtual void didLoseOutputSurface() OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 172 | virtual void onSwapBuffersComplete() OVERRIDE; |
| 173 | virtual void setFullRootLayerDamage() OVERRIDE; |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 174 | virtual void setManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE; |
| 175 | virtual void enforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE; |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 176 | virtual bool hasImplThread() const OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 177 | |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 178 | // TileManagerClient implementation. |
| 179 | virtual void ScheduleManageTiles() OVERRIDE; |
[email protected] | d142a47d | 2012-12-07 08:18:37 | [diff] [blame] | 180 | virtual void ScheduleCheckForCompletedSetPixels() OVERRIDE; |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 181 | |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 182 | // OutputSurfaceClient implementation. |
| 183 | virtual void OnVSyncParametersChanged(base::TimeTicks timebase, base::TimeDelta interval) OVERRIDE; |
| 184 | virtual void OnSendFrameToParentCompositorAck(const CompositorFrameAck&) OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 185 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 186 | // LayerTreeImplClient implementation. |
| 187 | virtual void OnCanDrawStateChangedForTree(LayerTreeImpl*) OVERRIDE; |
| 188 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 189 | // Implementation |
| 190 | bool canDraw(); |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 191 | OutputSurface* outputSurface() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 192 | |
| 193 | std::string layerTreeAsText() const; |
| 194 | |
| 195 | void finishAllRendering(); |
| 196 | int sourceAnimationFrameNumber() const; |
| 197 | |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 198 | bool initializeRenderer(scoped_ptr<OutputSurface>); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 199 | bool isContextLost(); |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 200 | TileManager* tileManager() { return m_tileManager.get(); } |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 201 | Renderer* renderer() { return m_renderer.get(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 202 | const RendererCapabilities& rendererCapabilities() const; |
| 203 | |
| 204 | bool swapBuffers(); |
| 205 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 206 | void readback(void* pixels, const gfx::Rect&); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 207 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 208 | LayerTreeImpl* activeTree() { return m_activeTree.get(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 209 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 210 | // TODO(nduca): Remove these in favor of LayerTreeImpl. |
| 211 | void setRootLayer(scoped_ptr<LayerImpl>); |
| 212 | LayerImpl* rootLayer() const { return m_activeTree->RootLayer(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 213 | |
| 214 | // Release ownership of the current layer tree and replace it with an empty |
| 215 | // tree. Returns the root layer of the detached tree. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 216 | scoped_ptr<LayerImpl> detachLayerTree(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 217 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 218 | LayerImpl* rootScrollLayer() const { return m_activeTree->root_scroll_layer(); } |
| 219 | |
| 220 | // TOOD(nduca): This goes away when scrolling moves to LayerTreeImpl. |
| 221 | LayerImpl* currentlyScrollingLayer() const { return m_activeTree->currently_scrolling_layer(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 222 | |
| 223 | bool visible() const { return m_visible; } |
| 224 | void setVisible(bool); |
| 225 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 226 | bool contentsTexturesPurged() const { return m_contentsTexturesPurged; } |
| 227 | void setContentsTexturesPurged(); |
| 228 | void resetContentsTexturesPurged(); |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 229 | size_t memoryAllocationLimitBytes() const { return m_managedMemoryPolicy.bytesLimitWhenVisible; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 230 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 231 | void setViewportSize(const gfx::Size& layoutViewportSize, const gfx::Size& deviceViewportSize); |
| 232 | const gfx::Size& layoutViewportSize() const { return m_layoutViewportSize; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 233 | |
| 234 | float deviceScaleFactor() const { return m_deviceScaleFactor; } |
| 235 | void setDeviceScaleFactor(float); |
| 236 | |
| 237 | float pageScaleFactor() const; |
| 238 | void setPageScaleFactorAndLimits(float pageScaleFactor, float minPageScaleFactor, float maxPageScaleFactor); |
| 239 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 240 | scoped_ptr<ScrollAndScaleSet> processScrollDeltas(); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 241 | gfx::Transform implTransform() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 242 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 243 | void startPageScaleAnimation(gfx::Vector2d targetOffset, bool useAnchor, float scale, base::TimeDelta duration); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 244 | |
| 245 | SkColor backgroundColor() const { return m_backgroundColor; } |
| 246 | void setBackgroundColor(SkColor color) { m_backgroundColor = color; } |
| 247 | |
| 248 | bool hasTransparentBackground() const { return m_hasTransparentBackground; } |
| 249 | void setHasTransparentBackground(bool transparent) { m_hasTransparentBackground = transparent; } |
[email protected] | 0a9fd4d | 2012-12-07 07:37:08 | [diff] [blame] | 250 | bool needsAnimateLayers() const { return !m_activeAnimationControllers.empty(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 251 | |
| 252 | void setNeedsRedraw(); |
| 253 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 254 | void renderingStats(RenderingStats*) const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 255 | |
| 256 | void updateRootScrollLayerImplTransform(); |
| 257 | |
[email protected] | d3afa11 | 2012-12-08 06:24:28 | [diff] [blame^] | 258 | void sendManagedMemoryStats( |
| 259 | size_t memoryVisibleBytes, |
| 260 | size_t memoryVisibleAndNearbyBytes, |
| 261 | size_t memoryUseBytes); |
| 262 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 263 | FrameRateCounter* fpsCounter() const { return m_fpsCounter.get(); } |
| 264 | DebugRectHistory* debugRectHistory() const { return m_debugRectHistory.get(); } |
| 265 | ResourceProvider* resourceProvider() const { return m_resourceProvider.get(); } |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 266 | Proxy* proxy() const { return m_proxy; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 267 | |
[email protected] | f511afb | 2012-11-30 01:55:20 | [diff] [blame] | 268 | void setDebugState(const LayerTreeDebugState& debugState) { m_debugState = debugState; } |
| 269 | const LayerTreeDebugState& debugState() const { return m_debugState; } |
| 270 | |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 271 | class CC_EXPORT CullRenderPassesWithCachedTextures { |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 272 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 273 | bool shouldRemoveRenderPass(const RenderPassDrawQuad&, const FrameData&) const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 274 | |
| 275 | // Iterates from the root first, in order to remove the surfaces closest |
| 276 | // to the root with cached textures, and all surfaces that draw into |
| 277 | // them. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 278 | size_t renderPassListBegin(const RenderPassList& list) const { return list.size() - 1; } |
| 279 | size_t renderPassListEnd(const RenderPassList&) const { return 0 - 1; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 280 | size_t renderPassListNext(size_t it) const { return it - 1; } |
| 281 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 282 | CullRenderPassesWithCachedTextures(Renderer& renderer) : m_renderer(renderer) { } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 283 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 284 | Renderer& m_renderer; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 285 | }; |
| 286 | |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 287 | class CC_EXPORT CullRenderPassesWithNoQuads { |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 288 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 289 | bool shouldRemoveRenderPass(const RenderPassDrawQuad&, const FrameData&) const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 290 | |
| 291 | // Iterates in draw order, so that when a surface is removed, and its |
| 292 | // target becomes empty, then its target can be removed also. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 293 | size_t renderPassListBegin(const RenderPassList&) const { return 0; } |
| 294 | size_t renderPassListEnd(const RenderPassList& list) const { return list.size(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 295 | size_t renderPassListNext(size_t it) const { return it + 1; } |
| 296 | }; |
| 297 | |
| 298 | template<typename RenderPassCuller> |
| 299 | static void removeRenderPasses(RenderPassCuller, FrameData&); |
| 300 | |
| 301 | protected: |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 302 | LayerTreeHostImpl(const LayerTreeSettings&, LayerTreeHostImplClient*, Proxy*); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 303 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 304 | void animatePageScale(base::TimeTicks monotonicTime); |
| 305 | void animateScrollbars(base::TimeTicks monotonicTime); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 306 | |
| 307 | // Exposed for testing. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 308 | void calculateRenderSurfaceLayerList(LayerList&); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 309 | |
| 310 | // Virtual for testing. |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 311 | virtual void animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 312 | |
| 313 | // Virtual for testing. |
| 314 | virtual base::TimeDelta lowFrequencyAnimationInterval() const; |
| 315 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 316 | LayerTreeHostImplClient* m_client; |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 317 | Proxy* m_proxy; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 318 | |
| 319 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 320 | void computeDoubleTapZoomDeltas(ScrollAndScaleSet* scrollInfo); |
| 321 | void computePinchZoomDeltas(ScrollAndScaleSet* scrollInfo); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 322 | void makeScrollAndScaleSet(ScrollAndScaleSet* scrollInfo, gfx::Vector2d scrollOffset, float pageScale); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 323 | |
| 324 | void setPageScaleDelta(float); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 325 | void updateMaxScrollOffset(); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 326 | void trackDamageForAllSurfaces(LayerImpl* rootDrawLayer, const LayerList& renderSurfaceLayerList); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 327 | |
| 328 | // Returns false if the frame should not be displayed. This function should |
| 329 | // only be called from prepareToDraw, as didDrawAllLayers must be called |
| 330 | // if this helper function is called. |
| 331 | bool calculateRenderPasses(FrameData&); |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 332 | void animateLayersRecursive(LayerImpl*, base::TimeTicks monotonicTime, base::Time wallClockTime, AnimationEventsVector*, bool& didAnimate, bool& needsAnimateLayers); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 333 | void setBackgroundTickingEnabled(bool); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 334 | gfx::Size contentSize() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 335 | |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 336 | void sendDidLoseOutputSurfaceRecursive(LayerImpl*); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 337 | void clearRenderSurfaces(); |
| 338 | bool ensureRenderSurfaceLayerList(); |
| 339 | void clearCurrentlyScrollingLayer(); |
| 340 | |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 341 | void animateScrollbarsRecursive(LayerImpl*, base::TimeTicks monotonicTime); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 342 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 343 | void dumpRenderSurfaces(std::string*, int indent, const LayerImpl*) const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 344 | |
[email protected] | 0a9fd4d | 2012-12-07 07:37:08 | [diff] [blame] | 345 | // AnimationRegistar implementation. |
| 346 | virtual void DidActivateAnimationController(LayerAnimationController*) OVERRIDE; |
| 347 | virtual void DidDeactivateAnimationController(LayerAnimationController*) OVERRIDE; |
| 348 | virtual void RegisterAnimationController(LayerAnimationController*) OVERRIDE; |
| 349 | virtual void UnregisterAnimationController(LayerAnimationController*) OVERRIDE; |
| 350 | |
[email protected] | 3be2171d | 2012-12-06 06:13:20 | [diff] [blame] | 351 | scoped_ptr<OutputSurface> m_outputSurface; |
[email protected] | 0a9fd4d | 2012-12-07 07:37:08 | [diff] [blame] | 352 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 353 | scoped_ptr<ResourceProvider> m_resourceProvider; |
| 354 | scoped_ptr<Renderer> m_renderer; |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 355 | scoped_ptr<TileManager> m_tileManager; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 356 | |
| 357 | scoped_ptr<LayerTreeImpl> m_activeTree; |
| 358 | |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 359 | bool m_scrollDeltaIsInViewportSpace; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 360 | LayerTreeSettings m_settings; |
[email protected] | f511afb | 2012-11-30 01:55:20 | [diff] [blame] | 361 | LayerTreeDebugState m_debugState; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 362 | gfx::Size m_layoutViewportSize; |
| 363 | gfx::Size m_deviceViewportSize; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 364 | float m_deviceScaleFactor; |
| 365 | bool m_visible; |
| 366 | bool m_contentsTexturesPurged; |
[email protected] | a0a0084 | 2012-10-22 22:50:28 | [diff] [blame] | 367 | ManagedMemoryPolicy m_managedMemoryPolicy; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 368 | |
| 369 | SkColor m_backgroundColor; |
| 370 | bool m_hasTransparentBackground; |
| 371 | |
| 372 | // If this is true, it is necessary to traverse the layer tree ticking the animators. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 373 | bool m_pinchGestureActive; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 374 | gfx::Point m_previousPinchAnchor; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 375 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 376 | scoped_ptr<PageScaleAnimation> m_pageScaleAnimation; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 377 | |
| 378 | // This is used for ticking animations slowly when hidden. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 379 | scoped_ptr<LayerTreeHostImplTimeSourceAdapter> m_timeSourceClientAdapter; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 380 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 381 | // List of visible layers for the most recently prepared frame. Used for |
| 382 | // rendering and input event hit testing. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 383 | LayerList m_renderSurfaceLayerList; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 384 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 385 | PinchZoomViewport m_pinchZoomViewport; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 386 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 387 | scoped_ptr<FrameRateCounter> m_fpsCounter; |
| 388 | scoped_ptr<DebugRectHistory> m_debugRectHistory; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 389 | |
[email protected] | f2bbb4e | 2012-12-07 21:40:49 | [diff] [blame] | 390 | int64 m_numImplThreadScrolls; |
| 391 | int64 m_numMainThreadScrolls; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 392 | |
[email protected] | f2bbb4e | 2012-12-07 21:40:49 | [diff] [blame] | 393 | int64 m_cumulativeNumLayersDrawn; |
| 394 | |
| 395 | int64 m_cumulativeNumMissingTiles; |
[email protected] | 9c2be6a | 2012-11-27 19:16:10 | [diff] [blame] | 396 | |
[email protected] | 0a9fd4d | 2012-12-07 07:37:08 | [diff] [blame] | 397 | AnimationControllerSet m_activeAnimationControllers; |
| 398 | |
| 399 | #if !defined(NDEBUG) |
| 400 | AnimationControllerSet m_allAnimationControllers; |
| 401 | #endif |
| 402 | |
[email protected] | d3afa11 | 2012-12-08 06:24:28 | [diff] [blame^] | 403 | size_t m_lastSentMemoryVisibleBytes; |
| 404 | size_t m_lastSentMemoryVisibleAndNearbyBytes; |
| 405 | size_t m_lastSentMemoryUseBytes; |
| 406 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 407 | DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 408 | }; |
| 409 | |
[email protected] | 0023e8b | 2012-10-15 12:52:45 | [diff] [blame] | 410 | } // namespace cc |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 411 | |
[email protected] | 8fcbaa37 | 2012-11-05 04:12:41 | [diff] [blame] | 412 | #endif // CC_LAYER_TREE_HOST_IMPL_H_ |