summaryrefslogtreecommitdiffstats
path: root/libs/hwui/Snapshot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/Snapshot.cpp')
-rw-r--r--libs/hwui/Snapshot.cpp58
1 files changed, 51 insertions, 7 deletions
diff --git a/libs/hwui/Snapshot.cpp b/libs/hwui/Snapshot.cpp
index 6bfa203..80f7eca 100644
--- a/libs/hwui/Snapshot.cpp
+++ b/libs/hwui/Snapshot.cpp
@@ -20,6 +20,8 @@
#include <SkCanvas.h>
+#include "utils/MathUtils.h"
+
namespace android {
namespace uirenderer {
@@ -34,8 +36,8 @@ Snapshot::Snapshot()
, fbo(0)
, invisible(false)
, empty(false)
- , height(0)
- , alpha(1.0f) {
+ , alpha(1.0f)
+ , roundRectClipState(NULL) {
transform = &mTransformRoot;
clipRect = &mClipRectRoot;
region = NULL;
@@ -53,10 +55,9 @@ Snapshot::Snapshot(const sp<Snapshot>& s, int saveFlags)
, fbo(s->fbo)
, invisible(s->invisible)
, empty(false)
- , viewport(s->viewport)
- , height(s->height)
- , alpha(s->alpha) {
-
+ , alpha(s->alpha)
+ , roundRectClipState(s->roundRectClipState)
+ , mViewportData(s->mViewportData) {
if (saveFlags & SkCanvas::kMatrix_SaveFlag) {
mTransformRoot.load(*s->transform);
transform = &mTransformRoot;
@@ -206,6 +207,49 @@ void Snapshot::resetTransform(float x, float y, float z) {
}
///////////////////////////////////////////////////////////////////////////////
+// Clipping outline
+///////////////////////////////////////////////////////////////////////////////
+
+void Snapshot::setClippingOutline(LinearAllocator& allocator, const Outline* outline) {
+ Rect bounds;
+ float radius;
+ if (!outline->getAsRoundRect(&bounds, &radius)) return; // only RR supported
+
+ if (!MathUtils::isPositive(radius)) return; // leave clipping up to rect clipping
+
+ RoundRectClipState* state = new (allocator) RoundRectClipState;
+
+ // store the inverse drawing matrix
+ Matrix4 outlineDrawingMatrix;
+ outlineDrawingMatrix.load(getOrthoMatrix());
+ outlineDrawingMatrix.multiply(*transform);
+ state->matrix.loadInverse(outlineDrawingMatrix);
+
+ // compute area under rounded corners - only draws overlapping these rects need to be clipped
+ for (int i = 0 ; i < 4; i++) {
+ state->dangerRects[i] = bounds;
+ }
+ state->dangerRects[0].bottom = state->dangerRects[1].bottom = bounds.top + radius;
+ state->dangerRects[0].right = state->dangerRects[2].right = bounds.left + radius;
+ state->dangerRects[1].left = state->dangerRects[3].left = bounds.right - radius;
+ state->dangerRects[2].top = state->dangerRects[3].top = bounds.bottom - radius;
+ for (int i = 0; i < 4; i++) {
+ transform->mapRect(state->dangerRects[i]);
+
+ // round danger rects out as though they are AA geometry (since they essentially are)
+ state->dangerRects[i].snapGeometryToPixelBoundaries(true);
+ }
+
+ // store RR area
+ bounds.inset(radius);
+ state->outlineInnerRect = bounds;
+ state->outlineRadius = radius;
+
+ // store as immutable so, for this frame, pointer uniquely identifies this bundle of shader info
+ roundRectClipState = state;
+}
+
+///////////////////////////////////////////////////////////////////////////////
// Queries
///////////////////////////////////////////////////////////////////////////////
@@ -215,7 +259,7 @@ bool Snapshot::isIgnored() const {
void Snapshot::dump() const {
ALOGD("Snapshot %p, flags %x, prev %p, height %d, ignored %d, hasComplexClip %d",
- this, flags, previous.get(), height, isIgnored(), clipRegion && !clipRegion->isEmpty());
+ this, flags, previous.get(), getViewportHeight(), isIgnored(), clipRegion && !clipRegion->isEmpty());
ALOGD(" ClipRect (at %p) %.1f %.1f %.1f %.1f",
clipRect, clipRect->left, clipRect->top, clipRect->right, clipRect->bottom);
ALOGD(" Transform (at %p):", transform);