2 * Copyright (C) 2011-2014 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"
31 #include "PlatformCALayer.h"
32 #include "PlatformCALayerClient.h"
33 #include "TiledBacking.h"
35 #include <wtf/Deque.h>
36 #include <wtf/HashMap.h>
37 #include <wtf/Noncopyable.h>
38 #include <wtf/PassOwnPtr.h>
39 #include <wtf/RetainPtr.h>
48 typedef Vector<RetainPtr<PlatformLayer>> PlatformLayerList;
50 class TileController final : public TiledBacking, public PlatformCALayerClient {
51 WTF_MAKE_NONCOPYABLE(TileController);
54 static PassOwnPtr<TileController> create(PlatformCALayer*);
57 void tileCacheLayerBoundsChanged();
59 void setNeedsDisplay();
60 void setNeedsDisplayInRect(const IntRect&);
65 bool acceleratesDrawing() const { return m_acceleratesDrawing; }
66 void setAcceleratesDrawing(bool);
68 void setTilesOpaque(bool);
69 bool tilesAreOpaque() const { return m_tilesAreOpaque; }
71 PlatformCALayer& rootLayer() { return *m_tileCacheLayer; }
73 void setTileDebugBorderWidth(float);
74 void setTileDebugBorderColor(Color);
76 virtual FloatRect visibleRect() const override { return m_visibleRect; }
78 unsigned blankPixelCount() const;
79 static unsigned blankPixelCountForTiles(const PlatformLayerList&, const FloatRect&, const IntPoint&);
82 unsigned numberOfUnparentedTiles() const;
83 void removeUnparentedTilesNow();
87 // Public for TileGrid
88 bool isInWindow() const { return m_isInWindow; }
90 float deviceScaleFactor() const { return m_deviceScaleFactor; }
91 FloatRect exposedRect() const { return m_exposedRect; }
93 Color tileDebugBorderColor() const { return m_tileDebugBorderColor; }
94 float tileDebugBorderWidth() const { return m_tileDebugBorderWidth; }
96 virtual IntSize tileSize() const override { return m_tileSize; }
97 virtual IntRect bounds() const override;
98 virtual bool hasMargins() const override;
99 virtual int topMarginHeight() const override;
100 virtual int bottomMarginHeight() const override;
101 virtual int leftMarginWidth() const override;
102 virtual int rightMarginWidth() const override;
103 virtual TileCoverage tileCoverage() const override { return m_tileCoverage; }
104 virtual bool unparentsOffscreenTiles() const override { return m_unparentsOffscreenTiles; }
106 IntRect boundsWithoutMargin() const;
108 FloatRect computeTileCoverageRect(const FloatRect& previousVisibleRect, const FloatRect& currentVisibleRect) const;
110 IntRect boundsAtLastRevalidate() const { return m_boundsAtLastRevalidate; }
111 IntRect boundsAtLastRevalidateWithoutMargin() const;
112 FloatRect visibleRectAtLastRevalidate() const { return m_visibleRectAtLastRevalidate; }
113 void didRevalidateTiles();
115 bool shouldAggressivelyRetainTiles() const;
116 bool shouldTemporarilyRetainTileCohorts() const;
118 typedef HashMap<PlatformCALayer*, int> RepaintCountMap;
119 RepaintCountMap& repaintCountMap() { return m_tileRepaintCounts; }
121 void updateTileCoverageMap();
123 RefPtr<PlatformCALayer> createTileLayer(const IntRect&);
125 Vector<RefPtr<PlatformCALayer>> containerLayers();
128 TileController(PlatformCALayer*);
130 TileGrid& tileGrid() { return *m_tileGrid; }
131 const TileGrid& tileGrid() const { return *m_tileGrid; }
133 // TiledBacking member functions.
134 virtual void setVisibleRect(const FloatRect&) override;
135 virtual bool tilesWouldChangeForVisibleRect(const FloatRect&) const override;
136 virtual void setExposedRect(const FloatRect&) override;
137 virtual void prepopulateRect(const FloatRect&) override;
138 virtual void setIsInWindow(bool) override;
139 virtual void setTileCoverage(TileCoverage) override;
140 virtual void revalidateTiles() override;
141 virtual void forceRepaint() override;
142 virtual IntRect tileGridExtent() const override;
143 virtual void setScrollingPerformanceLoggingEnabled(bool flag) override { m_scrollingPerformanceLoggingEnabled = flag; }
144 virtual bool scrollingPerformanceLoggingEnabled() const override { return m_scrollingPerformanceLoggingEnabled; }
145 virtual void setUnparentsOffscreenTiles(bool flag) override { m_unparentsOffscreenTiles = flag; }
146 virtual double retainedTileBackingStoreMemory() const override;
147 virtual IntRect tileCoverageRect() const override;
148 virtual PlatformCALayer* tiledScrollingIndicatorLayer() override;
149 virtual void setScrollingModeIndication(ScrollingModeIndication) override;
150 virtual void setTileMargins(int marginTop, int marginBottom, int marginLeft, int marginRight) override;
152 // PlatformCALayerClient
153 virtual void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) override { }
154 virtual bool platformCALayerRespondsToLayoutChanges() const override { return false; }
155 virtual void platformCALayerAnimationStarted(CFTimeInterval) override { }
156 virtual GraphicsLayer::CompositingCoordinatesOrientation platformCALayerContentsOrientation() const override { return GraphicsLayer::CompositingCoordinatesTopDown; }
157 virtual void platformCALayerPaintContents(PlatformCALayer*, GraphicsContext&, const FloatRect&) override;
158 virtual bool platformCALayerShowDebugBorders() const override;
159 virtual bool platformCALayerShowRepaintCounter(PlatformCALayer*) const override;
160 virtual int platformCALayerIncrementRepaintCount(PlatformCALayer*) override;
162 virtual bool platformCALayerContentsOpaque() const override { return m_tilesAreOpaque; }
163 virtual bool platformCALayerDrawsContent() const override { return true; }
164 virtual void platformCALayerLayerDidDisplay(PlatformLayer*) override { }
166 virtual void platformCALayerSetNeedsToRevalidateTiles() override { }
167 virtual float platformCALayerDeviceScaleFactor() const override;
169 void scheduleTileRevalidation(double interval);
170 void tileRevalidationTimerFired(Timer<TileController>*);
172 void setNeedsRevalidateTiles();
174 void drawTileMapContents(CGContextRef, CGRect);
176 PlatformCALayerClient* owningGraphicsLayer() const { return m_tileCacheLayer->owner(); }
178 PlatformCALayer* m_tileCacheLayer;
179 RefPtr<PlatformCALayer> m_tiledScrollingIndicatorLayer; // Used for coverage visualization.
180 RefPtr<PlatformCALayer> m_visibleRectIndicatorLayer;
182 std::unique_ptr<TileGrid> m_tileGrid;
185 FloatRect m_visibleRect;
186 FloatRect m_visibleRectAtLastRevalidate;
187 FloatRect m_exposedRect; // The exposed area of containing platform views.
188 IntRect m_boundsAtLastRevalidate;
190 Timer<TileController> m_tileRevalidationTimer;
192 RepaintCountMap m_tileRepaintCounts;
194 float m_deviceScaleFactor;
196 TileCoverage m_tileCoverage;
198 // m_marginTop and m_marginBottom are the height in pixels of the top and bottom margin tiles. The width
199 // of those tiles will be equivalent to the width of the other tiles in the grid. m_marginRight and
200 // m_marginLeft are the width in pixels of the right and left margin tiles, respectively. The height of
201 // those tiles will be equivalent to the height of the other tiles in the grid.
208 bool m_scrollingPerformanceLoggingEnabled;
209 bool m_unparentsOffscreenTiles;
210 bool m_acceleratesDrawing;
211 bool m_tilesAreOpaque;
212 bool m_hasTilesWithTemporaryScaleFactor; // Used to make low-res tiles when zooming.
214 Color m_tileDebugBorderColor;
215 float m_tileDebugBorderWidth;
216 ScrollingModeIndication m_indicatorMode;
219 } // namespace WebCore
221 #endif // TileController_h