Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / tools / page.hxx
blob54773f21413db4158c7e16472f3f216550e23850
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 #ifndef INCLUDED_CANVAS_SOURCE_TOOLS_PAGE_HXX
21 #define INCLUDED_CANVAS_SOURCE_TOOLS_PAGE_HXX
23 #include <basegfx/vector/b2isize.hxx>
24 #include <basegfx/range/b2irectangle.hxx>
25 #include <canvas/rendering/icolorbuffer.hxx>
26 #include <canvas/rendering/irendermodule.hxx>
27 #include <canvas/rendering/isurface.hxx>
29 #include <list>
30 #include <vector>
31 #include <boost/shared_ptr.hpp>
32 #include "surfacerect.hxx"
34 namespace canvas
36 class PageFragment;
38 typedef ::boost::shared_ptr< PageFragment > FragmentSharedPtr;
40 /** One page of IRenderModule-provided texture space
42 class Page
44 public:
45 Page( const IRenderModuleSharedPtr& rRenderModule );
47 FragmentSharedPtr allocateSpace( const ::basegfx::B2ISize& rSize );
48 bool nakedFragment( const FragmentSharedPtr& pFragment );
49 void free( const FragmentSharedPtr& pFragment );
50 const ISurfaceSharedPtr& getSurface() const { return mpSurface; }
51 bool isValid() const;
52 void validate();
54 private:
55 typedef std::list<FragmentSharedPtr> FragmentContainer_t;
57 IRenderModuleSharedPtr mpRenderModule;
58 ISurfaceSharedPtr mpSurface;
59 FragmentContainer_t mpFragments;
61 bool insert( SurfaceRect& r );
62 bool isValidLocation( const SurfaceRect& r ) const;
65 typedef ::boost::shared_ptr< Page > PageSharedPtr;
68 /** A part of a page, which gets allocated to a surface
70 class PageFragment
72 public:
73 PageFragment( const SurfaceRect& r,
74 Page* pPage ) :
75 mpPage(pPage),
76 maRect(r),
77 mpBuffer(),
78 maSourceOffset()
82 /// Creates a 'naked' fragment.
83 PageFragment( const ::basegfx::B2ISize& rSize ) :
84 mpPage(NULL),
85 maRect(rSize),
86 mpBuffer(),
87 maSourceOffset()
91 bool isNaked() const { return (mpPage == NULL); }
92 const SurfaceRect& getRect() const { return maRect; }
93 const ::basegfx::B2IPoint& getPos() const { return maRect.maPos; }
94 const ::basegfx::B2ISize& getSize() const { return maRect.maSize; }
95 void setColorBuffer( const IColorBufferSharedPtr& pColorBuffer ) { mpBuffer=pColorBuffer; }
96 void setSourceOffset( const ::basegfx::B2IPoint& rOffset ) { maSourceOffset=rOffset; }
97 void setPage( Page* pPage ) { mpPage=pPage; }
99 void free( const FragmentSharedPtr& pFragment )
101 if(mpPage)
102 mpPage->free(pFragment);
104 mpPage=NULL;
107 bool select( bool bRefresh )
109 // request was made to select this fragment,
110 // but this fragment has not been located on any
111 // of the available pages, we need to hurry now.
112 if(!(mpPage))
113 return false;
115 ISurfaceSharedPtr pSurface(mpPage->getSurface());
117 // select this surface before wiping the contents
118 // since a specific implementation could trigger
119 // a rendering operation here...
120 if(!(pSurface->selectTexture()))
121 return false;
123 // call refresh() if requested, otherwise we're up to date...
124 return !bRefresh || refresh();
127 bool refresh()
129 if(!(mpPage))
130 return false;
132 ISurfaceSharedPtr pSurface(mpPage->getSurface());
134 return pSurface->update( maRect.maPos,
135 ::basegfx::B2IRectangle(
136 maSourceOffset,
137 maSourceOffset + maRect.maSize ),
138 *mpBuffer );
141 private:
142 Page* mpPage;
143 SurfaceRect maRect;
144 IColorBufferSharedPtr mpBuffer;
145 ::basegfx::B2IPoint maSourceOffset;
149 #endif
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */