avoid Skia GPU surfaces for small virtual devices (bsc#1183308)

This is similar to the previous Cairo commit. Fetching pixels
from the GPU is not as slow as fetching them from the XServer,
but this still can make a visible difference. And small surfaces
should not need fast GPU rendering that much, so hopefully this
improves more cases than it regresses.

Change-Id: Ida031b38cd1ce14ded464747c20a38c6d094c5a0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128310
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
This commit is contained in:
Luboš Luňák
2022-01-24 14:40:22 +01:00
parent cf9be3417b
commit 8ca549ebc0
2 changed files with 23 additions and 3 deletions
@@ -33,6 +33,7 @@
#include <cppuhelper/basemutex.hxx>
#include <vcl/lazydelete.hxx>
#include <vcl/dibtools.hxx>
#include <vcl/skia/SkiaHelper.hxx>
// buffered VDev usage
@@ -105,10 +106,17 @@ bool VDevBuffer::isSizeSuitable(const VclPtr<VirtualDevice>& device, const Size&
if (device->GetOutputWidthPixel() >= rSizePixel.getWidth()
&& device->GetOutputHeightPixel() >= rSizePixel.getHeight())
{
bool requireSmall = false;
#if defined(UNX)
// HACK: See the small size handling in SvpSalVirtualDevice::CreateSurface().
// Make sure to not reuse a larger device when a small one should be preferred.
if (device->GetRenderBackendName() == "svp")
requireSmall = true;
#endif
// The same for Skia, see renderMethodToUseForSize().
if (SkiaHelper::isVCLSkiaEnabled())
requireSmall = true;
if (requireSmall)
{
if (rSizePixel.getWidth() <= 32 && rSizePixel.getHeight() <= 32
&& (device->GetOutputWidthPixel() > 32 || device->GetOutputHeightPixel() > 32))
@@ -116,7 +124,6 @@ bool VDevBuffer::isSizeSuitable(const VclPtr<VirtualDevice>& device, const Size&
return false;
}
}
#endif
return true;
}
return false;
+15 -2
View File
@@ -467,12 +467,25 @@ static std::unique_ptr<sk_app::WindowContext> getTemporaryWindowContext()
}
#endif
static RenderMethod renderMethodToUseForSize(const SkISize& size)
{
// Do not use GPU for small surfaces. The problem is that due to the separate alpha hack
// we quite often may call GetBitmap() on VirtualDevice, which is relatively slow
// when the pixels need to be fetched from the GPU. And there are documents that use
// many tiny surfaces (bsc#1183308 for example), where this slowness adds up too much.
// This should be re-evaluated once the separate alpha hack is removed (SKIA_USE_BITMAP32)
// and we no longer (hopefully) fetch pixels that often.
if (size.width() <= 32 && size.height() <= 32)
return RenderRaster;
return renderMethodToUse();
}
sk_sp<SkSurface> createSkSurface(int width, int height, SkColorType type, SkAlphaType alpha)
{
SkiaZone zone;
assert(type == kN32_SkColorType || type == kAlpha_8_SkColorType);
sk_sp<SkSurface> surface;
switch (renderMethodToUse())
switch (renderMethodToUseForSize({ width, height }))
{
case RenderVulkan:
case RenderMetal:
@@ -518,7 +531,7 @@ sk_sp<SkImage> createSkImage(const SkBitmap& bitmap)
{
SkiaZone zone;
assert(bitmap.colorType() == kN32_SkColorType || bitmap.colorType() == kAlpha_8_SkColorType);
switch (renderMethodToUse())
switch (renderMethodToUseForSize(bitmap.dimensions()))
{
case RenderVulkan:
case RenderMetal: