Tue, 06 Jan 2015 21:39:09 +0100
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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=4 et sw=4 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef GLCONTEXTEGL_H_ |
michael@0 | 8 | #define GLCONTEXTEGL_H_ |
michael@0 | 9 | |
michael@0 | 10 | #include "GLContext.h" |
michael@0 | 11 | #include "GLLibraryEGL.h" |
michael@0 | 12 | |
michael@0 | 13 | #ifdef MOZ_WIDGET_GONK |
michael@0 | 14 | #include "HwcComposer2D.h" |
michael@0 | 15 | #endif |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace gl { |
michael@0 | 19 | |
michael@0 | 20 | class GLContextEGL : public GLContext |
michael@0 | 21 | { |
michael@0 | 22 | friend class TextureImageEGL; |
michael@0 | 23 | |
michael@0 | 24 | static already_AddRefed<GLContextEGL> |
michael@0 | 25 | CreateGLContext(const SurfaceCaps& caps, |
michael@0 | 26 | GLContextEGL *shareContext, |
michael@0 | 27 | bool isOffscreen, |
michael@0 | 28 | EGLConfig config, |
michael@0 | 29 | EGLSurface surface); |
michael@0 | 30 | |
michael@0 | 31 | public: |
michael@0 | 32 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL) |
michael@0 | 33 | GLContextEGL(const SurfaceCaps& caps, |
michael@0 | 34 | GLContext* shareContext, |
michael@0 | 35 | bool isOffscreen, |
michael@0 | 36 | EGLConfig config, |
michael@0 | 37 | EGLSurface surface, |
michael@0 | 38 | EGLContext context); |
michael@0 | 39 | |
michael@0 | 40 | ~GLContextEGL(); |
michael@0 | 41 | |
michael@0 | 42 | virtual GLContextType GetContextType() const MOZ_OVERRIDE { return GLContextType::EGL; } |
michael@0 | 43 | |
michael@0 | 44 | static GLContextEGL* Cast(GLContext* gl) { |
michael@0 | 45 | MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL); |
michael@0 | 46 | return static_cast<GLContextEGL*>(gl); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | bool Init() MOZ_OVERRIDE; |
michael@0 | 50 | |
michael@0 | 51 | virtual bool IsDoubleBuffered() const MOZ_OVERRIDE { |
michael@0 | 52 | return mIsDoubleBuffered; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void SetIsDoubleBuffered(bool aIsDB) { |
michael@0 | 56 | mIsDoubleBuffered = aIsDB; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | virtual bool SupportsRobustness() const MOZ_OVERRIDE { |
michael@0 | 60 | return sEGLLibrary.HasRobustness(); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | virtual bool IsANGLE() const MOZ_OVERRIDE { |
michael@0 | 64 | return sEGLLibrary.IsANGLE(); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | virtual bool BindTexImage() MOZ_OVERRIDE; |
michael@0 | 68 | |
michael@0 | 69 | virtual bool ReleaseTexImage() MOZ_OVERRIDE; |
michael@0 | 70 | |
michael@0 | 71 | void SetEGLSurfaceOverride(EGLSurface surf); |
michael@0 | 72 | |
michael@0 | 73 | virtual bool MakeCurrentImpl(bool aForce) MOZ_OVERRIDE; |
michael@0 | 74 | |
michael@0 | 75 | virtual bool IsCurrent() MOZ_OVERRIDE; |
michael@0 | 76 | |
michael@0 | 77 | virtual bool RenewSurface() MOZ_OVERRIDE; |
michael@0 | 78 | |
michael@0 | 79 | virtual void ReleaseSurface() MOZ_OVERRIDE; |
michael@0 | 80 | |
michael@0 | 81 | virtual bool SetupLookupFunction() MOZ_OVERRIDE; |
michael@0 | 82 | |
michael@0 | 83 | virtual bool SwapBuffers() MOZ_OVERRIDE; |
michael@0 | 84 | |
michael@0 | 85 | // hold a reference to the given surface |
michael@0 | 86 | // for the lifetime of this context. |
michael@0 | 87 | void HoldSurface(gfxASurface *aSurf); |
michael@0 | 88 | |
michael@0 | 89 | EGLContext GetEGLContext() { |
michael@0 | 90 | return mContext; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | bool BindTex2DOffscreen(GLContext *aOffscreen); |
michael@0 | 94 | void UnbindTex2DOffscreen(GLContext *aOffscreen); |
michael@0 | 95 | void BindOffscreenFramebuffer(); |
michael@0 | 96 | |
michael@0 | 97 | static already_AddRefed<GLContextEGL> |
michael@0 | 98 | CreateEGLPixmapOffscreenContext(const gfxIntSize& size); |
michael@0 | 99 | |
michael@0 | 100 | static already_AddRefed<GLContextEGL> |
michael@0 | 101 | CreateEGLPBufferOffscreenContext(const gfxIntSize& size); |
michael@0 | 102 | |
michael@0 | 103 | protected: |
michael@0 | 104 | friend class GLContextProviderEGL; |
michael@0 | 105 | |
michael@0 | 106 | EGLConfig mConfig; |
michael@0 | 107 | EGLSurface mSurface; |
michael@0 | 108 | EGLSurface mSurfaceOverride; |
michael@0 | 109 | EGLContext mContext; |
michael@0 | 110 | nsRefPtr<gfxASurface> mThebesSurface; |
michael@0 | 111 | bool mBound; |
michael@0 | 112 | |
michael@0 | 113 | bool mIsPBuffer; |
michael@0 | 114 | bool mIsDoubleBuffered; |
michael@0 | 115 | bool mCanBindToTexture; |
michael@0 | 116 | bool mShareWithEGLImage; |
michael@0 | 117 | #ifdef MOZ_WIDGET_GONK |
michael@0 | 118 | nsRefPtr<HwcComposer2D> mHwc; |
michael@0 | 119 | #endif |
michael@0 | 120 | bool mOwnsContext; |
michael@0 | 121 | |
michael@0 | 122 | static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(EGLConfig config, |
michael@0 | 123 | EGLenum bindToTextureFormat, |
michael@0 | 124 | gfxIntSize& pbsize); |
michael@0 | 125 | }; |
michael@0 | 126 | |
michael@0 | 127 | } |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | #endif // GLCONTEXTEGL_H_ |