/work/obj-fuzz/dist/include/mozilla/layers/MultiTiledContentClient.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_GFX_MULTITILEDCONTENTCLIENT_H |
8 | | #define MOZILLA_GFX_MULTITILEDCONTENTCLIENT_H |
9 | | |
10 | | #include "ClientLayerManager.h" // for ClientLayerManager |
11 | | #include "nsRegion.h" // for nsIntRegion |
12 | | #include "mozilla/gfx/2D.h" // for gfx::Tile |
13 | | #include "mozilla/gfx/Point.h" // for IntPoint |
14 | | #include "mozilla/layers/CompositableClient.h" // for CompositableClient |
15 | | #include "mozilla/layers/LayersMessages.h" // for TileDescriptor |
16 | | #include "mozilla/layers/TiledContentClient.h" // for ClientTiledPaintedLayer |
17 | | #include "mozilla/UniquePtr.h" // for UniquePtr |
18 | | #include "TiledLayerBuffer.h" // for TiledLayerBuffer |
19 | | |
20 | | namespace mozilla { |
21 | | namespace layers { |
22 | | |
23 | | class ClientLayerManager; |
24 | | |
25 | | class ClientMultiTiledLayerBuffer |
26 | | : public TiledLayerBuffer<ClientMultiTiledLayerBuffer, TileClient> |
27 | | , public ClientTiledLayerBuffer |
28 | | { |
29 | | friend class TiledLayerBuffer<ClientMultiTiledLayerBuffer, TileClient>; |
30 | | public: |
31 | | ClientMultiTiledLayerBuffer(ClientTiledPaintedLayer& aPaintedLayer, |
32 | | CompositableClient& aCompositableClient, |
33 | | ClientLayerManager* aManager, |
34 | | SharedFrameMetricsHelper* aHelper); |
35 | | |
36 | | void PaintThebes(const nsIntRegion& aNewValidRegion, |
37 | | const nsIntRegion& aPaintRegion, |
38 | | const nsIntRegion& aDirtyRegion, |
39 | | LayerManager::DrawPaintedLayerCallback aCallback, |
40 | | void* aCallbackData, |
41 | | TilePaintFlags aFlags = TilePaintFlags::None) override; |
42 | | |
43 | 0 | virtual bool SupportsProgressiveUpdate() override { return true; } |
44 | | /** |
45 | | * Performs a progressive update of a given tiled buffer. |
46 | | * See ComputeProgressiveUpdateRegion below for parameter documentation. |
47 | | * aOutDrawnRegion is an outparameter that contains the region that was |
48 | | * drawn, and which can now be added to the layer's valid region. |
49 | | */ |
50 | | bool ProgressiveUpdate(const nsIntRegion& aValidRegion, |
51 | | const nsIntRegion& aInvalidRegion, |
52 | | const nsIntRegion& aOldValidRegion, |
53 | | nsIntRegion& aOutDrawnRegion, |
54 | | BasicTiledLayerPaintData* aPaintData, |
55 | | LayerManager::DrawPaintedLayerCallback aCallback, |
56 | | void* aCallbackData) override; |
57 | | |
58 | 0 | void ResetPaintedAndValidState() override { |
59 | 0 | mValidRegion.SetEmpty(); |
60 | 0 | mTiles.mSize.width = 0; |
61 | 0 | mTiles.mSize.height = 0; |
62 | 0 | DiscardBuffers(); |
63 | 0 | mRetainedTiles.Clear(); |
64 | 0 | } |
65 | | |
66 | | |
67 | 0 | const nsIntRegion& GetValidRegion() override { |
68 | 0 | return TiledLayerBuffer::GetValidRegion(); |
69 | 0 | } |
70 | | |
71 | 0 | bool IsLowPrecision() const override { |
72 | 0 | return TiledLayerBuffer::IsLowPrecision(); |
73 | 0 | } |
74 | | |
75 | | void Dump(std::stringstream& aStream, |
76 | | const char* aPrefix, |
77 | | bool aDumpHtml, |
78 | 0 | TextureDumpMode aCompress) override { |
79 | 0 | TiledLayerBuffer::Dump(aStream, aPrefix, aDumpHtml, aCompress); |
80 | 0 | } |
81 | | |
82 | | void ReadLock(); |
83 | | |
84 | | void Release(); |
85 | | |
86 | | void DiscardBuffers(); |
87 | | |
88 | | SurfaceDescriptorTiles GetSurfaceDescriptorTiles(); |
89 | | |
90 | 0 | void SetResolution(float aResolution) { |
91 | 0 | if (mResolution == aResolution) { |
92 | 0 | return; |
93 | 0 | } |
94 | 0 | |
95 | 0 | Update(nsIntRegion(), nsIntRegion(), nsIntRegion(), TilePaintFlags::None); |
96 | 0 | mResolution = aResolution; |
97 | 0 | } |
98 | | |
99 | | protected: |
100 | | bool ValidateTile(TileClient& aTile, |
101 | | const nsIntPoint& aTileRect, |
102 | | nsIntRegion& aDirtyRegion, |
103 | | TilePaintFlags aFlags); |
104 | | |
105 | | void Update(const nsIntRegion& aNewValidRegion, |
106 | | const nsIntRegion& aPaintRegion, |
107 | | const nsIntRegion& aDirtyRegion, |
108 | | TilePaintFlags aFlags); |
109 | | |
110 | 0 | TileClient GetPlaceholderTile() const { return TileClient(); } |
111 | | |
112 | | private: |
113 | | RefPtr<ClientLayerManager> mManager; |
114 | | LayerManager::DrawPaintedLayerCallback mCallback; |
115 | | void* mCallbackData; |
116 | | |
117 | | // The region that will be made valid during Update(). Once Update() is |
118 | | // completed then this is identical to mValidRegion. |
119 | | nsIntRegion mNewValidRegion; |
120 | | |
121 | | SharedFrameMetricsHelper* mSharedFrameMetricsHelper; |
122 | | |
123 | | // Parameters that are collected during Update for a paint before they |
124 | | // are either executed or replayed on the paint thread. |
125 | | AutoTArray<gfx::Tile, 4> mPaintTiles; |
126 | | AutoTArray<UniquePtr<PaintTask>, 4> mPaintTasks; |
127 | | |
128 | | /** |
129 | | * While we're adding tiles, this is used to keep track of the position of |
130 | | * the top-left of the top-left-most tile. When we come to wrap the tiles in |
131 | | * TiledDrawTarget we subtract the value of this member from each tile's |
132 | | * offset so that all the tiles have a positive offset, then add a |
133 | | * translation to the TiledDrawTarget to compensate. This is important so |
134 | | * that the mRect of the TiledDrawTarget is always at a positive x/y |
135 | | * position, otherwise its GetSize() methods will be broken. |
136 | | */ |
137 | | gfx::IntPoint mTilingOrigin; |
138 | | /** |
139 | | * Calculates the region to update in a single progressive update transaction. |
140 | | * This employs some heuristics to update the most 'sensible' region to |
141 | | * update at this point in time, and how large an update should be performed |
142 | | * at once to maintain visual coherency. |
143 | | * |
144 | | * aInvalidRegion is the current invalid region. |
145 | | * aOldValidRegion is the valid region of mTiledBuffer at the beginning of the |
146 | | * current transaction. |
147 | | * aRegionToPaint will be filled with the region to update. This may be empty, |
148 | | * which indicates that there is no more work to do. |
149 | | * aIsRepeated should be true if this function has already been called during |
150 | | * this transaction. |
151 | | * |
152 | | * Returns true if it should be called again, false otherwise. In the case |
153 | | * that aRegionToPaint is empty, this will return aIsRepeated for convenience. |
154 | | */ |
155 | | bool ComputeProgressiveUpdateRegion(const nsIntRegion& aInvalidRegion, |
156 | | const nsIntRegion& aOldValidRegion, |
157 | | nsIntRegion& aRegionToPaint, |
158 | | BasicTiledLayerPaintData* aPaintData, |
159 | | bool aIsRepeated); |
160 | | |
161 | | void MaybeSyncTextures(const nsIntRegion& aPaintRegion, |
162 | | const TilesPlacement& aNewTiles, |
163 | | const gfx::IntSize& aScaledTileSize); |
164 | | }; |
165 | | |
166 | | /** |
167 | | * An implementation of TiledContentClient that supports |
168 | | * multiple tiles and a low precision buffer. |
169 | | */ |
170 | | class MultiTiledContentClient : public TiledContentClient |
171 | | { |
172 | | public: |
173 | | MultiTiledContentClient(ClientTiledPaintedLayer& aPaintedLayer, |
174 | | ClientLayerManager* aManager); |
175 | | |
176 | | protected: |
177 | | ~MultiTiledContentClient() |
178 | 0 | { |
179 | 0 | MOZ_COUNT_DTOR(MultiTiledContentClient); |
180 | 0 |
|
181 | 0 | mTiledBuffer.DiscardBuffers(); |
182 | 0 | mLowPrecisionTiledBuffer.DiscardBuffers(); |
183 | 0 | } |
184 | | |
185 | | public: |
186 | | void ClearCachedResources() override; |
187 | | void UpdatedBuffer(TiledBufferType aType) override; |
188 | | |
189 | 0 | ClientTiledLayerBuffer* GetTiledBuffer() override { return &mTiledBuffer; } |
190 | 0 | ClientTiledLayerBuffer* GetLowPrecisionTiledBuffer() override { |
191 | 0 | if (mHasLowPrecision) { |
192 | 0 | return &mLowPrecisionTiledBuffer; |
193 | 0 | } |
194 | 0 | return nullptr; |
195 | 0 | } |
196 | | |
197 | | private: |
198 | | SharedFrameMetricsHelper mSharedFrameMetricsHelper; |
199 | | ClientMultiTiledLayerBuffer mTiledBuffer; |
200 | | ClientMultiTiledLayerBuffer mLowPrecisionTiledBuffer; |
201 | | bool mHasLowPrecision; |
202 | | }; |
203 | | |
204 | | } // namespace layers |
205 | | } // namespace mozilla |
206 | | |
207 | | #endif // MOZILLA_GFX_MULTITILEDCONTENTCLIENT_H |