зеркало из https://github.com/mozilla/moz-skia.git
Setting perspective in fixed point.
http://codereview.appspot.com/5088043/ git-svn-id: http://skia.googlecode.com/svn/trunk@2435 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
cf385232c4
Коммит
07faed1102
|
@ -58,9 +58,9 @@ static SkString dumpMatrix(SkDumpCanvas* canvas) {
|
|||
SkScalarToFloat(m.get(SkMatrix::kMSkewX)),
|
||||
SkScalarToFloat(m.get(SkMatrix::kMSkewY)));
|
||||
str.appendf("Perspective (%0.4g, %0.4g, %0.4g) ",
|
||||
SkScalarToFloat(m.get(SkMatrix::kMPersp0)),
|
||||
SkScalarToFloat(m.get(SkMatrix::kMPersp1)),
|
||||
SkScalarToFloat(m.get(SkMatrix::kMPersp2)));
|
||||
SkScalarToFloat(SkPerspToScalar(m.get(SkMatrix::kMPersp0))),
|
||||
SkScalarToFloat(SkPerspToScalar(m.get(SkMatrix::kMPersp1))),
|
||||
SkScalarToFloat(SkPerspToScalar(m.get(SkMatrix::kMPersp2))));
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -150,4 +150,4 @@ void SkDebugDumper::dump(SkDumpCanvas* canvas, SkDumpCanvas::Verb verb,
|
|||
state->post();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ protected:
|
|||
canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
|
||||
SkMatrix mat;
|
||||
mat.reset();
|
||||
mat.setPerspY(SK_Scalar1 / 1000);
|
||||
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 1000));
|
||||
canvas->concat(mat);
|
||||
canvas->drawPaint(bkgnrd);
|
||||
canvas->restore();
|
||||
|
@ -98,8 +98,8 @@ protected:
|
|||
// draw the paths in perspective
|
||||
SkMatrix persp;
|
||||
persp.reset();
|
||||
persp.setPerspX(-SK_Scalar1 / 1800);
|
||||
persp.setPerspY(SK_Scalar1 / 500);
|
||||
persp.setPerspX(SkScalarToPersp(-SK_Scalar1 / 1800));
|
||||
persp.setPerspY(SkScalarToPersp(SK_Scalar1 / 500));
|
||||
canvas->concat(persp);
|
||||
|
||||
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
||||
|
|
|
@ -14,6 +14,16 @@
|
|||
|
||||
class SkString;
|
||||
|
||||
#ifdef SK_SCALAR_IS_FLOAT
|
||||
typedef SkScalar SkPersp;
|
||||
#define SkScalarToPersp(x) (x)
|
||||
#define SkPerspToScalar(x) (x)
|
||||
#else
|
||||
typedef SkFract SkPersp;
|
||||
#define SkScalarToPersp(x) SkFixedToFract(x)
|
||||
#define SkPerspToScalar(x) SkFractToFixed(x)
|
||||
#endif
|
||||
|
||||
/** \class SkMatrix
|
||||
|
||||
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
|
||||
|
@ -114,8 +124,8 @@ public:
|
|||
SkScalar getSkewX() const { return fMat[kMSkewX]; }
|
||||
SkScalar getTranslateX() const { return fMat[kMTransX]; }
|
||||
SkScalar getTranslateY() const { return fMat[kMTransY]; }
|
||||
SkScalar getPerspX() const { return fMat[kMPersp0]; }
|
||||
SkScalar getPerspY() const { return fMat[kMPersp1]; }
|
||||
SkPersp getPerspX() const { return fMat[kMPersp0]; }
|
||||
SkPersp getPerspY() const { return fMat[kMPersp1]; }
|
||||
|
||||
SkScalar& operator[](int index) {
|
||||
SkASSERT((unsigned)index < 9);
|
||||
|
@ -135,12 +145,12 @@ public:
|
|||
void setSkewX(SkScalar v) { this->set(kMSkewX, v); }
|
||||
void setTranslateX(SkScalar v) { this->set(kMTransX, v); }
|
||||
void setTranslateY(SkScalar v) { this->set(kMTransY, v); }
|
||||
void setPerspX(SkScalar v) { this->set(kMPersp0, v); }
|
||||
void setPerspY(SkScalar v) { this->set(kMPersp1, v); }
|
||||
void setPerspX(SkPersp v) { this->set(kMPersp0, v); }
|
||||
void setPerspY(SkPersp v) { this->set(kMPersp1, v); }
|
||||
|
||||
void setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
|
||||
SkScalar skewY, SkScalar scaleY, SkScalar transY,
|
||||
SkScalar persp0, SkScalar persp1, SkScalar persp2) {
|
||||
SkPersp persp0, SkPersp persp1, SkPersp persp2) {
|
||||
fMat[kMScaleX] = scaleX;
|
||||
fMat[kMSkewX] = skewX;
|
||||
fMat[kMTransX] = transX;
|
||||
|
|
|
@ -119,10 +119,10 @@ void SkDrawMatrix::dump(SkAnimateMaker* maker) {
|
|||
result = fMatrix.getTranslateY();
|
||||
if (result)
|
||||
SkDebugf("ty=\"%g\" ", SkScalarToFloat(result));
|
||||
result = fMatrix.getPerspX();
|
||||
result = SkPerspToScalar(fMatrix.getPerspX());
|
||||
if (result)
|
||||
SkDebugf("perspect-x=\"%g\" ", SkScalarToFloat(result));
|
||||
result = fMatrix.getPerspY();
|
||||
result = SkPerspToScalar(fMatrix.getPerspY());
|
||||
if (result)
|
||||
SkDebugf("perspect-y=\"%g\" ", SkScalarToFloat(result));
|
||||
SkDebugf("/>\n");
|
||||
|
@ -190,14 +190,9 @@ void SkDrawMatrix::onEndElement(SkAnimateMaker& ) {
|
|||
fMatrix.setSkewY(vals[3]);
|
||||
fMatrix.setScaleY(vals[4]);
|
||||
fMatrix.setTranslateY(vals[5]);
|
||||
#ifdef SK_SCALAR_IS_FIXED
|
||||
fMatrix.setPerspX(SkFixedToFract(vals[6]));
|
||||
fMatrix.setPerspY(SkFixedToFract(vals[7]));
|
||||
#else
|
||||
fMatrix.setPerspX(vals[6]);
|
||||
fMatrix.setPerspY(vals[7]);
|
||||
#endif
|
||||
// fMatrix.setPerspW(vals[8]);
|
||||
fMatrix.setPerspX(SkScalarToPersp(vals[6]));
|
||||
fMatrix.setPerspY(SkScalarToPersp(vals[7]));
|
||||
// fMatrix.setPerspW(SkScalarToPersp(vals[8]));
|
||||
goto setConcat;
|
||||
}
|
||||
if (fChildHasID == false) {
|
||||
|
@ -229,18 +224,10 @@ bool SkDrawMatrix::setProperty(int index, SkScriptValue& scriptValue) {
|
|||
fMatrix.setTranslateY((*scriptValue.fOperand.fArray)[1].fScalar);
|
||||
return true;
|
||||
case SK_PROPERTY(perspectX):
|
||||
#ifdef SK_SCALAR_IS_FIXED
|
||||
fMatrix.setPerspX(SkFixedToFract(number));
|
||||
#else
|
||||
fMatrix.setPerspX(number);
|
||||
#endif
|
||||
fMatrix.setPerspX(SkScalarToPersp((number)));
|
||||
break;
|
||||
case SK_PROPERTY(perspectY):
|
||||
#ifdef SK_SCALAR_IS_FIXED
|
||||
fMatrix.setPerspY(SkFixedToFract(number));
|
||||
#else
|
||||
fMatrix.setPerspY(number);
|
||||
#endif
|
||||
fMatrix.setPerspY(SkScalarToPersp((number)));
|
||||
break;
|
||||
case SK_PROPERTY(rotate): {
|
||||
SkMatrix temp;
|
||||
|
|
|
@ -81,12 +81,12 @@ void test_matrix_max_stretch(skiatest::Reporter* reporter) {
|
|||
|
||||
SkMatrix perspX;
|
||||
perspX.reset();
|
||||
perspX.setPerspX(SK_Scalar1 / 1000);
|
||||
perspX.setPerspX(SkScalarToPersp(SK_Scalar1 / 1000));
|
||||
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxStretch());
|
||||
|
||||
SkMatrix perspY;
|
||||
perspY.reset();
|
||||
perspY.setPerspX(-SK_Scalar1 / 500);
|
||||
perspY.setPerspX(SkScalarToPersp(-SK_Scalar1 / 500));
|
||||
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxStretch());
|
||||
|
||||
SkMatrix baseMats[] = {scale, rot90Scale, rotate,
|
||||
|
@ -234,7 +234,7 @@ void TestMatrix(skiatest::Reporter* reporter) {
|
|||
REPORTER_ASSERT(reporter, affineEqual(TransY));
|
||||
#undef affineEqual
|
||||
|
||||
mat.set(SkMatrix::kMPersp1, SkIntToScalar(1));
|
||||
mat.set(SkMatrix::kMPersp1, SkScalarToPersp(SK_Scalar1 / 2));
|
||||
REPORTER_ASSERT(reporter, !mat.asAffine(affine));
|
||||
|
||||
test_matrix_max_stretch(reporter);
|
||||
|
|
Загрузка…
Ссылка в новой задаче