summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-05-04 13:54:37 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-05-04 15:29:53 +0200
commit7f0b5f8eb234d2e1cc40055b275799df503ea736 (patch)
treeb3e6bbecd261bc4dbaaf987514e463064707d677
parentc46a231b987b92bd866b415d1a0ba0d3a26a2457 (diff)
Use sal::systools::COMReference and drop dxcanvas::COMReference
Change-Id: I352147dd86d8ba73da1706c42c885bef0f11b2cd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115071 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--canvas/source/directx/dx_9rm.cxx44
-rw-r--r--canvas/source/directx/dx_rendermodule.hxx2
-rw-r--r--canvas/source/directx/dx_surfacebitmap.cxx4
-rw-r--r--canvas/source/directx/dx_surfacebitmap.hxx4
-rw-r--r--canvas/source/directx/dx_surfacegraphics.cxx6
-rw-r--r--canvas/source/directx/dx_surfacegraphics.hxx2
-rw-r--r--canvas/source/directx/dx_winstuff.hxx86
7 files changed, 34 insertions, 114 deletions
diff --git a/canvas/source/directx/dx_9rm.cxx b/canvas/source/directx/dx_9rm.cxx
index 0c8667c5f7ea..65499f2b55fe 100644
--- a/canvas/source/directx/dx_9rm.cxx
+++ b/canvas/source/directx/dx_9rm.cxx
@@ -111,7 +111,7 @@ namespace dxcanvas
};
DXRenderModule& mrRenderModule;
- COMReference<IDirect3DTexture9> mpTexture;
+ sal::systools::COMReference<IDirect3DTexture9> mpTexture;
::basegfx::B2IVector maSize;
};
@@ -130,7 +130,7 @@ namespace dxcanvas
virtual void lock() const override { maMutex.acquire(); }
virtual void unlock() const override { maMutex.release(); }
- virtual COMReference<IDirect3DSurface9>
+ virtual sal::systools::COMReference<IDirect3DSurface9>
createSystemMemorySurface( const ::basegfx::B2IVector& rSize ) override;
virtual void disposing() override;
virtual HWND getHWND() const override { return mhWnd; }
@@ -147,7 +147,7 @@ namespace dxcanvas
virtual void pushVertex( const ::canvas::Vertex& vertex ) override;
virtual bool isError() override;
- COMReference<IDirect3DDevice9> getDevice() { return mpDevice; }
+ sal::systools::COMReference<IDirect3DDevice9> getDevice() { return mpDevice; }
void flushVertexCache();
void commitVertexCache();
@@ -166,10 +166,10 @@ namespace dxcanvas
static ::osl::Mutex maMutex;
HWND mhWnd;
- COMReference<IDirect3DDevice9> mpDevice;
- COMReference<IDirect3D9> mpDirect3D9;
- COMReference<IDirect3DSwapChain9> mpSwapChain;
- COMReference<IDirect3DVertexBuffer9> mpVertexBuffer;
+ sal::systools::COMReference<IDirect3DDevice9> mpDevice;
+ sal::systools::COMReference<IDirect3D9> mpDirect3D9;
+ sal::systools::COMReference<IDirect3DSwapChain9> mpSwapChain;
+ sal::systools::COMReference<IDirect3DVertexBuffer9> mpVertexBuffer;
std::shared_ptr<canvas::ISurface> mpTexture;
VclPtr<SystemChildWindow> mpWindow;
::basegfx::B2IVector maSize;
@@ -246,7 +246,7 @@ namespace dxcanvas
ENSURE_ARG_OR_THROW(rSize.getX() > 0 && rSize.getY() > 0,
"DXSurface::DXSurface(): request for zero-sized surface");
- COMReference<IDirect3DDevice9> pDevice(rRenderModule.getDevice());
+ sal::systools::COMReference<IDirect3DDevice9> pDevice(rRenderModule.getDevice());
IDirect3DTexture9 *pTexture(nullptr);
if(FAILED(pDevice->CreateTexture(
@@ -257,7 +257,7 @@ namespace dxcanvas
&pTexture,nullptr)))
return;
- mpTexture=COMReference<IDirect3DTexture9>(pTexture);
+ mpTexture = sal::systools::COMReference<IDirect3DTexture9>(pTexture, false);
maSize = rSize;
}
@@ -282,7 +282,7 @@ namespace dxcanvas
{
ImplRenderModuleGuard aGuard( mrRenderModule );
mrRenderModule.flushVertexCache();
- COMReference<IDirect3DDevice9> pDevice(mrRenderModule.getDevice());
+ sal::systools::COMReference<IDirect3DDevice9> pDevice(mrRenderModule.getDevice());
if( FAILED(pDevice->SetTexture(0,mpTexture.get())) )
return false;
@@ -499,7 +499,7 @@ namespace dxcanvas
"Could not create DirectX device - out of memory!" );
}
- mpVertexBuffer=COMReference<IDirect3DVertexBuffer9>(pVB);
+ mpVertexBuffer = sal::systools::COMReference<IDirect3DVertexBuffer9>(pVB, false);
}
@@ -542,8 +542,8 @@ namespace dxcanvas
// TODO(F2): since we would like to share precious hardware
// resources, the direct3d9 object should be global. each new
// request for a canvas should only create a new swapchain.
- mpDirect3D9 = COMReference<IDirect3D9>(
- Direct3DCreate9(D3D_SDK_VERSION));
+ mpDirect3D9 = sal::systools::COMReference<IDirect3D9>(
+ Direct3DCreate9(D3D_SDK_VERSION), false);
if(!mpDirect3D9.is())
return false;
@@ -730,12 +730,12 @@ namespace dxcanvas
return false;
// got it, store it in a safe place...
- mpDevice=COMReference<IDirect3DDevice9>(pDevice);
+ mpDevice = sal::systools::COMReference<IDirect3DDevice9>(pDevice, false);
// After CreateDevice, the first swap chain already exists, so just get it...
IDirect3DSwapChain9 *pSwapChain(nullptr);
pDevice->GetSwapChain(0,&pSwapChain);
- mpSwapChain=COMReference<IDirect3DSwapChain9>(pSwapChain);
+ mpSwapChain = sal::systools::COMReference<IDirect3DSwapChain9>(pSwapChain, false);
if( !mpSwapChain.is() )
return false;
@@ -757,10 +757,10 @@ namespace dxcanvas
// DXRenderModule::createSystemMemorySurface
- COMReference<IDirect3DSurface9> DXRenderModule::createSystemMemorySurface( const ::basegfx::B2IVector& rSize )
+ sal::systools::COMReference<IDirect3DSurface9> DXRenderModule::createSystemMemorySurface( const ::basegfx::B2IVector& rSize )
{
if(isDisposed())
- return COMReference<IDirect3DSurface9>(nullptr);
+ return sal::systools::COMReference<IDirect3DSurface9>(nullptr);
// please note that D3DFMT_X8R8G8B8 is the only format we're
// able to choose here, since GetDC() doesn't support any
@@ -778,7 +778,7 @@ namespace dxcanvas
"Could not create offscreen surface - out of mem!" );
}
- return COMReference<IDirect3DSurface9>(pSurface);
+ return sal::systools::COMReference<IDirect3DSurface9>(pSurface, false);
}
@@ -815,7 +815,7 @@ namespace dxcanvas
// DX was kind enough to really reset the device...
do
{
- mpVertexBuffer.reset();
+ mpVertexBuffer.clear();
hr = mpDevice->Reset(&mad3dpp);
if(SUCCEEDED(hr))
{
@@ -830,7 +830,7 @@ namespace dxcanvas
throw lang::NoSupportException(
"Could not create DirectX device - out of memory!" );
}
- mpVertexBuffer=COMReference<IDirect3DVertexBuffer9>(pVB);
+ mpVertexBuffer = sal::systools::COMReference<IDirect3DVertexBuffer9>(pVB, false);
// retry after the restore
if(SUCCEEDED(mpSwapChain->Present(&aRect,&aRect,nullptr,nullptr,0)))
@@ -897,12 +897,12 @@ namespace dxcanvas
mad3dpp.BackBufferHeight = maSize.getY();
// clear before, save resources
- mpSwapChain.reset();
+ mpSwapChain.clear();
IDirect3DSwapChain9 *pSwapChain(nullptr);
if(FAILED(mpDevice->CreateAdditionalSwapChain(&mad3dpp,&pSwapChain)))
return;
- mpSwapChain=COMReference<IDirect3DSwapChain9>(pSwapChain);
+ mpSwapChain = sal::systools::COMReference<IDirect3DSwapChain9>(pSwapChain, false);
// clear the render target [which is the backbuffer in this case].
// we are forced to do this once, and furthermore right now.
diff --git a/canvas/source/directx/dx_rendermodule.hxx b/canvas/source/directx/dx_rendermodule.hxx
index d8ea283b0791..6e8a8fb2aff5 100644
--- a/canvas/source/directx/dx_rendermodule.hxx
+++ b/canvas/source/directx/dx_rendermodule.hxx
@@ -60,7 +60,7 @@ namespace dxcanvas
/// Write a snapshot of the screen to disk
virtual void screenShot() = 0;
- virtual COMReference<surface_type>
+ virtual sal::systools::COMReference<surface_type>
createSystemMemorySurface(
const ::basegfx::B2IVector& rSize ) = 0;
diff --git a/canvas/source/directx/dx_surfacebitmap.cxx b/canvas/source/directx/dx_surfacebitmap.cxx
index e8eb44566c8f..b6e4e12489c2 100644
--- a/canvas/source/directx/dx_surfacebitmap.cxx
+++ b/canvas/source/directx/dx_surfacebitmap.cxx
@@ -47,7 +47,7 @@ namespace dxcanvas
struct DXColorBuffer : public canvas::IColorBuffer
{
public:
- DXColorBuffer( const COMReference<surface_type>& rSurface,
+ DXColorBuffer( const sal::systools::COMReference<surface_type>& rSurface,
const ::basegfx::B2IVector& rSize )
: maSize(rSize)
, maLockedRect{}
@@ -69,7 +69,7 @@ namespace dxcanvas
::basegfx::B2IVector maSize;
mutable D3DLOCKED_RECT maLockedRect;
- mutable COMReference<surface_type> mpSurface;
+ sal::systools::COMReference<surface_type> mpSurface;
};
sal_uInt8* DXColorBuffer::lock() const
diff --git a/canvas/source/directx/dx_surfacebitmap.hxx b/canvas/source/directx/dx_surfacebitmap.hxx
index 323a3b7f1737..ec71f4823e93 100644
--- a/canvas/source/directx/dx_surfacebitmap.hxx
+++ b/canvas/source/directx/dx_surfacebitmap.hxx
@@ -45,7 +45,7 @@ namespace dxcanvas
virtual ::basegfx::B2IVector getSize() const override;
virtual bool hasAlpha() const override;
- COMReference<surface_type> getSurface() const { return mpSurface; }
+ sal::systools::COMReference<surface_type> getSurface() const { return mpSurface; }
bool draw( double fAlpha,
const ::basegfx::B2DPoint& rPos,
@@ -107,7 +107,7 @@ namespace dxcanvas
// container for pixel data, we need to use a directx
// surface since GDI+ sucks...
- COMReference<surface_type> mpSurface;
+ sal::systools::COMReference<surface_type> mpSurface;
// since GDI+ does not work correctly in case we
// run on a 16bit display [don't ask me why] we need
diff --git a/canvas/source/directx/dx_surfacegraphics.cxx b/canvas/source/directx/dx_surfacegraphics.cxx
index a496b41017dd..075f2fc15341 100644
--- a/canvas/source/directx/dx_surfacegraphics.cxx
+++ b/canvas/source/directx/dx_surfacegraphics.cxx
@@ -30,10 +30,10 @@ namespace dxcanvas
{
struct GraphicsDeleter
{
- COMReference<surface_type> mpSurface;
+ sal::systools::COMReference<surface_type> mpSurface;
HDC maHDC;
- GraphicsDeleter(const COMReference<surface_type>& rSurface, HDC hdc) :
+ GraphicsDeleter(const sal::systools::COMReference<surface_type>& rSurface, HDC hdc) :
mpSurface(rSurface),
maHDC(hdc)
{}
@@ -52,7 +52,7 @@ namespace dxcanvas
};
}
- GraphicsSharedPtr createSurfaceGraphics(const COMReference<surface_type>& rSurface )
+ GraphicsSharedPtr createSurfaceGraphics(const sal::systools::COMReference<surface_type>& rSurface )
{
GraphicsSharedPtr pRet;
HDC aHDC;
diff --git a/canvas/source/directx/dx_surfacegraphics.hxx b/canvas/source/directx/dx_surfacegraphics.hxx
index 5f4e1a742ac5..4260383e2ed8 100644
--- a/canvas/source/directx/dx_surfacegraphics.hxx
+++ b/canvas/source/directx/dx_surfacegraphics.hxx
@@ -30,7 +30,7 @@ namespace dxcanvas
GraphicsSharedPtr returned has a deleter that does all the
necessary DX cleanup work).
*/
-GraphicsSharedPtr createSurfaceGraphics(const COMReference<surface_type>& rSurface);
+GraphicsSharedPtr createSurfaceGraphics(const sal::systools::COMReference<surface_type>& rSurface);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/canvas/source/directx/dx_winstuff.hxx b/canvas/source/directx/dx_winstuff.hxx
index b4c54c780971..4cd0007fa955 100644
--- a/canvas/source/directx/dx_winstuff.hxx
+++ b/canvas/source/directx/dx_winstuff.hxx
@@ -24,8 +24,6 @@
#include <basegfx/numeric/ftools.hxx>
-
-#define WIN32_LEAN_AND_MEAN
#include <prewin.h>
// Enabling Direct3D Debug Information Further more, with registry key
@@ -62,89 +60,11 @@ namespace dxcanvas
typedef std::shared_ptr< Gdiplus::Bitmap > BitmapSharedPtr;
typedef std::shared_ptr< Gdiplus::Font > FontSharedPtr;
typedef std::shared_ptr< Gdiplus::TextureBrush > TextureBrushSharedPtr;
-
- /** COM object RAII wrapper
-
- This template wraps a Windows COM object, transparently
- handling lifetime issues the C++ way (i.e. releasing the
- reference when the object is destroyed)
- */
- template< typename T > class COMReference
- {
- public:
- typedef T Wrappee;
-
- COMReference() :
- mp( nullptr )
- {
- }
-
- /** Create from raw pointer
-
- @attention This constructor assumes the interface is
- already acquired (unless p is NULL), no additional AddRef
- is called here.
-
- This caters e.g. for all DirectX factory methods, which
- return the created interfaces pre-acquired, into a raw
- pointer. Simply pass the pointer to this class, but don't
- call Release manually on it!
-
- @example IDirectDrawSurface* pSurface;
- pDD->CreateSurface(&aSurfaceDesc, &pSurface, NULL);
- mpSurface = COMReference< IDirectDrawSurface >(pSurface);
-
- */
- explicit COMReference( T* p ) :
- mp( p )
- {
- }
-
- COMReference( const COMReference& rNew ) :
- mp( nullptr )
- {
- if( rNew.mp == nullptr )
- return;
-
- rNew.mp->AddRef(); // do that _before_ assigning the
- // pointer. Just in case...
- mp = rNew.mp;
- }
-
- COMReference& operator=( const COMReference& rRHS )
- {
- COMReference aTmp(rRHS);
- std::swap( mp, aTmp.mp );
-
- return *this;
- }
-
- ~COMReference()
- {
- reset();
- }
-
- int reset()
- {
- int refcount = 0;
- if( mp )
- refcount = mp->Release();
-
- mp = nullptr;
- return refcount;
- }
-
- bool is() const { return mp != nullptr; }
- T* get() const { return mp; }
- T* operator->() const { return mp; }
- T& operator*() const { return *mp; }
-
- private:
- T* mp;
- };
-
}
+#include <systools/win32/comtools.hxx> // for COMReference; must be inside prewin...postwin
+// Attention! All DirectX factory methods return the created interfaces pre-acquired, into a raw
+// pointer. Do not call AddRef on them when constructing COMReference!
#include <postwin.h>