xref: /aoo42x/main/canvas/source/tools/page.hxx (revision 91c99ff4)
1*91c99ff4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*91c99ff4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*91c99ff4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*91c99ff4SAndrew Rist  * distributed with this work for additional information
6*91c99ff4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*91c99ff4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*91c99ff4SAndrew Rist  * "License"); you may not use this file except in compliance
9*91c99ff4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*91c99ff4SAndrew Rist  *
11*91c99ff4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*91c99ff4SAndrew Rist  *
13*91c99ff4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*91c99ff4SAndrew Rist  * software distributed under the License is distributed on an
15*91c99ff4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*91c99ff4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*91c99ff4SAndrew Rist  * specific language governing permissions and limitations
18*91c99ff4SAndrew Rist  * under the License.
19*91c99ff4SAndrew Rist  *
20*91c99ff4SAndrew Rist  *************************************************************/
21*91c99ff4SAndrew Rist 
22*91c99ff4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_CANVAS_PAGE_HXX
25cdf0e10cSrcweir #define INCLUDED_CANVAS_PAGE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx>
28cdf0e10cSrcweir #include <basegfx/range/b2irectangle.hxx>
29cdf0e10cSrcweir #include <canvas/rendering/icolorbuffer.hxx>
30cdf0e10cSrcweir #include <canvas/rendering/irendermodule.hxx>
31cdf0e10cSrcweir #include <canvas/rendering/isurface.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <list>
34cdf0e10cSrcweir #include <vector>
35cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
36cdf0e10cSrcweir #include "surfacerect.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace canvas
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 	class PageFragment;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 	typedef ::boost::shared_ptr< PageFragment > FragmentSharedPtr;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     /** One page of IRenderModule-provided texture space
45cdf0e10cSrcweir      */
46cdf0e10cSrcweir 	class Page
47cdf0e10cSrcweir 	{
48cdf0e10cSrcweir     public:
49cdf0e10cSrcweir         Page( const IRenderModuleSharedPtr& rRenderModule );
50cdf0e10cSrcweir 
51cdf0e10cSrcweir         FragmentSharedPtr        allocateSpace( const ::basegfx::B2ISize& rSize );
52cdf0e10cSrcweir         bool                     nakedFragment( const FragmentSharedPtr& pFragment );
53cdf0e10cSrcweir         void                     free( const FragmentSharedPtr& pFragment );
getSurface() const54cdf0e10cSrcweir         const ISurfaceSharedPtr& getSurface() const { return mpSurface; }
55cdf0e10cSrcweir         bool                     isValid() const;
56cdf0e10cSrcweir         void                     validate();
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     private:
59cdf0e10cSrcweir         typedef std::list<FragmentSharedPtr> FragmentContainer_t;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         IRenderModuleSharedPtr  mpRenderModule;
62cdf0e10cSrcweir         ISurfaceSharedPtr       mpSurface;
63cdf0e10cSrcweir         FragmentContainer_t     mpFragments;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         bool insert( SurfaceRect& r );
66cdf0e10cSrcweir         bool isValidLocation( const SurfaceRect& r ) const;
67cdf0e10cSrcweir 	};
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	typedef ::boost::shared_ptr< Page > PageSharedPtr;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     /** A part of a page, which gets allocated to a surface
73cdf0e10cSrcweir      */
74cdf0e10cSrcweir 	class PageFragment
75cdf0e10cSrcweir 	{
76cdf0e10cSrcweir     public:
PageFragment(const SurfaceRect & r,Page * pPage)77cdf0e10cSrcweir         PageFragment( const SurfaceRect& r,
78cdf0e10cSrcweir                       Page*              pPage ) :
79cdf0e10cSrcweir             mpPage(pPage),
80cdf0e10cSrcweir             maRect(r),
81cdf0e10cSrcweir             mpBuffer(),
82cdf0e10cSrcweir             maSourceOffset()
83cdf0e10cSrcweir         {
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         /// Creates a 'naked' fragment.
PageFragment(const::basegfx::B2ISize & rSize)87cdf0e10cSrcweir         PageFragment( const ::basegfx::B2ISize& rSize ) :
88cdf0e10cSrcweir             mpPage(NULL),
89cdf0e10cSrcweir             maRect(rSize),
90cdf0e10cSrcweir             mpBuffer(),
91cdf0e10cSrcweir             maSourceOffset()
92cdf0e10cSrcweir         {
93cdf0e10cSrcweir         }
94cdf0e10cSrcweir 
isNaked() const95cdf0e10cSrcweir         bool                        isNaked() const { return (mpPage == NULL); }
getRect() const96cdf0e10cSrcweir         const SurfaceRect&          getRect() const { return maRect; }
getPos() const97cdf0e10cSrcweir         const ::basegfx::B2IPoint&  getPos() const { return maRect.maPos; }
getSize() const98cdf0e10cSrcweir         const ::basegfx::B2ISize&   getSize() const { return maRect.maSize; }
setColorBuffer(const IColorBufferSharedPtr & pColorBuffer)99cdf0e10cSrcweir         void                        setColorBuffer( const IColorBufferSharedPtr& pColorBuffer ) { mpBuffer=pColorBuffer; }
setSourceOffset(const::basegfx::B2IPoint & rOffset)100cdf0e10cSrcweir         void                        setSourceOffset( const ::basegfx::B2IPoint& rOffset ) { maSourceOffset=rOffset; }
setPage(Page * pPage)101cdf0e10cSrcweir         void                        setPage( Page* pPage ) { mpPage=pPage; }
102cdf0e10cSrcweir 
free(const FragmentSharedPtr & pFragment)103cdf0e10cSrcweir         void free( const FragmentSharedPtr& pFragment )
104cdf0e10cSrcweir         {
105cdf0e10cSrcweir             if(mpPage)
106cdf0e10cSrcweir                 mpPage->free(pFragment);
107cdf0e10cSrcweir 
108cdf0e10cSrcweir             mpPage=NULL;
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir 
select(bool bRefresh)111cdf0e10cSrcweir         bool select( bool bRefresh )
112cdf0e10cSrcweir         {
113cdf0e10cSrcweir             // request was made to select this fragment,
114cdf0e10cSrcweir             // but this fragment has not been located on any
115cdf0e10cSrcweir             // of the available pages, we need to hurry now.
116cdf0e10cSrcweir             if(!(mpPage))
117cdf0e10cSrcweir                 return false;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir             ISurfaceSharedPtr pSurface(mpPage->getSurface());
120cdf0e10cSrcweir 
121cdf0e10cSrcweir             // select this surface before wiping the contents
122cdf0e10cSrcweir             // since a specific implementation could trigger
123cdf0e10cSrcweir             // a rendering operation here...
124cdf0e10cSrcweir             if(!(pSurface->selectTexture()))
125cdf0e10cSrcweir                 return false;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir             // call refresh() if requested, otherwise we're up to date...
128cdf0e10cSrcweir             return bRefresh ? refresh() : true;
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir 
refresh()131cdf0e10cSrcweir         bool refresh()
132cdf0e10cSrcweir         {
133cdf0e10cSrcweir             if(!(mpPage))
134cdf0e10cSrcweir                 return false;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             ISurfaceSharedPtr pSurface(mpPage->getSurface());
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             return pSurface->update( maRect.maPos,
139cdf0e10cSrcweir                                      ::basegfx::B2IRectangle(
140cdf0e10cSrcweir                                          maSourceOffset,
141cdf0e10cSrcweir                                          maSourceOffset + maRect.maSize ),
142cdf0e10cSrcweir                                      *mpBuffer );
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     private:
146cdf0e10cSrcweir         Page*                 mpPage;
147cdf0e10cSrcweir         SurfaceRect           maRect;
148cdf0e10cSrcweir         IColorBufferSharedPtr mpBuffer;
149cdf0e10cSrcweir         ::basegfx::B2IPoint   maSourceOffset;
150cdf0e10cSrcweir 	};
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir #endif
154