LibreOffice Module canvas (master)  1
page.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
26 #include <rendering/isurface.hxx>
27 
28 #include <memory>
29 #include <vector>
30 #include "surfacerect.hxx"
31 
32 namespace canvas
33 {
34  class PageFragment;
35 
36  typedef std::shared_ptr< PageFragment > FragmentSharedPtr;
37 
40  class Page
41  {
42  public:
43  explicit Page( const std::shared_ptr<IRenderModule>& rRenderModule );
44 
45  FragmentSharedPtr allocateSpace( const ::basegfx::B2ISize& rSize );
46  bool nakedFragment( const FragmentSharedPtr& pFragment );
47  void free( const FragmentSharedPtr& pFragment );
48  const std::shared_ptr<ISurface>& getSurface() const { return mpSurface; }
49  bool isValid() const;
50  void validate();
51 
52  private:
53  typedef std::vector<FragmentSharedPtr> FragmentContainer_t;
54 
55  std::shared_ptr<IRenderModule> mpRenderModule;
56  std::shared_ptr<ISurface> mpSurface;
57  FragmentContainer_t mpFragments;
58 
59  bool insert( SurfaceRect& r );
60  bool isValidLocation( const SurfaceRect& r ) const;
61  };
62 
63  typedef std::shared_ptr< Page > PageSharedPtr;
64 
65 
69  {
70  public:
72  Page* pPage ) :
73  mpPage(pPage),
74  maRect(r),
75  mpBuffer(),
77  {
78  }
79 
81  explicit PageFragment( const ::basegfx::B2ISize& rSize ) :
82  mpPage(nullptr),
83  maRect(rSize),
84  mpBuffer(),
86  {
87  }
88 
89  bool isNaked() const { return (mpPage == nullptr); }
90  const SurfaceRect& getRect() const { return maRect; }
91  const ::basegfx::B2IPoint& getPos() const { return maRect.maPos; }
92  const ::basegfx::B2ISize& getSize() const { return maRect.maSize; }
93  void setColorBuffer( const std::shared_ptr<IColorBuffer>& pColorBuffer ) { mpBuffer=pColorBuffer; }
94  void setSourceOffset( const ::basegfx::B2IPoint& rOffset ) { maSourceOffset=rOffset; }
95  void setPage( Page* pPage ) { mpPage=pPage; }
96 
97  void free( const FragmentSharedPtr& pFragment )
98  {
99  if(mpPage)
100  mpPage->free(pFragment);
101 
102  mpPage=nullptr;
103  }
104 
105  bool select( bool bRefresh )
106  {
107  // request was made to select this fragment,
108  // but this fragment has not been located on any
109  // of the available pages, we need to hurry now.
110  if(!mpPage)
111  return false;
112 
113  std::shared_ptr<ISurface> pSurface(mpPage->getSurface());
114 
115  // select this surface before wiping the contents
116  // since a specific implementation could trigger
117  // a rendering operation here...
118  if(!(pSurface->selectTexture()))
119  return false;
120 
121  // call refresh() if requested, otherwise we're up to date...
122  return !bRefresh || refresh();
123  }
124 
125  bool refresh()
126  {
127  if(!mpPage)
128  return false;
129 
130  std::shared_ptr<ISurface> pSurface(mpPage->getSurface());
131 
132  return pSurface->update( maRect.maPos,
136  *mpBuffer );
137  }
138 
139  private:
142  std::shared_ptr<IColorBuffer> mpBuffer;
144  };
145 }
146 
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool nakedFragment(const FragmentSharedPtr &pFragment)
Definition: page.cxx:59
void free(const FragmentSharedPtr &pFragment)
Definition: page.hxx:97
std::shared_ptr< Page > PageSharedPtr
Definition: page.hxx:63
const SurfaceRect & getRect() const
Definition: page.hxx:90
bool isNaked() const
Definition: page.hxx:89
::basegfx::B2IPoint maSourceOffset
Definition: page.hxx:143
FragmentSharedPtr allocateSpace(const ::basegfx::B2ISize &rSize)
Definition: page.cxx:46
void setPage(Page *pPage)
Definition: page.hxx:95
A part of a page, which gets allocated to a surface.
Definition: page.hxx:68
PageFragment(const SurfaceRect &r, Page *pPage)
Definition: page.hxx:71
bool insert(SurfaceRect &r)
Definition: page.cxx:85
const ::basegfx::B2ISize & getSize() const
Definition: page.hxx:92
FragmentContainer_t mpFragments
Definition: page.hxx:57
void free(const FragmentSharedPtr &pFragment)
Definition: page.cxx:72
const std::shared_ptr< ISurface > & getSurface() const
Definition: page.hxx:48
PageFragment(const ::basegfx::B2ISize &rSize)
Creates a 'naked' fragment.
Definition: page.hxx:81
bool isValid() const
Definition: page.cxx:41
bool isValidLocation(const SurfaceRect &r) const
Definition: page.cxx:116
const ::basegfx::B2IPoint & getPos() const
Definition: page.hxx:91
void setColorBuffer(const std::shared_ptr< IColorBuffer > &pColorBuffer)
Definition: page.hxx:93
bool select(bool bRefresh)
Definition: page.hxx:105
SurfaceRect maRect
Definition: page.hxx:141
Page(const std::shared_ptr< IRenderModule > &rRenderModule)
Definition: page.cxx:26
std::shared_ptr< ISurface > mpSurface
Definition: page.hxx:56
std::shared_ptr< IColorBuffer > mpBuffer
Definition: page.hxx:142
::basegfx::B2IPoint maPos
Definition: surfacerect.hxx:39
One page of IRenderModule-provided texture space.
Definition: page.hxx:40
::basegfx::B2ISize maSize
Definition: surfacerect.hxx:40
void setSourceOffset(const ::basegfx::B2IPoint &rOffset)
Definition: page.hxx:94
std::vector< FragmentSharedPtr > FragmentContainer_t
Definition: page.hxx:53
std::shared_ptr< IRenderModule > mpRenderModule
Definition: page.hxx:55
std::shared_ptr< PageFragment > FragmentSharedPtr
Definition: page.hxx:34
This implements some equivalent to basegfx::B2IBox, but instead of two BasicBox ranges, it uses a position and a size.
Definition: surfacerect.hxx:37
void validate()
Definition: page.cxx:32