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 | #ifndef GFX_ASYNCCOMPOSITIONMANAGER_H |
michael@0 | 7 | #define GFX_ASYNCCOMPOSITIONMANAGER_H |
michael@0 | 8 | |
michael@0 | 9 | #include "Units.h" // for LayerPoint, etc |
michael@0 | 10 | #include "mozilla/layers/LayerManagerComposite.h" // for LayerManagerComposite |
michael@0 | 11 | #include "gfx3DMatrix.h" // for gfx3DMatrix |
michael@0 | 12 | #include "mozilla/Attributes.h" // for MOZ_DELETE, MOZ_FINAL, etc |
michael@0 | 13 | #include "mozilla/RefPtr.h" // for RefCounted |
michael@0 | 14 | #include "mozilla/TimeStamp.h" // for TimeStamp |
michael@0 | 15 | #include "mozilla/dom/ScreenOrientation.h" // for ScreenOrientation |
michael@0 | 16 | #include "mozilla/gfx/BasePoint.h" // for BasePoint |
michael@0 | 17 | #include "mozilla/layers/LayersMessages.h" // for TargetConfig |
michael@0 | 18 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 19 | #include "nsISupportsImpl.h" // for LayerManager::AddRef, etc |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { |
michael@0 | 22 | namespace layers { |
michael@0 | 23 | |
michael@0 | 24 | class AsyncPanZoomController; |
michael@0 | 25 | class Layer; |
michael@0 | 26 | class LayerManagerComposite; |
michael@0 | 27 | class AutoResolveRefLayers; |
michael@0 | 28 | |
michael@0 | 29 | // Represents (affine) transforms that are calculated from a content view. |
michael@0 | 30 | struct ViewTransform { |
michael@0 | 31 | ViewTransform(LayerPoint aTranslation = LayerPoint(), |
michael@0 | 32 | ParentLayerToScreenScale aScale = ParentLayerToScreenScale()) |
michael@0 | 33 | : mTranslation(aTranslation) |
michael@0 | 34 | , mScale(aScale) |
michael@0 | 35 | {} |
michael@0 | 36 | |
michael@0 | 37 | operator gfx3DMatrix() const |
michael@0 | 38 | { |
michael@0 | 39 | return |
michael@0 | 40 | gfx3DMatrix::Translation(mTranslation.x, mTranslation.y, 0) * |
michael@0 | 41 | gfx3DMatrix::ScalingMatrix(mScale.scale, mScale.scale, 1); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | bool operator==(const ViewTransform& rhs) const { |
michael@0 | 45 | return mTranslation == rhs.mTranslation && mScale == rhs.mScale; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | bool operator!=(const ViewTransform& rhs) const { |
michael@0 | 49 | return !(*this == rhs); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | LayerPoint mTranslation; |
michael@0 | 53 | ParentLayerToScreenScale mScale; |
michael@0 | 54 | }; |
michael@0 | 55 | |
michael@0 | 56 | /** |
michael@0 | 57 | * Manage async composition effects. This class is only used with OMTC and only |
michael@0 | 58 | * lives on the compositor thread. It is a layer on top of the layer manager |
michael@0 | 59 | * (LayerManagerComposite) which deals with elements of composition which are |
michael@0 | 60 | * usually dealt with by dom or layout when main thread rendering, but which can |
michael@0 | 61 | * short circuit that stuff to directly affect layers as they are composited, |
michael@0 | 62 | * for example, off-main thread animation, async video, async pan/zoom. |
michael@0 | 63 | */ |
michael@0 | 64 | class AsyncCompositionManager MOZ_FINAL |
michael@0 | 65 | { |
michael@0 | 66 | friend class AutoResolveRefLayers; |
michael@0 | 67 | public: |
michael@0 | 68 | NS_INLINE_DECL_REFCOUNTING(AsyncCompositionManager) |
michael@0 | 69 | |
michael@0 | 70 | AsyncCompositionManager(LayerManagerComposite* aManager) |
michael@0 | 71 | : mLayerManager(aManager) |
michael@0 | 72 | , mIsFirstPaint(false) |
michael@0 | 73 | , mLayersUpdated(false) |
michael@0 | 74 | , mReadyForCompose(true) |
michael@0 | 75 | { |
michael@0 | 76 | } |
michael@0 | 77 | ~AsyncCompositionManager() |
michael@0 | 78 | { |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * This forces the is-first-paint flag to true. This is intended to |
michael@0 | 83 | * be called by the widget code when it loses its viewport information |
michael@0 | 84 | * (or for whatever reason wants to refresh the viewport information). |
michael@0 | 85 | * The information refresh happens because the compositor will call |
michael@0 | 86 | * SetFirstPaintViewport on the next frame of composition. |
michael@0 | 87 | */ |
michael@0 | 88 | void ForceIsFirstPaint() { mIsFirstPaint = true; } |
michael@0 | 89 | |
michael@0 | 90 | // Sample transforms for layer trees. Return true to request |
michael@0 | 91 | // another animation frame. |
michael@0 | 92 | bool TransformShadowTree(TimeStamp aCurrentFrame); |
michael@0 | 93 | |
michael@0 | 94 | // Calculates the correct rotation and applies the transform to |
michael@0 | 95 | // our layer manager |
michael@0 | 96 | void ComputeRotation(); |
michael@0 | 97 | |
michael@0 | 98 | // Call after updating our layer tree. |
michael@0 | 99 | void Updated(bool isFirstPaint, const TargetConfig& aTargetConfig) |
michael@0 | 100 | { |
michael@0 | 101 | mIsFirstPaint |= isFirstPaint; |
michael@0 | 102 | mLayersUpdated = true; |
michael@0 | 103 | mTargetConfig = aTargetConfig; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | bool RequiresReorientation(mozilla::dom::ScreenOrientation aOrientation) |
michael@0 | 107 | { |
michael@0 | 108 | return mTargetConfig.orientation() != aOrientation; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | // True if the underlying layer tree is ready to be composited. |
michael@0 | 112 | bool ReadyForCompose() { return mReadyForCompose; } |
michael@0 | 113 | |
michael@0 | 114 | // Returns true if the next composition will be the first for a |
michael@0 | 115 | // particular document. |
michael@0 | 116 | bool IsFirstPaint() { return mIsFirstPaint; } |
michael@0 | 117 | |
michael@0 | 118 | private: |
michael@0 | 119 | void TransformScrollableLayer(Layer* aLayer); |
michael@0 | 120 | // Return true if an AsyncPanZoomController content transform was |
michael@0 | 121 | // applied for |aLayer|. *aWantNextFrame is set to true if the |
michael@0 | 122 | // controller wants another animation frame. |
michael@0 | 123 | bool ApplyAsyncContentTransformToTree(TimeStamp aCurrentFrame, Layer* aLayer, |
michael@0 | 124 | bool* aWantNextFrame); |
michael@0 | 125 | /** |
michael@0 | 126 | * Update the shadow transform for aLayer assuming that is a scrollbar, |
michael@0 | 127 | * so that it stays in sync with the content that is being scrolled by APZ. |
michael@0 | 128 | */ |
michael@0 | 129 | void ApplyAsyncTransformToScrollbar(TimeStamp aCurrentFrame, ContainerLayer* aLayer); |
michael@0 | 130 | |
michael@0 | 131 | void SetFirstPaintViewport(const LayerIntPoint& aOffset, |
michael@0 | 132 | const CSSToLayerScale& aZoom, |
michael@0 | 133 | const CSSRect& aCssPageRect); |
michael@0 | 134 | void SetPageRect(const CSSRect& aCssPageRect); |
michael@0 | 135 | void SyncViewportInfo(const LayerIntRect& aDisplayPort, |
michael@0 | 136 | const CSSToLayerScale& aDisplayResolution, |
michael@0 | 137 | bool aLayersUpdated, |
michael@0 | 138 | ScreenPoint& aScrollOffset, |
michael@0 | 139 | CSSToScreenScale& aScale, |
michael@0 | 140 | LayerMargin& aFixedLayerMargins, |
michael@0 | 141 | ScreenPoint& aOffset); |
michael@0 | 142 | void SyncFrameMetrics(const ScreenPoint& aScrollOffset, |
michael@0 | 143 | float aZoom, |
michael@0 | 144 | const CSSRect& aCssPageRect, |
michael@0 | 145 | bool aLayersUpdated, |
michael@0 | 146 | const CSSRect& aDisplayPort, |
michael@0 | 147 | const CSSToLayerScale& aDisplayResolution, |
michael@0 | 148 | bool aIsFirstPaint, |
michael@0 | 149 | LayerMargin& aFixedLayerMargins, |
michael@0 | 150 | ScreenPoint& aOffset); |
michael@0 | 151 | |
michael@0 | 152 | /** |
michael@0 | 153 | * Adds a translation to the transform of any fixed position (whose parent |
michael@0 | 154 | * layer is not fixed) or sticky position layer descendant of |
michael@0 | 155 | * aTransformedSubtreeRoot. The translation is chosen so that the layer's |
michael@0 | 156 | * anchor point relative to aTransformedSubtreeRoot's parent layer is the same |
michael@0 | 157 | * as it was when aTransformedSubtreeRoot's GetLocalTransform() was |
michael@0 | 158 | * aPreviousTransformForRoot. For sticky position layers, the translation is |
michael@0 | 159 | * further intersected with the layer's sticky scroll ranges. |
michael@0 | 160 | * This function will also adjust layers so that the given content document |
michael@0 | 161 | * fixed position margins will be respected during asynchronous panning and |
michael@0 | 162 | * zooming. |
michael@0 | 163 | */ |
michael@0 | 164 | void AlignFixedAndStickyLayers(Layer* aLayer, Layer* aTransformedSubtreeRoot, |
michael@0 | 165 | const gfx::Matrix4x4& aPreviousTransformForRoot, |
michael@0 | 166 | const LayerMargin& aFixedLayerMargins); |
michael@0 | 167 | |
michael@0 | 168 | /** |
michael@0 | 169 | * DRAWING PHASE ONLY |
michael@0 | 170 | * |
michael@0 | 171 | * For reach RefLayer in our layer tree, look up its referent and connect it |
michael@0 | 172 | * to the layer tree, if found. |
michael@0 | 173 | */ |
michael@0 | 174 | void ResolveRefLayers(); |
michael@0 | 175 | /** |
michael@0 | 176 | * Detaches all referents resolved by ResolveRefLayers. |
michael@0 | 177 | * Assumes that mLayerManager->GetRoot() and mTargetConfig have not changed |
michael@0 | 178 | * since ResolveRefLayers was called. |
michael@0 | 179 | */ |
michael@0 | 180 | void DetachRefLayers(); |
michael@0 | 181 | |
michael@0 | 182 | TargetConfig mTargetConfig; |
michael@0 | 183 | CSSRect mContentRect; |
michael@0 | 184 | |
michael@0 | 185 | nsRefPtr<LayerManagerComposite> mLayerManager; |
michael@0 | 186 | // When this flag is set, the next composition will be the first for a |
michael@0 | 187 | // particular document (i.e. the document displayed on the screen will change). |
michael@0 | 188 | // This happens when loading a new page or switching tabs. We notify the |
michael@0 | 189 | // front-end (e.g. Java on Android) about this so that it take the new page |
michael@0 | 190 | // size and zoom into account when providing us with the next view transform. |
michael@0 | 191 | bool mIsFirstPaint; |
michael@0 | 192 | |
michael@0 | 193 | // This flag is set during a layers update, so that the first composition |
michael@0 | 194 | // after a layers update has it set. It is cleared after that first composition. |
michael@0 | 195 | bool mLayersUpdated; |
michael@0 | 196 | |
michael@0 | 197 | bool mReadyForCompose; |
michael@0 | 198 | }; |
michael@0 | 199 | |
michael@0 | 200 | class MOZ_STACK_CLASS AutoResolveRefLayers { |
michael@0 | 201 | public: |
michael@0 | 202 | AutoResolveRefLayers(AsyncCompositionManager* aManager) : mManager(aManager) |
michael@0 | 203 | { |
michael@0 | 204 | if (mManager) { |
michael@0 | 205 | mManager->ResolveRefLayers(); |
michael@0 | 206 | } |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | ~AutoResolveRefLayers() |
michael@0 | 210 | { |
michael@0 | 211 | if (mManager) { |
michael@0 | 212 | mManager->DetachRefLayers(); |
michael@0 | 213 | } |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | private: |
michael@0 | 217 | AsyncCompositionManager* mManager; |
michael@0 | 218 | |
michael@0 | 219 | AutoResolveRefLayers(const AutoResolveRefLayers&) MOZ_DELETE; |
michael@0 | 220 | AutoResolveRefLayers& operator=(const AutoResolveRefLayers&) MOZ_DELETE; |
michael@0 | 221 | }; |
michael@0 | 222 | |
michael@0 | 223 | } // layers |
michael@0 | 224 | } // mozilla |
michael@0 | 225 | |
michael@0 | 226 | #endif |