Bug 1058919 - Make regions and matrix printable. r=botond

--HG--
extra : rebase_source : d881d86afbba64ba989c66fe98de89ef0a381dba
This commit is contained in:
Benoit Girard 2014-08-27 18:38:42 -04:00
Родитель 7db0e437f7
Коммит cf2697d0ae
4 изменённых файлов: 57 добавлений и 15 удалений

Просмотреть файл

@ -1113,23 +1113,25 @@ nsRect nsRegion::GetLargestRectangle (const nsRect& aContainingRect) const {
return bestRect;
}
std::ostream& operator<<(std::ostream& stream, const nsRegion& m) {
stream << "[";
int n;
pixman_box32_t *boxes = pixman_region32_rectangles(const_cast<pixman_region32_t*>(&m.mImpl), &n);
for (int i=0; i<n; i++) {
if (i != 0) {
stream << "; ";
}
stream << boxes[i].x1 << "," << boxes[i].y1 << "," << boxes[i].x2 << "," << boxes[i].y2;
}
stream << "]";
return stream;
}
nsCString
nsRegion::ToString() const {
nsCString result;
result.Append('[');
int n;
pixman_box32_t *boxes = pixman_region32_rectangles(const_cast<pixman_region32_t*>(&mImpl), &n);
for (int i=0; i<n; i++) {
if (i != 0) {
result.AppendLiteral("; ");
}
result.Append(nsPrintfCString("%d,%d,%d,%d", boxes[i].x1, boxes[i].y1, boxes[i].x2, boxes[i].y2));
}
result.Append(']');
return result;
return nsCString(mozilla::ToString(this).c_str());
}

Просмотреть файл

@ -10,6 +10,7 @@
#include <stdint.h> // for uint32_t, uint64_t
#include <sys/types.h> // for int32_t
#include "gfxCore.h" // for NS_GFX
#include "mozilla/ToString.h" // for mozilla::ToString
#include "nsCoord.h" // for nscoord
#include "nsError.h" // for nsresult
#include "nsPoint.h" // for nsIntPoint, nsPoint
@ -68,6 +69,8 @@ public:
return IsEqual(aRgn);
}
friend std::ostream& operator<<(std::ostream& stream, const nsRegion& m);
void Swap(nsRegion* aOther)
{
pixman_region32_t tmp = mImpl;
@ -462,6 +465,10 @@ public:
return IsEqual(aRgn);
}
friend std::ostream& operator<<(std::ostream& stream, const nsIntRegion& m) {
return stream << m.mImpl;
}
void Swap(nsIntRegion* aOther)
{
mImpl.Swap(&aOther->mImpl);

Просмотреть файл

@ -36,6 +36,27 @@ public:
*/
gfx3DMatrix(void);
friend std::ostream& operator<<(std::ostream& stream, const gfx3DMatrix& m) {
if (m.IsIdentity()) {
return stream << "[ I ]";
}
if (m.Is2D()) {
return stream << "["
<< m._11 << " " << m._12 << "; "
<< m._21 << " " << m._22 << "; "
<< m._41 << " " << m._42
<< "]";
}
return stream << "["
<< m._11 << " " << m._12 << " " << m._13 << " " << m._14 << "; "
<< m._21 << " " << m._22 << " " << m._23 << " " << m._24 << "; "
<< m._31 << " " << m._32 << " " << m._33 << " " << m._34 << "; "
<< m._41 << " " << m._42 << " " << m._43 << " " << m._44
<< "]";
}
/**
* Matrix multiplication.
*/

Просмотреть файл

@ -50,6 +50,18 @@ public:
_21(c), _22(d),
_31(tx), _32(ty) { }
friend std::ostream& operator<<(std::ostream& stream, const gfxMatrix& m) {
if (m.IsIdentity()) {
return stream << "[identity]";
}
return stream << "["
<< m._11 << " " << m._12
<< m._21 << " " << m._22
<< m._31 << " " << m._32
<< "]";
}
/**
* Post-multiplies m onto the matrix.
*/