Add stagingProperties

Change-Id: Ic7de551f8843fd70a77f738e33028e25c020bb3c
diff --git a/libs/hwui/RenderProperties.cpp b/libs/hwui/RenderProperties.cpp
index 902a748..8b69b08 100644
--- a/libs/hwui/RenderProperties.cpp
+++ b/libs/hwui/RenderProperties.cpp
@@ -2,8 +2,8 @@
  * Copyright (C) 2014 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * you mPrimitiveFields.may not use this file except in compliance with the License.
+ * You mPrimitiveFields.may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -13,8 +13,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+#define LOG_TAG "OpenGLRenderer"
+
 #include "RenderProperties.h"
 
+#include <utils/Trace.h>
+
+#include <SkCanvas.h>
 #include <SkMatrix.h>
 
 #include "Matrix.h"
@@ -22,7 +28,7 @@
 namespace android {
 namespace uirenderer {
 
-RenderProperties::RenderProperties()
+RenderProperties::PrimitiveFields::PrimitiveFields()
         : mClipToBounds(true)
         , mProjectBackwards(false)
         , mProjectionReceiver(false)
@@ -32,89 +38,146 @@
         , mRotation(0), mRotationX(0), mRotationY(0)
         , mScaleX(1), mScaleY(1)
         , mPivotX(0), mPivotY(0)
-        , mCameraDistance(0)
         , mLeft(0), mTop(0), mRight(0), mBottom(0)
         , mWidth(0), mHeight(0)
         , mPrevWidth(-1), mPrevHeight(-1)
         , mPivotExplicitlySet(false)
         , mMatrixDirty(false)
         , mMatrixIsIdentity(true)
-        , mTransformMatrix(NULL)
         , mMatrixFlags(0)
-        , mTransformCamera(NULL)
-        , mTransformMatrix3D(NULL)
-        , mStaticMatrix(NULL)
-        , mAnimationMatrix(NULL)
         , mCaching(false) {
 }
 
-RenderProperties::~RenderProperties() {
+RenderProperties::ComputedFields::ComputedFields()
+        : mTransformMatrix(NULL)
+        , mTransformCamera(NULL)
+        , mTransformMatrix3D(NULL) {
+}
+
+RenderProperties::ComputedFields::~ComputedFields() {
     delete mTransformMatrix;
     delete mTransformCamera;
     delete mTransformMatrix3D;
+}
+
+RenderProperties::RenderProperties()
+        : mCameraDistance(0)
+        , mStaticMatrix(NULL)
+        , mAnimationMatrix(NULL) {
+}
+
+RenderProperties::~RenderProperties() {
     delete mStaticMatrix;
     delete mAnimationMatrix;
 }
 
-float RenderProperties::getPivotX() {
-    updateMatrix();
-    return mPivotX;
+RenderProperties& RenderProperties::operator=(const RenderProperties& other) {
+    if (this != &other) {
+        mPrimitiveFields = other.mPrimitiveFields;
+        setStaticMatrix(other.getStaticMatrix());
+        setAnimationMatrix(other.getAnimationMatrix());
+        setCameraDistance(other.getCameraDistance());
+
+        // Update the computed fields
+        updateMatrix();
+    }
+    return *this;
 }
 
-float RenderProperties::getPivotY() {
-    updateMatrix();
-    return mPivotY;
+void RenderProperties::debugOutputProperties(const int level) const {
+    if (mPrimitiveFields.mLeft != 0 || mPrimitiveFields.mTop != 0) {
+        ALOGD("%*sTranslate (left, top) %d, %d", level * 2, "", mPrimitiveFields.mLeft, mPrimitiveFields.mTop);
+    }
+    if (mStaticMatrix) {
+        ALOGD("%*sConcatMatrix (static) %p: " SK_MATRIX_STRING,
+                level * 2, "", mStaticMatrix, SK_MATRIX_ARGS(mStaticMatrix));
+    }
+    if (mAnimationMatrix) {
+        ALOGD("%*sConcatMatrix (animation) %p: " SK_MATRIX_STRING,
+                level * 2, "", mAnimationMatrix, SK_MATRIX_ARGS(mAnimationMatrix));
+    }
+    if (mPrimitiveFields.mMatrixFlags != 0) {
+        if (mPrimitiveFields.mMatrixFlags == TRANSLATION) {
+            ALOGD("%*sTranslate %.2f, %.2f, %.2f",
+                    level * 2, "", mPrimitiveFields.mTranslationX, mPrimitiveFields.mTranslationY, mPrimitiveFields.mTranslationZ);
+        } else {
+            ALOGD("%*sConcatMatrix %p: " MATRIX_4_STRING,
+                    level * 2, "", mComputedFields.mTransformMatrix, MATRIX_4_ARGS(mComputedFields.mTransformMatrix));
+        }
+    }
+
+    bool clipToBoundsNeeded = mPrimitiveFields.mCaching ? false : mPrimitiveFields.mClipToBounds;
+    if (mPrimitiveFields.mAlpha < 1) {
+        if (mPrimitiveFields.mCaching) {
+            ALOGD("%*sSetOverrideLayerAlpha %.2f", level * 2, "", mPrimitiveFields.mAlpha);
+        } else if (!mPrimitiveFields.mHasOverlappingRendering) {
+            ALOGD("%*sScaleAlpha %.2f", level * 2, "", mPrimitiveFields.mAlpha);
+        } else {
+            int flags = SkCanvas::kHasAlphaLayer_SaveFlag;
+            if (clipToBoundsNeeded) {
+                flags |= SkCanvas::kClipToLayer_SaveFlag;
+                clipToBoundsNeeded = false; // clipping done by save layer
+            }
+            ALOGD("%*sSaveLayerAlpha %.2f, %.2f, %.2f, %.2f, %d, 0x%x", level * 2, "",
+                    (float) 0, (float) 0, (float) mPrimitiveFields.mRight - mPrimitiveFields.mLeft, (float) mPrimitiveFields.mBottom - mPrimitiveFields.mTop,
+                    (int)(mPrimitiveFields.mAlpha * 255), flags);
+        }
+    }
+    if (clipToBoundsNeeded) {
+        ALOGD("%*sClipRect %.2f, %.2f, %.2f, %.2f", level * 2, "", 0.0f, 0.0f,
+                (float) mPrimitiveFields.mRight - mPrimitiveFields.mLeft, (float) mPrimitiveFields.mBottom - mPrimitiveFields.mTop);
+    }
 }
 
 void RenderProperties::updateMatrix() {
-    if (mMatrixDirty) {
-        // 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 (mPrimitiveFields.mMatrixDirty) {
+        // NOTE: mComputedFields.mTransformMatrix won't be up to date if a DisplayList goes from a complex transform
+        // to a pure translate. This is safe because the mPrimitiveFields.matrix isn't read in pure translate cases.
+        if (mPrimitiveFields.mMatrixFlags && mPrimitiveFields.mMatrixFlags != TRANSLATION) {
+            if (!mComputedFields.mTransformMatrix) {
+                // only allocate a mPrimitiveFields.matrix if we have a complex transform
+                mComputedFields.mTransformMatrix = new Matrix4();
             }
-            if (!mPivotExplicitlySet) {
-                if (mWidth != mPrevWidth || mHeight != mPrevHeight) {
-                    mPrevWidth = mWidth;
-                    mPrevHeight = mHeight;
-                    mPivotX = mPrevWidth / 2.0f;
-                    mPivotY = mPrevHeight / 2.0f;
+            if (!mPrimitiveFields.mPivotExplicitlySet) {
+                if (mPrimitiveFields.mWidth != mPrimitiveFields.mPrevWidth || mPrimitiveFields.mHeight != mPrimitiveFields.mPrevHeight) {
+                    mPrimitiveFields.mPrevWidth = mPrimitiveFields.mWidth;
+                    mPrimitiveFields.mPrevHeight = mPrimitiveFields.mHeight;
+                    mPrimitiveFields.mPivotX = mPrimitiveFields.mPrevWidth / 2.0f;
+                    mPrimitiveFields.mPivotY = mPrimitiveFields.mPrevHeight / 2.0f;
                 }
             }
 
-            if ((mMatrixFlags & ROTATION_3D) == 0) {
-                mTransformMatrix->loadTranslate(
-                        mPivotX + mTranslationX,
-                        mPivotY + mTranslationY,
+            if ((mPrimitiveFields.mMatrixFlags & ROTATION_3D) == 0) {
+                mComputedFields.mTransformMatrix->loadTranslate(
+                        mPrimitiveFields.mPivotX + mPrimitiveFields.mTranslationX,
+                        mPrimitiveFields.mPivotY + mPrimitiveFields.mTranslationY,
                         0);
-                mTransformMatrix->rotate(mRotation, 0, 0, 1);
-                mTransformMatrix->scale(mScaleX, mScaleY, 1);
-                mTransformMatrix->translate(-mPivotX, -mPivotY);
+                mComputedFields.mTransformMatrix->rotate(mPrimitiveFields.mRotation, 0, 0, 1);
+                mComputedFields.mTransformMatrix->scale(mPrimitiveFields.mScaleX, mPrimitiveFields.mScaleY, 1);
+                mComputedFields.mTransformMatrix->translate(-mPrimitiveFields.mPivotX, -mPrimitiveFields.mPivotY);
             } else {
-                if (!mTransformCamera) {
-                    mTransformCamera = new Sk3DView();
-                    mTransformMatrix3D = new SkMatrix();
+                if (!mComputedFields.mTransformCamera) {
+                    mComputedFields.mTransformCamera = new Sk3DView();
+                    mComputedFields.mTransformMatrix3D = new SkMatrix();
                 }
                 SkMatrix transformMatrix;
                 transformMatrix.reset();
-                mTransformCamera->save();
-                transformMatrix.preScale(mScaleX, mScaleY, mPivotX, mPivotY);
-                mTransformCamera->rotateX(mRotationX);
-                mTransformCamera->rotateY(mRotationY);
-                mTransformCamera->rotateZ(-mRotation);
-                mTransformCamera->getMatrix(mTransformMatrix3D);
-                mTransformMatrix3D->preTranslate(-mPivotX, -mPivotY);
-                mTransformMatrix3D->postTranslate(mPivotX + mTranslationX,
-                        mPivotY + mTranslationY);
-                transformMatrix.postConcat(*mTransformMatrix3D);
-                mTransformCamera->restore();
+                mComputedFields.mTransformCamera->save();
+                transformMatrix.preScale(mPrimitiveFields.mScaleX, mPrimitiveFields.mScaleY, mPrimitiveFields.mPivotX, mPrimitiveFields.mPivotY);
+                mComputedFields.mTransformCamera->rotateX(mPrimitiveFields.mRotationX);
+                mComputedFields.mTransformCamera->rotateY(mPrimitiveFields.mRotationY);
+                mComputedFields.mTransformCamera->rotateZ(-mPrimitiveFields.mRotation);
+                mComputedFields.mTransformCamera->getMatrix(mComputedFields.mTransformMatrix3D);
+                mComputedFields.mTransformMatrix3D->preTranslate(-mPrimitiveFields.mPivotX, -mPrimitiveFields.mPivotY);
+                mComputedFields.mTransformMatrix3D->postTranslate(mPrimitiveFields.mPivotX + mPrimitiveFields.mTranslationX,
+                        mPrimitiveFields.mPivotY + mPrimitiveFields.mTranslationY);
+                transformMatrix.postConcat(*mComputedFields.mTransformMatrix3D);
+                mComputedFields.mTransformCamera->restore();
 
-                mTransformMatrix->load(transformMatrix);
+                mComputedFields.mTransformMatrix->load(transformMatrix);
             }
         }
-        mMatrixDirty = false;
+        mPrimitiveFields.mMatrixDirty = false;
     }
 }