1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxReusableSurfaceWrapper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef GFXCOWSURFACEWRAPPER 1.9 +#define GFXCOWSURFACEWRAPPER 1.10 + 1.11 +#include "gfxImageSurface.h" 1.12 +#include "nsISupportsImpl.h" 1.13 +#include "nsAutoPtr.h" 1.14 + 1.15 + 1.16 +/** 1.17 + * Provides an interface to implement a cross thread/process wrapper for a 1.18 + * gfxImageSurface that has copy-on-write semantics. 1.19 + * 1.20 + * Only the owner thread can write to the surface and acquire 1.21 + * read locks. Destroying a gfxReusableSurfaceWrapper releases 1.22 + * a read lock. 1.23 + * 1.24 + * OMTC Usage: 1.25 + * 1) Content creates a writable copy of this surface 1.26 + * wrapper which will be optimized to the same wrapper if there 1.27 + * are no readers. 1.28 + * 2) The surface is sent from content to the compositor once 1.29 + * or potentially many times, each increasing a read lock. 1.30 + * 3) When the compositor receives the surface, it adopts the 1.31 + * read lock. 1.32 + * 4) Once the compositor has processed the surface and uploaded 1.33 + * the content, it then releases the read lock by dereferencing 1.34 + * its wrapper. 1.35 + */ 1.36 +class gfxReusableSurfaceWrapper { 1.37 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxReusableSurfaceWrapper) 1.38 +public: 1.39 + 1.40 + /** 1.41 + * Returns a read-only pointer to the image data. 1.42 + */ 1.43 + virtual const unsigned char* GetReadOnlyData() const = 0; 1.44 + 1.45 + /** 1.46 + * Returns the image surface format. 1.47 + */ 1.48 + virtual gfxImageFormat Format() = 0; 1.49 + 1.50 + /** 1.51 + * Returns a writable copy of the image. 1.52 + * If necessary this will copy the wrapper. If there are no contention 1.53 + * the same wrapper will be returned. A ReadLock must be held when 1.54 + * calling this function, and calling it will give up this lock. 1.55 + */ 1.56 + virtual gfxReusableSurfaceWrapper* GetWritable(gfxImageSurface** aSurface) = 0; 1.57 + 1.58 + /** 1.59 + * A read only lock count is recorded, any attempts to 1.60 + * call GetWritable() while this count is greater than one will 1.61 + * create a new surface/wrapper pair. 1.62 + * 1.63 + * When a surface's read count falls to zero, its memory will be 1.64 + * deallocated. It is the responsibility of the user to make sure 1.65 + * that all locks are matched with an equal number of unlocks. 1.66 + */ 1.67 + virtual void ReadLock() = 0; 1.68 + virtual void ReadUnlock() = 0; 1.69 + 1.70 + /** 1.71 + * Types for each implementation of gfxReusableSurfaceWrapper. 1.72 + */ 1.73 + enum Type { 1.74 + TYPE_SHARED_IMAGE, 1.75 + TYPE_IMAGE, 1.76 + 1.77 + TYPE_MAX 1.78 + }; 1.79 + 1.80 + /** 1.81 + * Returns a unique ID for each implementation of gfxReusableSurfaceWrapper. 1.82 + */ 1.83 + virtual Type GetType() = 0; 1.84 + 1.85 +protected: 1.86 + // Protected destructor, to discourage deletion outside of Release(): 1.87 + virtual ~gfxReusableSurfaceWrapper() {} 1.88 + 1.89 + NS_DECL_OWNINGTHREAD 1.90 +}; 1.91 + 1.92 +#endif // GFXCOWSURFACEWRAPPER