summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-10-08 12:19:18 +0200
committerLuboš Luňák <l.lunak@collabora.com>2019-10-10 11:17:18 +0200
commitca5dbaa1b00c93461a8f0ebcf5dc420320e13ff9 (patch)
tree485685d012cab7e61742d3af32441f10a7c83657
parentdb75c4e194cb97aa4e352fa38a45c012ce597e30 (diff)
initial implementation of Skia drawing on screen in Windowsprivate/llunak/skia
Change-Id: I1562bd2cfd1862947042bef3343aefd851a65002
-rw-r--r--external/skia/make-api-visible.patch20
-rw-r--r--vcl/Library_vclplug_win.mk2
-rw-r--r--vcl/inc/skia/salbmp.hxx2
-rw-r--r--vcl/inc/skia/win/gdiimpl.hxx53
-rw-r--r--vcl/inc/win/salinst.h1
-rw-r--r--vcl/skia/gdiimpl.cxx1
-rw-r--r--vcl/skia/salbmp.cxx1
-rw-r--r--vcl/skia/win/gdiimpl.cxx96
-rw-r--r--vcl/source/window/event.cxx7
-rw-r--r--vcl/source/window/status.cxx3
-rw-r--r--vcl/win/app/salinst.cxx14
-rw-r--r--vcl/win/gdi/salfont.cxx1
-rw-r--r--vcl/win/gdi/salgdi.cxx6
-rw-r--r--vcl/win/gdi/salgdi2.cxx9
-rw-r--r--vcl/win/gdi/salnativewidgets-luna.cxx1
-rw-r--r--vcl/win/gdi/winlayout.cxx3
16 files changed, 215 insertions, 5 deletions
diff --git a/external/skia/make-api-visible.patch b/external/skia/make-api-visible.patch
index d2c3b1f794e3..45f4ee44ae71 100644
--- a/external/skia/make-api-visible.patch
+++ b/external/skia/make-api-visible.patch
@@ -15,3 +15,23 @@
} // namespace window_context_factory
+--- skia/tools/sk_app/win/WindowContextFactory_win.h
++++ skia/tools/sk_app/win/WindowContextFactory_win.h
+@@ -18,13 +18,13 @@ struct DisplayParams;
+
+ namespace window_context_factory {
+
+-WindowContext* NewVulkanForWin(HWND, const DisplayParams&);
++SK_API WindowContext* NewVulkanForWin(HWND, const DisplayParams&);
+
+-WindowContext* NewGLForWin(HWND, const DisplayParams&);
++SK_API WindowContext* NewGLForWin(HWND, const DisplayParams&);
+
+-WindowContext* NewANGLEForWin(HWND, const DisplayParams&);
++SK_API WindowContext* NewANGLEForWin(HWND, const DisplayParams&);
+
+-WindowContext* NewRasterForWin(HWND, const DisplayParams&);
++SK_API WindowContext* NewRasterForWin(HWND, const DisplayParams&);
+
+ } // namespace window_context_factory
+
diff --git a/vcl/Library_vclplug_win.mk b/vcl/Library_vclplug_win.mk
index f64cc0392d13..a2979674d00a 100644
--- a/vcl/Library_vclplug_win.mk
+++ b/vcl/Library_vclplug_win.mk
@@ -55,10 +55,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/salbmp.hxx b/vcl/inc/skia/salbmp.hxx
index 543fbb669cf2..97a88db790c4 100644
--- a/vcl/inc/skia/salbmp.hxx
+++ b/vcl/inc/skia/salbmp.hxx
@@ -66,6 +66,8 @@ public:
const SkBitmap& GetAlphaSkBitmap() const;
+ const BitmapPalette& GetBitmapPalette() const { return mPalette; }
+
#ifdef DBG_UTIL
void dump(const char* file) const;
#endif
diff --git a/vcl/inc/skia/win/gdiimpl.hxx b/vcl/inc/skia/win/gdiimpl.hxx
new file mode 100644
index 000000000000..03f04ca4889c
--- /dev/null
+++ b/vcl/inc/skia/win/gdiimpl.hxx
@@ -0,0 +1,53 @@
+/* -*- 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 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/inc/win/salinst.h b/vcl/inc/win/salinst.h
index bcd3540ad8a9..7a0c9c51ed76 100644
--- a/vcl/inc/win/salinst.h
+++ b/vcl/inc/win/salinst.h
@@ -63,6 +63,7 @@ public:
virtual SalSystem* CreateSalSystem() override;
virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
virtual bool IsMainThread() const override;
+ std::shared_ptr<vcl::BackendCapabilities> GetBackendCapabilities() override;
virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override;
virtual bool AnyInput( VclInputFlags nType ) override;
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index c9936d675d66..8454de7bff0f 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -495,6 +495,7 @@ bool SkiaSalGraphicsImpl::drawAlphaBitmap(const SalTwoRect& rPosAry, const SalBi
&paint);
paint.setBlendMode(SkBlendMode::kSrcIn);
canvas.drawBitmap(static_cast<const SkiaSalBitmap&>(rSourceBitmap).GetSkBitmap(), 0, 0, &paint);
+ canvas.flush();
drawBitmap(rPosAry, tmpBitmap);
return true;
}
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index b066569e1a45..8c466bc87296 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -362,7 +362,6 @@ const SkBitmap& SkiaSalBitmap::GetAlphaSkBitmap() const
const_cast<SkBitmap&>(mAlphaBitmap)
.setPixelRef(sk_ref_sp(mBitmap.pixelRef()), mBitmap.pixelRefOrigin().x(),
mBitmap.pixelRefOrigin().y());
- return mAlphaBitmap;
}
}
return mAlphaBitmap;
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
new file mode 100644
index 000000000000..fa173226b871
--- /dev/null
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -0,0 +1,96 @@
+/* -*- 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::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/source/window/event.cxx b/vcl/source/window/event.cxx
index c8c6b730e1dd..f962b57c209f 100644
--- a/vcl/source/window/event.cxx
+++ b/vcl/source/window/event.cxx
@@ -22,6 +22,7 @@
#include <vcl/dockwin.hxx>
#include <vcl/layout.hxx>
#include <vcl/opengl/OpenGLWrapper.hxx>
+#include <vcl/skia/SkiaHelper.hxx>
#include <sal/log.hxx>
#include <window.h>
@@ -517,10 +518,12 @@ void Window::ImplCallResize()
#if HAVE_FEATURE_OPENGL
if( OpenGLWrapper::isVCLOpenGLEnabled() )
Invalidate();
-
- // Normally we avoid blanking on re-size unless people might notice:
else
#endif
+ if( SkiaHelper::isVCLSkiaEnabled() ) // TODO
+ Invalidate();
+ // Normally we avoid blanking on re-size unless people might notice:
+ else
if( GetBackground().IsGradient() )
Invalidate();
diff --git a/vcl/source/window/status.cxx b/vcl/source/window/status.cxx
index 61c17df48dab..deb552f8d4a8 100644
--- a/vcl/source/window/status.cxx
+++ b/vcl/source/window/status.cxx
@@ -30,6 +30,7 @@
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLWrapper.hxx>
#endif
+#include <vcl/skia/SkiaHelper.hxx>
#include <svdata.hxx>
#include <window.h>
@@ -723,6 +724,8 @@ void StatusBar::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle
if( OpenGLWrapper::isVCLOpenGLEnabled() )
bOffscreen = false;
#endif
+ if( SkiaHelper::isVCLSkiaEnabled() ) // TODO
+ bOffscreen = false;
if (!bOffscreen)
rRenderContext.Erase(rRect);
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx
index 3a5fd78f743b..54df30da1f0e 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>
@@ -967,12 +969,22 @@ 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>();
}
+std::shared_ptr<vcl::BackendCapabilities> WinSalInstance::GetBackendCapabilities()
+{
+ auto pBackendCapabilities = SalInstance::GetBackendCapabilities();
+ if( SkiaHelper::isVCLSkiaEnabled())
+ pBackendCapabilities->mbSupportsBitmap32 = true;
+ return pBackendCapabilities;
+}
+
int WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(int, LPEXCEPTION_POINTERS pExceptionInfo)
{
// Decide if an exception is a c++ (mostly UNO) exception or a process violation.
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 5a866092bf30..2218e5030e04 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 2d4a283bb818..19553f415eee 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 ceddcb5b2c8a..7e04366351f6 100644
--- a/vcl/win/gdi/salgdi2.cxx
+++ b/vcl/win/gdi/salgdi2.cxx
@@ -30,12 +30,14 @@
#include <win/salgdi.h>
#include <win/salframe.h>
#include <opengl/salbmp.hxx>
+#include <skia/salbmp.hxx>
#include <vcl/salbtype.hxx>
#include <vcl/bitmapaccess.hxx>
#include <outdata.hxx>
#include <salgdiimpl.hxx>
#include <opengl/win/gdiimpl.hxx>
+#include <skia/win/gdiimpl.hxx>
bool WinSalGraphics::supportsOperation( OutDevSupportType eType ) const
@@ -120,6 +122,11 @@ void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap)
{
aBitmapPalette = pGLSalBitmap->GetBitmapPalette();
}
+ SkiaSalBitmap* pSkiaSalBitmap = dynamic_cast<SkiaSalBitmap*>(&rSalBitmap);
+ if (pSkiaSalBitmap != nullptr) // TODO
+ {
+ aBitmapPalette = pSkiaSalBitmap->GetBitmapPalette();
+ }
BitmapBuffer* pRead = rSalBitmap.AcquireBuffer(BitmapAccessMode::Read);
@@ -165,6 +172,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());
@@ -183,6 +191,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 84a9bda35ec3..1bfc5312b9a6 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 25949dc0692e..ec8472a5256b 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -434,6 +434,7 @@ bool WinSalGraphics::DrawCachedGlyphs(const GenericSalLayout& rLayout)
COLORREF color = GetTextColor(hDC);
Color salColor = Color(GetRValue(color), GetGValue(color), GetBValue(color));
+ // TODO skia
WinOpenGLSalGraphicsImpl *pImpl = dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get());
if (!pImpl)
return false;
@@ -475,6 +476,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
@@ -523,6 +525,7 @@ void WinSalGraphics::DrawTextLayout(const GenericSalLayout& rLayout)
tools::Rectangle aRect;
rLayout.GetBoundRect(aRect);
+ // TODO skia
WinOpenGLSalGraphicsImpl *pImpl = dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get());
if (pImpl)