summaryrefslogtreecommitdiff
path: root/libs/hwui/CanvasState.cpp
diff options
context:
space:
mode:
author Rob Tsuk <robtsuk@google.com> 2015-01-06 13:22:54 -0800
committer Rob Tsuk <robtsuk@google.com> 2015-01-14 17:24:58 -0800
commit487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8 (patch)
tree6515f9b52f874f5f076a25df83a353de10a3da14 /libs/hwui/CanvasState.cpp
parent382d6a9ed2360ceb462ea46a60f0f106fdb52540 (diff)
Clipping performance improvements
Create a ClipArea class to handle tracking clip regions. This class can select the most efficient implementation depending on the types of clipping presented. ClipArea re-used the rectangle and region-based clipping implementations as well as adding a "list of rotated rectangles" approach that is more efficient for rotated views with children. Change-Id: I2133761a2462ebc0852b394220e265974b3086f0
Diffstat (limited to 'libs/hwui/CanvasState.cpp')
-rw-r--r--libs/hwui/CanvasState.cpp43
1 files changed, 7 insertions, 36 deletions
diff --git a/libs/hwui/CanvasState.cpp b/libs/hwui/CanvasState.cpp
index 9d2ccf17c299..85f860da4505 100644
--- a/libs/hwui/CanvasState.cpp
+++ b/libs/hwui/CanvasState.cpp
@@ -155,47 +155,18 @@ void CanvasState::concatMatrix(const Matrix4& matrix) {
///////////////////////////////////////////////////////////////////////////////
bool CanvasState::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) {
- if (CC_LIKELY(currentTransform()->rectToRect())) {
- mDirtyClip |= mSnapshot->clip(left, top, right, bottom, op);
- return !mSnapshot->clipRect->isEmpty();
- }
-
- SkPath path;
- path.addRect(left, top, right, bottom);
-
- return CanvasState::clipPath(&path, op);
+ mDirtyClip |= mSnapshot->clip(left, top, right, bottom, op);
+ return !mSnapshot->clipIsEmpty();
}
bool CanvasState::clipPath(const SkPath* path, SkRegion::Op op) {
- SkMatrix transform;
- currentTransform()->copyTo(transform);
-
- SkPath transformed;
- path->transform(transform, &transformed);
-
- SkRegion clip;
- if (!mSnapshot->previous->clipRegion->isEmpty()) {
- clip.setRegion(*mSnapshot->previous->clipRegion);
- } else {
- if (mSnapshot->previous == firstSnapshot()) {
- clip.setRect(0, 0, getWidth(), getHeight());
- } else {
- Rect* bounds = mSnapshot->previous->clipRect;
- clip.setRect(bounds->left, bounds->top, bounds->right, bounds->bottom);
- }
- }
-
- SkRegion region;
- region.setPath(transformed, clip);
-
- // region is the transformed input path, masked by the previous clip
- mDirtyClip |= mSnapshot->clipRegionTransformed(region, op);
- return !mSnapshot->clipRect->isEmpty();
+ mDirtyClip |= mSnapshot->clipPath(*path, op);
+ return !mSnapshot->clipIsEmpty();
}
bool CanvasState::clipRegion(const SkRegion* region, SkRegion::Op op) {
mDirtyClip |= mSnapshot->clipRegionTransformed(*region, op);
- return !mSnapshot->clipRect->isEmpty();
+ return !mSnapshot->clipIsEmpty();
}
void CanvasState::setClippingOutline(LinearAllocator& allocator, const Outline* outline) {
@@ -245,7 +216,7 @@ bool CanvasState::calculateQuickRejectForScissor(float left, float top,
currentTransform()->mapRect(r);
r.snapGeometryToPixelBoundaries(snapOut);
- Rect clipRect(*currentClipRect());
+ Rect clipRect(currentClipRect());
clipRect.snapToPixelBoundaries();
if (!clipRect.intersects(r)) return true;
@@ -273,7 +244,7 @@ bool CanvasState::quickRejectConservative(float left, float top,
currentTransform()->mapRect(r);
r.roundOut(); // rounded out to be conservative
- Rect clipRect(*currentClipRect());
+ Rect clipRect(currentClipRect());
clipRect.snapToPixelBoundaries();
if (!clipRect.intersects(r)) return true;