summaryrefslogtreecommitdiff
path: root/vcl/skia
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2020-04-24 16:58:09 +0000
committerLuboš Luňák <l.lunak@collabora.com>2020-05-04 21:46:46 +0200
commit16ab4c5cc82829927c2e876af7e511c0f1fb6284 (patch)
tree05b6f44a2c441bec31f23c7cd8654b99685c5b13 /vcl/skia
parent603df08a1e0211099ce2cf258cfe64a74ed6ded9 (diff)
remove old Skia text render methods that do not use Skia directly
The cairo-based method on Unix and manual glyph handling way taken from GL on Windows should be longer be needed, now that using Skia itself for text rendering seems to work fine. This reverts more or less reverts the following commits: b1d3ef798a89d11b853c467fa9ce0fe6ed235735 5ac9a62f3a354db80837bdd1c95b763989b303bb 619959827003814053a5e9ec81acfd07b3aa270a 6f5c85daa0e5073d87d1d7699bfa59af159686ca ad3580df085b3a3d66eb73cae997ea5ca178ccc1 f109a1ac6fdf0c878d53dfea6fceffd93248608f 59205c742c43b4c456b69c3fd94e7fa35ff3eec0 Change-Id: Ib28b2469c7d6471c227bb2aa08d5485bb24c2fe1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93428 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/skia')
-rw-r--r--vcl/skia/gdiimpl.cxx34
-rw-r--r--vcl/skia/packedsurfaceatlas.cxx175
-rw-r--r--vcl/skia/win/gdiimpl.cxx46
-rw-r--r--vcl/skia/win/winlayout.cxx65
-rw-r--r--vcl/skia/x11/cairotextrender.cxx92
-rw-r--r--vcl/skia/x11/gdiimpl.cxx1
6 files changed, 0 insertions, 413 deletions
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index efecb95b7920..bd55aaf8a044 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -198,7 +198,6 @@ SkiaSalGraphicsImpl::SkiaSalGraphicsImpl(SalGraphics& rParent, SalGeometryProvid
, mFillColor(SALCOLOR_NONE)
, mXorMode(false)
, mFlush(new SkiaFlushIdle(this))
- , mPendingPixelsToFlush(0)
{
}
@@ -338,20 +337,6 @@ void SkiaSalGraphicsImpl::postDraw()
else if (!mFlush->IsActive())
mFlush->Start();
}
- // Skia (at least when using Vulkan) queues drawing commands and executes them only later.
- // But some operations may queue way too much data to draw, leading to Vulkan getting out of memory,
- // which at least on Linux leads to driver problems affecting even the whole X11 session.
- // One such problematic operation may be drawBitmap(SkBitmap), which is used by SkiaX11CairoTextRender
- // to draw text, which is internally done by creating the SkBitmap from cairo surface data. Apparently
- // the cairo surface's size matches the size of the destination (window), which may be large,
- // and each text drawing allocates a new surface (and thus SkBitmap). So we may end up queueing up
- // millions of pixels of bitmap data. So force a flush if such a possibly problematic operation
- // has queued up too much data.
- if (mPendingPixelsToFlush > 10 * 1024 * 1024)
- {
- mSurface->flush();
- mPendingPixelsToFlush = 0;
- }
SkiaZone::leave(); // matched in preDraw()
}
@@ -1301,25 +1286,6 @@ void SkiaSalGraphicsImpl::drawImage(const SalTwoRect& rPosAry, const sk_sp<SkIma
postDraw();
}
-void SkiaSalGraphicsImpl::drawBitmap(const SalTwoRect& rPosAry, const SkBitmap& aBitmap,
- SkBlendMode eBlendMode)
-{
- SkRect aSourceRect
- = SkRect::MakeXYWH(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight);
- SkRect aDestinationRect = SkRect::MakeXYWH(rPosAry.mnDestX, rPosAry.mnDestY,
- rPosAry.mnDestWidth, rPosAry.mnDestHeight);
-
- SkPaint aPaint;
- aPaint.setBlendMode(eBlendMode);
-
- preDraw();
- SAL_INFO("vcl.skia.trace", "drawbitmap(" << this << "): " << rPosAry << ":" << int(eBlendMode));
- getDrawCanvas()->drawBitmapRect(aBitmap, aSourceRect, aDestinationRect, &aPaint);
- addXorRegion(aDestinationRect);
- mPendingPixelsToFlush += aBitmap.width() * aBitmap.height();
- postDraw();
-}
-
bool SkiaSalGraphicsImpl::drawTransformedBitmap(const basegfx::B2DPoint& rNull,
const basegfx::B2DPoint& rX,
const basegfx::B2DPoint& rY,
diff --git a/vcl/skia/packedsurfaceatlas.cxx b/vcl/skia/packedsurfaceatlas.cxx
deleted file mode 100644
index 7f358c30eb94..000000000000
--- a/vcl/skia/packedsurfaceatlas.cxx
+++ /dev/null
@@ -1,175 +0,0 @@
-/* -*- 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/packedsurfaceatlas.hxx>
-
-#include <memory>
-#include <assert.h>
-
-#include <sal/config.h>
-#include <sal/log.hxx>
-
-#include <skia/utils.hxx>
-
-namespace
-{
-struct Node
-{
- tools::Rectangle const mRectangle;
- std::unique_ptr<Node> mLeftNode;
- std::unique_ptr<Node> mRightNode;
- bool mOccupied;
-
- explicit Node(int nWidth, int nHeight);
- explicit Node(tools::Rectangle const& aRectangle);
-
- bool isLeaf() const;
- Node* insert(int nWidth, int nHeight, int nPadding);
-};
-}
-
-Node::Node(int nWidth, int nHeight)
- : mRectangle(tools::Rectangle(Point(), Size(nWidth, nHeight)))
- , mLeftNode()
- , mRightNode()
- , mOccupied(false)
-{
-}
-
-Node::Node(tools::Rectangle const& aRectangle)
- : mRectangle(aRectangle)
- , mLeftNode()
- , mRightNode()
- , mOccupied(false)
-{
-}
-
-bool Node::isLeaf() const { return mLeftNode == nullptr && mRightNode == nullptr; }
-
-Node* Node::insert(int nWidth, int nHeight, int nPadding)
-{
- if (!isLeaf())
- {
- Node* pNewNode = mLeftNode->insert(nWidth, nHeight, nPadding);
-
- if (pNewNode != nullptr)
- return pNewNode;
-
- return mRightNode->insert(nWidth, nHeight, nPadding);
- }
- else
- {
- if (mOccupied)
- {
- return nullptr;
- }
-
- if (nWidth > mRectangle.GetWidth() || nHeight > mRectangle.GetHeight())
- { // does not fit
- return nullptr;
- }
-
- if (nWidth == mRectangle.GetWidth() && nHeight == mRectangle.GetHeight())
- { // perfect fit
- mOccupied = true;
- return this;
- }
-
- int dw = mRectangle.GetWidth() - nWidth;
- int dh = mRectangle.GetHeight() - nHeight;
-
- tools::Rectangle aLeftRect;
- tools::Rectangle aRightRect;
- if (dw > dh)
- {
- aLeftRect = tools::Rectangle(Point(mRectangle.Left(), mRectangle.Top()),
- Size(nWidth, mRectangle.GetHeight()));
- aRightRect = tools::Rectangle(
- Point(nPadding + mRectangle.Left() + nWidth, mRectangle.Top()),
- Size(mRectangle.GetWidth() - nWidth - nPadding, mRectangle.GetHeight()));
- }
- else
- {
- aLeftRect = tools::Rectangle(Point(mRectangle.Left(), mRectangle.Top()),
- Size(mRectangle.GetWidth(), nHeight));
- aRightRect = tools::Rectangle(
- Point(mRectangle.Left(), nPadding + mRectangle.Top() + nHeight),
- Size(mRectangle.GetWidth(), mRectangle.GetHeight() - nHeight - nPadding));
- }
-
- mLeftNode.reset(new Node(aLeftRect));
- mRightNode.reset(new Node(aRightRect));
-
- return mLeftNode->insert(nWidth, nHeight, nPadding);
- }
-}
-
-struct SkiaPackedSurfaceAtlasManager::PackedSurface
-{
- sk_sp<SkSurface> mpSurface;
- std::unique_ptr<Node> mpRootNode;
-
- PackedSurface(int nWidth, int nHeight)
- : mpSurface(SkiaHelper::createSkSurface(nWidth, nHeight))
- , mpRootNode(new Node(nWidth, nHeight))
- {
- assert(mpSurface);
- }
-};
-
-SkiaPackedSurfaceAtlasManager::SkiaPackedSurfaceAtlasManager(int nSurfaceWidth, int nSurfaceHeight)
- : mnSurfaceWidth(nSurfaceWidth)
- , mnSurfaceHeight(nSurfaceHeight)
-{
-}
-
-SkiaPackedSurfaceAtlasManager::~SkiaPackedSurfaceAtlasManager() {}
-
-void SkiaPackedSurfaceAtlasManager::CreateNewSurface()
-{
- std::unique_ptr<PackedSurface> pPackedSurface(
- new PackedSurface(mnSurfaceWidth, mnSurfaceHeight));
- maPackedSurfaces.push_back(std::move(pPackedSurface));
- SAL_INFO("vcl.skia.trace",
- "SkiaPackedSurfaceAtlas adding surface, count: " << maPackedSurfaces.size());
-}
-
-SkiaPackedSurface SkiaPackedSurfaceAtlasManager::Reserve(int nWidth, int nHeight)
-{
- for (std::unique_ptr<PackedSurface>& pPackedSurface : maPackedSurfaces)
- {
- Node* pNode = pPackedSurface->mpRootNode->insert(nWidth, nHeight, 1);
- if (pNode != nullptr)
- return SkiaPackedSurface(pPackedSurface->mpSurface, pNode->mRectangle);
- }
- CreateNewSurface();
- std::unique_ptr<PackedSurface>& pPackedSurface = maPackedSurfaces.back();
- Node* pNode = pPackedSurface->mpRootNode->insert(nWidth, nHeight, 1);
- if (pNode != nullptr)
- return SkiaPackedSurface(pPackedSurface->mpSurface, pNode->mRectangle);
- return SkiaPackedSurface();
-}
-
-std::vector<sk_sp<SkSurface>>
-SkiaPackedSurfaceAtlasManager::ReduceSurfaceNumber(int nMaxNumberOfSurfaces)
-{
- std::vector<sk_sp<SkSurface>> aSurfaces;
- while (int(maPackedSurfaces.size()) > nMaxNumberOfSurfaces)
- {
- // Remove oldest created surface
- aSurfaces.push_back(maPackedSurfaces[0]->mpSurface);
- maPackedSurfaces.erase(maPackedSurfaces.begin());
- SAL_INFO("vcl.skia.trace",
- "PackedSurfaceAtlas removing surface, count: " << maPackedSurfaces.size());
- }
- return aSurfaces;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index f65eb7cc69eb..6129c8e266da 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -17,7 +17,6 @@
#include <comphelper/windowserrorstring.hxx>
#include <SkCanvas.h>
-#include <SkColorFilter.h>
#include <SkPaint.h>
#include <SkPixelRef.h>
#include <SkTypeface_win.h>
@@ -66,7 +65,6 @@ void WinSkiaSalGraphicsImpl::freeResources() {}
void WinSkiaSalGraphicsImpl::performFlush()
{
SkiaZone zone;
- mPendingPixelsToFlush = 0;
if (mWindowContext)
mWindowContext->swapBuffers();
}
@@ -237,50 +235,6 @@ void WinSkiaSalGraphicsImpl::ClearDevFontCache()
fontEdgingDone = false;
}
-void WinSkiaSalGraphicsImpl::PreDrawText() { preDraw(); }
-
-void WinSkiaSalGraphicsImpl::PostDrawText() { postDraw(); }
-
-static SkColor toSkColor(Color color)
-{
- return SkColorSetARGB(255 - color.GetTransparency(), color.GetRed(), color.GetGreen(),
- color.GetBlue());
-}
-
-void WinSkiaSalGraphicsImpl::DeferredTextDraw(const CompatibleDC::Texture* pTexture,
- Color aMaskColor, const SalTwoRect& rPosAry)
-{
- assert(dynamic_cast<const SkiaCompatibleDC::PackedTexture*>(pTexture));
- const SkiaCompatibleDC::PackedTexture* texture
- = static_cast<const SkiaCompatibleDC::PackedTexture*>(pTexture);
- preDraw();
- SkPaint paint;
- // The glyph is painted as white, modulate it to be of the appropriate color.
- // SkiaCompatibleDC::wantsTextColorWhite() ensures the glyph is white.
- // TODO maybe other black/white in WinFontInstance::CacheGlyphToAtlas() should be swapped.
- paint.setColorFilter(SkColorFilters::Blend(toSkColor(aMaskColor), SkBlendMode::kModulate));
- // We use SkiaPackedSurface, so use also the appropriate rectangle in the source SkSurface.
- const tools::Rectangle& rect = texture->packedSurface.mRect;
- // The source in SalTwoRect is actually just the size.
- assert(rPosAry.mnSrcX == 0 && rPosAry.mnSrcY == 0);
- assert(rPosAry.mnSrcWidth == rect.GetWidth());
- assert(rPosAry.mnSrcHeight == rect.GetHeight());
- mSurface->getCanvas()->drawImageRect(
- texture->packedSurface.mSurface->makeImageSnapshot(),
- SkRect::MakeXYWH(rect.getX(), rect.getY(), rect.GetWidth(), rect.GetHeight()),
- SkRect::MakeXYWH(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth,
- rPosAry.mnDestHeight),
- &paint);
- postDraw();
-}
-
-void WinSkiaSalGraphicsImpl::DrawTextMask(CompatibleDC::Texture* pTexture, Color nMaskColor,
- const SalTwoRect& rPosAry)
-{
- assert(dynamic_cast<SkiaCompatibleDC::Texture*>(pTexture));
- drawMask(rPosAry, static_cast<const SkiaCompatibleDC::Texture*>(pTexture)->image, nMaskColor);
-}
-
SkiaCompatibleDC::SkiaCompatibleDC(SalGraphics& rGraphics, int x, int y, int width, int height)
: CompatibleDC(rGraphics, x, y, width, height, false)
{
diff --git a/vcl/skia/win/winlayout.cxx b/vcl/skia/win/winlayout.cxx
deleted file mode 100644
index da8a9f6cf2be..000000000000
--- a/vcl/skia/win/winlayout.cxx
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- 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/winlayout.hxx>
-
-#include <skia/win/gdiimpl.hxx>
-
-#include <SkCanvas.h>
-#include <SkPaint.h>
-
-bool SkiaGlobalWinGlyphCache::AllocateTexture(WinGlyphDrawElement& rElement, CompatibleDC* dc)
-{
- assert(rElement.maTexture.get() == nullptr);
- assert(dynamic_cast<SkiaCompatibleDC*>(dc));
- SkiaCompatibleDC* sdc = static_cast<SkiaCompatibleDC*>(dc);
- SkiaCompatibleDC::PackedTexture* texture = new SkiaCompatibleDC::PackedTexture;
- rElement.maTexture.reset(texture);
- texture->packedSurface
- = mPackedSurfaceAtlas.Reserve(sdc->getBitmapWidth(), sdc->getBitmapHeight());
- if (!texture->packedSurface.mSurface)
- return false;
- // Draw the dc's content to the reserved place in the atlas.
- SkCanvas* canvas = texture->packedSurface.mSurface->getCanvas();
- const tools::Rectangle& rect = texture->packedSurface.mRect;
- SkPaint paint;
- paint.setBlendMode(SkBlendMode::kSrc); // copy as is
- canvas->drawImageRect(
- sdc->getAsImage(),
- SkRect::MakeXYWH(rect.getX(), rect.getY(), rect.GetWidth(), rect.GetHeight()), &paint);
- return true;
-}
-
-void SkiaGlobalWinGlyphCache::Prune()
-{
- std::vector<sk_sp<SkSurface>> aSurfaces = mPackedSurfaceAtlas.ReduceSurfaceNumber(8);
- if (!aSurfaces.empty())
- {
- for (auto& pWinGlyphCache : maWinGlyphCaches)
- static_cast<SkiaWinGlyphCache*>(pWinGlyphCache)->RemoveSurfaces(aSurfaces);
- }
-}
-
-void SkiaWinGlyphCache::RemoveSurfaces(const std::vector<sk_sp<SkSurface>>& surfaces)
-{
- auto it = maWinTextureCache.begin();
- while (it != maWinTextureCache.end())
- {
- assert(dynamic_cast<SkiaCompatibleDC::PackedTexture*>(it->second.maTexture.get()));
- sk_sp<SkSurface> surface
- = static_cast<SkiaCompatibleDC::PackedTexture*>(it->second.maTexture.get())
- ->packedSurface.mSurface;
- if (std::find(surfaces.begin(), surfaces.end(), surface) != surfaces.end())
- it = maWinTextureCache.erase(it);
- else
- ++it;
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/skia/x11/cairotextrender.cxx b/vcl/skia/x11/cairotextrender.cxx
deleted file mode 100644
index eb05134e3a74..000000000000
--- a/vcl/skia/x11/cairotextrender.cxx
+++ /dev/null
@@ -1,92 +0,0 @@
-/* -*- 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/x11/cairotextrender.hxx>
-
-#include <salbmp.hxx>
-#include <skia/gdiimpl.hxx>
-#include <osl/endian.h>
-
-#include <cairo.h>
-
-SkiaX11CairoTextRender::SkiaX11CairoTextRender(X11SalGraphics& rParent)
- : X11CairoTextRender(rParent)
-{
-}
-
-cairo_t* SkiaX11CairoTextRender::getCairoContext()
-{
- cairo_surface_t* surface = nullptr;
- SkiaSalGraphicsImpl* pImpl = dynamic_cast<SkiaSalGraphicsImpl*>(mrParent.GetImpl());
- if (pImpl)
- {
- tools::Rectangle aClipRect = pImpl->getClipRegion().GetBoundRect();
- if (aClipRect.IsEmpty())
- {
- aClipRect.setWidth(GetWidth());
- aClipRect.setHeight(GetHeight());
- }
- surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, aClipRect.GetWidth(),
- aClipRect.GetHeight());
- }
- if (!surface)
- return nullptr;
- cairo_t* cr = cairo_create(surface);
- cairo_surface_destroy(surface);
- return cr;
-}
-
-void SkiaX11CairoTextRender::getSurfaceOffset(double& nDX, double& nDY)
-{
- SkiaSalGraphicsImpl* pImpl = dynamic_cast<SkiaSalGraphicsImpl*>(mrParent.GetImpl());
- if (pImpl)
- {
- tools::Rectangle aClipRect = pImpl->getClipRegion().GetBoundRect();
- nDX = -aClipRect.Left();
- nDY = -aClipRect.Top();
- }
-}
-
-void SkiaX11CairoTextRender::releaseCairoContext(cairo_t* cr)
-{
- SkiaSalGraphicsImpl* pImpl = dynamic_cast<SkiaSalGraphicsImpl*>(mrParent.GetImpl());
- if (!pImpl)
- {
- cairo_destroy(cr);
- return;
- }
-
- cairo_surface_t* pSurface = cairo_get_target(cr);
- int nWidth = cairo_image_surface_get_width(pSurface);
- int nHeight = cairo_image_surface_get_height(pSurface);
- cairo_surface_flush(pSurface);
- unsigned char* pSrc = cairo_image_surface_get_data(pSurface);
-
- tools::Rectangle aClipRect = pImpl->getClipRegion().GetBoundRect();
-
- SalTwoRect aRect(0, 0, nWidth, nHeight, aClipRect.Left(), aClipRect.Top(), nWidth, nHeight);
-
- SkImageInfo info;
-#ifdef OSL_LITENDIAN
- info = SkImageInfo::Make(nWidth, nHeight, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
-#else
- info = SkImageInfo::Make(nWidth, nHeight, kARGB_8888_SkColorType, kPremul_SkAlphaType);
-#endif
- SkBitmap bitmap;
- if (!bitmap.installPixels(info, pSrc, nWidth * 4))
- abort();
- bitmap.setImmutable();
-
- pImpl->drawBitmap(aRect, bitmap);
-
- bitmap.reset();
- cairo_destroy(cr);
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/skia/x11/gdiimpl.cxx b/vcl/skia/x11/gdiimpl.cxx
index 0ed4b6a0ccbd..4754bfc64f95 100644
--- a/vcl/skia/x11/gdiimpl.cxx
+++ b/vcl/skia/x11/gdiimpl.cxx
@@ -128,7 +128,6 @@ void X11SkiaSalGraphicsImpl::freeResources() {}
void X11SkiaSalGraphicsImpl::performFlush()
{
SkiaZone zone;
- mPendingPixelsToFlush = 0;
// TODO XPutImage() is somewhat inefficient, XShmPutImage() should be preferred.
mWindowContext->swapBuffers();
}