1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <o3tl/lru_map.hxx>
13 #include "opengl/win/gdiimpl.hxx"
15 #include <win/wincomp.hxx>
16 #include <win/saldata.hxx>
17 #include <win/salframe.h>
19 WinOpenGLSalGraphicsImpl::WinOpenGLSalGraphicsImpl(WinSalGraphics
& rGraphics
,
20 SalGeometryProvider
*mpProvider
):
21 OpenGLSalGraphicsImpl(rGraphics
,mpProvider
),
26 void WinOpenGLSalGraphicsImpl::copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
)
28 OpenGLSalGraphicsImpl
*pImpl
= pSrcGraphics
? static_cast< OpenGLSalGraphicsImpl
* >(pSrcGraphics
->GetImpl()) : static_cast< OpenGLSalGraphicsImpl
*>(mrParent
.GetImpl());
29 OpenGLSalGraphicsImpl::DoCopyBits( rPosAry
, *pImpl
);
32 rtl::Reference
<OpenGLContext
> WinOpenGLSalGraphicsImpl::CreateWinContext()
34 rtl::Reference
<OpenGLContext
> pContext
= OpenGLContext::Create();
35 pContext
->requestSingleBufferedRendering();
36 pContext
->init( mrParent
.mhLocalDC
, mrParent
.mhWnd
);
40 bool WinOpenGLSalGraphicsImpl::UseContext( const rtl::Reference
<OpenGLContext
> &pContext
)
42 if( !pContext
.is() || !pContext
->isInitialized() || IsForeignContext( pContext
) )
46 return pContext
->getOpenGLWindow().hWnd
== mrParent
.mhWnd
&&
47 pContext
->getOpenGLWindow().hDC
== mrParent
.mhLocalDC
;
50 void WinOpenGLSalGraphicsImpl::Init()
52 if ( !IsOffscreen() && mpContext
.is() && mpContext
->isInitialized() &&
53 ( mpContext
->getOpenGLWindow().hWnd
!= mrParent
.mhWnd
||
54 mpContext
->getOpenGLWindow().hDC
== mrParent
.mhLocalDC
) )
56 // This can legitimiately happen, SalFrame keeps 2x
57 // SalGraphics which share the same hWnd and hDC.
58 // The shape 'Area' dialog does reparenting to trigger this.
59 SAL_WARN("vcl.opengl", "Unusual: Windows handle / DC changed without DeInit");
63 OpenGLSalGraphicsImpl::Init();
69 typedef std::pair
<ControlCacheKey
, std::unique_ptr
<TextureCombo
>> ControlCachePair
;
70 typedef o3tl::lru_map
<ControlCacheKey
, std::unique_ptr
<TextureCombo
>, ControlCacheHashFunction
> ControlCacheType
;
72 ControlCacheType
gTextureCache(200);
76 bool WinOpenGLSalGraphicsImpl::TryRenderCachedNativeControl(ControlCacheKey
& rControlCacheKey
, int nX
, int nY
)
78 static bool gbCacheEnabled
= !getenv("SAL_WITHOUT_WIDGET_CACHE");
83 ControlCacheType::const_iterator iterator
= gTextureCache
.find(rControlCacheKey
);
85 if (iterator
== gTextureCache
.end())
88 const std::unique_ptr
<TextureCombo
>& pCombo
= iterator
->second
;
92 OpenGLTexture
& rTexture
= *pCombo
->mpTexture
;
94 SalTwoRect
aPosAry(0, 0, rTexture
.GetWidth(), rTexture
.GetHeight(),
95 nX
, nY
, rTexture
.GetWidth(), rTexture
.GetHeight());
98 DrawTextureDiff(rTexture
, *pCombo
->mpMask
, aPosAry
);
100 DrawTexture(rTexture
, aPosAry
);
107 bool WinOpenGLSalGraphicsImpl::RenderCompatibleDC(OpenGLCompatibleDC
& rWhite
, OpenGLCompatibleDC
& rBlack
,
108 int nX
, int nY
, TextureCombo
& rCombo
)
112 rCombo
.mpTexture
.reset(rWhite
.getTexture());
113 rCombo
.mpMask
.reset(rBlack
.getTexture());
116 if (rCombo
.mpTexture
&& rCombo
.mpMask
)
118 OpenGLTexture
& rTexture
= *rCombo
.mpTexture
;
120 SalTwoRect
aPosAry(0, 0, rTexture
.GetWidth(), rTexture
.GetHeight(),
121 nX
, nY
, rTexture
.GetWidth(), rTexture
.GetHeight());
123 DrawTextureDiff(*rCombo
.mpTexture
, *rCombo
.mpMask
, aPosAry
);
130 bool WinOpenGLSalGraphicsImpl::RenderAndCacheNativeControl(OpenGLCompatibleDC
& rWhite
, OpenGLCompatibleDC
& rBlack
,
131 int nX
, int nY
, ControlCacheKey
& aControlCacheKey
)
133 std::unique_ptr
<TextureCombo
> pCombo(new TextureCombo
);
135 bool bResult
= RenderCompatibleDC(rWhite
, rBlack
, nX
, nY
, *pCombo
);
139 if (!aControlCacheKey
.canCacheControl())
142 ControlCachePair
pair(aControlCacheKey
, std::move(pCombo
));
143 gTextureCache
.insert(std::move(pair
));
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */