gecko-dev/gfx/thebes/gfxReusableSurfaceWrapper.h

90 строки
2.7 KiB
C
Исходник Обычный вид История

/* 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
#include "gfxImageSurface.h"
#include "nsISupportsImpl.h"
#include "nsAutoPtr.h"
/**
* Provides an interface to implement a cross thread/process wrapper for a
* gfxImageSurface that has copy-on-write semantics.
*
* Only the owner thread can write to the surface and acquire
* read locks. Destroying a gfxReusableSurfaceWrapper releases
* a read lock.
*
* OMTC Usage:
* 1) Content creates a writable copy of this surface
* wrapper which will be optimized to the same wrapper if there
* are no readers.
* 2) The surface is sent from content to the compositor once
* 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.
*/
class gfxReusableSurfaceWrapper {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxReusableSurfaceWrapper)
public:
/**
* Returns a read-only pointer to the image data.
*/
virtual const unsigned char* GetReadOnlyData() const = 0;
/**
* Returns the image surface format.
*/
Bug 913872 - Take nested enums out of gfxASurface - 1/3 : automatic changes - r=jrmuizel Generated by these regexes: find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/gfx[A-Za-z0-9_]*Surface\:\:[a-z]*\(\(ImageFormat\|SurfaceType\|ContentType\|MemoryLocation\)[0-9A-Za-z_]*\)/gfx\1/g' find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/gfx[A-Za-z0-9_]*Surface\:\:[a-z]*\(\(CONTENT_\|MEMORY_\)[0-9A-Za-z_]*\)/GFX_\1/g' find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)\(CONTENT_COLOR\|CONTENT_ALPHA\|CONTENT_COLOR_ALPHA\|CONTENT_SENTINEL\|MEMORY_IN_PROCESS_HEAP\|MEMORY_IN_PROCESS_NONHEAP\|MEMORY_OUT_OF_PROCESS\)\($\|[^A-Za-z0-9_]\)/\1GFX_\2\3/g' find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)\(ImageFormatARGB32\|ImageFormatRGB24\|ImageFormatA8\|ImageFormatA1\|ImageFormatRGB16_565\|ImageFormatUnknown\|SurfaceTypeImage\|SurfaceTypePDF\|SurfaceTypePS\|SurfaceTypeXlib\|SurfaceTypeXcb\|SurfaceTypeGlitz\|SurfaceTypeQuartz\|SurfaceTypeWin32\|SurfaceTypeBeOS\|SurfaceTypeDirectFB\|SurfaceTypeSVG\|SurfaceTypeOS2\|SurfaceTypeWin32Printing\|SurfaceTypeQuartzImage\|SurfaceTypeScript\|SurfaceTypeQPainter\|SurfaceTypeRecording\|SurfaceTypeVG\|SurfaceTypeGL\|SurfaceTypeDRM\|SurfaceTypeTee\|SurfaceTypeXML\|SurfaceTypeSkia\|SurfaceTypeSubsurface\|SurfaceTypeD2D\|SurfaceTypeMax\)\($\|[^A-Za-z0-9_]\)/\1gfx\2\3/g'
2013-09-25 00:45:13 +04:00
virtual gfxImageFormat Format() = 0;
/**
* Returns a writable copy of the image.
* If necessary this will copy the wrapper. If there are no contention
* the same wrapper will be returned. A ReadLock must be held when
* calling this function, and calling it will give up this lock.
*/
virtual gfxReusableSurfaceWrapper* GetWritable(gfxImageSurface** aSurface) = 0;
/**
* A read only lock count is recorded, any attempts to
* call GetWritable() while this count is greater than one will
* create a new surface/wrapper pair.
*
* 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.
*/
virtual void ReadLock() = 0;
virtual void ReadUnlock() = 0;
/**
* 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;
protected:
// Protected destructor, to discourage deletion outside of Release():
virtual ~gfxReusableSurfaceWrapper() {}
NS_DECL_OWNINGTHREAD
};
#endif // GFXCOWSURFACEWRAPPER