gfx/thebes/gfxReusableSharedImageSurfaceWrapper.h
author ffxbld
Thu, 13 Feb 2014 19:59:34 -0500
branchGECKO280b3_2014021319_RELBRANCH
changeset 176295 1f89dd5f5d38ea7361e472ec5ae547f8c338f04c
parent 174271 781892a439cf94def2bcb9c497e70868a36b8ab4
child 216144 91a4d189f5d75a231be157f9be994b3b4b13f062
permissions -rw-r--r--
Automated checkin: version bump for firefox 28.0b3 release. DONTBUILD CLOSED TREE a=release

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GFXSHMCOWSURFACEWRAPPER
#define GFXSHMCOWSURFACEWRAPPER

#include "gfxReusableSurfaceWrapper.h"
#include "mozilla/RefPtr.h"

class gfxSharedImageSurface;

namespace mozilla {
namespace ipc {
class Shmem;
}
namespace layers {
class ISurfaceAllocator;
}
}

/**
 * A cross-process capable implementation of gfxReusableSurfaceWrapper based
 * on gfxSharedImageSurface.
 */
class gfxReusableSharedImageSurfaceWrapper : public gfxReusableSurfaceWrapper {
public:
  gfxReusableSharedImageSurfaceWrapper(mozilla::layers::ISurfaceAllocator* aAllocator,
                                       gfxSharedImageSurface* aSurface);
  ~gfxReusableSharedImageSurfaceWrapper();

  const unsigned char* GetReadOnlyData() const MOZ_OVERRIDE;
  gfxImageFormat Format() MOZ_OVERRIDE;
  gfxReusableSurfaceWrapper* GetWritable(gfxImageSurface** aSurface) MOZ_OVERRIDE;
  void ReadLock() MOZ_OVERRIDE;
  void ReadUnlock() MOZ_OVERRIDE;

  Type GetType()
  {
    return TYPE_SHARED_IMAGE;
  }

  /**
   * Returns the shared memory segment that backs the shared image surface.
   */
  mozilla::ipc::Shmem& GetShmem();

  /**
   * Create a gfxReusableSurfaceWrapper from the shared memory segment of a
   * gfxSharedImageSurface. A ReadLock must be held, which will be adopted by
   * the returned gfxReusableSurfaceWrapper.
   */
  static already_AddRefed<gfxReusableSharedImageSurfaceWrapper>
  Open(mozilla::layers::ISurfaceAllocator* aAllocator, const mozilla::ipc::Shmem& aShmem);

private:
  mozilla::RefPtr<mozilla::layers::ISurfaceAllocator> mAllocator;
  nsRefPtr<gfxSharedImageSurface>         mSurface;
};

#endif // GFXSHMCOWSURFACEWRAPPER