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_CONTENTHOST_H |
michael@0 | 7 | #define GFX_CONTENTHOST_H |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> // for uint32_t |
michael@0 | 10 | #include <stdio.h> // for FILE |
michael@0 | 11 | #include "mozilla-config.h" // for MOZ_DUMP_PAINTING |
michael@0 | 12 | #include "CompositableHost.h" // for CompositableHost, etc |
michael@0 | 13 | #include "RotatedBuffer.h" // for RotatedContentBuffer, etc |
michael@0 | 14 | #include "mozilla/Attributes.h" // for MOZ_OVERRIDE |
michael@0 | 15 | #include "mozilla/RefPtr.h" // for RefPtr |
michael@0 | 16 | #include "mozilla/gfx/BasePoint.h" // for BasePoint |
michael@0 | 17 | #include "mozilla/gfx/Point.h" // for Point |
michael@0 | 18 | #include "mozilla/gfx/Rect.h" // for Rect |
michael@0 | 19 | #include "mozilla/gfx/Types.h" // for Filter |
michael@0 | 20 | #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc |
michael@0 | 21 | #include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator |
michael@0 | 22 | #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor |
michael@0 | 23 | #include "mozilla/layers/LayersTypes.h" // for etc |
michael@0 | 24 | #include "mozilla/layers/TextureHost.h" // for TextureHost |
michael@0 | 25 | #include "mozilla/mozalloc.h" // for operator delete |
michael@0 | 26 | #include "nsAutoPtr.h" // for nsAutoPtr |
michael@0 | 27 | #include "nsCOMPtr.h" // for already_AddRefed |
michael@0 | 28 | #include "nsDebug.h" // for NS_RUNTIMEABORT |
michael@0 | 29 | #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc |
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 |
michael@0 | 34 | #include "nscore.h" // for nsACString |
michael@0 | 35 | |
michael@0 | 36 | namespace mozilla { |
michael@0 | 37 | namespace gfx { |
michael@0 | 38 | class Matrix4x4; |
michael@0 | 39 | } |
michael@0 | 40 | namespace layers { |
michael@0 | 41 | class Compositor; |
michael@0 | 42 | class ThebesBufferData; |
michael@0 | 43 | class TiledLayerComposer; |
michael@0 | 44 | struct EffectChain; |
michael@0 | 45 | class TextureImageTextureSourceOGL; |
michael@0 | 46 | |
michael@0 | 47 | struct TexturedEffect; |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * ContentHosts are used for compositing Thebes layers, always matched by a |
michael@0 | 51 | * ContentClient of the same type. |
michael@0 | 52 | * |
michael@0 | 53 | * ContentHosts support only UpdateThebes(), not Update(). |
michael@0 | 54 | */ |
michael@0 | 55 | class ContentHost : public CompositableHost |
michael@0 | 56 | { |
michael@0 | 57 | public: |
michael@0 | 58 | // Subclasses should implement this method if they support being used as a |
michael@0 | 59 | // tiling. |
michael@0 | 60 | virtual TiledLayerComposer* AsTiledLayerComposer() { return nullptr; } |
michael@0 | 61 | |
michael@0 | 62 | virtual bool UpdateThebes(const ThebesBufferData& aData, |
michael@0 | 63 | const nsIntRegion& aUpdated, |
michael@0 | 64 | const nsIntRegion& aOldValidRegionBack, |
michael@0 | 65 | nsIntRegion* aUpdatedRegionBack) = 0; |
michael@0 | 66 | |
michael@0 | 67 | virtual void SetPaintWillResample(bool aResample) { } |
michael@0 | 68 | |
michael@0 | 69 | protected: |
michael@0 | 70 | ContentHost(const TextureInfo& aTextureInfo) |
michael@0 | 71 | : CompositableHost(aTextureInfo) |
michael@0 | 72 | {} |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * Base class for non-tiled ContentHosts. |
michael@0 | 77 | * |
michael@0 | 78 | * Ownership of the SurfaceDescriptor and the resources it represents is passed |
michael@0 | 79 | * from the ContentClient to the ContentHost when the TextureClient/Hosts are |
michael@0 | 80 | * created, that is recevied here by SetTextureHosts which assigns one or two |
michael@0 | 81 | * texture hosts (for single and double buffering) to the ContentHost. |
michael@0 | 82 | * |
michael@0 | 83 | * It is the responsibility of the ContentHost to destroy its resources when |
michael@0 | 84 | * they are recreated or the ContentHost dies. |
michael@0 | 85 | */ |
michael@0 | 86 | class ContentHostBase : public ContentHost |
michael@0 | 87 | { |
michael@0 | 88 | public: |
michael@0 | 89 | typedef RotatedContentBuffer::ContentType ContentType; |
michael@0 | 90 | typedef RotatedContentBuffer::PaintState PaintState; |
michael@0 | 91 | |
michael@0 | 92 | ContentHostBase(const TextureInfo& aTextureInfo); |
michael@0 | 93 | virtual ~ContentHostBase(); |
michael@0 | 94 | |
michael@0 | 95 | virtual void Composite(EffectChain& aEffectChain, |
michael@0 | 96 | float aOpacity, |
michael@0 | 97 | const gfx::Matrix4x4& aTransform, |
michael@0 | 98 | const gfx::Filter& aFilter, |
michael@0 | 99 | const gfx::Rect& aClipRect, |
michael@0 | 100 | const nsIntRegion* aVisibleRegion = nullptr, |
michael@0 | 101 | TiledLayerProperties* aLayerProperties = nullptr); |
michael@0 | 102 | |
michael@0 | 103 | virtual void SetPaintWillResample(bool aResample) { mPaintWillResample = aResample; } |
michael@0 | 104 | |
michael@0 | 105 | virtual bool Lock() = 0; |
michael@0 | 106 | virtual void Unlock() = 0; |
michael@0 | 107 | |
michael@0 | 108 | virtual NewTextureSource* GetTextureSource() = 0; |
michael@0 | 109 | virtual NewTextureSource* GetTextureSourceOnWhite() = 0; |
michael@0 | 110 | |
michael@0 | 111 | protected: |
michael@0 | 112 | virtual nsIntPoint GetOriginOffset() |
michael@0 | 113 | { |
michael@0 | 114 | return mBufferRect.TopLeft() - mBufferRotation; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | bool PaintWillResample() { return mPaintWillResample; } |
michael@0 | 118 | |
michael@0 | 119 | nsIntRect mBufferRect; |
michael@0 | 120 | nsIntPoint mBufferRotation; |
michael@0 | 121 | bool mPaintWillResample; |
michael@0 | 122 | bool mInitialised; |
michael@0 | 123 | }; |
michael@0 | 124 | |
michael@0 | 125 | /** |
michael@0 | 126 | * Shared ContentHostBase implementation for content hosts that |
michael@0 | 127 | * use up to two TextureHosts. |
michael@0 | 128 | */ |
michael@0 | 129 | class ContentHostTexture : public ContentHostBase |
michael@0 | 130 | { |
michael@0 | 131 | public: |
michael@0 | 132 | ContentHostTexture(const TextureInfo& aTextureInfo) |
michael@0 | 133 | : ContentHostBase(aTextureInfo) |
michael@0 | 134 | , mLocked(false) |
michael@0 | 135 | { } |
michael@0 | 136 | |
michael@0 | 137 | virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; |
michael@0 | 138 | |
michael@0 | 139 | #ifdef MOZ_DUMP_PAINTING |
michael@0 | 140 | virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE; |
michael@0 | 141 | |
michael@0 | 142 | virtual void Dump(FILE* aFile=nullptr, |
michael@0 | 143 | const char* aPrefix="", |
michael@0 | 144 | bool aDumpHtml=false) MOZ_OVERRIDE; |
michael@0 | 145 | #endif |
michael@0 | 146 | |
michael@0 | 147 | virtual void PrintInfo(nsACString& aTo, const char* aPrefix) MOZ_OVERRIDE; |
michael@0 | 148 | |
michael@0 | 149 | virtual void UseTextureHost(TextureHost* aTexture) MOZ_OVERRIDE; |
michael@0 | 150 | virtual void UseComponentAlphaTextures(TextureHost* aTextureOnBlack, |
michael@0 | 151 | TextureHost* aTextureOnWhite) MOZ_OVERRIDE; |
michael@0 | 152 | |
michael@0 | 153 | virtual bool Lock() { |
michael@0 | 154 | MOZ_ASSERT(!mLocked); |
michael@0 | 155 | if (!mTextureHost) { |
michael@0 | 156 | return false; |
michael@0 | 157 | } |
michael@0 | 158 | if (!mTextureHost->Lock()) { |
michael@0 | 159 | return false; |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | if (mTextureHostOnWhite && !mTextureHostOnWhite->Lock()) { |
michael@0 | 163 | return false; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | mLocked = true; |
michael@0 | 167 | return true; |
michael@0 | 168 | } |
michael@0 | 169 | virtual void Unlock() { |
michael@0 | 170 | MOZ_ASSERT(mLocked); |
michael@0 | 171 | mTextureHost->Unlock(); |
michael@0 | 172 | if (mTextureHostOnWhite) { |
michael@0 | 173 | mTextureHostOnWhite->Unlock(); |
michael@0 | 174 | } |
michael@0 | 175 | mLocked = false; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | virtual NewTextureSource* GetTextureSource() { |
michael@0 | 179 | MOZ_ASSERT(mLocked); |
michael@0 | 180 | return mTextureHost->GetTextureSources(); |
michael@0 | 181 | } |
michael@0 | 182 | virtual NewTextureSource* GetTextureSourceOnWhite() { |
michael@0 | 183 | MOZ_ASSERT(mLocked); |
michael@0 | 184 | if (mTextureHostOnWhite) { |
michael@0 | 185 | return mTextureHostOnWhite->GetTextureSources(); |
michael@0 | 186 | } |
michael@0 | 187 | return nullptr; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | LayerRenderState GetRenderState(); |
michael@0 | 191 | |
michael@0 | 192 | protected: |
michael@0 | 193 | RefPtr<TextureHost> mTextureHost; |
michael@0 | 194 | RefPtr<TextureHost> mTextureHostOnWhite; |
michael@0 | 195 | bool mLocked; |
michael@0 | 196 | }; |
michael@0 | 197 | |
michael@0 | 198 | /** |
michael@0 | 199 | * Double buffering is implemented by swapping the front and back TextureHosts. |
michael@0 | 200 | * We assume that whenever we use double buffering, then we have |
michael@0 | 201 | * render-to-texture and thus no texture upload to do. |
michael@0 | 202 | */ |
michael@0 | 203 | class ContentHostDoubleBuffered : public ContentHostTexture |
michael@0 | 204 | { |
michael@0 | 205 | public: |
michael@0 | 206 | ContentHostDoubleBuffered(const TextureInfo& aTextureInfo) |
michael@0 | 207 | : ContentHostTexture(aTextureInfo) |
michael@0 | 208 | {} |
michael@0 | 209 | |
michael@0 | 210 | virtual ~ContentHostDoubleBuffered() {} |
michael@0 | 211 | |
michael@0 | 212 | virtual CompositableType GetType() { return COMPOSITABLE_CONTENT_DOUBLE; } |
michael@0 | 213 | |
michael@0 | 214 | virtual bool UpdateThebes(const ThebesBufferData& aData, |
michael@0 | 215 | const nsIntRegion& aUpdated, |
michael@0 | 216 | const nsIntRegion& aOldValidRegionBack, |
michael@0 | 217 | nsIntRegion* aUpdatedRegionBack); |
michael@0 | 218 | |
michael@0 | 219 | protected: |
michael@0 | 220 | nsIntRegion mValidRegionForNextBackBuffer; |
michael@0 | 221 | }; |
michael@0 | 222 | |
michael@0 | 223 | /** |
michael@0 | 224 | * Single buffered, therefore we must synchronously upload the image from the |
michael@0 | 225 | * TextureHost in the layers transaction (i.e., in UpdateThebes). |
michael@0 | 226 | */ |
michael@0 | 227 | class ContentHostSingleBuffered : public ContentHostTexture |
michael@0 | 228 | { |
michael@0 | 229 | public: |
michael@0 | 230 | ContentHostSingleBuffered(const TextureInfo& aTextureInfo) |
michael@0 | 231 | : ContentHostTexture(aTextureInfo) |
michael@0 | 232 | {} |
michael@0 | 233 | virtual ~ContentHostSingleBuffered() {} |
michael@0 | 234 | |
michael@0 | 235 | virtual CompositableType GetType() { return COMPOSITABLE_CONTENT_SINGLE; } |
michael@0 | 236 | |
michael@0 | 237 | virtual bool UpdateThebes(const ThebesBufferData& aData, |
michael@0 | 238 | const nsIntRegion& aUpdated, |
michael@0 | 239 | const nsIntRegion& aOldValidRegionBack, |
michael@0 | 240 | nsIntRegion* aUpdatedRegionBack); |
michael@0 | 241 | }; |
michael@0 | 242 | |
michael@0 | 243 | /** |
michael@0 | 244 | * Maintains a host-side only texture, and gets provided with |
michael@0 | 245 | * surfaces that only cover the changed pixels during an update. |
michael@0 | 246 | * |
michael@0 | 247 | * Takes ownership of the passed in update surfaces, and must |
michael@0 | 248 | * free them once texture upload is complete. |
michael@0 | 249 | * |
michael@0 | 250 | * Delays texture uploads until the next composite to |
michael@0 | 251 | * avoid blocking the main thread. |
michael@0 | 252 | */ |
michael@0 | 253 | class ContentHostIncremental : public ContentHostBase |
michael@0 | 254 | { |
michael@0 | 255 | public: |
michael@0 | 256 | ContentHostIncremental(const TextureInfo& aTextureInfo); |
michael@0 | 257 | ~ContentHostIncremental(); |
michael@0 | 258 | |
michael@0 | 259 | virtual CompositableType GetType() { return BUFFER_CONTENT_INC; } |
michael@0 | 260 | |
michael@0 | 261 | virtual LayerRenderState GetRenderState() MOZ_OVERRIDE { return LayerRenderState(); } |
michael@0 | 262 | |
michael@0 | 263 | virtual bool CreatedIncrementalTexture(ISurfaceAllocator* aAllocator, |
michael@0 | 264 | const TextureInfo& aTextureInfo, |
michael@0 | 265 | const nsIntRect& aBufferRect) MOZ_OVERRIDE; |
michael@0 | 266 | |
michael@0 | 267 | virtual void UpdateIncremental(TextureIdentifier aTextureId, |
michael@0 | 268 | SurfaceDescriptor& aSurface, |
michael@0 | 269 | const nsIntRegion& aUpdated, |
michael@0 | 270 | const nsIntRect& aBufferRect, |
michael@0 | 271 | const nsIntPoint& aBufferRotation) MOZ_OVERRIDE; |
michael@0 | 272 | |
michael@0 | 273 | virtual bool UpdateThebes(const ThebesBufferData& aData, |
michael@0 | 274 | const nsIntRegion& aUpdated, |
michael@0 | 275 | const nsIntRegion& aOldValidRegionBack, |
michael@0 | 276 | nsIntRegion* aUpdatedRegionBack) |
michael@0 | 277 | { |
michael@0 | 278 | NS_ERROR("Shouldn't call this"); |
michael@0 | 279 | return false; |
michael@0 | 280 | } |
michael@0 | 281 | |
michael@0 | 282 | virtual bool Lock() { |
michael@0 | 283 | MOZ_ASSERT(!mLocked); |
michael@0 | 284 | ProcessTextureUpdates(); |
michael@0 | 285 | mLocked = true; |
michael@0 | 286 | return true; |
michael@0 | 287 | } |
michael@0 | 288 | |
michael@0 | 289 | virtual void Unlock() { |
michael@0 | 290 | MOZ_ASSERT(mLocked); |
michael@0 | 291 | mLocked = false; |
michael@0 | 292 | } |
michael@0 | 293 | |
michael@0 | 294 | virtual NewTextureSource* GetTextureSource(); |
michael@0 | 295 | virtual NewTextureSource* GetTextureSourceOnWhite(); |
michael@0 | 296 | |
michael@0 | 297 | private: |
michael@0 | 298 | |
michael@0 | 299 | void FlushUpdateQueue(); |
michael@0 | 300 | void ProcessTextureUpdates(); |
michael@0 | 301 | |
michael@0 | 302 | class Request |
michael@0 | 303 | { |
michael@0 | 304 | public: |
michael@0 | 305 | Request() |
michael@0 | 306 | { |
michael@0 | 307 | MOZ_COUNT_CTOR(ContentHostIncremental::Request); |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | virtual ~Request() |
michael@0 | 311 | { |
michael@0 | 312 | MOZ_COUNT_DTOR(ContentHostIncremental::Request); |
michael@0 | 313 | } |
michael@0 | 314 | |
michael@0 | 315 | virtual void Execute(ContentHostIncremental *aHost) = 0; |
michael@0 | 316 | }; |
michael@0 | 317 | |
michael@0 | 318 | class TextureCreationRequest : public Request |
michael@0 | 319 | { |
michael@0 | 320 | public: |
michael@0 | 321 | TextureCreationRequest(const TextureInfo& aTextureInfo, |
michael@0 | 322 | const nsIntRect& aBufferRect) |
michael@0 | 323 | : mTextureInfo(aTextureInfo) |
michael@0 | 324 | , mBufferRect(aBufferRect) |
michael@0 | 325 | {} |
michael@0 | 326 | |
michael@0 | 327 | virtual void Execute(ContentHostIncremental *aHost); |
michael@0 | 328 | |
michael@0 | 329 | private: |
michael@0 | 330 | TextureInfo mTextureInfo; |
michael@0 | 331 | nsIntRect mBufferRect; |
michael@0 | 332 | }; |
michael@0 | 333 | |
michael@0 | 334 | class TextureUpdateRequest : public Request |
michael@0 | 335 | { |
michael@0 | 336 | public: |
michael@0 | 337 | TextureUpdateRequest(ISurfaceAllocator* aDeAllocator, |
michael@0 | 338 | TextureIdentifier aTextureId, |
michael@0 | 339 | SurfaceDescriptor& aDescriptor, |
michael@0 | 340 | const nsIntRegion& aUpdated, |
michael@0 | 341 | const nsIntRect& aBufferRect, |
michael@0 | 342 | const nsIntPoint& aBufferRotation) |
michael@0 | 343 | : mDeAllocator(aDeAllocator) |
michael@0 | 344 | , mTextureId(aTextureId) |
michael@0 | 345 | , mDescriptor(aDescriptor) |
michael@0 | 346 | , mUpdated(aUpdated) |
michael@0 | 347 | , mBufferRect(aBufferRect) |
michael@0 | 348 | , mBufferRotation(aBufferRotation) |
michael@0 | 349 | {} |
michael@0 | 350 | |
michael@0 | 351 | ~TextureUpdateRequest() |
michael@0 | 352 | { |
michael@0 | 353 | //TODO: Recycle these? |
michael@0 | 354 | mDeAllocator->DestroySharedSurface(&mDescriptor); |
michael@0 | 355 | } |
michael@0 | 356 | |
michael@0 | 357 | virtual void Execute(ContentHostIncremental *aHost); |
michael@0 | 358 | |
michael@0 | 359 | private: |
michael@0 | 360 | enum XSide { |
michael@0 | 361 | LEFT, RIGHT |
michael@0 | 362 | }; |
michael@0 | 363 | enum YSide { |
michael@0 | 364 | TOP, BOTTOM |
michael@0 | 365 | }; |
michael@0 | 366 | |
michael@0 | 367 | nsIntRect GetQuadrantRectangle(XSide aXSide, YSide aYSide) const; |
michael@0 | 368 | |
michael@0 | 369 | RefPtr<ISurfaceAllocator> mDeAllocator; |
michael@0 | 370 | TextureIdentifier mTextureId; |
michael@0 | 371 | SurfaceDescriptor mDescriptor; |
michael@0 | 372 | nsIntRegion mUpdated; |
michael@0 | 373 | nsIntRect mBufferRect; |
michael@0 | 374 | nsIntPoint mBufferRotation; |
michael@0 | 375 | }; |
michael@0 | 376 | |
michael@0 | 377 | nsTArray<nsAutoPtr<Request> > mUpdateList; |
michael@0 | 378 | |
michael@0 | 379 | // Specific to OGL to avoid exposing methods on TextureSource that only |
michael@0 | 380 | // have one implementation. |
michael@0 | 381 | RefPtr<TextureImageTextureSourceOGL> mSource; |
michael@0 | 382 | RefPtr<TextureImageTextureSourceOGL> mSourceOnWhite; |
michael@0 | 383 | |
michael@0 | 384 | RefPtr<ISurfaceAllocator> mDeAllocator; |
michael@0 | 385 | bool mLocked; |
michael@0 | 386 | }; |
michael@0 | 387 | |
michael@0 | 388 | } |
michael@0 | 389 | } |
michael@0 | 390 | |
michael@0 | 391 | #endif |