1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
/*
Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "Damage.h"
#include "FilterOperations.h"
#include "TextureMapperAnimation.h"
#include "TextureMapperSolidColorLayer.h"
#include <wtf/TZoneMalloc.h>
#include <wtf/WeakPtr.h>
namespace WebCore {
class CoordinatedAnimatedBackingStoreClient;
class TextureMapperLayer;
}
namespace WTF {
template<typename T> struct IsDeprecatedWeakRefSmartPointerException;
template<> struct IsDeprecatedWeakRefSmartPointerException<WebCore::TextureMapperLayer> : std::true_type { };
}
namespace WebCore {
class TextureMapper;
class TextureMapperFlattenedLayer;
class TextureMapperPaintOptions;
class TextureMapperPlatformLayer;
class TextureMapperLayer : public CanMakeWeakPtr<TextureMapperLayer> {
WTF_MAKE_TZONE_ALLOCATED(TextureMapperLayer);
WTF_MAKE_NONCOPYABLE(TextureMapperLayer);
public:
WEBCORE_EXPORT TextureMapperLayer();
WEBCORE_EXPORT virtual ~TextureMapperLayer();
#if USE(COORDINATED_GRAPHICS)
void setID(uint32_t id) { m_id = id; }
uint32_t id() { return m_id; }
#endif
const Vector<TextureMapperLayer*>& children() const { return m_children; }
WEBCORE_EXPORT void setChildren(const Vector<TextureMapperLayer*>&);
WEBCORE_EXPORT void setMaskLayer(TextureMapperLayer*);
WEBCORE_EXPORT void setReplicaLayer(TextureMapperLayer*);
WEBCORE_EXPORT void setBackdropLayer(TextureMapperLayer*);
WEBCORE_EXPORT void setBackdropFiltersRect(const FloatRoundedRect&);
WEBCORE_EXPORT void setPosition(const FloatPoint&);
WEBCORE_EXPORT void setBoundsOrigin(const FloatPoint&);
WEBCORE_EXPORT void setSize(const FloatSize&);
WEBCORE_EXPORT void setAnchorPoint(const FloatPoint3D&);
WEBCORE_EXPORT void setPreserves3D(bool);
WEBCORE_EXPORT void setTransform(const TransformationMatrix&);
WEBCORE_EXPORT void setChildrenTransform(const TransformationMatrix&);
WEBCORE_EXPORT void setContentsRect(const FloatRect&);
WEBCORE_EXPORT void setMasksToBounds(bool);
WEBCORE_EXPORT void setDrawsContent(bool);
bool drawsContent() const { return m_state.drawsContent; }
bool contentsAreVisible() const { return m_state.contentsVisible; }
FloatSize size() const { return m_state.size; }
float opacity() const { return m_state.opacity; }
TransformationMatrix transform() const { return m_state.transform; }
const TransformationMatrix& toSurfaceTransform() const { return m_layerTransforms.combined; }
WEBCORE_EXPORT void setContentsVisible(bool);
WEBCORE_EXPORT void setContentsOpaque(bool);
WEBCORE_EXPORT void setBackfaceVisibility(bool);
WEBCORE_EXPORT void setOpacity(float);
WEBCORE_EXPORT void setSolidColor(const Color&);
WEBCORE_EXPORT void setBackgroundColor(const Color&);
WEBCORE_EXPORT void setContentsTileSize(const FloatSize&);
WEBCORE_EXPORT void setContentsTilePhase(const FloatSize&);
WEBCORE_EXPORT void setContentsClippingRect(const FloatRoundedRect&);
WEBCORE_EXPORT void setContentsRectClipsDescendants(bool);
WEBCORE_EXPORT void setFilters(const FilterOperations&);
bool hasFilters() const
{
return !m_currentFilters.isEmpty();
}
void setShowDebugBorder(bool showDebugBorder) { m_state.showDebugBorders = showDebugBorder; }
void setDebugBorderColor(Color debugBorderColor) { m_state.debugBorderColor = debugBorderColor; }
void setDebugBorderWidth(float debugBorderWidth) { m_state.debugBorderWidth = debugBorderWidth; }
void setShowRepaintCounter(bool showRepaintCounter) { m_state.showRepaintCounter = showRepaintCounter; }
void setRepaintCount(int repaintCount) { m_state.repaintCount = repaintCount; }
WEBCORE_EXPORT void setContentsLayer(TextureMapperPlatformLayer*);
void setAnimations(const TextureMapperAnimations&);
WEBCORE_EXPORT void setBackingStore(TextureMapperBackingStore*);
#if USE(COORDINATED_GRAPHICS)
void setAnimatedBackingStoreClient(CoordinatedAnimatedBackingStoreClient*);
#endif
WEBCORE_EXPORT bool applyAnimationsRecursively(MonotonicTime);
bool syncAnimations(MonotonicTime);
WEBCORE_EXPORT bool descendantsOrSelfHaveRunningAnimations() const;
WEBCORE_EXPORT void prepareForPainting(TextureMapper&);
WEBCORE_EXPORT void paint(TextureMapper&);
void addChild(TextureMapperLayer*);
#if ENABLE(DAMAGE_TRACKING)
void setDamagePropagation(bool enabled) { m_damagePropagation = enabled; }
void setDamage(const Damage&);
void collectDamage(TextureMapper&, Damage&);
#endif
FloatRect effectiveLayerRect() const;
private:
TextureMapperLayer& backdropRootLayer() const
{
if (m_effectTarget)
return m_effectTarget->backdropRootLayer();
if (m_parent) {
if (m_parent->flattensAsLeafOf3DSceneOr3DPerspective()
|| m_parent->m_state.opacity < 1
|| m_parent->hasMask()
|| m_parent->hasFilters()) {
return *m_parent;
}
return m_parent->backdropRootLayer();
}
return const_cast<TextureMapperLayer&>(*this);
}
void processDescendantLayersFlatteningRequirements();
void processFlatteningRequirements();
void computeFlattenedRegion(Region&, bool) const;
void destroyFlattenedDescendantLayers();
struct ComputeTransformData;
void computeTransformsRecursive(ComputeTransformData&);
TransformationMatrix replicaTransform();
void removeFromParent();
void removeAllChildren();
enum class ComputeOverlapRegionMode : uint8_t {
Intersection,
Union,
Mask
};
struct ComputeOverlapRegionData {
ComputeOverlapRegionMode mode;
IntRect clipBounds;
Region& overlapRegion;
Region& nonOverlapRegion;
};
void computeOverlapRegions(ComputeOverlapRegionData&, const TransformationMatrix&, bool includesReplica = true);
Vector<IntRect, 1> computeConsolidatedOverlapRegionRects(TextureMapperPaintOptions&);
void paintRecursive(TextureMapperPaintOptions&);
void paintFlattened(TextureMapperPaintOptions&);
void paintWith3DRenderingContext(TextureMapperPaintOptions&);
void paintSelfChildrenReplicaFilterAndMask(TextureMapperPaintOptions&);
void paintUsingOverlapRegions(TextureMapperPaintOptions&);
void paintIntoSurface(TextureMapperPaintOptions&);
void paintWithIntermediateSurface(TextureMapperPaintOptions&, const IntRect&);
void paintSelfAndChildrenWithIntermediateSurface(TextureMapperPaintOptions&, const IntRect&);
void paintSelfChildrenFilterAndMask(TextureMapperPaintOptions&);
void paintSelf(TextureMapperPaintOptions&);
void paintSelfAndChildren(TextureMapperPaintOptions&);
void paintSelfAndChildrenWithReplica(TextureMapperPaintOptions&);
void paintBackdrop(TextureMapperPaintOptions&);
void applyMask(TextureMapperPaintOptions&);
void collect3DRenderingContextLayers(Vector<TextureMapperLayer*>&);
#if ENABLE(DAMAGE_TRACKING)
bool canInferDamage() const { return m_damagePropagation && !m_damage.isInvalid(); }
void collectDamageRecursive(TextureMapperPaintOptions&, Damage&);
void collectDamageSelfAndChildren(TextureMapperPaintOptions&, Damage&);
void collectDamageSelf(TextureMapperPaintOptions&, Damage&);
void collectDamageSelfChildrenReplicaFilterAndMask(TextureMapperPaintOptions&, Damage&);
void collectDamageSelfChildrenFilterAndMask(TextureMapperPaintOptions&, Damage&);
void damageWholeLayerDueToTransformChange(const TransformationMatrix& beforeChange, const TransformationMatrix& afterChange);
FloatRect transformRectForDamage(const FloatRect&, const TransformationMatrix&, const TextureMapperPaintOptions&);
#endif
bool isVisible() const;
bool shouldBlend() const;
bool flattensAsLeafOf3DSceneOr3DPerspective() const;
bool preserves3D() const { return m_state.preserves3D; }
bool isLeafOf3DRenderingContext() const { return !m_state.preserves3D && (m_parent && m_parent->preserves3D()); }
bool isFlattened() const { return !!m_flattenedLayer; }
bool hasMask() const { return !!m_state.maskLayer; }
bool hasBackdrop() const { return !!m_state.backdropLayer; }
inline FloatRect layerRect() const
{
return FloatRect(FloatPoint::zero(), m_state.size);
}
Vector<TextureMapperLayer*> m_children;
TextureMapperLayer* m_parent { nullptr };
WeakPtr<TextureMapperLayer> m_effectTarget;
TextureMapperBackingStore* m_backingStore { nullptr };
TextureMapperPlatformLayer* m_contentsLayer { nullptr };
std::unique_ptr<TextureMapperFlattenedLayer> m_flattenedLayer;
float m_currentOpacity { 1.0 };
FilterOperations m_currentFilters;
struct State {
FloatPoint pos;
FloatPoint3D anchorPoint;
FloatPoint boundsOrigin;
FloatSize size;
TransformationMatrix transform;
TransformationMatrix childrenTransform;
float opacity;
FloatRect contentsRect;
FloatSize contentsTileSize;
FloatSize contentsTilePhase;
FloatRoundedRect contentsClippingRect;
WeakPtr<TextureMapperLayer> maskLayer;
WeakPtr<TextureMapperLayer> replicaLayer;
WeakPtr<TextureMapperLayer> backdropLayer;
FloatRoundedRect backdropFiltersRect;
Color solidColor;
Color backgroundColor;
FilterOperations filters;
Color debugBorderColor;
float debugBorderWidth;
int repaintCount;
bool preserves3D : 1;
bool masksToBounds : 1;
bool drawsContent : 1;
bool contentsVisible : 1;
bool contentsOpaque : 1;
bool contentsRectClipsDescendants : 1;
bool backfaceVisibility : 1;
bool visible : 1;
bool showDebugBorders : 1;
bool showRepaintCounter : 1;
State()
: anchorPoint(0.5, 0.5, 0)
, opacity(1)
, debugBorderWidth(0)
, repaintCount(0)
, preserves3D(false)
, masksToBounds(false)
, drawsContent(false)
, contentsVisible(true)
, contentsOpaque(false)
, contentsRectClipsDescendants(false)
, backfaceVisibility(true)
, visible(true)
, showDebugBorders(false)
, showRepaintCounter(false)
{
}
};
State m_state;
TextureMapperAnimations m_animations;
#if USE(COORDINATED_GRAPHICS)
uint32_t m_id { 0 };
RefPtr<CoordinatedAnimatedBackingStoreClient> m_animatedBackingStoreClient;
#endif
bool m_isBackdrop { false };
bool m_isReplica { false };
#if ENABLE(DAMAGE_TRACKING)
bool m_damagePropagation { false };
Damage m_damage; // In layer coordinate space.
Damage m_inferredDamage; // In global coordinate space.
FloatRect m_accumulatedOverlapRegionDamage;
#endif
struct {
TransformationMatrix localTransform;
TransformationMatrix combined;
TransformationMatrix combinedForChildren;
#if USE(COORDINATED_GRAPHICS)
TransformationMatrix futureLocalTransform;
TransformationMatrix futureCombined;
TransformationMatrix futureCombinedForChildren;
#endif
} m_layerTransforms;
};
} // namespace WebCore
|