Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef MOZILLA_GFX_TILEDCONTENTCLIENT_H |
michael@0 | 7 | #define MOZILLA_GFX_TILEDCONTENTCLIENT_H |
michael@0 | 8 | |
michael@0 | 9 | #include <stddef.h> // for size_t |
michael@0 | 10 | #include <stdint.h> // for uint16_t |
michael@0 | 11 | #include <algorithm> // for swap |
michael@0 | 12 | #include "Layers.h" // for LayerManager, etc |
michael@0 | 13 | #include "TiledLayerBuffer.h" // for TiledLayerBuffer |
michael@0 | 14 | #include "Units.h" // for CSSPoint |
michael@0 | 15 | #include "gfx3DMatrix.h" // for gfx3DMatrix |
michael@0 | 16 | #include "gfxTypes.h" |
michael@0 | 17 | #include "mozilla/Attributes.h" // for MOZ_OVERRIDE |
michael@0 | 18 | #include "mozilla/RefPtr.h" // for RefPtr |
michael@0 | 19 | #include "mozilla/ipc/Shmem.h" // for Shmem |
michael@0 | 20 | #include "mozilla/ipc/SharedMemory.h" // for SharedMemory |
michael@0 | 21 | #include "mozilla/layers/CompositableClient.h" // for CompositableClient |
michael@0 | 22 | #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc |
michael@0 | 23 | #include "mozilla/layers/LayersMessages.h" // for TileDescriptor |
michael@0 | 24 | #include "mozilla/layers/TextureClient.h" |
michael@0 | 25 | #include "mozilla/layers/TextureClientPool.h" |
michael@0 | 26 | #include "ClientLayerManager.h" |
michael@0 | 27 | #include "mozilla/mozalloc.h" // for operator delete |
michael@0 | 28 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 29 | #include "nsISupportsImpl.h" // for MOZ_COUNT_DTOR |
michael@0 | 30 | #include "nsPoint.h" // for nsIntPoint |
michael@0 | 31 | #include "nsRect.h" // for nsIntRect |
michael@0 | 32 | #include "nsRegion.h" // for nsIntRegion |
michael@0 | 33 | #include "nsTArray.h" // for nsTArray, nsTArray_Impl, etc |
michael@0 | 34 | #include "mozilla/layers/ISurfaceAllocator.h" |
michael@0 | 35 | #include "gfxReusableSurfaceWrapper.h" |
michael@0 | 36 | #include "pratom.h" // For PR_ATOMIC_INCREMENT/DECREMENT |
michael@0 | 37 | #include "gfxPrefs.h" |
michael@0 | 38 | |
michael@0 | 39 | namespace mozilla { |
michael@0 | 40 | namespace layers { |
michael@0 | 41 | |
michael@0 | 42 | class BasicTileDescriptor; |
michael@0 | 43 | class ClientTiledThebesLayer; |
michael@0 | 44 | class ClientLayerManager; |
michael@0 | 45 | |
michael@0 | 46 | |
michael@0 | 47 | // A class to help implement copy-on-write semantics for shared tiles. |
michael@0 | 48 | class gfxSharedReadLock { |
michael@0 | 49 | protected: |
michael@0 | 50 | virtual ~gfxSharedReadLock() {} |
michael@0 | 51 | |
michael@0 | 52 | public: |
michael@0 | 53 | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxSharedReadLock) |
michael@0 | 54 | |
michael@0 | 55 | virtual int32_t ReadLock() = 0; |
michael@0 | 56 | virtual int32_t ReadUnlock() = 0; |
michael@0 | 57 | virtual int32_t GetReadCount() = 0; |
michael@0 | 58 | virtual bool IsValid() const = 0; |
michael@0 | 59 | |
michael@0 | 60 | enum gfxSharedReadLockType { |
michael@0 | 61 | TYPE_MEMORY, |
michael@0 | 62 | TYPE_SHMEM |
michael@0 | 63 | }; |
michael@0 | 64 | virtual gfxSharedReadLockType GetType() = 0; |
michael@0 | 65 | |
michael@0 | 66 | protected: |
michael@0 | 67 | NS_DECL_OWNINGTHREAD |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | class gfxMemorySharedReadLock : public gfxSharedReadLock { |
michael@0 | 71 | public: |
michael@0 | 72 | gfxMemorySharedReadLock(); |
michael@0 | 73 | |
michael@0 | 74 | ~gfxMemorySharedReadLock(); |
michael@0 | 75 | |
michael@0 | 76 | virtual int32_t ReadLock() MOZ_OVERRIDE; |
michael@0 | 77 | |
michael@0 | 78 | virtual int32_t ReadUnlock() MOZ_OVERRIDE; |
michael@0 | 79 | |
michael@0 | 80 | virtual int32_t GetReadCount() MOZ_OVERRIDE; |
michael@0 | 81 | |
michael@0 | 82 | virtual gfxSharedReadLockType GetType() MOZ_OVERRIDE { return TYPE_MEMORY; } |
michael@0 | 83 | |
michael@0 | 84 | virtual bool IsValid() const MOZ_OVERRIDE { return true; }; |
michael@0 | 85 | |
michael@0 | 86 | private: |
michael@0 | 87 | int32_t mReadCount; |
michael@0 | 88 | }; |
michael@0 | 89 | |
michael@0 | 90 | class gfxShmSharedReadLock : public gfxSharedReadLock { |
michael@0 | 91 | private: |
michael@0 | 92 | struct ShmReadLockInfo { |
michael@0 | 93 | int32_t readCount; |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | public: |
michael@0 | 97 | gfxShmSharedReadLock(ISurfaceAllocator* aAllocator); |
michael@0 | 98 | |
michael@0 | 99 | ~gfxShmSharedReadLock(); |
michael@0 | 100 | |
michael@0 | 101 | virtual int32_t ReadLock() MOZ_OVERRIDE; |
michael@0 | 102 | |
michael@0 | 103 | virtual int32_t ReadUnlock() MOZ_OVERRIDE; |
michael@0 | 104 | |
michael@0 | 105 | virtual int32_t GetReadCount() MOZ_OVERRIDE; |
michael@0 | 106 | |
michael@0 | 107 | virtual bool IsValid() const MOZ_OVERRIDE { return mAllocSuccess; }; |
michael@0 | 108 | |
michael@0 | 109 | virtual gfxSharedReadLockType GetType() MOZ_OVERRIDE { return TYPE_SHMEM; } |
michael@0 | 110 | |
michael@0 | 111 | mozilla::layers::ShmemSection& GetShmemSection() { return mShmemSection; } |
michael@0 | 112 | |
michael@0 | 113 | static already_AddRefed<gfxShmSharedReadLock> |
michael@0 | 114 | Open(mozilla::layers::ISurfaceAllocator* aAllocator, const mozilla::layers::ShmemSection& aShmemSection) |
michael@0 | 115 | { |
michael@0 | 116 | nsRefPtr<gfxShmSharedReadLock> readLock = new gfxShmSharedReadLock(aAllocator, aShmemSection); |
michael@0 | 117 | return readLock.forget(); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | private: |
michael@0 | 121 | gfxShmSharedReadLock(ISurfaceAllocator* aAllocator, const mozilla::layers::ShmemSection& aShmemSection) |
michael@0 | 122 | : mAllocator(aAllocator) |
michael@0 | 123 | , mShmemSection(aShmemSection) |
michael@0 | 124 | , mAllocSuccess(true) |
michael@0 | 125 | { |
michael@0 | 126 | MOZ_COUNT_CTOR(gfxShmSharedReadLock); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | ShmReadLockInfo* GetShmReadLockInfoPtr() |
michael@0 | 130 | { |
michael@0 | 131 | return reinterpret_cast<ShmReadLockInfo*> |
michael@0 | 132 | (mShmemSection.shmem().get<char>() + mShmemSection.offset()); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | RefPtr<ISurfaceAllocator> mAllocator; |
michael@0 | 136 | mozilla::layers::ShmemSection mShmemSection; |
michael@0 | 137 | bool mAllocSuccess; |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | /** |
michael@0 | 141 | * Represent a single tile in tiled buffer. The buffer keeps tiles, |
michael@0 | 142 | * each tile keeps a reference to a texture client and a read-lock. This |
michael@0 | 143 | * read-lock is used to help implement a copy-on-write mechanism. The tile |
michael@0 | 144 | * should be locked before being sent to the compositor. The compositor should |
michael@0 | 145 | * unlock the read-lock as soon as it has finished with the buffer in the |
michael@0 | 146 | * TextureHost to prevent more textures being created than is necessary. |
michael@0 | 147 | * Ideal place to store per tile debug information. |
michael@0 | 148 | */ |
michael@0 | 149 | struct TileClient |
michael@0 | 150 | { |
michael@0 | 151 | // Placeholder |
michael@0 | 152 | TileClient(); |
michael@0 | 153 | |
michael@0 | 154 | TileClient(const TileClient& o); |
michael@0 | 155 | |
michael@0 | 156 | TileClient& operator=(const TileClient& o); |
michael@0 | 157 | |
michael@0 | 158 | bool operator== (const TileClient& o) const |
michael@0 | 159 | { |
michael@0 | 160 | return mFrontBuffer == o.mFrontBuffer; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | bool operator!= (const TileClient& o) const |
michael@0 | 164 | { |
michael@0 | 165 | return mFrontBuffer != o.mFrontBuffer; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | void SetLayerManager(ClientLayerManager *aManager) |
michael@0 | 169 | { |
michael@0 | 170 | mManager = aManager; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | bool IsPlaceholderTile() |
michael@0 | 174 | { |
michael@0 | 175 | return mBackBuffer == nullptr && mFrontBuffer == nullptr; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | void ReadUnlock() |
michael@0 | 179 | { |
michael@0 | 180 | MOZ_ASSERT(mFrontLock, "ReadLock with no gfxSharedReadLock"); |
michael@0 | 181 | if (mFrontLock) { |
michael@0 | 182 | mFrontLock->ReadUnlock(); |
michael@0 | 183 | } |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | void ReadLock() |
michael@0 | 187 | { |
michael@0 | 188 | MOZ_ASSERT(mFrontLock, "ReadLock with no gfxSharedReadLock"); |
michael@0 | 189 | if (mFrontLock) { |
michael@0 | 190 | mFrontLock->ReadLock(); |
michael@0 | 191 | } |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | void Release() |
michael@0 | 195 | { |
michael@0 | 196 | DiscardFrontBuffer(); |
michael@0 | 197 | DiscardBackBuffer(); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | TileDescriptor GetTileDescriptor(); |
michael@0 | 201 | |
michael@0 | 202 | /** |
michael@0 | 203 | * Swaps the front and back buffers. |
michael@0 | 204 | */ |
michael@0 | 205 | void Flip(); |
michael@0 | 206 | |
michael@0 | 207 | /** |
michael@0 | 208 | * Returns an unlocked TextureClient that can be used for writing new |
michael@0 | 209 | * data to the tile. This may flip the front-buffer to the back-buffer if |
michael@0 | 210 | * the front-buffer is still locked by the host, or does not have an |
michael@0 | 211 | * internal buffer (and so will always be locked). |
michael@0 | 212 | */ |
michael@0 | 213 | TextureClient* GetBackBuffer(const nsIntRegion& aDirtyRegion, |
michael@0 | 214 | TextureClientPool *aPool, |
michael@0 | 215 | bool *aCreatedTextureClient, |
michael@0 | 216 | bool aCanRerasterizeValidRegion); |
michael@0 | 217 | |
michael@0 | 218 | void DiscardFrontBuffer(); |
michael@0 | 219 | |
michael@0 | 220 | void DiscardBackBuffer(); |
michael@0 | 221 | |
michael@0 | 222 | RefPtr<TextureClient> mBackBuffer; |
michael@0 | 223 | RefPtr<TextureClient> mFrontBuffer; |
michael@0 | 224 | RefPtr<gfxSharedReadLock> mBackLock; |
michael@0 | 225 | RefPtr<gfxSharedReadLock> mFrontLock; |
michael@0 | 226 | RefPtr<ClientLayerManager> mManager; |
michael@0 | 227 | #ifdef GFX_TILEDLAYER_DEBUG_OVERLAY |
michael@0 | 228 | TimeStamp mLastUpdate; |
michael@0 | 229 | #endif |
michael@0 | 230 | nsIntRegion mInvalidFront; |
michael@0 | 231 | nsIntRegion mInvalidBack; |
michael@0 | 232 | |
michael@0 | 233 | private: |
michael@0 | 234 | void ValidateBackBufferFromFront(const nsIntRegion &aDirtyRegion, |
michael@0 | 235 | bool aCanRerasterizeValidRegion); |
michael@0 | 236 | }; |
michael@0 | 237 | |
michael@0 | 238 | /** |
michael@0 | 239 | * This struct stores all the data necessary to perform a paint so that it |
michael@0 | 240 | * doesn't need to be recalculated on every repeated transaction. |
michael@0 | 241 | */ |
michael@0 | 242 | struct BasicTiledLayerPaintData { |
michael@0 | 243 | /* |
michael@0 | 244 | * The scroll offset of the content from the nearest ancestor layer that |
michael@0 | 245 | * represents scrollable content with a display port set. |
michael@0 | 246 | */ |
michael@0 | 247 | ParentLayerPoint mScrollOffset; |
michael@0 | 248 | |
michael@0 | 249 | /* |
michael@0 | 250 | * The scroll offset of the content from the nearest ancestor layer that |
michael@0 | 251 | * represents scrollable content with a display port set, for the last |
michael@0 | 252 | * layer update transaction. |
michael@0 | 253 | */ |
michael@0 | 254 | ParentLayerPoint mLastScrollOffset; |
michael@0 | 255 | |
michael@0 | 256 | /* |
michael@0 | 257 | * The transform matrix to go from Screen units to ParentLayer units. |
michael@0 | 258 | */ |
michael@0 | 259 | gfx3DMatrix mTransformParentLayerToLayoutDevice; |
michael@0 | 260 | |
michael@0 | 261 | /* |
michael@0 | 262 | * The critical displayport of the content from the nearest ancestor layer |
michael@0 | 263 | * that represents scrollable content with a display port set. Empty if a |
michael@0 | 264 | * critical displayport is not set. |
michael@0 | 265 | * |
michael@0 | 266 | * This is in LayoutDevice coordinates, but is stored as an nsIntRect for |
michael@0 | 267 | * convenience when intersecting with the layer's mValidRegion. |
michael@0 | 268 | */ |
michael@0 | 269 | nsIntRect mCriticalDisplayPort; |
michael@0 | 270 | |
michael@0 | 271 | /* |
michael@0 | 272 | * The viewport of the content from the nearest ancestor layer that |
michael@0 | 273 | * represents scrollable content with a display port set. |
michael@0 | 274 | */ |
michael@0 | 275 | LayoutDeviceRect mViewport; |
michael@0 | 276 | |
michael@0 | 277 | /* |
michael@0 | 278 | * The render resolution of the document that the content this layer |
michael@0 | 279 | * represents is in. |
michael@0 | 280 | */ |
michael@0 | 281 | CSSToParentLayerScale mResolution; |
michael@0 | 282 | |
michael@0 | 283 | /* |
michael@0 | 284 | * The composition bounds of the layer, in LayoutDevice coordinates. This is |
michael@0 | 285 | * used to make sure that tiled updates to regions that are visible to the |
michael@0 | 286 | * user are grouped coherently. |
michael@0 | 287 | */ |
michael@0 | 288 | LayoutDeviceRect mCompositionBounds; |
michael@0 | 289 | |
michael@0 | 290 | /* |
michael@0 | 291 | * Low precision updates are always executed a tile at a time in repeated |
michael@0 | 292 | * transactions. This counter is set to 1 on the first transaction of a low |
michael@0 | 293 | * precision update, and incremented for each subsequent transaction. |
michael@0 | 294 | */ |
michael@0 | 295 | uint16_t mLowPrecisionPaintCount; |
michael@0 | 296 | |
michael@0 | 297 | /* |
michael@0 | 298 | * Whether this is the first time this layer is painting |
michael@0 | 299 | */ |
michael@0 | 300 | bool mFirstPaint : 1; |
michael@0 | 301 | |
michael@0 | 302 | /* |
michael@0 | 303 | * Whether there is further work to complete this paint. This is used to |
michael@0 | 304 | * determine whether or not to repeat the transaction when painting |
michael@0 | 305 | * progressively. |
michael@0 | 306 | */ |
michael@0 | 307 | bool mPaintFinished : 1; |
michael@0 | 308 | }; |
michael@0 | 309 | |
michael@0 | 310 | class SharedFrameMetricsHelper |
michael@0 | 311 | { |
michael@0 | 312 | public: |
michael@0 | 313 | SharedFrameMetricsHelper(); |
michael@0 | 314 | ~SharedFrameMetricsHelper(); |
michael@0 | 315 | |
michael@0 | 316 | /** |
michael@0 | 317 | * This is called by the BasicTileLayer to determine if it is still interested |
michael@0 | 318 | * in the update of this display-port to continue. We can return true here |
michael@0 | 319 | * to abort the current update and continue with any subsequent ones. This |
michael@0 | 320 | * is useful for slow-to-render pages when the display-port starts lagging |
michael@0 | 321 | * behind enough that continuing to draw it is wasted effort. |
michael@0 | 322 | */ |
michael@0 | 323 | bool UpdateFromCompositorFrameMetrics(ContainerLayer* aLayer, |
michael@0 | 324 | bool aHasPendingNewThebesContent, |
michael@0 | 325 | bool aLowPrecision, |
michael@0 | 326 | ParentLayerRect& aCompositionBounds, |
michael@0 | 327 | CSSToParentLayerScale& aZoom); |
michael@0 | 328 | |
michael@0 | 329 | /** |
michael@0 | 330 | * When a shared FrameMetrics can not be found for a given layer, |
michael@0 | 331 | * this function is used to find the first non-empty composition bounds |
michael@0 | 332 | * by traversing up the layer tree. |
michael@0 | 333 | */ |
michael@0 | 334 | void FindFallbackContentFrameMetrics(ContainerLayer* aLayer, |
michael@0 | 335 | ParentLayerRect& aCompositionBounds, |
michael@0 | 336 | CSSToParentLayerScale& aZoom); |
michael@0 | 337 | /** |
michael@0 | 338 | * Determines if the compositor's upcoming composition bounds has fallen |
michael@0 | 339 | * outside of the contents display port. If it has then the compositor |
michael@0 | 340 | * will start to checker board. Checker boarding is when the compositor |
michael@0 | 341 | * tries to composite a tile and it is not available. Historically |
michael@0 | 342 | * a tile with a checker board pattern was used. Now a blank tile is used. |
michael@0 | 343 | */ |
michael@0 | 344 | bool AboutToCheckerboard(const FrameMetrics& aContentMetrics, |
michael@0 | 345 | const FrameMetrics& aCompositorMetrics); |
michael@0 | 346 | private: |
michael@0 | 347 | bool mLastProgressiveUpdateWasLowPrecision; |
michael@0 | 348 | bool mProgressiveUpdateWasInDanger; |
michael@0 | 349 | }; |
michael@0 | 350 | |
michael@0 | 351 | /** |
michael@0 | 352 | * Provide an instance of TiledLayerBuffer backed by drawable TextureClients. |
michael@0 | 353 | * This buffer provides an implementation of ValidateTile using a |
michael@0 | 354 | * thebes callback and can support painting using a single paint buffer. |
michael@0 | 355 | * Whether a single paint buffer is used is controlled by |
michael@0 | 356 | * gfxPrefs::PerTileDrawing(). |
michael@0 | 357 | */ |
michael@0 | 358 | class ClientTiledLayerBuffer |
michael@0 | 359 | : public TiledLayerBuffer<ClientTiledLayerBuffer, TileClient> |
michael@0 | 360 | { |
michael@0 | 361 | friend class TiledLayerBuffer<ClientTiledLayerBuffer, TileClient>; |
michael@0 | 362 | |
michael@0 | 363 | public: |
michael@0 | 364 | ClientTiledLayerBuffer(ClientTiledThebesLayer* aThebesLayer, |
michael@0 | 365 | CompositableClient* aCompositableClient, |
michael@0 | 366 | ClientLayerManager* aManager, |
michael@0 | 367 | SharedFrameMetricsHelper* aHelper); |
michael@0 | 368 | ClientTiledLayerBuffer() |
michael@0 | 369 | : mThebesLayer(nullptr) |
michael@0 | 370 | , mCompositableClient(nullptr) |
michael@0 | 371 | , mManager(nullptr) |
michael@0 | 372 | , mLastPaintOpaque(false) |
michael@0 | 373 | , mSharedFrameMetricsHelper(nullptr) |
michael@0 | 374 | {} |
michael@0 | 375 | |
michael@0 | 376 | void PaintThebes(const nsIntRegion& aNewValidRegion, |
michael@0 | 377 | const nsIntRegion& aPaintRegion, |
michael@0 | 378 | LayerManager::DrawThebesLayerCallback aCallback, |
michael@0 | 379 | void* aCallbackData); |
michael@0 | 380 | |
michael@0 | 381 | void ReadUnlock(); |
michael@0 | 382 | |
michael@0 | 383 | void ReadLock(); |
michael@0 | 384 | |
michael@0 | 385 | void Release(); |
michael@0 | 386 | |
michael@0 | 387 | void DiscardBackBuffers(); |
michael@0 | 388 | |
michael@0 | 389 | const CSSToParentLayerScale& GetFrameResolution() { return mFrameResolution; } |
michael@0 | 390 | |
michael@0 | 391 | void SetFrameResolution(const CSSToParentLayerScale& aResolution) { mFrameResolution = aResolution; } |
michael@0 | 392 | |
michael@0 | 393 | bool HasFormatChanged() const; |
michael@0 | 394 | |
michael@0 | 395 | /** |
michael@0 | 396 | * Performs a progressive update of a given tiled buffer. |
michael@0 | 397 | * See ComputeProgressiveUpdateRegion below for parameter documentation. |
michael@0 | 398 | */ |
michael@0 | 399 | bool ProgressiveUpdate(nsIntRegion& aValidRegion, |
michael@0 | 400 | nsIntRegion& aInvalidRegion, |
michael@0 | 401 | const nsIntRegion& aOldValidRegion, |
michael@0 | 402 | BasicTiledLayerPaintData* aPaintData, |
michael@0 | 403 | LayerManager::DrawThebesLayerCallback aCallback, |
michael@0 | 404 | void* aCallbackData); |
michael@0 | 405 | |
michael@0 | 406 | SurfaceDescriptorTiles GetSurfaceDescriptorTiles(); |
michael@0 | 407 | |
michael@0 | 408 | protected: |
michael@0 | 409 | TileClient ValidateTile(TileClient aTile, |
michael@0 | 410 | const nsIntPoint& aTileRect, |
michael@0 | 411 | const nsIntRegion& dirtyRect); |
michael@0 | 412 | |
michael@0 | 413 | // If this returns true, we perform the paint operation into a single large |
michael@0 | 414 | // buffer and copy it out to the tiles instead of calling PaintThebes() on |
michael@0 | 415 | // each tile individually. Somewhat surprisingly, this turns out to be faster |
michael@0 | 416 | // on Android. |
michael@0 | 417 | bool UseSinglePaintBuffer() { return !gfxPrefs::PerTileDrawing(); } |
michael@0 | 418 | |
michael@0 | 419 | void ReleaseTile(TileClient aTile) { aTile.Release(); } |
michael@0 | 420 | |
michael@0 | 421 | void SwapTiles(TileClient& aTileA, TileClient& aTileB) { std::swap(aTileA, aTileB); } |
michael@0 | 422 | |
michael@0 | 423 | TileClient GetPlaceholderTile() const { return TileClient(); } |
michael@0 | 424 | |
michael@0 | 425 | private: |
michael@0 | 426 | gfxContentType GetContentType() const; |
michael@0 | 427 | ClientTiledThebesLayer* mThebesLayer; |
michael@0 | 428 | CompositableClient* mCompositableClient; |
michael@0 | 429 | ClientLayerManager* mManager; |
michael@0 | 430 | LayerManager::DrawThebesLayerCallback mCallback; |
michael@0 | 431 | void* mCallbackData; |
michael@0 | 432 | CSSToParentLayerScale mFrameResolution; |
michael@0 | 433 | bool mLastPaintOpaque; |
michael@0 | 434 | |
michael@0 | 435 | // The DrawTarget we use when UseSinglePaintBuffer() above is true. |
michael@0 | 436 | RefPtr<gfx::DrawTarget> mSinglePaintDrawTarget; |
michael@0 | 437 | nsIntPoint mSinglePaintBufferOffset; |
michael@0 | 438 | SharedFrameMetricsHelper* mSharedFrameMetricsHelper; |
michael@0 | 439 | |
michael@0 | 440 | /** |
michael@0 | 441 | * Calculates the region to update in a single progressive update transaction. |
michael@0 | 442 | * This employs some heuristics to update the most 'sensible' region to |
michael@0 | 443 | * update at this point in time, and how large an update should be performed |
michael@0 | 444 | * at once to maintain visual coherency. |
michael@0 | 445 | * |
michael@0 | 446 | * aInvalidRegion is the current invalid region. |
michael@0 | 447 | * aOldValidRegion is the valid region of mTiledBuffer at the beginning of the |
michael@0 | 448 | * current transaction. |
michael@0 | 449 | * aRegionToPaint will be filled with the region to update. This may be empty, |
michael@0 | 450 | * which indicates that there is no more work to do. |
michael@0 | 451 | * aIsRepeated should be true if this function has already been called during |
michael@0 | 452 | * this transaction. |
michael@0 | 453 | * |
michael@0 | 454 | * Returns true if it should be called again, false otherwise. In the case |
michael@0 | 455 | * that aRegionToPaint is empty, this will return aIsRepeated for convenience. |
michael@0 | 456 | */ |
michael@0 | 457 | bool ComputeProgressiveUpdateRegion(const nsIntRegion& aInvalidRegion, |
michael@0 | 458 | const nsIntRegion& aOldValidRegion, |
michael@0 | 459 | nsIntRegion& aRegionToPaint, |
michael@0 | 460 | BasicTiledLayerPaintData* aPaintData, |
michael@0 | 461 | bool aIsRepeated); |
michael@0 | 462 | }; |
michael@0 | 463 | |
michael@0 | 464 | class TiledContentClient : public CompositableClient |
michael@0 | 465 | { |
michael@0 | 466 | // XXX: for now the layer which owns us interacts directly with our buffers. |
michael@0 | 467 | // We should have a content client for each tiled buffer which manages its |
michael@0 | 468 | // own valid region, resolution, etc. Then we could have a much cleaner |
michael@0 | 469 | // interface and tidy up BasicTiledThebesLayer::PaintThebes (bug 862547). |
michael@0 | 470 | friend class ClientTiledThebesLayer; |
michael@0 | 471 | |
michael@0 | 472 | public: |
michael@0 | 473 | TiledContentClient(ClientTiledThebesLayer* aThebesLayer, |
michael@0 | 474 | ClientLayerManager* aManager); |
michael@0 | 475 | |
michael@0 | 476 | ~TiledContentClient() |
michael@0 | 477 | { |
michael@0 | 478 | MOZ_COUNT_DTOR(TiledContentClient); |
michael@0 | 479 | |
michael@0 | 480 | mTiledBuffer.Release(); |
michael@0 | 481 | mLowPrecisionTiledBuffer.Release(); |
michael@0 | 482 | } |
michael@0 | 483 | |
michael@0 | 484 | virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE |
michael@0 | 485 | { |
michael@0 | 486 | return TextureInfo(BUFFER_TILED); |
michael@0 | 487 | } |
michael@0 | 488 | |
michael@0 | 489 | virtual void ClearCachedResources() MOZ_OVERRIDE; |
michael@0 | 490 | |
michael@0 | 491 | enum TiledBufferType { |
michael@0 | 492 | TILED_BUFFER, |
michael@0 | 493 | LOW_PRECISION_TILED_BUFFER |
michael@0 | 494 | }; |
michael@0 | 495 | void UseTiledLayerBuffer(TiledBufferType aType); |
michael@0 | 496 | |
michael@0 | 497 | private: |
michael@0 | 498 | SharedFrameMetricsHelper mSharedFrameMetricsHelper; |
michael@0 | 499 | ClientTiledLayerBuffer mTiledBuffer; |
michael@0 | 500 | ClientTiledLayerBuffer mLowPrecisionTiledBuffer; |
michael@0 | 501 | }; |
michael@0 | 502 | |
michael@0 | 503 | } |
michael@0 | 504 | } |
michael@0 | 505 | |
michael@0 | 506 | #endif |