cid#1607171 Data race condition
[LibreOffice.git] / canvas / source / cairo / cairo_cachedbitmap.cxx
blobe548778b2fe4766868c4ee3260d1226c796f9aba
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>
22 #include <com/sun/star/rendering/XCanvas.hpp>
23 #include <com/sun/star/rendering/RepaintResult.hpp>
24 #include <utility>
25 #include <comphelper/diagnose_ex.hxx>
27 #include "cairo_cachedbitmap.hxx"
28 #include "cairo_repainttarget.hxx"
31 using namespace ::cairo;
32 using namespace ::com::sun::star;
34 namespace cairocanvas
36 CachedBitmap::CachedBitmap( SurfaceSharedPtr pSurface,
37 const rendering::ViewState& rUsedViewState,
38 rendering::RenderState aUsedRenderState,
39 const uno::Reference< rendering::XCanvas >& rTarget ) :
40 CachedPrimitiveBase( rUsedViewState, rTarget ),
41 mpSurface(std::move( pSurface )),
42 maRenderState(std::move( aUsedRenderState ))
45 void CachedBitmap::disposing(std::unique_lock<std::mutex>& rGuard)
47 mpSurface.reset();
48 CachedPrimitiveBase::disposing(rGuard);
51 ::sal_Int8 CachedBitmap::doRedraw( const rendering::ViewState& rNewState,
52 const rendering::ViewState& /*rOldState*/,
53 const uno::Reference< rendering::XCanvas >& rTargetCanvas,
54 bool bSameViewTransform )
56 ENSURE_OR_THROW( bSameViewTransform,
57 "CachedBitmap::doRedraw(): base called with changed view transform "
58 "(told otherwise during construction)" );
60 RepaintTarget* pTarget = dynamic_cast< RepaintTarget* >(rTargetCanvas.get());
62 ENSURE_OR_THROW( pTarget,
63 "CachedBitmap::redraw(): cannot cast target to RepaintTarget" );
65 if( !pTarget->repaint( mpSurface,
66 rNewState,
67 maRenderState ) )
69 // target failed to repaint
70 return rendering::RepaintResult::FAILED;
73 return rendering::RepaintResult::REDRAWN;
77 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */