From fffc089fa57a1b97faa34cb2de453f8a3514aad0 Mon Sep 17 00:00:00 2001 From: Dom Date: Sun, 13 Feb 2022 21:29:21 +0800 Subject: [PATCH] Add Cap and Join enums to Stroke class. --- src/rendering/renderers/ShapeRenderer.cpp | 3 +- src/rendering/utils/TGFXTypes.cpp | 44 +++++++++++++++++++++ src/rendering/utils/TGFXTypes.h | 28 ++++++++++++++ tgfx/include/core/Stroke.h | 47 ++++++++++++++++++++--- tgfx/include/gpu/Paint.h | 8 ++-- tgfx/include/gpu/YUVTexture.h | 3 ++ tgfx/src/core/PathEffect.cpp | 14 +++---- tgfx/src/gpu/opengl/GLCanvas.cpp | 1 - 8 files changed, 130 insertions(+), 18 deletions(-) create mode 100644 src/rendering/utils/TGFXTypes.cpp create mode 100644 src/rendering/utils/TGFXTypes.h diff --git a/src/rendering/renderers/ShapeRenderer.cpp b/src/rendering/renderers/ShapeRenderer.cpp index 1ab176ea65..ecb4dd9227 100644 --- a/src/rendering/renderers/ShapeRenderer.cpp +++ b/src/rendering/renderers/ShapeRenderer.cpp @@ -27,6 +27,7 @@ #include "rendering/graphics/Graphic.h" #include "rendering/graphics/Shape.h" #include "rendering/utils/PathUtil.h" +#include "rendering/utils/TGFXTypes.h" namespace pag { @@ -47,7 +48,7 @@ enum class PaintType { Fill, Stroke, GradientFill, GradientStroke }; */ struct StrokePaint { Stroke getStroke() const { - return Stroke(strokeWidth, lineCap, lineJoin, miterLimit); + return Stroke(strokeWidth, ToTGFXCap(lineCap), ToTGFXJoin(lineJoin), miterLimit); } float strokeWidth; diff --git a/src/rendering/utils/TGFXTypes.cpp b/src/rendering/utils/TGFXTypes.cpp new file mode 100644 index 0000000000..3fb916b53a --- /dev/null +++ b/src/rendering/utils/TGFXTypes.cpp @@ -0,0 +1,44 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// 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. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "TGFXTypes.h" + +namespace pag { +Stroke::Cap ToTGFXCap(Enum cap) { + switch (cap) { + case LineCap::Round: + return Stroke::Cap::Round; + case LineCap::Square: + return Stroke::Cap::Square; + default: + return Stroke::Cap::Butt; + } +} + +Stroke::Join ToTGFXJoin(Enum join) { + switch (join) { + case LineJoin::Round: + return Stroke::Join::Round; + case LineJoin::Bevel: + return Stroke::Join::Bevel; + default: + return Stroke::Join::Miter; + } +} + +} // namespace pag diff --git a/src/rendering/utils/TGFXTypes.h b/src/rendering/utils/TGFXTypes.h new file mode 100644 index 0000000000..71d8b56f56 --- /dev/null +++ b/src/rendering/utils/TGFXTypes.h @@ -0,0 +1,28 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// 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. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "core/Stroke.h" +#include "pag/file.h" + +namespace pag { +Stroke::Cap ToTGFXCap(Enum cap); + +Stroke::Join ToTGFXJoin(Enum join); +} // namespace pag diff --git a/tgfx/include/core/Stroke.h b/tgfx/include/core/Stroke.h index 31df4a38b8..bbca542f0c 100644 --- a/tgfx/include/core/Stroke.h +++ b/tgfx/include/core/Stroke.h @@ -18,20 +18,57 @@ #pragma once -#include "pag/file.h" - namespace pag { /** * Stroke controls options applied when stroking geometries (paths, glyphs). */ class Stroke { public: + /** + * Cap draws at the beginning and end of an open path contour. + */ + enum class Cap { + /** + * No stroke extension. + */ + Butt, + /** + * Adds circle + */ + Round, + /** + * Adds square + */ + Square + }; + + /** + * Join specifies how corners are drawn when a shape is stroked. Join affects the four corners + * of a stroked rectangle, and the connected segments in a stroked path. Choose miter join to draw + * sharp corners. Choose round join to draw a circle with a radius equal to the stroke width on + * top of the corner. Choose bevel join to minimally connect the thick strokes. + */ + enum class Join { + /** + * Extends to miter limit. + */ + Miter, + /** + * Adds circle. + */ + Round, + /** + * Connects outside edges. + */ + Bevel + }; + Stroke() = default; /** * Creates a new Stroke width specified options. */ - explicit Stroke(float width, Enum cap = LineCap::Butt, Enum join = LineJoin::Miter, + explicit Stroke(float width, Cap cap = Cap::Butt, Join join = Join::Miter, float miterLimit = 4.0f) : width(width), cap(cap), join(join), miterLimit(miterLimit) { } @@ -44,12 +81,12 @@ class Stroke { /** * The geometry drawn at the beginning and end of strokes. */ - Enum cap = LineCap::Butt; + Cap cap = Cap::Butt; /** * The geometry drawn at the corners of strokes. */ - Enum join = LineJoin::Miter; + Join join = Join::Miter; /** * The limit at which a sharp corner is drawn beveled. diff --git a/tgfx/include/gpu/Paint.h b/tgfx/include/gpu/Paint.h index 6c08b48efc..de15dab5b3 100644 --- a/tgfx/include/gpu/Paint.h +++ b/tgfx/include/gpu/Paint.h @@ -110,28 +110,28 @@ class Paint { /** * Returns the geometry drawn at the beginning and end of strokes. */ - Enum getLineCap() const { + Stroke::Cap getLineCap() const { return stroke.cap; } /** * Sets the geometry drawn at the beginning and end of strokes. */ - void setLineCap(Enum cap) { + void setLineCap(Stroke::Cap cap) { stroke.cap = cap; } /** * Returns the geometry drawn at the corners of strokes. */ - Enum getLineJoin() const { + Stroke::Join getLineJoin() const { return stroke.join; } /** * Sets the geometry drawn at the corners of strokes. */ - void setLineJoin(Enum join) { + void setLineJoin(Stroke::Join join) { stroke.join = join; } diff --git a/tgfx/include/gpu/YUVTexture.h b/tgfx/include/gpu/YUVTexture.h index 6921c25580..ae82b37bd8 100644 --- a/tgfx/include/gpu/YUVTexture.h +++ b/tgfx/include/gpu/YUVTexture.h @@ -23,6 +23,9 @@ namespace pag { +/** + * YUVTexture wraps separate textures in the GPU backend for Y, U, and V planes. + */ class YUVTexture : public Texture { public: /** diff --git a/tgfx/src/core/PathEffect.cpp b/tgfx/src/core/PathEffect.cpp index eeb11e2efe..07e3d15487 100644 --- a/tgfx/src/core/PathEffect.cpp +++ b/tgfx/src/core/PathEffect.cpp @@ -18,7 +18,7 @@ #include "core/PathEffect.h" #include "core/PathRef.h" -#include "pag/file.h" +#include "core/Stroke.h" namespace pag { using namespace pk; @@ -58,22 +58,22 @@ class StrokePathEffect : public PathEffect { SkPaint paint = {}; }; -static SkPaint::Cap ToSkLineCap(Enum cap) { +static SkPaint::Cap ToSkLineCap(Stroke::Cap cap) { switch (cap) { - case LineCap::Round: + case Stroke::Cap::Round: return SkPaint::kRound_Cap; - case LineCap::Square: + case Stroke::Cap::Square: return SkPaint::kSquare_Cap; default: return SkPaint::kButt_Cap; } } -static SkPaint::Join ToSkLineJoin(Enum join) { +static SkPaint::Join ToSkLineJoin(Stroke::Join join) { switch (join) { - case LineJoin::Round: + case Stroke::Join::Round: return SkPaint::kRound_Join; - case LineJoin::Bevel: + case Stroke::Join::Bevel: return SkPaint::kBevel_Join; default: return SkPaint::kMiter_Join; diff --git a/tgfx/src/gpu/opengl/GLCanvas.cpp b/tgfx/src/gpu/opengl/GLCanvas.cpp index 66576bffef..9ce3ad8262 100644 --- a/tgfx/src/gpu/opengl/GLCanvas.cpp +++ b/tgfx/src/gpu/opengl/GLCanvas.cpp @@ -28,7 +28,6 @@ #include "gpu/ColorShader.h" #include "gpu/TextureFragmentProcessor.h" #include "gpu/TextureMaskFragmentProcessor.h" -#include "pag/file.h" namespace pag { GLCanvas::GLCanvas(Surface* surface) : Canvas(surface) {