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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CCLayerTreeHost_h
#define CCLayerTreeHost_h
#include "GraphicsContext3D.h"
#include "GraphicsTypes3D.h"
#include "IntRect.h"
#include "RateLimiter.h"
#include "SkColor.h"
#include "cc/CCAnimationEvents.h"
#include "cc/CCGraphicsContext.h"
#include "cc/CCLayerTreeHostCommon.h"
#include "cc/CCOcclusionTracker.h"
#include "cc/CCPrioritizedTextureManager.h"
#include "cc/CCProxy.h"
#include <limits>
#include <wtf/HashMap.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
namespace WebCore {
class CCGraphicsContext;
class CCLayerChromium;
class CCLayerTreeHostImpl;
class CCLayerTreeHostImplClient;
class CCTextureUpdater;
class ManagedTexture;
class Region;
class TextureAllocator;
class CCPrioritizedTextureManager;
struct CCRenderingStats;
struct CCScrollAndScaleSet;
class CCLayerTreeHostClient {
public:
virtual void willBeginFrame() = 0;
// Marks finishing compositing-related tasks on the main thread. In threaded mode, this corresponds to didCommit().
virtual void didBeginFrame() = 0;
virtual void updateAnimations(double frameBeginTime) = 0;
virtual void layout() = 0;
virtual void applyScrollAndScale(const IntSize& scrollDelta, float pageScale) = 0;
virtual PassOwnPtr<WebKit::WebGraphicsContext3D> createContext3D() = 0;
virtual void didRecreateContext(bool success) = 0;
virtual void willCommit() = 0;
virtual void didCommit() = 0;
virtual void didCommitAndDrawFrame() = 0;
virtual void didCompleteSwapBuffers() = 0;
// Used only in the single-threaded path.
virtual void scheduleComposite() = 0;
protected:
virtual ~CCLayerTreeHostClient() { }
};
struct CCLayerTreeSettings {
CCLayerTreeSettings()
: acceleratePainting(false)
, forceSoftwareCompositing(false)
, showFPSCounter(false)
, showPlatformLayerTree(false)
, showPaintRects(false)
, showPropertyChangedRects(false)
, showSurfaceDamageRects(false)
, showScreenSpaceRects(false)
, showReplicaScreenSpaceRects(false)
, showOccludingRects(false)
, refreshRate(0)
, maxPartialTextureUpdates(std::numeric_limits<size_t>::max())
, defaultTileSize(IntSize(256, 256))
, maxUntiledLayerSize(IntSize(512, 512))
{ }
bool acceleratePainting;
bool forceSoftwareCompositing;
bool showFPSCounter;
bool showPlatformLayerTree;
bool showPaintRects;
bool showPropertyChangedRects;
bool showSurfaceDamageRects;
bool showScreenSpaceRects;
bool showReplicaScreenSpaceRects;
bool showOccludingRects;
double refreshRate;
size_t maxPartialTextureUpdates;
IntSize defaultTileSize;
IntSize maxUntiledLayerSize;
};
// Provides information on an Impl's rendering capabilities back to the CCLayerTreeHost
struct LayerRendererCapabilities {
LayerRendererCapabilities()
: bestTextureFormat(0)
, contextHasCachedFrontBuffer(false)
, usingPartialSwap(false)
, usingMapSub(false)
, usingAcceleratedPainting(false)
, usingSetVisibility(false)
, usingSwapCompleteCallback(false)
, usingTextureUsageHint(false)
, usingTextureStorageExtension(false)
, usingGpuMemoryManager(false)
, usingDiscardFramebuffer(false)
, usingEglImage(false)
, maxTextureSize(0) { }
GC3Denum bestTextureFormat;
bool contextHasCachedFrontBuffer;
bool usingPartialSwap;
bool usingMapSub;
bool usingAcceleratedPainting;
bool usingSetVisibility;
bool usingSwapCompleteCallback;
bool usingTextureUsageHint;
bool usingTextureStorageExtension;
bool usingGpuMemoryManager;
bool usingDiscardFramebuffer;
bool usingEglImage;
int maxTextureSize;
};
class CCLayerTreeHost : public RateLimiterClient {
WTF_MAKE_NONCOPYABLE(CCLayerTreeHost);
public:
static PassOwnPtr<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 commitComplete();
PassOwnPtr<CCGraphicsContext> createContext();
virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl(CCLayerTreeHostImplClient*);
void didLoseContext();
enum RecreateResult {
RecreateSucceeded,
RecreateFailedButTryAgain,
RecreateFailedAndGaveUp,
};
RecreateResult recreateContext();
void willCommit() { m_client->willCommit(); }
void didCommitAndDrawFrame() { m_client->didCommitAndDrawFrame(); }
void didCompleteSwapBuffers() { m_client->didCompleteSwapBuffers(); }
void deleteContentsTexturesOnImplThread(TextureAllocator*);
virtual void acquireLayerTextures();
// Returns false if we should abort this frame due to initialization failure.
bool initializeLayerRendererIfNeeded();
void updateLayers(CCTextureUpdater&, size_t contentsMemoryLimitBytes);
CCLayerTreeHostClient* client() { return m_client; }
int compositorIdentifier() const { return m_compositorIdentifier; }
// 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 animationFrameNumber() const { return m_animationFrameNumber; }
int commitNumber() const { return m_commitNumber; }
void renderingStats(CCRenderingStats&) const;
const LayerRendererCapabilities& layerRendererCapabilities() const;
// Test only hook
void loseContext(int numTimes);
void setNeedsAnimate();
// virtual for testing
virtual void setNeedsCommit();
void setNeedsRedraw();
bool commitRequested() const;
void setAnimationEvents(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime);
virtual void didAddAnimation();
LayerChromium* rootLayer() { return m_rootLayer.get(); }
const LayerChromium* rootLayer() const { return m_rootLayer.get(); }
void setRootLayer(PassRefPtr<LayerChromium>);
const CCLayerTreeSettings& settings() const { return m_settings; }
void setViewportSize(const IntSize&);
const IntSize& viewportSize() const { return m_viewportSize; }
// Gives the viewport size in device/content space.
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;
// This will cause contents texture manager to evict all textures, but
// without deleting them. This happens after all content textures have
// already been deleted on impl, after getting a 0 allocation limit.
// Set during a commit, but before updateLayers.
void evictAllContentTextures();
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 startRateLimiter(WebKit::WebGraphicsContext3D*);
void stopRateLimiter(WebKit::WebGraphicsContext3D*);
// RateLimitClient implementation
virtual void rateLimit() OVERRIDE;
bool bufferedUpdates();
bool requestPartialTextureUpdate();
void deleteTextureAfterCommit(PassOwnPtr<CCPrioritizedTexture>);
void setDeviceScaleFactor(float);
float deviceScaleFactor() const { return m_deviceScaleFactor; }
protected:
CCLayerTreeHost(CCLayerTreeHostClient*, const CCLayerTreeSettings&);
bool initialize();
private:
typedef Vector<RefPtr<LayerChromium> > LayerList;
typedef Vector<OwnPtr<CCPrioritizedTexture> > TextureList;
void initializeLayerRenderer();
static void update(LayerChromium*, CCTextureUpdater&, const CCOcclusionTracker*);
bool paintLayerContents(const LayerList&, CCTextureUpdater&);
bool paintMasksForRenderSurface(LayerChromium*, CCTextureUpdater&);
void updateLayers(LayerChromium*, CCTextureUpdater&);
void prioritizeTextures(const LayerList& updateList);
void animateLayers(double monotonicTime);
bool animateLayersRecursive(LayerChromium* current, double monotonicTime);
void setAnimationEventsRecursive(const CCAnimationEventsVector&, LayerChromium*, double wallClockTime);
int m_compositorIdentifier;
bool m_animating;
bool m_needsAnimateLayers;
CCLayerTreeHostClient* m_client;
int m_animationFrameNumber;
int m_commitNumber;
OwnPtr<CCProxy> m_proxy;
bool m_layerRendererInitialized;
bool m_contextLost;
int m_numTimesRecreateShouldFail;
int m_numFailedRecreateAttempts;
RefPtr<LayerChromium> m_rootLayer;
OwnPtr<CCPrioritizedTextureManager> m_contentsTextureManager;
CCLayerTreeSettings m_settings;
IntSize m_viewportSize;
IntSize m_deviceViewportSize;
float m_deviceScaleFactor;
bool m_visible;
typedef HashMap<WebKit::WebGraphicsContext3D*, RefPtr<RateLimiter> > RateLimiterMap;
RateLimiterMap m_rateLimiters;
float m_pageScaleFactor;
float m_minPageScaleFactor, m_maxPageScaleFactor;
bool m_triggerIdleUpdates;
SkColor m_backgroundColor;
bool m_hasTransparentBackground;
TextureList m_deleteTextureAfterCommitList;
size_t m_partialTextureUpdateRequests;
static bool s_needsFilterContext;
};
}
#endif
|