11#include < stdexcept>
22#include " common.h"
33#include < include/effects/SkRuntimeEffect.h>
4- // #include <include/core/SkM44.h> // defines SkV3, SkV4 ; M44 used in Matrix/Canvas ; Revisit.
4+ // #include <include/core/SkM44.h> // defines SkV2, SkV3, SkV4 ; M44 used in Matrix/Canvas ; Revisit.
55#include < pybind11/stl_bind.h>
66
77PYBIND11_MAKE_OPAQUE (std::vector<SkRuntimeEffect::ChildPtr>)
@@ -16,6 +16,22 @@ py::class_<SkSpan<const SkRuntimeEffect::ChildPtr>> span_runtime_effect_childptr
1616
1717py::class_<SkRuntimeEffectBuilder> runtime_effect_builder (m, " RuntimeEffectBuilder" );
1818
19+ py::class_<SkV2>(m, " V2" )
20+ .def (py::init (
21+ [] (float x, float y) {
22+ return SkV2{x, y};
23+ }))
24+ .def (py::init (
25+ [] (py::tuple v2) {
26+ if (v2.size () != 2 )
27+ throw py::value_error (" V2 must have exactly two elements." );
28+ return SkV2{v2[0 ].cast <float >(), v2[1 ].cast <float >()};
29+ }),
30+ py::arg (" v2" ))
31+ ;
32+
33+ py::implicitly_convertible<py::tuple, SkV2>();
34+
1935py::class_<SkV3>(m, " V3" )
2036 .def (py::init (
2137 [] (float x, float y, float z) {
@@ -197,9 +213,11 @@ runtime_effect_builder
197213 py::arg (" name" ), py::arg (" uniform" ))
198214 .def (" setUniform" ,
199215 [] (SkRuntimeEffectBuilder& builder, std::string_view name, py::list vN) {
200- if (vN.size () != 3 && vN.size () != 4 )
201- throw py::value_error (" Input must have exactly three or four elements." );
216+ if (vN.size () != 2 && vN. size () != 3 && vN.size () != 4 )
217+ throw py::value_error (" Input must have exactly two, three or four elements." );
202218 auto v = builder.uniform (name);
219+ if (vN.size () == 2 )
220+ v = SkV2{vN[0 ].cast <float >(), vN[1 ].cast <float >()};
203221 if (vN.size () == 3 )
204222 v = SkV3{vN[0 ].cast <float >(), vN[1 ].cast <float >(), vN[2 ].cast <float >()};
205223 if (vN.size () == 4 )
0 commit comments