tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / canvas / source / cairo / cairo_canvasbitmap.cxx
blobc4de75ee2fce038016f7ebbb62c15445c8c05d45
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 <cppuhelper/supportsservice.hxx>
24 #include <comphelper/diagnose_ex.hxx>
25 #include <utility>
26 #include <vcl/bitmapex.hxx>
27 #include <vcl/BitmapTools.hxx>
29 #include <cairo.h>
31 #include "cairo_canvasbitmap.hxx"
33 using namespace ::cairo;
34 using namespace ::com::sun::star;
36 namespace cairocanvas
38 CanvasBitmap::CanvasBitmap( const ::basegfx::B2ISize& rSize,
39 SurfaceProviderRef rSurfaceProvider,
40 rendering::XGraphicDevice* pDevice,
41 bool bHasAlpha ) :
42 mpSurfaceProvider(std::move( rSurfaceProvider )),
43 maSize(rSize),
44 mbHasAlpha(bHasAlpha)
46 ENSURE_OR_THROW( mpSurfaceProvider.is(),
47 "CanvasBitmap::CanvasBitmap(): Invalid surface or device" );
49 SAL_INFO(
50 "canvas.cairo",
51 "bitmap size: " << rSize.getWidth() << "x" << rSize.getHeight());
53 mpBufferSurface = mpSurfaceProvider->createSurface( rSize, bHasAlpha ? CAIRO_CONTENT_COLOR_ALPHA : CAIRO_CONTENT_COLOR );
54 mpBufferCairo = mpBufferSurface->getCairo();
56 maCanvasHelper.init( rSize, *mpSurfaceProvider, pDevice );
57 maCanvasHelper.setSurface( mpBufferSurface, bHasAlpha );
59 // clear bitmap to 100% transparent
60 maCanvasHelper.clear();
63 void CanvasBitmap::disposeThis()
65 mpSurfaceProvider.clear();
67 mpBufferCairo.reset();
68 mpBufferSurface.reset();
70 // forward to parent
71 CanvasBitmap_Base::disposeThis();
74 SurfaceSharedPtr CanvasBitmap::getSurface()
76 return mpBufferSurface;
79 SurfaceSharedPtr CanvasBitmap::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
81 return mpSurfaceProvider->createSurface(rSize,aContent);
84 SurfaceSharedPtr CanvasBitmap::createSurface( ::Bitmap& rBitmap )
86 return mpSurfaceProvider->createSurface(rBitmap);
89 SurfaceSharedPtr CanvasBitmap::changeSurface()
91 // non-modifiable surface here
92 return SurfaceSharedPtr();
95 OutputDevice* CanvasBitmap::getOutputDevice()
97 return mpSurfaceProvider->getOutputDevice();
100 bool CanvasBitmap::repaint( const SurfaceSharedPtr& pSurface,
101 const rendering::ViewState& viewState,
102 const rendering::RenderState& renderState )
104 return maCanvasHelper.repaint( pSurface, viewState, renderState );
107 uno::Any SAL_CALL CanvasBitmap::getFastPropertyValue( sal_Int32 nHandle )
109 uno::Any aRV( sal_Int32(0) );
110 // 0 ... get BitmapEx
111 // 1 ... get Pixbuf with bitmap RGB content
112 // 2 ... return nothing (empty Any)
113 switch( nHandle )
115 case 0:
117 aRV <<= reinterpret_cast<sal_Int64>( nullptr );
118 if ( !mbHasAlpha )
119 break;
121 BitmapEx* pBitmapEx = vcl::bitmap::CreateFromCairoSurface(
122 ::Size( maSize.getWidth(), maSize.getHeight() ),
123 getSurface()->getCairoSurface().get());
124 if (pBitmapEx)
125 aRV <<= reinterpret_cast<sal_Int64>( pBitmapEx );
127 break;
129 case 1:
131 aRV = getOutputDevice()->GetNativeSurfaceHandle(mpBufferSurface, maSize);
132 break;
134 case 2:
136 // Always return nothing - for the RGB surface support.
137 // Alpha code paths go via the above case 0.
138 aRV = uno::Any();
139 break;
143 return aRV;
146 OUString SAL_CALL CanvasBitmap::getImplementationName( )
148 return u"CairoCanvas.CanvasBitmap"_ustr;
151 sal_Bool SAL_CALL CanvasBitmap::supportsService( const OUString& ServiceName )
153 return cppu::supportsService( this, ServiceName );
156 uno::Sequence< OUString > SAL_CALL CanvasBitmap::getSupportedServiceNames( )
158 return { u"com.sun.star.rendering.CanvasBitmap"_ustr };
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */