gfx/gl/SharedSurfaceEGL.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/gl/SharedSurfaceEGL.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     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 +#ifndef SHARED_SURFACE_EGL_H_
    1.10 +#define SHARED_SURFACE_EGL_H_
    1.11 +
    1.12 +#include "SharedSurfaceGL.h"
    1.13 +#include "SurfaceFactory.h"
    1.14 +#include "GLLibraryEGL.h"
    1.15 +#include "SurfaceTypes.h"
    1.16 +#include "mozilla/Attributes.h"
    1.17 +#include "mozilla/Mutex.h"
    1.18 +
    1.19 +namespace mozilla {
    1.20 +namespace gl {
    1.21 +
    1.22 +class GLContext;
    1.23 +class TextureGarbageBin;
    1.24 +
    1.25 +class SharedSurface_EGLImage
    1.26 +    : public SharedSurface_GL
    1.27 +{
    1.28 +public:
    1.29 +    static SharedSurface_EGLImage* Create(GLContext* prodGL,
    1.30 +                                          const GLFormats& formats,
    1.31 +                                          const gfx::IntSize& size,
    1.32 +                                          bool hasAlpha,
    1.33 +                                          EGLContext context);
    1.34 +
    1.35 +    static SharedSurface_EGLImage* Cast(SharedSurface* surf) {
    1.36 +        MOZ_ASSERT(surf->Type() == SharedSurfaceType::EGLImageShare);
    1.37 +
    1.38 +        return (SharedSurface_EGLImage*)surf;
    1.39 +    }
    1.40 +
    1.41 +    static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
    1.42 +
    1.43 +protected:
    1.44 +    mutable Mutex mMutex;
    1.45 +    GLLibraryEGL* const mEGL;
    1.46 +    const GLFormats mFormats;
    1.47 +    GLuint mProdTex;
    1.48 +    EGLImage mImage;
    1.49 +    GLContext* mCurConsGL;
    1.50 +    GLuint mConsTex;
    1.51 +    nsRefPtr<TextureGarbageBin> mGarbageBin;
    1.52 +    EGLSync mSync;
    1.53 +
    1.54 +    SharedSurface_EGLImage(GLContext* gl,
    1.55 +                           GLLibraryEGL* egl,
    1.56 +                           const gfx::IntSize& size,
    1.57 +                           bool hasAlpha,
    1.58 +                           const GLFormats& formats,
    1.59 +                           GLuint prodTex,
    1.60 +                           EGLImage image);
    1.61 +
    1.62 +    EGLDisplay Display() const;
    1.63 +    void UpdateProdTexture(const MutexAutoLock& curAutoLock);
    1.64 +
    1.65 +public:
    1.66 +    virtual ~SharedSurface_EGLImage();
    1.67 +
    1.68 +    virtual void LockProdImpl() MOZ_OVERRIDE {}
    1.69 +    virtual void UnlockProdImpl() MOZ_OVERRIDE {}
    1.70 +
    1.71 +
    1.72 +    virtual void Fence() MOZ_OVERRIDE;
    1.73 +    virtual bool WaitSync() MOZ_OVERRIDE;
    1.74 +
    1.75 +    virtual GLuint ProdTexture() MOZ_OVERRIDE {
    1.76 +      return mProdTex;
    1.77 +    }
    1.78 +
    1.79 +    // Implementation-specific functions below:
    1.80 +    // Returns texture and target
    1.81 +    void AcquireConsumerTexture(GLContext* consGL, GLuint* out_texture, GLuint* out_target);
    1.82 +};
    1.83 +
    1.84 +
    1.85 +
    1.86 +class SurfaceFactory_EGLImage
    1.87 +    : public SurfaceFactory_GL
    1.88 +{
    1.89 +public:
    1.90 +    // Fallible:
    1.91 +    static SurfaceFactory_EGLImage* Create(GLContext* prodGL,
    1.92 +                                           const SurfaceCaps& caps);
    1.93 +
    1.94 +protected:
    1.95 +    const EGLContext mContext;
    1.96 +
    1.97 +    SurfaceFactory_EGLImage(GLContext* prodGL,
    1.98 +                            EGLContext context,
    1.99 +                            const SurfaceCaps& caps)
   1.100 +        : SurfaceFactory_GL(prodGL, SharedSurfaceType::EGLImageShare, caps)
   1.101 +        , mContext(context)
   1.102 +    {}
   1.103 +
   1.104 +public:
   1.105 +    virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
   1.106 +        bool hasAlpha = mReadCaps.alpha;
   1.107 +        return SharedSurface_EGLImage::Create(mGL, mFormats, size, hasAlpha, mContext);
   1.108 +    }
   1.109 +};
   1.110 +
   1.111 +} /* namespace gfx */
   1.112 +} /* namespace mozilla */
   1.113 +
   1.114 +#endif /* SHARED_SURFACE_EGL_H_ */

mercurial