2012-04-18 03:21:07 +04: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 17:59:25 +04:00
|
|
|
#include "gfxImageSurface.h"
|
2012-04-18 03:21:07 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-08-19 17:59:25 +04:00
|
|
|
* Provides an interface to implement a cross thread/process wrapper for a
|
|
|
|
* gfxImageSurface that has copy-on-write semantics.
|
2012-04-18 03:21:07 +04:00
|
|
|
*
|
2013-08-19 17:59:25 +04:00
|
|
|
* Only the owner thread can write to the surface and acquire
|
|
|
|
* read locks. Destroying a gfxReusableSurfaceWrapper releases
|
|
|
|
* a read lock.
|
2012-04-18 03:21:07 +04:00
|
|
|
*
|
|
|
|
* OMTC Usage:
|
|
|
|
* 1) Content creates a writable copy of this surface
|
2013-08-19 17:59:25 +04:00
|
|
|
* wrapper which will be optimized to the same wrapper if there
|
2012-04-18 03:21:07 +04:00
|
|
|
* are no readers.
|
|
|
|
* 2) The surface is sent from content to the compositor once
|
2013-08-19 17:59:25 +04: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-18 03:21:07 +04:00
|
|
|
*/
|
|
|
|
class gfxReusableSurfaceWrapper {
|
2012-05-28 05:34:20 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxReusableSurfaceWrapper)
|
2012-04-18 03:21:07 +04:00
|
|
|
public:
|
2013-08-19 17:59:25 +04:00
|
|
|
|
2012-04-18 03:21:07 +04:00
|
|
|
/**
|
2013-08-19 17:59:25 +04:00
|
|
|
* Returns a read-only pointer to the image data.
|
2012-04-18 03:21:07 +04:00
|
|
|
*/
|
2013-08-19 17:59:25 +04:00
|
|
|
virtual const unsigned char* GetReadOnlyData() const = 0;
|
2013-08-19 17:59:22 +04:00
|
|
|
|
|
|
|
/**
|
2013-08-19 17:59:25 +04:00
|
|
|
* Returns the image surface format.
|
2013-08-19 17:59:22 +04:00
|
|
|
*/
|
2013-09-25 00:45:13 +04:00
|
|
|
virtual gfxImageFormat Format() = 0;
|
2012-04-17 03:04:24 +04:00
|
|
|
|
2012-04-18 03:21:07 +04:00
|
|
|
/**
|
2013-08-19 17:59:25 +04:00
|
|
|
* Returns a writable copy of the image.
|
2012-04-18 03:21:07 +04:00
|
|
|
* If necessary this will copy the wrapper. If there are no contention
|
2013-08-19 17:59:22 +04: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-18 03:21:07 +04:00
|
|
|
*/
|
2013-08-19 17:59:25 +04:00
|
|
|
virtual gfxReusableSurfaceWrapper* GetWritable(gfxImageSurface** aSurface) = 0;
|
2012-04-18 03:21:07 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A read only lock count is recorded, any attempts to
|
2013-08-19 17:59:22 +04:00
|
|
|
* call GetWritable() while this count is greater than one will
|
2012-04-18 03:21:07 +04:00
|
|
|
* create a new surface/wrapper pair.
|
2013-08-19 17:59:22 +04: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-18 03:21:07 +04:00
|
|
|
*/
|
2013-08-19 17:59:25 +04:00
|
|
|
virtual void ReadLock() = 0;
|
|
|
|
virtual void ReadUnlock() = 0;
|
2012-04-18 03:21:07 +04:00
|
|
|
|
2013-08-19 17:59:27 +04: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 17:59:25 +04:00
|
|
|
protected:
|
2014-04-04 20:27:02 +04:00
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
|
|
|
virtual ~gfxReusableSurfaceWrapper() {}
|
|
|
|
|
2012-04-18 03:21:07 +04:00
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GFXCOWSURFACEWRAPPER
|