/* -*- 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 #include #include #include "opengl/framebuffer.hxx" #include "opengl/texture.hxx" #include "opengl/PackedTextureAtlas.hxx" struct Node { Rectangle mRectangle; std::unique_ptr mLeftNode; std::unique_ptr mRightNode; bool mOccupied; explicit Node(int nWidth, int nHeight); explicit Node(Rectangle& aRectangle); bool isLeaf(); Node* insert(int nWidth, int nHeight, int nPadding); }; Node::Node(int nWidth, int nHeight) : mRectangle(Rectangle(Point(), Size(nWidth, nHeight))) , mLeftNode() , mRightNode() , mOccupied(false) {} Node::Node(Rectangle& aRectangle) : mRectangle(aRectangle) , mLeftNode() , mRightNode() , mOccupied(false) {} bool Node::isLeaf() { return mLeftNode.get() == nullptr && mRightNode.get() == 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; Rectangle aLeftRect; Rectangle aRightRect; if (dw > dh) { aLeftRect = Rectangle(Point(mRectangle.Left(), mRectangle.Top()), Size(nWidth, mRectangle.GetHeight())); aRightRect = Rectangle(Point(nPadding + mRectangle.Left() + nWidth, mRectangle.Top()), Size(mRectangle.GetWidth() - nWidth - nPadding, mRectangle.GetHeight())); } else { aLeftRect = Rectangle(Point(mRectangle.Left(), mRectangle.Top()), Size(mRectangle.GetWidth(), nHeight)); aRightRect = 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 PackedTexture { std::shared_ptr mpTexture; std::unique_ptr mpRootNode; PackedTexture(int nWidth, int nHeight) : mpTexture(new ImplOpenGLTexture(nWidth, nHeight, true)) , mpRootNode(new Node(nWidth, nHeight)) {} }; PackedTextureAtlasManager::PackedTextureAtlasManager(int nTextureWidth, int nTextureHeight) : mnTextureWidth(nTextureWidth) , mnTextureHeight(nTextureHeight) { } PackedTextureAtlasManager::~PackedTextureAtlasManager() { for (std::unique_ptr& pPackedTexture : maPackedTextures) { // Free texture early in VCL shutdown while we have a context. pPackedTexture->mpTexture.reset(); } } void PackedTextureAtlasManager::CreateNewTexture() { std::unique_ptr pPackedTexture(new PackedTexture(mnTextureWidth, mnTextureHeight)); GLuint nTextureID = pPackedTexture->mpTexture->mnTexture; maPackedTextures.push_back(std::move(pPackedTexture)); VCL_GL_INFO("PackedTextureAtlas::CreateNewTexture adding texture: " << nTextureID << " atlases: " << maPackedTextures.size()); } OpenGLTexture PackedTextureAtlasManager::Reserve(int nWidth, int nHeight) { for (std::unique_ptr& pPackedTexture : maPackedTextures) { Node* pNode = pPackedTexture->mpRootNode->insert(nWidth, nHeight, 1); if (pNode != nullptr) { return OpenGLTexture(pPackedTexture->mpTexture, pNode->mRectangle, -1); } } CreateNewTexture(); std::unique_ptr& pPackedTexture = maPackedTextures.back(); Node* pNode = pPackedTexture->mpRootNode->insert(nWidth, nHeight, 1); if (pNode != nullptr) { return OpenGLTexture(pPackedTexture->mpTexture, pNode->mRectangle, -1); } return OpenGLTexture(); } OpenGLTexture PackedTextureAtlasManager::InsertBuffer(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData) { OpenGLTexture aTexture = Reserve(nWidth, nHeight); if (aTexture && pData == nullptr) return aTexture; aTexture.CopyData(nWidth, nHeight, nFormat, nType, pData); return aTexture; } std::vector PackedTextureAtlasManager::ReduceTextureNumber(int nMaxNumberOfTextures) { std::vector aTextureIDs; while (int(maPackedTextures.size()) > nMaxNumberOfTextures) { // Remove oldest created texture GLuint nTextureID = maPackedTextures[0]->mpTexture->mnTexture; aTextureIDs.push_back(nTextureID); maPackedTextures.erase(maPackedTextures.begin()); VCL_GL_INFO("PackedTextureAtlas::ReduceTextureNumber removing texture: " << nTextureID << " atlases: " << maPackedTextures.size()); } return aTextureIDs; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ value='distro/collabora/viewer2'>distro/collabora/viewer2 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2020-06-04Upcoming loplugin:elidestringvar: i18npoolStephan Bergmann
2020-03-23sw: add pad-to-5 numberingMiklos Vajna
2020-03-20sw pad-to-4 numbering: add doc model, UNO API and layoutMiklos Vajna
2020-03-17sw pad-to-3 numbering: add doc model, UNO API and layoutMiklos Vajna
2020-03-03sw padded numbering: add layoutMiklos Vajna
2019-12-03Adapt CPPUNIT_ASSERT to C++20 deleted ostream << for sal_Unicode (aka char16_t)Stephan Bergmann
2019-10-23size some stringbuffer to prevent re-allocNoel Grandin
2019-10-17Rename OUStringLiteral1 to OUStringCharStephan Bergmann
2019-06-27Ditch "using namespace U_ICU_NAMESPACE;", qualify icu:: insteadEike Rathke
2019-05-28tdf#42949 Fix IWYU warnings in i18npool/Gabor Kelemen
2018-09-18loplugin:useuniqueptr in TestTextSearchNoel Grandin
2018-06-01loplugin: look for CPPUNIT_ASSERT_EQUALS with params swappedNoel Grandin
2018-05-22tdf#113694 Fix BreakIterator_CTL surrogate pairsKhaled Hosny
2018-01-15More loplugin:cstylecast: i18npoolStephan Bergmann
2018-01-12More loplugin:cstylecast: i18npoolStephan Bergmann
2017-10-04tdf#96197 do not break Korean words in the middle.Mark Hung
2017-07-18loplugin:constparams in i18npool,opencl,svlNoel Grandin
2017-06-25loplugin:oncevar in helpcompiler..jvmfwkNoel Grandin
2017-06-08remove some unnecessary use of OUStringBufferNoel Grandin
2017-04-28loplugin:salunicodeliteral: i18npoolStephan Bergmann
2017-04-04make UNO enums scoped for internal LO codeNoel Grandin
2017-03-28tdf#106755: Fix script type for combining marksKhaled Hosny
2017-03-01Blind fix for 32-bit buildsStephan Bergmann
2017-03-01typesafe wrappers for css::i18nutil::TransliterationModulesNoel Grandin
2016-10-06coverity#1373441 Side effect in assertionCaolán McNamara
2016-10-01silence coverity#1373441 Side effect in assertionCaolán McNamara
2016-09-30i18npool: fix loplugin:cppunitassertequals warningsMiklos Vajna
2016-08-30loplugin:stringconstant: adapt to improved OUStringLiteral1 (i18npool)Stephan Bergmann
2016-07-22crashtesting: fix tdf92993-1.docx failureCaolán McNamara
2016-04-24unit test for tdf#99468Eike Rathke
2016-02-23SearchFlags::WILD_MATCH_SELECTION, SearchOptions2::WildcardEscapeCharacterEike Rathke
2016-02-17wildcard search unit tests, tdf#72196Eike Rathke
2015-11-23tdf#94810: fix reverse offset mappingMike Kaganski
2015-11-04use uno::Reference::set method instead of assignmentNoel Grandin
2015-10-12Replace "SAL_OVERRIDE" with "override" in LIBO_INTERNAL_ONLY codeStephan Bergmann
2015-09-03Related: tdf#52020 Disable ICU Breakiterator for KhmerNathan Wells
2015-08-18i18npool: tdf#88206 replace cppu::WeakImplHelper*Takeshi Abe
2015-06-25loplugin:stringconstant: Flag more inefficienciesStephan Bergmann
2015-06-02loplugin:cstylecast: deal with those that are (technically) const_castStephan Bergmann