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 bool clipsToExposedRect() OVERRIDE { return m_clipsToExposedRect; }
112 virtual void setClipsToExposedRect(bool) OVERRIDE;
113 virtual void prepopulateRect(const FloatRect&) OVERRIDE;
114 virtual void setIsInWindow(bool) OVERRIDE;
115 virtual void setTileCoverage(TileCoverage) OVERRIDE;
116 virtual TileCoverage tileCoverage() const OVERRIDE { return m_tileCoverage; }
117 virtual void forceRepaint() OVERRIDE;
118 virtual IntSize tileSize() const OVERRIDE { return m_tileSize; }
119 virtual IntRect tileGridExtent() const OVERRIDE;
120 virtual void setScrollingPerformanceLoggingEnabled(bool flag) OVERRIDE { m_scrollingPerformanceLoggingEnabled = flag; }
121 virtual bool scrollingPerformanceLoggingEnabled() const OVERRIDE { return m_scrollingPerformanceLoggingEnabled; }
122 virtual void setAggressivelyRetainsTiles(bool flag) OVERRIDE { m_aggressivelyRetainsTiles = flag; }
123 virtual bool aggressivelyRetainsTiles() const OVERRIDE { return m_aggressivelyRetainsTiles; }
124 virtual void setUnparentsOffscreenTiles(bool flag) OVERRIDE { m_unparentsOffscreenTiles = flag; }
125 virtual bool unparentsOffscreenTiles() const OVERRIDE { return m_unparentsOffscreenTiles; }
126 virtual double retainedTileBackingStoreMemory() const OVERRIDE;
127 virtual IntRect tileCoverageRect() const OVERRIDE;
128 virtual CALayer *tiledScrollingIndicatorLayer() OVERRIDE;
129 virtual void setScrollingModeIndication(ScrollingModeIndication) OVERRIDE;
131 IntRect bounds() const;
133 IntRect rectForTileIndex(const TileIndex&) const;
134 void getTileIndexRangeForRect(const IntRect&, TileIndex& topLeft, TileIndex& bottomRight) const;
136 FloatRect computeTileCoverageRect(const FloatRect& previousVisibleRect) const;
137 IntSize tileSizeForCoverageRect(const FloatRect&) const;
139 void scheduleTileRevalidation(double interval);
140 void tileRevalidationTimerFired(Timer<TileController>*);
142 void scheduleCohortRemoval();
143 void cohortRemovalTimerFired(Timer<TileController>*);
145 typedef unsigned TileValidationPolicyFlags;
147 void revalidateTiles(TileValidationPolicyFlags foregroundValidationPolicy = 0, TileValidationPolicyFlags backgroundValidationPolicy = 0);
148 void ensureTilesForRect(const FloatRect&);
149 void updateTileCoverageMap();
151 void removeAllTiles();
152 void removeAllSecondaryTiles();
153 void removeTilesInCohort(TileCohort);
155 TileCohort nextTileCohort() const;
156 void startedNewCohort(TileCohort);
158 TileCohort newestTileCohort() const;
159 TileCohort oldestTileCohort() const;
161 void setTileNeedsDisplayInRect(const TileIndex&, TileInfo&, const IntRect& repaintRectInTileCoords, const IntRect& coverageRectInTileCoords);
163 WebTileLayer* tileLayerAtIndex(const TileIndex&) const;
164 RetainPtr<WebTileLayer> createTileLayer(const IntRect&);
166 bool shouldShowRepaintCounters() const;
167 void drawRepaintCounter(WebTileLayer *, CGContextRef);
169 WebTiledBackingLayer* m_tileCacheLayer;
170 RetainPtr<CALayer> m_tileContainerLayer;
171 RetainPtr<WebTiledScrollingIndicatorLayer> m_tiledScrollingIndicatorLayer; // Used for coverage visualization.
174 FloatRect m_visibleRect;
175 FloatRect m_visibleRectAtLastRevalidate;
176 FloatRect m_exposedRect; // The exposed area of containing platform views.
178 typedef HashMap<TileIndex, TileInfo> TileMap;
180 Timer<TileController> m_tileRevalidationTimer;
181 Timer<TileController> m_cohortRemovalTimer;
183 struct TileCohortInfo {
185 double creationTime; // in monotonicallyIncreasingTime().
186 TileCohortInfo(TileCohort inCohort, double inTime)
188 , creationTime(inTime)
191 typedef Deque<TileCohortInfo> TileCohortList;
192 TileCohortList m_cohortList;
194 IntRect m_primaryTileCoverageRect; // In tile coords.
197 CGFloat m_deviceScaleFactor;
199 TileCoverage m_tileCoverage;
201 bool m_scrollingPerformanceLoggingEnabled;
202 bool m_aggressivelyRetainsTiles;
203 bool m_unparentsOffscreenTiles;
204 bool m_acceleratesDrawing;
205 bool m_tilesAreOpaque;
206 bool m_clipsToExposedRect;
208 RetainPtr<CGColorRef> m_tileDebugBorderColor;
209 float m_tileDebugBorderWidth;
210 ScrollingModeIndication m_indicatorMode;
213 } // namespace WebCore
215 #endif // TileController_h