fix warnings

code style



git-svn-id: http://skia.googlecode.com/svn/trunk@1147 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-04-18 18:47:46 +00:00
parent d5683e2caa
commit 91408cc296

View File

@ -19,12 +19,10 @@
static SkScalar SkScalarDotDiv(int count, const SkScalar a[], int step_a,
const SkScalar b[], int step_b,
SkScalar denom)
{
SkScalar denom) {
#ifdef SK_SCALAR_IS_FLOAT
float prod = 0;
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++) {
prod += a[0] * b[0];
a += step_a;
b += step_b;
@ -34,8 +32,7 @@ static SkScalar SkScalarDotDiv(int count, const SkScalar a[], int step_a,
Sk64 prod, tmp;
prod.set(0);
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++) {
tmp.setMul(a[0], b[0]);
prod.add(tmp);
a += step_a;
@ -47,12 +44,10 @@ static SkScalar SkScalarDotDiv(int count, const SkScalar a[], int step_a,
}
static SkScalar SkScalarDot(int count, const SkScalar a[], int step_a,
const SkScalar b[], int step_b)
{
const SkScalar b[], int step_b) {
#ifdef SK_SCALAR_IS_FLOAT
float prod = 0;
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++) {
prod += a[0] * b[0];
a += step_a;
b += step_b;
@ -62,8 +57,7 @@ static SkScalar SkScalarDot(int count, const SkScalar a[], int step_a,
Sk64 prod, tmp;
prod.set(0);
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++) {
tmp.setMul(a[0], b[0]);
prod.add(tmp);
a += step_a;
@ -73,18 +67,18 @@ static SkScalar SkScalarDot(int count, const SkScalar a[], int step_a,
#endif
}
//////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
SkUnitScalar SkPoint3D::normalize(SkUnit3D* unit) const
{
SkUnitScalar SkPoint3D::normalize(SkUnit3D* unit) const {
#ifdef SK_SCALAR_IS_FLOAT
float mag = sk_float_sqrt(fX*fX + fY*fY + fZ*fZ);
if (mag)
{
if (mag) {
float scale = 1.0f / mag;
unit->fX = fX * scale;
unit->fY = fY * scale;
unit->fZ = fZ * scale;
} else {
unit->fX = unit->fY = unit->fZ = 0;
}
#else
Sk64 tmp1, tmp2;
@ -96,32 +90,30 @@ SkUnitScalar SkPoint3D::normalize(SkUnit3D* unit) const
tmp1.add(tmp2);
SkFixed mag = tmp1.getSqrt();
if (mag)
{
if (mag) {
// what if mag < SK_Fixed1 ??? we will underflow the fixdiv
SkFixed scale = SkFixedDiv(SK_Fract1, mag);
unit->fX = SkFixedMul(fX, scale);
unit->fY = SkFixedMul(fY, scale);
unit->fZ = SkFixedMul(fZ, scale);
} else {
unit->fX = unit->fY = unit->fZ = 0;
}
#endif
return mag;
}
SkUnitScalar SkUnit3D::Dot(const SkUnit3D& a, const SkUnit3D& b)
{
SkUnitScalar SkUnit3D::Dot(const SkUnit3D& a, const SkUnit3D& b) {
return SkUnitScalarMul(a.fX, b.fX) +
SkUnitScalarMul(a.fY, b.fY) +
SkUnitScalarMul(a.fZ, b.fZ);
}
void SkUnit3D::Cross(const SkUnit3D& a, const SkUnit3D& b, SkUnit3D* cross)
{
void SkUnit3D::Cross(const SkUnit3D& a, const SkUnit3D& b, SkUnit3D* cross) {
SkASSERT(cross);
// use x,y,z, in case &a == cross or &b == cross
SkScalar x = SkUnitScalarMul(a.fY, b.fZ) - SkUnitScalarMul(a.fZ, b.fY);
SkScalar y = SkUnitScalarMul(a.fZ, b.fX) - SkUnitScalarMul(a.fX, b.fY);
SkScalar z = SkUnitScalarMul(a.fX, b.fY) - SkUnitScalarMul(a.fY, b.fX);
@ -129,32 +121,28 @@ void SkUnit3D::Cross(const SkUnit3D& a, const SkUnit3D& b, SkUnit3D* cross)
cross->set(x, y, z);
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
SkPatch3D::SkPatch3D()
{
SkPatch3D::SkPatch3D() {
this->reset();
}
void SkPatch3D::reset()
{
void SkPatch3D::reset() {
fOrigin.set(0, 0, 0);
fU.set(SK_Scalar1, 0, 0);
fV.set(0, -SK_Scalar1, 0);
}
void SkPatch3D::transform(const SkMatrix3D& m, SkPatch3D* dst) const
{
if (dst == NULL)
void SkPatch3D::transform(const SkMatrix3D& m, SkPatch3D* dst) const {
if (dst == NULL) {
dst = (SkPatch3D*)this;
}
m.mapVector(fU, &dst->fU);
m.mapVector(fV, &dst->fV);
m.mapPoint(fOrigin, &dst->fOrigin);
}
SkScalar SkPatch3D::dotWith(SkScalar dx, SkScalar dy, SkScalar dz) const
{
SkScalar SkPatch3D::dotWith(SkScalar dx, SkScalar dy, SkScalar dz) const {
SkScalar cx = SkScalarMul(fU.fY, fV.fZ) - SkScalarMul(fU.fZ, fV.fY);
SkScalar cy = SkScalarMul(fU.fZ, fV.fX) - SkScalarMul(fU.fX, fV.fY);
SkScalar cz = SkScalarMul(fU.fX, fV.fY) - SkScalarMul(fU.fY, fV.fX);
@ -162,24 +150,21 @@ SkScalar SkPatch3D::dotWith(SkScalar dx, SkScalar dy, SkScalar dz) const
return SkScalarMul(cx, dx) + SkScalarMul(cy, dy) + SkScalarMul(cz, dz);
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void SkMatrix3D::reset()
{
void SkMatrix3D::reset() {
memset(fMat, 0, sizeof(fMat));
fMat[0][0] = fMat[1][1] = fMat[2][2] = SK_Scalar1;
}
void SkMatrix3D::setTranslate(SkScalar x, SkScalar y, SkScalar z)
{
void SkMatrix3D::setTranslate(SkScalar x, SkScalar y, SkScalar z) {
memset(fMat, 0, sizeof(fMat));
fMat[0][0] = x;
fMat[1][1] = y;
fMat[2][2] = z;
}
void SkMatrix3D::setRotateX(SkScalar degX)
{
void SkMatrix3D::setRotateX(SkScalar degX) {
SkScalar s, c;
s = SkScalarSinCos(SkDegreesToRadians(degX), &c);
@ -188,8 +173,7 @@ void SkMatrix3D::setRotateX(SkScalar degX)
this->setRow(2, 0, s, c);
}
void SkMatrix3D::setRotateY(SkScalar degY)
{
void SkMatrix3D::setRotateY(SkScalar degY) {
SkScalar s, c;
s = SkScalarSinCos(SkDegreesToRadians(degY), &c);
@ -198,8 +182,7 @@ void SkMatrix3D::setRotateY(SkScalar degY)
this->setRow(2, s, 0, c);
}
void SkMatrix3D::setRotateZ(SkScalar degZ)
{
void SkMatrix3D::setRotateZ(SkScalar degZ) {
SkScalar s, c;
s = SkScalarSinCos(SkDegreesToRadians(degZ), &c);
@ -208,78 +191,73 @@ void SkMatrix3D::setRotateZ(SkScalar degZ)
this->setRow(2, 0, 0, SK_Scalar1);
}
void SkMatrix3D::preTranslate(SkScalar x, SkScalar y, SkScalar z)
{
void SkMatrix3D::preTranslate(SkScalar x, SkScalar y, SkScalar z) {
SkScalar col[3] = { x, y, z};
for (int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++) {
fMat[i][3] += SkScalarDot(3, &fMat[i][0], 1, col, 1);
}
}
void SkMatrix3D::preRotateX(SkScalar degX)
{
void SkMatrix3D::preRotateX(SkScalar degX) {
SkMatrix3D m;
m.setRotateX(degX);
this->setConcat(*this, m);
}
void SkMatrix3D::preRotateY(SkScalar degY)
{
void SkMatrix3D::preRotateY(SkScalar degY) {
SkMatrix3D m;
m.setRotateY(degY);
this->setConcat(*this, m);
}
void SkMatrix3D::preRotateZ(SkScalar degZ)
{
void SkMatrix3D::preRotateZ(SkScalar degZ) {
SkMatrix3D m;
m.setRotateZ(degZ);
this->setConcat(*this, m);
}
void SkMatrix3D::setConcat(const SkMatrix3D& a, const SkMatrix3D& b)
{
void SkMatrix3D::setConcat(const SkMatrix3D& a, const SkMatrix3D& b) {
SkMatrix3D tmp;
SkMatrix3D* c = this;
if (this == &a || this == &b)
if (this == &a || this == &b) {
c = &tmp;
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++)
for (int j = 0; j < 3; j++) {
c->fMat[i][j] = SkScalarDot(3, &a.fMat[i][0], 1, &b.fMat[0][j], 4);
c->fMat[i][3] = SkScalarDot(3, &a.fMat[i][0], 1, &b.fMat[0][3], 4) + a.fMat[i][3];
}
c->fMat[i][3] = SkScalarDot(3, &a.fMat[i][0], 1,
&b.fMat[0][3], 4) + a.fMat[i][3];
}
if (c == &tmp)
if (c == &tmp) {
*this = tmp;
}
}
void SkMatrix3D::mapPoint(const SkPoint3D& src, SkPoint3D* dst) const
{
void SkMatrix3D::mapPoint(const SkPoint3D& src, SkPoint3D* dst) const {
SkScalar x = SkScalarDot(3, &fMat[0][0], 1, &src.fX, 1) + fMat[0][3];
SkScalar y = SkScalarDot(3, &fMat[1][0], 1, &src.fX, 1) + fMat[1][3];
SkScalar z = SkScalarDot(3, &fMat[2][0], 1, &src.fX, 1) + fMat[2][3];
dst->set(x, y, z);
}
void SkMatrix3D::mapVector(const SkVector3D& src, SkVector3D* dst) const
{
void SkMatrix3D::mapVector(const SkVector3D& src, SkVector3D* dst) const {
SkScalar x = SkScalarDot(3, &fMat[0][0], 1, &src.fX, 1);
SkScalar y = SkScalarDot(3, &fMat[1][0], 1, &src.fX, 1);
SkScalar z = SkScalarDot(3, &fMat[2][0], 1, &src.fX, 1);
dst->set(x, y, z);
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
SkCamera3D::SkCamera3D()
{
SkCamera3D::SkCamera3D() {
this->reset();
}
void SkCamera3D::reset()
{
void SkCamera3D::reset() {
fLocation.set(0, 0, -SkIntToScalar(576)); // 8 inches backward
fAxis.set(0, 0, SK_Scalar1); // forward
fZenith.set(0, -SK_Scalar1, 0); // up
@ -289,13 +267,11 @@ void SkCamera3D::reset()
fNeedToUpdate = true;
}
void SkCamera3D::update()
{
void SkCamera3D::update() {
fNeedToUpdate = true;
}
void SkCamera3D::doUpdate() const
{
void SkCamera3D::doUpdate() const {
SkUnit3D axis, zenith, cross;
fAxis.normalize(&axis);
@ -330,10 +306,8 @@ void SkCamera3D::doUpdate() const
}
}
void SkCamera3D::patchToMatrix(const SkPatch3D& quilt, SkMatrix* matrix) const
{
if (fNeedToUpdate)
{
void SkCamera3D::patchToMatrix(const SkPatch3D& quilt, SkMatrix* matrix) const {
if (fNeedToUpdate) {
this->doUpdate();
fNeedToUpdate = false;
}
@ -366,16 +340,14 @@ void SkCamera3D::patchToMatrix(const SkPatch3D& quilt, SkMatrix* matrix) const
matrix->set(SkMatrix::kMPersp2, SK_UnitScalar1);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
Sk3DView::Sk3DView()
{
Sk3DView::Sk3DView() {
fInitialRec.fMatrix.reset();
fRec = &fInitialRec;
}
Sk3DView::~Sk3DView()
{
Sk3DView::~Sk3DView() {
Rec* rec = fRec;
while (rec != &fInitialRec) {
Rec* next = rec->fNext;
@ -384,16 +356,14 @@ Sk3DView::~Sk3DView()
}
}
void Sk3DView::save()
{
void Sk3DView::save() {
Rec* rec = SkNEW(Rec);
rec->fNext = fRec;
rec->fMatrix = fRec->fMatrix;
fRec = rec;
}
void Sk3DView::restore()
{
void Sk3DView::restore() {
SkASSERT(fRec != &fInitialRec);
Rec* next = fRec->fNext;
SkDELETE(fRec);
@ -401,8 +371,7 @@ void Sk3DView::restore()
}
#ifdef ANDROID
void Sk3DView::setCameraLocation(SkScalar x, SkScalar y, SkScalar z)
{
void Sk3DView::setCameraLocation(SkScalar x, SkScalar y, SkScalar z) {
// the camera location is passed in inches, set in pt
SkScalar lz = z * SkFloatToScalar(72.0f);
fCamera.fLocation.set(x * SkFloatToScalar(72.0f), y * SkFloatToScalar(72.0f), lz);
@ -412,37 +381,30 @@ void Sk3DView::setCameraLocation(SkScalar x, SkScalar y, SkScalar z)
}
#endif
void Sk3DView::translate(SkScalar x, SkScalar y, SkScalar z)
{
void Sk3DView::translate(SkScalar x, SkScalar y, SkScalar z) {
fRec->fMatrix.preTranslate(x, y, z);
}
void Sk3DView::rotateX(SkScalar deg)
{
void Sk3DView::rotateX(SkScalar deg) {
fRec->fMatrix.preRotateX(deg);
}
void Sk3DView::rotateY(SkScalar deg)
{
void Sk3DView::rotateY(SkScalar deg) {
fRec->fMatrix.preRotateY(deg);
}
void Sk3DView::rotateZ(SkScalar deg)
{
void Sk3DView::rotateZ(SkScalar deg) {
fRec->fMatrix.preRotateZ(deg);
}
SkScalar Sk3DView::dotWithNormal(SkScalar x, SkScalar y, SkScalar z) const
{
SkScalar Sk3DView::dotWithNormal(SkScalar x, SkScalar y, SkScalar z) const {
SkPatch3D patch;
patch.transform(fRec->fMatrix);
return patch.dotWith(x, y, z);
}
void Sk3DView::getMatrix(SkMatrix* matrix) const
{
if (matrix != NULL)
{
void Sk3DView::getMatrix(SkMatrix* matrix) const {
if (matrix != NULL) {
SkPatch3D patch;
patch.transform(fRec->fMatrix);
fCamera.patchToMatrix(patch, matrix);
@ -451,8 +413,7 @@ void Sk3DView::getMatrix(SkMatrix* matrix) const
#include "SkCanvas.h"
void Sk3DView::applyToCanvas(SkCanvas* canvas) const
{
void Sk3DView::applyToCanvas(SkCanvas* canvas) const {
SkMatrix matrix;
this->getMatrix(&matrix);