Skip to content

Commit

Permalink
Allocate TransformationMatrix on PartitionAlloc
Browse files Browse the repository at this point in the history
TransformationMatrix needs to be 16-byte aligned on 64-bit platforms
due to use of vector instructions. PartitionAlloc has an ability to allocate
a multiple-of-16-byte object with 16-byte alignment, but Oilpan doesn't have
the ability.

So this CL changes CSSMatrix and DOMMatrixReadOnly so that they hold
TransformationMatrix via an OwnPtr, which makes sure that TransformationMatrix
is allocated on PartitionAlloc.

Patch by haraken@chromium.org, reviewed at
https://codereview.chromium.org/1361373002/
This is identical to this patch, except that the check in
checkAlignment() is done conditionally.

BUG=534853
TBR=haraken

Review URL: https://codereview.chromium.org/1359363005

Cr-Commit-Position: refs/heads/master@{#350931}
  • Loading branch information
nico authored and Commit bot committed Sep 25, 2015
1 parent 5c003ed commit 997afdd
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 138 deletions.
40 changes: 19 additions & 21 deletions third_party/WebKit/Source/core/css/CSSMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::create(ExecutionContext* executionC
}

CSSMatrix::CSSMatrix(const TransformationMatrix& m)
: m_matrix(m)
: m_matrix(adoptPtr(new TransformationMatrix(m)))
{
}

CSSMatrix::CSSMatrix(const String& s, ExceptionState& exceptionState)
: m_matrix(adoptPtr(new TransformationMatrix))
{
setMatrixValue(s, exceptionState);
}
Expand Down Expand Up @@ -82,11 +83,8 @@ void CSSMatrix::setMatrixValue(const String& string, ExceptionState& exceptionSt
// if a param has a percentage ('%')
if (operations.dependsOnBoxSize())
exceptionState.throwDOMException(SyntaxError, "The transformation depends on the box size, which is not supported.");
TransformationMatrix t;
operations.apply(FloatSize(0, 0), t);

// set the matrix
m_matrix = t;
m_matrix = adoptPtr(new TransformationMatrix);
operations.apply(FloatSize(0, 0), *m_matrix);
} else { // There is something there but parsing failed.
exceptionState.throwDOMException(SyntaxError, "Failed to parse '" + string + "'.");
}
Expand All @@ -98,17 +96,17 @@ PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::multiply(CSSMatrix* secondMatrix) c
if (!secondMatrix)
return nullptr;

return CSSMatrix::create(TransformationMatrix(m_matrix).multiply(secondMatrix->m_matrix));
return CSSMatrix::create(TransformationMatrix(*m_matrix).multiply(*secondMatrix->m_matrix));
}

PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::inverse(ExceptionState& exceptionState) const
{
if (!m_matrix.isInvertible()) {
if (!m_matrix->isInvertible()) {
exceptionState.throwDOMException(NotSupportedError, "The matrix is not invertable.");
return nullptr;
}

return CSSMatrix::create(m_matrix.inverse());
return CSSMatrix::create(m_matrix->inverse());
}

PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::translate(double x, double y, double z) const
Expand All @@ -119,7 +117,7 @@ PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::translate(double x, double y, doubl
y = 0;
if (std::isnan(z))
z = 0;
return CSSMatrix::create(TransformationMatrix(m_matrix).translate3d(x, y, z));
return CSSMatrix::create(TransformationMatrix(*m_matrix).translate3d(x, y, z));
}

PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::scale(double scaleX, double scaleY, double scaleZ) const
Expand All @@ -130,7 +128,7 @@ PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::scale(double scaleX, double scaleY,
scaleY = scaleX;
if (std::isnan(scaleZ))
scaleZ = 1;
return CSSMatrix::create(TransformationMatrix(m_matrix).scale3d(scaleX, scaleY, scaleZ));
return CSSMatrix::create(TransformationMatrix(*m_matrix).scale3d(scaleX, scaleY, scaleZ));
}

PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::rotate(double rotX, double rotY, double rotZ) const
Expand All @@ -148,7 +146,7 @@ PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::rotate(double rotX, double rotY, do
rotY = 0;
if (std::isnan(rotZ))
rotZ = 0;
return CSSMatrix::create(TransformationMatrix(m_matrix).rotate3d(rotX, rotY, rotZ));
return CSSMatrix::create(TransformationMatrix(*m_matrix).rotate3d(rotX, rotY, rotZ));
}

PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::rotateAxisAngle(double x, double y, double z, double angle) const
Expand All @@ -163,33 +161,33 @@ PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::rotateAxisAngle(double x, double y,
angle = 0;
if (!x && !y && !z)
z = 1;
return CSSMatrix::create(TransformationMatrix(m_matrix).rotate3d(x, y, z, angle));
return CSSMatrix::create(TransformationMatrix(*m_matrix).rotate3d(x, y, z, angle));
}

PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::skewX(double angle) const
{
if (std::isnan(angle))
angle = 0;
return CSSMatrix::create(TransformationMatrix(m_matrix).skewX(angle));
return CSSMatrix::create(TransformationMatrix(*m_matrix).skewX(angle));
}

PassRefPtrWillBeRawPtr<CSSMatrix> CSSMatrix::skewY(double angle) const
{
if (std::isnan(angle))
angle = 0;
return CSSMatrix::create(TransformationMatrix(m_matrix).skewY(angle));
return CSSMatrix::create(TransformationMatrix(*m_matrix).skewY(angle));
}

String CSSMatrix::toString() const
{
// FIXME - Need to ensure valid CSS floating point values (https://bugs.webkit.org/show_bug.cgi?id=20674)
if (m_matrix.isAffine())
return String::format("matrix(%f, %f, %f, %f, %f, %f)", m_matrix.a(), m_matrix.b(), m_matrix.c(), m_matrix.d(), m_matrix.e(), m_matrix.f());
if (m_matrix->isAffine())
return String::format("matrix(%f, %f, %f, %f, %f, %f)", m_matrix->a(), m_matrix->b(), m_matrix->c(), m_matrix->d(), m_matrix->e(), m_matrix->f());
return String::format("matrix3d(%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f)",
m_matrix.m11(), m_matrix.m12(), m_matrix.m13(), m_matrix.m14(),
m_matrix.m21(), m_matrix.m22(), m_matrix.m23(), m_matrix.m24(),
m_matrix.m31(), m_matrix.m32(), m_matrix.m33(), m_matrix.m34(),
m_matrix.m41(), m_matrix.m42(), m_matrix.m43(), m_matrix.m44());
m_matrix->m11(), m_matrix->m12(), m_matrix->m13(), m_matrix->m14(),
m_matrix->m21(), m_matrix->m22(), m_matrix->m23(), m_matrix->m24(),
m_matrix->m31(), m_matrix->m32(), m_matrix->m33(), m_matrix->m34(),
m_matrix->m41(), m_matrix->m42(), m_matrix->m43(), m_matrix->m44());
}

} // namespace blink
104 changes: 54 additions & 50 deletions third_party/WebKit/Source/core/css/CSSMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace blink {
class ExceptionState;
class ExecutionContext;

class CSSMatrix final : public RefCountedWillBeGarbageCollected<CSSMatrix>, public ScriptWrappable {
class CSSMatrix final : public RefCountedWillBeGarbageCollectedFinalized<CSSMatrix>, public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtrWillBeRawPtr<CSSMatrix> create(const TransformationMatrix& m)
Expand All @@ -45,53 +45,53 @@ class CSSMatrix final : public RefCountedWillBeGarbageCollected<CSSMatrix>, publ
}
static PassRefPtrWillBeRawPtr<CSSMatrix> create(ExecutionContext*, const String&, ExceptionState&);

double a() const { return m_matrix.a(); }
double b() const { return m_matrix.b(); }
double c() const { return m_matrix.c(); }
double d() const { return m_matrix.d(); }
double e() const { return m_matrix.e(); }
double f() const { return m_matrix.f(); }

void setA(double f) { m_matrix.setA(f); }
void setB(double f) { m_matrix.setB(f); }
void setC(double f) { m_matrix.setC(f); }
void setD(double f) { m_matrix.setD(f); }
void setE(double f) { m_matrix.setE(f); }
void setF(double f) { m_matrix.setF(f); }

double m11() const { return m_matrix.m11(); }
double m12() const { return m_matrix.m12(); }
double m13() const { return m_matrix.m13(); }
double m14() const { return m_matrix.m14(); }
double m21() const { return m_matrix.m21(); }
double m22() const { return m_matrix.m22(); }
double m23() const { return m_matrix.m23(); }
double m24() const { return m_matrix.m24(); }
double m31() const { return m_matrix.m31(); }
double m32() const { return m_matrix.m32(); }
double m33() const { return m_matrix.m33(); }
double m34() const { return m_matrix.m34(); }
double m41() const { return m_matrix.m41(); }
double m42() const { return m_matrix.m42(); }
double m43() const { return m_matrix.m43(); }
double m44() const { return m_matrix.m44(); }

void setM11(double f) { m_matrix.setM11(f); }
void setM12(double f) { m_matrix.setM12(f); }
void setM13(double f) { m_matrix.setM13(f); }
void setM14(double f) { m_matrix.setM14(f); }
void setM21(double f) { m_matrix.setM21(f); }
void setM22(double f) { m_matrix.setM22(f); }
void setM23(double f) { m_matrix.setM23(f); }
void setM24(double f) { m_matrix.setM24(f); }
void setM31(double f) { m_matrix.setM31(f); }
void setM32(double f) { m_matrix.setM32(f); }
void setM33(double f) { m_matrix.setM33(f); }
void setM34(double f) { m_matrix.setM34(f); }
void setM41(double f) { m_matrix.setM41(f); }
void setM42(double f) { m_matrix.setM42(f); }
void setM43(double f) { m_matrix.setM43(f); }
void setM44(double f) { m_matrix.setM44(f); }
double a() const { return m_matrix->a(); }
double b() const { return m_matrix->b(); }
double c() const { return m_matrix->c(); }
double d() const { return m_matrix->d(); }
double e() const { return m_matrix->e(); }
double f() const { return m_matrix->f(); }

void setA(double f) { m_matrix->setA(f); }
void setB(double f) { m_matrix->setB(f); }
void setC(double f) { m_matrix->setC(f); }
void setD(double f) { m_matrix->setD(f); }
void setE(double f) { m_matrix->setE(f); }
void setF(double f) { m_matrix->setF(f); }

double m11() const { return m_matrix->m11(); }
double m12() const { return m_matrix->m12(); }
double m13() const { return m_matrix->m13(); }
double m14() const { return m_matrix->m14(); }
double m21() const { return m_matrix->m21(); }
double m22() const { return m_matrix->m22(); }
double m23() const { return m_matrix->m23(); }
double m24() const { return m_matrix->m24(); }
double m31() const { return m_matrix->m31(); }
double m32() const { return m_matrix->m32(); }
double m33() const { return m_matrix->m33(); }
double m34() const { return m_matrix->m34(); }
double m41() const { return m_matrix->m41(); }
double m42() const { return m_matrix->m42(); }
double m43() const { return m_matrix->m43(); }
double m44() const { return m_matrix->m44(); }

void setM11(double f) { m_matrix->setM11(f); }
void setM12(double f) { m_matrix->setM12(f); }
void setM13(double f) { m_matrix->setM13(f); }
void setM14(double f) { m_matrix->setM14(f); }
void setM21(double f) { m_matrix->setM21(f); }
void setM22(double f) { m_matrix->setM22(f); }
void setM23(double f) { m_matrix->setM23(f); }
void setM24(double f) { m_matrix->setM24(f); }
void setM31(double f) { m_matrix->setM31(f); }
void setM32(double f) { m_matrix->setM32(f); }
void setM33(double f) { m_matrix->setM33(f); }
void setM34(double f) { m_matrix->setM34(f); }
void setM41(double f) { m_matrix->setM41(f); }
void setM42(double f) { m_matrix->setM42(f); }
void setM43(double f) { m_matrix->setM43(f); }
void setM44(double f) { m_matrix->setM44(f); }

void setMatrixValue(const String&, ExceptionState&);

Expand Down Expand Up @@ -142,7 +142,7 @@ class CSSMatrix final : public RefCountedWillBeGarbageCollected<CSSMatrix>, publ
// the skew values on the left (result = skewY(angle) * this)
PassRefPtrWillBeRawPtr<CSSMatrix> skewY(double angle) const;

const TransformationMatrix& transform() const { return m_matrix; }
const TransformationMatrix& transform() const { return *m_matrix; }

String toString() const;

Expand All @@ -152,7 +152,11 @@ class CSSMatrix final : public RefCountedWillBeGarbageCollected<CSSMatrix>, publ
CSSMatrix(const TransformationMatrix&);
CSSMatrix(const String&, ExceptionState&);

TransformationMatrix m_matrix;
// TransformationMatrix needs to be 16-byte aligned. PartitionAlloc
// supports 16-byte alignment but Oilpan doesn't. So we use an OwnPtr
// to allocate TransformationMatrix on PartitionAlloc.
// TODO(oilpan): Oilpan should support 16-byte aligned allocations.
OwnPtr<TransformationMatrix> m_matrix;
};

} // namespace blink
Expand Down
16 changes: 9 additions & 7 deletions third_party/WebKit/Source/core/dom/DOMMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other)

