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 "CanvasLayerComposite.h" |
michael@0 | 7 | #include "composite/CompositableHost.h" // for CompositableHost |
michael@0 | 8 | #include "gfx2DGlue.h" // for ToFilter, ToMatrix4x4 |
michael@0 | 9 | #include "GraphicsFilter.h" // for GraphicsFilter |
michael@0 | 10 | #include "gfxUtils.h" // for gfxUtils, etc |
michael@0 | 11 | #include "mozilla/gfx/Matrix.h" // for Matrix4x4 |
michael@0 | 12 | #include "mozilla/gfx/Point.h" // for Point |
michael@0 | 13 | #include "mozilla/gfx/Rect.h" // for Rect |
michael@0 | 14 | #include "mozilla/layers/Compositor.h" // for Compositor |
michael@0 | 15 | #include "mozilla/layers/Effects.h" // for EffectChain |
michael@0 | 16 | #include "mozilla/mozalloc.h" // for operator delete |
michael@0 | 17 | #include "nsAString.h" |
michael@0 | 18 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 19 | #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc |
michael@0 | 20 | #include "nsPoint.h" // for nsIntPoint |
michael@0 | 21 | #include "nsString.h" // for nsAutoCString |
michael@0 | 22 | |
michael@0 | 23 | using namespace mozilla; |
michael@0 | 24 | using namespace mozilla::layers; |
michael@0 | 25 | using namespace mozilla::gfx; |
michael@0 | 26 | |
michael@0 | 27 | CanvasLayerComposite::CanvasLayerComposite(LayerManagerComposite* aManager) |
michael@0 | 28 | : CanvasLayer(aManager, nullptr) |
michael@0 | 29 | , LayerComposite(aManager) |
michael@0 | 30 | , mImageHost(nullptr) |
michael@0 | 31 | { |
michael@0 | 32 | MOZ_COUNT_CTOR(CanvasLayerComposite); |
michael@0 | 33 | mImplData = static_cast<LayerComposite*>(this); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | CanvasLayerComposite::~CanvasLayerComposite() |
michael@0 | 37 | { |
michael@0 | 38 | MOZ_COUNT_DTOR(CanvasLayerComposite); |
michael@0 | 39 | |
michael@0 | 40 | CleanupResources(); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | bool |
michael@0 | 44 | CanvasLayerComposite::SetCompositableHost(CompositableHost* aHost) |
michael@0 | 45 | { |
michael@0 | 46 | switch (aHost->GetType()) { |
michael@0 | 47 | case BUFFER_IMAGE_SINGLE: |
michael@0 | 48 | case BUFFER_IMAGE_BUFFERED: |
michael@0 | 49 | case COMPOSITABLE_IMAGE: |
michael@0 | 50 | mImageHost = aHost; |
michael@0 | 51 | return true; |
michael@0 | 52 | default: |
michael@0 | 53 | return false; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | Layer* |
michael@0 | 59 | CanvasLayerComposite::GetLayer() |
michael@0 | 60 | { |
michael@0 | 61 | return this; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | LayerRenderState |
michael@0 | 65 | CanvasLayerComposite::GetRenderState() |
michael@0 | 66 | { |
michael@0 | 67 | if (mDestroyed || !mImageHost || !mImageHost->IsAttached()) { |
michael@0 | 68 | return LayerRenderState(); |
michael@0 | 69 | } |
michael@0 | 70 | return mImageHost->GetRenderState(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | void |
michael@0 | 74 | CanvasLayerComposite::RenderLayer(const nsIntRect& aClipRect) |
michael@0 | 75 | { |
michael@0 | 76 | if (!mImageHost || !mImageHost->IsAttached()) { |
michael@0 | 77 | return; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | mCompositor->MakeCurrent(); |
michael@0 | 81 | |
michael@0 | 82 | #ifdef MOZ_DUMP_PAINTING |
michael@0 | 83 | if (gfxUtils::sDumpPainting) { |
michael@0 | 84 | RefPtr<gfx::DataSourceSurface> surf = mImageHost->GetAsSurface(); |
michael@0 | 85 | WriteSnapshotToDumpFile(this, surf); |
michael@0 | 86 | } |
michael@0 | 87 | #endif |
michael@0 | 88 | |
michael@0 | 89 | GraphicsFilter filter = mFilter; |
michael@0 | 90 | #ifdef ANDROID |
michael@0 | 91 | // Bug 691354 |
michael@0 | 92 | // Using the LINEAR filter we get unexplained artifacts. |
michael@0 | 93 | // Use NEAREST when no scaling is required. |
michael@0 | 94 | Matrix matrix; |
michael@0 | 95 | bool is2D = GetEffectiveTransform().Is2D(&matrix); |
michael@0 | 96 | if (is2D && !ThebesMatrix(matrix).HasNonTranslationOrFlip()) { |
michael@0 | 97 | filter = GraphicsFilter::FILTER_NEAREST; |
michael@0 | 98 | } |
michael@0 | 99 | #endif |
michael@0 | 100 | |
michael@0 | 101 | EffectChain effectChain(this); |
michael@0 | 102 | |
michael@0 | 103 | LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(mMaskLayer, effectChain); |
michael@0 | 104 | gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height); |
michael@0 | 105 | |
michael@0 | 106 | mImageHost->Composite(effectChain, |
michael@0 | 107 | GetEffectiveOpacity(), |
michael@0 | 108 | GetEffectiveTransform(), |
michael@0 | 109 | gfx::ToFilter(filter), |
michael@0 | 110 | clipRect); |
michael@0 | 111 | mImageHost->BumpFlashCounter(); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | CompositableHost* |
michael@0 | 115 | CanvasLayerComposite::GetCompositableHost() |
michael@0 | 116 | { |
michael@0 | 117 | if ( mImageHost && mImageHost->IsAttached()) { |
michael@0 | 118 | return mImageHost.get(); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | return nullptr; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | void |
michael@0 | 125 | CanvasLayerComposite::CleanupResources() |
michael@0 | 126 | { |
michael@0 | 127 | if (mImageHost) { |
michael@0 | 128 | mImageHost->Detach(this); |
michael@0 | 129 | } |
michael@0 | 130 | mImageHost = nullptr; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | nsACString& |
michael@0 | 134 | CanvasLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix) |
michael@0 | 135 | { |
michael@0 | 136 | CanvasLayer::PrintInfo(aTo, aPrefix); |
michael@0 | 137 | aTo += "\n"; |
michael@0 | 138 | if (mImageHost && mImageHost->IsAttached()) { |
michael@0 | 139 | nsAutoCString pfx(aPrefix); |
michael@0 | 140 | pfx += " "; |
michael@0 | 141 | mImageHost->PrintInfo(aTo, pfx.get()); |
michael@0 | 142 | } |
michael@0 | 143 | return aTo; |
michael@0 | 144 | } |
michael@0 | 145 |