gfx/gl/SharedSurfaceEGL.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef SHARED_SURFACE_EGL_H_
     7 #define SHARED_SURFACE_EGL_H_
     9 #include "SharedSurfaceGL.h"
    10 #include "SurfaceFactory.h"
    11 #include "GLLibraryEGL.h"
    12 #include "SurfaceTypes.h"
    13 #include "mozilla/Attributes.h"
    14 #include "mozilla/Mutex.h"
    16 namespace mozilla {
    17 namespace gl {
    19 class GLContext;
    20 class TextureGarbageBin;
    22 class SharedSurface_EGLImage
    23     : public SharedSurface_GL
    24 {
    25 public:
    26     static SharedSurface_EGLImage* Create(GLContext* prodGL,
    27                                           const GLFormats& formats,
    28                                           const gfx::IntSize& size,
    29                                           bool hasAlpha,
    30                                           EGLContext context);
    32     static SharedSurface_EGLImage* Cast(SharedSurface* surf) {
    33         MOZ_ASSERT(surf->Type() == SharedSurfaceType::EGLImageShare);
    35         return (SharedSurface_EGLImage*)surf;
    36     }
    38     static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
    40 protected:
    41     mutable Mutex mMutex;
    42     GLLibraryEGL* const mEGL;
    43     const GLFormats mFormats;
    44     GLuint mProdTex;
    45     EGLImage mImage;
    46     GLContext* mCurConsGL;
    47     GLuint mConsTex;
    48     nsRefPtr<TextureGarbageBin> mGarbageBin;
    49     EGLSync mSync;
    51     SharedSurface_EGLImage(GLContext* gl,
    52                            GLLibraryEGL* egl,
    53                            const gfx::IntSize& size,
    54                            bool hasAlpha,
    55                            const GLFormats& formats,
    56                            GLuint prodTex,
    57                            EGLImage image);
    59     EGLDisplay Display() const;
    60     void UpdateProdTexture(const MutexAutoLock& curAutoLock);
    62 public:
    63     virtual ~SharedSurface_EGLImage();
    65     virtual void LockProdImpl() MOZ_OVERRIDE {}
    66     virtual void UnlockProdImpl() MOZ_OVERRIDE {}
    69     virtual void Fence() MOZ_OVERRIDE;
    70     virtual bool WaitSync() MOZ_OVERRIDE;
    72     virtual GLuint ProdTexture() MOZ_OVERRIDE {
    73       return mProdTex;
    74     }
    76     // Implementation-specific functions below:
    77     // Returns texture and target
    78     void AcquireConsumerTexture(GLContext* consGL, GLuint* out_texture, GLuint* out_target);
    79 };
    83 class SurfaceFactory_EGLImage
    84     : public SurfaceFactory_GL
    85 {
    86 public:
    87     // Fallible:
    88     static SurfaceFactory_EGLImage* Create(GLContext* prodGL,
    89                                            const SurfaceCaps& caps);
    91 protected:
    92     const EGLContext mContext;
    94     SurfaceFactory_EGLImage(GLContext* prodGL,
    95                             EGLContext context,
    96                             const SurfaceCaps& caps)
    97         : SurfaceFactory_GL(prodGL, SharedSurfaceType::EGLImageShare, caps)
    98         , mContext(context)
    99     {}
   101 public:
   102     virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
   103         bool hasAlpha = mReadCaps.alpha;
   104         return SharedSurface_EGLImage::Create(mGL, mFormats, size, hasAlpha, mContext);
   105     }
   106 };
   108 } /* namespace gfx */
   109 } /* namespace mozilla */
   111 #endif /* SHARED_SURFACE_EGL_H_ */

mercurial