gfx/layers/composite/TextureHost.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/composite/TextureHost.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,646 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 +* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +* License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_GFX_TEXTUREHOST_H
    1.10 +#define MOZILLA_GFX_TEXTUREHOST_H
    1.11 +
    1.12 +#include <stddef.h>                     // for size_t
    1.13 +#include <stdint.h>                     // for uint64_t, uint32_t, uint8_t
    1.14 +#include "gfxTypes.h"
    1.15 +#include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
    1.16 +#include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
    1.17 +#include "mozilla/RefPtr.h"             // for RefPtr, TemporaryRef, etc
    1.18 +#include "mozilla/gfx/2D.h"             // for DataSourceSurface
    1.19 +#include "mozilla/gfx/Point.h"          // for IntSize, IntPoint
    1.20 +#include "mozilla/gfx/Types.h"          // for SurfaceFormat, etc
    1.21 +#include "mozilla/layers/CompositorTypes.h"  // for TextureFlags, etc
    1.22 +#include "mozilla/layers/LayersTypes.h"  // for LayerRenderState, etc
    1.23 +#include "mozilla/mozalloc.h"           // for operator delete
    1.24 +#include "nsCOMPtr.h"                   // for already_AddRefed
    1.25 +#include "nsDebug.h"                    // for NS_RUNTIMEABORT
    1.26 +#include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
    1.27 +#include "nsRegion.h"                   // for nsIntRegion
    1.28 +#include "nsTraceRefcnt.h"              // for MOZ_COUNT_CTOR, etc
    1.29 +#include "nscore.h"                     // for nsACString
    1.30 +#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
    1.31 +
    1.32 +class gfxReusableSurfaceWrapper;
    1.33 +struct nsIntPoint;
    1.34 +struct nsIntSize;
    1.35 +struct nsIntRect;
    1.36 +
    1.37 +namespace mozilla {
    1.38 +namespace ipc {
    1.39 +class Shmem;
    1.40 +}
    1.41 +
    1.42 +namespace layers {
    1.43 +
    1.44 +class Compositor;
    1.45 +class CompositableHost;
    1.46 +class CompositableBackendSpecificData;
    1.47 +class SurfaceDescriptor;
    1.48 +class ISurfaceAllocator;
    1.49 +class TextureHostOGL;
    1.50 +class TextureSourceOGL;
    1.51 +class TextureSourceD3D9;
    1.52 +class TextureSourceD3D11;
    1.53 +class TextureSourceBasic;
    1.54 +class DataTextureSource;
    1.55 +class PTextureParent;
    1.56 +class TextureParent;
    1.57 +
    1.58 +/**
    1.59 + * A view on a TextureHost where the texture is internally represented as tiles
    1.60 + * (contrast with a tiled buffer, where each texture is a tile). For iteration by
    1.61 + * the texture's buffer host.
    1.62 + * This is only useful when the underlying surface is too big to fit in one
    1.63 + * device texture, which forces us to split it in smaller parts.
    1.64 + * Tiled Compositable is a different thing.
    1.65 + */
    1.66 +class TileIterator
    1.67 +{
    1.68 +public:
    1.69 +  virtual void BeginTileIteration() = 0;
    1.70 +  virtual void EndTileIteration() {};
    1.71 +  virtual nsIntRect GetTileRect() = 0;
    1.72 +  virtual size_t GetTileCount() = 0;
    1.73 +  virtual bool NextTile() = 0;
    1.74 +};
    1.75 +
    1.76 +/**
    1.77 + * TextureSource is the interface for texture objects that can be composited
    1.78 + * by a given compositor backend. Since the drawing APIs are different
    1.79 + * between backends, the TextureSource interface is split into different
    1.80 + * interfaces (TextureSourceOGL, etc.), and TextureSource mostly provide
    1.81 + * access to these interfaces.
    1.82 + *
    1.83 + * This class is used on the compositor side.
    1.84 + */
    1.85 +class TextureSource
    1.86 +{
    1.87 +protected:
    1.88 +  virtual ~TextureSource();
    1.89 +
    1.90 +public:
    1.91 +  NS_INLINE_DECL_REFCOUNTING(TextureSource)
    1.92 +
    1.93 +  TextureSource();
    1.94 +
    1.95 +  /**
    1.96 +   * Return the size of the texture in texels.
    1.97 +   * If this is a tile iterator, GetSize must return the size of the current tile.
    1.98 +   */
    1.99 +  virtual gfx::IntSize GetSize() const = 0;
   1.100 +
   1.101 +  /**
   1.102 +   * Return the pixel format of this texture
   1.103 +   */
   1.104 +  virtual gfx::SurfaceFormat GetFormat() const { return gfx::SurfaceFormat::UNKNOWN; }
   1.105 +
   1.106 +  /**
   1.107 +   * Cast to a TextureSource for for each backend..
   1.108 +   */
   1.109 +  virtual TextureSourceOGL* AsSourceOGL() { return nullptr; }
   1.110 +  virtual TextureSourceD3D9* AsSourceD3D9() { return nullptr; }
   1.111 +  virtual TextureSourceD3D11* AsSourceD3D11() { return nullptr; }
   1.112 +  virtual TextureSourceBasic* AsSourceBasic() { return nullptr; }
   1.113 +
   1.114 +  /**
   1.115 +   * Cast to a DataTextureSurce.
   1.116 +   */
   1.117 +  virtual DataTextureSource* AsDataTextureSource() { return nullptr; }
   1.118 +
   1.119 +  /**
   1.120 +   * In some rare cases we currently need to consider a group of textures as one
   1.121 +   * TextureSource, that can be split in sub-TextureSources.
   1.122 +   */
   1.123 +  virtual TextureSource* GetSubSource(int index) { return nullptr; }
   1.124 +
   1.125 +  /**
   1.126 +   * Overload this if the TextureSource supports big textures that don't fit in
   1.127 +   * one device texture and must be tiled internally.
   1.128 +   */
   1.129 +  virtual TileIterator* AsTileIterator() { return nullptr; }
   1.130 +
   1.131 +  virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData);
   1.132 +
   1.133 +protected:
   1.134 +  RefPtr<CompositableBackendSpecificData> mCompositableBackendData;
   1.135 +};
   1.136 +
   1.137 +/**
   1.138 + * XXX - merge this class with TextureSource when deprecated texture classes
   1.139 + * are completely removed.
   1.140 + */
   1.141 +class NewTextureSource : public TextureSource
   1.142 +{
   1.143 +public:
   1.144 +  NewTextureSource()
   1.145 +  {
   1.146 +    MOZ_COUNT_CTOR(NewTextureSource);
   1.147 +  }
   1.148 +  virtual ~NewTextureSource()
   1.149 +  {
   1.150 +    MOZ_COUNT_DTOR(NewTextureSource);
   1.151 +  }
   1.152 +
   1.153 +  /**
   1.154 +   * Should be overridden in order to deallocate the data that is associated
   1.155 +   * with the rendering backend, such as GL textures.
   1.156 +   */
   1.157 +  virtual void DeallocateDeviceData() = 0;
   1.158 +
   1.159 +  virtual void SetCompositor(Compositor* aCompositor) {}
   1.160 +
   1.161 +  void SetNextSibling(NewTextureSource* aTexture)
   1.162 +  {
   1.163 +    mNextSibling = aTexture;
   1.164 +  }
   1.165 +
   1.166 +  NewTextureSource* GetNextSibling() const
   1.167 +  {
   1.168 +    return mNextSibling;
   1.169 +  }
   1.170 +
   1.171 +  // temporary adapter to use the same SubSource API as the old TextureSource
   1.172 +  virtual TextureSource* GetSubSource(int index) MOZ_OVERRIDE
   1.173 +  {
   1.174 +    switch (index) {
   1.175 +      case 0: return this;
   1.176 +      case 1: return GetNextSibling();
   1.177 +      case 2: return GetNextSibling() ? GetNextSibling()->GetNextSibling() : nullptr;
   1.178 +    }
   1.179 +    return nullptr;
   1.180 +  }
   1.181 +
   1.182 +protected:
   1.183 +  RefPtr<NewTextureSource> mNextSibling;
   1.184 +};
   1.185 +
   1.186 +/**
   1.187 + * Interface for TextureSources that can be updated from a DataSourceSurface.
   1.188 + *
   1.189 + * All backend should implement at least one DataTextureSource.
   1.190 + */
   1.191 +class DataTextureSource : public NewTextureSource
   1.192 +{
   1.193 +public:
   1.194 +  DataTextureSource()
   1.195 +    : mUpdateSerial(0)
   1.196 +  {}
   1.197 +
   1.198 +  virtual DataTextureSource* AsDataTextureSource() MOZ_OVERRIDE { return this; }
   1.199 +
   1.200 +  /**
   1.201 +   * Upload a (portion of) surface to the TextureSource.
   1.202 +   *
   1.203 +   * The DataTextureSource doesn't own aSurface, although it owns and manage
   1.204 +   * the device texture it uploads to internally.
   1.205 +   */
   1.206 +  virtual bool Update(gfx::DataSourceSurface* aSurface,
   1.207 +                      nsIntRegion* aDestRegion = nullptr,
   1.208 +                      gfx::IntPoint* aSrcOffset = nullptr) = 0;
   1.209 +
   1.210 +  /**
   1.211 +   * A facility to avoid reuploading when it is not necessary.
   1.212 +   * The caller of Update can use GetUpdateSerial to see if the number has changed
   1.213 +   * since last update, and call SetUpdateSerial after each successful update.
   1.214 +   * The caller is responsible for managing the update serial except when the
   1.215 +   * texture data is deallocated in which case the TextureSource should always
   1.216 +   * reset the update serial to zero.
   1.217 +   */
   1.218 +  uint32_t GetUpdateSerial() const { return mUpdateSerial; }
   1.219 +  void SetUpdateSerial(uint32_t aValue) { mUpdateSerial = aValue; }
   1.220 +
   1.221 +  // By default at least set the update serial to zero.
   1.222 +  // overloaded versions should do that too.
   1.223 +  virtual void DeallocateDeviceData() MOZ_OVERRIDE
   1.224 +  {
   1.225 +    SetUpdateSerial(0);
   1.226 +  }
   1.227 +
   1.228 +#ifdef DEBUG
   1.229 +  /**
   1.230 +   * Provide read access to the data as a DataSourceSurface.
   1.231 +   *
   1.232 +   * This is expected to be very slow and should be used for mostly debugging.
   1.233 +   * XXX - implement everywhere and make it pure virtual.
   1.234 +   */
   1.235 +  virtual TemporaryRef<gfx::DataSourceSurface> ReadBack() { return nullptr; };
   1.236 +#endif
   1.237 +
   1.238 +private:
   1.239 +  uint32_t mUpdateSerial;
   1.240 +};
   1.241 +
   1.242 +/**
   1.243 + * TextureHost is a thin abstraction over texture data that need to be shared
   1.244 + * between the content process and the compositor process. It is the
   1.245 + * compositor-side half of a TextureClient/TextureHost pair. A corresponding
   1.246 + * TextureClient lives on the content-side.
   1.247 + *
   1.248 + * TextureHost only knows how to deserialize or synchronize generic image data
   1.249 + * (SurfaceDescriptor) and provide access to one or more TextureSource objects
   1.250 + * (these provide the necessary APIs for compositor backends to composite the
   1.251 + * image).
   1.252 + *
   1.253 + * A TextureHost implementation corresponds to one SurfaceDescriptor type, as
   1.254 + * opposed to TextureSource that corresponds to device textures.
   1.255 + * This means that for YCbCr planes, even though they are represented as
   1.256 + * 3 textures internally (3 TextureSources), we use 1 TextureHost and not 3,
   1.257 + * because the 3 planes are stored in the same buffer of shared memory, before
   1.258 + * they are uploaded separately.
   1.259 + *
   1.260 + * There is always one and only one TextureHost per TextureClient, and the
   1.261 + * TextureClient/Host pair only owns one buffer of image data through its
   1.262 + * lifetime. This means that the lifetime of the underlying shared data
   1.263 + * matches the lifetime of the TextureClient/Host pair. It also means
   1.264 + * TextureClient/Host do not implement double buffering, which is the
   1.265 + * reponsibility of the compositable (which would use two Texture pairs).
   1.266 + *
   1.267 + * The Lock/Unlock mecanism here mirrors Lock/Unlock in TextureClient.
   1.268 + *
   1.269 + */
   1.270 +class TextureHost
   1.271 +  : public AtomicRefCountedWithFinalize<TextureHost>
   1.272 +{
   1.273 +  /**
   1.274 +   * Called once, just before the destructor.
   1.275 +   *
   1.276 +   * Here goes the shut-down code that uses virtual methods.
   1.277 +   * Must only be called by Release().
   1.278 +   */
   1.279 +  void Finalize();
   1.280 +
   1.281 +  friend class AtomicRefCountedWithFinalize<TextureHost>;
   1.282 +public:
   1.283 +  TextureHost(TextureFlags aFlags);
   1.284 +
   1.285 +  virtual ~TextureHost();
   1.286 +
   1.287 +  /**
   1.288 +   * Factory method.
   1.289 +   */
   1.290 +  static TemporaryRef<TextureHost> Create(const SurfaceDescriptor& aDesc,
   1.291 +                                          ISurfaceAllocator* aDeallocator,
   1.292 +                                          TextureFlags aFlags);
   1.293 +
   1.294 +  /**
   1.295 +   * Tell to TextureChild that TextureHost is recycled.
   1.296 +   * This function should be called from TextureHost's RecycleCallback.
   1.297 +   * If SetRecycleCallback is set to TextureHost.
   1.298 +   * TextureHost can be recycled by calling RecycleCallback
   1.299 +   * when reference count becomes one.
   1.300 +   * One reference count is always added by TextureChild.
   1.301 +   */
   1.302 +  void CompositorRecycle();
   1.303 +
   1.304 +  /**
   1.305 +   * Lock the texture host for compositing.
   1.306 +   */
   1.307 +  virtual bool Lock() { return true; }
   1.308 +
   1.309 +  /**
   1.310 +   * Unlock the texture host after compositing.
   1.311 +   */
   1.312 +  virtual void Unlock() {}
   1.313 +
   1.314 +  /**
   1.315 +   * Note that the texture host format can be different from its corresponding
   1.316 +   * texture source's. For example a ShmemTextureHost can have the ycbcr
   1.317 +   * format and produce 3 "alpha" textures sources.
   1.318 +   */
   1.319 +  virtual gfx::SurfaceFormat GetFormat() const = 0;
   1.320 +
   1.321 +  /**
   1.322 +   * Return a list of TextureSources for use with a Compositor.
   1.323 +   *
   1.324 +   * This can trigger texture uploads, so do not call it inside transactions
   1.325 +   * so as to not upload textures while the main thread is blocked.
   1.326 +   * Must not be called while this TextureHost is not sucessfully Locked.
   1.327 +   */
   1.328 +  virtual NewTextureSource* GetTextureSources() = 0;
   1.329 +
   1.330 +  /**
   1.331 +   * Is called before compositing if the shared data has changed since last
   1.332 +   * composition.
   1.333 +   * This method should be overload in cases like when we need to do a texture
   1.334 +   * upload for example.
   1.335 +   *
   1.336 +   * @param aRegion The region that has been changed, if nil, it means that the
   1.337 +   * entire surface should be updated.
   1.338 +   */
   1.339 +  virtual void Updated(const nsIntRegion* aRegion = nullptr) {}
   1.340 +
   1.341 +  /**
   1.342 +   * Sets this TextureHost's compositor.
   1.343 +   * A TextureHost can change compositor on certain occasions, in particular if
   1.344 +   * it belongs to an async Compositable.
   1.345 +   * aCompositor can be null, in which case the TextureHost must cleanup  all
   1.346 +   * of it's device textures.
   1.347 +   */
   1.348 +  virtual void SetCompositor(Compositor* aCompositor) {}
   1.349 +
   1.350 +  /**
   1.351 +   * Should be overridden in order to deallocate the data that is associated
   1.352 +   * with the rendering backend, such as GL textures.
   1.353 +   */
   1.354 +  virtual void DeallocateDeviceData() {}
   1.355 +
   1.356 +  /**
   1.357 +   * Should be overridden in order to deallocate the data that is shared with
   1.358 +   * the content side, such as shared memory.
   1.359 +   */
   1.360 +  virtual void DeallocateSharedData() {}
   1.361 +
   1.362 +  /**
   1.363 +   * Should be overridden in order to force the TextureHost to drop all references
   1.364 +   * to it's shared data.
   1.365 +   *
   1.366 +   * This is important to ensure the correctness of the deallocation protocol.
   1.367 +   */
   1.368 +  virtual void ForgetSharedData() {}
   1.369 +
   1.370 +  virtual gfx::IntSize GetSize() const = 0;
   1.371 +
   1.372 +  /**
   1.373 +   * Debug facility.
   1.374 +   * XXX - cool kids use Moz2D. See bug 882113.
   1.375 +   */
   1.376 +  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() = 0;
   1.377 +
   1.378 +  /**
   1.379 +   * XXX - Flags should only be set at creation time, this will be removed.
   1.380 +   */
   1.381 +  void SetFlags(TextureFlags aFlags) { mFlags = aFlags; }
   1.382 +
   1.383 +  /**
   1.384 +   * XXX - Flags should only be set at creation time, this will be removed.
   1.385 +   */
   1.386 +  void AddFlag(TextureFlags aFlag) { mFlags |= aFlag; }
   1.387 +
   1.388 +  TextureFlags GetFlags() { return mFlags; }
   1.389 +
   1.390 +  /**
   1.391 +   * Allocate and deallocate a TextureParent actor.
   1.392 +   *
   1.393 +   * TextureParent< is an implementation detail of TextureHost that is not
   1.394 +   * exposed to the rest of the code base. CreateIPDLActor and DestroyIPDLActor
   1.395 +   * are for use with the managing IPDL protocols only (so that they can
   1.396 +   * implement AllocPTextureParent and DeallocPTextureParent).
   1.397 +   */
   1.398 +  static PTextureParent* CreateIPDLActor(ISurfaceAllocator* aAllocator,
   1.399 +                                         const SurfaceDescriptor& aSharedData,
   1.400 +                                         TextureFlags aFlags);
   1.401 +  static bool DestroyIPDLActor(PTextureParent* actor);
   1.402 +
   1.403 +  /**
   1.404 +   * Destroy the TextureChild/Parent pair.
   1.405 +   */
   1.406 +  static bool SendDeleteIPDLActor(PTextureParent* actor);
   1.407 +
   1.408 +  /**
   1.409 +   * Get the TextureHost corresponding to the actor passed in parameter.
   1.410 +   */
   1.411 +  static TextureHost* AsTextureHost(PTextureParent* actor);
   1.412 +
   1.413 +  /**
   1.414 +   * Return a pointer to the IPDLActor.
   1.415 +   *
   1.416 +   * This is to be used with IPDL messages only. Do not store the returned
   1.417 +   * pointer.
   1.418 +   */
   1.419 +  PTextureParent* GetIPDLActor();
   1.420 +
   1.421 +  /**
   1.422 +   * Specific to B2G's Composer2D
   1.423 +   * XXX - more doc here
   1.424 +   */
   1.425 +  virtual LayerRenderState GetRenderState()
   1.426 +  {
   1.427 +    // By default we return an empty render state, this should be overridden
   1.428 +    // by the TextureHost implementations that are used on B2G with Composer2D
   1.429 +    return LayerRenderState();
   1.430 +  }
   1.431 +
   1.432 +  virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData);
   1.433 +
   1.434 +  // If a texture host holds a reference to shmem, it should override this method
   1.435 +  // to forget about the shmem _without_ releasing it.
   1.436 +  virtual void OnShutdown() {}
   1.437 +
   1.438 +  // Forget buffer actor. Used only for hacky fix for bug 966446. 
   1.439 +  virtual void ForgetBufferActor() {}
   1.440 +
   1.441 +  virtual const char *Name() { return "TextureHost"; }
   1.442 +  virtual void PrintInfo(nsACString& aTo, const char* aPrefix);
   1.443 +
   1.444 +  /**
   1.445 +   * Indicates whether the TextureHost implementation is backed by an
   1.446 +   * in-memory buffer. The consequence of this is that locking the
   1.447 +   * TextureHost does not contend with locking the texture on the client side.
   1.448 +   */
   1.449 +  virtual bool HasInternalBuffer() const { return false; }
   1.450 +
   1.451 +  /**
   1.452 +   * Cast to a TextureHost for each backend.
   1.453 +   */
   1.454 +  virtual TextureHostOGL* AsHostOGL() { return nullptr; }
   1.455 +
   1.456 +protected:
   1.457 +  PTextureParent* mActor;
   1.458 +  TextureFlags mFlags;
   1.459 +  RefPtr<CompositableBackendSpecificData> mCompositableBackendData;
   1.460 +
   1.461 +  friend class TextureParent;
   1.462 +};
   1.463 +
   1.464 +/**
   1.465 + * TextureHost that wraps a random access buffer such as a Shmem or some raw
   1.466 + * memory.
   1.467 + *
   1.468 + * This TextureHost is backend-independent and the backend-specific bits are
   1.469 + * in the TextureSource.
   1.470 + * This class must be inherited to implement GetBuffer and DeallocSharedData
   1.471 + * (see ShmemTextureHost and MemoryTextureHost)
   1.472 + *
   1.473 + * Uploads happen when Lock is called.
   1.474 + *
   1.475 + * BufferTextureHost supports YCbCr and flavours of RGBA images (RGBX, A, etc.).
   1.476 + */
   1.477 +class BufferTextureHost : public TextureHost
   1.478 +{
   1.479 +public:
   1.480 +  BufferTextureHost(gfx::SurfaceFormat aFormat,
   1.481 +                    TextureFlags aFlags);
   1.482 +
   1.483 +  ~BufferTextureHost();
   1.484 +
   1.485 +  virtual uint8_t* GetBuffer() = 0;
   1.486 +
   1.487 +  virtual size_t GetBufferSize() = 0;
   1.488 +
   1.489 +  virtual void Updated(const nsIntRegion* aRegion = nullptr) MOZ_OVERRIDE;
   1.490 +
   1.491 +  virtual bool Lock() MOZ_OVERRIDE;
   1.492 +
   1.493 +  virtual void Unlock() MOZ_OVERRIDE;
   1.494 +
   1.495 +  virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE;
   1.496 +
   1.497 +  virtual void DeallocateDeviceData() MOZ_OVERRIDE;
   1.498 +
   1.499 +  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
   1.500 +
   1.501 +  /**
   1.502 +   * Return the format that is exposed to the compositor when calling
   1.503 +   * GetTextureSources.
   1.504 +   *
   1.505 +   * If the shared format is YCbCr and the compositor does not support it,
   1.506 +   * GetFormat will be RGB32 (even though mFormat is SurfaceFormat::YUV).
   1.507 +   */
   1.508 +  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
   1.509 +
   1.510 +  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
   1.511 +
   1.512 +  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE;
   1.513 +
   1.514 +  virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return true; }
   1.515 +
   1.516 +protected:
   1.517 +  bool Upload(nsIntRegion *aRegion = nullptr);
   1.518 +  bool MaybeUpload(nsIntRegion *aRegion = nullptr);
   1.519 +
   1.520 +  Compositor* mCompositor;
   1.521 +  RefPtr<DataTextureSource> mFirstSource;
   1.522 +  nsIntRegion mMaybeUpdatedRegion;
   1.523 +  gfx::IntSize mSize;
   1.524 +  // format of the data that is shared with the content process.
   1.525 +  gfx::SurfaceFormat mFormat;
   1.526 +  uint32_t mUpdateSerial;
   1.527 +  bool mLocked;
   1.528 +  bool mPartialUpdate;
   1.529 +};
   1.530 +
   1.531 +/**
   1.532 + * TextureHost that wraps shared memory.
   1.533 + * the corresponding texture on the client side is ShmemTextureClient.
   1.534 + * This TextureHost is backend-independent.
   1.535 + */
   1.536 +class ShmemTextureHost : public BufferTextureHost
   1.537 +{
   1.538 +public:
   1.539 +  ShmemTextureHost(const mozilla::ipc::Shmem& aShmem,
   1.540 +                   gfx::SurfaceFormat aFormat,
   1.541 +                   ISurfaceAllocator* aDeallocator,
   1.542 +                   TextureFlags aFlags);
   1.543 +
   1.544 +  ~ShmemTextureHost();
   1.545 +
   1.546 +  virtual void DeallocateSharedData() MOZ_OVERRIDE;
   1.547 +
   1.548 +  virtual void ForgetSharedData() MOZ_OVERRIDE;
   1.549 +
   1.550 +  virtual uint8_t* GetBuffer() MOZ_OVERRIDE;
   1.551 +
   1.552 +  virtual size_t GetBufferSize() MOZ_OVERRIDE;
   1.553 +
   1.554 +  virtual const char *Name() MOZ_OVERRIDE { return "ShmemTextureHost"; }
   1.555 +
   1.556 +  virtual void OnShutdown() MOZ_OVERRIDE;
   1.557 +
   1.558 +protected:
   1.559 +  mozilla::ipc::Shmem* mShmem;
   1.560 +  RefPtr<ISurfaceAllocator> mDeallocator;
   1.561 +};
   1.562 +
   1.563 +/**
   1.564 + * TextureHost that wraps raw memory.
   1.565 + * The corresponding texture on the client side is MemoryTextureClient.
   1.566 + * Can obviously not be used in a cross process setup.
   1.567 + * This TextureHost is backend-independent.
   1.568 + */
   1.569 +class MemoryTextureHost : public BufferTextureHost
   1.570 +{
   1.571 +public:
   1.572 +  MemoryTextureHost(uint8_t* aBuffer,
   1.573 +                    gfx::SurfaceFormat aFormat,
   1.574 +                    TextureFlags aFlags);
   1.575 +
   1.576 +  ~MemoryTextureHost();
   1.577 +
   1.578 +  virtual void DeallocateSharedData() MOZ_OVERRIDE;
   1.579 +
   1.580 +  virtual void ForgetSharedData() MOZ_OVERRIDE;
   1.581 +
   1.582 +  virtual uint8_t* GetBuffer() MOZ_OVERRIDE;
   1.583 +
   1.584 +  virtual size_t GetBufferSize() MOZ_OVERRIDE;
   1.585 +
   1.586 +  virtual const char *Name() MOZ_OVERRIDE { return "MemoryTextureHost"; }
   1.587 +
   1.588 +protected:
   1.589 +  uint8_t* mBuffer;
   1.590 +};
   1.591 +
   1.592 +class MOZ_STACK_CLASS AutoLockTextureHost
   1.593 +{
   1.594 +public:
   1.595 +  AutoLockTextureHost(TextureHost* aTexture)
   1.596 +    : mTexture(aTexture)
   1.597 +  {
   1.598 +    mLocked = mTexture ? mTexture->Lock() : false;
   1.599 +  }
   1.600 +
   1.601 +  ~AutoLockTextureHost()
   1.602 +  {
   1.603 +    if (mTexture && mLocked) {
   1.604 +      mTexture->Unlock();
   1.605 +    }
   1.606 +  }
   1.607 +
   1.608 +  bool Failed() { return mTexture && !mLocked; }
   1.609 +
   1.610 +private:
   1.611 +  RefPtr<TextureHost> mTexture;
   1.612 +  bool mLocked;
   1.613 +};
   1.614 +
   1.615 +/**
   1.616 + * This can be used as an offscreen rendering target by the compositor, and
   1.617 + * subsequently can be used as a source by the compositor.
   1.618 + */
   1.619 +class CompositingRenderTarget : public TextureSource
   1.620 +{
   1.621 +public:
   1.622 +  CompositingRenderTarget(const gfx::IntPoint& aOrigin)
   1.623 +    : mOrigin(aOrigin)
   1.624 +  {}
   1.625 +  virtual ~CompositingRenderTarget() {}
   1.626 +
   1.627 +#ifdef MOZ_DUMP_PAINTING
   1.628 +  virtual TemporaryRef<gfx::DataSourceSurface> Dump(Compositor* aCompositor) { return nullptr; }
   1.629 +#endif
   1.630 +
   1.631 +  const gfx::IntPoint& GetOrigin() { return mOrigin; }
   1.632 +
   1.633 +private:
   1.634 +  gfx::IntPoint mOrigin;
   1.635 +};
   1.636 +
   1.637 +/**
   1.638 + * Creates a TextureHost that can be used with any of the existing backends
   1.639 + * Not all SurfaceDescriptor types are supported
   1.640 + */
   1.641 +TemporaryRef<TextureHost>
   1.642 +CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
   1.643 +                                    ISurfaceAllocator* aDeallocator,
   1.644 +                                    TextureFlags aFlags);
   1.645 +
   1.646 +}
   1.647 +}
   1.648 +
   1.649 +#endif

mercurial