Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 GFX_TILEDCONTENTHOST_H |
michael@0 | 7 | #define GFX_TILEDCONTENTHOST_H |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> // for uint16_t |
michael@0 | 10 | #include <stdio.h> // for FILE |
michael@0 | 11 | #include <algorithm> // for swap |
michael@0 | 12 | #include "ContentHost.h" // for ContentHost |
michael@0 | 13 | #include "TiledLayerBuffer.h" // for TiledLayerBuffer, etc |
michael@0 | 14 | #include "CompositableHost.h" |
michael@0 | 15 | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
michael@0 | 16 | #include "mozilla/Attributes.h" // for MOZ_OVERRIDE |
michael@0 | 17 | #include "mozilla/RefPtr.h" // for RefPtr |
michael@0 | 18 | #include "mozilla/gfx/Point.h" // for Point |
michael@0 | 19 | #include "mozilla/gfx/Rect.h" // for Rect |
michael@0 | 20 | #include "mozilla/gfx/Types.h" // for Filter |
michael@0 | 21 | #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc |
michael@0 | 22 | #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor |
michael@0 | 23 | #include "mozilla/layers/LayersTypes.h" // for LayerRenderState, etc |
michael@0 | 24 | #include "mozilla/layers/TextureHost.h" // for TextureHost |
michael@0 | 25 | #include "mozilla/layers/TiledContentClient.h" |
michael@0 | 26 | #include "mozilla/mozalloc.h" // for operator delete |
michael@0 | 27 | #include "nsRegion.h" // for nsIntRegion |
michael@0 | 28 | #include "nscore.h" // for nsACString |
michael@0 | 29 | |
michael@0 | 30 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 31 | #include <ui/Fence.h> |
michael@0 | 32 | #endif |
michael@0 | 33 | |
michael@0 | 34 | class gfxReusableSurfaceWrapper; |
michael@0 | 35 | struct nsIntPoint; |
michael@0 | 36 | struct nsIntRect; |
michael@0 | 37 | struct nsIntSize; |
michael@0 | 38 | |
michael@0 | 39 | namespace mozilla { |
michael@0 | 40 | namespace gfx { |
michael@0 | 41 | class Matrix4x4; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | namespace layers { |
michael@0 | 45 | |
michael@0 | 46 | class Compositor; |
michael@0 | 47 | class ISurfaceAllocator; |
michael@0 | 48 | class Layer; |
michael@0 | 49 | class ThebesBufferData; |
michael@0 | 50 | struct EffectChain; |
michael@0 | 51 | |
michael@0 | 52 | |
michael@0 | 53 | class TileHost { |
michael@0 | 54 | public: |
michael@0 | 55 | // Constructs a placeholder TileHost. See the comments above |
michael@0 | 56 | // TiledLayerBuffer for more information on what this is used for; |
michael@0 | 57 | // essentially, this is a sentinel used to represent an invalid or blank |
michael@0 | 58 | // tile. |
michael@0 | 59 | TileHost() |
michael@0 | 60 | : mSharedLock(nullptr) |
michael@0 | 61 | , mTextureHost(nullptr) |
michael@0 | 62 | {} |
michael@0 | 63 | |
michael@0 | 64 | // Constructs a TileHost from a gfxSharedReadLock and TextureHost. |
michael@0 | 65 | TileHost(gfxSharedReadLock* aSharedLock, |
michael@0 | 66 | TextureHost* aTextureHost) |
michael@0 | 67 | : mSharedLock(aSharedLock) |
michael@0 | 68 | , mTextureHost(aTextureHost) |
michael@0 | 69 | {} |
michael@0 | 70 | |
michael@0 | 71 | TileHost(const TileHost& o) { |
michael@0 | 72 | mTextureHost = o.mTextureHost; |
michael@0 | 73 | mSharedLock = o.mSharedLock; |
michael@0 | 74 | } |
michael@0 | 75 | TileHost& operator=(const TileHost& o) { |
michael@0 | 76 | if (this == &o) { |
michael@0 | 77 | return *this; |
michael@0 | 78 | } |
michael@0 | 79 | mTextureHost = o.mTextureHost; |
michael@0 | 80 | mSharedLock = o.mSharedLock; |
michael@0 | 81 | return *this; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | bool operator== (const TileHost& o) const { |
michael@0 | 85 | return mTextureHost == o.mTextureHost; |
michael@0 | 86 | } |
michael@0 | 87 | bool operator!= (const TileHost& o) const { |
michael@0 | 88 | return mTextureHost != o.mTextureHost; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | bool IsPlaceholderTile() const { return mTextureHost == nullptr; } |
michael@0 | 92 | |
michael@0 | 93 | void ReadUnlock() { |
michael@0 | 94 | if (mSharedLock) { |
michael@0 | 95 | mSharedLock->ReadUnlock(); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | RefPtr<gfxSharedReadLock> mSharedLock; |
michael@0 | 100 | RefPtr<TextureHost> mTextureHost; |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | class TiledLayerBufferComposite |
michael@0 | 104 | : public TiledLayerBuffer<TiledLayerBufferComposite, TileHost> |
michael@0 | 105 | { |
michael@0 | 106 | friend class TiledLayerBuffer<TiledLayerBufferComposite, TileHost>; |
michael@0 | 107 | |
michael@0 | 108 | public: |
michael@0 | 109 | typedef TiledLayerBuffer<TiledLayerBufferComposite, TileHost>::Iterator Iterator; |
michael@0 | 110 | |
michael@0 | 111 | TiledLayerBufferComposite(); |
michael@0 | 112 | TiledLayerBufferComposite(ISurfaceAllocator* aAllocator, |
michael@0 | 113 | const SurfaceDescriptorTiles& aDescriptor, |
michael@0 | 114 | const nsIntRegion& aOldPaintedRegion); |
michael@0 | 115 | |
michael@0 | 116 | TileHost GetPlaceholderTile() const { return TileHost(); } |
michael@0 | 117 | |
michael@0 | 118 | // Stores the absolute resolution of the containing frame, calculated |
michael@0 | 119 | // by the sum of the resolutions of all parent layers' FrameMetrics. |
michael@0 | 120 | const CSSToParentLayerScale& GetFrameResolution() { return mFrameResolution; } |
michael@0 | 121 | |
michael@0 | 122 | void ReadUnlock(); |
michael@0 | 123 | |
michael@0 | 124 | void ReleaseTextureHosts(); |
michael@0 | 125 | |
michael@0 | 126 | /** |
michael@0 | 127 | * This will synchronously upload any necessary texture contents, making the |
michael@0 | 128 | * sources immediately available for compositing. For texture hosts that |
michael@0 | 129 | * don't have an internal buffer, this is unlikely to actually do anything. |
michael@0 | 130 | */ |
michael@0 | 131 | void Upload(); |
michael@0 | 132 | |
michael@0 | 133 | void SetCompositor(Compositor* aCompositor); |
michael@0 | 134 | |
michael@0 | 135 | bool HasDoubleBufferedTiles() { return mHasDoubleBufferedTiles; } |
michael@0 | 136 | |
michael@0 | 137 | bool IsValid() const { return !mUninitialized; } |
michael@0 | 138 | |
michael@0 | 139 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 140 | virtual void SetReleaseFence(const android::sp<android::Fence>& aReleaseFence); |
michael@0 | 141 | #endif |
michael@0 | 142 | |
michael@0 | 143 | // Recycle callback for TextureHost. |
michael@0 | 144 | // Used when TiledContentClient is present in client side. |
michael@0 | 145 | static void RecycleCallback(TextureHost* textureHost, void* aClosure); |
michael@0 | 146 | |
michael@0 | 147 | protected: |
michael@0 | 148 | TileHost ValidateTile(TileHost aTile, |
michael@0 | 149 | const nsIntPoint& aTileRect, |
michael@0 | 150 | const nsIntRegion& dirtyRect); |
michael@0 | 151 | |
michael@0 | 152 | // do nothing, the desctructor in the texture host takes care of releasing resources |
michael@0 | 153 | void ReleaseTile(TileHost aTile) {} |
michael@0 | 154 | |
michael@0 | 155 | void SwapTiles(TileHost& aTileA, TileHost& aTileB) { std::swap(aTileA, aTileB); } |
michael@0 | 156 | |
michael@0 | 157 | private: |
michael@0 | 158 | CSSToParentLayerScale mFrameResolution; |
michael@0 | 159 | bool mHasDoubleBufferedTiles; |
michael@0 | 160 | bool mUninitialized; |
michael@0 | 161 | }; |
michael@0 | 162 | |
michael@0 | 163 | /** |
michael@0 | 164 | * ContentHost for tiled Thebes layers. Since tiled layers are special snow |
michael@0 | 165 | * flakes, we have a unique update process. All the textures that back the |
michael@0 | 166 | * tiles are added in the usual way, but Updated is called on the host side |
michael@0 | 167 | * in response to a message that describes the transaction for every tile. |
michael@0 | 168 | * Composition happens in the normal way. |
michael@0 | 169 | * |
michael@0 | 170 | * TiledContentHost has a TiledLayerBufferComposite which keeps hold of the tiles. |
michael@0 | 171 | * Each tile has a reference to a texture host. During the layers transaction, we |
michael@0 | 172 | * receive a list of descriptors for the client-side tile buffer tiles |
michael@0 | 173 | * (UseTiledLayerBuffer). If we receive two transactions before a composition, |
michael@0 | 174 | * we immediately unlock and discard the unused buffer. |
michael@0 | 175 | * |
michael@0 | 176 | * When the content host is composited, we first validate the TiledLayerBuffer |
michael@0 | 177 | * (Upload), which calls Updated on each tile's texture host to make sure the |
michael@0 | 178 | * texture data has been uploaded. For single-buffered tiles, we unlock at this |
michael@0 | 179 | * point, for double-buffered tiles we unlock and discard the last composited |
michael@0 | 180 | * buffer after compositing a new one. Rendering takes us to RenderTile which |
michael@0 | 181 | * is similar to Composite for non-tiled ContentHosts. |
michael@0 | 182 | */ |
michael@0 | 183 | class TiledContentHost : public ContentHost, |
michael@0 | 184 | public TiledLayerComposer |
michael@0 | 185 | { |
michael@0 | 186 | public: |
michael@0 | 187 | TiledContentHost(const TextureInfo& aTextureInfo); |
michael@0 | 188 | |
michael@0 | 189 | ~TiledContentHost(); |
michael@0 | 190 | |
michael@0 | 191 | virtual LayerRenderState GetRenderState() MOZ_OVERRIDE |
michael@0 | 192 | { |
michael@0 | 193 | return LayerRenderState(); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | |
michael@0 | 197 | virtual bool UpdateThebes(const ThebesBufferData& aData, |
michael@0 | 198 | const nsIntRegion& aUpdated, |
michael@0 | 199 | const nsIntRegion& aOldValidRegionBack, |
michael@0 | 200 | nsIntRegion* aUpdatedRegionBack) |
michael@0 | 201 | { |
michael@0 | 202 | NS_ERROR("N/A for tiled layers"); |
michael@0 | 203 | return false; |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | const nsIntRegion& GetValidLowPrecisionRegion() const |
michael@0 | 207 | { |
michael@0 | 208 | return mLowPrecisionTiledBuffer.GetValidRegion(); |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | void UseTiledLayerBuffer(ISurfaceAllocator* aAllocator, |
michael@0 | 212 | const SurfaceDescriptorTiles& aTiledDescriptor); |
michael@0 | 213 | |
michael@0 | 214 | void Composite(EffectChain& aEffectChain, |
michael@0 | 215 | float aOpacity, |
michael@0 | 216 | const gfx::Matrix4x4& aTransform, |
michael@0 | 217 | const gfx::Filter& aFilter, |
michael@0 | 218 | const gfx::Rect& aClipRect, |
michael@0 | 219 | const nsIntRegion* aVisibleRegion = nullptr, |
michael@0 | 220 | TiledLayerProperties* aLayerProperties = nullptr); |
michael@0 | 221 | |
michael@0 | 222 | virtual CompositableType GetType() { return BUFFER_TILED; } |
michael@0 | 223 | |
michael@0 | 224 | virtual TiledLayerComposer* AsTiledLayerComposer() MOZ_OVERRIDE { return this; } |
michael@0 | 225 | |
michael@0 | 226 | virtual void Attach(Layer* aLayer, |
michael@0 | 227 | Compositor* aCompositor, |
michael@0 | 228 | AttachFlags aFlags = NO_FLAGS) MOZ_OVERRIDE; |
michael@0 | 229 | |
michael@0 | 230 | #ifdef MOZ_DUMP_PAINTING |
michael@0 | 231 | virtual void Dump(FILE* aFile=nullptr, |
michael@0 | 232 | const char* aPrefix="", |
michael@0 | 233 | bool aDumpHtml=false) MOZ_OVERRIDE; |
michael@0 | 234 | #endif |
michael@0 | 235 | |
michael@0 | 236 | virtual void PrintInfo(nsACString& aTo, const char* aPrefix); |
michael@0 | 237 | |
michael@0 | 238 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 239 | /** |
michael@0 | 240 | * Store a fence that will signal when the current buffer is no longer being read. |
michael@0 | 241 | * Similar to android's GLConsumer::setReleaseFence() |
michael@0 | 242 | */ |
michael@0 | 243 | virtual void SetReleaseFence(const android::sp<android::Fence>& aReleaseFence) |
michael@0 | 244 | { |
michael@0 | 245 | mTiledBuffer.SetReleaseFence(aReleaseFence); |
michael@0 | 246 | mLowPrecisionTiledBuffer.SetReleaseFence(aReleaseFence); |
michael@0 | 247 | } |
michael@0 | 248 | #endif |
michael@0 | 249 | |
michael@0 | 250 | private: |
michael@0 | 251 | |
michael@0 | 252 | void RenderLayerBuffer(TiledLayerBufferComposite& aLayerBuffer, |
michael@0 | 253 | EffectChain& aEffectChain, |
michael@0 | 254 | float aOpacity, |
michael@0 | 255 | const gfx::Filter& aFilter, |
michael@0 | 256 | const gfx::Rect& aClipRect, |
michael@0 | 257 | nsIntRegion aMaskRegion, |
michael@0 | 258 | gfx::Matrix4x4 aTransform); |
michael@0 | 259 | |
michael@0 | 260 | // Renders a single given tile. |
michael@0 | 261 | void RenderTile(const TileHost& aTile, |
michael@0 | 262 | EffectChain& aEffectChain, |
michael@0 | 263 | float aOpacity, |
michael@0 | 264 | const gfx::Matrix4x4& aTransform, |
michael@0 | 265 | const gfx::Filter& aFilter, |
michael@0 | 266 | const gfx::Rect& aClipRect, |
michael@0 | 267 | const nsIntRegion& aScreenRegion, |
michael@0 | 268 | const nsIntPoint& aTextureOffset, |
michael@0 | 269 | const nsIntSize& aTextureBounds); |
michael@0 | 270 | |
michael@0 | 271 | void EnsureTileStore() {} |
michael@0 | 272 | |
michael@0 | 273 | TiledLayerBufferComposite mTiledBuffer; |
michael@0 | 274 | TiledLayerBufferComposite mLowPrecisionTiledBuffer; |
michael@0 | 275 | TiledLayerBufferComposite mOldTiledBuffer; |
michael@0 | 276 | TiledLayerBufferComposite mOldLowPrecisionTiledBuffer; |
michael@0 | 277 | bool mPendingUpload; |
michael@0 | 278 | bool mPendingLowPrecisionUpload; |
michael@0 | 279 | }; |
michael@0 | 280 | |
michael@0 | 281 | } |
michael@0 | 282 | } |
michael@0 | 283 | |
michael@0 | 284 | #endif |