gfx/thebes/gfxReusableSurfaceWrapper.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef GFXCOWSURFACEWRAPPER
michael@0 6 #define GFXCOWSURFACEWRAPPER
michael@0 7
michael@0 8 #include "gfxImageSurface.h"
michael@0 9 #include "nsISupportsImpl.h"
michael@0 10 #include "nsAutoPtr.h"
michael@0 11
michael@0 12
michael@0 13 /**
michael@0 14 * Provides an interface to implement a cross thread/process wrapper for a
michael@0 15 * gfxImageSurface that has copy-on-write semantics.
michael@0 16 *
michael@0 17 * Only the owner thread can write to the surface and acquire
michael@0 18 * read locks. Destroying a gfxReusableSurfaceWrapper releases
michael@0 19 * a read lock.
michael@0 20 *
michael@0 21 * OMTC Usage:
michael@0 22 * 1) Content creates a writable copy of this surface
michael@0 23 * wrapper which will be optimized to the same wrapper if there
michael@0 24 * are no readers.
michael@0 25 * 2) The surface is sent from content to the compositor once
michael@0 26 * or potentially many times, each increasing a read lock.
michael@0 27 * 3) When the compositor receives the surface, it adopts the
michael@0 28 * read lock.
michael@0 29 * 4) Once the compositor has processed the surface and uploaded
michael@0 30 * the content, it then releases the read lock by dereferencing
michael@0 31 * its wrapper.
michael@0 32 */
michael@0 33 class gfxReusableSurfaceWrapper {
michael@0 34 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxReusableSurfaceWrapper)
michael@0 35 public:
michael@0 36
michael@0 37 /**
michael@0 38 * Returns a read-only pointer to the image data.
michael@0 39 */
michael@0 40 virtual const unsigned char* GetReadOnlyData() const = 0;
michael@0 41
michael@0 42 /**
michael@0 43 * Returns the image surface format.
michael@0 44 */
michael@0 45 virtual gfxImageFormat Format() = 0;
michael@0 46
michael@0 47 /**
michael@0 48 * Returns a writable copy of the image.
michael@0 49 * If necessary this will copy the wrapper. If there are no contention
michael@0 50 * the same wrapper will be returned. A ReadLock must be held when
michael@0 51 * calling this function, and calling it will give up this lock.
michael@0 52 */
michael@0 53 virtual gfxReusableSurfaceWrapper* GetWritable(gfxImageSurface** aSurface) = 0;
michael@0 54
michael@0 55 /**
michael@0 56 * A read only lock count is recorded, any attempts to
michael@0 57 * call GetWritable() while this count is greater than one will
michael@0 58 * create a new surface/wrapper pair.
michael@0 59 *
michael@0 60 * When a surface's read count falls to zero, its memory will be
michael@0 61 * deallocated. It is the responsibility of the user to make sure
michael@0 62 * that all locks are matched with an equal number of unlocks.
michael@0 63 */
michael@0 64 virtual void ReadLock() = 0;
michael@0 65 virtual void ReadUnlock() = 0;
michael@0 66
michael@0 67 /**
michael@0 68 * Types for each implementation of gfxReusableSurfaceWrapper.
michael@0 69 */
michael@0 70 enum Type {
michael@0 71 TYPE_SHARED_IMAGE,
michael@0 72 TYPE_IMAGE,
michael@0 73
michael@0 74 TYPE_MAX
michael@0 75 };
michael@0 76
michael@0 77 /**
michael@0 78 * Returns a unique ID for each implementation of gfxReusableSurfaceWrapper.
michael@0 79 */
michael@0 80 virtual Type GetType() = 0;
michael@0 81
michael@0 82 protected:
michael@0 83 // Protected destructor, to discourage deletion outside of Release():
michael@0 84 virtual ~gfxReusableSurfaceWrapper() {}
michael@0 85
michael@0 86 NS_DECL_OWNINGTHREAD
michael@0 87 };
michael@0 88
michael@0 89 #endif // GFXCOWSURFACEWRAPPER

mercurial