Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pass

NAME = 'skia-python'
__version__ = '0.0.5'
__version__ = '0.0.6'

SKIA_PATH = os.getenv('SKIA_PATH', 'skia')
SKIA_OUT_PATH = os.getenv(
Expand Down
2 changes: 1 addition & 1 deletion src/skia/Bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ bitmap

:return: :py:class:`ColorSpace` in :py:class:`ImageInfo`, or nullptr
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refColorSpace", &SkBitmap::refColorSpace,
R"docstring(
Returns smart pointer to :py:class:`ColorSpace`, the range of colors,
Expand Down
27 changes: 11 additions & 16 deletions src/skia/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ py::class_<SkAutoCanvasRestore>(m, "AutoCanvasRestore", R"docstring(
R"docstring(
Preserves :py:meth:`Canvas.save` count.

Optionally saves SkCanvas clip and SkCanvas matrix.
Optionally saves :py:class:`Canvas` clip and :py:class:`Canvas` matrix.

:param skia.Canvas canvas: :py:class:`Canvas` to guard
:param bool doSave: call :py:meth:`Canvas.save`
:return: utility to restore :py:class:`Canvas` state on destructor
)docstring",
py::arg("canvas"), py::arg("doSave") = true)
py::arg("canvas"), py::arg("doSave") = true,
py::keep_alive<0, 1>())
.def("restore", &SkAutoCanvasRestore::restore,
R"docstring(
Restores :py:class:`Canvas` to saved state immediately.

Subsequent calls and destructor have no effect.
)docstring")
.def("__enter__", [] (SkAutoCanvasRestore& self) { return; })
.def("__exit__", [] (SkAutoCanvasRestore& self, py::args args) {
self.restore();
})
.def("__enter__", [] (SkAutoCanvasRestore& self) {})
.def("__exit__",
[] (SkAutoCanvasRestore& self, py::args args) { self.restore(); })
;

