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 "ThebesLayerComposite.h" |
michael@0 | 7 | #include "CompositableHost.h" // for TiledLayerProperties, etc |
michael@0 | 8 | #include "FrameMetrics.h" // for FrameMetrics |
michael@0 | 9 | #include "Units.h" // for CSSRect, LayerPixel, etc |
michael@0 | 10 | #include "gfx2DGlue.h" // for ToMatrix4x4 |
michael@0 | 11 | #include "gfxUtils.h" // for gfxUtils, etc |
michael@0 | 12 | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
michael@0 | 13 | #include "mozilla/gfx/Matrix.h" // for Matrix4x4 |
michael@0 | 14 | #include "mozilla/gfx/Point.h" // for Point |
michael@0 | 15 | #include "mozilla/gfx/Rect.h" // for RoundedToInt, Rect |
michael@0 | 16 | #include "mozilla/gfx/Types.h" // for Filter::Filter::LINEAR |
michael@0 | 17 | #include "mozilla/layers/Compositor.h" // for Compositor |
michael@0 | 18 | #include "mozilla/layers/ContentHost.h" // for ContentHost |
michael@0 | 19 | #include "mozilla/layers/Effects.h" // for EffectChain |
michael@0 | 20 | #include "mozilla/mozalloc.h" // for operator delete |
michael@0 | 21 | #include "nsAString.h" |
michael@0 | 22 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 23 | #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc |
michael@0 | 24 | #include "nsMathUtils.h" // for NS_lround |
michael@0 | 25 | #include "nsPoint.h" // for nsIntPoint |
michael@0 | 26 | #include "nsRect.h" // for nsIntRect |
michael@0 | 27 | #include "nsSize.h" // for nsIntSize |
michael@0 | 28 | #include "nsString.h" // for nsAutoCString |
michael@0 | 29 | #include "TextRenderer.h" |
michael@0 | 30 | #include "GeckoProfiler.h" |
michael@0 | 31 | |
michael@0 | 32 | namespace mozilla { |
michael@0 | 33 | namespace layers { |
michael@0 | 34 | |
michael@0 | 35 | class TiledLayerComposer; |
michael@0 | 36 | |
michael@0 | 37 | ThebesLayerComposite::ThebesLayerComposite(LayerManagerComposite *aManager) |
michael@0 | 38 | : ThebesLayer(aManager, nullptr) |
michael@0 | 39 | , LayerComposite(aManager) |
michael@0 | 40 | , mBuffer(nullptr) |
michael@0 | 41 | , mRequiresTiledProperties(false) |
michael@0 | 42 | { |
michael@0 | 43 | MOZ_COUNT_CTOR(ThebesLayerComposite); |
michael@0 | 44 | mImplData = static_cast<LayerComposite*>(this); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | ThebesLayerComposite::~ThebesLayerComposite() |
michael@0 | 48 | { |
michael@0 | 49 | MOZ_COUNT_DTOR(ThebesLayerComposite); |
michael@0 | 50 | CleanupResources(); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | bool |
michael@0 | 54 | ThebesLayerComposite::SetCompositableHost(CompositableHost* aHost) |
michael@0 | 55 | { |
michael@0 | 56 | switch (aHost->GetType()) { |
michael@0 | 57 | case BUFFER_CONTENT_INC: |
michael@0 | 58 | case BUFFER_TILED: |
michael@0 | 59 | case COMPOSITABLE_CONTENT_SINGLE: |
michael@0 | 60 | case COMPOSITABLE_CONTENT_DOUBLE: |
michael@0 | 61 | mBuffer = static_cast<ContentHost*>(aHost); |
michael@0 | 62 | return true; |
michael@0 | 63 | default: |
michael@0 | 64 | return false; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | void |
michael@0 | 69 | ThebesLayerComposite::Disconnect() |
michael@0 | 70 | { |
michael@0 | 71 | Destroy(); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | void |
michael@0 | 75 | ThebesLayerComposite::Destroy() |
michael@0 | 76 | { |
michael@0 | 77 | if (!mDestroyed) { |
michael@0 | 78 | CleanupResources(); |
michael@0 | 79 | mDestroyed = true; |
michael@0 | 80 | } |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | Layer* |
michael@0 | 84 | ThebesLayerComposite::GetLayer() |
michael@0 | 85 | { |
michael@0 | 86 | return this; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | TiledLayerComposer* |
michael@0 | 90 | ThebesLayerComposite::GetTiledLayerComposer() |
michael@0 | 91 | { |
michael@0 | 92 | if (!mBuffer) { |
michael@0 | 93 | return nullptr; |
michael@0 | 94 | } |
michael@0 | 95 | MOZ_ASSERT(mBuffer->IsAttached()); |
michael@0 | 96 | return mBuffer->AsTiledLayerComposer(); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | LayerRenderState |
michael@0 | 100 | ThebesLayerComposite::GetRenderState() |
michael@0 | 101 | { |
michael@0 | 102 | if (!mBuffer || !mBuffer->IsAttached() || mDestroyed) { |
michael@0 | 103 | return LayerRenderState(); |
michael@0 | 104 | } |
michael@0 | 105 | return mBuffer->GetRenderState(); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | void |
michael@0 | 109 | ThebesLayerComposite::RenderLayer(const nsIntRect& aClipRect) |
michael@0 | 110 | { |
michael@0 | 111 | if (!mBuffer || !mBuffer->IsAttached()) { |
michael@0 | 112 | return; |
michael@0 | 113 | } |
michael@0 | 114 | PROFILER_LABEL("ThebesLayerComposite", "RenderLayer"); |
michael@0 | 115 | |
michael@0 | 116 | MOZ_ASSERT(mBuffer->GetCompositor() == mCompositeManager->GetCompositor() && |
michael@0 | 117 | mBuffer->GetLayer() == this, |
michael@0 | 118 | "buffer is corrupted"); |
michael@0 | 119 | |
michael@0 | 120 | gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height); |
michael@0 | 121 | |
michael@0 | 122 | #ifdef MOZ_DUMP_PAINTING |
michael@0 | 123 | if (gfxUtils::sDumpPainting) { |
michael@0 | 124 | RefPtr<gfx::DataSourceSurface> surf = mBuffer->GetAsSurface(); |
michael@0 | 125 | if (surf) { |
michael@0 | 126 | WriteSnapshotToDumpFile(this, surf); |
michael@0 | 127 | } |
michael@0 | 128 | } |
michael@0 | 129 | #endif |
michael@0 | 130 | |
michael@0 | 131 | EffectChain effectChain(this); |
michael@0 | 132 | LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(mMaskLayer, effectChain); |
michael@0 | 133 | |
michael@0 | 134 | nsIntRegion visibleRegion = GetEffectiveVisibleRegion(); |
michael@0 | 135 | |
michael@0 | 136 | TiledLayerProperties tiledLayerProps; |
michael@0 | 137 | if (mRequiresTiledProperties) { |
michael@0 | 138 | tiledLayerProps.mVisibleRegion = visibleRegion; |
michael@0 | 139 | tiledLayerProps.mEffectiveResolution = GetEffectiveResolution(); |
michael@0 | 140 | tiledLayerProps.mValidRegion = mValidRegion; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | mBuffer->SetPaintWillResample(MayResample()); |
michael@0 | 144 | |
michael@0 | 145 | mBuffer->Composite(effectChain, |
michael@0 | 146 | GetEffectiveOpacity(), |
michael@0 | 147 | GetEffectiveTransform(), |
michael@0 | 148 | gfx::Filter::LINEAR, |
michael@0 | 149 | clipRect, |
michael@0 | 150 | &visibleRegion, |
michael@0 | 151 | mRequiresTiledProperties ? &tiledLayerProps |
michael@0 | 152 | : nullptr); |
michael@0 | 153 | mBuffer->BumpFlashCounter(); |
michael@0 | 154 | |
michael@0 | 155 | if (mRequiresTiledProperties) { |
michael@0 | 156 | mValidRegion = tiledLayerProps.mValidRegion; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | mCompositeManager->GetCompositor()->MakeCurrent(); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | CompositableHost* |
michael@0 | 163 | ThebesLayerComposite::GetCompositableHost() |
michael@0 | 164 | { |
michael@0 | 165 | if (mBuffer && mBuffer->IsAttached()) { |
michael@0 | 166 | return mBuffer.get(); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | return nullptr; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | void |
michael@0 | 173 | ThebesLayerComposite::CleanupResources() |
michael@0 | 174 | { |
michael@0 | 175 | if (mBuffer) { |
michael@0 | 176 | mBuffer->Detach(this); |
michael@0 | 177 | } |
michael@0 | 178 | mBuffer = nullptr; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | CSSToScreenScale |
michael@0 | 182 | ThebesLayerComposite::GetEffectiveResolution() |
michael@0 | 183 | { |
michael@0 | 184 | for (ContainerLayer* parent = GetParent(); parent; parent = parent->GetParent()) { |
michael@0 | 185 | const FrameMetrics& metrics = parent->GetFrameMetrics(); |
michael@0 | 186 | if (metrics.GetScrollId() != FrameMetrics::NULL_SCROLL_ID) { |
michael@0 | 187 | return metrics.GetZoom(); |
michael@0 | 188 | } |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | return CSSToScreenScale(1.0); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | nsACString& |
michael@0 | 195 | ThebesLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix) |
michael@0 | 196 | { |
michael@0 | 197 | ThebesLayer::PrintInfo(aTo, aPrefix); |
michael@0 | 198 | aTo += "\n"; |
michael@0 | 199 | if (mBuffer && mBuffer->IsAttached()) { |
michael@0 | 200 | nsAutoCString pfx(aPrefix); |
michael@0 | 201 | pfx += " "; |
michael@0 | 202 | mBuffer->PrintInfo(aTo, pfx.get()); |
michael@0 | 203 | } |
michael@0 | 204 | return aTo; |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | } /* layers */ |
michael@0 | 208 | } /* mozilla */ |