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>
|
|
|
|
|
2019-10-07 12:40:02 +02:00
|
|
|
#include <tools/sk_app/unix/WindowContextFactory_unix.h>
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
X11SkiaSalGraphicsImpl::~X11SkiaSalGraphicsImpl() {}
|
|
|
|
|
2019-09-20 18:46:43 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::Init()
|
|
|
|
{
|
|
|
|
// 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
|
|
|
SkiaSalGraphicsImpl::Init();
|
|
|
|
}
|
2019-10-12 17:46:11 +02:00
|
|
|
|
2020-09-22 12:48:10 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::createWindowContext(bool forceRaster)
|
2020-02-06 15:48:14 +01:00
|
|
|
{
|
|
|
|
assert(mX11Parent.GetDrawable() != None);
|
2021-03-01 20:18:12 +01:00
|
|
|
mWindowContext = createWindowContext(mX11Parent.GetXDisplay(), mX11Parent.GetDrawable(),
|
|
|
|
&mX11Parent.GetVisual(), GetWidth(), GetHeight(),
|
|
|
|
forceRaster ? RenderRaster : renderMethodToUse(), false);
|
2020-02-06 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<sk_app::WindowContext>
|
|
|
|
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;
|
2019-10-07 12:40:02 +02:00
|
|
|
sk_app::DisplayParams displayParams;
|
2019-11-22 12:30:16 +01:00
|
|
|
displayParams.fColorType = 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)
|
2020-09-28 15:13:08 +02:00
|
|
|
displayParams.fDisableVsync = true;
|
|
|
|
#endif
|
2019-10-07 12:40:02 +02:00
|
|
|
sk_app::window_context_factory::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;
|
2019-11-12 16:10:50 +01:00
|
|
|
#ifdef DBG_UTIL
|
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:
|
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).
|
2019-11-22 12:30:16 +01:00
|
|
|
displayParams.fColorType
|
2020-10-02 20:36:27 +02:00
|
|
|
= (visual->red_mask > visual->blue_mask ? kBGRA_8888_SkColorType
|
|
|
|
: kRGBA_8888_SkColorType);
|
2020-02-06 15:48:14 +01:00
|
|
|
return sk_app::window_context_factory::MakeRasterForXlib(winInfo, displayParams);
|
2021-03-01 20:18:12 +01:00
|
|
|
case RenderVulkan:
|
2020-02-06 15:48:14 +01:00
|
|
|
return sk_app::window_context_factory::MakeVulkanForXlib(winInfo, displayParams);
|
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);
|
|
|
|
}
|
|
|
|
|
2019-10-07 12:40:02 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::DeInit()
|
2019-10-02 17:15:07 +02:00
|
|
|
{
|
2020-02-05 11:56:40 +01:00
|
|
|
SkiaZone zone;
|
2019-10-07 12:40:02 +02:00
|
|
|
SkiaSalGraphicsImpl::DeInit();
|
2019-10-22 10:32:01 +02:00
|
|
|
mWindowContext.reset();
|
2019-10-02 17:15:07 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 12:40:02 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::freeResources() {}
|
|
|
|
|
2020-09-30 10:05:53 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::Flush() { performFlush(); }
|
|
|
|
|
2019-10-02 17:15:07 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::performFlush()
|
|
|
|
{
|
2020-02-05 11:56:40 +01:00
|
|
|
SkiaZone zone;
|
2020-07-15 12:16:47 +02:00
|
|
|
flushDrawing();
|
2019-10-02 17:15:07 +02:00
|
|
|
// TODO XPutImage() is somewhat inefficient, XShmPutImage() should be preferred.
|
2020-10-06 14:51:21 +02:00
|
|
|
if (mWindowContext)
|
2020-10-06 22:14:36 +02:00
|
|
|
{
|
|
|
|
if (mDirtyRect.intersect(SkIRect::MakeWH(GetWidth(), GetHeight())))
|
|
|
|
mWindowContext->swapBuffers(&mDirtyRect);
|
|
|
|
mDirtyRect.setEmpty();
|
|
|
|
}
|
2019-10-02 17:15:07 +02:00
|
|
|
}
|
|
|
|
|
2020-03-25 12:27:50 +01:00
|
|
|
std::unique_ptr<sk_app::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;
|
|
|
|
}
|
|
|
|
std::unique_ptr<sk_app::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: */
|