vcl/skia/osx/gdiimpl.cxx | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-)
New commits: commit 899deee84589306764a19383e3518e66714ca5e5 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Thu Nov 18 12:23:11 2021 +0100 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Thu Nov 18 16:44:18 2021 +0100 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.lu...@collabora.com> 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 commit 5a76ae27a90fcb7e170a1cdd822a4bfd260e03a3 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Thu Nov 18 12:20:15 2021 +0100 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Thu Nov 18 16:44:03 2021 +0100 fix background color of some native controls with Skia/Mac (tdf#145748) Some of the control drawing calls use CGContextFillRect() to draw background for controls, so since we use a temporary context, set up colors for such drawing. Change-Id: I41cfa29e29fcf86598d49fbbed0b159c48c63d6a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125468 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/vcl/skia/osx/gdiimpl.cxx b/vcl/skia/osx/gdiimpl.cxx index 0f451f8916df..58e03e16f3be 100644 --- a/vcl/skia/osx/gdiimpl.cxx +++ b/vcl/skia/osx/gdiimpl.cxx @@ -201,6 +201,15 @@ bool AquaSkiaSalGraphicsImpl::drawNativeControl(ControlType nType, ControlPart n SAL_WARN("vcl.skia", "drawNativeControl(): Failed to allocate bitmap context"); return false; } + // Setup context state for drawing (performDrawNativeControl() e.g. fills background in some cases). + CGContextSetFillColorSpace(context, GetSalData()->mxRGBSpace); + CGContextSetStrokeColorSpace(context, GetSalData()->mxRGBSpace); + RGBAColor lineColor = RGBAColor(mLineColor); + CGContextSetRGBStrokeColor(context, lineColor.GetRed(), lineColor.GetGreen(), + lineColor.GetBlue(), lineColor.GetAlpha()); + RGBAColor fillColor = RGBAColor(mFillColor); + 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()); // Flip drawing upside down.