diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-11-18 12:23:11 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-11-18 16:44:18 +0100 |
commit | 899deee84589306764a19383e3518e66714ca5e5 (patch) | |
tree | 603987c7282a36ee28bfbdd286171319ea842141 | |
parent | 5a76ae27a90fcb7e170a1cdd822a4bfd260e03a3 (diff) |
add an extra margin to native control drawing on Skia/Mac
Some controls draw outside of their given area, which would get cropped
when first drawing to a temporary context limited to just that size.
I haven't managed to find a way to calculate the proper marging, so
just add something that's hopefully enough but not too big.
Change-Id: I1a15a3ab8cbd26cbe4fb52628b300ee70c8d51ad
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125469
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r-- | vcl/skia/osx/gdiimpl.cxx | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/vcl/skia/osx/gdiimpl.cxx b/vcl/skia/osx/gdiimpl.cxx index 58e03e16f3be..126f43bb6ac3 100644 --- a/vcl/skia/osx/gdiimpl.cxx +++ b/vcl/skia/osx/gdiimpl.cxx @@ -187,9 +187,19 @@ bool AquaSkiaSalGraphicsImpl::drawNativeControl(ControlType nType, ControlPart n const tools::Rectangle& rControlRegion, ControlState nState, const ImplControlValue& aValue) { + // rControlRegion is not the whole area that the control should be painted to (e.g. highlight + // around focused lineedit is outside of it). Since we draw to a temporary bitmap, we need tofind out + // the real size. Using getNativeControlRegion() might seem like the function to call, but we need + // the other direction - what is called rControlRegion here is rNativeContentRegion in that function + // what's called rControlRegion there is what we need here. Moreover getNativeControlRegion() + // in some cases returns a fixed size that does not depend on its input, so we have no way to + // actually find out what the original size was (or maybe the function is kind of broken, I don't know). + // So, add a generous margin and hope it's enough. + tools::Rectangle boundingRegion(rControlRegion); + boundingRegion.expand(50 * mScaling); // Do a scaled bitmap in HiDPI in order not to lose precision. - const tools::Long width = rControlRegion.GetWidth() * mScaling; - const tools::Long height = rControlRegion.GetHeight() * mScaling; + const tools::Long width = boundingRegion.GetWidth() * mScaling; + const tools::Long height = boundingRegion.GetHeight() * mScaling; const size_t bytes = width * height * 4; std::unique_ptr<sal_uInt8[]> data(new sal_uInt8[bytes]); memset(data.get(), 0, bytes); @@ -211,7 +221,9 @@ bool AquaSkiaSalGraphicsImpl::drawNativeControl(ControlType nType, ControlPart n CGContextSetRGBFillColor(context, fillColor.GetRed(), fillColor.GetGreen(), fillColor.GetBlue(), fillColor.GetAlpha()); // Adjust for our drawn-to coordinates in the bitmap. - tools::Rectangle movedRegion(Point(0, 0), rControlRegion.GetSize()); + tools::Rectangle movedRegion(Point(rControlRegion.getX() - boundingRegion.getX(), + rControlRegion.getY() - boundingRegion.getY()), + rControlRegion.GetSize()); // Flip drawing upside down. CGContextTranslateCTM(context, 0, height); CGContextScaleCTM(context, 1, -1); @@ -232,15 +244,15 @@ bool AquaSkiaSalGraphicsImpl::drawNativeControl(ControlType nType, ControlPart n preDraw(); SAL_INFO("vcl.skia.trace", "drawnativecontrol(" << this << "): " << rControlRegion << ":" << int(nType) << "/" << int(nPart)); - tools::Rectangle updateRect = rControlRegion; + tools::Rectangle updateRect = boundingRegion; // For background update only part that is not clipped, the same // as in AquaGraphicsBackend::drawNativeControl(). if (nType == ControlType::WindowBackground) updateRect.Intersection(mClipRegion.GetBoundRect()); addUpdateRegion(SkRect::MakeXYWH(updateRect.getX(), updateRect.getY(), updateRect.GetWidth(), updateRect.GetHeight())); - SkRect drawRect = SkRect::MakeXYWH(rControlRegion.getX(), rControlRegion.getY(), - rControlRegion.GetWidth(), rControlRegion.GetHeight()); + SkRect drawRect = SkRect::MakeXYWH(boundingRegion.getX(), boundingRegion.getY(), + boundingRegion.GetWidth(), boundingRegion.GetHeight()); assert(drawRect.width() * mScaling == bitmap.width()); // no scaling should be needed getDrawCanvas()->drawImageRect(bitmap.asImage(), drawRect, SkSamplingOptions()); ++mPendingOperationsToFlush; // tdf#136369 |