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>
|
|
|
|
|
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
|
|
|
|
2019-11-15 14:42:05 +01:00
|
|
|
void X11SkiaSalGraphicsImpl::createWindowContext()
|
2020-02-06 15:48:14 +01:00
|
|
|
{
|
|
|
|
assert(mX11Parent.GetDrawable() != None);
|
|
|
|
mWindowContext = createWindowContext(mX11Parent.GetXDisplay(), mX11Parent.GetDrawable(),
|
|
|
|
&mX11Parent.GetVisual(), GetWidth(), GetHeight(),
|
2020-03-25 12:27:50 +01:00
|
|
|
SkiaHelper::renderMethodToUse(), false);
|
2020-02-06 15:48:14 +01:00
|
|
|
if (mWindowContext && SkiaHelper::renderMethodToUse() == SkiaHelper::RenderVulkan)
|
|
|
|
mIsGPU = true;
|
|
|
|
else
|
|
|
|
mIsGPU = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
SkiaHelper::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;
|
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
|
|
|
|
// Our patched Skia has VulkanWindowContext that shares GrContext, which requires
|
|
|
|
// 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
|
|
|
|
// checkDeviceBlacklisted() needs a WindowContext and may be called before SalVisual
|
|
|
|
// 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
|
|
|
{
|
2019-11-13 13:27:57 +01:00
|
|
|
case SkiaHelper::RenderRaster:
|
2019-11-22 12:30:16 +01:00
|
|
|
// TODO The Skia Xlib code actually requires the non-native color type to work properly.
|
|
|
|
displayParams.fColorType
|
|
|
|
= (displayParams.fColorType == kBGRA_8888_SkColorType ? kRGBA_8888_SkColorType
|
|
|
|
: kBGRA_8888_SkColorType);
|
2020-02-06 15:48:14 +01:00
|
|
|
return sk_app::window_context_factory::MakeRasterForXlib(winInfo, displayParams);
|
2019-11-13 13:27:57 +01:00
|
|
|
case SkiaHelper::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
|
|
|
|
{
|
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() {}
|
|
|
|
|
2019-10-02 17:15:07 +02:00
|
|
|
void X11SkiaSalGraphicsImpl::performFlush()
|
|
|
|
{
|
2020-02-05 11:56:40 +01:00
|
|
|
SkiaZone zone;
|
2019-10-02 17:15:07 +02:00
|
|
|
// TODO XPutImage() is somewhat inefficient, XShmPutImage() should be preferred.
|
2019-10-07 12:40:02 +02:00
|
|
|
mWindowContext->swapBuffers();
|
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(
|
|
|
|
salDisplay->GetDisplay(), None, visual, 1, 1, SkiaHelper::RenderVulkan, temporary);
|
|
|
|
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: */
|