vcl/inc/opengl/AccumulatedTextures.hxx | 7 +++++ vcl/opengl/PackedTextureAtlas.cxx | 8 +++--- vcl/opengl/gdiimpl.cxx | 7 ++++- vcl/opengl/texture.cxx | 10 +++++--- vcl/win/source/gdi/winlayout.cxx | 39 +++++++++++++++++++++------------ 5 files changed, 46 insertions(+), 25 deletions(-)
New commits: commit 5d7badd2f2341171733c5fabf111ecf9674bc3d4 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sat Apr 30 14:58:27 2016 +0900 tdf#99258 bail out if we fail to reserve the texture + more (cherry picked from commit d22ca8d8cb050b9006720f39c612c5c32eab8795) also includes coverity fixes from commits: coverity#1358428 fix "Null pointer dereferences" 4e07c7e279b21c4ae93b832a65e221e2dab5391d cid#1358836 reorganize to silence Resource leak in object 6e970c11645f1a05638e49da9e2911fe59628838 Check if we have an OpenGL context before using API that requires it 347e46da399b8cc96d9dd8dbfd62120db473b555 opengl: Check if texture is valid before asking for Id 0214aa8ce427905477602dbf1d55278c4959fcac Change-Id: I830e313352b69a7665bff953aadb1334be0dc847 Reviewed-on: https://gerrit.libreoffice.org/24829 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tor Lillqvist <t...@collabora.com> Tested-by: Tor Lillqvist <t...@collabora.com> diff --git a/vcl/inc/opengl/AccumulatedTextures.hxx b/vcl/inc/opengl/AccumulatedTextures.hxx index e74c065..882a694 100644 --- a/vcl/inc/opengl/AccumulatedTextures.hxx +++ b/vcl/inc/opengl/AccumulatedTextures.hxx @@ -88,8 +88,11 @@ public: maEntries.clear(); } - void insert(OpenGLTexture& rTexture, const SalColor& aColor, const SalTwoRect& r2Rect) + bool insert(OpenGLTexture& rTexture, const SalColor& aColor, const SalTwoRect& r2Rect) { + if (!rTexture) + return false; + GLuint nTextureId = rTexture.Id(); if (maEntries.find(nTextureId) == maEntries.end()) @@ -100,6 +103,8 @@ public: std::unique_ptr<AccumulatedTexturesEntry>& rEntry = maEntries[nTextureId]; rEntry->insert(rTexture, aColor, r2Rect); + + return true; } AccumulatedTexturesMap& getAccumulatedTexturesMap() diff --git a/vcl/opengl/PackedTextureAtlas.cxx b/vcl/opengl/PackedTextureAtlas.cxx index 0231cbd..c8e9c3f 100644 --- a/vcl/opengl/PackedTextureAtlas.cxx +++ b/vcl/opengl/PackedTextureAtlas.cxx @@ -110,7 +110,7 @@ Node* Node::insert(int nWidth, int nHeight, int nPadding) struct PackedTexture { - ImplOpenGLTexture* mpTexture; + std::unique_ptr<ImplOpenGLTexture> mpTexture; std::unique_ptr<Node> mpRootNode; int mnDeallocatedArea; @@ -132,7 +132,7 @@ PackedTextureAtlasManager::~PackedTextureAtlasManager() for (std::unique_ptr<PackedTexture>& pPackedTexture : maPackedTextures) { // Free texture early in VCL shutdown while we have a context. - delete pPackedTexture->mpTexture; + pPackedTexture->mpTexture.reset(); } } @@ -152,7 +152,7 @@ OpenGLTexture PackedTextureAtlasManager::Reserve(int nWidth, int nHeight) Node* pNode = pPackedTexture->mpRootNode->insert(nWidth, nHeight, 1); if (pNode != nullptr) { - return OpenGLTexture(pPackedTexture->mpTexture, pNode->mRectangle, -1); + return OpenGLTexture(pPackedTexture->mpTexture.get(), pNode->mRectangle, -1); } } CreateNewTexture(); @@ -160,7 +160,7 @@ OpenGLTexture PackedTextureAtlasManager::Reserve(int nWidth, int nHeight) Node* pNode = pPackedTexture->mpRootNode->insert(nWidth, nHeight, 1); if (pNode != nullptr) { - return OpenGLTexture(pPackedTexture->mpTexture, pNode->mRectangle, -1); + return OpenGLTexture(pPackedTexture->mpTexture.get(), pNode->mRectangle, -1); } return OpenGLTexture(); } diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index d9640b9..c6139e8 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -2497,8 +2497,11 @@ void OpenGLSalGraphicsImpl::doFlush() { FlushDeferredDrawing(); - mpContext->state()->scissor().disable(); - mpContext->state()->stencil().disable(); + if (OpenGLContext::hasCurrent()) + { + mpContext->state()->scissor().disable(); + mpContext->state()->stencil().disable(); + } if( IsOffscreen() ) return; diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx index 9f5f9a2..63e39b8 100644 --- a/vcl/opengl/texture.cxx +++ b/vcl/opengl/texture.cxx @@ -413,11 +413,11 @@ void OpenGLTexture::FillCoords<GL_TRIANGLES>(std::vector<GLfloat>& aCoord, const GLfloat y1 = 0.0f; GLfloat y2 = 0.0f; - double fTextureWidth(mpImpl->mnWidth); - double fTextureHeight(mpImpl->mnHeight); - if (mpImpl) { + double fTextureWidth(mpImpl->mnWidth); + double fTextureHeight(mpImpl->mnHeight); + x1 = (maRect.Left() + rPosAry.mnSrcX) / fTextureWidth; x2 = (maRect.Left() + rPosAry.mnSrcX + rPosAry.mnSrcWidth) / fTextureWidth; @@ -472,7 +472,9 @@ void OpenGLTexture::GetWholeCoord( GLfloat* pCoord ) const OpenGLTexture OpenGLTexture::GetWholeTexture() { - return OpenGLTexture(mpImpl, Rectangle(Point(0, 0), Size(mpImpl->mnWidth, mpImpl->mnHeight)), -1); + if (mpImpl) + return OpenGLTexture(mpImpl, Rectangle(Point(0, 0), Size(mpImpl->mnWidth, mpImpl->mnHeight)), -1); + return OpenGLTexture(); } GLenum OpenGLTexture::GetFilter() const diff --git a/vcl/win/source/gdi/winlayout.cxx b/vcl/win/source/gdi/winlayout.cxx index 170c94b..360a3d3 100644 --- a/vcl/win/source/gdi/winlayout.cxx +++ b/vcl/win/source/gdi/winlayout.cxx @@ -127,10 +127,12 @@ public: gGlobalGlyphCache.get()->maGlyphCaches.erase(this); } - void ReserveTextureSpace(OpenGLGlyphDrawElement& rElement, int nWidth, int nHeight) + bool ReserveTextureSpace(OpenGLGlyphDrawElement& rElement, int nWidth, int nHeight) { GlobalGlyphCache* pGlobalGlyphCache = gGlobalGlyphCache.get(); rElement.maTexture = pGlobalGlyphCache->maPackedTextureAtlas.Reserve(nWidth, nHeight); + if (!rElement.maTexture) + return false; std::vector<GLuint> aTextureIDs = pGlobalGlyphCache->maPackedTextureAtlas.ReduceTextureNumber(8); if (!aTextureIDs.empty()) { @@ -139,6 +141,7 @@ public: pGlyphCache->RemoveTextures(aTextureIDs); } } + return true; } void RemoveTextures(std::vector<GLuint>& rTextureIDs) @@ -508,8 +511,11 @@ bool ImplWinFontEntry::CacheGlyphToAtlas(bool bRealGlyphIndices, int nGlyphIndex pTxt->ReleaseFont(); - maGlyphCache.ReserveTextureSpace(aElement, nBitmapWidth, nBitmapHeight); - aDC.copyToTexture(aElement.maTexture); + if (!maGlyphCache.ReserveTextureSpace(aElement, nBitmapWidth, nBitmapHeight)) + return false; + if (!aDC.copyToTexture(aElement.maTexture)) + return false; + maGlyphCache.PutDrawElementInCache(aElement, nGlyphIndex); SelectFont(aDC.getCompatibleHDC(), hOrigFont); @@ -1459,11 +1465,11 @@ bool SimpleWinLayout::CacheGlyphs(SalGraphics& rGraphics) const nCodePoint = mpOutGlyphs[i]; } - if (mrWinFontEntry.GetGlyphCache().IsGlyphCached(nCodePoint)) - continue; - - if (!mrWinFontEntry.CacheGlyphToAtlas(false, nCodePoint, *this, rGraphics)) - return false; + if (!mrWinFontEntry.GetGlyphCache().IsGlyphCached(nCodePoint)) + { + if (!mrWinFontEntry.CacheGlyphToAtlas(false, nCodePoint, *this, rGraphics)) + return false; + } } return true; @@ -1508,6 +1514,9 @@ bool SimpleWinLayout::DrawCachedGlyphs(SalGraphics& rGraphics) const OpenGLGlyphDrawElement& rElement(mrWinFontEntry.GetGlyphCache().GetDrawElement(nCodePoint)); OpenGLTexture& rTexture = rElement.maTexture; + if (!rTexture) + return false; + SalTwoRect a2Rects(0, 0, rTexture.GetWidth(), rTexture.GetHeight(), nAdvance + aPos.X() - rElement.getExtraOffset() + rElement.maLeftOverhangs, @@ -2729,12 +2738,11 @@ bool UniscribeLayout::CacheGlyphs(SalGraphics& rGraphics) const for (int i = 0; i < mnGlyphCount; i++) { int nCodePoint = mpOutGlyphs[i]; - - if (mrWinFontEntry.GetGlyphCache().IsGlyphCached(nCodePoint)) - continue; - - if (!mrWinFontEntry.CacheGlyphToAtlas(true, nCodePoint, *this, rGraphics)) - return false; + if (!mrWinFontEntry.GetGlyphCache().IsGlyphCached(nCodePoint)) + { + if (!mrWinFontEntry.CacheGlyphToAtlas(true, nCodePoint, *this, rGraphics)) + return false; + } } } @@ -2994,6 +3002,9 @@ bool UniscribeLayout::DrawCachedGlyphsUsingTextures(SalGraphics& rGraphics) cons OpenGLGlyphDrawElement& rElement = mrWinFontEntry.GetGlyphCache().GetDrawElement(mpOutGlyphs[i]); OpenGLTexture& rTexture = rElement.maTexture; + if (!rTexture) + return false; + if (rElement.mbVertical) { SalTwoRect a2Rects(0, 0,
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits