1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef INCLUDED_CANVAS_PAGE_HXX 29*cdf0e10cSrcweir #define INCLUDED_CANVAS_PAGE_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx> 32*cdf0e10cSrcweir #include <basegfx/range/b2irectangle.hxx> 33*cdf0e10cSrcweir #include <canvas/rendering/icolorbuffer.hxx> 34*cdf0e10cSrcweir #include <canvas/rendering/irendermodule.hxx> 35*cdf0e10cSrcweir #include <canvas/rendering/isurface.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <list> 38*cdf0e10cSrcweir #include <vector> 39*cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 40*cdf0e10cSrcweir #include "surfacerect.hxx" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir namespace canvas 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir class PageFragment; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir typedef ::boost::shared_ptr< PageFragment > FragmentSharedPtr; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir /** One page of IRenderModule-provided texture space 49*cdf0e10cSrcweir */ 50*cdf0e10cSrcweir class Page 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir public: 53*cdf0e10cSrcweir Page( const IRenderModuleSharedPtr& rRenderModule ); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir FragmentSharedPtr allocateSpace( const ::basegfx::B2ISize& rSize ); 56*cdf0e10cSrcweir bool nakedFragment( const FragmentSharedPtr& pFragment ); 57*cdf0e10cSrcweir void free( const FragmentSharedPtr& pFragment ); 58*cdf0e10cSrcweir const ISurfaceSharedPtr& getSurface() const { return mpSurface; } 59*cdf0e10cSrcweir bool isValid() const; 60*cdf0e10cSrcweir void validate(); 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir private: 63*cdf0e10cSrcweir typedef std::list<FragmentSharedPtr> FragmentContainer_t; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir IRenderModuleSharedPtr mpRenderModule; 66*cdf0e10cSrcweir ISurfaceSharedPtr mpSurface; 67*cdf0e10cSrcweir FragmentContainer_t mpFragments; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir bool insert( SurfaceRect& r ); 70*cdf0e10cSrcweir bool isValidLocation( const SurfaceRect& r ) const; 71*cdf0e10cSrcweir }; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir typedef ::boost::shared_ptr< Page > PageSharedPtr; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir /** A part of a page, which gets allocated to a surface 77*cdf0e10cSrcweir */ 78*cdf0e10cSrcweir class PageFragment 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir public: 81*cdf0e10cSrcweir PageFragment( const SurfaceRect& r, 82*cdf0e10cSrcweir Page* pPage ) : 83*cdf0e10cSrcweir mpPage(pPage), 84*cdf0e10cSrcweir maRect(r), 85*cdf0e10cSrcweir mpBuffer(), 86*cdf0e10cSrcweir maSourceOffset() 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir /// Creates a 'naked' fragment. 91*cdf0e10cSrcweir PageFragment( const ::basegfx::B2ISize& rSize ) : 92*cdf0e10cSrcweir mpPage(NULL), 93*cdf0e10cSrcweir maRect(rSize), 94*cdf0e10cSrcweir mpBuffer(), 95*cdf0e10cSrcweir maSourceOffset() 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir bool isNaked() const { return (mpPage == NULL); } 100*cdf0e10cSrcweir const SurfaceRect& getRect() const { return maRect; } 101*cdf0e10cSrcweir const ::basegfx::B2IPoint& getPos() const { return maRect.maPos; } 102*cdf0e10cSrcweir const ::basegfx::B2ISize& getSize() const { return maRect.maSize; } 103*cdf0e10cSrcweir void setColorBuffer( const IColorBufferSharedPtr& pColorBuffer ) { mpBuffer=pColorBuffer; } 104*cdf0e10cSrcweir void setSourceOffset( const ::basegfx::B2IPoint& rOffset ) { maSourceOffset=rOffset; } 105*cdf0e10cSrcweir void setPage( Page* pPage ) { mpPage=pPage; } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void free( const FragmentSharedPtr& pFragment ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir if(mpPage) 110*cdf0e10cSrcweir mpPage->free(pFragment); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir mpPage=NULL; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir bool select( bool bRefresh ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir // request was made to select this fragment, 118*cdf0e10cSrcweir // but this fragment has not been located on any 119*cdf0e10cSrcweir // of the available pages, we need to hurry now. 120*cdf0e10cSrcweir if(!(mpPage)) 121*cdf0e10cSrcweir return false; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir ISurfaceSharedPtr pSurface(mpPage->getSurface()); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // select this surface before wiping the contents 126*cdf0e10cSrcweir // since a specific implementation could trigger 127*cdf0e10cSrcweir // a rendering operation here... 128*cdf0e10cSrcweir if(!(pSurface->selectTexture())) 129*cdf0e10cSrcweir return false; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // call refresh() if requested, otherwise we're up to date... 132*cdf0e10cSrcweir return bRefresh ? refresh() : true; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir bool refresh() 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir if(!(mpPage)) 138*cdf0e10cSrcweir return false; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir ISurfaceSharedPtr pSurface(mpPage->getSurface()); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir return pSurface->update( maRect.maPos, 143*cdf0e10cSrcweir ::basegfx::B2IRectangle( 144*cdf0e10cSrcweir maSourceOffset, 145*cdf0e10cSrcweir maSourceOffset + maRect.maSize ), 146*cdf0e10cSrcweir *mpBuffer ); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir private: 150*cdf0e10cSrcweir Page* mpPage; 151*cdf0e10cSrcweir SurfaceRect maRect; 152*cdf0e10cSrcweir IColorBufferSharedPtr mpBuffer; 153*cdf0e10cSrcweir ::basegfx::B2IPoint maSourceOffset; 154*cdf0e10cSrcweir }; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir #endif 158