diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-10-02 14:11:25 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-11-27 09:55:06 +0100 |
commit | 94941da28f69cbca6c3d125ec267fe2efadc0a1d (patch) | |
tree | 20bf21071a269fba2c42250d73f792552cff64fa /vcl | |
parent | b4f3a3596056ae4064548b38ac1af3da4fec9506 (diff) |
implement Skia setClipRegion()
Change-Id: I9e525936bba50b565704ee1b60d7464a7397dc80
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/skia/gdiimpl.cxx | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx index ba764cbdd0b9..b2341c90632c 100644 --- a/vcl/skia/gdiimpl.cxx +++ b/vcl/skia/gdiimpl.cxx @@ -24,6 +24,7 @@ #include <SkCanvas.h> #include <SkPath.h> +#include <SkRegion.h> #ifdef DBG_UTIL #include <fstream> @@ -43,26 +44,66 @@ void SkiaSalGraphicsImpl::Init() { // TODO mSurface = SkSurface::MakeRasterN32Premul(GetWidth(), GetHeight()); + mSurface->getCanvas()->save(); // see SetClipRegion() + mClipRegion = vcl::Region(tools::Rectangle(0, 0, GetWidth(), GetHeight())); } void SkiaSalGraphicsImpl::DeInit() { mSurface.reset(); } void SkiaSalGraphicsImpl::freeResources() {} -const vcl::Region& SkiaSalGraphicsImpl::getClipRegion() const { return mClipRegion; } +static SkIRect toSkIRect(const tools::Rectangle& rectangle) +{ + return SkIRect::MakeXYWH(rectangle.Left(), rectangle.Top(), rectangle.GetWidth(), + rectangle.GetHeight()); +} + +static SkRegion toSkRegion(const vcl::Region& region) +{ + if (region.IsEmpty()) + return SkRegion(); + if (region.IsRectangle()) + return SkRegion(toSkIRect(region.GetBoundRect())); + if (!region.HasPolyPolygonOrB2DPolyPolygon()) + { + SkRegion skRegion; + RectangleVector rectangles; + region.GetRegionRectangles(rectangles); + for (const tools::Rectangle& rect : rectangles) + skRegion.op(toSkIRect(rect), SkRegion::kUnion_Op); + return skRegion; + } + abort(); +} bool SkiaSalGraphicsImpl::setClipRegion(const vcl::Region& region) { + if (mClipRegion == region) + return true; mClipRegion = region; + SkCanvas* canvas = mSurface->getCanvas(); + // SkCanvas::clipRegion() can only further reduce the clip region, + // but we need to set the given region, which may extend it. + // So handle that by always having the full clip region saved on the stack + // and always go back to that. SkCanvas::restore() only affects the clip + // and the matrix. + canvas->restore(); + canvas->save(); + canvas->clipRegion(toSkRegion(region)); return true; } +void SkiaSalGraphicsImpl::ResetClipRegion() +{ + setClipRegion(vcl::Region(tools::Rectangle(0, 0, GetWidth(), GetHeight()))); +} + +const vcl::Region& SkiaSalGraphicsImpl::getClipRegion() const { return mClipRegion; } + sal_uInt16 SkiaSalGraphicsImpl::GetBitCount() const { return 32; } long SkiaSalGraphicsImpl::GetGraphicsWidth() const { return GetWidth(); } -void SkiaSalGraphicsImpl::ResetClipRegion() { mClipRegion.SetEmpty(); } - void SkiaSalGraphicsImpl::SetLineColor() { mLineColor = SALCOLOR_NONE; } void SkiaSalGraphicsImpl::SetLineColor(Color nColor) { mLineColor = nColor; } |