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 MOZILLA_GFX_TEXTUREHOST_H |
michael@0 | 7 | #define MOZILLA_GFX_TEXTUREHOST_H |
michael@0 | 8 | |
michael@0 | 9 | #include <stddef.h> // for size_t |
michael@0 | 10 | #include <stdint.h> // for uint64_t, uint32_t, uint8_t |
michael@0 | 11 | #include "gfxTypes.h" |
michael@0 | 12 | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
michael@0 | 13 | #include "mozilla/Attributes.h" // for MOZ_OVERRIDE |
michael@0 | 14 | #include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef, etc |
michael@0 | 15 | #include "mozilla/gfx/2D.h" // for DataSourceSurface |
michael@0 | 16 | #include "mozilla/gfx/Point.h" // for IntSize, IntPoint |
michael@0 | 17 | #include "mozilla/gfx/Types.h" // for SurfaceFormat, etc |
michael@0 | 18 | #include "mozilla/layers/CompositorTypes.h" // for TextureFlags, etc |
michael@0 | 19 | #include "mozilla/layers/LayersTypes.h" // for LayerRenderState, etc |
michael@0 | 20 | #include "mozilla/mozalloc.h" // for operator delete |
michael@0 | 21 | #include "nsCOMPtr.h" // for already_AddRefed |
michael@0 | 22 | #include "nsDebug.h" // for NS_RUNTIMEABORT |
michael@0 | 23 | #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc |
michael@0 | 24 | #include "nsRegion.h" // for nsIntRegion |
michael@0 | 25 | #include "nsTraceRefcnt.h" // for MOZ_COUNT_CTOR, etc |
michael@0 | 26 | #include "nscore.h" // for nsACString |
michael@0 | 27 | #include "mozilla/layers/AtomicRefCountedWithFinalize.h" |
michael@0 | 28 | |
michael@0 | 29 | class gfxReusableSurfaceWrapper; |
michael@0 | 30 | struct nsIntPoint; |
michael@0 | 31 | struct nsIntSize; |
michael@0 | 32 | struct nsIntRect; |
michael@0 | 33 | |
michael@0 | 34 | namespace mozilla { |
michael@0 | 35 | namespace ipc { |
michael@0 | 36 | class Shmem; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | namespace layers { |
michael@0 | 40 | |
michael@0 | 41 | class Compositor; |
michael@0 | 42 | class CompositableHost; |
michael@0 | 43 | class CompositableBackendSpecificData; |
michael@0 | 44 | class SurfaceDescriptor; |
michael@0 | 45 | class ISurfaceAllocator; |
michael@0 | 46 | class TextureHostOGL; |
michael@0 | 47 | class TextureSourceOGL; |
michael@0 | 48 | class TextureSourceD3D9; |
michael@0 | 49 | class TextureSourceD3D11; |
michael@0 | 50 | class TextureSourceBasic; |
michael@0 | 51 | class DataTextureSource; |
michael@0 | 52 | class PTextureParent; |
michael@0 | 53 | class TextureParent; |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * A view on a TextureHost where the texture is internally represented as tiles |
michael@0 | 57 | * (contrast with a tiled buffer, where each texture is a tile). For iteration by |
michael@0 | 58 | * the texture's buffer host. |
michael@0 | 59 | * This is only useful when the underlying surface is too big to fit in one |
michael@0 | 60 | * device texture, which forces us to split it in smaller parts. |
michael@0 | 61 | * Tiled Compositable is a different thing. |
michael@0 | 62 | */ |
michael@0 | 63 | class TileIterator |
michael@0 | 64 | { |
michael@0 | 65 | public: |
michael@0 | 66 | virtual void BeginTileIteration() = 0; |
michael@0 | 67 | virtual void EndTileIteration() {}; |
michael@0 | 68 | virtual nsIntRect GetTileRect() = 0; |
michael@0 | 69 | virtual size_t GetTileCount() = 0; |
michael@0 | 70 | virtual bool NextTile() = 0; |
michael@0 | 71 | }; |
michael@0 | 72 | |
michael@0 | 73 | /** |
michael@0 | 74 | * TextureSource is the interface for texture objects that can be composited |
michael@0 | 75 | * by a given compositor backend. Since the drawing APIs are different |
michael@0 | 76 | * between backends, the TextureSource interface is split into different |
michael@0 | 77 | * interfaces (TextureSourceOGL, etc.), and TextureSource mostly provide |
michael@0 | 78 | * access to these interfaces. |
michael@0 | 79 | * |
michael@0 | 80 | * This class is used on the compositor side. |
michael@0 | 81 | */ |
michael@0 | 82 | class TextureSource |
michael@0 | 83 | { |
michael@0 | 84 | protected: |
michael@0 | 85 | virtual ~TextureSource(); |
michael@0 | 86 | |
michael@0 | 87 | public: |
michael@0 | 88 | NS_INLINE_DECL_REFCOUNTING(TextureSource) |
michael@0 | 89 | |
michael@0 | 90 | TextureSource(); |
michael@0 | 91 | |
michael@0 | 92 | /** |
michael@0 | 93 | * Return the size of the texture in texels. |
michael@0 | 94 | * If this is a tile iterator, GetSize must return the size of the current tile. |
michael@0 | 95 | */ |
michael@0 | 96 | virtual gfx::IntSize GetSize() const = 0; |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * Return the pixel format of this texture |
michael@0 | 100 | */ |
michael@0 | 101 | virtual gfx::SurfaceFormat GetFormat() const { return gfx::SurfaceFormat::UNKNOWN; } |
michael@0 | 102 | |
michael@0 | 103 | /** |
michael@0 | 104 | * Cast to a TextureSource for for each backend.. |
michael@0 | 105 | */ |
michael@0 | 106 | virtual TextureSourceOGL* AsSourceOGL() { return nullptr; } |
michael@0 | 107 | virtual TextureSourceD3D9* AsSourceD3D9() { return nullptr; } |
michael@0 | 108 | virtual TextureSourceD3D11* AsSourceD3D11() { return nullptr; } |
michael@0 | 109 | virtual TextureSourceBasic* AsSourceBasic() { return nullptr; } |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * Cast to a DataTextureSurce. |
michael@0 | 113 | */ |
michael@0 | 114 | virtual DataTextureSource* AsDataTextureSource() { return nullptr; } |
michael@0 | 115 | |
michael@0 | 116 | /** |
michael@0 | 117 | * In some rare cases we currently need to consider a group of textures as one |
michael@0 | 118 | * TextureSource, that can be split in sub-TextureSources. |
michael@0 | 119 | */ |
michael@0 | 120 | virtual TextureSource* GetSubSource(int index) { return nullptr; } |
michael@0 | 121 | |
michael@0 | 122 | /** |
michael@0 | 123 | * Overload this if the TextureSource supports big textures that don't fit in |
michael@0 | 124 | * one device texture and must be tiled internally. |
michael@0 | 125 | */ |
michael@0 | 126 | virtual TileIterator* AsTileIterator() { return nullptr; } |
michael@0 | 127 | |
michael@0 | 128 | virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData); |
michael@0 | 129 | |
michael@0 | 130 | protected: |
michael@0 | 131 | RefPtr<CompositableBackendSpecificData> mCompositableBackendData; |
michael@0 | 132 | }; |
michael@0 | 133 | |
michael@0 | 134 | /** |
michael@0 | 135 | * XXX - merge this class with TextureSource when deprecated texture classes |
michael@0 | 136 | * are completely removed. |
michael@0 | 137 | */ |
michael@0 | 138 | class NewTextureSource : public TextureSource |
michael@0 | 139 | { |
michael@0 | 140 | public: |
michael@0 | 141 | NewTextureSource() |
michael@0 | 142 | { |
michael@0 | 143 | MOZ_COUNT_CTOR(NewTextureSource); |
michael@0 | 144 | } |
michael@0 | 145 | virtual ~NewTextureSource() |
michael@0 | 146 | { |
michael@0 | 147 | MOZ_COUNT_DTOR(NewTextureSource); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | /** |
michael@0 | 151 | * Should be overridden in order to deallocate the data that is associated |
michael@0 | 152 | * with the rendering backend, such as GL textures. |
michael@0 | 153 | */ |
michael@0 | 154 | virtual void DeallocateDeviceData() = 0; |
michael@0 | 155 | |
michael@0 | 156 | virtual void SetCompositor(Compositor* aCompositor) {} |
michael@0 | 157 | |
michael@0 | 158 | void SetNextSibling(NewTextureSource* aTexture) |
michael@0 | 159 | { |
michael@0 | 160 | mNextSibling = aTexture; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | NewTextureSource* GetNextSibling() const |
michael@0 | 164 | { |
michael@0 | 165 | return mNextSibling; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | // temporary adapter to use the same SubSource API as the old TextureSource |
michael@0 | 169 | virtual TextureSource* GetSubSource(int index) MOZ_OVERRIDE |
michael@0 | 170 | { |
michael@0 | 171 | switch (index) { |
michael@0 | 172 | case 0: return this; |
michael@0 | 173 | case 1: return GetNextSibling(); |
michael@0 | 174 | case 2: return GetNextSibling() ? GetNextSibling()->GetNextSibling() : nullptr; |
michael@0 | 175 | } |
michael@0 | 176 | return nullptr; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | protected: |
michael@0 | 180 | RefPtr<NewTextureSource> mNextSibling; |
michael@0 | 181 | }; |
michael@0 | 182 | |
michael@0 | 183 | /** |
michael@0 | 184 | * Interface for TextureSources that can be updated from a DataSourceSurface. |
michael@0 | 185 | * |
michael@0 | 186 | * All backend should implement at least one DataTextureSource. |
michael@0 | 187 | */ |
michael@0 | 188 | class DataTextureSource : public NewTextureSource |
michael@0 | 189 | { |
michael@0 | 190 | public: |
michael@0 | 191 | DataTextureSource() |
michael@0 | 192 | : mUpdateSerial(0) |
michael@0 | 193 | {} |
michael@0 | 194 | |
michael@0 | 195 | virtual DataTextureSource* AsDataTextureSource() MOZ_OVERRIDE { return this; } |
michael@0 | 196 | |
michael@0 | 197 | /** |
michael@0 | 198 | * Upload a (portion of) surface to the TextureSource. |
michael@0 | 199 | * |
michael@0 | 200 | * The DataTextureSource doesn't own aSurface, although it owns and manage |
michael@0 | 201 | * the device texture it uploads to internally. |
michael@0 | 202 | */ |
michael@0 | 203 | virtual bool Update(gfx::DataSourceSurface* aSurface, |
michael@0 | 204 | nsIntRegion* aDestRegion = nullptr, |
michael@0 | 205 | gfx::IntPoint* aSrcOffset = nullptr) = 0; |
michael@0 | 206 | |
michael@0 | 207 | /** |
michael@0 | 208 | * A facility to avoid reuploading when it is not necessary. |
michael@0 | 209 | * The caller of Update can use GetUpdateSerial to see if the number has changed |
michael@0 | 210 | * since last update, and call SetUpdateSerial after each successful update. |
michael@0 | 211 | * The caller is responsible for managing the update serial except when the |
michael@0 | 212 | * texture data is deallocated in which case the TextureSource should always |
michael@0 | 213 | * reset the update serial to zero. |
michael@0 | 214 | */ |
michael@0 | 215 | uint32_t GetUpdateSerial() const { return mUpdateSerial; } |
michael@0 | 216 | void SetUpdateSerial(uint32_t aValue) { mUpdateSerial = aValue; } |
michael@0 | 217 | |
michael@0 | 218 | // By default at least set the update serial to zero. |
michael@0 | 219 | // overloaded versions should do that too. |
michael@0 | 220 | virtual void DeallocateDeviceData() MOZ_OVERRIDE |
michael@0 | 221 | { |
michael@0 | 222 | SetUpdateSerial(0); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | #ifdef DEBUG |
michael@0 | 226 | /** |
michael@0 | 227 | * Provide read access to the data as a DataSourceSurface. |
michael@0 | 228 | * |
michael@0 | 229 | * This is expected to be very slow and should be used for mostly debugging. |
michael@0 | 230 | * XXX - implement everywhere and make it pure virtual. |
michael@0 | 231 | */ |
michael@0 | 232 | virtual TemporaryRef<gfx::DataSourceSurface> ReadBack() { return nullptr; }; |
michael@0 | 233 | #endif |
michael@0 | 234 | |
michael@0 | 235 | private: |
michael@0 | 236 | uint32_t mUpdateSerial; |
michael@0 | 237 | }; |
michael@0 | 238 | |
michael@0 | 239 | /** |
michael@0 | 240 | * TextureHost is a thin abstraction over texture data that need to be shared |
michael@0 | 241 | * between the content process and the compositor process. It is the |
michael@0 | 242 | * compositor-side half of a TextureClient/TextureHost pair. A corresponding |
michael@0 | 243 | * TextureClient lives on the content-side. |
michael@0 | 244 | * |
michael@0 | 245 | * TextureHost only knows how to deserialize or synchronize generic image data |
michael@0 | 246 | * (SurfaceDescriptor) and provide access to one or more TextureSource objects |
michael@0 | 247 | * (these provide the necessary APIs for compositor backends to composite the |
michael@0 | 248 | * image). |
michael@0 | 249 | * |
michael@0 | 250 | * A TextureHost implementation corresponds to one SurfaceDescriptor type, as |
michael@0 | 251 | * opposed to TextureSource that corresponds to device textures. |
michael@0 | 252 | * This means that for YCbCr planes, even though they are represented as |
michael@0 | 253 | * 3 textures internally (3 TextureSources), we use 1 TextureHost and not 3, |
michael@0 | 254 | * because the 3 planes are stored in the same buffer of shared memory, before |
michael@0 | 255 | * they are uploaded separately. |
michael@0 | 256 | * |
michael@0 | 257 | * There is always one and only one TextureHost per TextureClient, and the |
michael@0 | 258 | * TextureClient/Host pair only owns one buffer of image data through its |
michael@0 | 259 | * lifetime. This means that the lifetime of the underlying shared data |
michael@0 | 260 | * matches the lifetime of the TextureClient/Host pair. It also means |
michael@0 | 261 | * TextureClient/Host do not implement double buffering, which is the |
michael@0 | 262 | * reponsibility of the compositable (which would use two Texture pairs). |
michael@0 | 263 | * |
michael@0 | 264 | * The Lock/Unlock mecanism here mirrors Lock/Unlock in TextureClient. |
michael@0 | 265 | * |
michael@0 | 266 | */ |
michael@0 | 267 | class TextureHost |
michael@0 | 268 | : public AtomicRefCountedWithFinalize<TextureHost> |
michael@0 | 269 | { |
michael@0 | 270 | /** |
michael@0 | 271 | * Called once, just before the destructor. |
michael@0 | 272 | * |
michael@0 | 273 | * Here goes the shut-down code that uses virtual methods. |
michael@0 | 274 | * Must only be called by Release(). |
michael@0 | 275 | */ |
michael@0 | 276 | void Finalize(); |
michael@0 | 277 | |
michael@0 | 278 | friend class AtomicRefCountedWithFinalize<TextureHost>; |
michael@0 | 279 | public: |
michael@0 | 280 | TextureHost(TextureFlags aFlags); |
michael@0 | 281 | |
michael@0 | 282 | virtual ~TextureHost(); |
michael@0 | 283 | |
michael@0 | 284 | /** |
michael@0 | 285 | * Factory method. |
michael@0 | 286 | */ |
michael@0 | 287 | static TemporaryRef<TextureHost> Create(const SurfaceDescriptor& aDesc, |
michael@0 | 288 | ISurfaceAllocator* aDeallocator, |
michael@0 | 289 | TextureFlags aFlags); |
michael@0 | 290 | |
michael@0 | 291 | /** |
michael@0 | 292 | * Tell to TextureChild that TextureHost is recycled. |
michael@0 | 293 | * This function should be called from TextureHost's RecycleCallback. |
michael@0 | 294 | * If SetRecycleCallback is set to TextureHost. |
michael@0 | 295 | * TextureHost can be recycled by calling RecycleCallback |
michael@0 | 296 | * when reference count becomes one. |
michael@0 | 297 | * One reference count is always added by TextureChild. |
michael@0 | 298 | */ |
michael@0 | 299 | void CompositorRecycle(); |
michael@0 | 300 | |
michael@0 | 301 | /** |
michael@0 | 302 | * Lock the texture host for compositing. |
michael@0 | 303 | */ |
michael@0 | 304 | virtual bool Lock() { return true; } |
michael@0 | 305 | |
michael@0 | 306 | /** |
michael@0 | 307 | * Unlock the texture host after compositing. |
michael@0 | 308 | */ |
michael@0 | 309 | virtual void Unlock() {} |
michael@0 | 310 | |
michael@0 | 311 | /** |
michael@0 | 312 | * Note that the texture host format can be different from its corresponding |
michael@0 | 313 | * texture source's. For example a ShmemTextureHost can have the ycbcr |
michael@0 | 314 | * format and produce 3 "alpha" textures sources. |
michael@0 | 315 | */ |
michael@0 | 316 | virtual gfx::SurfaceFormat GetFormat() const = 0; |
michael@0 | 317 | |
michael@0 | 318 | /** |
michael@0 | 319 | * Return a list of TextureSources for use with a Compositor. |
michael@0 | 320 | * |
michael@0 | 321 | * This can trigger texture uploads, so do not call it inside transactions |
michael@0 | 322 | * so as to not upload textures while the main thread is blocked. |
michael@0 | 323 | * Must not be called while this TextureHost is not sucessfully Locked. |
michael@0 | 324 | */ |
michael@0 | 325 | virtual NewTextureSource* GetTextureSources() = 0; |
michael@0 | 326 | |
michael@0 | 327 | /** |
michael@0 | 328 | * Is called before compositing if the shared data has changed since last |
michael@0 | 329 | * composition. |
michael@0 | 330 | * This method should be overload in cases like when we need to do a texture |
michael@0 | 331 | * upload for example. |
michael@0 | 332 | * |
michael@0 | 333 | * @param aRegion The region that has been changed, if nil, it means that the |
michael@0 | 334 | * entire surface should be updated. |
michael@0 | 335 | */ |
michael@0 | 336 | virtual void Updated(const nsIntRegion* aRegion = nullptr) {} |
michael@0 | 337 | |
michael@0 | 338 | /** |
michael@0 | 339 | * Sets this TextureHost's compositor. |
michael@0 | 340 | * A TextureHost can change compositor on certain occasions, in particular if |
michael@0 | 341 | * it belongs to an async Compositable. |
michael@0 | 342 | * aCompositor can be null, in which case the TextureHost must cleanup all |
michael@0 | 343 | * of it's device textures. |
michael@0 | 344 | */ |
michael@0 | 345 | virtual void SetCompositor(Compositor* aCompositor) {} |
michael@0 | 346 | |
michael@0 | 347 | /** |
michael@0 | 348 | * Should be overridden in order to deallocate the data that is associated |
michael@0 | 349 | * with the rendering backend, such as GL textures. |
michael@0 | 350 | */ |
michael@0 | 351 | virtual void DeallocateDeviceData() {} |
michael@0 | 352 | |
michael@0 | 353 | /** |
michael@0 | 354 | * Should be overridden in order to deallocate the data that is shared with |
michael@0 | 355 | * the content side, such as shared memory. |
michael@0 | 356 | */ |
michael@0 | 357 | virtual void DeallocateSharedData() {} |
michael@0 | 358 | |
michael@0 | 359 | /** |
michael@0 | 360 | * Should be overridden in order to force the TextureHost to drop all references |
michael@0 | 361 | * to it's shared data. |
michael@0 | 362 | * |
michael@0 | 363 | * This is important to ensure the correctness of the deallocation protocol. |
michael@0 | 364 | */ |
michael@0 | 365 | virtual void ForgetSharedData() {} |
michael@0 | 366 | |
michael@0 | 367 | virtual gfx::IntSize GetSize() const = 0; |
michael@0 | 368 | |
michael@0 | 369 | /** |
michael@0 | 370 | * Debug facility. |
michael@0 | 371 | * XXX - cool kids use Moz2D. See bug 882113. |
michael@0 | 372 | */ |
michael@0 | 373 | virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() = 0; |
michael@0 | 374 | |
michael@0 | 375 | /** |
michael@0 | 376 | * XXX - Flags should only be set at creation time, this will be removed. |
michael@0 | 377 | */ |
michael@0 | 378 | void SetFlags(TextureFlags aFlags) { mFlags = aFlags; } |
michael@0 | 379 | |
michael@0 | 380 | /** |
michael@0 | 381 | * XXX - Flags should only be set at creation time, this will be removed. |
michael@0 | 382 | */ |
michael@0 | 383 | void AddFlag(TextureFlags aFlag) { mFlags |= aFlag; } |
michael@0 | 384 | |
michael@0 | 385 | TextureFlags GetFlags() { return mFlags; } |
michael@0 | 386 | |
michael@0 | 387 | /** |
michael@0 | 388 | * Allocate and deallocate a TextureParent actor. |
michael@0 | 389 | * |
michael@0 | 390 | * TextureParent< is an implementation detail of TextureHost that is not |
michael@0 | 391 | * exposed to the rest of the code base. CreateIPDLActor and DestroyIPDLActor |
michael@0 | 392 | * are for use with the managing IPDL protocols only (so that they can |
michael@0 | 393 | * implement AllocPTextureParent and DeallocPTextureParent). |
michael@0 | 394 | */ |
michael@0 | 395 | static PTextureParent* CreateIPDLActor(ISurfaceAllocator* aAllocator, |
michael@0 | 396 | const SurfaceDescriptor& aSharedData, |
michael@0 | 397 | TextureFlags aFlags); |
michael@0 | 398 | static bool DestroyIPDLActor(PTextureParent* actor); |
michael@0 | 399 | |
michael@0 | 400 | /** |
michael@0 | 401 | * Destroy the TextureChild/Parent pair. |
michael@0 | 402 | */ |
michael@0 | 403 | static bool SendDeleteIPDLActor(PTextureParent* actor); |
michael@0 | 404 | |
michael@0 | 405 | /** |
michael@0 | 406 | * Get the TextureHost corresponding to the actor passed in parameter. |
michael@0 | 407 | */ |
michael@0 | 408 | static TextureHost* AsTextureHost(PTextureParent* actor); |
michael@0 | 409 | |
michael@0 | 410 | /** |
michael@0 | 411 | * Return a pointer to the IPDLActor. |
michael@0 | 412 | * |
michael@0 | 413 | * This is to be used with IPDL messages only. Do not store the returned |
michael@0 | 414 | * pointer. |
michael@0 | 415 | */ |
michael@0 | 416 | PTextureParent* GetIPDLActor(); |
michael@0 | 417 | |
michael@0 | 418 | /** |
michael@0 | 419 | * Specific to B2G's Composer2D |
michael@0 | 420 | * XXX - more doc here |
michael@0 | 421 | */ |
michael@0 | 422 | virtual LayerRenderState GetRenderState() |
michael@0 | 423 | { |
michael@0 | 424 | // By default we return an empty render state, this should be overridden |
michael@0 | 425 | // by the TextureHost implementations that are used on B2G with Composer2D |
michael@0 | 426 | return LayerRenderState(); |
michael@0 | 427 | } |
michael@0 | 428 | |
michael@0 | 429 | virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData); |
michael@0 | 430 | |
michael@0 | 431 | // If a texture host holds a reference to shmem, it should override this method |
michael@0 | 432 | // to forget about the shmem _without_ releasing it. |
michael@0 | 433 | virtual void OnShutdown() {} |
michael@0 | 434 | |
michael@0 | 435 | // Forget buffer actor. Used only for hacky fix for bug 966446. |
michael@0 | 436 | virtual void ForgetBufferActor() {} |
michael@0 | 437 | |
michael@0 | 438 | virtual const char *Name() { return "TextureHost"; } |
michael@0 | 439 | virtual void PrintInfo(nsACString& aTo, const char* aPrefix); |
michael@0 | 440 | |
michael@0 | 441 | /** |
michael@0 | 442 | * Indicates whether the TextureHost implementation is backed by an |
michael@0 | 443 | * in-memory buffer. The consequence of this is that locking the |
michael@0 | 444 | * TextureHost does not contend with locking the texture on the client side. |
michael@0 | 445 | */ |
michael@0 | 446 | virtual bool HasInternalBuffer() const { return false; } |
michael@0 | 447 | |
michael@0 | 448 | /** |
michael@0 | 449 | * Cast to a TextureHost for each backend. |
michael@0 | 450 | */ |
michael@0 | 451 | virtual TextureHostOGL* AsHostOGL() { return nullptr; } |
michael@0 | 452 | |
michael@0 | 453 | protected: |
michael@0 | 454 | PTextureParent* mActor; |
michael@0 | 455 | TextureFlags mFlags; |
michael@0 | 456 | RefPtr<CompositableBackendSpecificData> mCompositableBackendData; |
michael@0 | 457 | |
michael@0 | 458 | friend class TextureParent; |
michael@0 | 459 | }; |
michael@0 | 460 | |
michael@0 | 461 | /** |
michael@0 | 462 | * TextureHost that wraps a random access buffer such as a Shmem or some raw |
michael@0 | 463 | * memory. |
michael@0 | 464 | * |
michael@0 | 465 | * This TextureHost is backend-independent and the backend-specific bits are |
michael@0 | 466 | * in the TextureSource. |
michael@0 | 467 | * This class must be inherited to implement GetBuffer and DeallocSharedData |
michael@0 | 468 | * (see ShmemTextureHost and MemoryTextureHost) |
michael@0 | 469 | * |
michael@0 | 470 | * Uploads happen when Lock is called. |
michael@0 | 471 | * |
michael@0 | 472 | * BufferTextureHost supports YCbCr and flavours of RGBA images (RGBX, A, etc.). |
michael@0 | 473 | */ |
michael@0 | 474 | class BufferTextureHost : public TextureHost |
michael@0 | 475 | { |
michael@0 | 476 | public: |
michael@0 | 477 | BufferTextureHost(gfx::SurfaceFormat aFormat, |
michael@0 | 478 | TextureFlags aFlags); |
michael@0 | 479 | |
michael@0 | 480 | ~BufferTextureHost(); |
michael@0 | 481 | |
michael@0 | 482 | virtual uint8_t* GetBuffer() = 0; |
michael@0 | 483 | |
michael@0 | 484 | virtual size_t GetBufferSize() = 0; |
michael@0 | 485 | |
michael@0 | 486 | virtual void Updated(const nsIntRegion* aRegion = nullptr) MOZ_OVERRIDE; |
michael@0 | 487 | |
michael@0 | 488 | virtual bool Lock() MOZ_OVERRIDE; |
michael@0 | 489 | |
michael@0 | 490 | virtual void Unlock() MOZ_OVERRIDE; |
michael@0 | 491 | |
michael@0 | 492 | virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE; |
michael@0 | 493 | |
michael@0 | 494 | virtual void DeallocateDeviceData() MOZ_OVERRIDE; |
michael@0 | 495 | |
michael@0 | 496 | virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; |
michael@0 | 497 | |
michael@0 | 498 | /** |
michael@0 | 499 | * Return the format that is exposed to the compositor when calling |
michael@0 | 500 | * GetTextureSources. |
michael@0 | 501 | * |
michael@0 | 502 | * If the shared format is YCbCr and the compositor does not support it, |
michael@0 | 503 | * GetFormat will be RGB32 (even though mFormat is SurfaceFormat::YUV). |
michael@0 | 504 | */ |
michael@0 | 505 | virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE; |
michael@0 | 506 | |
michael@0 | 507 | virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } |
michael@0 | 508 | |
michael@0 | 509 | virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE; |
michael@0 | 510 | |
michael@0 | 511 | virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return true; } |
michael@0 | 512 | |
michael@0 | 513 | protected: |
michael@0 | 514 | bool Upload(nsIntRegion *aRegion = nullptr); |
michael@0 | 515 | bool MaybeUpload(nsIntRegion *aRegion = nullptr); |
michael@0 | 516 | |
michael@0 | 517 | Compositor* mCompositor; |
michael@0 | 518 | RefPtr<DataTextureSource> mFirstSource; |
michael@0 | 519 | nsIntRegion mMaybeUpdatedRegion; |
michael@0 | 520 | gfx::IntSize mSize; |
michael@0 | 521 | // format of the data that is shared with the content process. |
michael@0 | 522 | gfx::SurfaceFormat mFormat; |
michael@0 | 523 | uint32_t mUpdateSerial; |
michael@0 | 524 | bool mLocked; |
michael@0 | 525 | bool mPartialUpdate; |
michael@0 | 526 | }; |
michael@0 | 527 | |
michael@0 | 528 | /** |
michael@0 | 529 | * TextureHost that wraps shared memory. |
michael@0 | 530 | * the corresponding texture on the client side is ShmemTextureClient. |
michael@0 | 531 | * This TextureHost is backend-independent. |
michael@0 | 532 | */ |
michael@0 | 533 | class ShmemTextureHost : public BufferTextureHost |
michael@0 | 534 | { |
michael@0 | 535 | public: |
michael@0 | 536 | ShmemTextureHost(const mozilla::ipc::Shmem& aShmem, |
michael@0 | 537 | gfx::SurfaceFormat aFormat, |
michael@0 | 538 | ISurfaceAllocator* aDeallocator, |
michael@0 | 539 | TextureFlags aFlags); |
michael@0 | 540 | |
michael@0 | 541 | ~ShmemTextureHost(); |
michael@0 | 542 | |
michael@0 | 543 | virtual void DeallocateSharedData() MOZ_OVERRIDE; |
michael@0 | 544 | |
michael@0 | 545 | virtual void ForgetSharedData() MOZ_OVERRIDE; |
michael@0 | 546 | |
michael@0 | 547 | virtual uint8_t* GetBuffer() MOZ_OVERRIDE; |
michael@0 | 548 | |
michael@0 | 549 | virtual size_t GetBufferSize() MOZ_OVERRIDE; |
michael@0 | 550 | |
michael@0 | 551 | virtual const char *Name() MOZ_OVERRIDE { return "ShmemTextureHost"; } |
michael@0 | 552 | |
michael@0 | 553 | virtual void OnShutdown() MOZ_OVERRIDE; |
michael@0 | 554 | |
michael@0 | 555 | protected: |
michael@0 | 556 | mozilla::ipc::Shmem* mShmem; |
michael@0 | 557 | RefPtr<ISurfaceAllocator> mDeallocator; |
michael@0 | 558 | }; |
michael@0 | 559 | |
michael@0 | 560 | /** |
michael@0 | 561 | * TextureHost that wraps raw memory. |
michael@0 | 562 | * The corresponding texture on the client side is MemoryTextureClient. |
michael@0 | 563 | * Can obviously not be used in a cross process setup. |
michael@0 | 564 | * This TextureHost is backend-independent. |
michael@0 | 565 | */ |
michael@0 | 566 | class MemoryTextureHost : public BufferTextureHost |
michael@0 | 567 | { |
michael@0 | 568 | public: |
michael@0 | 569 | MemoryTextureHost(uint8_t* aBuffer, |
michael@0 | 570 | gfx::SurfaceFormat aFormat, |
michael@0 | 571 | TextureFlags aFlags); |
michael@0 | 572 | |
michael@0 | 573 | ~MemoryTextureHost(); |
michael@0 | 574 | |
michael@0 | 575 | virtual void DeallocateSharedData() MOZ_OVERRIDE; |
michael@0 | 576 | |
michael@0 | 577 | virtual void ForgetSharedData() MOZ_OVERRIDE; |
michael@0 | 578 | |
michael@0 | 579 | virtual uint8_t* GetBuffer() MOZ_OVERRIDE; |
michael@0 | 580 | |
michael@0 | 581 | virtual size_t GetBufferSize() MOZ_OVERRIDE; |
michael@0 | 582 | |
michael@0 | 583 | virtual const char *Name() MOZ_OVERRIDE { return "MemoryTextureHost"; } |
michael@0 | 584 | |
michael@0 | 585 | protected: |
michael@0 | 586 | uint8_t* mBuffer; |
michael@0 | 587 | }; |
michael@0 | 588 | |
michael@0 | 589 | class MOZ_STACK_CLASS AutoLockTextureHost |
michael@0 | 590 | { |
michael@0 | 591 | public: |
michael@0 | 592 | AutoLockTextureHost(TextureHost* aTexture) |
michael@0 | 593 | : mTexture(aTexture) |
michael@0 | 594 | { |
michael@0 | 595 | mLocked = mTexture ? mTexture->Lock() : false; |
michael@0 | 596 | } |
michael@0 | 597 | |
michael@0 | 598 | ~AutoLockTextureHost() |
michael@0 | 599 | { |
michael@0 | 600 | if (mTexture && mLocked) { |
michael@0 | 601 | mTexture->Unlock(); |
michael@0 | 602 | } |
michael@0 | 603 | } |
michael@0 | 604 | |
michael@0 | 605 | bool Failed() { return mTexture && !mLocked; } |
michael@0 | 606 | |
michael@0 | 607 | private: |
michael@0 | 608 | RefPtr<TextureHost> mTexture; |
michael@0 | 609 | bool mLocked; |
michael@0 | 610 | }; |
michael@0 | 611 | |
michael@0 | 612 | /** |
michael@0 | 613 | * This can be used as an offscreen rendering target by the compositor, and |
michael@0 | 614 | * subsequently can be used as a source by the compositor. |
michael@0 | 615 | */ |
michael@0 | 616 | class CompositingRenderTarget : public TextureSource |
michael@0 | 617 | { |
michael@0 | 618 | public: |
michael@0 | 619 | CompositingRenderTarget(const gfx::IntPoint& aOrigin) |
michael@0 | 620 | : mOrigin(aOrigin) |
michael@0 | 621 | {} |
michael@0 | 622 | virtual ~CompositingRenderTarget() {} |
michael@0 | 623 | |
michael@0 | 624 | #ifdef MOZ_DUMP_PAINTING |
michael@0 | 625 | virtual TemporaryRef<gfx::DataSourceSurface> Dump(Compositor* aCompositor) { return nullptr; } |
michael@0 | 626 | #endif |
michael@0 | 627 | |
michael@0 | 628 | const gfx::IntPoint& GetOrigin() { return mOrigin; } |
michael@0 | 629 | |
michael@0 | 630 | private: |
michael@0 | 631 | gfx::IntPoint mOrigin; |
michael@0 | 632 | }; |
michael@0 | 633 | |
michael@0 | 634 | /** |
michael@0 | 635 | * Creates a TextureHost that can be used with any of the existing backends |
michael@0 | 636 | * Not all SurfaceDescriptor types are supported |
michael@0 | 637 | */ |
michael@0 | 638 | TemporaryRef<TextureHost> |
michael@0 | 639 | CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc, |
michael@0 | 640 | ISurfaceAllocator* aDeallocator, |
michael@0 | 641 | TextureFlags aFlags); |
michael@0 | 642 | |
michael@0 | 643 | } |
michael@0 | 644 | } |
michael@0 | 645 | |
michael@0 | 646 | #endif |