[Libreoffice-bugs] [Bug 137468] Severe performance degradation on a macOS with 10-bit displays
bugzilla-daemon at bugs.documentfoundation.org
bugzilla-daemon at bugs.documentfoundation.org
Tue Oct 27 05:29:44 UTC 2020
https://bugs.documentfoundation.org/show_bug.cgi?id=137468
--- Comment #45 from Leo Wang <ilford at gmail.com> ---
Patch dated 2020-10-27.
1. Code style adjustments according to comments on Gerrit.
2. Small performance improvements:
- Create the CGImage based on window's color space instead of the display's.
- Set blend mode to kCGBlendModeCopy when copying bitmaps.
----------------------------------------
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h
index 8058b68378b6..0aaf71f0f839 100644
--- a/vcl/inc/quartz/salgdi.h
+++ b/vcl/inc/quartz/salgdi.h
@@ -134,6 +134,8 @@ class AquaSalGraphics : public SalGraphics
{
CGLayerHolder maLayer; // Quartz graphics layer
CGContextHolder maContextHolder; // Quartz drawing context
+ CGContextHolder maBGContextHolder; // Quartz drawing context for CGLayer
+ CGContextHolder maCSContextHolder; // Quartz drawing context considering
the color space
XorEmulation* mpXorEmulation;
int mnXorMode; // 0: off 1: on 2:
invert only
diff --git a/vcl/quartz/salgdicommon.cxx b/vcl/quartz/salgdicommon.cxx
index 7f96124f96ac..7c7dcac7898f 100644
--- a/vcl/quartz/salgdicommon.cxx
+++ b/vcl/quartz/salgdicommon.cxx
@@ -426,11 +426,14 @@ void AquaSalGraphics::copyArea( long nDstX, long
nDstY,long nSrcX, long nSrcY,
CGContextScaleCTM( xSrcContext, +1, -1 );
aSrcPoint.y = (nScaledSourceY + nScaledSourceHeight) - (mnHeight *
fScale);
}
+ CGContextSetBlendMode(xSrcContext, kCGBlendModeCopy);
+
CGContextDrawLayerAtPoint(xSrcContext, aSrcPoint, maLayer.get());
}
// draw at new destination
const CGRect aTargetRect = CGRectMake(nScaledTargetX, nScaledTargetY,
nScaledSourceWidth, nScaledSourceHeight);
+ CGContextSetBlendMode(xCopyContext, kCGBlendModeCopy);
CGContextDrawLayerInRect(xCopyContext, aTargetRect,
sSourceLayerHolder.get());
maContextHolder.restoreState();
diff --git a/vcl/quartz/salgdiutils.cxx b/vcl/quartz/salgdiutils.cxx
index 426aea29dc78..57953e536796 100644
--- a/vcl/quartz/salgdiutils.cxx
+++ b/vcl/quartz/salgdiutils.cxx
@@ -69,11 +69,28 @@ void AquaSalGraphics::SetPrinterGraphics( CGContextRef
xContext, long nDPIX, lon
void AquaSalGraphics::InvalidateContext()
{
UnsetState();
+
+ CGContextRelease(maContextHolder.get());
+ CGContextRelease(maBGContextHolder.get());
+ CGContextRelease(maCSContextHolder.get());
+
maContextHolder.set(nullptr);
+ maCSContextHolder.set(nullptr);
+ maBGContextHolder.set(nullptr);
}
void AquaSalGraphics::UnsetState()
{
+ if (maBGContextHolder.isSet())
+ {
+ CGContextRelease(maBGContextHolder.get());
+ maBGContextHolder.set(nullptr);
+ }
+ if (maCSContextHolder.isSet())
+ {
+ CGContextRelease(maCSContextHolder.get());
+ maBGContextHolder.set(nullptr);
+ }
if (maContextHolder.isSet())
{
maContextHolder.restoreState();
@@ -119,7 +136,12 @@ bool AquaSalGraphics::CheckContext()
{
CGContextRelease(maContextHolder.get());
}
+ CGContextRelease(maBGContextHolder.get());
+ CGContextRelease(maCSContextHolder.get());
+
maContextHolder.set(nullptr);
+ maBGContextHolder.set(nullptr);
+ maCSContextHolder.set(nullptr);
maLayer.set(nullptr);
}
@@ -133,14 +155,17 @@ bool AquaSalGraphics::CheckContext()
const CGSize aLayerSize = { static_cast<CGFloat>(nScaledWidth),
static_cast<CGFloat>(nScaledHeight) };
const int nBytesPerRow = (nBitmapDepth * nScaledWidth) / 8;
- void* pRawData = std::malloc(nBytesPerRow * nScaledHeight);
- const int nFlags = kCGImageAlphaNoneSkipFirst;
- CGContextHolder aContextHolder(CGBitmapContextCreate(
- pRawData, nScaledWidth, nScaledHeight, 8, nBytesPerRow,
GetSalData()->mxRGBSpace, nFlags));
+ int nFlags = kCGImageAlphaNoneSkipFirst |
kCGBitmapByteOrder32Host;
+ maBGContextHolder.set(CGBitmapContextCreate(
+ NULL, nScaledWidth, nScaledHeight, 8, nBytesPerRow,
GetSalData()->mxRGBSpace, nFlags));
- maLayer.set(CGLayerCreateWithContext(aContextHolder.get(),
aLayerSize, nullptr));
+ maLayer.set(CGLayerCreateWithContext(maBGContextHolder.get(),
aLayerSize, nullptr));
maLayer.setScale(fScale);
+ nFlags = kCGImageAlphaPremultipliedFirst |
kCGBitmapByteOrder32Host;
+ maCSContextHolder.set(CGBitmapContextCreate(
+ NULL, nScaledWidth, nScaledHeight, 8, nBytesPerRow,
GetSalData()->mxRGBSpace, nFlags));
+
CGContextRef xDrawContext = CGLayerGetContext(maLayer.get());
maContextHolder = xDrawContext;
@@ -217,8 +242,17 @@ void AquaSalGraphics::UpdateWindow( NSRect& )
const CGSize aSize = maLayer.getSizePoints();
const CGRect aRect = CGRectMake(0, 0, aSize.width, aSize.height);
+ const CGRect aRectPoints = { CGPointZero, maLayer.getSizePixels() };
+ CGContextSetBlendMode(maCSContextHolder.get(), kCGBlendModeCopy);
+ CGContextDrawLayerInRect(maCSContextHolder.get(), aRectPoints,
maLayer.get());
+
+ CGImageRef img = CGBitmapContextCreateImage(maCSContextHolder.get());
+ CGImageRef displayColorSpaceImage =
CGImageCreateCopyWithColorSpace(img, [[mpFrame->getNSWindow() colorSpace]
CGColorSpace]);
+ CGContextSetBlendMode(rCGContextHolder.get(), kCGBlendModeCopy);
+ CGContextDrawImage(rCGContextHolder.get(), aRect,
displayColorSpaceImage);
- CGContextDrawLayerInRect(rCGContextHolder.get(), aRect,
maLayer.get());
+ CGImageRelease(img);
+ CGImageRelease(displayColorSpaceImage);
rCGContextHolder.restoreState();
}
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20201027/045e736c/attachment.htm>
More information about the Libreoffice-bugs
mailing list