summaryrefslogtreecommitdiff
path: root/vcl/opengl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-10-15 16:17:26 +0200
committerLuboš Luňák <l.lunak@collabora.com>2019-11-27 09:55:08 +0100
commitb6cbf5dbd067c63f94872e31f2332e95edc201dd (patch)
treec169fd52f259038dca208c2bcc6904f38163fb1b /vcl/opengl
parent8fa83a3265e25b164cb11d598f1fbb49a7b8fbf1 (diff)
refactor Windows OpenGLGlyphCache stuff to be reusable for Skia
Basically just remove 'OpenGL' from names of most of the classes, turn them into base classes that have OpenGL subclasses that actually implement the functionality. Change-Id: Idf1f347cebc2a417bda37d6955201c775ecb0890
Diffstat (limited to 'vcl/opengl')
-rw-r--r--vcl/opengl/gdiimpl.cxx6
-rw-r--r--vcl/opengl/win/gdiimpl.cxx67
-rw-r--r--vcl/opengl/win/winlayout.cxx56
3 files changed, 119 insertions, 10 deletions
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 30d2299978ea..0f0e40dd7eaa 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -1324,12 +1324,6 @@ void OpenGLSalGraphicsImpl::DrawMask( OpenGLTexture& rMask, Color nMaskColor, co
mpProgram->Clean();
}
-void OpenGLSalGraphicsImpl::DeferredTextDraw(OpenGLTexture const & rTexture, Color aMaskColor, const SalTwoRect& rPosAry)
-{
- mpRenderList->addDrawTextureWithMaskColor(rTexture, aMaskColor, rPosAry);
- PostBatchDraw();
-}
-
void OpenGLSalGraphicsImpl::FlushLinesOrTriangles(DrawShaderType eType, RenderParameters const & rParameters)
{
if (!UseProgram("combinedVertexShader", "combinedFragmentShader", "#define USE_VERTEX_COLORS"))
diff --git a/vcl/opengl/win/gdiimpl.cxx b/vcl/opengl/win/gdiimpl.cxx
index b0d1188519c2..d71a03714198 100644
--- a/vcl/opengl/win/gdiimpl.cxx
+++ b/vcl/opengl/win/gdiimpl.cxx
@@ -756,6 +756,37 @@ ControlCacheType & TheTextureCache::get() {
return data->m_pTextureCache->cache;
}
+OpenGLCompatibleDC::OpenGLCompatibleDC(SalGraphics &rGraphics, int x, int y, int width, int height)
+: CompatibleDC( rGraphics, x, y, width, height, false )
+{
+}
+
+OpenGLTexture* OpenGLCompatibleDC::getOpenGLTexture()
+{
+ if (!mpImpl)
+ return nullptr;
+
+ // turn what's in the mpData into a texture
+ return new OpenGLTexture(maRects.mnSrcWidth, maRects.mnSrcHeight, GL_BGRA, GL_UNSIGNED_BYTE, mpData);
+}
+
+std::unique_ptr<CompatibleDC::Texture> OpenGLCompatibleDC::getTexture()
+{
+ auto ret = std::make_unique<OpenGLCompatibleDC::Texture>();
+ ret->texture = OpenGLTexture(maRects.mnSrcWidth, maRects.mnSrcHeight, GL_BGRA, GL_UNSIGNED_BYTE, mpData);
+ return ret;
+}
+
+bool OpenGLCompatibleDC::copyToTexture(CompatibleDC::Texture& aTexture)
+{
+ if (!mpImpl)
+ return false;
+
+ assert(dynamic_cast<OpenGLCompatibleDC::Texture*>(&aTexture));
+ return static_cast<OpenGLCompatibleDC::Texture&>(aTexture).texture.CopyData(
+ maRects.mnSrcWidth, maRects.mnSrcHeight, GL_BGRA, GL_UNSIGNED_BYTE, reinterpret_cast<sal_uInt8*>(mpData));
+}
+
bool WinOpenGLSalGraphicsImpl::TryRenderCachedNativeControl(ControlCacheKey const & rControlCacheKey, int nX, int nY)
{
static bool gbCacheEnabled = !getenv("SAL_WITHOUT_WIDGET_CACHE");
@@ -801,8 +832,8 @@ bool WinOpenGLSalGraphicsImpl::RenderCompatibleDC(OpenGLCompatibleDC& rWhite, Op
PreDraw();
- rCombo.mpTexture.reset(rWhite.getTexture());
- rCombo.mpMask.reset(rBlack.getTexture());
+ rCombo.mpTexture.reset(rWhite.getOpenGLTexture());
+ rCombo.mpMask.reset(rBlack.getOpenGLTexture());
bRet = RenderTextureCombo(rCombo, nX, nY);
@@ -810,12 +841,16 @@ bool WinOpenGLSalGraphicsImpl::RenderCompatibleDC(OpenGLCompatibleDC& rWhite, Op
return bRet;
}
-bool WinOpenGLSalGraphicsImpl::RenderAndCacheNativeControl(OpenGLCompatibleDC& rWhite, OpenGLCompatibleDC& rBlack,
+bool WinOpenGLSalGraphicsImpl::RenderAndCacheNativeControl(CompatibleDC& rWhite, CompatibleDC& rBlack,
int nX, int nY , ControlCacheKey& aControlCacheKey)
{
+ assert(dynamic_cast<OpenGLCompatibleDC*>(&rWhite));
+ assert(dynamic_cast<OpenGLCompatibleDC*>(&rBlack));
+
std::unique_ptr<TextureCombo> pCombo(new TextureCombo);
- bool bResult = RenderCompatibleDC(rWhite, rBlack, nX, nY, *pCombo);
+ bool bResult = RenderCompatibleDC(static_cast<OpenGLCompatibleDC&>(rWhite),
+ static_cast<OpenGLCompatibleDC&>(rBlack), nX, nY, *pCombo);
if (!bResult)
return false;
@@ -828,4 +863,28 @@ bool WinOpenGLSalGraphicsImpl::RenderAndCacheNativeControl(OpenGLCompatibleDC& r
return bResult;
}
+void WinOpenGLSalGraphicsImpl::PreDrawText()
+{
+ PreDraw();
+}
+
+void WinOpenGLSalGraphicsImpl::PostDrawText()
+{
+ PostDraw();
+}
+
+void WinOpenGLSalGraphicsImpl::DeferredTextDraw(const CompatibleDC::Texture* pTexture, Color aMaskColor, const SalTwoRect& rPosAry)
+{
+ assert(dynamic_cast<const OpenGLCompatibleDC::Texture*>(pTexture));
+ mpRenderList->addDrawTextureWithMaskColor(
+ static_cast<const OpenGLCompatibleDC::Texture*>(pTexture)->texture, aMaskColor, rPosAry);
+ PostBatchDraw();
+}
+
+void WinOpenGLSalGraphicsImpl::DrawMask( CompatibleDC::Texture* pTexture, Color nMaskColor, const SalTwoRect& rPosAry )
+{
+ assert(dynamic_cast<OpenGLCompatibleDC::Texture*>(pTexture));
+ DrawMask( static_cast<OpenGLCompatibleDC::Texture*>(pTexture)->texture, nMaskColor, rPosAry );
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/win/winlayout.cxx b/vcl/opengl/win/winlayout.cxx
new file mode 100644
index 000000000000..ddc72c8b28cf
--- /dev/null
+++ b/vcl/opengl/win/winlayout.cxx
@@ -0,0 +1,56 @@
+/* -*- 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 <opengl/win/winlayout.hxx>
+
+#include <opengl/win/gdiimpl.hxx>
+
+bool OpenGLGlobalWinGlyphCache::AllocateTexture(WinGlyphDrawElement& rElement, int nWidth,
+ int nHeight)
+{
+ assert(rElement.maTexture.get() == nullptr);
+ OpenGLCompatibleDC::Texture* texture = new OpenGLCompatibleDC::Texture;
+ rElement.maTexture.reset(texture);
+ texture->texture = maPackedTextureAtlas.Reserve(nWidth, nHeight);
+ if (!texture->texture)
+ return false;
+ std::vector<GLuint> aTextureIDs = maPackedTextureAtlas.ReduceTextureNumber(8);
+ if (!aTextureIDs.empty())
+ {
+ for (auto& pWinGlyphCache : maWinGlyphCaches)
+ {
+ assert(dynamic_cast<OpenGLWinGlyphCache*>(pWinGlyphCache));
+ static_cast<OpenGLWinGlyphCache*>(pWinGlyphCache)->RemoveTextures(aTextureIDs);
+ }
+ }
+ return true;
+}
+
+void OpenGLWinGlyphCache::RemoveTextures(std::vector<GLuint>& rTextureIDs)
+{
+ auto it = maWinTextureCache.begin();
+
+ while (it != maWinTextureCache.end())
+ {
+ assert(dynamic_cast<OpenGLCompatibleDC::Texture*>(it->second.maTexture.get()));
+ GLuint nTextureID
+ = static_cast<OpenGLCompatibleDC::Texture*>(it->second.maTexture.get())->texture.Id();
+
+ if (std::find(rTextureIDs.begin(), rTextureIDs.end(), nTextureID) != rTextureIDs.end())
+ {
+ it = maWinTextureCache.erase(it);
+ }
+ else
+ {
+ ++it;
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */