OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CCLayerTreeHost_h | 5 #ifndef CCLayerTreeHost_h |
6 #define CCLayerTreeHost_h | 6 #define CCLayerTreeHost_h |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 struct hash<WebKit::WebGraphicsContext3D*> { | 29 struct hash<WebKit::WebGraphicsContext3D*> { |
30 size_t operator()(WebKit::WebGraphicsContext3D* ptr) const { | 30 size_t operator()(WebKit::WebGraphicsContext3D* ptr) const { |
31 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); | 31 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); |
32 } | 32 } |
33 }; | 33 }; |
34 } // namespace BASE_HASH_NAMESPACE | 34 } // namespace BASE_HASH_NAMESPACE |
35 #endif // COMPILER | 35 #endif // COMPILER |
36 | 36 |
37 namespace cc { | 37 namespace cc { |
38 | 38 |
39 class CCFontAtlas; | 39 class FontAtlas; |
40 class CCLayerChromium; | 40 class Layer; |
41 class CCLayerTreeHostImpl; | 41 class LayerTreeHostImpl; |
42 class CCLayerTreeHostImplClient; | 42 class LayerTreeHostImplClient; |
43 class CCPrioritizedTextureManager; | 43 class PrioritizedTextureManager; |
44 class CCTextureUpdateQueue; | 44 class TextureUpdateQueue; |
45 class HeadsUpDisplayLayerChromium; | 45 class HeadsUpDisplayLayer; |
46 class Region; | 46 class Region; |
47 struct CCScrollAndScaleSet; | 47 struct ScrollAndScaleSet; |
48 | 48 |
49 struct CCLayerTreeSettings { | 49 struct LayerTreeSettings { |
50 CCLayerTreeSettings(); | 50 LayerTreeSettings(); |
51 ~CCLayerTreeSettings(); | 51 ~LayerTreeSettings(); |
52 | 52 |
53 bool acceleratePainting; | 53 bool acceleratePainting; |
54 bool showFPSCounter; | 54 bool showFPSCounter; |
55 bool showPlatformLayerTree; | 55 bool showPlatformLayerTree; |
56 bool showPaintRects; | 56 bool showPaintRects; |
57 bool showPropertyChangedRects; | 57 bool showPropertyChangedRects; |
58 bool showSurfaceDamageRects; | 58 bool showSurfaceDamageRects; |
59 bool showScreenSpaceRects; | 59 bool showScreenSpaceRects; |
60 bool showReplicaScreenSpaceRects; | 60 bool showReplicaScreenSpaceRects; |
61 bool showOccludingRects; | 61 bool showOccludingRects; |
62 bool renderVSyncEnabled; | 62 bool renderVSyncEnabled; |
63 double refreshRate; | 63 double refreshRate; |
64 size_t maxPartialTextureUpdates; | 64 size_t maxPartialTextureUpdates; |
65 IntSize defaultTileSize; | 65 IntSize defaultTileSize; |
66 IntSize maxUntiledLayerSize; | 66 IntSize maxUntiledLayerSize; |
67 IntSize minimumOcclusionTrackingSize; | 67 IntSize minimumOcclusionTrackingSize; |
68 | 68 |
69 bool showDebugInfo() const { return showPlatformLayerTree || showFPSCounter
|| showDebugRects(); } | 69 bool showDebugInfo() const { return showPlatformLayerTree || showFPSCounter
|| showDebugRects(); } |
70 bool showDebugRects() const { return showPaintRects || showPropertyChangedRe
cts || showSurfaceDamageRects || showScreenSpaceRects || showReplicaScreenSpaceR
ects || showOccludingRects; } | 70 bool showDebugRects() const { return showPaintRects || showPropertyChangedRe
cts || showSurfaceDamageRects || showScreenSpaceRects || showReplicaScreenSpaceR
ects || showOccludingRects; } |
71 }; | 71 }; |
72 | 72 |
73 // Provides information on an Impl's rendering capabilities back to the CCLayerT
reeHost | 73 // Provides information on an Impl's rendering capabilities back to the LayerTre
eHost |
74 struct RendererCapabilities { | 74 struct RendererCapabilities { |
75 RendererCapabilities(); | 75 RendererCapabilities(); |
76 ~RendererCapabilities(); | 76 ~RendererCapabilities(); |
77 | 77 |
78 GC3Denum bestTextureFormat; | 78 GC3Denum bestTextureFormat; |
79 bool contextHasCachedFrontBuffer; | 79 bool contextHasCachedFrontBuffer; |
80 bool usingPartialSwap; | 80 bool usingPartialSwap; |
81 bool usingAcceleratedPainting; | 81 bool usingAcceleratedPainting; |
82 bool usingSetVisibility; | 82 bool usingSetVisibility; |
83 bool usingSwapCompleteCallback; | 83 bool usingSwapCompleteCallback; |
84 bool usingGpuMemoryManager; | 84 bool usingGpuMemoryManager; |
85 bool usingDiscardFramebuffer; | 85 bool usingDiscardFramebuffer; |
86 bool usingEglImage; | 86 bool usingEglImage; |
87 int maxTextureSize; | 87 int maxTextureSize; |
88 }; | 88 }; |
89 | 89 |
90 class CCLayerTreeHost : public RateLimiterClient { | 90 class LayerTreeHost : public RateLimiterClient { |
91 public: | 91 public: |
92 static scoped_ptr<CCLayerTreeHost> create(CCLayerTreeHostClient*, const CCLa
yerTreeSettings&); | 92 static scoped_ptr<LayerTreeHost> create(LayerTreeHostClient*, const LayerTre
eSettings&); |
93 virtual ~CCLayerTreeHost(); | 93 virtual ~LayerTreeHost(); |
94 | 94 |
95 void setSurfaceReady(); | 95 void setSurfaceReady(); |
96 | 96 |
97 // Returns true if any CCLayerTreeHost is alive. | 97 // Returns true if any LayerTreeHost is alive. |
98 static bool anyLayerTreeHostInstanceExists(); | 98 static bool anyLayerTreeHostInstanceExists(); |
99 | 99 |
100 static bool needsFilterContext() { return s_needsFilterContext; } | 100 static bool needsFilterContext() { return s_needsFilterContext; } |
101 static void setNeedsFilterContext(bool needsFilterContext) { s_needsFilterCo
ntext = needsFilterContext; } | 101 static void setNeedsFilterContext(bool needsFilterContext) { s_needsFilterCo
ntext = needsFilterContext; } |
102 bool needsSharedContext() const { return needsFilterContext() || settings().
acceleratePainting; } | 102 bool needsSharedContext() const { return needsFilterContext() || settings().
acceleratePainting; } |
103 | 103 |
104 // CCLayerTreeHost interface to CCProxy. | 104 // LayerTreeHost interface to Proxy. |
105 void willBeginFrame() { m_client->willBeginFrame(); } | 105 void willBeginFrame() { m_client->willBeginFrame(); } |
106 void didBeginFrame() { m_client->didBeginFrame(); } | 106 void didBeginFrame() { m_client->didBeginFrame(); } |
107 void updateAnimations(double monotonicFrameBeginTime); | 107 void updateAnimations(double monotonicFrameBeginTime); |
108 void layout(); | 108 void layout(); |
109 void beginCommitOnImplThread(CCLayerTreeHostImpl*); | 109 void beginCommitOnImplThread(LayerTreeHostImpl*); |
110 void finishCommitOnImplThread(CCLayerTreeHostImpl*); | 110 void finishCommitOnImplThread(LayerTreeHostImpl*); |
111 void willCommit(); | 111 void willCommit(); |
112 void commitComplete(); | 112 void commitComplete(); |
113 scoped_ptr<CCGraphicsContext> createContext(); | 113 scoped_ptr<GraphicsContext> createContext(); |
114 scoped_ptr<CCInputHandler> createInputHandler(); | 114 scoped_ptr<InputHandler> createInputHandler(); |
115 virtual scoped_ptr<CCLayerTreeHostImpl> createLayerTreeHostImpl(CCLayerTreeH
ostImplClient*); | 115 virtual scoped_ptr<LayerTreeHostImpl> createLayerTreeHostImpl(LayerTreeHostI
mplClient*); |
116 void didLoseContext(); | 116 void didLoseContext(); |
117 enum RecreateResult { | 117 enum RecreateResult { |
118 RecreateSucceeded, | 118 RecreateSucceeded, |
119 RecreateFailedButTryAgain, | 119 RecreateFailedButTryAgain, |
120 RecreateFailedAndGaveUp, | 120 RecreateFailedAndGaveUp, |
121 }; | 121 }; |
122 RecreateResult recreateContext(); | 122 RecreateResult recreateContext(); |
123 void didCommitAndDrawFrame() { m_client->didCommitAndDrawFrame(); } | 123 void didCommitAndDrawFrame() { m_client->didCommitAndDrawFrame(); } |
124 void didCompleteSwapBuffers() { m_client->didCompleteSwapBuffers(); } | 124 void didCompleteSwapBuffers() { m_client->didCompleteSwapBuffers(); } |
125 void deleteContentsTexturesOnImplThread(CCResourceProvider*); | 125 void deleteContentsTexturesOnImplThread(ResourceProvider*); |
126 virtual void acquireLayerTextures(); | 126 virtual void acquireLayerTextures(); |
127 // Returns false if we should abort this frame due to initialization failure
. | 127 // Returns false if we should abort this frame due to initialization failure
. |
128 bool initializeRendererIfNeeded(); | 128 bool initializeRendererIfNeeded(); |
129 void updateLayers(CCTextureUpdateQueue&, size_t contentsMemoryLimitBytes); | 129 void updateLayers(TextureUpdateQueue&, size_t contentsMemoryLimitBytes); |
130 | 130 |
131 CCLayerTreeHostClient* client() { return m_client; } | 131 LayerTreeHostClient* client() { return m_client; } |
132 | 132 |
133 // Only used when compositing on the main thread. | 133 // Only used when compositing on the main thread. |
134 void composite(); | 134 void composite(); |
135 void scheduleComposite(); | 135 void scheduleComposite(); |
136 | 136 |
137 // Composites and attempts to read back the result into the provided | 137 // Composites and attempts to read back the result into the provided |
138 // buffer. If it wasn't possible, e.g. due to context lost, will return | 138 // buffer. If it wasn't possible, e.g. due to context lost, will return |
139 // false. | 139 // false. |
140 bool compositeAndReadback(void *pixels, const IntRect&); | 140 bool compositeAndReadback(void *pixels, const IntRect&); |
141 | 141 |
142 void finishAllRendering(); | 142 void finishAllRendering(); |
143 | 143 |
144 int commitNumber() const { return m_commitNumber; } | 144 int commitNumber() const { return m_commitNumber; } |
145 | 145 |
146 void renderingStats(CCRenderingStats*) const; | 146 void renderingStats(RenderingStats*) const; |
147 | 147 |
148 const RendererCapabilities& rendererCapabilities() const; | 148 const RendererCapabilities& rendererCapabilities() const; |
149 | 149 |
150 // Test only hook | 150 // Test only hook |
151 void loseContext(int numTimes); | 151 void loseContext(int numTimes); |
152 | 152 |
153 void setNeedsAnimate(); | 153 void setNeedsAnimate(); |
154 // virtual for testing | 154 // virtual for testing |
155 virtual void setNeedsCommit(); | 155 virtual void setNeedsCommit(); |
156 void setNeedsRedraw(); | 156 void setNeedsRedraw(); |
157 bool commitRequested() const; | 157 bool commitRequested() const; |
158 | 158 |
159 void setAnimationEvents(scoped_ptr<CCAnimationEventsVector>, double wallCloc
kTime); | 159 void setAnimationEvents(scoped_ptr<AnimationEventsVector>, double wallClockT
ime); |
160 virtual void didAddAnimation(); | 160 virtual void didAddAnimation(); |
161 | 161 |
162 LayerChromium* rootLayer() { return m_rootLayer.get(); } | 162 Layer* rootLayer() { return m_rootLayer.get(); } |
163 const LayerChromium* rootLayer() const { return m_rootLayer.get(); } | 163 const Layer* rootLayer() const { return m_rootLayer.get(); } |
164 void setRootLayer(scoped_refptr<LayerChromium>); | 164 void setRootLayer(scoped_refptr<Layer>); |
165 | 165 |
166 const CCLayerTreeSettings& settings() const { return m_settings; } | 166 const LayerTreeSettings& settings() const { return m_settings; } |
167 | 167 |
168 void setViewportSize(const IntSize& layoutViewportSize, const IntSize& devic
eViewportSize); | 168 void setViewportSize(const IntSize& layoutViewportSize, const IntSize& devic
eViewportSize); |
169 | 169 |
170 const IntSize& layoutViewportSize() const { return m_layoutViewportSize; } | 170 const IntSize& layoutViewportSize() const { return m_layoutViewportSize; } |
171 const IntSize& deviceViewportSize() const { return m_deviceViewportSize; } | 171 const IntSize& deviceViewportSize() const { return m_deviceViewportSize; } |
172 | 172 |
173 void setPageScaleFactorAndLimits(float pageScaleFactor, float minPageScaleFa
ctor, float maxPageScaleFactor); | 173 void setPageScaleFactorAndLimits(float pageScaleFactor, float minPageScaleFa
ctor, float maxPageScaleFactor); |
174 | 174 |
175 void setBackgroundColor(SkColor color) { m_backgroundColor = color; } | 175 void setBackgroundColor(SkColor color) { m_backgroundColor = color; } |
176 | 176 |
177 void setHasTransparentBackground(bool transparent) { m_hasTransparentBackgro
und = transparent; } | 177 void setHasTransparentBackground(bool transparent) { m_hasTransparentBackgro
und = transparent; } |
178 | 178 |
179 CCPrioritizedTextureManager* contentsTextureManager() const; | 179 PrioritizedTextureManager* contentsTextureManager() const; |
180 | 180 |
181 bool visible() const { return m_visible; } | 181 bool visible() const { return m_visible; } |
182 void setVisible(bool); | 182 void setVisible(bool); |
183 | 183 |
184 void startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor,
float scale, double durationSec); | 184 void startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor,
float scale, double durationSec); |
185 | 185 |
186 void applyScrollAndScale(const CCScrollAndScaleSet&); | 186 void applyScrollAndScale(const ScrollAndScaleSet&); |
187 void setImplTransform(const WebKit::WebTransformationMatrix&); | 187 void setImplTransform(const WebKit::WebTransformationMatrix&); |
188 | 188 |
189 void startRateLimiter(WebKit::WebGraphicsContext3D*); | 189 void startRateLimiter(WebKit::WebGraphicsContext3D*); |
190 void stopRateLimiter(WebKit::WebGraphicsContext3D*); | 190 void stopRateLimiter(WebKit::WebGraphicsContext3D*); |
191 | 191 |
192 // RateLimitClient implementation | 192 // RateLimitClient implementation |
193 virtual void rateLimit() OVERRIDE; | 193 virtual void rateLimit() OVERRIDE; |
194 | 194 |
195 bool bufferedUpdates(); | 195 bool bufferedUpdates(); |
196 bool requestPartialTextureUpdate(); | 196 bool requestPartialTextureUpdate(); |
197 void deleteTextureAfterCommit(scoped_ptr<CCPrioritizedTexture>); | 197 void deleteTextureAfterCommit(scoped_ptr<PrioritizedTexture>); |
198 | 198 |
199 void setDeviceScaleFactor(float); | 199 void setDeviceScaleFactor(float); |
200 float deviceScaleFactor() const { return m_deviceScaleFactor; } | 200 float deviceScaleFactor() const { return m_deviceScaleFactor; } |
201 | 201 |
202 void setFontAtlas(scoped_ptr<CCFontAtlas>); | 202 void setFontAtlas(scoped_ptr<FontAtlas>); |
203 | 203 |
204 HeadsUpDisplayLayerChromium* hudLayer() const { return m_hudLayer.get(); } | 204 HeadsUpDisplayLayer* hudLayer() const { return m_hudLayer.get(); } |
205 | 205 |
206 protected: | 206 protected: |
207 CCLayerTreeHost(CCLayerTreeHostClient*, const CCLayerTreeSettings&); | 207 LayerTreeHost(LayerTreeHostClient*, const LayerTreeSettings&); |
208 bool initialize(); | 208 bool initialize(); |
209 | 209 |
210 private: | 210 private: |
211 typedef std::vector<scoped_refptr<LayerChromium> > LayerList; | 211 typedef std::vector<scoped_refptr<Layer> > LayerList; |
212 | 212 |
213 void initializeRenderer(); | 213 void initializeRenderer(); |
214 | 214 |
215 void update(LayerChromium*, CCTextureUpdateQueue&, const CCOcclusionTracker*
); | 215 void update(Layer*, TextureUpdateQueue&, const OcclusionTracker*); |
216 bool paintLayerContents(const LayerList&, CCTextureUpdateQueue&); | 216 bool paintLayerContents(const LayerList&, TextureUpdateQueue&); |
217 bool paintMasksForRenderSurface(LayerChromium*, CCTextureUpdateQueue&); | 217 bool paintMasksForRenderSurface(Layer*, TextureUpdateQueue&); |
218 | 218 |
219 void updateLayers(LayerChromium*, CCTextureUpdateQueue&); | 219 void updateLayers(Layer*, TextureUpdateQueue&); |
220 | 220 |
221 void prioritizeTextures(const LayerList&, CCOverdrawMetrics&); | 221 void prioritizeTextures(const LayerList&, OverdrawMetrics&); |
222 void setPrioritiesForSurfaces(size_t surfaceMemoryBytes); | 222 void setPrioritiesForSurfaces(size_t surfaceMemoryBytes); |
223 void setPrioritiesForLayers(const LayerList&); | 223 void setPrioritiesForLayers(const LayerList&); |
224 size_t calculateMemoryForRenderSurfaces(const LayerList& updateList); | 224 size_t calculateMemoryForRenderSurfaces(const LayerList& updateList); |
225 | 225 |
226 void animateLayers(double monotonicTime); | 226 void animateLayers(double monotonicTime); |
227 bool animateLayersRecursive(LayerChromium* current, double monotonicTime); | 227 bool animateLayersRecursive(Layer* current, double monotonicTime); |
228 void setAnimationEventsRecursive(const CCAnimationEventsVector&, LayerChromi
um*, double wallClockTime); | 228 void setAnimationEventsRecursive(const AnimationEventsVector&, Layer*, doubl
e wallClockTime); |
229 | 229 |
230 bool m_animating; | 230 bool m_animating; |
231 bool m_needsAnimateLayers; | 231 bool m_needsAnimateLayers; |
232 | 232 |
233 CCLayerTreeHostClient* m_client; | 233 LayerTreeHostClient* m_client; |
234 | 234 |
235 int m_commitNumber; | 235 int m_commitNumber; |
236 CCRenderingStats m_renderingStats; | 236 RenderingStats m_renderingStats; |
237 | 237 |
238 scoped_ptr<CCProxy> m_proxy; | 238 scoped_ptr<Proxy> m_proxy; |
239 bool m_rendererInitialized; | 239 bool m_rendererInitialized; |
240 bool m_contextLost; | 240 bool m_contextLost; |
241 int m_numTimesRecreateShouldFail; | 241 int m_numTimesRecreateShouldFail; |
242 int m_numFailedRecreateAttempts; | 242 int m_numFailedRecreateAttempts; |
243 | 243 |
244 scoped_refptr<LayerChromium> m_rootLayer; | 244 scoped_refptr<Layer> m_rootLayer; |
245 scoped_refptr<HeadsUpDisplayLayerChromium> m_hudLayer; | 245 scoped_refptr<HeadsUpDisplayLayer> m_hudLayer; |
246 scoped_ptr<CCFontAtlas> m_fontAtlas; | 246 scoped_ptr<FontAtlas> m_fontAtlas; |
247 | 247 |
248 scoped_ptr<CCPrioritizedTextureManager> m_contentsTextureManager; | 248 scoped_ptr<PrioritizedTextureManager> m_contentsTextureManager; |
249 scoped_ptr<CCPrioritizedTexture> m_surfaceMemoryPlaceholder; | 249 scoped_ptr<PrioritizedTexture> m_surfaceMemoryPlaceholder; |
250 | 250 |
251 CCLayerTreeSettings m_settings; | 251 LayerTreeSettings m_settings; |
252 | 252 |
253 IntSize m_layoutViewportSize; | 253 IntSize m_layoutViewportSize; |
254 IntSize m_deviceViewportSize; | 254 IntSize m_deviceViewportSize; |
255 float m_deviceScaleFactor; | 255 float m_deviceScaleFactor; |
256 | 256 |
257 bool m_visible; | 257 bool m_visible; |
258 | 258 |
259 typedef base::hash_map<WebKit::WebGraphicsContext3D*, scoped_refptr<RateLimi
ter> > RateLimiterMap; | 259 typedef base::hash_map<WebKit::WebGraphicsContext3D*, scoped_refptr<RateLimi
ter> > RateLimiterMap; |
260 RateLimiterMap m_rateLimiters; | 260 RateLimiterMap m_rateLimiters; |
261 | 261 |
262 float m_pageScaleFactor; | 262 float m_pageScaleFactor; |
263 float m_minPageScaleFactor, m_maxPageScaleFactor; | 263 float m_minPageScaleFactor, m_maxPageScaleFactor; |
264 WebKit::WebTransformationMatrix m_implTransform; | 264 WebKit::WebTransformationMatrix m_implTransform; |
265 bool m_triggerIdleUpdates; | 265 bool m_triggerIdleUpdates; |
266 | 266 |
267 SkColor m_backgroundColor; | 267 SkColor m_backgroundColor; |
268 bool m_hasTransparentBackground; | 268 bool m_hasTransparentBackground; |
269 | 269 |
270 typedef ScopedPtrVector<CCPrioritizedTexture> TextureList; | 270 typedef ScopedPtrVector<PrioritizedTexture> TextureList; |
271 TextureList m_deleteTextureAfterCommitList; | 271 TextureList m_deleteTextureAfterCommitList; |
272 size_t m_partialTextureUpdateRequests; | 272 size_t m_partialTextureUpdateRequests; |
273 | 273 |
274 static bool s_needsFilterContext; | 274 static bool s_needsFilterContext; |
275 | 275 |
276 DISALLOW_COPY_AND_ASSIGN(CCLayerTreeHost); | 276 DISALLOW_COPY_AND_ASSIGN(LayerTreeHost); |
277 }; | 277 }; |
278 | 278 |
279 } // namespace cc | 279 } // namespace cc |
280 | 280 |
281 #endif | 281 #endif |
OLD | NEW |