gfx/layers/basic/BasicContainerLayer.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; 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 "BasicContainerLayer.h"
michael@0 7 #include <sys/types.h> // for int32_t
michael@0 8 #include "BasicLayersImpl.h" // for ToData
michael@0 9 #include "basic/BasicImplData.h" // for BasicImplData
michael@0 10 #include "basic/BasicLayers.h" // for BasicLayerManager
michael@0 11 #include "mozilla/gfx/BaseRect.h" // for BaseRect
michael@0 12 #include "mozilla/mozalloc.h" // for operator new
michael@0 13 #include "nsAutoPtr.h" // for nsRefPtr
michael@0 14 #include "nsCOMPtr.h" // for already_AddRefed
michael@0 15 #include "nsISupportsImpl.h" // for Layer::AddRef, etc
michael@0 16 #include "nsPoint.h" // for nsIntPoint
michael@0 17 #include "nsRect.h" // for nsIntRect
michael@0 18 #include "nsRegion.h" // for nsIntRegion
michael@0 19
michael@0 20 using namespace mozilla::gfx;
michael@0 21
michael@0 22 namespace mozilla {
michael@0 23 namespace layers {
michael@0 24
michael@0 25 BasicContainerLayer::~BasicContainerLayer()
michael@0 26 {
michael@0 27 while (mFirstChild) {
michael@0 28 ContainerLayer::RemoveChild(mFirstChild);
michael@0 29 }
michael@0 30
michael@0 31 MOZ_COUNT_DTOR(BasicContainerLayer);
michael@0 32 }
michael@0 33
michael@0 34 void
michael@0 35 BasicContainerLayer::ComputeEffectiveTransforms(const Matrix4x4& aTransformToSurface)
michael@0 36 {
michael@0 37 // We push groups for container layers if we need to, which always
michael@0 38 // are aligned in device space, so it doesn't really matter how we snap
michael@0 39 // containers.
michael@0 40 Matrix residual;
michael@0 41 Matrix4x4 idealTransform = GetLocalTransform() * aTransformToSurface;
michael@0 42 idealTransform.ProjectTo2D();
michael@0 43
michael@0 44 if (!idealTransform.CanDraw2D()) {
michael@0 45 mEffectiveTransform = idealTransform;
michael@0 46 ComputeEffectiveTransformsForChildren(Matrix4x4());
michael@0 47 ComputeEffectiveTransformForMaskLayer(Matrix4x4());
michael@0 48 mUseIntermediateSurface = true;
michael@0 49 return;
michael@0 50 }
michael@0 51
michael@0 52 mEffectiveTransform = SnapTransformTranslation(idealTransform, &residual);
michael@0 53 // We always pass the ideal matrix down to our children, so there is no
michael@0 54 // need to apply any compensation using the residual from SnapTransformTranslation.
michael@0 55 ComputeEffectiveTransformsForChildren(idealTransform);
michael@0 56
michael@0 57 ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
michael@0 58
michael@0 59 Layer* child = GetFirstChild();
michael@0 60 bool hasSingleBlendingChild = false;
michael@0 61 if (!HasMultipleChildren() && child) {
michael@0 62 hasSingleBlendingChild = child->GetMixBlendMode() != CompositionOp::OP_OVER;
michael@0 63 }
michael@0 64
michael@0 65 /* If we have a single childand it is not blending,, it can just inherit our opacity,
michael@0 66 * otherwise we need a PushGroup and we need to mark ourselves as using
michael@0 67 * an intermediate surface so our children don't inherit our opacity
michael@0 68 * via GetEffectiveOpacity.
michael@0 69 * Having a mask layer always forces our own push group
michael@0 70 * Having a blend mode also always forces our own push group
michael@0 71 */
michael@0 72 mUseIntermediateSurface =
michael@0 73 GetMaskLayer() ||
michael@0 74 GetForceIsolatedGroup() ||
michael@0 75 (GetMixBlendMode() != CompositionOp::OP_OVER && HasMultipleChildren()) ||
michael@0 76 (GetEffectiveOpacity() != 1.0 && (HasMultipleChildren() || hasSingleBlendingChild));
michael@0 77 }
michael@0 78
michael@0 79 bool
michael@0 80 BasicContainerLayer::ChildrenPartitionVisibleRegion(const nsIntRect& aInRect)
michael@0 81 {
michael@0 82 Matrix transform;
michael@0 83 if (!GetEffectiveTransform().CanDraw2D(&transform) ||
michael@0 84 ThebesMatrix(transform).HasNonIntegerTranslation())
michael@0 85 return false;
michael@0 86
michael@0 87 nsIntPoint offset(int32_t(transform._31), int32_t(transform._32));
michael@0 88 nsIntRect rect = aInRect.Intersect(GetEffectiveVisibleRegion().GetBounds() + offset);
michael@0 89 nsIntRegion covered;
michael@0 90
michael@0 91 for (Layer* l = mFirstChild; l; l = l->GetNextSibling()) {
michael@0 92 if (ToData(l)->IsHidden())
michael@0 93 continue;
michael@0 94
michael@0 95 Matrix childTransform;
michael@0 96 if (!l->GetEffectiveTransform().CanDraw2D(&childTransform) ||
michael@0 97 ThebesMatrix(childTransform).HasNonIntegerTranslation() ||
michael@0 98 l->GetEffectiveOpacity() != 1.0)
michael@0 99 return false;
michael@0 100 nsIntRegion childRegion = l->GetEffectiveVisibleRegion();
michael@0 101 childRegion.MoveBy(int32_t(childTransform._31), int32_t(childTransform._32));
michael@0 102 childRegion.And(childRegion, rect);
michael@0 103 if (l->GetClipRect()) {
michael@0 104 childRegion.And(childRegion, *l->GetClipRect() + offset);
michael@0 105 }
michael@0 106 nsIntRegion intersection;
michael@0 107 intersection.And(covered, childRegion);
michael@0 108 if (!intersection.IsEmpty())
michael@0 109 return false;
michael@0 110 covered.Or(covered, childRegion);
michael@0 111 }
michael@0 112
michael@0 113 return covered.Contains(rect);
michael@0 114 }
michael@0 115
michael@0 116 void
michael@0 117 BasicContainerLayer::Validate(LayerManager::DrawThebesLayerCallback aCallback,
michael@0 118 void* aCallbackData)
michael@0 119 {
michael@0 120 for (Layer* l = mFirstChild; l; l = l->GetNextSibling()) {
michael@0 121 BasicImplData* data = ToData(l);
michael@0 122 data->Validate(aCallback, aCallbackData);
michael@0 123 if (l->GetMaskLayer()) {
michael@0 124 data = ToData(l->GetMaskLayer());
michael@0 125 data->Validate(aCallback, aCallbackData);
michael@0 126 }
michael@0 127 }
michael@0 128 }
michael@0 129
michael@0 130 already_AddRefed<ContainerLayer>
michael@0 131 BasicLayerManager::CreateContainerLayer()
michael@0 132 {
michael@0 133 NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
michael@0 134 nsRefPtr<ContainerLayer> layer = new BasicContainerLayer(this);
michael@0 135 return layer.forget();
michael@0 136 }
michael@0 137
michael@0 138 }
michael@0 139 }

mercurial