Skip to content

Commit

Permalink
Update headers + lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhonnyg committed Jan 15, 2025
1 parent d20844b commit 92aa76e
Show file tree
Hide file tree
Showing 26 changed files with 177 additions and 69 deletions.
2 changes: 1 addition & 1 deletion defold-rive/include/rive/artboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class Artboard : public ArtboardBase, public CoreContext
void setDataContextFromInstance(ViewModelInstance* viewModelInstance);
void addDataBind(DataBind* dataBind);
void populateDataBinds(std::vector<DataBind*>* dataBinds);
void sortDataBinds(std::vector<DataBind*> dataBinds);
void sortDataBinds();
void collectDataBinds();

bool hasAudio() const;
Expand Down
3 changes: 3 additions & 0 deletions defold-rive/include/rive/data_bind/data_bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class DataBind : public DataBindBase
DataConverter* converter() const { return m_dataConverter; };
void converter(DataConverter* value) { m_dataConverter = value; };
ViewModelInstanceValue* source() const { return m_Source; };
bool toSource();
bool toTarget();

protected:
ComponentDirt m_Dirt = ComponentDirt::Filthy;
Expand All @@ -40,6 +42,7 @@ class DataBind : public DataBindBase
DataBindContextValue* m_ContextValue = nullptr;
DataConverter* m_dataConverter = nullptr;
DataType outputType();
bool bindsOnce();
#ifdef WITH_RIVE_TOOLS
public:
void onChanged(DataBindChanged callback) { m_changedCallback = callback; }
Expand Down
1 change: 1 addition & 0 deletions defold-rive/include/rive/layout_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class LayoutComponent : public LayoutComponentBase,
void positionTypeChanged();
void scaleTypeChanged();
void displayChanged();
void flexDirectionChanged();
#endif
void buildDependencies() override;

Expand Down
126 changes: 126 additions & 0 deletions defold-rive/include/rive/math/bezier_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright 2021 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Initial import from skia:src/gpu/tessellate/Tessellation.h
* skia:src/core/SkGeometry.h
*
* Copyright 2022 Rive
*/

#pragma once

#include "rive/math/simd.hpp"
#include "rive/math/vec2d.hpp"
#include <math.h>

namespace rive
{
namespace math
{
// Decides the number of polar segments the tessellator adds for each curve.
// (Uniform steps in tangent angle.) The tessellator will add this number of
// polar segments for each radian of rotation in local path space.
template <int Precision>
float calc_polar_segments_per_radian(float approxDevStrokeRadius)
{
float cosTheta = 1.f - (1.f / Precision) / approxDevStrokeRadius;
return .5f / acosf(std::max(cosTheta, -1.f));
}

Vec2D eval_cubic_at(const Vec2D p[4], float t);

// Given a src cubic bezier, chop it at the specified t value,
// where 0 <= t <= 1, and return the two new cubics in dst:
// dst[0..3] and dst[3..6]
void chop_cubic_at(const Vec2D src[4], Vec2D dst[7], float t);

// Given a src cubic bezier, chop it at the specified t0 and t1 values,
// where 0 <= t0 <= t1 <= 1, and return the three new cubics in dst:
// dst[0..3], dst[3..6], and dst[6..9]
void chop_cubic_at(const Vec2D src[4], Vec2D dst[10], float t0, float t1);

// Given a src cubic bezier, chop it at the specified t values,
// where 0 <= t0 <= t1 <= ... <= 1, and return the new cubics in dst:
// dst[0..3],dst[3..6],...,dst[3*t_count..3*(t_count+1)]
void chop_cubic_at(const Vec2D src[4],
Vec2D dst[],
const float tValues[],
int tCount);

// Measures the angle between two vectors, in the range [0, pi].
float measure_angle_between_vectors(Vec2D a, Vec2D b);

// Returns 0, 1, or 2 T values at which to chop the given curve in order to
// guarantee the resulting cubics are convex and rotate no more than 180
// degrees.
//
// - If the cubic is "serpentine", then the T values are any inflection points
// in [0 < T < 1].
// - If the cubic is linear, then the T values are any 180-degree cusp points
// in [0 < T < 1].
// - Otherwise the T value is the point at which rotation reaches 180 degrees,
// iff in [0 < T < 1].
//
// 'areCusps' is set to true if the chop point occurred at a cusp (within
// tolerance), or if the chop point(s) occurred at 180-degree turnaround points
// on a degenerate flat line.
int find_cubic_convex_180_chops(const Vec2D[], float T[2], bool* areCusps);

// Optimized SIMD helper for evaluating a single cubic at many points.
class EvalCubic
{
public:
inline EvalCubic(const Vec2D pts[])
{
// Cubic power-basis form:
//
// | 1 0 0 0| |P0|
// Cubic(T) = x,y = |1 t t^2 t^3| * |-3 3 0 0| * |P1|
// | 3 -6 3 0| |P2|
// |-1 3 -3 1| |P3|
//
// Find the cubic's power basis coefficients. These define the bezier
// curve as:
//
// |t^3|
// Cubic(T) = x,y = |A B C| * |t^2| + P0
// |. . .| |t |
//
// (Duplicate coefficients across a float4 so we can evaluate two at
// once.)
m_P0 = simd::load2f(pts + 0).xyxy;
float4 P1 = simd::load2f(pts + 1).xyxy;
float4 P2 = simd::load2f(pts + 2).xyxy;
float4 P3 = simd::load2f(pts + 3).xyxy;
m_C = 3.f * (P1 - m_P0);
float4 D = 3.f * (P2 - P1);
float4 E = P3 - m_P0;
m_B = D - m_C;
m_A = E - D;
}

// Evaluates [x, y] at location t.
inline float2 operator()(float t) const
{
// At^3 + Bt^2 + Ct + P0
return t * (t * (t * m_A.xy + m_B.xy) + m_C.xy) + m_P0.xy;
}

// Evaluates [Xa, Ya, Xb, Yb] at locations [Ta, Ta, Tb, Tb].
inline float4 operator()(float4 t) const
{
// At^3 + Bt^2 + Ct + P0
return t * (t * (t * m_A + m_B) + m_C) + m_P0;
}

private:
float4 m_A;
float4 m_B;
float4 m_C;
float4 m_P0;
};
} // namespace math
} // namespace rive
1 change: 1 addition & 0 deletions defold-rive/include/rive/math/path_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class FillRule
{
nonZero,
evenOdd,
clockwise,
};

enum class PathDirection
Expand Down
1 change: 1 addition & 0 deletions defold-rive/include/rive/nested_artboard_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class NestedArtboardLayout : public NestedArtboardLayoutBase
#endif
Core* clone() const override;
void markNestedLayoutDirty();
void markLayoutNodeDirty();
void update(ComponentDirt value) override;
StatusCode onAddedClean(CoreContext* context) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ class RenderContextD3DImpl : public RenderContextHelperImpl
gpu::StorageBufferStructure) override;
std::unique_ptr<BufferRing> makeVertexBufferRing(
size_t capacityInBytes) override;
std::unique_ptr<BufferRing> makeTextureTransferBufferRing(
size_t capacityInBytes) override;

void resizeGradientTexture(uint32_t width, uint32_t height) override;
void resizeTessellationTexture(uint32_t width, uint32_t height) override;
Expand Down
3 changes: 0 additions & 3 deletions defold-rive/include/rive/renderer/draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ class RiveRenderPathDraw : public Draw
gpu::InterlockMode);

const Gradient* gradient() const { return m_gradientRef; }
FillRule fillRule() const { return m_fillRule; }
gpu::PaintType paintType() const { return m_paintType; }
float strokeRadius() const { return m_strokeRadius; }
gpu::ContourDirections contourDirections() const
Expand Down Expand Up @@ -310,8 +309,6 @@ class RiveRenderPathDraw : public Draw

const RiveRenderPath* const m_pathRef;
const Gradient* m_gradientRef;
const FillRule m_fillRule; // Bc RiveRenderPath fillRule can mutate during
// the artboard draw process.
const gpu::PaintType m_paintType;
float m_strokeRadius = 0;
gpu::ContourDirections m_contourDirections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ class RenderContextGLImpl : public RenderContextHelperImpl
gpu::StorageBufferStructure) override;
std::unique_ptr<BufferRing> makeVertexBufferRing(
size_t capacityInBytes) override;
std::unique_ptr<BufferRing> makeTextureTransferBufferRing(
size_t capacityInBytes) override;

void resizeGradientTexture(uint32_t width, uint32_t height) override;
void resizeTessellationTexture(uint32_t width, uint32_t height) override;
Expand Down
53 changes: 25 additions & 28 deletions defold-rive/include/rive/renderer/gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,20 @@ struct GradientSpan
// fixed-point range 0..65535.
RIVE_ALWAYS_INLINE void set(uint32_t x0Fixed,
uint32_t x1Fixed,
float y_,
uint32_t y,
uint32_t flags,
ColorInt color0_,
ColorInt color1_)
{
assert(x0Fixed < 65536);
assert(x1Fixed < 65536);
horizontalSpan = (x1Fixed << 16) | x0Fixed;
y = y_;
yWithFlags = flags | y;
color0 = color0_;
color1 = color1_;
}
uint32_t horizontalSpan;
uint32_t y;
uint32_t yWithFlags;
uint32_t color0;
uint32_t color1;
};
Expand All @@ -161,6 +162,9 @@ static_assert(256 % sizeof(GradientSpan) == 0);
constexpr static size_t kGradSpanBufferAlignmentInElements =
256 / sizeof(GradientSpan);

