diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-10-08 12:19:18 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-11-27 09:55:07 +0100 |
commit | 71a07e886c61b47370ddaaf1b3d4b88971ef9efc (patch) | |
tree | a90d1b4084925f707a6b1f31f7ca3f218f0c0a0e /vcl | |
parent | 3027980cdfaa954e4b4c244d3cd493923077d359 (diff) |
initial implementation of Skia drawing on screen in Windows
Change-Id: I1562bd2cfd1862947042bef3343aefd851a65002
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vclplug_win.mk | 2 | ||||
-rw-r--r-- | vcl/inc/skia/win/gdiimpl.hxx | 54 | ||||
-rw-r--r-- | vcl/skia/win/gdiimpl.cxx | 103 | ||||
-rw-r--r-- | vcl/win/app/salinst.cxx | 6 | ||||
-rw-r--r-- | vcl/win/gdi/salfont.cxx | 1 | ||||
-rw-r--r-- | vcl/win/gdi/salgdi.cxx | 6 | ||||
-rw-r--r-- | vcl/win/gdi/salgdi2.cxx | 3 | ||||
-rw-r--r-- | vcl/win/gdi/salnativewidgets-luna.cxx | 1 | ||||
-rw-r--r-- | vcl/win/gdi/winlayout.cxx | 3 |
9 files changed, 177 insertions, 2 deletions
diff --git a/vcl/Library_vclplug_win.mk b/vcl/Library_vclplug_win.mk index 2b05aae476b3..a062ebcafabd 100644 --- a/vcl/Library_vclplug_win.mk +++ b/vcl/Library_vclplug_win.mk @@ -57,10 +57,12 @@ $(eval $(call gb_Library_use_externals,vclplug_win,\ epoxy \ glm_headers \ harfbuzz \ + skia \ )) $(eval $(call gb_Library_add_exception_objects,vclplug_win,\ vcl/opengl/win/gdiimpl \ + vcl/skia/win/gdiimpl \ vcl/win/app/saldata \ vcl/win/app/salinfo \ vcl/win/app/salinst \ diff --git a/vcl/inc/skia/win/gdiimpl.hxx b/vcl/inc/skia/win/gdiimpl.hxx new file mode 100644 index 000000000000..621d8d4b4a78 --- /dev/null +++ b/vcl/inc/skia/win/gdiimpl.hxx @@ -0,0 +1,54 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_VCL_INC_SKIA_WIN_GDIIMPL_HXX +#define INCLUDED_VCL_INC_SKIA_WIN_GDIIMPL_HXX + +#include <memory> +#include <vcl/dllapi.h> + +#include <skia/gdiimpl.hxx> +#include <win/salgdi.h> + +class ControlCacheKey; +namespace sk_app +{ +class WindowContext; +} + +class WinSkiaSalGraphicsImpl : public SkiaSalGraphicsImpl +{ +private: + WinSalGraphics& mWinParent; + +public: + WinSkiaSalGraphicsImpl(WinSalGraphics& rGraphics, SalGeometryProvider* mpProvider); + + virtual void Init() override; + virtual void DeInit() override; + virtual void copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) override; + + virtual void freeResources() override; + + bool TryRenderCachedNativeControl(ControlCacheKey const& rControlCacheKey, int nX, int nY); + + bool RenderAndCacheNativeControl(OpenGLCompatibleDC& rWhite, OpenGLCompatibleDC& rBlack, int nX, + int nY, ControlCacheKey& aControlCacheKey); + +protected: + virtual void createSurface() override; + virtual void performFlush() override; + +private: + std::unique_ptr<sk_app::WindowContext> mWindowContext; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx new file mode 100644 index 000000000000..0763334f0ebf --- /dev/null +++ b/vcl/skia/win/gdiimpl.cxx @@ -0,0 +1,103 @@ +/* -*- 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/. + */ + +#include <skia/win/gdiimpl.hxx> + +#include <tools/sk_app/win/WindowContextFactory_win.h> +#include <tools/sk_app/WindowContext.h> + +WinSkiaSalGraphicsImpl::WinSkiaSalGraphicsImpl(WinSalGraphics& rGraphics, + SalGeometryProvider* mpProvider) + : SkiaSalGraphicsImpl(rGraphics, mpProvider) + , mWinParent(rGraphics) +{ +} + +void WinSkiaSalGraphicsImpl::copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) +{ + (void)rPosAry; + (void)pSrcGraphics; + // TODO +} + +void WinSkiaSalGraphicsImpl::Init() +{ +#if 0 // TODO + if (!IsOffscreen() && mpContext.is() && mpContext->isInitialized()) + { + const GLWinWindow& rGLWindow = static_cast<const GLWinWindow&>(mpContext->getOpenGLWindow()); + if (rGLWindow.hWnd != mrWinParent.mhWnd || rGLWindow.hDC == mrWinParent.mhLocalDC) + { + // This can legitimately happen, SalFrame keeps 2x + // SalGraphics which share the same hWnd and hDC. + // The shape 'Area' dialog does reparenting to trigger this. + SAL_WARN("vcl.opengl", "Unusual: Windows handle / DC changed without DeInit"); + DeInit(); + } + } +#endif + SkiaSalGraphicsImpl::Init(); +} + +void WinSkiaSalGraphicsImpl::createSurface() +{ + if (isOffscreen()) + return SkiaSalGraphicsImpl::createSurface(); + if (GetWidth() == 0 || GetHeight() == 0) + { + // When created, Init() gets called with size (0,0), which is invalid size + // for Skia. So fake a surface, Init() will get called later again with the correct size. + mSurface = SkSurface::MakeRasterN32Premul(1, 1); + return; + } + sk_app::DisplayParams displayParams; + mWindowContext.reset( + sk_app::window_context_factory::NewRasterForWin(mWinParent.gethWnd(), displayParams)); + assert(SkToBool(mWindowContext)); // TODO + mSurface = mWindowContext->getBackbufferSurface(); + assert(mSurface.get()); +} + +void WinSkiaSalGraphicsImpl::DeInit() +{ + mWindowContext.reset(); + SkiaSalGraphicsImpl::DeInit(); +} + +void WinSkiaSalGraphicsImpl::freeResources() {} + +void WinSkiaSalGraphicsImpl::performFlush() +{ + if (mWindowContext) + mWindowContext->swapBuffers(); +} + +bool WinSkiaSalGraphicsImpl::TryRenderCachedNativeControl(ControlCacheKey const& rControlCacheKey, + int nX, int nY) +{ + (void)rControlCacheKey; + (void)nX; + (void)nY; + return false; // TODO +} + +// TODO OpenGLCompatibleDC? +bool WinSkiaSalGraphicsImpl::RenderAndCacheNativeControl(OpenGLCompatibleDC& rWhite, + OpenGLCompatibleDC& rBlack, int nX, int nY, + ControlCacheKey& aControlCacheKey) +{ + (void)rWhite; + (void)rBlack; + (void)nX; + (void)nY; + (void)aControlCacheKey; + return false; // TODO +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx index 2cf9a4f57d9c..20c6d3c8a9f7 100644 --- a/vcl/win/app/salinst.cxx +++ b/vcl/win/app/salinst.cxx @@ -32,11 +32,13 @@ #include <vcl/inputtypes.hxx> #include <vcl/opengl/OpenGLHelper.hxx> #include <vcl/opengl/OpenGLContext.hxx> +#include <vcl/skia/SkiaHelper.hxx> #include <vcl/timer.hxx> #include <vclpluginapi.h> #include <opengl/salbmp.hxx> #include <opengl/win/gdiimpl.hxx> +#include <skia/salbmp.hxx> #include <win/wincomp.hxx> #include <win/salids.hrc> #include <win/saldata.hxx> @@ -965,7 +967,9 @@ SalTimer* WinSalInstance::CreateSalTimer() std::shared_ptr<SalBitmap> WinSalInstance::CreateSalBitmap() { - if (OpenGLHelper::isVCLOpenGLEnabled()) + if (SkiaHelper::isVCLSkiaEnabled()) + return std::make_shared<SkiaSalBitmap>(); + else if (OpenGLHelper::isVCLOpenGLEnabled()) return std::make_shared<OpenGLSalBitmap>(); else return std::make_shared<WinSalBitmap>(); diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index 0a962c49f8db..5716b69a676b 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -781,6 +781,7 @@ void ImplGetLogFontFromFontSelect( HDC hDC, static BYTE nDefaultQuality = NONANTIALIASED_QUALITY; if (nDefaultQuality == NONANTIALIASED_QUALITY) { + // TODO SKIA if (OpenGLWrapper::isVCLOpenGLEnabled()) nDefaultQuality = ANTIALIASED_QUALITY; else diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx index c8b1aa4471e7..8503af1c04ad 100644 --- a/vcl/win/gdi/salgdi.cxx +++ b/vcl/win/gdi/salgdi.cxx @@ -35,8 +35,10 @@ #include <salgdiimpl.hxx> #include "gdiimpl.hxx" #include <opengl/win/gdiimpl.hxx> +#include <skia/win/gdiimpl.hxx> #include <vcl/opengl/OpenGLHelper.hxx> +#include <vcl/skia/SkiaHelper.hxx> #define DITHER_PAL_DELTA 51 @@ -619,7 +621,9 @@ WinSalGraphics::WinSalGraphics(WinSalGraphics::Type eType, bool bScreen, HWND hW mpStdClipRgnData(nullptr), mnPenWidth(GSL_PEN_WIDTH) { - if (OpenGLHelper::isVCLOpenGLEnabled() && !mbPrinter) + if (SkiaHelper::isVCLSkiaEnabled() && !mbPrinter) + mpImpl.reset(new WinSkiaSalGraphicsImpl(*this, pProvider)); + else if (OpenGLHelper::isVCLOpenGLEnabled() && !mbPrinter) mpImpl.reset(new WinOpenGLSalGraphicsImpl(*this, pProvider)); else mpImpl.reset(new WinSalGraphicsImpl(*this)); diff --git a/vcl/win/gdi/salgdi2.cxx b/vcl/win/gdi/salgdi2.cxx index 9c8e9845ff91..795cc4d08284 100644 --- a/vcl/win/gdi/salgdi2.cxx +++ b/vcl/win/gdi/salgdi2.cxx @@ -39,6 +39,7 @@ #include <outdata.hxx> #include <salgdiimpl.hxx> #include <opengl/win/gdiimpl.hxx> +#include <skia/win/gdiimpl.hxx> bool WinSalGraphics::supportsOperation( OutDevSupportType eType ) const @@ -168,6 +169,7 @@ void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap) void WinSalGraphics::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) { if (dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get()) == nullptr && + dynamic_cast<WinSkiaSalGraphicsImpl*>(mpImpl.get()) == nullptr && dynamic_cast<const WinSalBitmap*>(&rSalBitmap) == nullptr) { std::unique_ptr<WinSalBitmap> pWinSalBitmap(new WinSalBitmap()); @@ -186,6 +188,7 @@ void WinSalGraphics::drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSTransparentBitmap ) { if (dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get()) == nullptr && + dynamic_cast<WinSkiaSalGraphicsImpl*>(mpImpl.get()) == nullptr && dynamic_cast<const WinSalBitmap*>(&rSSalBitmap) == nullptr) { std::unique_ptr<WinSalBitmap> pWinSalBitmap(new WinSalBitmap()); diff --git a/vcl/win/gdi/salnativewidgets-luna.cxx b/vcl/win/gdi/salnativewidgets-luna.cxx index 2eb7161974f8..12338c69f34f 100644 --- a/vcl/win/gdi/salnativewidgets-luna.cxx +++ b/vcl/win/gdi/salnativewidgets-luna.cxx @@ -1159,6 +1159,7 @@ bool WinSalGraphics::drawNativeControl( ControlType nType, tools::Rectangle cacheRect = rControlRegion; Size keySize = cacheRect.GetSize(); + // TODO SKIA WinOpenGLSalGraphicsImpl* pImpl = dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get()); // tdf#95618 - A few controls render outside the region they're given. diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx index 9f4da1950245..7fa273a79c97 100644 --- a/vcl/win/gdi/winlayout.cxx +++ b/vcl/win/gdi/winlayout.cxx @@ -477,6 +477,7 @@ bool WinSalGraphics::DrawCachedGlyphs(const GenericSalLayout& rLayout) COLORREF color = GetTextColor(hDC); Color salColor(GetRValue(color), GetGValue(color), GetBValue(color)); + // TODO SKIA WinOpenGLSalGraphicsImpl *pImpl = dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get()); if (!pImpl) return false; @@ -518,6 +519,7 @@ void WinSalGraphics::DrawTextLayout(const GenericSalLayout& rLayout) const WinFontInstance* pWinFont = static_cast<const WinFontInstance*>(&rLayout.GetFont()); const HFONT hLayoutFont = pWinFont->GetHFONT(); + // TODO SKIA bool bUseOpenGL = OpenGLHelper::isVCLOpenGLEnabled() && !mbPrinter; // Our DirectWrite renderer is incomplete, skip it for vertical text where glyphs are not @@ -566,6 +568,7 @@ void WinSalGraphics::DrawTextLayout(const GenericSalLayout& rLayout) tools::Rectangle aRect; rLayout.GetBoundRect(aRect); + // TODO SKIA WinOpenGLSalGraphicsImpl *pImpl = dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get()); if (pImpl) |