|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef MOZILLA_GFX_SIMPLETILEDCONTENTCLIENT_H |
|
7 #define MOZILLA_GFX_SIMPLETILEDCONTENTCLIENT_H |
|
8 |
|
9 // We include this header here so that we don't need to |
|
10 // duplicate BasicTiledLayerPaintData |
|
11 #include "TiledContentClient.h" |
|
12 |
|
13 #include "SharedBuffer.h" |
|
14 |
|
15 namespace mozilla { |
|
16 namespace layers { |
|
17 |
|
18 class ClientTiledThebesLayer; |
|
19 |
|
20 class SimpleTiledLayerTile; |
|
21 class SimpleTiledLayerBuffer; |
|
22 class SimpleClientTiledThebesLayer; |
|
23 class SimpleTiledLayerBuffer; |
|
24 |
|
25 #define GFX_SIMP_TILEDLAYER_DEBUG_OVERLAY |
|
26 |
|
27 struct SimpleTiledLayerTile |
|
28 { |
|
29 RefPtr<TextureClient> mTileBuffer; |
|
30 RefPtr<ClientLayerManager> mManager; |
|
31 nsRefPtr<SharedBuffer> mCachedBuffer; |
|
32 TimeStamp mLastUpdate; |
|
33 |
|
34 SimpleTiledLayerTile() { } |
|
35 |
|
36 SimpleTiledLayerTile(ClientLayerManager *aManager, TextureClient *aBuffer) |
|
37 : mTileBuffer(aBuffer) |
|
38 , mManager(aManager) |
|
39 { } |
|
40 |
|
41 bool operator== (const SimpleTiledLayerTile& o) const |
|
42 { |
|
43 return mTileBuffer == o.mTileBuffer; |
|
44 } |
|
45 |
|
46 bool operator!= (const SimpleTiledLayerTile& o) const |
|
47 { |
|
48 return mTileBuffer != o.mTileBuffer; |
|
49 } |
|
50 |
|
51 void SetLayerManager(ClientLayerManager *aManager) |
|
52 { |
|
53 mManager = aManager; |
|
54 } |
|
55 |
|
56 bool IsPlaceholderTile() |
|
57 { |
|
58 return mTileBuffer == nullptr; |
|
59 } |
|
60 |
|
61 TileDescriptor GetTileDescriptor() |
|
62 { |
|
63 if (mTileBuffer) |
|
64 return TexturedTileDescriptor(nullptr, mTileBuffer->GetIPDLActor(), 0); |
|
65 |
|
66 NS_NOTREACHED("Unhandled SimpleTiledLayerTile type"); |
|
67 return PlaceholderTileDescriptor(); |
|
68 } |
|
69 |
|
70 void Release() |
|
71 { |
|
72 mTileBuffer = nullptr; |
|
73 mCachedBuffer = nullptr; |
|
74 } |
|
75 }; |
|
76 |
|
77 class SimpleTiledLayerBuffer |
|
78 : public TiledLayerBuffer<SimpleTiledLayerBuffer, SimpleTiledLayerTile> |
|
79 { |
|
80 friend class TiledLayerBuffer<SimpleTiledLayerBuffer, SimpleTiledLayerTile>; |
|
81 |
|
82 public: |
|
83 SimpleTiledLayerBuffer(SimpleClientTiledThebesLayer* aThebesLayer, |
|
84 CompositableClient* aCompositableClient, |
|
85 ClientLayerManager* aManager) |
|
86 : mThebesLayer(aThebesLayer) |
|
87 , mCompositableClient(aCompositableClient) |
|
88 , mManager(aManager) |
|
89 , mLastPaintOpaque(false) |
|
90 {} |
|
91 |
|
92 SimpleTiledLayerBuffer() |
|
93 : mLastPaintOpaque(false) |
|
94 {} |
|
95 |
|
96 void PaintThebes(const nsIntRegion& aNewValidRegion, |
|
97 const nsIntRegion& aPaintRegion, |
|
98 LayerManager::DrawThebesLayerCallback aCallback, |
|
99 void* aCallbackData); |
|
100 |
|
101 SurfaceDescriptorTiles GetSurfaceDescriptorTiles(); |
|
102 |
|
103 void Release() { |
|
104 for (size_t i = 0; i < mRetainedTiles.Length(); i++) { |
|
105 mRetainedTiles[i].Release(); |
|
106 } |
|
107 } |
|
108 |
|
109 const CSSToParentLayerScale& GetFrameResolution() const { return mFrameResolution; } |
|
110 void SetFrameResolution(const CSSToParentLayerScale& aResolution) { mFrameResolution = aResolution; } |
|
111 |
|
112 bool HasFormatChanged() const; |
|
113 private: |
|
114 SimpleClientTiledThebesLayer* mThebesLayer; |
|
115 CompositableClient* mCompositableClient; |
|
116 ClientLayerManager* mManager; |
|
117 LayerManager::DrawThebesLayerCallback mCallback; |
|
118 void* mCallbackData; |
|
119 CSSToParentLayerScale mFrameResolution; |
|
120 bool mLastPaintOpaque; |
|
121 |
|
122 gfxContentType GetContentType() const; |
|
123 |
|
124 SimpleTiledLayerTile ValidateTile(SimpleTiledLayerTile aTile, |
|
125 const nsIntPoint& aTileOrigin, |
|
126 const nsIntRegion& aDirtyRect); |
|
127 |
|
128 SimpleTiledLayerTile GetPlaceholderTile() const { return SimpleTiledLayerTile(); } |
|
129 |
|
130 void ReleaseTile(SimpleTiledLayerTile aTile) { aTile.Release(); } |
|
131 |
|
132 void SwapTiles(SimpleTiledLayerTile& aTileA, SimpleTiledLayerTile& aTileB) { std::swap(aTileA, aTileB); } |
|
133 }; |
|
134 |
|
135 class SimpleTiledContentClient : public CompositableClient |
|
136 { |
|
137 friend class SimpleClientTiledThebesLayer; |
|
138 |
|
139 public: |
|
140 SimpleTiledContentClient(SimpleClientTiledThebesLayer* aThebesLayer, |
|
141 ClientLayerManager* aManager); |
|
142 |
|
143 ~SimpleTiledContentClient(); |
|
144 |
|
145 virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE |
|
146 { |
|
147 return TextureInfo(BUFFER_SIMPLE_TILED); |
|
148 } |
|
149 |
|
150 void UseTiledLayerBuffer(); |
|
151 |
|
152 private: |
|
153 SimpleTiledLayerBuffer mTiledBuffer; |
|
154 }; |
|
155 |
|
156 class SimpleClientTiledThebesLayer : public ThebesLayer, |
|
157 public ClientLayer |
|
158 { |
|
159 typedef ThebesLayer Base; |
|
160 |
|
161 public: |
|
162 SimpleClientTiledThebesLayer(ClientLayerManager* const aManager); |
|
163 ~SimpleClientTiledThebesLayer(); |
|
164 |
|
165 // Thebes Layer |
|
166 virtual Layer* AsLayer() { return this; } |
|
167 virtual void InvalidateRegion(const nsIntRegion& aRegion) { |
|
168 mInvalidRegion.Or(mInvalidRegion, aRegion); |
|
169 mValidRegion.Sub(mValidRegion, aRegion); |
|
170 } |
|
171 |
|
172 // Shadow methods |
|
173 virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs); |
|
174 virtual ShadowableLayer* AsShadowableLayer() { return this; } |
|
175 |
|
176 virtual void Disconnect() { ClientLayer::Disconnect(); } |
|
177 |
|
178 virtual void RenderLayer(); |
|
179 |
|
180 protected: |
|
181 ClientLayerManager* ClientManager() { return static_cast<ClientLayerManager*>(mManager); } |
|
182 |
|
183 RefPtr<SimpleTiledContentClient> mContentClient; |
|
184 }; |
|
185 |
|
186 } // mozilla |
|
187 } // layers |
|
188 |
|
189 #endif |