DOMMatrix::DOMMatrix(const TransformationMatrix& matrix, bool is2D)
{
m_matrix = matrix;
m_matrix = adoptPtr(new TransformationMatrix(matrix));
m_is2D = is2D;
}

Expand All @@ -34,7 +34,8 @@ DOMMatrix* DOMMatrix::multiplySelf(DOMMatrix* other)
if (!other->is2D())
m_is2D = false;

m_matrix = m_matrix * other->matrix();
TransformationMatrix& matrix = *m_matrix;
*m_matrix = matrix * other->matrix();

return this;
}
Expand All @@ -44,7 +45,8 @@ DOMMatrix* DOMMatrix::preMultiplySelf(DOMMatrix* other)
if (!other->is2D())
m_is2D = false;

m_matrix = other->matrix() * m_matrix;
TransformationMatrix& matrix = *m_matrix;
*m_matrix = other->matrix() * matrix;

return this;
}
Expand All @@ -58,9 +60,9 @@ DOMMatrix* DOMMatrix::translateSelf(double tx, double ty, double tz)
m_is2D = false;

if (m_is2D)
m_matrix.translate(tx, ty);
m_matrix->translate(tx, ty);
else
m_matrix.translate3d(tx, ty, tz);
m_matrix->translate3d(tx, ty, tz);

