Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e54f0758 authored by Chris Craik's avatar Chris Craik Committed by Android (Google) Code Review
Browse files

Merge "Cap scales used for tessellation with minimum and maximum" into lmp-dev

parents 2e597923 74cf7e6a
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -386,9 +386,6 @@ class GLES20Canvas extends HardwareCanvas {

    @Override
    public void scale(float sx, float sy) {
        // TODO: remove
        if (sx > 1000000 || sy > 1000000) throw new IllegalArgumentException("invalid scales passed " + sx + ", " + sy);

        nScale(mRenderer, sx, sy);
    }

+0 −6
Original line number Diff line number Diff line
@@ -598,9 +598,6 @@ public class RenderNode {
     * @see #getScaleX()
     */
    public boolean setScaleX(float scaleX) {
        if (scaleX > 1000000) {
            throw new IllegalArgumentException("Invalid scale: " + scaleX);
        }
        return nSetScaleX(mNativeRenderNode, scaleX);
    }

@@ -622,9 +619,6 @@ public class RenderNode {
     * @see #getScaleY()
     */
    public boolean setScaleY(float scaleY) {
        if (scaleY > 1000000) {
            throw new IllegalArgumentException("Invalid scale: " + scaleY);
        }
        return nSetScaleY(mNativeRenderNode, scaleY);
    }

+1 −6
Original line number Diff line number Diff line
@@ -58,11 +58,6 @@ namespace uirenderer {
// Defines
///////////////////////////////////////////////////////////////////////////////

#define RAD_TO_DEG (180.0f / 3.14159265f)
#define MIN_ANGLE 0.001f

#define ALPHA_THRESHOLD 0

static GLenum getFilter(const SkPaint* paint) {
    if (!paint || paint->getFilterLevel() != SkPaint::kNone_FilterLevel) {
        return GL_LINEAR;
@@ -692,7 +687,7 @@ void OpenGLRenderer::updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect
            (fboLayer && clip.isEmpty())) {
        mSnapshot->empty = fboLayer;
    } else {
        mSnapshot->invisible = mSnapshot->invisible || (alpha <= ALPHA_THRESHOLD && fboLayer);
        mSnapshot->invisible = mSnapshot->invisible || (alpha <= 0 && fboLayer);
    }
}

+14 −23
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@
#include "Matrix.h"
#include "Vector.h"
#include "Vertex.h"
#include "utils/MathUtils.h"

namespace android {
namespace uirenderer {
@@ -56,12 +57,11 @@ namespace uirenderer {
#define OUTLINE_REFINE_THRESHOLD_SQUARED (0.5f * 0.5f)
#define ROUND_CAP_THRESH 0.25f
#define PI 3.1415926535897932f
#define MAX_DEPTH 15

// temporary error thresholds
#define ERROR_DEPTH 20
#define ERROR_SCALE 1e10
#define ERROR_SQR_INV_THRESH 1e-20

/**
 * Extracts the x and y scale from the transform as positive values, and clamps them
 */
void PathTessellator::extractTessellationScales(const Matrix4& transform,
        float* scaleX, float* scaleY) {
    if (CC_LIKELY(transform.isPureTranslate())) {
@@ -72,11 +72,8 @@ void PathTessellator::extractTessellationScales(const Matrix4& transform,
        float m01 = transform.data[Matrix4::kSkewY];
        float m10 = transform.data[Matrix4::kSkewX];
        float m11 = transform.data[Matrix4::kScaleY];
        *scaleX = sqrt(m00 * m00 + m01 * m01);
        *scaleY = sqrt(m10 * m10 + m11 * m11);

        LOG_ALWAYS_FATAL_IF(*scaleX > ERROR_SCALE || *scaleY > ERROR_SCALE,
                "scales %e x %e too large for tessellation", *scaleX, *scaleY);
        *scaleX = MathUtils::clampTessellationScale(sqrt(m00 * m00 + m01 * m01));
        *scaleY = MathUtils::clampTessellationScale(sqrt(m10 * m10 + m11 * m11));
    }
}

@@ -109,8 +106,8 @@ public:
        } else {
            float scaleX, scaleY;
            PathTessellator::extractTessellationScales(transform, &scaleX, &scaleY);
            inverseScaleX = (scaleX != 0) ? (1.0f / scaleX) : 1.0f;
            inverseScaleY = (scaleY != 0) ? (1.0f / scaleY) : 1.0f;
            inverseScaleX = 1.0f / scaleX;
            inverseScaleY = 1.0f / scaleY;
        }

        if (isAA && halfStrokeWidth != 0 && inverseScaleX == inverseScaleY &&
@@ -914,9 +911,6 @@ bool PathTessellator::approximatePathOutlineVertices(const SkPath& path, bool fo
        Vector<Vertex>& outputVertices) {
    ATRACE_CALL();

    LOG_ALWAYS_FATAL_IF(sqrInvScaleX < ERROR_SQR_INV_THRESH || sqrInvScaleY < ERROR_SQR_INV_THRESH,
            "Invalid scale factors used for approx %e, %e", sqrInvScaleX, sqrInvScaleY);

    // TODO: to support joins other than sharp miter, join vertices should be labelled in the
    // perimeter, or resolved into more vertices. Reconsider forceClose-ing in that case.
    SkPath::Iter iter(path, forceClose);
@@ -975,9 +969,6 @@ void PathTessellator::recursiveCubicBezierVertices(
        float p2x, float p2y, float c2x, float c2y,
        float sqrInvScaleX, float sqrInvScaleY, float thresholdSquared,
        Vector<Vertex>& outputVertices, int depth) {
    LOG_ALWAYS_FATAL_IF(depth >= ERROR_DEPTH, "ERROR DEPTH exceeded: cubic approx, invscale %e x %e, vertcount %d",
            sqrInvScaleX, sqrInvScaleY, outputVertices.size());

    float dx = p2x - p1x;
    float dy = p2y - p1y;
    float d1 = fabs((c1x - p2x) * dy - (c1y - p2y) * dx);
@@ -985,7 +976,8 @@ void PathTessellator::recursiveCubicBezierVertices(
    float d = d1 + d2;

    // multiplying by sqrInvScaleY/X equivalent to multiplying in dimensional scale factors
    if (d * d < thresholdSquared * (dx * dx * sqrInvScaleY + dy * dy * sqrInvScaleX)) {
    if (depth >= MAX_DEPTH
            || d * d <= thresholdSquared * (dx * dx * sqrInvScaleY + dy * dy * sqrInvScaleX)) {
        // below thresh, draw line by adding endpoint
        pushToVector(outputVertices, p2x, p2y);
    } else {
@@ -1023,14 +1015,13 @@ void PathTessellator::recursiveQuadraticBezierVertices(
        float cx, float cy,
        float sqrInvScaleX, float sqrInvScaleY, float thresholdSquared,
        Vector<Vertex>& outputVertices, int depth) {
    LOG_ALWAYS_FATAL_IF(depth >= ERROR_DEPTH, "ERROR_DEPTH exceeded: quadratic approx, invscale %e x %e, vertcount %d",
            sqrInvScaleX, sqrInvScaleY, outputVertices.size());

    float dx = bx - ax;
    float dy = by - ay;
    float d = (cx - bx) * dy - (cy - by) * dx;

    if (d * d < thresholdSquared * (dx * dx * sqrInvScaleY + dy * dy * sqrInvScaleX)) {
    // multiplying by sqrInvScaleY/X equivalent to multiplying in dimensional scale factors
    if (depth >= MAX_DEPTH
            || d * d <= thresholdSquared * (dx * dx * sqrInvScaleY + dy * dy * sqrInvScaleX)) {
        // below thresh, draw line by adding endpoint
        pushToVector(outputVertices, bx, by);
    } else {
+0 −2
Original line number Diff line number Diff line
@@ -313,7 +313,6 @@ public:
    }

    bool setScaleX(float scaleX) {
        LOG_ALWAYS_FATAL_IF(scaleX > 1000000, "invalid scaleX %e", scaleX);
        return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleX, scaleX);
    }

@@ -322,7 +321,6 @@ public:
    }

    bool setScaleY(float scaleY) {
        LOG_ALWAYS_FATAL_IF(scaleY > 1000000, "invalid scaleY %e", scaleY);
        return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleY, scaleY);
    }

Loading