Rework Outline API, remove isolatedZVolume remnants
Change-Id: I30c2fe832dcb98fa6329b1a595b3d3aafbdcad6b
diff --git a/libs/hwui/Outline.h b/libs/hwui/Outline.h
new file mode 100644
index 0000000..f42be50
--- /dev/null
+++ b/libs/hwui/Outline.h
@@ -0,0 +1,90 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OUTLINE_H
+#define OUTLINE_H
+
+#include <SkPath.h>
+
+#include "Rect.h"
+
+namespace android {
+namespace uirenderer {
+
+class Outline {
+public:
+ Outline()
+ : mShouldClip(false)
+ , mType(kOutlineType_None)
+ , mRadius(0) {}
+
+ void setRoundRect(int left, int top, int right, int bottom, int radius) {
+ mType = kOutlineType_RoundRect;
+ mBounds.set(left, top, right, bottom);
+ mRadius = radius;
+ mPath.reset();
+ mPath.addRoundRect(SkRect::MakeLTRB(left, top, right, bottom),
+ radius, radius);
+ }
+
+ void setConvexPath(const SkPath* outline) {
+ if (!outline) {
+ setEmpty();
+ return;
+ }
+ mType = kOutlineType_ConvexPath;
+ mPath = *outline;
+ mBounds.set(outline->getBounds());
+ }
+
+ void setEmpty() {
+ mType = kOutlineType_None;
+ mPath.reset();
+ }
+
+ void setShouldClip(bool clip) {
+ mShouldClip = clip;
+ }
+
+
+ bool willClip() const {
+ // only round rect outlines can be used for clipping
+ return mShouldClip && (mType == kOutlineType_RoundRect);
+ }
+
+ const SkPath* getPath() {
+ if (mType == kOutlineType_None) return NULL;
+
+ return &mPath;
+ }
+
+private:
+ enum OutlineType {
+ kOutlineType_None = 0,
+ kOutlineType_ConvexPath = 1,
+ kOutlineType_RoundRect = 2
+ };
+
+ bool mShouldClip;
+ OutlineType mType;
+ Rect mBounds;
+ float mRadius;
+ SkPath mPath;
+};
+
+} /* namespace uirenderer */
+} /* namespace android */
+
+#endif /* OUTLINE_H */
diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp
index e371590..8aed857 100644
--- a/libs/hwui/RenderNode.cpp
+++ b/libs/hwui/RenderNode.cpp
@@ -128,14 +128,14 @@
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) properties().mRight - properties().mLeft, (float) properties().mBottom - properties().mTop,
+ ALOGD("%*sSaveLayerAlpha %d, %d, %d, %d, %d, 0x%x", level * 2, "",
+ 0, 0, properties().mWidth, properties().mHeight,
(int)(properties().mAlpha * 255), flags);
}
}
if (clipToBoundsNeeded) {
- ALOGD("%*sClipRect %.2f, %.2f, %.2f, %.2f", level * 2, "", 0.0f, 0.0f,
- (float) properties().mRight - properties().mLeft, (float) properties().mBottom - properties().mTop);
+ ALOGD("%*sClipRect %d, %d, %d, %d", level * 2, "",
+ 0, 0, properties().mWidth, properties().mHeight);
}
}
@@ -185,17 +185,20 @@
}
SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
- 0, 0, properties().mRight - properties().mLeft, properties().mBottom - properties().mTop, properties().mAlpha * 255, saveFlags);
+ 0, 0, properties().mWidth, properties().mHeight,
+ properties().mAlpha * 255, saveFlags);
handler(op, PROPERTY_SAVECOUNT, properties().mClipToBounds);
}
}
if (clipToBoundsNeeded) {
- ClipRectOp* op = new (handler.allocator()) ClipRectOp(0, 0,
- properties().mRight - properties().mLeft, properties().mBottom - properties().mTop, SkRegion::kIntersect_Op);
+ ClipRectOp* op = new (handler.allocator()) ClipRectOp(
+ 0, 0, properties().mWidth, properties().mHeight, SkRegion::kIntersect_Op);
handler(op, PROPERTY_SAVECOUNT, properties().mClipToBounds);
}
- if (CC_UNLIKELY(properties().mClipToOutline && !properties().mOutline.isEmpty())) {
- ClipPathOp* op = new (handler.allocator()) ClipPathOp(&properties().mOutline, SkRegion::kIntersect_Op);
+ if (CC_UNLIKELY(properties().mOutline.willClip())) {
+ // TODO: optimize RR case
+ ClipPathOp* op = new (handler.allocator()) ClipPathOp(properties().mOutline.getPath(),
+ SkRegion::kIntersect_Op);
handler(op, PROPERTY_SAVECOUNT, properties().mClipToBounds);
}
}
@@ -443,7 +446,7 @@
DisplayListOp* shadowOp = new (alloc) DrawShadowOp(
shadowMatrixXY, shadowMatrixZ,
- caster->properties().mAlpha, &(caster->properties().mOutline),
+ caster->properties().mAlpha, caster->properties().mOutline.getPath(),
caster->properties().mWidth, caster->properties().mHeight);
handler(shadowOp, PROPERTY_SAVECOUNT, properties().mClipToBounds);
}
diff --git a/libs/hwui/RenderProperties.cpp b/libs/hwui/RenderProperties.cpp
index 233aace..902a748 100644
--- a/libs/hwui/RenderProperties.cpp
+++ b/libs/hwui/RenderProperties.cpp
@@ -26,7 +26,6 @@
: mClipToBounds(true)
, mProjectBackwards(false)
, mProjectionReceiver(false)
- , mClipToOutline(false)
, mAlpha(1)
, mHasOverlappingRendering(true)
, mTranslationX(0), mTranslationY(0), mTranslationZ(0)
@@ -47,7 +46,6 @@
, mStaticMatrix(NULL)
, mAnimationMatrix(NULL)
, mCaching(false) {
- mOutline.rewind();
}
RenderProperties::~RenderProperties() {
diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h
index 6e3b8ae..57fa4ba 100644
--- a/libs/hwui/RenderProperties.h
+++ b/libs/hwui/RenderProperties.h
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef RENDERNODEPROPERTIES_H_
-#define RENDERNODEPROPERTIES_H_
+#ifndef RENDERNODEPROPERTIES_H
+#define RENDERNODEPROPERTIES_H
#include <stddef.h>
#include <cutils/compiler.h>
@@ -22,7 +22,9 @@
#include <SkCamera.h>
#include <SkMatrix.h>
-#include <SkPath.h>
+
+#include "Rect.h"
+#include "Outline.h"
#define TRANSLATION 0x0001
#define ROTATION 0x0002
@@ -64,18 +66,6 @@
return mProjectionReceiver;
}
- void setOutline(const SkPath* outline) {
- if (!outline) {
- mOutline.reset();
- } else {
- mOutline = *outline;
- }
- }
-
- void setClipToOutline(bool clipToOutline) {
- mClipToOutline = clipToOutline;
- }
-
void setStaticMatrix(SkMatrix* matrix) {
delete mStaticMatrix;
mStaticMatrix = new SkMatrix(*matrix);
@@ -375,14 +365,18 @@
mCaching = caching;
}
- int getWidth() {
+ int getWidth() const {
return mWidth;
}
- int getHeight() {
+ int getHeight() const {
return mHeight;
}
+ Outline& outline() {
+ return mOutline;
+ }
+
private:
void onTranslationUpdate() {
mMatrixDirty = true;
@@ -396,11 +390,10 @@
void updateMatrix();
// Rendering properties
+ Outline mOutline;
bool mClipToBounds;
bool mProjectBackwards;
bool mProjectionReceiver;
- SkPath mOutline;
- bool mClipToOutline;
float mAlpha;
bool mHasOverlappingRendering;
float mTranslationX, mTranslationY, mTranslationZ;
@@ -436,4 +429,4 @@
} /* namespace uirenderer */
} /* namespace android */
-#endif /* RENDERNODEPROPERTIES_H_ */
+#endif /* RENDERNODEPROPERTIES_H */