return this;
}
Expand Down Expand Up @@ -90,9 +92,9 @@ DOMMatrix* DOMMatrix::scaleNonUniformSelf(double sx, double sy, double sz,
translateSelf(ox, oy, oz);

if (m_is2D)
m_matrix.scaleNonUniform(sx, sy);
m_matrix->scaleNonUniform(sx, sy);
else
m_matrix.scale3d(sx, sy, sz);
m_matrix->scale3d(sx, sy, sz);

if (hasTranslation)
translateSelf(-ox, -oy, -oz);
Expand Down
46 changes: 23 additions & 23 deletions third_party/WebKit/Source/core/dom/DOMMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ class DOMMatrix : public DOMMatrixReadOnly {
static DOMMatrix* create();
static DOMMatrix* create(DOMMatrixReadOnly*);

void setA(double value) { m_matrix.setM11(value); }
void setB(double value) { m_matrix.setM12(value); }
void setC(double value) { m_matrix.setM21(value); }
void setD(double value) { m_matrix.setM22(value); }
void setE(double value) { m_matrix.setM41(value); }
void setF(double value) { m_matrix.setM42(value); }

void setM11(double value) { m_matrix.setM11(value); }
void setM12(double value) { m_matrix.setM12(value); }
void setM13(double value) { m_matrix.setM13(value); setIs2D(!value); }
void setM14(double value) { m_matrix.setM14(value); setIs2D(!value); }
void setM21(double value) { m_matrix.setM21(value); }
void setM22(double value) { m_matrix.setM22(value); }
void setM23(double value) { m_matrix.setM23(value); setIs2D(!value); }
void setM24(double value) { m_matrix.setM24(value); setIs2D(!value); }
void setM31(double value) { m_matrix.setM31(value); setIs2D(!value); }
void setM32(double value) { m_matrix.setM32(value); setIs2D(!value); }
void setM33(double value) { m_matrix.setM33(value); setIs2D(value != 1); }
void setM34(double value) { m_matrix.setM34(value); setIs2D(!value); }
void setM41(double value) { m_matrix.setM41(value); }
void setM42(double value) { m_matrix.setM42(value); }
void setM43(double value) { m_matrix.setM43(value); setIs2D(!value); }
void setM44(double value) { m_matrix.setM44(value); setIs2D(value != 1); }
void setA(double value) { m_matrix->setM11(value); }
void setB(double value) { m_matrix->setM12(value); }
void setC(double value) { m_matrix->setM21(value); }
void setD(double value) { m_matrix->setM22(value); }
void setE(double value) { m_matrix->setM41(value); }
void setF(double value) { m_matrix->setM42(value); }

void setM11(double value) { m_matrix->setM11(value); }
void setM12(double value) { m_matrix->setM12(value); }
void setM13(double value) { m_matrix->setM13(value); setIs2D(!value); }
void setM14(double value) { m_matrix->setM14(value); setIs2D(!value); }
void setM21(double value) { m_matrix->setM21(value); }
void setM22(double value) { m_matrix->setM22(value); }
void setM23(double value) { m_matrix->setM23(value); setIs2D(!value); }
void setM24(double value) { m_matrix->setM24(value); setIs2D(!value); }
void setM31(double value) { m_matrix->setM31(value); setIs2D(!value); }
void setM32(double value) { m_matrix->setM32(value); setIs2D(!value); }
void setM33(double value) { m_matrix->setM33(value); setIs2D(value != 1); }
void setM34(double value) { m_matrix->setM34(value); setIs2D(!value); }
void setM41(double value) { m_matrix->setM41(value); }
void setM42(double value) { m_matrix->setM42(value); }
void setM43(double value) { m_matrix->setM43(value); setIs2D(!value); }
void setM44(double value) { m_matrix->setM44(value); setIs2D(value != 1); }

DOMMatrix* multiplySelf(DOMMatrix*);
DOMMatrix* preMultiplySelf(DOMMatrix*);
Expand Down
18 changes: 9 additions & 9 deletions third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool DOMMatrixReadOnly::is2D() const

bool DOMMatrixReadOnly::isIdentity() const
{
return m_matrix.isIdentity();
return m_matrix->isIdentity();
}

DOMMatrix* DOMMatrixReadOnly::multiply(DOMMatrix* other)
Expand Down Expand Up @@ -46,10 +46,10 @@ DOMMatrix* DOMMatrixReadOnly::scaleNonUniform(double sx, double sy, double sz,
PassRefPtr<DOMFloat32Array> DOMMatrixReadOnly::toFloat32Array() const
{
float array[] = {
static_cast<float>(m_matrix.m11()), static_cast<float>(m_matrix.m12()), static_cast<float>(m_matrix.m13()), static_cast<float>(m_matrix.m14()),
static_cast<float>(m_matrix.m21()), static_cast<float>(m_matrix.m22()), static_cast<float>(m_matrix.m23()), static_cast<float>(m_matrix.m24()),
static_cast<float>(m_matrix.m31()), static_cast<float>(m_matrix.m32()), static_cast<float>(m_matrix.m33()), static_cast<float>(m_matrix.m34()),
static_cast<float>(m_matrix.m41()), static_cast<float>(m_matrix.m42()), static_cast<float>(m_matrix.m43()), static_cast<float>(m_matrix.m44())
static_cast<float>(m_matrix->m11()), static_cast<float>(m_matrix->m12()), static_cast<float>(m_matrix->m13()), static_cast<float>(m_matrix->m14()),
static_cast<float>(m_matrix->m21()), static_cast<float>(m_matrix->m22()), static_cast<float>(m_matrix->m23()), static_cast<float>(m_matrix->m24()),
static_cast<float>(m_matrix->m31()), static_cast<float>(m_matrix->m32()), static_cast<float>(m_matrix->m33()), static_cast<float>(m_matrix->m34()),
static_cast<float>(m_matrix->m41()), static_cast<float>(m_matrix->m42()), static_cast<float>(m_matrix->m43()), static_cast<float>(m_matrix->m44())
};

return DOMFloat32Array::create(array, 16);
Expand All @@ -58,10 +58,10 @@ PassRefPtr<DOMFloat32Array> DOMMatrixReadOnly::toFloat32Array() const
PassRefPtr<DOMFloat64Array> DOMMatrixReadOnly::toFloat64Array() const
{
double array[] = {
m_matrix.m11(), m_matrix.m12(), m_matrix.m13(), m_matrix.m14(),
m_matrix.m21(), m_matrix.m22(), m_matrix.m23(), m_matrix.m24(),
m_matrix.m31(), m_matrix.m32(), m_matrix.m33(), m_matrix.m34(),
m_matrix.m41(), m_matrix.m42(), m_matrix.m43(), m_matrix.m44()
m_matrix->m11(), m_matrix->m12(), m_matrix->m13(), m_matrix->m14(),
m_matrix->m21(), m_matrix->m22(), m_matrix->m23(), m_matrix->m24(),
m_matrix->m31(), m_matrix->m32(), m_matrix->m33(), m_matrix->m34(),
m_matrix->m41(), m_matrix->m42(), m_matrix->m43(), m_matrix->m44()
};

return DOMFloat64Array::create(array, 16);
Expand Down
Loading

0 comments on commit 997afdd

Please sign in to comment.