Line data Source code
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 :
21 : #include <canvas/debug.hxx>
22 : #include <tools/diagnose_ex.h>
23 : #include <canvas/verbosetrace.hxx>
24 :
25 : #include <rtl/math.hxx>
26 :
27 : #include <vcl/outdev.hxx>
28 : #include <vcl/bitmap.hxx>
29 : #include <vcl/alpha.hxx>
30 : #include <vcl/bitmapex.hxx>
31 : #include <vcl/canvastools.hxx>
32 :
33 : #include <basegfx/matrix/b2dhommatrix.hxx>
34 : #include <basegfx/point/b2dpoint.hxx>
35 : #include <basegfx/tools/canvastools.hxx>
36 : #include <basegfx/polygon/b2dpolygon.hxx>
37 : #include <basegfx/polygon/b2dpolygontools.hxx>
38 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
39 : #include <basegfx/numeric/ftools.hxx>
40 :
41 : #include <canvas/canvastools.hxx>
42 :
43 : #include "canvascustomsprite.hxx"
44 :
45 :
46 : using namespace ::com::sun::star;
47 :
48 :
49 : namespace vclcanvas
50 : {
51 :
52 0 : CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D& rSpriteSize,
53 : rendering::XGraphicDevice& rDevice,
54 : const ::canvas::SpriteSurface::Reference& rOwningSpriteCanvas,
55 : const OutDevProviderSharedPtr& rOutDevProvider,
56 0 : bool bShowSpriteBounds )
57 : {
58 0 : ENSURE_OR_THROW( rOwningSpriteCanvas.get() &&
59 : rOutDevProvider,
60 : "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
61 :
62 : // setup back buffer
63 : // -----------------
64 :
65 : const ::Size aSize(
66 : static_cast<sal_Int32>( ::std::max( 1.0,
67 0 : ceil( rSpriteSize.Width ))), // round up to nearest int,
68 : // enforce sprite to have at
69 : // least (1,1) pixel size
70 : static_cast<sal_Int32>( ::std::max( 1.0,
71 0 : ceil( rSpriteSize.Height ))) );
72 :
73 : // create content backbuffer in screen depth
74 0 : BackBufferSharedPtr pBackBuffer( new BackBuffer( rOutDevProvider->getOutDev() ) );
75 0 : pBackBuffer->setSize( aSize );
76 :
77 : // create mask backbuffer, with one bit color depth
78 0 : BackBufferSharedPtr pBackBufferMask( new BackBuffer( rOutDevProvider->getOutDev(),
79 0 : true ) );
80 0 : pBackBufferMask->setSize( aSize );
81 :
82 : // TODO(F1): Implement alpha vdev (could prolly enable
83 : // antialiasing again, then)
84 :
85 : // disable font antialiasing (causes ugly shadows otherwise)
86 0 : pBackBuffer->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT );
87 0 : pBackBufferMask->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT );
88 :
89 : // set mask vdev drawmode, such that everything is painted
90 : // black. That leaves us with a binary image, white for
91 : // background, black for painted content
92 0 : pBackBufferMask->getOutDev().SetDrawMode( DRAWMODE_BLACKLINE | DRAWMODE_BLACKFILL | DRAWMODE_BLACKTEXT |
93 0 : DRAWMODE_BLACKGRADIENT | DRAWMODE_BLACKBITMAP );
94 :
95 :
96 : // setup canvas helper
97 : // -------------------
98 :
99 : // always render into back buffer, don't preserve state (it's
100 : // our private VDev, after all), have notion of alpha
101 : maCanvasHelper.init( rDevice,
102 : pBackBuffer,
103 : false,
104 0 : true );
105 0 : maCanvasHelper.setBackgroundOutDev( pBackBufferMask );
106 :
107 :
108 : // setup sprite helper
109 : // -------------------
110 :
111 : maSpriteHelper.init( rSpriteSize,
112 : rOwningSpriteCanvas,
113 : pBackBuffer,
114 : pBackBufferMask,
115 0 : bShowSpriteBounds );
116 :
117 : // clear sprite to 100% transparent
118 0 : maCanvasHelper.clear();
119 0 : }
120 :
121 : #define IMPLEMENTATION_NAME "VCLCanvas.CanvasCustomSprite"
122 : #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite"
123 :
124 0 : ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException )
125 : {
126 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
127 : }
128 :
129 0 : sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
130 : {
131 0 : return ServiceName == SERVICE_NAME;
132 : }
133 :
134 0 : uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException )
135 : {
136 0 : uno::Sequence< ::rtl::OUString > aRet(1);
137 0 : aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
138 :
139 0 : return aRet;
140 : }
141 :
142 : // Sprite
143 0 : void CanvasCustomSprite::redraw( OutputDevice& rOutDev,
144 : bool bBufferedUpdate ) const
145 : {
146 0 : SolarMutexGuard aGuard;
147 :
148 0 : redraw( rOutDev, maSpriteHelper.getPosPixel(), bBufferedUpdate );
149 0 : }
150 :
151 0 : void CanvasCustomSprite::redraw( OutputDevice& rOutDev,
152 : const ::basegfx::B2DPoint& rOrigOutputPos,
153 : bool bBufferedUpdate ) const
154 : {
155 0 : SolarMutexGuard aGuard;
156 :
157 : maSpriteHelper.redraw( rOutDev,
158 : rOrigOutputPos,
159 : mbSurfaceDirty,
160 0 : bBufferedUpdate );
161 :
162 0 : mbSurfaceDirty = false;
163 0 : }
164 :
165 0 : bool CanvasCustomSprite::repaint( const GraphicObjectSharedPtr& rGrf,
166 : const rendering::ViewState& viewState,
167 : const rendering::RenderState& renderState,
168 : const ::Point& rPt,
169 : const ::Size& rSz,
170 : const GraphicAttr& rAttr ) const
171 : {
172 0 : SolarMutexGuard aGuard;
173 :
174 0 : mbSurfaceDirty = true;
175 :
176 0 : return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
177 : }
178 :
179 0 : }
180 :
181 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|