gfx/gl/SharedSurfaceGralloc.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/gl/SharedSurfaceGralloc.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     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_GRALLOC_H_
    1.10 +#define SHARED_SURFACE_GRALLOC_H_
    1.11 +
    1.12 +#include "SharedSurfaceGL.h"
    1.13 +#include "mozilla/layers/ISurfaceAllocator.h"
    1.14 +#include "mozilla/layers/LayersSurfaces.h"
    1.15 +#include "mozilla/layers/TextureClient.h"
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace layers {
    1.19 +class ISurfaceAllocator;
    1.20 +}
    1.21 +
    1.22 +namespace gl {
    1.23 +class GLContext;
    1.24 +class GLLibraryEGL;
    1.25 +
    1.26 +class SharedSurface_Gralloc
    1.27 +    : public SharedSurface_GL
    1.28 +{
    1.29 +public:
    1.30 +    static SharedSurface_Gralloc* Create(GLContext* prodGL,
    1.31 +                                         const GLFormats& formats,
    1.32 +                                         const gfx::IntSize& size,
    1.33 +                                         bool hasAlpha,
    1.34 +                                         layers::ISurfaceAllocator* allocator);
    1.35 +
    1.36 +    static SharedSurface_Gralloc* Cast(SharedSurface* surf) {
    1.37 +        MOZ_ASSERT(surf->Type() == SharedSurfaceType::Gralloc);
    1.38 +
    1.39 +        return (SharedSurface_Gralloc*)surf;
    1.40 +    }
    1.41 +
    1.42 +protected:
    1.43 +    GLLibraryEGL* const mEGL;
    1.44 +    RefPtr<layers::ISurfaceAllocator> mAllocator;
    1.45 +    RefPtr<layers::TextureClient> mTextureClient;
    1.46 +    const GLuint mProdTex;
    1.47 +
    1.48 +    SharedSurface_Gralloc(GLContext* prodGL,
    1.49 +                          const gfx::IntSize& size,
    1.50 +                          bool hasAlpha,
    1.51 +                          GLLibraryEGL* egl,
    1.52 +                          layers::ISurfaceAllocator* allocator,
    1.53 +                          layers::TextureClient* textureClient,
    1.54 +                          GLuint prodTex)
    1.55 +        : SharedSurface_GL(SharedSurfaceType::Gralloc,
    1.56 +                           AttachmentType::GLTexture,
    1.57 +                           prodGL,
    1.58 +                           size,
    1.59 +                           hasAlpha)
    1.60 +        , mEGL(egl)
    1.61 +        , mAllocator(allocator)
    1.62 +        , mTextureClient(textureClient)
    1.63 +        , mProdTex(prodTex)
    1.64 +    {}
    1.65 +
    1.66 +    static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
    1.67 +
    1.68 +public:
    1.69 +    virtual ~SharedSurface_Gralloc();
    1.70 +
    1.71 +    virtual void Fence() MOZ_OVERRIDE;
    1.72 +    virtual bool WaitSync() MOZ_OVERRIDE;
    1.73 +
    1.74 +    virtual void LockProdImpl() MOZ_OVERRIDE {}
    1.75 +    virtual void UnlockProdImpl() MOZ_OVERRIDE {}
    1.76 +
    1.77 +    virtual GLuint ProdTexture() MOZ_OVERRIDE {
    1.78 +        return mProdTex;
    1.79 +    }
    1.80 +
    1.81 +    layers::TextureClient* GetTextureClient() {
    1.82 +        return mTextureClient;
    1.83 +    }
    1.84 +};
    1.85 +
    1.86 +class SurfaceFactory_Gralloc
    1.87 +    : public SurfaceFactory_GL
    1.88 +{
    1.89 +protected:
    1.90 +    RefPtr<layers::ISurfaceAllocator> mAllocator;
    1.91 +
    1.92 +public:
    1.93 +    SurfaceFactory_Gralloc(GLContext* prodGL,
    1.94 +                           const SurfaceCaps& caps,
    1.95 +                           layers::ISurfaceAllocator* allocator = nullptr);
    1.96 +
    1.97 +    virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
    1.98 +        bool hasAlpha = mReadCaps.alpha;
    1.99 +        if (!mAllocator) {
   1.100 +            return nullptr;
   1.101 +        }
   1.102 +        return SharedSurface_Gralloc::Create(mGL, mFormats, size, hasAlpha, mAllocator);
   1.103 +    }
   1.104 +};
   1.105 +
   1.106 +} /* namespace gl */
   1.107 +} /* namespace mozilla */
   1.108 +
   1.109 +#endif /* SHARED_SURFACE_GRALLOC_H_ */

mercurial