LibreOffice Module canvas (master) 1
cairo_canvasbitmap.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21#include <sal/log.hxx>
22
25#include <utility>
26#include <vcl/bitmapex.hxx>
27#include <vcl/BitmapTools.hxx>
28
29#include <cairo.h>
30
32
33using namespace ::cairo;
34using namespace ::com::sun::star;
35
36namespace cairocanvas
37{
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)
45 {
46 ENSURE_OR_THROW( mpSurfaceProvider.is(),
47 "CanvasBitmap::CanvasBitmap(): Invalid surface or device" );
48
50 "canvas.cairo",
51 "bitmap size: " << rSize.getWidth() << "x" << rSize.getHeight());
52
53 mpBufferSurface = mpSurfaceProvider->createSurface( rSize, bHasAlpha ? CAIRO_CONTENT_COLOR_ALPHA : CAIRO_CONTENT_COLOR );
54 mpBufferCairo = mpBufferSurface->getCairo();
55
56 maCanvasHelper.init( rSize, *mpSurfaceProvider, pDevice );
57 maCanvasHelper.setSurface( mpBufferSurface, bHasAlpha );
58
59 // clear bitmap to 100% transparent
60 maCanvasHelper.clear();
61 }
62
63 void CanvasBitmap::disposeThis()
64 {
65 mpSurfaceProvider.clear();
66
67 mpBufferCairo.reset();
68 mpBufferSurface.reset();
69
70 // forward to parent
71 CanvasBitmap_Base::disposeThis();
72 }
73
74 SurfaceSharedPtr CanvasBitmap::getSurface()
75 {
76 return mpBufferSurface;
77 }
78
79 SurfaceSharedPtr CanvasBitmap::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
80 {
81 return mpSurfaceProvider->createSurface(rSize,aContent);
82 }
83
84 SurfaceSharedPtr CanvasBitmap::createSurface( ::Bitmap& rBitmap )
85 {
86 return mpSurfaceProvider->createSurface(rBitmap);
87 }
88
89 SurfaceSharedPtr CanvasBitmap::changeSurface()
90 {
91 // non-modifiable surface here
92 return SurfaceSharedPtr();
93 }
94
95 OutputDevice* CanvasBitmap::getOutputDevice()
96 {
97 return mpSurfaceProvider->getOutputDevice();
98 }
99
100 bool CanvasBitmap::repaint( const SurfaceSharedPtr& pSurface,
101 const rendering::ViewState& viewState,
102 const rendering::RenderState& renderState )
103 {
104 return maCanvasHelper.repaint( pSurface, viewState, renderState );
105 }
106
107 uno::Any SAL_CALL CanvasBitmap::getFastPropertyValue( sal_Int32 nHandle )
108 {
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 )
114 {
115 case 0:
116 {
117 aRV <<= reinterpret_cast<sal_Int64>( nullptr );
118 if ( !mbHasAlpha )
119 break;
120
121 BitmapEx* pBitmapEx = vcl::bitmap::CreateFromCairoSurface(
123 getSurface()->getCairoSurface().get());
124 if (pBitmapEx)
125 aRV <<= reinterpret_cast<sal_Int64>( pBitmapEx );
126
127 break;
128 }
129 case 1:
130 {
131 aRV = getOutputDevice()->GetNativeSurfaceHandle(mpBufferSurface, maSize);
132 break;
133 }
134 case 2:
135 {
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;
140 }
141 }
142
143 return aRV;
144 }
145
146 OUString SAL_CALL CanvasBitmap::getImplementationName( )
147 {
148 return "CairoCanvas.CanvasBitmap";
149 }
150
151 sal_Bool SAL_CALL CanvasBitmap::supportsService( const OUString& ServiceName )
152 {
153 return cppu::supportsService( this, ServiceName );
154 }
155
156 uno::Sequence< OUString > SAL_CALL CanvasBitmap::getSupportedServiceNames( )
157 {
158 return { "com.sun.star.rendering.CanvasBitmap" };
159 }
160
161}
162
163/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TYPE getWidth() const
TYPE getHeight() const
CanvasBitmap(const ::basegfx::B2ISize &rSize, SurfaceProviderRef rDevice, css::rendering::XGraphicDevice *pDevice, bool bHasAlpha)
Create a canvas bitmap for the given surface.
#define ENSURE_OR_THROW(c, m)
::basegfx::B2ISize maSize
Definition: dx_9rm.cxx:116
#define SAL_INFO(area, stream)
std::shared_ptr< Surface > SurfaceSharedPtr
class SAL_LOPLUGIN_ANNOTATE("crosscast") SurfaceProvider typedef ::rtl::Reference< SurfaceProvider > SurfaceProviderRef
Target interface for XCachedPrimitive implementations.
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
sal_Int32 nHandle
unsigned char sal_Bool