// Gradient spans are drawn as 1px-tall triangle strips with 3 sub-rectangles.
constexpr uint32_t GRAD_SPAN_TRI_STRIP_VERTEX_COUNT = 8;

// Each curve gets tessellated into vertices. This is performed by rendering a
// horizontal span of positions and normals into the tessellation data texture,
// GP-GPU style. TessVertexSpan defines one instance of a horizontal
Expand Down Expand Up @@ -324,11 +328,10 @@ struct ColorRampLocation
// and images reference an additional Gradient* and Texture* respectively.
union SimplePaintValue
{
ColorInt color = 0xff000000; // PaintType::solidColor
ColorRampLocation
colorRampLocation; // Paintype::linearGradient, Paintype::radialGradient
float imageOpacity; // PaintType::image
uint32_t outerClipID; // Paintype::clipUpdate
ColorInt color = 0xff000000; // PaintType::solidColor
ColorRampLocation colorRampLocation; // Paintype::linear/radialGradient
float imageOpacity; // PaintType::image
uint32_t outerClipID; // Paintype::clipUpdate
};
static_assert(sizeof(SimplePaintValue) == 4);

Expand Down Expand Up @@ -773,10 +776,12 @@ enum class DrawContents
none = 0,
opaquePaint = 1 << 0,
stroke = 1 << 1,
evenOddFill = 1 << 2,
activeClip = 1 << 3,
clipUpdate = 1 << 4,
advancedBlend = 1 << 5,
clockwiseFill = 1 << 2,
nonZeroFill = 1 << 3,
evenOddFill = 1 << 4,
activeClip = 1 << 5,
clipUpdate = 1 << 6,
advancedBlend = 1 << 7,
};
RIVE_MAKE_ENUM_BITSET(DrawContents)

Expand Down Expand Up @@ -830,12 +835,7 @@ struct DrawBatch
// memory from the CPU instead of rendering them.
struct TwoTexelRamp
{
void set(const ColorInt colors[2])
{
UnpackColorToRGBA8(colors[0], colorData);
UnpackColorToRGBA8(colors[1], colorData + 4);
}
uint8_t colorData[8];
ColorInt color0, color1;
};
static_assert(sizeof(TwoTexelRamp) == 8 * sizeof(uint8_t));

Expand All @@ -857,7 +857,7 @@ class CommandBufferCompletionFence : public RefCnt<CommandBufferCompletionFence>
//
// 1. Render the complex gradients from the gradSpanBuffer to the gradient
// texture
// (complexGradSpanCount, firstComplexGradSpan, complexGradRowsTop,
// (gradSpanCount, firstComplexGradSpan, complexGradRowsTop,
// complexGradRowsHeight).
//
// 2. Transfer the simple gradient texels from the simpleColorRampsBuffer to
Expand Down Expand Up @@ -907,17 +907,14 @@ struct FlushDescriptor
size_t firstPaintAux = 0;
uint32_t contourCount = 0;
size_t firstContour = 0;
uint32_t complexGradSpanCount = 0;
size_t firstComplexGradSpan = 0;
uint32_t gradSpanCount = 0;
size_t firstGradSpan = 0;
uint32_t tessVertexSpanCount = 0;
size_t firstTessVertexSpan = 0;
uint32_t simpleGradTexelsWidth = 0;
uint32_t simpleGradTexelsHeight = 0;
size_t simpleGradDataOffsetInBytes = 0;
uint32_t complexGradRowsTop = 0;
uint32_t complexGradRowsHeight = 0;
uint32_t gradDataHeight = 0;
uint32_t tessDataHeight = 0;
bool clockwiseFill = false; // Override path fill rules with "clockwise".
// Override path fill rules with "clockwise".
bool clockwiseFillOverride = false;
bool hasTriangleVertices = false;
bool wireframe = false;
bool isFinalFlushOfFrame = false;
Expand Down Expand Up @@ -1108,7 +1105,7 @@ struct PaintData
constexpr static StorageBufferStructure kBufferStructure =
StorageBufferStructure::uint32x2;

void set(FillRule,
void set(DrawContents singleDrawContents,
PaintType,
SimplePaintValue,
GradTextureLayout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ class RenderContextMetalImpl : public RenderContextHelperImpl
size_t capacityInBytes, StorageBufferStructure) override;
std::unique_ptr<BufferRing> makeVertexBufferRing(
size_t capacityInBytes) override;
std::unique_ptr<BufferRing> makeTextureTransferBufferRing(
size_t capacityInBytes) override;

private:
// Renders paths to the main render target.
Expand Down
Loading

0 comments on commit 92aa76e

Please sign in to comment.