1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _VCLCANVAS_SPRITECANVASHELPER_HXX_
25 #define _VCLCANVAS_SPRITECANVASHELPER_HXX_
26 
27 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
28 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
29 
30 #include <vcl/virdev.hxx>
31 
32 #include <canvas/spriteredrawmanager.hxx>
33 #include <canvas/elapsedtime.hxx>
34 #include <canvas/vclwrapper.hxx>
35 #include "canvashelper.hxx"
36 #include "impltools.hxx"
37 
38 
39 namespace vclcanvas
40 {
41     class RedrawManager;
42     class SpriteCanvas;
43 
44     class SpriteCanvasHelper : public CanvasHelper
45     {
46     public:
47         SpriteCanvasHelper();
48 
49         void init( const OutDevProviderSharedPtr& rOutDev,
50                    SpriteCanvas&                  rOwningSpriteCanvas,
51                    ::canvas::SpriteRedrawManager& rManager,
52                    bool                           bProtect,
53                    bool                           bHaveAlpha );
54 
55         /// Dispose all internal references
56         void disposing();
57 
58         // XSpriteCanvas
59         ::com::sun::star::uno::Reference<
60   			::com::sun::star::rendering::XAnimatedSprite > 		createSpriteFromAnimation(
61                 const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimation >& animation );
62 
63         ::com::sun::star::uno::Reference<
64   			::com::sun::star::rendering::XAnimatedSprite > 		createSpriteFromBitmaps(
65                 const ::com::sun::star::uno::Sequence<
66                 	  ::com::sun::star::uno::Reference<
67                 			::com::sun::star::rendering::XBitmap > >& animationBitmaps,
68                 sal_Int8                                              interpolationMode );
69 
70         ::com::sun::star::uno::Reference<
71   			::com::sun::star::rendering::XCustomSprite > 		createCustomSprite(
72                 const ::com::sun::star::geometry::RealSize2D& spriteSize );
73 
74         ::com::sun::star::uno::Reference<
75   			::com::sun::star::rendering::XSprite > 				createClonedSprite(
76                 const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite >& original );
77 
78         /** Actually perform the screen update
79 
80         	@param bUpdateAll
81             sal_True, if everything must be updated, not only changed
82             sprites
83 
84             @param io_bSurfaceDirty
85             In/out parameter, whether backbuffer surface is dirty (if
86             yes, we're performing a full update, anyway)
87          */
88         sal_Bool updateScreen( sal_Bool bUpdateAll,
89                                bool&	io_bSurfaceDirty );
90 
91         // SpriteRedrawManager functor calls
92         // -------------------------------------------------
93 
94         /** Gets called for simple background repaints
95          */
96         void backgroundPaint( const ::basegfx::B2DRange& rUpdateRect );
97 
98         /** Gets called when area can be handled by scrolling.
99 
100         	Called method must copy screen content from rMoveStart to
101         	rMoveEnd, and restore the background in the uncovered
102         	areas.
103 
104             @param rMoveStart
105             Source rect of the scroll
106 
107             @param rMoveEnd
108             Dest rect of the scroll
109 
110             @param rUpdateArea
111             All info necessary, should rMoveStart be partially or
112             fully outside the outdev
113          */
114         void scrollUpdate( const ::basegfx::B2DRange& 							rMoveStart,
115                            const ::basegfx::B2DRange& 							rMoveEnd,
116                            const ::canvas::SpriteRedrawManager::UpdateArea& 	rUpdateArea );
117 
118         void opaqueUpdate( const ::basegfx::B2DRange&                          rTotalArea,
119                            const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites );
120 
121         void genericUpdate( const ::basegfx::B2DRange&                          rTotalArea,
122                             const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites );
123 
isUnsafeScrolling() const124         ::com::sun::star::uno::Any isUnsafeScrolling() const
125         {
126             return ::com::sun::star::uno::makeAny(mbIsUnsafeScrolling);
127         }
enableUnsafeScrolling(const::com::sun::star::uno::Any & rAny)128         void enableUnsafeScrolling( const ::com::sun::star::uno::Any& rAny )
129         {
130             mbIsUnsafeScrolling = rAny.get<bool>();
131         }
132 
isSpriteBounds() const133         ::com::sun::star::uno::Any isSpriteBounds() const
134         {
135             return ::com::sun::star::uno::makeAny(mbShowSpriteBounds);
136         }
enableSpriteBounds(const::com::sun::star::uno::Any & rAny)137         void enableSpriteBounds( const ::com::sun::star::uno::Any& rAny )
138         {
139             mbShowSpriteBounds = rAny.get<bool>();
140         }
141 
142     private:
143         void renderFrameCounter( OutputDevice& rOutDev );
144         void renderSpriteCount( OutputDevice& rOutDev );
145         void renderMemUsage( OutputDevice& rOutDev );
146 
147         /// Set from the SpriteCanvas: instance coordinating sprite redraw
148     	::canvas::SpriteRedrawManager*					mpRedrawManager;
149 
150         /// Set from the init method. used to generate sprites
151         SpriteCanvas*                                   mpOwningSpriteCanvas;
152 
153         /** Background compositing surface.
154 
155         	Typically, sprites will be composited in the background,
156         	before pushing them to screen. This happens here.
157          */
158         ::canvas::vcltools::VCLObject< VirtualDevice >	maVDev;
159 
160         /// For the frame counter timings
161         ::canvas::tools::ElapsedTime					maLastUpdate;
162 
163         /// When true, canvas displays debug info on each frame
164         bool											mbShowFrameInfo;
165 
166         /// When true, canvas creates all new sprites with red lines in the corners
167         bool											mbShowSpriteBounds;
168 
169         /// When true, canvas uses the scroll optimization (direct scrolls in front buffer)
170         bool                                            mbIsUnsafeScrolling;
171     };
172 }
173 
174 #endif /* _VCLCANVAS_SPRITECANVASHELPER_HXX_ */
175 
176