2019-10-12 17:46:11 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2019-10-02 17:15:07 +02:00
|
|
|
*
|
|
|
|
* Some of this code is based on Skia source code, covered by the following
|
|
|
|
* license notice (see readlicense_oo for the full license):
|
|
|
|
*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*
|
2019-10-12 17:46:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <skia/x11/gdiimpl.hxx>
|
|
|
|
|
2024-10-10 14:39:39 +02:00
|
|
|
#include <tools/window/unix/RasterWindowContext_unix.h>
|
|
|
|
#include <tools/window/unix/GaneshVulkanWindowContext_unix.h>
|
|
|
|
#include <tools/window/unix/XlibWindowInfo.h>
|
2019-10-07 12:40:02 +02:00
|
|
|
|
2020-02-06 15:48:14 +01:00
|
|
|
#include <skia/utils.hxx>
|
2020-02-05 11:56:40 +01:00
|
|
|
#include <skia/zone.hxx>
|
2019-11-13 13:27:57 +01:00
|
|
|
|
2020-03-25 12:27:50 +01:00
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
2021-03-01 20:18:12 +01:00
|
|
|
using namespace SkiaHelper;
|
|
|
|
|
2019-10-12 17:46:11 +02:00
|
|
|
X11SkiaSalGraphicsImpl::X11SkiaSalGraphicsImpl(X11SalGraphics& rParent)
|
|
|
|
: SkiaSalGraphicsImpl(rParent, rParent.GetGeometryProvider())
|
2019-10-14 15:43:08 +02:00
|
|
|
, mX11Parent(rParent)
|
2019-10-12 17:46:11 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-11-18 19:49:51 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::UpdateX11GeometryProvider()
|
2019-09-20 18:46:43 +02:00
|
|
|
{
|
|
|
|
// The m_pFrame and m_pVDev pointers are updated late in X11
|
2019-10-14 15:43:08 +02:00
|
|
|
setProvider(mX11Parent.GetGeometryProvider());
|
2019-09-20 18:46:43 +02:00
|
|
|
}
|
2019-10-12 17:46:11 +02:00
|
|
|
|
2021-08-23 17:57:48 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::createWindowSurfaceInternal(bool forceRaster)
|
2020-02-06 15:48:14 +01:00
|
|
|
{
|
2021-08-23 17:57:48 +02:00
|
|
|
assert(!mWindowContext);
|
|
|
|
assert(!mSurface);
|
2020-02-06 15:48:14 +01:00
|
|
|
assert(mX11Parent.GetDrawable() != None);
|
2021-08-24 21:32:20 +02:00
|
|
|
RenderMethod renderMethod = forceRaster ? RenderRaster : renderMethodToUse();
|
2021-11-15 18:17:57 +01:00
|
|
|
mScaling = getWindowScaling();
|
2021-03-01 20:18:12 +01:00
|
|
|
mWindowContext = createWindowContext(mX11Parent.GetXDisplay(), mX11Parent.GetDrawable(),
|
2021-11-15 18:17:57 +01:00
|
|
|
&mX11Parent.GetVisual(), GetWidth() * mScaling,
|
|
|
|
GetHeight() * mScaling, renderMethod, false);
|
2021-08-23 17:57:48 +02:00
|
|
|
if (mWindowContext)
|
2021-08-24 21:32:20 +02:00
|
|
|
{
|
|
|
|
// See flushSurfaceToWindowContext().
|
|
|
|
if (renderMethod == RenderRaster)
|
2021-08-30 12:10:44 +02:00
|
|
|
mSurface = mWindowContext->getBackbufferSurface();
|
2021-08-24 21:32:20 +02:00
|
|
|
else
|
|
|
|
mSurface = createSkSurface(GetWidth(), GetHeight());
|
|
|
|
}
|
2020-02-06 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
2024-10-05 19:15:52 +02:00
|
|
|
std::unique_ptr<skwindow::WindowContext>
|
2020-02-06 15:48:14 +01:00
|
|
|
X11SkiaSalGraphicsImpl::createWindowContext(Display* display, Drawable drawable,
|
2020-03-25 12:27:50 +01:00
|
|
|
const XVisualInfo* visual, int width, int height,
|
2021-03-01 20:18:12 +01:00
|
|
|
RenderMethod renderMethod, bool temporary)
|
2019-10-02 17:15:07 +02:00
|
|
|
{
|
2020-02-05 11:56:40 +01:00
|
|
|
SkiaZone zone;
|
2025-03-11 15:06:56 +02:00
|
|
|
skwindow::DisplayParamsBuilder displayParamsBuilder;
|
|
|
|
displayParamsBuilder.colorType(kN32_SkColorType);
|
2020-09-28 15:13:08 +02:00
|
|
|
#if defined LINUX
|
|
|
|
// WORKAROUND: VSync causes freezes that can even temporarily freeze the entire desktop.
|
|
|
|
// This happens even with the latest 450.66 drivers despite them claiming a fix for vsync.
|
|
|
|
// https://forums.developer.nvidia.com/t/hangs-freezes-when-vulkan-v-sync-vk-present-mode-fifo-khr-is-enabled/67751
|
2021-03-01 20:18:12 +01:00
|
|
|
if (getVendor() == DriverBlocklist::VendorNVIDIA)
|
2025-03-11 15:06:56 +02:00
|
|
|
displayParamsBuilder.disableVsync(true);
|
2020-09-28 15:13:08 +02:00
|
|
|
#endif
|
2024-10-05 19:15:52 +02:00
|
|
|
skwindow::XlibWindowInfo winInfo;
|
2020-02-06 15:48:14 +01:00
|
|
|
assert(display);
|
|
|
|
winInfo.fDisplay = display;
|
|
|
|
winInfo.fWindow = drawable;
|
2019-10-07 12:40:02 +02:00
|
|
|
winInfo.fFBConfig = nullptr; // not used
|
2020-03-25 12:27:50 +01:00
|
|
|
winInfo.fVisualInfo = const_cast<XVisualInfo*>(visual);
|
|
|
|
assert(winInfo.fVisualInfo->visual != nullptr); // make sure it's not an uninitialized SalVisual
|
2020-02-06 15:48:14 +01:00
|
|
|
winInfo.fWidth = width;
|
|
|
|
winInfo.fHeight = height;
|
2022-03-16 16:21:52 +01:00
|
|
|
#if defined DBG_UTIL && !defined NDEBUG
|
2020-08-25 11:01:39 +02:00
|
|
|
// Our patched Skia has VulkanWindowContext that shares grDirectContext, which requires
|
2019-11-12 16:10:50 +01:00
|
|
|
// that the X11 visual is always the same. Ensure it is so.
|
|
|
|
static VisualID checkVisualID = -1U;
|
2020-03-25 12:27:50 +01:00
|
|
|
// Exception is for the temporary case during startup, when SkiaHelper's
|
2020-07-06 03:01:51 +02:00
|
|
|
// checkDeviceDenylisted() needs a WindowContext and may be called before SalVisual
|
2020-03-25 12:27:50 +01:00
|
|
|
// is ready.
|
|
|
|
if (!temporary)
|
|
|
|
{
|
|
|
|
assert(checkVisualID == -1U || winInfo.fVisualInfo->visualid == checkVisualID);
|
|
|
|
checkVisualID = winInfo.fVisualInfo->visualid;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
(void)temporary;
|
2019-11-12 16:10:50 +01:00
|
|
|
#endif
|
2020-02-06 15:48:14 +01:00
|
|
|
switch (renderMethod)
|
2019-10-22 10:51:09 +02:00
|
|
|
{
|
2021-03-01 20:18:12 +01:00
|
|
|
case RenderRaster:
|
2025-03-11 15:06:56 +02:00
|
|
|
{
|
2020-10-02 20:36:27 +02:00
|
|
|
// Make sure we ask for color type that matches the X11 visual. If red mask
|
|
|
|
// is larger value than blue mask, then on little endian this means blue is first.
|
|
|
|
// This should also preferably match SK_R32_SHIFT set in config_skia.h, as that
|
|
|
|
// improves performance, the common setup seems to be BGRA (possibly because of
|
|
|
|
// choosing OpenGL-capable visual).
|
2025-03-11 15:06:56 +02:00
|
|
|
displayParamsBuilder.colorType(visual->red_mask > visual->blue_mask
|
|
|
|
? kBGRA_8888_SkColorType
|
|
|
|
: kRGBA_8888_SkColorType);
|
|
|
|
return skwindow::MakeRasterForXlib(winInfo, displayParamsBuilder.build());
|
|
|
|
}
|
2021-03-01 20:18:12 +01:00
|
|
|
case RenderVulkan:
|
2025-03-11 15:06:56 +02:00
|
|
|
return skwindow::MakeGaneshVulkanForXlib(winInfo, displayParamsBuilder.build());
|
2021-08-23 17:57:48 +02:00
|
|
|
case RenderMetal:
|
|
|
|
abort();
|
|
|
|
break;
|
2019-10-22 10:51:09 +02:00
|
|
|
}
|
2020-02-06 15:48:14 +01:00
|
|
|
abort();
|
2019-10-02 17:15:07 +02:00
|
|
|
}
|
|
|
|
|
2019-11-12 10:57:30 +01:00
|
|
|
bool X11SkiaSalGraphicsImpl::avoidRecreateByResize() const
|
|
|
|
{
|
2021-02-25 11:37:54 +00:00
|
|
|
if (SkiaSalGraphicsImpl::avoidRecreateByResize())
|
|
|
|
return true;
|
2019-11-14 11:26:58 +01:00
|
|
|
if (!mSurface || isOffscreen())
|
2019-11-12 10:57:30 +01:00
|
|
|
return false;
|
|
|
|
// Skia's WindowContext uses actual dimensions of the X window, which due to X11 being
|
|
|
|
// asynchronous may be temporarily different from what VCL thinks are the dimensions.
|
|
|
|
// That can lead to us repeatedly calling recreateSurface() because of "incorrect"
|
|
|
|
// size, and we otherwise need to check for size changes, because VCL does not inform us.
|
|
|
|
// Avoid the problem here by checking the size of the X window and bail out if Skia
|
|
|
|
// would just return the same size as it is now.
|
|
|
|
Window r;
|
|
|
|
int x, y;
|
|
|
|
unsigned int w, h, border, depth;
|
|
|
|
XGetGeometry(mX11Parent.GetXDisplay(), mX11Parent.GetDrawable(), &r, &x, &y, &w, &h, &border,
|
|
|
|
&depth);
|
|
|
|
return mSurface->width() == int(w) && mSurface->height() == int(h);
|
|
|
|
}
|
|
|
|
|
2020-09-30 10:05:53 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::Flush() { performFlush(); }
|
|
|
|
|
2024-10-05 19:15:52 +02:00
|
|
|
std::unique_ptr<skwindow::WindowContext> createVulkanWindowContext(bool temporary)
|
2020-02-06 15:48:14 +01:00
|
|
|
{
|
|
|
|
SalDisplay* salDisplay = vcl_sal::getSalDisplay(GetGenericUnixSalData());
|
2020-03-25 12:27:50 +01:00
|
|
|
const XVisualInfo* visual;
|
|
|
|
XVisualInfo* visuals = nullptr;
|
|
|
|
if (!temporary)
|
|
|
|
visual = &salDisplay->GetVisual(salDisplay->GetDefaultXScreen());
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// SalVisual from salDisplay may not be setup yet at this point, get
|
|
|
|
// info for the default visual.
|
|
|
|
XVisualInfo search;
|
|
|
|
search.visualid = XVisualIDFromVisual(
|
|
|
|
DefaultVisual(salDisplay->GetDisplay(), salDisplay->GetDefaultXScreen().getXScreen()));
|
|
|
|
int count;
|
|
|
|
visuals = XGetVisualInfo(salDisplay->GetDisplay(), VisualIDMask, &search, &count);
|
|
|
|
assert(count == 1);
|
|
|
|
visual = visuals;
|
|
|
|
}
|
2024-10-05 19:15:52 +02:00
|
|
|
std::unique_ptr<skwindow::WindowContext> ret = X11SkiaSalGraphicsImpl::createWindowContext(
|
2021-03-01 20:18:12 +01:00
|
|
|
salDisplay->GetDisplay(), None, visual, 1, 1, RenderVulkan, temporary);
|
2020-03-25 12:27:50 +01:00
|
|
|
if (temporary)
|
|
|
|
XFree(visuals);
|
|
|
|
return ret;
|
2020-02-06 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 12:04:08 +01:00
|
|
|
void X11SkiaSalGraphicsImpl::prepareSkia() { SkiaHelper::prepareSkia(createVulkanWindowContext); }
|
2020-02-06 15:48:14 +01:00
|
|
|
|
2019-10-12 17:46:11 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|