2023年12月18日发(作者:)
/* * Copyright (C) 2012 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 * * /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 ANDROID_HWUI_PATH_TESSELLATOR_H#define ANDROID_HWUI_PATH_TESSELLATOR_H#include "Matrix.h"#include "Rect.h"#include "Vertex.h"#include "VertexBuffer.h"#include #include class SkPath;class SkPaint;namespace android {namespace uirenderer {/** * Structure used for threshold values in outline path tessellation. * * TODO: PaintInfo should store one of this object, and initialized all values in constructor * depending on its type (point, line or path). */struct PathApproximationInfo { PathApproximationInfo(float invScaleX, float invScaleY, float pixelThreshold) : thresholdSquared(pixelThreshold * pixelThreshold) , sqrInvScaleX(invScaleX * invScaleX) , sqrInvScaleY(invScaleY * invScaleY) , thresholdForConicQuads(pixelThreshold * std::min(invScaleX, invScaleY) / 2.0f) { }; const float thresholdSquared; const float sqrInvScaleX; const float sqrInvScaleY; const float thresholdForConicQuads;};class PathTessellator {public: /** * Populates scaleX and scaleY with the 'tessellation scale' of the transform - the effective X * and Y scales that tessellation will take into account when generating the 1.0 pixel thick * ramp. * * Two instances of the same shape (size, paint, etc.) will only generate the same vertices if * their tessellation scales are equal. */ static void extractTessellationScales(const Matrix4& transform, float* scaleX, float* scaleY); /** * Populates a VertexBuffer with a tessellated approximation of the input convex path, as a single * triangle strip. Note: joins are not currently supported. * * @param path The path to be approximated * @param paint The paint the path will be drawn with, indicating AA, painting style * (stroke vs fill), stroke width, stroke cap & join style, etc. * @param transform The transform the path is to be drawn with, used to drive stretch-aware path * vertex approximation, and correct AA ramp offsetting. * @param vertexBuffer The output buffer */ static void tessellatePath(const SkPath& path, const SkPaint* paint, const mat4& transform, VertexBuffer& vertexBuffer);......
发布评论