summaryrefslogtreecommitdiff
path: root/vcl/inc/win/winlayout.hxx
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/inc/win/winlayout.hxx
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/inc/win/winlayout.hxx')
-rw-r--r--vcl/inc/win/winlayout.hxx83
1 files changed, 21 insertions, 62 deletions
diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
index 035998e2bcd9..aef394fa83e3 100644
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -26,8 +26,6 @@
#include <svsys.h>
#include <win/salgdi.h>
-#include <opengl/PackedTextureAtlas.hxx>
-
class WinFontInstance;
namespace
@@ -38,11 +36,11 @@ const int GLYPH_SPACE_RATIO = 8;
const int GLYPH_OFFSET_RATIO = GLYPH_SPACE_RATIO * 2;
}
-struct OpenGLGlyphDrawElement
+struct WinGlyphDrawElement
{
tools::Rectangle maLocation;
int maLeftOverhangs;
- OpenGLTexture maTexture;
+ std::unique_ptr<CompatibleDC::Texture> maTexture;
int mnBaselineOffset;
int mnHeight;
bool mbVertical;
@@ -58,87 +56,48 @@ struct OpenGLGlyphDrawElement
}
};
-class OpenGLGlyphCache;
+class WinGlyphCache;
-struct GlobalOpenGLGlyphCache
+struct GlobalWinGlyphCache
{
- GlobalOpenGLGlyphCache()
- : maPackedTextureAtlas(2048, 2048)
- {}
+ std::unordered_set<WinGlyphCache*> maWinGlyphCaches;
- PackedTextureAtlasManager maPackedTextureAtlas;
- std::unordered_set<OpenGLGlyphCache*> maOpenGLGlyphCaches;
+ static GlobalWinGlyphCache * get();
- static GlobalOpenGLGlyphCache * get();
+ virtual bool AllocateTexture(WinGlyphDrawElement& rElement, int nWidth, int nHeight) = 0;
};
-class OpenGLGlyphCache
+class WinGlyphCache
{
-private:
- std::unordered_map<int, OpenGLGlyphDrawElement> maOpenGLTextureCache;
+protected:
+ std::unordered_map<int, WinGlyphDrawElement> maWinTextureCache;
public:
- OpenGLGlyphCache()
- {
- GlobalOpenGLGlyphCache::get()->maOpenGLGlyphCaches.insert(this);
- }
-
- ~OpenGLGlyphCache()
- {
- GlobalOpenGLGlyphCache::get()->maOpenGLGlyphCaches.erase(this);
- }
-
- static bool ReserveTextureSpace(OpenGLGlyphDrawElement& rElement, int nWidth, int nHeight)
+ WinGlyphCache()
{
- GlobalOpenGLGlyphCache* pGlobalOpenGLGlyphCache = GlobalOpenGLGlyphCache::get();
- rElement.maTexture = pGlobalOpenGLGlyphCache->maPackedTextureAtlas.Reserve(nWidth, nHeight);
- if (!rElement.maTexture)
- return false;
- std::vector<GLuint> aTextureIDs = pGlobalOpenGLGlyphCache->maPackedTextureAtlas.ReduceTextureNumber(8);
- if (!aTextureIDs.empty())
- {
- for (auto& pOpenGLGlyphCache: pGlobalOpenGLGlyphCache->maOpenGLGlyphCaches)
- {
- pOpenGLGlyphCache->RemoveTextures(aTextureIDs);
- }
- }
- return true;
+ GlobalWinGlyphCache::get()->maWinGlyphCaches.insert(this);
}
- void RemoveTextures(std::vector<GLuint>& rTextureIDs)
+ virtual ~WinGlyphCache()
{
- auto it = maOpenGLTextureCache.begin();
-
- while (it != maOpenGLTextureCache.end())
- {
- GLuint nTextureID = it->second.maTexture.Id();
-
- if (std::find(rTextureIDs.begin(), rTextureIDs.end(), nTextureID) != rTextureIDs.end())
- {
- it = maOpenGLTextureCache.erase(it);
- }
- else
- {
- ++it;
- }
- }
+ GlobalWinGlyphCache::get()->maWinGlyphCaches.erase(this);
}
- void PutDrawElementInCache(const OpenGLGlyphDrawElement& rElement, int nGlyphIndex)
+ void PutDrawElementInCache(WinGlyphDrawElement&& rElement, int nGlyphIndex)
{
assert(!IsGlyphCached(nGlyphIndex));
- maOpenGLTextureCache[nGlyphIndex] = rElement;
+ maWinTextureCache[nGlyphIndex] = std::move( rElement );
}
- OpenGLGlyphDrawElement& GetDrawElement(int nGlyphIndex)
+ WinGlyphDrawElement& GetDrawElement(int nGlyphIndex)
{
assert(IsGlyphCached(nGlyphIndex));
- return maOpenGLTextureCache[nGlyphIndex];
+ return maWinTextureCache[nGlyphIndex];
}
bool IsGlyphCached(int nGlyphIndex) const
{
- return maOpenGLTextureCache.find(nGlyphIndex) != maOpenGLTextureCache.end();
+ return maWinTextureCache.find(nGlyphIndex) != maWinTextureCache.end();
}
};
@@ -167,7 +126,7 @@ public:
WinFontFace * GetFontFace() { return static_cast<WinFontFace *>(LogicalFontInstance::GetFontFace()); }
bool CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, SalGraphics& rGraphics, const GenericSalLayout& rLayout);
- OpenGLGlyphCache& GetOpenGLGlyphCache() { return maOpenGLGlyphCache; }
+ WinGlyphCache& GetWinGlyphCache() { return maWinGlyphCache; }
bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const override;
@@ -180,7 +139,7 @@ private:
WinSalGraphics *m_pGraphics;
HFONT m_hFont;
float m_fScale;
- OpenGLGlyphCache maOpenGLGlyphCache;
+ WinGlyphCache maWinGlyphCache;
};
class TextOutRenderer