2 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef TileController_h
27 #define TileController_h
29 #include "FloatRect.h"
30 #include "IntPointHash.h"
32 #include "TiledBacking.h"
34 #include <wtf/Deque.h>
35 #include <wtf/HashMap.h>
36 #include <wtf/Noncopyable.h>
37 #include <wtf/PassOwnPtr.h>
38 #include <wtf/RetainPtr.h>
41 OBJC_CLASS WebTiledBackingLayer;
42 OBJC_CLASS WebTileLayer;
43 OBJC_CLASS WebTiledScrollingIndicatorLayer;
51 typedef Vector<RetainPtr<WebTileLayer> > WebTileLayerList;
53 class TileController : public TiledBacking {
54 WTF_MAKE_NONCOPYABLE(TileController);
57 static PassOwnPtr<TileController> create(WebTiledBackingLayer*);
60 void tileCacheLayerBoundsChanged();
62 void setNeedsDisplay();
63 void setNeedsDisplayInRect(const IntRect&);
64 void drawLayer(WebTileLayer *, CGContextRef);
66 void setScale(CGFloat);
67 CGFloat scale() const { return m_scale; }
69 bool acceleratesDrawing() const { return m_acceleratesDrawing; }
70 void setAcceleratesDrawing(bool);
72 void setTilesOpaque(bool);
73 bool tilesAreOpaque() const { return m_tilesAreOpaque; }
75 CALayer *tileContainerLayer() const { return m_tileContainerLayer.get(); }
77 void setTileDebugBorderWidth(float);
78 void setTileDebugBorderColor(CGColorRef);
80 virtual FloatRect visibleRect() const OVERRIDE { return m_visibleRect; }
82 unsigned blankPixelCount() const;
83 static unsigned blankPixelCountForTiles(const WebTileLayerList&, const FloatRect&, const IntPoint&);
85 // Only public for the WebTileCacheMapLayer.
86 void drawTileMapContents(CGContextRef, CGRect);
89 // Only public for inline methods in the implementation file.
90 typedef IntPoint TileIndex;
91 typedef unsigned TileCohort;
92 static const TileCohort VisibleTileCohort = UINT_MAX;
95 RetainPtr<WebTileLayer> layer;
96 TileCohort cohort; // VisibleTileCohort is visible.
100 : cohort(VisibleTileCohort)
101 , hasStaleContent(false)
106 TileController(WebTiledBackingLayer*);
108 // TiledBacking member functions.
109 virtual void setVisibleRect(const FloatRect&) OVERRIDE;
110 virtual void setExposedRect(const FloatRect&) OVERRIDE;
111 virtual void setClipsToExposedRect(bool) OVERRIDE;
112 virtual void prepopulateRect(const FloatRect&) OVERRIDE;
113 virtual void setIsInWindow(bool) OVERRIDE;
114 virtual void setTileCoverage(TileCoverage) OVERRIDE;
115 virtual TileCoverage tileCoverage() const OVERRIDE { return m_tileCoverage; }
116 virtual void forceRepaint() OVERRIDE;
117 virtual IntSize tileSize() const OVERRIDE { return m_tileSize; }
118 virtual IntRect tileGridExtent() const OVERRIDE;
119 virtual void setScrollingPerformanceLoggingEnabled(bool flag) OVERRIDE { m_scrollingPerformanceLoggingEnabled = flag; }
120 virtual bool scrollingPerformanceLoggingEnabled() const OVERRIDE { return m_scrollingPerformanceLoggingEnabled; }
121 virtual void setAggressivelyRetainsTiles(bool flag) OVERRIDE { m_aggressivelyRetainsTiles = flag; }
122 virtual bool aggressivelyRetainsTiles() const OVERRIDE { return m_aggressivelyRetainsTiles; }
123 virtual void setUnparentsOffscreenTiles(bool flag) OVERRIDE { m_unparentsOffscreenTiles = flag; }
124 virtual bool unparentsOffscreenTiles() const OVERRIDE { return m_unparentsOffscreenTiles; }
125 virtual IntRect tileCoverageRect() const OVERRIDE;
126 virtual CALayer *tiledScrollingIndicatorLayer() OVERRIDE;
127 virtual void setScrollingModeIndication(ScrollingModeIndication) OVERRIDE;
129 IntRect bounds() const;
131 IntRect rectForTileIndex(const TileIndex&) const;
132 void getTileIndexRangeForRect(const IntRect&, TileIndex& topLeft, TileIndex& bottomRight) const;
134 FloatRect computeTileCoverageRect(const FloatRect& previousVisibleRect) const;
135 IntSize tileSizeForCoverageRect(const FloatRect&) const;
137 void scheduleTileRevalidation(double interval);
138 void tileRevalidationTimerFired(Timer<TileController>*);
140 void scheduleCohortRemoval();
141 void cohortRemovalTimerFired(Timer<TileController>*);
143 typedef unsigned TileValidationPolicyFlags;
145 void revalidateTiles(TileValidationPolicyFlags foregroundValidationPolicy = 0, TileValidationPolicyFlags backgroundValidationPolicy = 0);
146 void ensureTilesForRect(const FloatRect&);
147 void updateTileCoverageMap();
149 void removeAllTiles();
150 void removeAllSecondaryTiles();
151 void removeTilesInCohort(TileCohort);
153 TileCohort nextTileCohort() const;
154 void startedNewCohort(TileCohort);
156 TileCohort newestTileCohort() const;
157 TileCohort oldestTileCohort() const;
159 void setTileNeedsDisplayInRect(const TileIndex&, TileInfo&, const IntRect& repaintRectInTileCoords, const IntRect& coverageRectInTileCoords);
161 WebTileLayer* tileLayerAtIndex(const TileIndex&) const;
162 RetainPtr<WebTileLayer> createTileLayer(const IntRect&);
164 bool shouldShowRepaintCounters() const;
165 void drawRepaintCounter(WebTileLayer *, CGContextRef);
167 WebTiledBackingLayer* m_tileCacheLayer;
168 RetainPtr<CALayer> m_tileContainerLayer;
169 RetainPtr<WebTiledScrollingIndicatorLayer> m_tiledScrollingIndicatorLayer; // Used for coverage visualization.
172 FloatRect m_visibleRect;
173 FloatRect m_visibleRectAtLastRevalidate;
174 FloatRect m_exposedRect; // The exposed area of containing platform views.
176 typedef HashMap<TileIndex, TileInfo> TileMap;
178 Timer<TileController> m_tileRevalidationTimer;
179 Timer<TileController> m_cohortRemovalTimer;
181 struct TileCohortInfo {
183 double creationTime; // in monotonicallyIncreasingTime().
184 TileCohortInfo(TileCohort inCohort, double inTime)
186 , creationTime(inTime)
189 typedef Deque<TileCohortInfo> TileCohortList;
190 TileCohortList m_cohortList;
192 IntRect m_primaryTileCoverageRect; // In tile coords.
195 CGFloat m_deviceScaleFactor;
197 TileCoverage m_tileCoverage;
199 bool m_scrollingPerformanceLoggingEnabled;
200 bool m_aggressivelyRetainsTiles;
201 bool m_unparentsOffscreenTiles;
202 bool m_acceleratesDrawing;
203 bool m_tilesAreOpaque;
204 bool m_clipsToExposedRect;
206 RetainPtr<CGColorRef> m_tileDebugBorderColor;
207 float m_tileDebugBorderWidth;
208 ScrollingModeIndication m_indicatorMode;
211 } // namespace WebCore
213 #endif // TileController_h