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: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "X11TextureHost.h" |
michael@0 | 7 | #include "mozilla/layers/BasicCompositor.h" |
michael@0 | 8 | #include "mozilla/layers/X11TextureSourceBasic.h" |
michael@0 | 9 | #ifdef GL_PROVIDER_GLX |
michael@0 | 10 | #include "mozilla/layers/CompositorOGL.h" |
michael@0 | 11 | #include "mozilla/layers/X11TextureSourceOGL.h" |
michael@0 | 12 | #endif |
michael@0 | 13 | #include "gfxXlibSurface.h" |
michael@0 | 14 | #include "gfx2DGlue.h" |
michael@0 | 15 | |
michael@0 | 16 | using namespace mozilla; |
michael@0 | 17 | using namespace mozilla::layers; |
michael@0 | 18 | using namespace mozilla::gfx; |
michael@0 | 19 | |
michael@0 | 20 | X11TextureHost::X11TextureHost(TextureFlags aFlags, |
michael@0 | 21 | const SurfaceDescriptorX11& aDescriptor) |
michael@0 | 22 | : TextureHost(aFlags) |
michael@0 | 23 | { |
michael@0 | 24 | nsRefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign(); |
michael@0 | 25 | mSurface = surface.get(); |
michael@0 | 26 | |
michael@0 | 27 | // The host always frees the pixmap. |
michael@0 | 28 | MOZ_ASSERT(!(aFlags & TEXTURE_DEALLOCATE_CLIENT)); |
michael@0 | 29 | mSurface->TakePixmap(); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | bool |
michael@0 | 33 | X11TextureHost::Lock() |
michael@0 | 34 | { |
michael@0 | 35 | if (!mCompositor) { |
michael@0 | 36 | return false; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | if (!mTextureSource) { |
michael@0 | 40 | switch (mCompositor->GetBackendType()) { |
michael@0 | 41 | case LayersBackend::LAYERS_BASIC: |
michael@0 | 42 | mTextureSource = |
michael@0 | 43 | new X11TextureSourceBasic(static_cast<BasicCompositor*>(mCompositor), |
michael@0 | 44 | mSurface); |
michael@0 | 45 | break; |
michael@0 | 46 | #ifdef GL_PROVIDER_GLX |
michael@0 | 47 | case LayersBackend::LAYERS_OPENGL: |
michael@0 | 48 | mTextureSource = |
michael@0 | 49 | new X11TextureSourceOGL(static_cast<CompositorOGL*>(mCompositor), |
michael@0 | 50 | mSurface); |
michael@0 | 51 | break; |
michael@0 | 52 | #endif |
michael@0 | 53 | default: |
michael@0 | 54 | return false; |
michael@0 | 55 | } |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | return true; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | void |
michael@0 | 62 | X11TextureHost::SetCompositor(Compositor* aCompositor) |
michael@0 | 63 | { |
michael@0 | 64 | mCompositor = aCompositor; |
michael@0 | 65 | if (mTextureSource) { |
michael@0 | 66 | mTextureSource->SetCompositor(aCompositor); |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | SurfaceFormat |
michael@0 | 71 | X11TextureHost::GetFormat() const |
michael@0 | 72 | { |
michael@0 | 73 | gfxContentType type = mSurface->GetContentType(); |
michael@0 | 74 | #ifdef GL_PROVIDER_GLX |
michael@0 | 75 | if (mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL) { |
michael@0 | 76 | return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type); |
michael@0 | 77 | } |
michael@0 | 78 | #endif |
michael@0 | 79 | return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | IntSize |
michael@0 | 83 | X11TextureHost::GetSize() const |
michael@0 | 84 | { |
michael@0 | 85 | return ToIntSize(mSurface->GetSize()); |
michael@0 | 86 | } |