cid#1607171 Data race condition
[LibreOffice.git] / canvas / source / cairo / cairo_spritedevicehelper.cxx
blob69a057c9918f1d589c75256f345c83c94ca7d49c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <vcl/cairo.hxx>
25 #include <cairo.h>
27 #include "cairo_devicehelper.hxx"
28 #include "cairo_spritecanvas.hxx"
30 using namespace ::cairo;
31 using namespace ::com::sun::star;
33 namespace cairocanvas
36 SpriteDeviceHelper::SpriteDeviceHelper() :
37 mpSpriteCanvas( nullptr ),
38 mbFullScreen( false )
41 void SpriteDeviceHelper::init( vcl::Window& rOutputWindow,
42 SpriteCanvas& rSpriteCanvas,
43 const ::basegfx::B2ISize& rSize,
44 bool bFullscreen )
46 DeviceHelper::init(rSpriteCanvas,
47 *rOutputWindow.GetOutDev());
49 mpSpriteCanvas = &rSpriteCanvas;
50 mbFullScreen = bFullscreen;
52 setSize( rSize );
55 void SpriteDeviceHelper::disposing()
57 // release all references
58 mpBufferSurface.reset();
59 mpSpriteCanvas = nullptr;
62 bool SpriteDeviceHelper::showBuffer( bool, bool )
64 SAL_WARN("canvas.cairo", "showBuffer Not supposed to be called, handled by SpriteCanvas");
65 return false;
68 bool SpriteDeviceHelper::switchBuffer( bool, bool )
70 SAL_WARN("canvas.cairo", "showBuffer Not supposed to be called, handled by SpriteCanvas");
71 return false;
74 uno::Any SpriteDeviceHelper::isAccelerated() const
76 return css::uno::Any(true);
79 uno::Any SpriteDeviceHelper::getDeviceHandle() const
81 return DeviceHelper::getDeviceHandle();
84 uno::Any SpriteDeviceHelper::getSurfaceHandle() const
86 return DeviceHelper::getSurfaceHandle();
89 void SpriteDeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
91 SAL_INFO(
92 "canvas.cairo",
93 "device size " << rSize.getWidth() << " x " << rSize.getHeight());
95 if( !mpSpriteCanvas )
96 return; // disposed
98 DeviceHelper::setSize(rSize);
100 if( mpBufferSurface && maSize != rSize )
101 mpBufferSurface.reset();
102 if( !mpBufferSurface )
103 mpBufferSurface = getWindowSurface()->getSimilar(
104 CAIRO_CONTENT_COLOR,
105 rSize.getWidth(), rSize.getHeight() );
107 if( maSize != rSize )
108 maSize = rSize;
110 mpSpriteCanvas->setSizePixel( maSize );
114 void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
116 setSize( ::basegfx::B2ISize(rBounds.Width, rBounds.Height) );
119 SurfaceSharedPtr const & SpriteDeviceHelper::getWindowSurface() const
121 return DeviceHelper::getSurface();
124 SurfaceSharedPtr SpriteDeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
126 if( mpBufferSurface )
127 return mpBufferSurface->getSimilar( aContent, rSize.getWidth(), rSize.getHeight() );
129 return SurfaceSharedPtr();
132 SurfaceSharedPtr SpriteDeviceHelper::createSurface( BitmapSystemData const & rData, const Size& rSize )
134 OutputDevice *pDevice = getOutputDevice();
135 if (pDevice)
136 return pDevice->CreateBitmapSurface(rData, rSize);
137 return SurfaceSharedPtr();
140 /** SpriteDeviceHelper::flush Flush the platform native window
142 * Flushes the window by using the internally stored mpSysData.
145 void SpriteDeviceHelper::flush()
147 SurfaceSharedPtr pWinSurface=getWindowSurface();
148 if( pWinSurface )
149 pWinSurface->flush();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */