2 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef TransformState_h
27 #define TransformState_h
29 #include "FloatPoint.h"
30 #include "FloatQuad.h"
32 #include "TransformationMatrix.h"
33 #include <wtf/Noncopyable.h>
34 #include <wtf/PassRefPtr.h>
35 #include <wtf/OwnPtr.h>
36 #include <wtf/RefCounted.h>
40 class TransformState
: Noncopyable
{
42 enum TransformDirection
{ ApplyTransformDirection
, UnapplyInverseTransformDirection
};
43 enum TransformAccumulation
{ FlattenTransform
, AccumulateTransform
};
45 // If quad is non-null, it will be mapped
46 TransformState(TransformDirection mappingDirection
, const FloatPoint
& p
, const FloatQuad
* quad
= 0)
47 : m_lastPlanarPoint(p
)
48 , m_accumulatingTransform(false)
49 , m_mapQuad(quad
!= 0)
50 , m_direction(mappingDirection
)
53 m_lastPlanarQuad
= *quad
;
56 void move(const IntSize
& s
, TransformAccumulation accumulate
= FlattenTransform
)
58 move(s
.width(), s
.height(), accumulate
);
61 void move(int x
, int y
, TransformAccumulation
= FlattenTransform
);
62 void applyTransform(const TransformationMatrix
& transformFromContainer
, TransformAccumulation
= FlattenTransform
);
65 // Return the coords of the point or quad in the last flattened layer
66 FloatPoint
lastPlanarPoint() const { return m_lastPlanarPoint
; }
67 FloatQuad
lastPlanarQuad() const { return m_lastPlanarQuad
; }
69 // Return the point or quad mapped through the current transform
70 FloatPoint
mappedPoint() const;
71 FloatQuad
mappedQuad() const;
74 void flattenWithTransform(const TransformationMatrix
&);
76 FloatPoint m_lastPlanarPoint
;
77 FloatQuad m_lastPlanarQuad
;
79 // We only allocate the transform if we need to
80 OwnPtr
<TransformationMatrix
> m_accumulatedTransform
;
81 bool m_accumulatingTransform
;
83 TransformDirection m_direction
;
86 class HitTestingTransformState
: public RefCounted
<HitTestingTransformState
> {
88 static PassRefPtr
<HitTestingTransformState
> create(const FloatPoint
& p
, const FloatQuad
& quad
)
90 return adoptRef(new HitTestingTransformState(p
, quad
));
93 static PassRefPtr
<HitTestingTransformState
> create(const HitTestingTransformState
& other
)
95 return adoptRef(new HitTestingTransformState(other
));
98 enum TransformAccumulation
{ FlattenTransform
, AccumulateTransform
};
99 void translate(int x
, int y
, TransformAccumulation
);
100 void applyTransform(const TransformationMatrix
& transformFromContainer
, TransformAccumulation
);
102 FloatPoint
mappedPoint() const;
103 FloatQuad
mappedQuad() const;
106 FloatPoint m_lastPlanarPoint
;
107 FloatQuad m_lastPlanarQuad
;
108 TransformationMatrix m_accumulatedTransform
;
109 bool m_accumulatingTransform
;
112 HitTestingTransformState(const FloatPoint
& p
, const FloatQuad
& quad
)
113 : m_lastPlanarPoint(p
)
114 , m_lastPlanarQuad(quad
)
115 , m_accumulatingTransform(false)
119 HitTestingTransformState(const HitTestingTransformState
& other
)
120 : RefCounted
<HitTestingTransformState
>()
121 , m_lastPlanarPoint(other
.m_lastPlanarPoint
)
122 , m_lastPlanarQuad(other
.m_lastPlanarQuad
)
123 , m_accumulatedTransform(other
.m_accumulatedTransform
)
124 , m_accumulatingTransform(other
.m_accumulatingTransform
)
128 void flattenWithTransform(const TransformationMatrix
&);
131 } // namespace WebCore
133 #endif // TransformState_h