michael@0: /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* SharedSurface abstracts an actual surface (can be a GL texture, but michael@0: * not necessarily) that handles sharing. michael@0: * Its specializations are: michael@0: * SharedSurface_Basic (client-side bitmap, does readback) michael@0: * SharedSurface_GLTexture michael@0: * SharedSurface_EGLImage michael@0: * SharedSurface_ANGLEShareHandle michael@0: */ michael@0: michael@0: #ifndef SHARED_SURFACE_H_ michael@0: #define SHARED_SURFACE_H_ michael@0: michael@0: #include michael@0: #include "mozilla/Attributes.h" michael@0: #include "GLDefs.h" michael@0: #include "mozilla/gfx/Point.h" michael@0: #include "SurfaceTypes.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: class SurfaceFactory; michael@0: michael@0: class SharedSurface michael@0: { michael@0: protected: michael@0: const SharedSurfaceType mType; michael@0: const APITypeT mAPI; michael@0: const AttachmentType mAttachType; michael@0: const gfx::IntSize mSize; michael@0: const bool mHasAlpha; michael@0: bool mIsLocked; michael@0: michael@0: SharedSurface(SharedSurfaceType type, michael@0: APITypeT api, michael@0: AttachmentType attachType, michael@0: const gfx::IntSize& size, michael@0: bool hasAlpha) michael@0: : mType(type) michael@0: , mAPI(api) michael@0: , mAttachType(attachType) michael@0: , mSize(size) michael@0: , mHasAlpha(hasAlpha) michael@0: , mIsLocked(false) michael@0: { michael@0: } michael@0: michael@0: public: michael@0: virtual ~SharedSurface() { michael@0: } michael@0: michael@0: static void Copy(SharedSurface* src, SharedSurface* dest, michael@0: SurfaceFactory* factory); michael@0: michael@0: // This locks the SharedSurface as the production buffer for the context. michael@0: // This is needed by backends which use PBuffers and/or EGLSurfaces. michael@0: virtual void LockProd() { michael@0: MOZ_ASSERT(!mIsLocked); michael@0: LockProdImpl(); michael@0: mIsLocked = true; michael@0: } michael@0: michael@0: // Unlocking is harmless if we're already unlocked. michael@0: virtual void UnlockProd() { michael@0: if (!mIsLocked) michael@0: return; michael@0: michael@0: UnlockProdImpl(); michael@0: mIsLocked = false; michael@0: } michael@0: michael@0: virtual void LockProdImpl() = 0; michael@0: virtual void UnlockProdImpl() = 0; michael@0: michael@0: virtual void Fence() = 0; michael@0: virtual bool WaitSync() = 0; michael@0: michael@0: michael@0: SharedSurfaceType Type() const { michael@0: return mType; michael@0: } michael@0: michael@0: APITypeT APIType() const { michael@0: return mAPI; michael@0: } michael@0: michael@0: AttachmentType AttachType() const { michael@0: return mAttachType; michael@0: } michael@0: michael@0: const gfx::IntSize& Size() const { michael@0: return mSize; michael@0: } michael@0: michael@0: bool HasAlpha() const { michael@0: return mHasAlpha; michael@0: } michael@0: }; michael@0: michael@0: } /* namespace gfx */ michael@0: } /* namespace mozilla */ michael@0: michael@0: #endif /* SHARED_SURFACE_H_ */