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_TEXTURECLIENT_H |
michael@0 | 7 | #define MOZILLA_GFX_TEXTURECLIENT_H |
michael@0 | 8 | |
michael@0 | 9 | #include <stddef.h> // for size_t |
michael@0 | 10 | #include <stdint.h> // for uint32_t, uint8_t, uint64_t |
michael@0 | 11 | #include "GLContextTypes.h" // for GLContext (ptr only), etc |
michael@0 | 12 | #include "GLTextureImage.h" // for TextureImage |
michael@0 | 13 | #include "ImageTypes.h" // for StereoMode |
michael@0 | 14 | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
michael@0 | 15 | #include "mozilla/Attributes.h" // for MOZ_OVERRIDE |
michael@0 | 16 | #include "mozilla/RefPtr.h" // for RefPtr, RefCounted |
michael@0 | 17 | #include "mozilla/gfx/2D.h" // for DrawTarget |
michael@0 | 18 | #include "mozilla/gfx/Point.h" // for IntSize |
michael@0 | 19 | #include "mozilla/gfx/Types.h" // for SurfaceFormat |
michael@0 | 20 | #include "mozilla/layers/FenceUtils.h" // for FenceHandle |
michael@0 | 21 | #include "mozilla/ipc/Shmem.h" // for Shmem |
michael@0 | 22 | #include "mozilla/layers/AtomicRefCountedWithFinalize.h" |
michael@0 | 23 | #include "mozilla/layers/CompositorTypes.h" // for TextureFlags, etc |
michael@0 | 24 | #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor |
michael@0 | 25 | #include "mozilla/layers/PTextureChild.h" // for PTextureChild |
michael@0 | 26 | #include "mozilla/mozalloc.h" // for operator delete |
michael@0 | 27 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 28 | #include "nsCOMPtr.h" // for already_AddRefed |
michael@0 | 29 | #include "nsISupportsImpl.h" // for TextureImage::AddRef, etc |
michael@0 | 30 | |
michael@0 | 31 | class gfxReusableSurfaceWrapper; |
michael@0 | 32 | class gfxImageSurface; |
michael@0 | 33 | |
michael@0 | 34 | namespace mozilla { |
michael@0 | 35 | namespace layers { |
michael@0 | 36 | |
michael@0 | 37 | class ContentClient; |
michael@0 | 38 | class CompositableForwarder; |
michael@0 | 39 | class ISurfaceAllocator; |
michael@0 | 40 | class CompositableClient; |
michael@0 | 41 | class PlanarYCbCrImage; |
michael@0 | 42 | class PlanarYCbCrData; |
michael@0 | 43 | class Image; |
michael@0 | 44 | class PTextureChild; |
michael@0 | 45 | class TextureChild; |
michael@0 | 46 | class BufferTextureClient; |
michael@0 | 47 | class TextureClient; |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * TextureClient is the abstraction that allows us to share data between the |
michael@0 | 51 | * content and the compositor side. |
michael@0 | 52 | */ |
michael@0 | 53 | |
michael@0 | 54 | enum TextureAllocationFlags { |
michael@0 | 55 | ALLOC_DEFAULT = 0, |
michael@0 | 56 | ALLOC_CLEAR_BUFFER = 1 |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Interface for TextureClients that can be updated using YCbCr data. |
michael@0 | 61 | */ |
michael@0 | 62 | class TextureClientYCbCr |
michael@0 | 63 | { |
michael@0 | 64 | public: |
michael@0 | 65 | /** |
michael@0 | 66 | * Copy aData into this texture client. |
michael@0 | 67 | * |
michael@0 | 68 | * This must never be called on a TextureClient that is not sucessfully locked. |
michael@0 | 69 | */ |
michael@0 | 70 | virtual bool UpdateYCbCr(const PlanarYCbCrData& aData) = 0; |
michael@0 | 71 | |
michael@0 | 72 | /** |
michael@0 | 73 | * Allocates for a given surface size, taking into account the pixel format |
michael@0 | 74 | * which is part of the state of the TextureClient. |
michael@0 | 75 | * |
michael@0 | 76 | * Does not clear the surface, since we consider that the surface |
michael@0 | 77 | * be painted entirely with opaque content. |
michael@0 | 78 | */ |
michael@0 | 79 | virtual bool AllocateForYCbCr(gfx::IntSize aYSize, |
michael@0 | 80 | gfx::IntSize aCbCrSize, |
michael@0 | 81 | StereoMode aStereoMode) = 0; |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * Holds the shared data of a TextureClient, to be destroyed later. |
michael@0 | 86 | * |
michael@0 | 87 | * TextureClient's destructor initiates the destruction sequence of the |
michael@0 | 88 | * texture client/host pair. If the shared data is to be deallocated on the |
michael@0 | 89 | * host side, there is nothing to do. |
michael@0 | 90 | * On the other hand, if the client data must be deallocated on the client |
michael@0 | 91 | * side, the CompositableClient will ask the TextureClient to drop its shared |
michael@0 | 92 | * data in the form of a TextureClientData object. This data will be kept alive |
michael@0 | 93 | * until the host side confirms that it is not using the data anymore and that |
michael@0 | 94 | * it is completely safe to deallocate the shared data. |
michael@0 | 95 | * |
michael@0 | 96 | * See: |
michael@0 | 97 | * - The PTexture IPDL protocol |
michael@0 | 98 | * - CompositableChild in TextureClient.cpp |
michael@0 | 99 | */ |
michael@0 | 100 | class TextureClientData { |
michael@0 | 101 | public: |
michael@0 | 102 | virtual void DeallocateSharedData(ISurfaceAllocator* allocator) = 0; |
michael@0 | 103 | virtual ~TextureClientData() {} |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | /** |
michael@0 | 107 | * TextureClient is a thin abstraction over texture data that need to be shared |
michael@0 | 108 | * between the content process and the compositor process. It is the |
michael@0 | 109 | * content-side half of a TextureClient/TextureHost pair. A corresponding |
michael@0 | 110 | * TextureHost lives on the compositor-side. |
michael@0 | 111 | * |
michael@0 | 112 | * TextureClient's primary purpose is to present texture data in a way that is |
michael@0 | 113 | * understood by the IPC system. There are two ways to use it: |
michael@0 | 114 | * - Use it to serialize image data that is not IPC-friendly (most likely |
michael@0 | 115 | * involving a copy into shared memory) |
michael@0 | 116 | * - preallocate it and paint directly into it, which avoids copy but requires |
michael@0 | 117 | * the painting code to be aware of TextureClient (or at least the underlying |
michael@0 | 118 | * shared memory). |
michael@0 | 119 | * |
michael@0 | 120 | * There is always one and only one TextureClient per TextureHost, and the |
michael@0 | 121 | * TextureClient/Host pair only owns one buffer of image data through its |
michael@0 | 122 | * lifetime. This means that the lifetime of the underlying shared data |
michael@0 | 123 | * matches the lifetime of the TextureClient/Host pair. It also means |
michael@0 | 124 | * TextureClient/Host do not implement double buffering, which is the |
michael@0 | 125 | * responsibility of the compositable (which would use two Texture pairs). |
michael@0 | 126 | * In order to send several different buffers to the compositor side, use |
michael@0 | 127 | * several TextureClients. |
michael@0 | 128 | */ |
michael@0 | 129 | class TextureClient |
michael@0 | 130 | : public AtomicRefCountedWithFinalize<TextureClient> |
michael@0 | 131 | { |
michael@0 | 132 | public: |
michael@0 | 133 | TextureClient(TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); |
michael@0 | 134 | virtual ~TextureClient(); |
michael@0 | 135 | |
michael@0 | 136 | static TemporaryRef<BufferTextureClient> |
michael@0 | 137 | CreateBufferTextureClient(ISurfaceAllocator* aAllocator, |
michael@0 | 138 | gfx::SurfaceFormat aFormat, |
michael@0 | 139 | TextureFlags aTextureFlags, |
michael@0 | 140 | gfx::BackendType aMoz2dBackend); |
michael@0 | 141 | |
michael@0 | 142 | static TemporaryRef<TextureClient> |
michael@0 | 143 | CreateTextureClientForDrawing(ISurfaceAllocator* aAllocator, |
michael@0 | 144 | gfx::SurfaceFormat aFormat, |
michael@0 | 145 | TextureFlags aTextureFlags, |
michael@0 | 146 | gfx::BackendType aMoz2dBackend, |
michael@0 | 147 | const gfx::IntSize& aSizeHint); |
michael@0 | 148 | |
michael@0 | 149 | virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; } |
michael@0 | 150 | |
michael@0 | 151 | /** |
michael@0 | 152 | * Locks the shared data, allowing the caller to get access to it. |
michael@0 | 153 | * |
michael@0 | 154 | * Please always lock/unlock when accessing the shared data. |
michael@0 | 155 | * If Lock() returns false, you should not attempt to access the shared data. |
michael@0 | 156 | */ |
michael@0 | 157 | virtual bool Lock(OpenMode aMode) { return IsValid(); } |
michael@0 | 158 | |
michael@0 | 159 | virtual void Unlock() {} |
michael@0 | 160 | |
michael@0 | 161 | virtual bool IsLocked() const = 0; |
michael@0 | 162 | |
michael@0 | 163 | virtual bool CanExposeDrawTarget() const { return false; } |
michael@0 | 164 | |
michael@0 | 165 | /** |
michael@0 | 166 | * Returns a DrawTarget to draw into the TextureClient. |
michael@0 | 167 | * |
michael@0 | 168 | * This must never be called on a TextureClient that is not sucessfully locked. |
michael@0 | 169 | * When called several times within one Lock/Unlock pair, this method should |
michael@0 | 170 | * return the same DrawTarget. |
michael@0 | 171 | * The DrawTarget is automatically flushed by the TextureClient when the latter |
michael@0 | 172 | * is unlocked, and the DrawTarget that will be returned within the next |
michael@0 | 173 | * lock/unlock pair may or may not be the same object. |
michael@0 | 174 | * Do not keep references to the DrawTarget outside of the lock/unlock pair. |
michael@0 | 175 | * |
michael@0 | 176 | * This is typically used as follows: |
michael@0 | 177 | * |
michael@0 | 178 | * if (!texture->Lock(OPEN_READ_WRITE)) { |
michael@0 | 179 | * return false; |
michael@0 | 180 | * } |
michael@0 | 181 | * { |
michael@0 | 182 | * // Restrict this code's scope to ensure all references to dt are gone |
michael@0 | 183 | * // when Unlock is called. |
michael@0 | 184 | * RefPtr<DrawTarget> dt = texture->GetAsDrawTarget(); |
michael@0 | 185 | * // use the draw target ... |
michael@0 | 186 | * } |
michael@0 | 187 | * texture->Unlock(); |
michael@0 | 188 | * |
michael@0 | 189 | */ |
michael@0 | 190 | virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() { return nullptr; } |
michael@0 | 191 | |
michael@0 | 192 | // TextureClients that can expose a DrawTarget should override this method. |
michael@0 | 193 | virtual gfx::SurfaceFormat GetFormat() const |
michael@0 | 194 | { |
michael@0 | 195 | return gfx::SurfaceFormat::UNKNOWN; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | /** |
michael@0 | 199 | * Allocates for a given surface size, taking into account the pixel format |
michael@0 | 200 | * which is part of the state of the TextureClient. |
michael@0 | 201 | * |
michael@0 | 202 | * Does not clear the surface by default, clearing the surface can be done |
michael@0 | 203 | * by passing the CLEAR_BUFFER flag. |
michael@0 | 204 | * |
michael@0 | 205 | * TextureClients that can expose a DrawTarget should override this method. |
michael@0 | 206 | */ |
michael@0 | 207 | virtual bool AllocateForSurface(gfx::IntSize aSize, |
michael@0 | 208 | TextureAllocationFlags flags = ALLOC_DEFAULT) |
michael@0 | 209 | { |
michael@0 | 210 | return false; |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | /** |
michael@0 | 214 | * Copies a rectangle from this texture client to a position in aTarget. |
michael@0 | 215 | * It is assumed that the necessary locks are in place; so this should at |
michael@0 | 216 | * least have a read lock and aTarget should at least have a write lock. |
michael@0 | 217 | */ |
michael@0 | 218 | virtual bool CopyToTextureClient(TextureClient* aTarget, |
michael@0 | 219 | const gfx::IntRect* aRect, |
michael@0 | 220 | const gfx::IntPoint* aPoint); |
michael@0 | 221 | |
michael@0 | 222 | /** |
michael@0 | 223 | * Returns true if this texture has a lock/unlock mechanism. |
michael@0 | 224 | * Textures that do not implement locking should be immutable or should |
michael@0 | 225 | * use immediate uploads (see TextureFlags in CompositorTypes.h) |
michael@0 | 226 | */ |
michael@0 | 227 | virtual bool ImplementsLocking() const { return false; } |
michael@0 | 228 | |
michael@0 | 229 | /** |
michael@0 | 230 | * Indicates whether the TextureClient implementation is backed by an |
michael@0 | 231 | * in-memory buffer. The consequence of this is that locking the |
michael@0 | 232 | * TextureClient does not contend with locking the texture on the host side. |
michael@0 | 233 | */ |
michael@0 | 234 | virtual bool HasInternalBuffer() const = 0; |
michael@0 | 235 | |
michael@0 | 236 | /** |
michael@0 | 237 | * Allocate and deallocate a TextureChild actor. |
michael@0 | 238 | * |
michael@0 | 239 | * TextureChild is an implementation detail of TextureClient that is not |
michael@0 | 240 | * exposed to the rest of the code base. CreateIPDLActor and DestroyIPDLActor |
michael@0 | 241 | * are for use with the managing IPDL protocols only (so that they can |
michael@0 | 242 | * implement AllocPextureChild and DeallocPTextureChild). |
michael@0 | 243 | */ |
michael@0 | 244 | static PTextureChild* CreateIPDLActor(); |
michael@0 | 245 | static bool DestroyIPDLActor(PTextureChild* actor); |
michael@0 | 246 | |
michael@0 | 247 | /** |
michael@0 | 248 | * Get the TextureClient corresponding to the actor passed in parameter. |
michael@0 | 249 | */ |
michael@0 | 250 | static TextureClient* AsTextureClient(PTextureChild* actor); |
michael@0 | 251 | |
michael@0 | 252 | virtual bool IsAllocated() const = 0; |
michael@0 | 253 | |
michael@0 | 254 | virtual gfx::IntSize GetSize() const = 0; |
michael@0 | 255 | |
michael@0 | 256 | /** |
michael@0 | 257 | * TextureFlags contain important information about various aspects |
michael@0 | 258 | * of the texture, like how its liferime is managed, and how it |
michael@0 | 259 | * should be displayed. |
michael@0 | 260 | * See TextureFlags in CompositorTypes.h. |
michael@0 | 261 | */ |
michael@0 | 262 | TextureFlags GetFlags() const { return mFlags; } |
michael@0 | 263 | |
michael@0 | 264 | /** |
michael@0 | 265 | * valid only for TEXTURE_RECYCLE TextureClient. |
michael@0 | 266 | * When called this texture client will grab a strong reference and release |
michael@0 | 267 | * it once the compositor notifies that it is done with the texture. |
michael@0 | 268 | * NOTE: In this stage the texture client can no longer be used by the |
michael@0 | 269 | * client in a transaction. |
michael@0 | 270 | */ |
michael@0 | 271 | void WaitForCompositorRecycle(); |
michael@0 | 272 | |
michael@0 | 273 | /** |
michael@0 | 274 | * After being shared with the compositor side, an immutable texture is never |
michael@0 | 275 | * modified, it can only be read. It is safe to not Lock/Unlock immutable |
michael@0 | 276 | * textures. |
michael@0 | 277 | */ |
michael@0 | 278 | bool IsImmutable() const { return mFlags & TEXTURE_IMMUTABLE; } |
michael@0 | 279 | |
michael@0 | 280 | void MarkImmutable() { AddFlags(TEXTURE_IMMUTABLE); } |
michael@0 | 281 | |
michael@0 | 282 | bool IsSharedWithCompositor() const { return mShared; } |
michael@0 | 283 | |
michael@0 | 284 | bool ShouldDeallocateInDestructor() const; |
michael@0 | 285 | |
michael@0 | 286 | /** |
michael@0 | 287 | * If this method returns false users of TextureClient are not allowed |
michael@0 | 288 | * to access the shared data. |
michael@0 | 289 | */ |
michael@0 | 290 | bool IsValid() const { return mValid; } |
michael@0 | 291 | |
michael@0 | 292 | /** |
michael@0 | 293 | * Create and init the TextureChild/Parent IPDL actor pair. |
michael@0 | 294 | * |
michael@0 | 295 | * Should be called only once per TextureClient. |
michael@0 | 296 | */ |
michael@0 | 297 | bool InitIPDLActor(CompositableForwarder* aForwarder); |
michael@0 | 298 | |
michael@0 | 299 | /** |
michael@0 | 300 | * Return a pointer to the IPDLActor. |
michael@0 | 301 | * |
michael@0 | 302 | * This is to be used with IPDL messages only. Do not store the returned |
michael@0 | 303 | * pointer. |
michael@0 | 304 | */ |
michael@0 | 305 | PTextureChild* GetIPDLActor(); |
michael@0 | 306 | |
michael@0 | 307 | /** |
michael@0 | 308 | * Triggers the destruction of the shared data and the corresponding TextureHost. |
michael@0 | 309 | * |
michael@0 | 310 | * If the texture flags contain TEXTURE_DEALLOCATE_CLIENT, the destruction |
michael@0 | 311 | * will be synchronously coordinated with the compositor side, otherwise it |
michael@0 | 312 | * will be done asynchronously. |
michael@0 | 313 | */ |
michael@0 | 314 | void ForceRemove(); |
michael@0 | 315 | |
michael@0 | 316 | virtual void SetReleaseFenceHandle(FenceHandle aReleaseFenceHandle) {} |
michael@0 | 317 | |
michael@0 | 318 | const FenceHandle& GetReleaseFenceHandle() const |
michael@0 | 319 | { |
michael@0 | 320 | return mReleaseFenceHandle; |
michael@0 | 321 | } |
michael@0 | 322 | |
michael@0 | 323 | /** |
michael@0 | 324 | * Wait until the current buffer is no longer being read. |
michael@0 | 325 | * |
michael@0 | 326 | * Platform support is necessary. gonk JB supports this function. |
michael@0 | 327 | */ |
michael@0 | 328 | virtual void WaitReleaseFence() {} |
michael@0 | 329 | |
michael@0 | 330 | private: |
michael@0 | 331 | /** |
michael@0 | 332 | * Called once, just before the destructor. |
michael@0 | 333 | * |
michael@0 | 334 | * Here goes the shut-down code that uses virtual methods. |
michael@0 | 335 | * Must only be called by Release(). |
michael@0 | 336 | */ |
michael@0 | 337 | void Finalize(); |
michael@0 | 338 | |
michael@0 | 339 | friend class AtomicRefCountedWithFinalize<TextureClient>; |
michael@0 | 340 | |
michael@0 | 341 | protected: |
michael@0 | 342 | /** |
michael@0 | 343 | * An invalid TextureClient cannot provide access to its shared data |
michael@0 | 344 | * anymore. This usually means it will soon be destroyed. |
michael@0 | 345 | */ |
michael@0 | 346 | void MarkInvalid() { mValid = false; } |
michael@0 | 347 | |
michael@0 | 348 | /** |
michael@0 | 349 | * Drop the shared data into a TextureClientData object and mark this |
michael@0 | 350 | * TextureClient as invalid. |
michael@0 | 351 | * |
michael@0 | 352 | * The TextureClient must not hold any reference to the shared data |
michael@0 | 353 | * after this method has been called. |
michael@0 | 354 | * The TextureClientData is owned by the caller. |
michael@0 | 355 | */ |
michael@0 | 356 | virtual TextureClientData* DropTextureData() = 0; |
michael@0 | 357 | |
michael@0 | 358 | /** |
michael@0 | 359 | * Should only be called *once* per texture, in TextureClient::InitIPDLActor. |
michael@0 | 360 | * Some texture implementations rely on the fact that the descriptor will be |
michael@0 | 361 | * deserialized. |
michael@0 | 362 | * Calling ToSurfaceDescriptor again after it has already returned true, |
michael@0 | 363 | * or never constructing a TextureHost with aDescriptor may result in a memory |
michael@0 | 364 | * leak (see CairoTextureClientD3D9 for example). |
michael@0 | 365 | */ |
michael@0 | 366 | virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor) = 0; |
michael@0 | 367 | |
michael@0 | 368 | void AddFlags(TextureFlags aFlags) |
michael@0 | 369 | { |
michael@0 | 370 | MOZ_ASSERT(!IsSharedWithCompositor()); |
michael@0 | 371 | mFlags |= aFlags; |
michael@0 | 372 | } |
michael@0 | 373 | |
michael@0 | 374 | RefPtr<TextureChild> mActor; |
michael@0 | 375 | TextureFlags mFlags; |
michael@0 | 376 | bool mShared; |
michael@0 | 377 | bool mValid; |
michael@0 | 378 | FenceHandle mReleaseFenceHandle; |
michael@0 | 379 | |
michael@0 | 380 | friend class TextureChild; |
michael@0 | 381 | friend void TestTextureClientSurface(TextureClient*, gfxImageSurface*); |
michael@0 | 382 | friend void TestTextureClientYCbCr(TextureClient*, PlanarYCbCrData&); |
michael@0 | 383 | }; |
michael@0 | 384 | |
michael@0 | 385 | /** |
michael@0 | 386 | * TextureClient that wraps a random access buffer such as a Shmem or raw memory. |
michael@0 | 387 | * This class must be inherited to implement the memory allocation and access bits. |
michael@0 | 388 | * (see ShmemTextureClient and MemoryTextureClient) |
michael@0 | 389 | */ |
michael@0 | 390 | class BufferTextureClient : public TextureClient |
michael@0 | 391 | , public TextureClientYCbCr |
michael@0 | 392 | { |
michael@0 | 393 | public: |
michael@0 | 394 | BufferTextureClient(ISurfaceAllocator* aAllocator, gfx::SurfaceFormat aFormat, |
michael@0 | 395 | gfx::BackendType aBackend, TextureFlags aFlags); |
michael@0 | 396 | |
michael@0 | 397 | virtual ~BufferTextureClient(); |
michael@0 | 398 | |
michael@0 | 399 | virtual bool IsAllocated() const = 0; |
michael@0 | 400 | |
michael@0 | 401 | virtual uint8_t* GetBuffer() const = 0; |
michael@0 | 402 | |
michael@0 | 403 | virtual gfx::IntSize GetSize() const { return mSize; } |
michael@0 | 404 | |
michael@0 | 405 | virtual bool Lock(OpenMode aMode) MOZ_OVERRIDE; |
michael@0 | 406 | |
michael@0 | 407 | virtual void Unlock() MOZ_OVERRIDE; |
michael@0 | 408 | |
michael@0 | 409 | virtual bool IsLocked() const MOZ_OVERRIDE { return mLocked; } |
michael@0 | 410 | |
michael@0 | 411 | virtual bool CanExposeDrawTarget() const MOZ_OVERRIDE { return true; } |
michael@0 | 412 | |
michael@0 | 413 | virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE; |
michael@0 | 414 | |
michael@0 | 415 | virtual bool AllocateForSurface(gfx::IntSize aSize, |
michael@0 | 416 | TextureAllocationFlags aFlags = ALLOC_DEFAULT) MOZ_OVERRIDE; |
michael@0 | 417 | |
michael@0 | 418 | // TextureClientYCbCr |
michael@0 | 419 | |
michael@0 | 420 | virtual TextureClientYCbCr* AsTextureClientYCbCr() MOZ_OVERRIDE { return this; } |
michael@0 | 421 | |
michael@0 | 422 | virtual bool UpdateYCbCr(const PlanarYCbCrData& aData) MOZ_OVERRIDE; |
michael@0 | 423 | |
michael@0 | 424 | virtual bool AllocateForYCbCr(gfx::IntSize aYSize, |
michael@0 | 425 | gfx::IntSize aCbCrSize, |
michael@0 | 426 | StereoMode aStereoMode) MOZ_OVERRIDE; |
michael@0 | 427 | |
michael@0 | 428 | virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; } |
michael@0 | 429 | |
michael@0 | 430 | // XXX - Bug 908196 - Make Allocate(uint32_t) and GetBufferSize() protected. |
michael@0 | 431 | // these two methods should only be called by methods of BufferTextureClient |
michael@0 | 432 | // that are overridden in GrallocTextureClient (which does not implement the |
michael@0 | 433 | // two methods below) |
michael@0 | 434 | virtual bool Allocate(uint32_t aSize) = 0; |
michael@0 | 435 | |
michael@0 | 436 | virtual size_t GetBufferSize() const = 0; |
michael@0 | 437 | |
michael@0 | 438 | virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return true; } |
michael@0 | 439 | |
michael@0 | 440 | ISurfaceAllocator* GetAllocator() const; |
michael@0 | 441 | |
michael@0 | 442 | protected: |
michael@0 | 443 | RefPtr<gfx::DrawTarget> mDrawTarget; |
michael@0 | 444 | RefPtr<ISurfaceAllocator> mAllocator; |
michael@0 | 445 | gfx::SurfaceFormat mFormat; |
michael@0 | 446 | gfx::IntSize mSize; |
michael@0 | 447 | gfx::BackendType mBackend; |
michael@0 | 448 | OpenMode mOpenMode; |
michael@0 | 449 | bool mUsingFallbackDrawTarget; |
michael@0 | 450 | bool mLocked; |
michael@0 | 451 | }; |
michael@0 | 452 | |
michael@0 | 453 | /** |
michael@0 | 454 | * TextureClient that wraps shared memory. |
michael@0 | 455 | * the corresponding texture on the host side is ShmemTextureHost. |
michael@0 | 456 | */ |
michael@0 | 457 | class ShmemTextureClient : public BufferTextureClient |
michael@0 | 458 | { |
michael@0 | 459 | public: |
michael@0 | 460 | ShmemTextureClient(ISurfaceAllocator* aAllocator, gfx::SurfaceFormat aFormat, |
michael@0 | 461 | gfx::BackendType aBackend, TextureFlags aFlags); |
michael@0 | 462 | |
michael@0 | 463 | ~ShmemTextureClient(); |
michael@0 | 464 | |
michael@0 | 465 | virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE; |
michael@0 | 466 | |
michael@0 | 467 | virtual bool Allocate(uint32_t aSize) MOZ_OVERRIDE; |
michael@0 | 468 | |
michael@0 | 469 | virtual uint8_t* GetBuffer() const MOZ_OVERRIDE; |
michael@0 | 470 | |
michael@0 | 471 | virtual size_t GetBufferSize() const MOZ_OVERRIDE; |
michael@0 | 472 | |
michael@0 | 473 | virtual bool IsAllocated() const MOZ_OVERRIDE { return mAllocated; } |
michael@0 | 474 | |
michael@0 | 475 | virtual TextureClientData* DropTextureData() MOZ_OVERRIDE; |
michael@0 | 476 | |
michael@0 | 477 | virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return true; } |
michael@0 | 478 | |
michael@0 | 479 | mozilla::ipc::Shmem& GetShmem() { return mShmem; } |
michael@0 | 480 | |
michael@0 | 481 | protected: |
michael@0 | 482 | mozilla::ipc::Shmem mShmem; |
michael@0 | 483 | bool mAllocated; |
michael@0 | 484 | }; |
michael@0 | 485 | |
michael@0 | 486 | /** |
michael@0 | 487 | * TextureClient that wraps raw memory. |
michael@0 | 488 | * The corresponding texture on the host side is MemoryTextureHost. |
michael@0 | 489 | * Can obviously not be used in a cross process setup. |
michael@0 | 490 | */ |
michael@0 | 491 | class MemoryTextureClient : public BufferTextureClient |
michael@0 | 492 | { |
michael@0 | 493 | public: |
michael@0 | 494 | MemoryTextureClient(ISurfaceAllocator* aAllocator, gfx::SurfaceFormat aFormat, |
michael@0 | 495 | gfx::BackendType aBackend, TextureFlags aFlags); |
michael@0 | 496 | |
michael@0 | 497 | ~MemoryTextureClient(); |
michael@0 | 498 | |
michael@0 | 499 | virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE; |
michael@0 | 500 | |
michael@0 | 501 | virtual bool Allocate(uint32_t aSize) MOZ_OVERRIDE; |
michael@0 | 502 | |
michael@0 | 503 | virtual uint8_t* GetBuffer() const MOZ_OVERRIDE { return mBuffer; } |
michael@0 | 504 | |
michael@0 | 505 | virtual size_t GetBufferSize() const MOZ_OVERRIDE { return mBufSize; } |
michael@0 | 506 | |
michael@0 | 507 | virtual bool IsAllocated() const MOZ_OVERRIDE { return mBuffer != nullptr; } |
michael@0 | 508 | |
michael@0 | 509 | virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return true; } |
michael@0 | 510 | |
michael@0 | 511 | virtual TextureClientData* DropTextureData() MOZ_OVERRIDE; |
michael@0 | 512 | |
michael@0 | 513 | protected: |
michael@0 | 514 | uint8_t* mBuffer; |
michael@0 | 515 | size_t mBufSize; |
michael@0 | 516 | }; |
michael@0 | 517 | |
michael@0 | 518 | struct TextureClientAutoUnlock |
michael@0 | 519 | { |
michael@0 | 520 | TextureClient* mTexture; |
michael@0 | 521 | |
michael@0 | 522 | TextureClientAutoUnlock(TextureClient* aTexture) |
michael@0 | 523 | : mTexture(aTexture) {} |
michael@0 | 524 | |
michael@0 | 525 | ~TextureClientAutoUnlock() |
michael@0 | 526 | { |
michael@0 | 527 | mTexture->Unlock(); |
michael@0 | 528 | } |
michael@0 | 529 | }; |
michael@0 | 530 | |
michael@0 | 531 | } |
michael@0 | 532 | } |
michael@0 | 533 | #endif |