2012-04-17 16:21:07 -07:00
|
|
|
/* 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 GFXCOWSURFACEWRAPPER
|
|
|
|
#define GFXCOWSURFACEWRAPPER
|
|
|
|
|
2013-08-19 06:59:25 -07:00
|
|
|
#include "gfxImageSurface.h"
|
2012-04-17 16:21:07 -07:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-08-19 06:59:25 -07:00
|
|
|
* Provides an interface to implement a cross thread/process wrapper for a
|
|
|
|
* gfxImageSurface that has copy-on-write semantics.
|
2012-04-17 16:21:07 -07:00
|
|
|
*
|
2013-08-19 06:59:25 -07:00
|
|
|
* Only the owner thread can write to the surface and acquire
|
|
|
|
* read locks. Destroying a gfxReusableSurfaceWrapper releases
|
|
|
|
* a read lock.
|
2012-04-17 16:21:07 -07:00
|
|
|
*
|
|
|
|
* OMTC Usage:
|
|
|
|
* 1) Content creates a writable copy of this surface
|
2013-08-19 06:59:25 -07:00
|
|
|
* wrapper which will be optimized to the same wrapper if there
|
2012-04-17 16:21:07 -07:00
|
|
|
* are no readers.
|
|
|
|
* 2) The surface is sent from content to the compositor once
|
2013-08-19 06:59:25 -07:00
|
|
|
* or potentially many times, each increasing a read lock.
|
|
|
|
* 3) When the compositor receives the surface, it adopts the
|
|
|
|
* read lock.
|
|
|
|
* 4) Once the compositor has processed the surface and uploaded
|
|
|
|
* the content, it then releases the read lock by dereferencing
|
|
|
|
* its wrapper.
|
2012-04-17 16:21:07 -07:00
|
|
|
*/
|
|
|
|
class gfxReusableSurfaceWrapper {
|
2012-05-27 18:34:20 -07:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxReusableSurfaceWrapper)
|
2012-04-17 16:21:07 -07:00
|
|
|
public:
|
2013-08-19 06:59:25 -07:00
|
|
|
virtual ~gfxReusableSurfaceWrapper() {}
|
|
|
|
|
2012-04-17 16:21:07 -07:00
|
|
|
/**
|
2013-08-19 06:59:25 -07:00
|
|
|
* Returns a read-only pointer to the image data.
|
2012-04-17 16:21:07 -07:00
|
|
|
*/
|
2013-08-19 06:59:25 -07:00
|
|
|
virtual const unsigned char* GetReadOnlyData() const = 0;
|
2013-08-19 06:59:22 -07:00
|
|
|
|
|
|
|
/**
|
2013-08-19 06:59:25 -07:00
|
|
|
* Returns the image surface format.
|
2013-08-19 06:59:22 -07:00
|
|
|
*/
|
2013-09-24 13:45:13 -07:00
|
|
|
virtual gfxImageFormat Format() = 0;
|
2012-04-16 16:04:24 -07:00
|
|
|
|
2012-04-17 16:21:07 -07:00
|
|
|
/**
|
2013-08-19 06:59:25 -07:00
|
|
|
* Returns a writable copy of the image.
|
2012-04-17 16:21:07 -07:00
|
|
|
* If necessary this will copy the wrapper. If there are no contention
|
2013-08-19 06:59:22 -07:00
|
|
|
* the same wrapper will be returned. A ReadLock must be held when
|
|
|
|
* calling this function, and calling it will give up this lock.
|
2012-04-17 16:21:07 -07:00
|
|
|
*/
|
2013-08-19 06:59:25 -07:00
|
|
|
virtual gfxReusableSurfaceWrapper* GetWritable(gfxImageSurface** aSurface) = 0;
|
2012-04-17 16:21:07 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A read only lock count is recorded, any attempts to
|
2013-08-19 06:59:22 -07:00
|
|
|
* call GetWritable() while this count is greater than one will
|
2012-04-17 16:21:07 -07:00
|
|
|
* create a new surface/wrapper pair.
|
2013-08-19 06:59:22 -07:00
|
|
|
*
|
|
|
|
* When a surface's read count falls to zero, its memory will be
|
|
|
|
* deallocated. It is the responsibility of the user to make sure
|
|
|
|
* that all locks are matched with an equal number of unlocks.
|
2012-04-17 16:21:07 -07:00
|
|
|
*/
|
2013-08-19 06:59:25 -07:00
|
|
|
virtual void ReadLock() = 0;
|
|
|
|
virtual void ReadUnlock() = 0;
|
2012-04-17 16:21:07 -07:00
|
|
|
|
2013-08-19 06:59:27 -07:00
|
|
|
/**
|
|
|
|
* Types for each implementation of gfxReusableSurfaceWrapper.
|
|
|
|
*/
|
|
|
|
enum Type {
|
|
|
|
TYPE_SHARED_IMAGE,
|
|
|
|
TYPE_IMAGE,
|
|
|
|
|
|
|
|
TYPE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a unique ID for each implementation of gfxReusableSurfaceWrapper.
|
|
|
|
*/
|
|
|
|
virtual Type GetType() = 0;
|
|
|
|
|
2013-08-19 06:59:25 -07:00
|
|
|
protected:
|
2012-04-17 16:21:07 -07:00
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GFXCOWSURFACEWRAPPER
|