diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/DisplayList.cpp | 89 | ||||
-rw-r--r-- | libs/hwui/DisplayList.h | 11 | ||||
-rw-r--r-- | libs/hwui/DisplayListOp.h | 6 | ||||
-rw-r--r-- | libs/hwui/Matrix.h | 12 |
4 files changed, 66 insertions, 52 deletions
diff --git a/libs/hwui/DisplayList.cpp b/libs/hwui/DisplayList.cpp index ae8c189..e50ef6f 100644 --- a/libs/hwui/DisplayList.cpp +++ b/libs/hwui/DisplayList.cpp @@ -300,12 +300,13 @@ float DisplayList::getPivotY() { void DisplayList::updateMatrix() { if (mMatrixDirty) { - if (!mTransformMatrix) { - mTransformMatrix = new SkMatrix(); - } - if (mMatrixFlags == 0 || mMatrixFlags == TRANSLATION) { - mTransformMatrix->reset(); - } else { + // NOTE: mTransformMatrix won't be up to date if a DisplayList goes from a complex transform + // to a pure translate. This is safe because the matrix isn't read in pure translate cases. + if (mMatrixFlags && mMatrixFlags != TRANSLATION) { + if (!mTransformMatrix) { + // only allocate a matrix if we have a complex transform + mTransformMatrix = new Matrix4(); + } if (!mPivotExplicitlySet) { if (mWidth != mPrevWidth || mHeight != mPrevHeight) { mPrevWidth = mWidth; @@ -314,28 +315,36 @@ void DisplayList::updateMatrix() { mPivotY = mPrevHeight / 2.0f; } } - if (!Caches::getInstance().propertyEnable3d && (mMatrixFlags & ROTATION_3D) == 0) { - mTransformMatrix->setTranslate(mTranslationX, mTranslationY); - mTransformMatrix->preRotate(mRotation, mPivotX, mPivotY); - mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY); + const bool perspectiveEnabled = Caches::getInstance().propertyEnable3d; + if (!perspectiveEnabled && (mMatrixFlags & ROTATION_3D) == 0) { + mTransformMatrix->loadTranslate( + mPivotX + mTranslationX, + mPivotY + mTranslationY, + 0); + mTransformMatrix->rotate(mRotation, 0, 0, 1); + mTransformMatrix->scale(mScaleX, mScaleY, 1); + mTransformMatrix->translate(-mPivotX, -mPivotY); } else { - if (Caches::getInstance().propertyEnable3d) { - mTransform.loadTranslate(mPivotX + mTranslationX, mPivotY + mTranslationY, + if (perspectiveEnabled) { + mTransformMatrix->loadTranslate( + mPivotX + mTranslationX, + mPivotY + mTranslationY, mTranslationZ); - mTransform.rotate(mRotationX, 1, 0, 0); - mTransform.rotate(mRotationY, 0, 1, 0); - mTransform.rotate(mRotation, 0, 0, 1); - mTransform.scale(mScaleX, mScaleY, 1); - mTransform.translate(-mPivotX, -mPivotY); + mTransformMatrix->rotate(mRotationX, 1, 0, 0); + mTransformMatrix->rotate(mRotationY, 0, 1, 0); + mTransformMatrix->rotate(mRotation, 0, 0, 1); + mTransformMatrix->scale(mScaleX, mScaleY, 1); + mTransformMatrix->translate(-mPivotX, -mPivotY); } else { /* TODO: support this old transform approach, based on API level */ if (!mTransformCamera) { mTransformCamera = new Sk3DView(); mTransformMatrix3D = new SkMatrix(); } - mTransformMatrix->reset(); + SkMatrix transformMatrix; + transformMatrix.reset(); mTransformCamera->save(); - mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY); + transformMatrix.preScale(mScaleX, mScaleY, mPivotX, mPivotY); mTransformCamera->rotateX(mRotationX); mTransformCamera->rotateY(mRotationY); mTransformCamera->rotateZ(-mRotation); @@ -343,8 +352,10 @@ void DisplayList::updateMatrix() { mTransformMatrix3D->preTranslate(-mPivotX, -mPivotY); mTransformMatrix3D->postTranslate(mPivotX + mTranslationX, mPivotY + mTranslationY); - mTransformMatrix->postConcat(*mTransformMatrix3D); + transformMatrix.postConcat(*mTransformMatrix3D); mTransformCamera->restore(); + + mTransformMatrix->load(transformMatrix); } } } @@ -358,19 +369,20 @@ void DisplayList::outputViewProperties(const int level) { ALOGD("%*sTranslate (left, top) %d, %d", level * 2, "", mLeft, mTop); } if (mStaticMatrix) { - ALOGD("%*sConcatMatrix (static) %p: " MATRIX_STRING, - level * 2, "", mStaticMatrix, MATRIX_ARGS(mStaticMatrix)); + ALOGD("%*sConcatMatrix (static) %p: " SK_MATRIX_STRING, + level * 2, "", mStaticMatrix, SK_MATRIX_ARGS(mStaticMatrix)); } if (mAnimationMatrix) { - ALOGD("%*sConcatMatrix (animation) %p: " MATRIX_STRING, - level * 2, "", mAnimationMatrix, MATRIX_ARGS(mAnimationMatrix)); + ALOGD("%*sConcatMatrix (animation) %p: " SK_MATRIX_STRING, + level * 2, "", mAnimationMatrix, SK_MATRIX_ARGS(mAnimationMatrix)); } if (mMatrixFlags != 0) { if (mMatrixFlags == TRANSLATION) { - ALOGD("%*sTranslate %f, %f", level * 2, "", mTranslationX, mTranslationY); + ALOGD("%*sTranslate %.2f, %.2f, %.2f", + level * 2, "", mTranslationX, mTranslationY, mTranslationZ); } else { - ALOGD("%*sConcatMatrix %p: " MATRIX_STRING, - level * 2, "", mTransformMatrix, MATRIX_ARGS(mTransformMatrix)); + ALOGD("%*sConcatMatrix %p: " MATRIX_4_STRING, + level * 2, "", mTransformMatrix, MATRIX_4_ARGS(mTransformMatrix)); } } @@ -420,19 +432,11 @@ void DisplayList::setViewProperties(OpenGLRenderer& renderer, T& handler, renderer.concatMatrix(mAnimationMatrix); } if (mMatrixFlags != 0) { - if (Caches::getInstance().propertyEnable3d) { - if (mMatrixFlags == TRANSLATION) { - renderer.translate(mTranslationX, mTranslationY, mTranslationZ); - } else { - renderer.concatMatrix(mTransform); - } + if (mMatrixFlags == TRANSLATION) { + renderer.translate(mTranslationX, mTranslationY, + Caches::getInstance().propertyEnable3d ? mTranslationZ : 0.0f); // TODO: necessary? } else { - // avoid setting translationZ, use SkMatrix - if (mMatrixFlags == TRANSLATION) { - renderer.translate(mTranslationX, mTranslationY, 0); - } else { - renderer.concatMatrix(mTransformMatrix); - } + renderer.concatMatrix(*mTransformMatrix); } } bool clipToBoundsNeeded = mCaching ? false : mClipToBounds; @@ -483,12 +487,7 @@ void DisplayList::applyViewPropertyTransforms(mat4& matrix) { if (mMatrixFlags == TRANSLATION) { matrix.translate(mTranslationX, mTranslationY, mTranslationZ); } else { - if (Caches::getInstance().propertyEnable3d) { - matrix.multiply(mTransform); - } else { - mat4 temp(*mTransformMatrix); - matrix.multiply(temp); - } + matrix.multiply(*mTransformMatrix); } } } diff --git a/libs/hwui/DisplayList.h b/libs/hwui/DisplayList.h index 935282e..adf48d4 100644 --- a/libs/hwui/DisplayList.h +++ b/libs/hwui/DisplayList.h @@ -622,13 +622,20 @@ private: bool mPivotExplicitlySet; bool mMatrixDirty; bool mMatrixIsIdentity; + + /** + * Stores the total transformation of the DisplayList based upon its scalar + * translate/rotate/scale properties. + * + * In the common translation-only case, the matrix isn't allocated and the mTranslation + * properties are used directly. + */ + Matrix4* mTransformMatrix; uint32_t mMatrixFlags; - SkMatrix* mTransformMatrix; Sk3DView* mTransformCamera; SkMatrix* mTransformMatrix3D; SkMatrix* mStaticMatrix; SkMatrix* mAnimationMatrix; - Matrix4 mTransform; bool mCaching; /** diff --git a/libs/hwui/DisplayListOp.h b/libs/hwui/DisplayListOp.h index 20bc93d..dec796a 100644 --- a/libs/hwui/DisplayListOp.h +++ b/libs/hwui/DisplayListOp.h @@ -465,7 +465,7 @@ public: virtual void output(int level, uint32_t logFlags) const { if (mMatrix) { - OP_LOG("SetMatrix " MATRIX_STRING, MATRIX_ARGS(mMatrix)); + OP_LOG("SetMatrix " SK_MATRIX_STRING, SK_MATRIX_ARGS(mMatrix)); } else { OP_LOGS("SetMatrix (reset)"); } @@ -487,7 +487,7 @@ public: } virtual void output(int level, uint32_t logFlags) const { - OP_LOG("ConcatMatrix " MATRIX_STRING, MATRIX_ARGS(mMatrix)); + OP_LOG("ConcatMatrix " SK_MATRIX_STRING, SK_MATRIX_ARGS(mMatrix)); } virtual const char* name() { return "ConcatMatrix"; } @@ -848,7 +848,7 @@ public: } virtual void output(int level, uint32_t logFlags) const { - OP_LOG("Draw bitmap %p matrix " MATRIX_STRING, mBitmap, MATRIX_ARGS(mMatrix)); + OP_LOG("Draw bitmap %p matrix " SK_MATRIX_STRING, mBitmap, SK_MATRIX_ARGS(mMatrix)); } virtual const char* name() { return "DrawBitmapMatrix"; } diff --git a/libs/hwui/Matrix.h b/libs/hwui/Matrix.h index 00ca050..5cd79b1 100644 --- a/libs/hwui/Matrix.h +++ b/libs/hwui/Matrix.h @@ -26,12 +26,20 @@ namespace android { namespace uirenderer { -#define MATRIX_STRING "[%.2f %.2f %.2f] [%.2f %.2f %.2f] [%.2f %.2f %.2f]" -#define MATRIX_ARGS(m) \ +#define SK_MATRIX_STRING "[%.2f %.2f %.2f] [%.2f %.2f %.2f] [%.2f %.2f %.2f]" +#define SK_MATRIX_ARGS(m) \ (m)->get(0), (m)->get(1), (m)->get(2), \ (m)->get(3), (m)->get(4), (m)->get(5), \ (m)->get(6), (m)->get(7), (m)->get(8) +#define MATRIX_4_STRING "[%.2f %.2f %.2f %.2f] [%.2f %.2f %.2f %.2f]" \ + " [%.2f %.2f %.2f %.2f] [%.2f %.2f %.2f %.2f]" +#define MATRIX_4_ARGS(m) \ + (m)->data[0], (m)->data[4], (m)->data[8], (m)->data[12], \ + (m)->data[1], (m)->data[5], (m)->data[9], (m)->data[13], \ + (m)->data[2], (m)->data[6], (m)->data[10], (m)->data[14], \ + (m)->data[3], (m)->data[7], (m)->data[11], (m)->data[15] \ + /////////////////////////////////////////////////////////////////////////////// // Classes /////////////////////////////////////////////////////////////////////////////// |