1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CCLayerTreeHost_h
#define CCLayerTreeHost_h
#include "base/basictypes.h"
#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "CCAnimationEvents.h"
#include "CCGraphicsContext.h"
#include "CCLayerTreeHostClient.h"
#include "CCLayerTreeHostCommon.h"
#include "CCOcclusionTracker.h"
#include "CCPrioritizedTextureManager.h"
#include "CCProxy.h"
#include "CCRenderingStats.h"
#include "IntRect.h"
#include "RateLimiter.h"
#include "scoped_ptr_vector.h"
#include "SkColor.h"
#include <limits>
#if defined(COMPILER_GCC)
namespace BASE_HASH_NAMESPACE {
template<>
struct hash<WebKit::WebGraphicsContext3D*> {
size_t operator()(WebKit::WebGraphicsContext3D* ptr) const {
return hash<size_t>()(reinterpret_cast<size_t>(ptr));
}
};
} // namespace BASE_HASH_NAMESPACE
#endif // COMPILER
namespace cc {
class CCFontAtlas;
class CCLayerChromium;
class CCLayerTreeHostImpl;
class CCLayerTreeHostImplClient;
class CCPrioritizedTextureManager;
class CCTextureUpdateQueue;
class HeadsUpDisplayLayerChromium;
class Region;
struct CCScrollAndScaleSet;
struct CCLayerTreeSettings {
CCLayerTreeSettings();
~CCLayerTreeSettings();
bool acceleratePainting;
bool showFPSCounter;
bool showPlatformLayerTree;
bool showPaintRects;
bool showPropertyChangedRects;
bool showSurfaceDamageRects;
bool showScreenSpaceRects;
bool showReplicaScreenSpaceRects;
bool showOccludingRects;
bool renderVSyncEnabled;
double refreshRate;
size_t maxPartialTextureUpdates;
IntSize defaultTileSize;
IntSize maxUntiledLayerSize;
IntSize minimumOcclusionTrackingSize;
bool showDebugInfo() const { return showPlatformLayerTree || showFPSCounter || showDebugRects(); }
bool showDebugRects() const { return showPaintRects || showPropertyChangedRects || showSurfaceDamageRects || showScreenSpaceRects || showReplicaScreenSpaceRects || showOccludingRects; }
};
// Provides information on an Impl's rendering capabilities back to the CCLayerTreeHost
struct RendererCapabilities {
RendererCapabilities();
~RendererCapabilities();
GC3Denum bestTextureFormat;
bool contextHasCachedFrontBuffer;
bool usingPartialSwap;
bool usingAcceleratedPainting;
bool usingSetVisibility;
bool usingSwapCompleteCallback;
bool usingGpuMemoryManager;
bool usingDiscardFramebuffer;
bool usingEglImage;
int maxTextureSize;
};
class CCLayerTreeHost : public RateLimiterClient {
public:
static scoped_ptr<CCLayerTreeHost> create(CCLayerTreeHostClient*, const CCLayerTreeSettings&);
virtual ~CCLayerTreeHost();
void setSurfaceReady();
// Returns true if any CCLayerTreeHost is alive.
static bool anyLayerTreeHostInstanceExists();
static bool needsFilterContext() { return s_needsFilterContext; }
static void setNeedsFilterContext(bool needsFilterContext) { s_needsFilterContext = needsFilterContext; }
bool needsSharedContext() const { return needsFilterContext() || settings().acceleratePainting; }
// CCLayerTreeHost interface to CCProxy.
void willBeginFrame() { m_client->willBeginFrame(); }
void didBeginFrame() { m_client->didBeginFrame(); }
void updateAnimations(double monotonicFrameBeginTime);
void layout();
void beginCommitOnImplThread(CCLayerTreeHostImpl*);
void finishCommitOnImplThread(CCLayerTreeHostImpl*);
void willCommit();
void commitComplete();
scoped_ptr<CCGraphicsContext> createContext();
scoped_ptr<CCInputHandler> createInputHandler();
virtual scoped_ptr<CCLayerTreeHostImpl> createLayerTreeHostImpl(CCLayerTreeHostImplClient*);
void didLoseContext();
enum RecreateResult {
RecreateSucceeded,
RecreateFailedButTryAgain,
RecreateFailedAndGaveUp,
};
RecreateResult recreateContext();
void didCommitAndDrawFrame() { m_client->didCommitAndDrawFrame(); }
void didCompleteSwapBuffers() { m_client->didCompleteSwapBuffers(); }
void deleteContentsTexturesOnImplThread(CCResourceProvider*);
virtual void acquireLayerTextures();
// Returns false if we should abort this frame due to initialization failure.
bool initializeRendererIfNeeded();
void updateLayers(CCTextureUpdateQueue&, size_t contentsMemoryLimitBytes);
CCLayerTreeHostClient* client() { return m_client; }
// Only used when compositing on the main thread.
void composite();
void scheduleComposite();
// Composites and attempts to read back the result into the provided
// buffer. If it wasn't possible, e.g. due to context lost, will return
// false.
bool compositeAndReadback(void *pixels, const IntRect&);
void finishAllRendering();
int commitNumber() const { return m_commitNumber; }
void renderingStats(CCRenderingStats*) const;
const RendererCapabilities& rendererCapabilities() const;
// Test only hook
void loseContext(int numTimes);
void setNeedsAnimate();
// virtual for testing
virtual void setNeedsCommit();
void setNeedsRedraw();
bool commitRequested() const;
void setAnimationEvents(scoped_ptr<CCAnimationEventsVector>, double wallClockTime);
virtual void didAddAnimation();
LayerChromium* rootLayer() { return m_rootLayer.get(); }
const LayerChromium* rootLayer() const { return m_rootLayer.get(); }
void setRootLayer(scoped_refptr<LayerChromium>);
const CCLayerTreeSettings& settings() const { return m_settings; }
void setViewportSize(const IntSize& layoutViewportSize, const IntSize& deviceViewportSize);
const IntSize& layoutViewportSize() const { return m_layoutViewportSize; }
const IntSize& deviceViewportSize() const { return m_deviceViewportSize; }
void setPageScaleFactorAndLimits(float pageScaleFactor, float minPageScaleFactor, float maxPageScaleFactor);
void setBackgroundColor(SkColor color) { m_backgroundColor = color; }
void setHasTransparentBackground(bool transparent) { m_hasTransparentBackground = transparent; }
CCPrioritizedTextureManager* contentsTextureManager() const;
// Delete contents textures' backing resources until they use only bytesLimit bytes. This may
// be called on the impl thread while the main thread is running.
void reduceContentsTexturesMemoryOnImplThread(size_t bytesLimit, CCResourceProvider*);
// Returns true if there any evicted backing textures that have not been deleted.
bool evictedContentsTexturesBackingsExist() const;
// Retrieve the list of all contents textures' backings that have been evicted, to pass to the
// main thread to unlink them from their owning textures.
void getEvictedContentTexturesBackings(CCPrioritizedTextureManager::BackingVector&);
// Unlink the list of contents textures' backings from their owning textures on the main thread
// before updating layers.
void unlinkEvictedContentTexturesBackings(const CCPrioritizedTextureManager::BackingVector&);
// Deletes all evicted backings, unlinking them from their owning textures if needed.
// Returns true if this function had to unlink any backings from their owning texture when
// destroying them. If this was the case, the impl layer tree may contain invalid resources.
bool deleteEvictedContentTexturesBackings();
bool visible() const { return m_visible; }
void setVisible(bool);
void startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, double durationSec);
void applyScrollAndScale(const CCScrollAndScaleSet&);
void setImplTransform(const WebKit::WebTransformationMatrix&);
void startRateLimiter(WebKit::WebGraphicsContext3D*);
void stopRateLimiter(WebKit::WebGraphicsContext3D*);
// RateLimitClient implementation
virtual void rateLimit() OVERRIDE;
bool bufferedUpdates();
bool requestPartialTextureUpdate();
void deleteTextureAfterCommit(scoped_ptr<CCPrioritizedTexture>);
void setDeviceScaleFactor(float);
float deviceScaleFactor() const { return m_deviceScaleFactor; }
void setFontAtlas(scoped_ptr<CCFontAtlas>);
HeadsUpDisplayLayerChromium* hudLayer() const { return m_hudLayer.get(); }
protected:
CCLayerTreeHost(CCLayerTreeHostClient*, const CCLayerTreeSettings&);
bool initialize();
private:
typedef std::vector<scoped_refptr<LayerChromium> > LayerList;
void initializeRenderer();
void update(LayerChromium*, CCTextureUpdateQueue&, const CCOcclusionTracker*);
bool paintLayerContents(const LayerList&, CCTextureUpdateQueue&);
bool paintMasksForRenderSurface(LayerChromium*, CCTextureUpdateQueue&);
void updateLayers(LayerChromium*, CCTextureUpdateQueue&);
void prioritizeTextures(const LayerList&, CCOverdrawMetrics&);
void setPrioritiesForSurfaces(size_t surfaceMemoryBytes);
void setPrioritiesForLayers(const LayerList&);
size_t calculateMemoryForRenderSurfaces(const LayerList& updateList);
void animateLayers(double monotonicTime);
bool animateLayersRecursive(LayerChromium* current, double monotonicTime);
void setAnimationEventsRecursive(const CCAnimationEventsVector&, LayerChromium*, double wallClockTime);
bool m_animating;
bool m_needsAnimateLayers;
CCLayerTreeHostClient* m_client;
int m_commitNumber;
CCRenderingStats m_renderingStats;
scoped_ptr<CCProxy> m_proxy;
bool m_rendererInitialized;
bool m_contextLost;
int m_numTimesRecreateShouldFail;
int m_numFailedRecreateAttempts;
scoped_refptr<LayerChromium> m_rootLayer;
scoped_refptr<HeadsUpDisplayLayerChromium> m_hudLayer;
scoped_ptr<CCFontAtlas> m_fontAtlas;
scoped_ptr<CCPrioritizedTextureManager> m_contentsTextureManager;
scoped_ptr<CCPrioritizedTexture> m_surfaceMemoryPlaceholder;
CCLayerTreeSettings m_settings;
IntSize m_layoutViewportSize;
IntSize m_deviceViewportSize;
float m_deviceScaleFactor;
bool m_visible;
typedef base::hash_map<WebKit::WebGraphicsContext3D*, scoped_refptr<RateLimiter> > RateLimiterMap;
RateLimiterMap m_rateLimiters;
float m_pageScaleFactor;
float m_minPageScaleFactor, m_maxPageScaleFactor;
WebKit::WebTransformationMatrix m_implTransform;
bool m_triggerIdleUpdates;
SkColor m_backgroundColor;
bool m_hasTransparentBackground;
typedef ScopedPtrVector<CCPrioritizedTexture> TextureList;
TextureList m_deleteTextureAfterCommitList;
size_t m_partialTextureUpdateRequests;
static bool s_needsFilterContext;
DISALLOW_COPY_AND_ASSIGN(CCLayerTreeHost);
};
} // namespace cc
#endif
|