Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / canvas / source / tools / page.hxx
blob6af4bf0f6be84387194e0260b221f47e57eff958
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 #pragma once
22 #include <basegfx/vector/b2isize.hxx>
23 #include <basegfx/vector/b2ivector.hxx>
24 #include <basegfx/range/b2irectangle.hxx>
25 #include <rendering/icolorbuffer.hxx>
26 #include <rendering/irendermodule.hxx>
27 #include <rendering/isurface.hxx>
29 #include <memory>
30 #include <vector>
31 #include "surfacerect.hxx"
33 namespace canvas
35 class PageFragment;
37 typedef std::shared_ptr< PageFragment > FragmentSharedPtr;
39 /** One page of IRenderModule-provided texture space
41 class Page
43 public:
44 explicit Page( const std::shared_ptr<IRenderModule>& rRenderModule );
46 FragmentSharedPtr allocateSpace( const ::basegfx::B2ISize& rSize );
47 bool nakedFragment( const FragmentSharedPtr& pFragment );
48 void free( const FragmentSharedPtr& pFragment );
49 const std::shared_ptr<ISurface>& getSurface() const { return mpSurface; }
50 bool isValid() const;
51 void validate();
53 private:
54 typedef std::vector<FragmentSharedPtr> FragmentContainer_t;
56 std::shared_ptr<IRenderModule> mpRenderModule;
57 std::shared_ptr<ISurface> mpSurface;
58 FragmentContainer_t mpFragments;
60 bool insert( SurfaceRect& r );
61 bool isValidLocation( const SurfaceRect& r ) const;
64 typedef std::shared_ptr< Page > PageSharedPtr;
67 /** A part of a page, which gets allocated to a surface
69 class PageFragment
71 public:
72 PageFragment( const SurfaceRect& r,
73 Page* pPage ) :
74 mpPage(pPage),
75 maRect(r),
76 mpBuffer(),
77 maSourceOffset()
81 /// Creates a 'naked' fragment.
82 explicit PageFragment( const ::basegfx::B2ISize& rSize ) :
83 mpPage(nullptr),
84 maRect(rSize),
85 mpBuffer(),
86 maSourceOffset()
90 bool isNaked() const { return (mpPage == nullptr); }
91 const SurfaceRect& getRect() const { return maRect; }
92 const ::basegfx::B2IPoint& getPos() const { return maRect.maPos; }
93 const ::basegfx::B2ISize& getSize() const { return maRect.maSize; }
94 void setColorBuffer( const std::shared_ptr<IColorBuffer>& pColorBuffer ) { mpBuffer=pColorBuffer; }
95 void setSourceOffset( const ::basegfx::B2IPoint& rOffset ) { maSourceOffset=rOffset; }
96 void setPage( Page* pPage ) { mpPage=pPage; }
98 void free( const FragmentSharedPtr& pFragment )
100 if(mpPage)
101 mpPage->free(pFragment);
103 mpPage=nullptr;
106 bool select( bool bRefresh )
108 // request was made to select this fragment,
109 // but this fragment has not been located on any
110 // of the available pages, we need to hurry now.
111 if(!mpPage)
112 return false;
114 std::shared_ptr<ISurface> pSurface(mpPage->getSurface());
116 // select this surface before wiping the contents
117 // since a specific implementation could trigger
118 // a rendering operation here...
119 if(!(pSurface->selectTexture()))
120 return false;
122 // call refresh() if requested, otherwise we're up to date...
123 return !bRefresh || refresh();
126 bool refresh()
128 if(!mpPage)
129 return false;
131 std::shared_ptr<ISurface> pSurface(mpPage->getSurface());
133 return pSurface->update( maRect.maPos,
134 ::basegfx::B2IRectangle(
135 maSourceOffset,
136 maSourceOffset + basegfx::B2IVector(maRect.maSize.getWidth(), maRect.maSize.getHeight())),
137 *mpBuffer );
140 private:
141 Page* mpPage;
142 SurfaceRect maRect;
143 std::shared_ptr<IColorBuffer> mpBuffer;
144 ::basegfx::B2IPoint maSourceOffset;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */