diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-11-06 16:14:50 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-11-27 09:55:16 +0100 |
commit | 54be644c092eebb8be57a251556fe3f0e5f99e57 (patch) | |
tree | 812d0e907d51ed41ba3441a4e9e427311eb29ed7 /vcl/skia | |
parent | 76ee0452b82f69f273526ba8a8c879ce17acb547 (diff) |
make SkiaSalGraphicsImpl use GPU-backed SkSurface also for offscreen
Skia's sk_app::WindowContext can create GPU-backed SkSurface only
for windows, but we also use virtual devices that are not windows.
Fortunately, SkSurface can be created GPU-backed from GrContext*
and sk_gpu_test::GrContextFactory seems to provide it easily.
It is not completely clear to me what the rules are on mixing
SkSurface's with different GrContext* (see the comment
in SkiaSalGraphicsImpl::copyBits()), but it seems to work fine.
Change-Id: I8110b67c41ab092e0c4b6a0973d6bed8a408c4c1
Diffstat (limited to 'vcl/skia')
-rw-r--r-- | vcl/skia/gdiimpl.cxx | 14 | ||||
-rw-r--r-- | vcl/skia/vulkan.cxx | 39 | ||||
-rw-r--r-- | vcl/skia/win/gdiimpl.cxx | 19 | ||||
-rw-r--r-- | vcl/skia/x11/gdiimpl.cxx | 20 |
4 files changed, 86 insertions, 6 deletions
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx index f505e7778d64..612e097b6e12 100644 --- a/vcl/skia/gdiimpl.cxx +++ b/vcl/skia/gdiimpl.cxx @@ -407,6 +407,8 @@ void SkiaSalGraphicsImpl::drawPixel(long nX, long nY, Color nColor) paint.setColor(toSkColor(nColor)); // Apparently drawPixel() is actually expected to set the pixel and not draw it. paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha + if (isGPU()) // TODO this may need caching? + ++nX; // https://bugs.chromium.org/p/skia/issues/detail?id=9611 canvas->drawPoint(nX, nY, paint); postDraw(); } @@ -677,7 +679,6 @@ void SkiaSalGraphicsImpl::copyArea(long nDestX, long nDestY, long nSrcX, long nS << Size(nSrcWidth, nSrcHeight)); sk_sp<SkImage> image = mSurface->makeImageSnapshot(SkIRect::MakeXYWH(nSrcX, nSrcY, nSrcWidth, nSrcHeight)); - // TODO makeNonTextureImage() ? mSurface->getCanvas()->drawImage(image, nDestX, nDestY); postDraw(); } @@ -690,14 +691,18 @@ void SkiaSalGraphicsImpl::copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcG { assert(dynamic_cast<SkiaSalGraphicsImpl*>(pSrcGraphics->GetImpl())); src = static_cast<SkiaSalGraphicsImpl*>(pSrcGraphics->GetImpl()); + src->checkSurface(); + // TODO Without this flush() Skia asserts if both src and destination are + // GPU-backed SkSurface that come from different GrContext (e.g. when + // src comes from SkiaVulkanGrContext and target is a window). I don't + // know if it's a Skia bug or our GrContext usage is incorrect. + src->mSurface->flush(); } else src = this; - src->checkSurface(); SAL_INFO("vcl.skia", "copybits(" << this << "): (" << src << "):" << rPosAry); sk_sp<SkImage> image = src->mSurface->makeImageSnapshot( SkIRect::MakeXYWH(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight)); - // TODO makeNonTextureImage() ? mSurface->getCanvas()->drawImageRect(image, SkRect::MakeXYWH(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, @@ -1055,7 +1060,8 @@ bool SkiaSalGraphicsImpl::supportsOperation(OutDevSupportType eType) const bool SkiaSalGraphicsImpl::isGPU() const { return mSurface.get() - && mSurface->getBackendRenderTarget(SkSurface::kFlushRead_BackendHandleAccess).isValid(); + && mSurface->getBackendRenderTarget(SkSurface::kFlushWrite_BackendHandleAccess) + .isValid(); } #ifdef DBG_UTIL diff --git a/vcl/skia/vulkan.cxx b/vcl/skia/vulkan.cxx new file mode 100644 index 000000000000..c5c9093739fc --- /dev/null +++ b/vcl/skia/vulkan.cxx @@ -0,0 +1,39 @@ +/* -*- 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/. + * + * 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. + * + */ + +#include <skia/vulkan.hxx> + +#include <GrContextFactory.h> + +#include <vcl/lazydelete.hxx> + +static GrContext* createGrContext() +{ + static vcl::DeleteOnDeinit<sk_gpu_test::GrContextFactory> factory( + new sk_gpu_test::GrContextFactory); + // The factory owns the context. + return factory.get()->get(sk_gpu_test::GrContextFactory::kVulkan_ContextType); +} + +GrContext* SkiaVulkanGrContext::getGrContext() +{ + static GrContext* context = createGrContext(); + return context; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx index d54120d5ffce..f908ace261a3 100644 --- a/vcl/skia/win/gdiimpl.cxx +++ b/vcl/skia/win/gdiimpl.cxx @@ -12,6 +12,7 @@ #include <tools/sk_app/win/WindowContextFactory_win.h> #include <tools/sk_app/WindowContext.h> #include <win/saldata.hxx> +#include <skia/vulkan.hxx> #include <SkColorFilter.h> #include <SkPixelRef.h> @@ -44,14 +45,30 @@ void WinSkiaSalGraphicsImpl::Init() void WinSkiaSalGraphicsImpl::createSurface() { + destroySurface(); if (isOffscreen()) + { + switch (renderMethodToUse()) + { + case RenderVulkan: + mSurface = SkSurface::MakeRenderTarget( + SkiaVulkanGrContext::getGrContext(), SkBudgeted::kNo, + SkImageInfo::MakeN32Premul(GetWidth(), GetHeight())); + assert(mSurface.get()); +#ifdef DBG_UTIL + prefillSurface(); +#endif + return; + default: + break; + } return SkiaSalGraphicsImpl::createSurface(); + } // When created, Init() gets called with size (0,0), which is invalid size // for Skia. Creating the actual surface is delayed, so the size should be always // valid here, but better check. assert(GetWidth() != 0 && GetHeight() != 0); sk_app::DisplayParams displayParams; - destroySurface(); switch (renderMethodToUse()) { case RenderRaster: diff --git a/vcl/skia/x11/gdiimpl.cxx b/vcl/skia/x11/gdiimpl.cxx index fff94936a33d..af602d35bede 100644 --- a/vcl/skia/x11/gdiimpl.cxx +++ b/vcl/skia/x11/gdiimpl.cxx @@ -21,6 +21,8 @@ #include <tools/sk_app/unix/WindowContextFactory_unix.h> #include <tools/sk_app/WindowContext.h> +#include <skia/vulkan.hxx> + X11SkiaSalGraphicsImpl::X11SkiaSalGraphicsImpl(X11SalGraphics& rParent) : SkiaSalGraphicsImpl(rParent, rParent.GetGeometryProvider()) , mX11Parent(rParent) @@ -38,8 +40,25 @@ void X11SkiaSalGraphicsImpl::Init() void X11SkiaSalGraphicsImpl::createSurface() { + destroySurface(); if (isOffscreen()) + { + switch (renderMethodToUse()) + { + case RenderVulkan: + mSurface = SkSurface::MakeRenderTarget( + SkiaVulkanGrContext::getGrContext(), SkBudgeted::kNo, + SkImageInfo::MakeN32Premul(GetWidth(), GetHeight())); + assert(mSurface.get()); +#ifdef DBG_UTIL + prefillSurface(); +#endif + return; + default: + break; + } return SkiaSalGraphicsImpl::createSurface(); + } sk_app::DisplayParams displayParams; // TODO The Skia Xlib code actually requires the non-native color type to work properly. // Use a macro to hide an unreachable code warning. @@ -59,7 +78,6 @@ void X11SkiaSalGraphicsImpl::createSurface() // Avoid this somehow. winInfo.fWidth = GetWidth(); winInfo.fHeight = GetHeight(); - destroySurface(); switch (renderMethodToUse()) { case RenderRaster: |