py::enum_<SkClipOp>(m, "ClipOp")
Expand Down Expand Up @@ -207,13 +207,11 @@ py::class_<SkCanvas::SaveLayerRec>(canvas, "SaveLayerRec",
.def_readwrite("fBounds", &SkCanvas::SaveLayerRec::fBounds,
R"docstring(
hints at layer size limit
)docstring",
py::return_value_policy::reference)
)docstring")
.def_readwrite("fPaint", &SkCanvas::SaveLayerRec::fPaint,
R"docstring(
modifies overlay
)docstring",
py::return_value_policy::reference)
)docstring")
.def_readwrite("fBackdrop", &SkCanvas::SaveLayerRec::fBackdrop,
R"docstring(
If not null, this triggers the same initialization behavior as setting
Expand All @@ -222,18 +220,15 @@ py::class_<SkCanvas::SaveLayerRec>(canvas, "SaveLayerRec",
layer, rather than initializing the new layer with transparent-black.

This is then filtered by fBackdrop (respecting the current clip).
)docstring",
py::return_value_policy::reference)
)docstring")
.def_readwrite("fClipMask", &SkCanvas::SaveLayerRec::fClipMask,
R"docstring(
clips layer with mask alpha
)docstring",
py::return_value_policy::reference)
)docstring")
.def_readwrite("fClipMatrix", &SkCanvas::SaveLayerRec::fClipMatrix,
R"docstring(
transforms mask alpha used to clip
)docstring",
py::return_value_policy::reference)
)docstring")
.def_readwrite("fSaveLayerFlags", &SkCanvas::SaveLayerRec::fSaveLayerFlags,
R"docstring(
preserves LCD text, creates with prior layer contents
Expand Down
6 changes: 3 additions & 3 deletions src/skia/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ py::class_<SkDocument, sk_sp<SkDocument>, SkRefCnt>(m, "Document",
[] (SkDocument* document, SkScalar width, SkScalar height) {
return PyAutoDocumentPage(document, width, height);
},
py::arg("width"), py::arg("height"))
py::arg("width"), py::arg("height"), py::keep_alive<0, 1>())
.def("beginPage", &SkDocument::beginPage,
R"docstring(
Begin a new page for the document, returning the canvas that will draw
Expand All @@ -96,7 +96,7 @@ py::class_<SkDocument, sk_sp<SkDocument>, SkRefCnt>(m, "Document",
deleted.
)docstring",
py::arg("width"), py::arg("height"), py::arg("content") = nullptr,
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("endPage", &SkDocument::endPage,
R"docstring(
Call :py:meth:`endPage` when the content for the current page has been
Expand Down Expand Up @@ -125,7 +125,7 @@ py::class_<SkDocument, sk_sp<SkDocument>, SkRefCnt>(m, "Document",
py::class_<PyAutoDocumentPage>(m, "_AutoDocumentPage")
.def("__enter__",
[] (PyAutoDocumentPage& page) { return page.beginPage(); },
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("__exit__",
[] (PyAutoDocumentPage& page, py::object exc_type, py::object exc_value,
py::object traceback) { page.endPage(); })
Expand Down
11 changes: 4 additions & 7 deletions src/skia/ImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace {
py::object IsColorFilterNode(const SkImageFilter& filter) {
SkColorFilter* colorfilter;
if (filter.isColorFilterNode(&colorfilter))
return py::cast(colorfilter);
return py::cast(sk_sp<SkColorFilter>(colorfilter));
return py::none();
}

Expand Down Expand Up @@ -130,18 +130,15 @@ imagefilter
.def("isColorFilterNode", &IsColorFilterNode,
R"docstring(
Returns :py:class:`ColorFilter` if it can. Otherwise returns None.
)docstring",
py::return_value_policy::reference)
.def("asColorFilter", &IsColorFilterNode,
py::return_value_policy::reference)
)docstring")
.def("asColorFilter", &IsColorFilterNode)
.def("asAColorFilter", &IsColorFilterNode,
R"docstring(
Returns colorfilter if this imagefilter can be completely replaced by
the returned colorfilter. Otherwise None.

i.e. the two effects will affect drawing in the same way.
)docstring",
py::return_value_policy::reference)
)docstring")
.def("countInputs", &SkImageFilter::countInputs,
R"docstring(
Returns the number of inputs this filter will accept (some inputs can be
Expand Down
4 changes: 2 additions & 2 deletions src/skia/ImageInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ py::class_<SkColorInfo>(m, "ColorInfo",
.def(py::init<const SkColorInfo&>())
// .def(py::init<SkColorInfo&&>())
.def("colorSpace", &SkColorInfo::colorSpace,
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refColorSpace", &SkColorInfo::refColorSpace)
.def("colorType", &SkColorInfo::colorType)
.def("alphaType", &SkColorInfo::alphaType)
Expand Down Expand Up @@ -230,7 +230,7 @@ py::class_<SkImageInfo>(m, "ImageInfo",

:return: :py:class:`ColorSpace`, or nullptr
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refColorSpace", &SkImageInfo::refColorSpace,
R"docstring(
Returns smart pointer to :py:class:`ColorSpace`, the range of colors.
Expand Down
10 changes: 5 additions & 5 deletions src/skia/Paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ paint

:return: :py:class:`Shader` if previously set, nullptr otherwise
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refShader", &SkPaint::refShader,
R"docstring(
Returns optional colors used when filling a path, such as a gradient.
Expand Down Expand Up @@ -510,7 +510,7 @@ paint

:return: :py:class:`ColorFilter` if previously set, nullptr otherwise
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refColorFilter", &SkPaint::refColorFilter,
R"docstring(
Returns :py:class:`ColorFilter` if set, or nullptr.
Expand Down Expand Up @@ -570,7 +570,7 @@ paint

:return: :py:class:`PathEffect` if previously set, nullptr otherwise
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refPathEffect", &SkPaint::refPathEffect,
R"docstring(
Returns :py:class:`PathEffect` if set, or nullptr.
Expand Down Expand Up @@ -605,7 +605,7 @@ paint

:return: :py:class:`MaskFilter` if previously set, nullptr otherwise
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refMaskFilter", &SkPaint::refMaskFilter,
R"docstring(
Returns :py:class:`MaskFilter` if set, or nullptr.
Expand Down Expand Up @@ -641,7 +641,7 @@ paint

:return: :py:class:`ImageFilter` if previously set, nullptr otherwise
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refImageFilter", &SkPaint::refImageFilter,
R"docstring(
Returns :py:class:`ImageFilter` if set, or nullptr.
Expand Down
3 changes: 2 additions & 1 deletion src/skia/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ py::class_<SkPath::RawIter>(path, "RawIter", R"docstring(

path
.def("__iter__",
[] (const SkPath& path) { return SkPath::Iter(path, false); })
[] (const SkPath& path) { return SkPath::Iter(path, false); },
py::keep_alive<0, 1>())
.def(py::init<>(), R"docstring(
Constructs an empty :py:class:`Path`.

Expand Down
12 changes: 7 additions & 5 deletions src/skia/Picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ py::class_<SkDrawable, sk_sp<SkDrawable>, SkFlattenable>(m, "Drawable",
py::overload_cast<SkCanvas*, SkScalar, SkScalar>(&SkDrawable::draw),
py::arg("canvas").none(false), py::arg("x"), py::arg("y"))
// .def("snapGpuDrawHandler", &SkDrawable::snapGpuDrawHandler)
.def("newPictureSnapshot", &SkDrawable::newPictureSnapshot,
py::return_value_policy::reference)
.def("newPictureSnapshot",
[] (SkDrawable& drawable) {
return sk_sp<SkPicture>(drawable.newPictureSnapshot());
})
.def("getGenerationID", &SkDrawable::getGenerationID,
R"docstring(
Return a unique value for this instance.
Expand Down Expand Up @@ -327,22 +329,22 @@ picturerecorder
:return: the canvas.
)docstring",
py::arg("bounds"), py::arg("recordFlags") = 0,
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("beginRecording",
[] (SkPictureRecorder& recorder, SkScalar width, SkScalar height,
uint32_t flags) {
return recorder.beginRecording(width, height, nullptr, flags);
},
py::arg("width"), py::arg("height"), py::arg("recordFlags") = 0,
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("getRecordingCanvas", &SkPictureRecorder::getRecordingCanvas,
R"docstring(
Returns the recording canvas if one is active, or NULL if recording is
not active.

This does not alter the refcnt on the canvas (if present).
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("finishRecordingAsPicture",
&SkPictureRecorder::finishRecordingAsPicture,
R"docstring(
Expand Down
2 changes: 1 addition & 1 deletion src/skia/Pixmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ py::class_<SkPixmap>(m, "Pixmap",

:return: :py:class:`ColorSpace` in :py:class:`ImageInfo`, or nullptr
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refColorSpace", &SkPixmap::refColorSpace,
R"docstring(
Returns smart pointer to :py:class:`ColorSpace`, the range of colors,
Expand Down
6 changes: 4 additions & 2 deletions src/skia/Rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ py::class_<SkIRect>(m, "IRect", R"docstring(
.def("__iter__",
[](const SkIRect& r) {
return py::make_iterator(&r.fLeft, &r.fLeft + 4);
})
},
py::keep_alive<0, 1>())
.def("__len__", [] (const SkIRect& r) { return 4; })
.def("__repr__",
[](const SkIRect& r) {
Expand Down Expand Up @@ -711,7 +712,8 @@ py::class_<SkRect>(m, "Rect", R"docstring(
.def("__iter__",
[](const SkRect& r) {
return py::make_iterator(&r.fLeft, &r.fLeft + 4);
})
},
py::keep_alive<0, 1>())
.def("__len__", [] (const SkRect& r) { return 4; })
.def("__repr__", [](const SkRect& r) {
std::stringstream s;
Expand Down
12 changes: 8 additions & 4 deletions src/skia/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ region
py::arg("data"))
.def_readonly_static("kOpCnt", &SkRegion::kOpCnt)
.def("__iter__",
[] (const SkRegion& region) { return SkRegion::Iterator(region); })
[] (const SkRegion& region) { return SkRegion::Iterator(region); },
py::keep_alive<0, 1>())
.def("iterator",
[] (const SkRegion& region) { return SkRegion::Iterator(region); },
R"docstring(
Expand All @@ -633,7 +634,8 @@ region

for rect in region.iterator():
pass
)docstring")
)docstring",
py::keep_alive<0, 1>())
.def("cliperator",
[] (const SkRegion& region, const SkIRect& clip) {
return SkRegion::Cliperator(region, clip);
Expand All @@ -649,7 +651,8 @@ region

:param skia.IRect clip: bounds of iteration
)docstring",
py::arg("clip"))
py::arg("clip"),
py::keep_alive<0, 1>())
.def("spanerator",
[] (const SkRegion& region, int y, int left, int right) {
return SkRegion::Spanerator(region, y, left, right);
Expand All @@ -667,7 +670,8 @@ region
:param int left: bounds of iteration
:param int right: bounds of iteration
)docstring",
py::arg("y"), py::arg("left"), py::arg("right"))
py::arg("y"), py::arg("left"), py::arg("right"),
py::keep_alive<0, 1>())
.def("__sub__",
&ApplyOp2<SkRegion, SkRegion, SkRegion::kDifference_Op>,
py::is_operator())
Expand Down
5 changes: 2 additions & 3 deletions src/skia/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ shader
std::vector<SkTileMode>& xy) {
if (xy.size() != 2)
throw std::runtime_error("xy must have two elements.");
return shader.isAImage(localMatrix, &xy[0]);
return sk_sp<SkImage>(shader.isAImage(localMatrix, &xy[0]));
},
R"docstring(
Iff this shader is backed by a single :py:class:`Image`, return its ptr
Expand All @@ -128,8 +128,7 @@ shader

If not, return nullptr.
)docstring",
py::arg("localMatrix"), py::arg("xy") = nullptr,
py::return_value_policy::reference)
py::arg("localMatrix"), py::arg("xy") = nullptr)
.def("isAImage", py::overload_cast<>(&SkShader::isAImage, py::const_))
.def("asAGradient", &SkShader::asAGradient, py::arg("info"))
.def("makeWithLocalMatrix", &SkShader::makeWithLocalMatrix,
Expand Down
6 changes: 4 additions & 2 deletions src/skia/Size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ py::class_<SkISize>(m, "ISize")
.def("__iter__",
[] (const SkISize& isize) {
return py::make_iterator(&isize.fWidth, &isize.fWidth + 2);
})
},
py::keep_alive<0, 1>())
.def("__len__", [] (const SkISize& isize) { return 2; })
.def("__repr__",
[] (const SkISize& isize) {
Expand Down Expand Up @@ -109,7 +110,8 @@ py::class_<SkSize>(m, "Size")
.def("__iter__",
[] (const SkSize& size) {
return py::make_iterator(&size.fWidth, &size.fWidth + 2);
})
},
py::keep_alive<0, 1>())
.def("__len__", [] (const SkSize& size) { return 2; })
.def("__repr__",
[] (const SkSize& size) {
Expand Down
8 changes: 4 additions & 4 deletions src/skia/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ py::class_<SkSurfaceCharacterization>(m, "SurfaceCharacterization")
.def("vulkanSecondaryCBCompatible",
&SkSurfaceCharacterization::vulkanSecondaryCBCompatible)
.def("colorSpace", &SkSurfaceCharacterization::colorSpace,
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("refColorSpace", &SkSurfaceCharacterization::refColorSpace)
.def("surfaceProps", &SkSurfaceCharacterization::surfaceProps)
;
Expand Down Expand Up @@ -177,7 +177,7 @@ surface
})
.def("__enter__",
[] (SkSurface& surface) { return surface.getCanvas(); },
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("__exit__",
[] (const SkSurface& surface, py::object exc_type, py::object exc_value,
py::object traceback) { })
Expand Down Expand Up @@ -281,7 +281,7 @@ surface

:return: GPU context, if available; nullptr otherwise
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("getBackendTexture", &SkSurface::getBackendTexture,
R"docstring(
Retrieves the back-end texture.
Expand Down Expand Up @@ -339,7 +339,7 @@ surface

:return: drawing :py:class:`Canvas` for :py:class:`Surface`
)docstring",
py::return_value_policy::reference)
py::return_value_policy::reference_internal)
.def("makeSurface",
py::overload_cast<const SkImageInfo&>(&SkSurface::makeSurface),
R"docstring(
Expand Down
Loading