vcl/inc/skia/utils.hxx       |    5 +++++
 vcl/inc/skia/win/gdiimpl.hxx |    5 +----
 vcl/skia/SkiaHelper.cxx      |   22 +++++++++++++++-------
 vcl/skia/gdiimpl.cxx         |    6 ++++--
 vcl/skia/win/gdiimpl.cxx     |   29 ++++++++++-------------------
 5 files changed, 35 insertions(+), 32 deletions(-)

New commits:
commit 1724b7a2cb16336b2c6e066504708396b8ecfa32
Author:     Luboš Luňák <l.lu...@centrum.cz>
AuthorDate: Mon Nov 16 11:14:33 2020 +0000
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Tue Nov 17 10:55:19 2020 +0100

    set Skia pixel geometry for every surface
    
    Skia update chrome/m88 removed the possibility to call
    SkFontLCDConfig::SetSubpixelOrder() to set subpixel setup for all
    surfaces. So I guess now we have to explicitly pass SkSurfaceProps
    to every single SkSurface we create.
    
    Change-Id: I15be37ba9301c92d0cb109e88f3d1396a7223208
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105922
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/vcl/inc/skia/utils.hxx b/vcl/inc/skia/utils.hxx
index 00feccedfdae..03e01d2e5d8b 100644
--- a/vcl/inc/skia/utils.hxx
+++ b/vcl/inc/skia/utils.hxx
@@ -75,6 +75,11 @@ sk_sp<SkImage> findCachedImage(const OString& key);
 void removeCachedImage(sk_sp<SkImage> image);
 constexpr int MAX_CACHE_SIZE = 4 * 2000 * 2000 * 4; // 4x 2000px 32bpp images, 
64MiB
 
+// SkSurfaceProps to be used by all Skia surfaces.
+VCL_DLLPUBLIC const SkSurfaceProps* surfaceProps();
+// Set pixel geometry to be used by SkSurfaceProps.
+VCL_DLLPUBLIC void setPixelGeometry(SkPixelGeometry pixelGeometry);
+
 #ifdef DBG_UTIL
 void prefillSurface(const sk_sp<SkSurface>& surface);
 VCL_DLLPUBLIC void dump(const SkBitmap& bitmap, const char* file);
diff --git a/vcl/inc/skia/win/gdiimpl.hxx b/vcl/inc/skia/win/gdiimpl.hxx
index 26ca29eaee7b..167b57147bf3 100644
--- a/vcl/inc/skia/win/gdiimpl.hxx
+++ b/vcl/inc/skia/win/gdiimpl.hxx
@@ -76,15 +76,12 @@ protected:
     virtual void createWindowContext(bool forceRaster = false) override;
     virtual void performFlush() override;
     sk_sp<SkTypeface> createDirectWriteTypeface(const LOGFONTW& logFont);
-    SkFont::Edging getFontEdging();
-    void initFontInfo();
+    static void initFontInfo();
     IDWriteFactory* dwriteFactory;
     IDWriteGdiInterop* dwriteGdiInterop;
     sk_sp<SkFontMgr> dwriteFontMgr;
     bool dwriteDone = false;
     static SkFont::Edging fontEdging;
-    static SkPixelGeometry pixelGeometry;
-    static bool fontInfoDone;
 };
 
 typedef std::pair<ControlCacheKey, sk_sp<SkImage>> SkiaControlCachePair;
diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx
index 3adef6a9afd2..b3aa5a1d1cbc 100644
--- a/vcl/skia/SkiaHelper.cxx
+++ b/vcl/skia/SkiaHelper.cxx
@@ -392,9 +392,9 @@ sk_sp<SkSurface> createSkSurface(int width, int height, 
SkColorType type, SkAlph
         {
             if (GrDirectContext* grDirectContext = getSharedGrDirectContext())
             {
-                surface
-                    = SkSurface::MakeRenderTarget(grDirectContext, 
SkBudgeted::kNo,
-                                                  SkImageInfo::Make(width, 
height, type, alpha));
+                surface = SkSurface::MakeRenderTarget(grDirectContext, 
SkBudgeted::kNo,
+                                                      SkImageInfo::Make(width, 
height, type, alpha),
+                                                      0, surfaceProps());
                 if (surface)
                 {
 #ifdef DBG_UTIL
@@ -411,7 +411,7 @@ sk_sp<SkSurface> createSkSurface(int width, int height, 
SkColorType type, SkAlph
             break;
     }
     // Create raster surface as a fallback.
-    surface = SkSurface::MakeRaster(SkImageInfo::Make(width, height, type, 
alpha));
+    surface = SkSurface::MakeRaster(SkImageInfo::Make(width, height, type, 
alpha), surfaceProps());
     assert(surface);
     if (surface)
     {
@@ -435,9 +435,9 @@ sk_sp<SkImage> createSkImage(const SkBitmap& bitmap)
         {
             if (GrDirectContext* grDirectContext = getSharedGrDirectContext())
             {
-                sk_sp<SkSurface> surface
-                    = SkSurface::MakeRenderTarget(grDirectContext, 
SkBudgeted::kNo,
-                                                  
bitmap.info().makeAlphaType(kPremul_SkAlphaType));
+                sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(
+                    grDirectContext, SkBudgeted::kNo,
+                    bitmap.info().makeAlphaType(kPremul_SkAlphaType), 0, 
surfaceProps());
                 if (surface)
                 {
                     SkPaint paint;
@@ -563,6 +563,14 @@ void cleanup()
     imageCacheSize = 0;
 }
 
+static SkSurfaceProps commonSurfaceProps;
+const SkSurfaceProps* surfaceProps() { return &commonSurfaceProps; }
+
+void setPixelGeometry(SkPixelGeometry pixelGeometry)
+{
+    commonSurfaceProps = SkSurfaceProps(commonSurfaceProps.flags(), 
pixelGeometry);
+}
+
 // Skia should not be used from VCL backends that do not actually support it, 
as there will be setup missing.
 // The code here (that is in the vcl lib) needs a function for creating Vulkan 
context that is
 // usually available only in the backend libs.
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index c2e96cd44576..e339171d9d80 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -1403,7 +1403,8 @@ void SkiaSalGraphicsImpl::invert(basegfx::B2DPolygon 
const& rPoly, SalInvert eFl
             SkRect area;
             aPath.getBounds().roundOut(&area);
             SkRect size = SkRect::MakeWH(area.width(), area.height());
-            sk_sp<SkSurface> surface = 
SkSurface::MakeRasterN32Premul(area.width(), area.height());
+            sk_sp<SkSurface> surface = 
SkSurface::MakeRasterN32Premul(area.width(), area.height(),
+                                                                      
SkiaHelper::surfaceProps());
             SkPaint copy;
             copy.setBlendMode(SkBlendMode::kSrc);
             flushDrawing();
@@ -1450,7 +1451,8 @@ void SkiaSalGraphicsImpl::invert(basegfx::B2DPolygon 
const& rPoly, SalInvert eFl
             SkRect area;
             aPath.getBounds().roundOut(&area);
             SkRect size = SkRect::MakeWH(area.width(), area.height());
-            sk_sp<SkSurface> surface = 
SkSurface::MakeRasterN32Premul(area.width(), area.height());
+            sk_sp<SkSurface> surface = 
SkSurface::MakeRasterN32Premul(area.width(), area.height(),
+                                                                      
SkiaHelper::surfaceProps());
             SkPaint copy;
             copy.setBlendMode(SkBlendMode::kSrc);
             flushDrawing();
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index 759ff1d477ec..d170fa121ec8 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -38,9 +38,7 @@ void WinSkiaSalGraphicsImpl::createWindowContext(bool 
forceRaster)
 {
     SkiaZone zone;
     sk_app::DisplayParams displayParams;
-    initFontInfo();
-    displayParams.fSurfaceProps
-        = SkSurfaceProps(displayParams.fSurfaceProps.flags(), pixelGeometry);
+    displayParams.fSurfaceProps = *SkiaHelper::surfaceProps();
     switch (forceRaster ? SkiaHelper::RenderRaster : 
SkiaHelper::renderMethodToUse())
     {
         case SkiaHelper::RenderRaster:
@@ -201,7 +199,7 @@ bool WinSkiaSalGraphicsImpl::DrawTextLayout(const 
GenericSalLayout& rLayout)
     if (fontHeight < 0)
         fontHeight = -fontHeight;
     SkFont font(typeface, fontHeight, fHScale, 0);
-    font.setEdging(getFontEdging());
+    font.setEdging(fontEdging);
     assert(dynamic_cast<SkiaSalGraphicsImpl*>(mWinParent.GetImpl()));
     SkiaSalGraphicsImpl* impl = 
static_cast<SkiaSalGraphicsImpl*>(mWinParent.GetImpl());
     COLORREF color = ::GetTextColor(mWinParent.getHDC());
@@ -212,19 +210,9 @@ bool WinSkiaSalGraphicsImpl::DrawTextLayout(const 
GenericSalLayout& rLayout)
 }
 
 SkFont::Edging WinSkiaSalGraphicsImpl::fontEdging;
-SkPixelGeometry WinSkiaSalGraphicsImpl::pixelGeometry;
-bool WinSkiaSalGraphicsImpl::fontInfoDone = false;
-
-SkFont::Edging WinSkiaSalGraphicsImpl::getFontEdging()
-{
-    initFontInfo();
-    return fontEdging;
-}
 
 void WinSkiaSalGraphicsImpl::initFontInfo()
 {
-    if (fontInfoDone)
-        return;
     // Skia needs to be explicitly told what kind of antialiasing should be 
used,
     // get it from system settings. This does not actually matter for the text
     // rendering itself, since Skia has been patched to simply use the setting
@@ -234,7 +222,7 @@ void WinSkiaSalGraphicsImpl::initFontInfo()
     // the glyphs will be rendered based on this setting (subpixel AA requires 
colors,
     // others do not).
     fontEdging = SkFont::Edging::kAlias;
-    pixelGeometry = kUnknown_SkPixelGeometry;
+    SkPixelGeometry pixelGeometry = kUnknown_SkPixelGeometry;
     BOOL set;
     if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &set, 0) && set)
     {
@@ -253,15 +241,14 @@ void WinSkiaSalGraphicsImpl::initFontInfo()
         else
             fontEdging = SkFont::Edging::kAntiAlias;
     }
-    // Cache this, it is actually visible a little bit when profiling.
-    fontInfoDone = true;
+    SkiaHelper::setPixelGeometry(pixelGeometry);
 }
 
 void WinSkiaSalGraphicsImpl::ClearDevFontCache()
 {
     dwriteFontMgr.reset();
     dwriteDone = false;
-    fontInfoDone = false;
+    initFontInfo(); // get font info again, just in case
 }
 
 SkiaCompatibleDC::SkiaCompatibleDC(SalGraphics& rGraphics, int x, int y, int 
width, int height)
@@ -408,6 +395,10 @@ std::unique_ptr<sk_app::WindowContext> 
createVulkanWindowContext(bool /*temporar
 }
 }
 
-void WinSkiaSalGraphicsImpl::prepareSkia() { 
SkiaHelper::prepareSkia(createVulkanWindowContext); }
+void WinSkiaSalGraphicsImpl::prepareSkia()
+{
+    initFontInfo();
+    SkiaHelper::prepareSkia(createVulkanWindowContext);
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to