1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/gl/SharedSurface.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* SharedSurface abstracts an actual surface (can be a GL texture, but 1.10 + * not necessarily) that handles sharing. 1.11 + * Its specializations are: 1.12 + * SharedSurface_Basic (client-side bitmap, does readback) 1.13 + * SharedSurface_GLTexture 1.14 + * SharedSurface_EGLImage 1.15 + * SharedSurface_ANGLEShareHandle 1.16 + */ 1.17 + 1.18 +#ifndef SHARED_SURFACE_H_ 1.19 +#define SHARED_SURFACE_H_ 1.20 + 1.21 +#include <stdint.h> 1.22 +#include "mozilla/Attributes.h" 1.23 +#include "GLDefs.h" 1.24 +#include "mozilla/gfx/Point.h" 1.25 +#include "SurfaceTypes.h" 1.26 + 1.27 +namespace mozilla { 1.28 +namespace gfx { 1.29 + 1.30 +class SurfaceFactory; 1.31 + 1.32 +class SharedSurface 1.33 +{ 1.34 +protected: 1.35 + const SharedSurfaceType mType; 1.36 + const APITypeT mAPI; 1.37 + const AttachmentType mAttachType; 1.38 + const gfx::IntSize mSize; 1.39 + const bool mHasAlpha; 1.40 + bool mIsLocked; 1.41 + 1.42 + SharedSurface(SharedSurfaceType type, 1.43 + APITypeT api, 1.44 + AttachmentType attachType, 1.45 + const gfx::IntSize& size, 1.46 + bool hasAlpha) 1.47 + : mType(type) 1.48 + , mAPI(api) 1.49 + , mAttachType(attachType) 1.50 + , mSize(size) 1.51 + , mHasAlpha(hasAlpha) 1.52 + , mIsLocked(false) 1.53 + { 1.54 + } 1.55 + 1.56 +public: 1.57 + virtual ~SharedSurface() { 1.58 + } 1.59 + 1.60 + static void Copy(SharedSurface* src, SharedSurface* dest, 1.61 + SurfaceFactory* factory); 1.62 + 1.63 + // This locks the SharedSurface as the production buffer for the context. 1.64 + // This is needed by backends which use PBuffers and/or EGLSurfaces. 1.65 + virtual void LockProd() { 1.66 + MOZ_ASSERT(!mIsLocked); 1.67 + LockProdImpl(); 1.68 + mIsLocked = true; 1.69 + } 1.70 + 1.71 + // Unlocking is harmless if we're already unlocked. 1.72 + virtual void UnlockProd() { 1.73 + if (!mIsLocked) 1.74 + return; 1.75 + 1.76 + UnlockProdImpl(); 1.77 + mIsLocked = false; 1.78 + } 1.79 + 1.80 + virtual void LockProdImpl() = 0; 1.81 + virtual void UnlockProdImpl() = 0; 1.82 + 1.83 + virtual void Fence() = 0; 1.84 + virtual bool WaitSync() = 0; 1.85 + 1.86 + 1.87 + SharedSurfaceType Type() const { 1.88 + return mType; 1.89 + } 1.90 + 1.91 + APITypeT APIType() const { 1.92 + return mAPI; 1.93 + } 1.94 + 1.95 + AttachmentType AttachType() const { 1.96 + return mAttachType; 1.97 + } 1.98 + 1.99 + const gfx::IntSize& Size() const { 1.100 + return mSize; 1.101 + } 1.102 + 1.103 + bool HasAlpha() const { 1.104 + return mHasAlpha; 1.105 + } 1.106 +}; 1.107 + 1.108 +} /* namespace gfx */ 1.109 +} /* namespace mozilla */ 1.110 + 1.111 +#endif /* SHARED_SURFACE_H_ */