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
28
29#include <memory>
30#include <vector>
31#include "surfacerect.hxx"
32
33namespace canvas
34{
35 class PageFragment;
36
37 typedef std::shared_ptr< PageFragment > FragmentSharedPtr;
38
41 class Page
42 {
43 public:
44 explicit Page( const std::shared_ptr<IRenderModule>& rRenderModule );
45
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();
52
53 private:
54 typedef std::vector<FragmentSharedPtr> FragmentContainer_t;
55
56 std::shared_ptr<IRenderModule> mpRenderModule;
57 std::shared_ptr<ISurface> mpSurface;
59
60 bool insert( SurfaceRect& r );
61 bool isValidLocation( const SurfaceRect& r ) const;
62 };
63
64 typedef std::shared_ptr< Page > PageSharedPtr;
65
66
70 {
71 public:
73 Page* pPage ) :
74 mpPage(pPage),
75 maRect(r),
76 mpBuffer(),
78 {
79 }
80
82 explicit PageFragment( const ::basegfx::B2ISize& rSize ) :
83 mpPage(nullptr),
84 maRect(rSize),
85 mpBuffer(),
87 {
88 }
89
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; }
97
98 void free( const FragmentSharedPtr& pFragment )
99 {
100 if(mpPage)
101 mpPage->free(pFragment);
102
103 mpPage=nullptr;
104 }
105
106 bool select( bool bRefresh )
107 {
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;
113
114 std::shared_ptr<ISurface> pSurface(mpPage->getSurface());
115
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;
121
122 // call refresh() if requested, otherwise we're up to date...
123 return !bRefresh || refresh();
124 }
125
126 bool refresh()
127 {
128 if(!mpPage)
129 return false;
130
131 std::shared_ptr<ISurface> pSurface(mpPage->getSurface());
132
133 return pSurface->update( maRect.maPos,
137 *mpBuffer );
138 }
139
140 private:
143 std::shared_ptr<IColorBuffer> mpBuffer;
145 };
146}
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TYPE getWidth() const
TYPE getHeight() const
A part of a page, which gets allocated to a surface.
Definition: page.hxx:70
bool select(bool bRefresh)
Definition: page.hxx:106
bool isNaked() const
Definition: page.hxx:90
PageFragment(const ::basegfx::B2ISize &rSize)
Creates a 'naked' fragment.
Definition: page.hxx:82
void free(const FragmentSharedPtr &pFragment)
Definition: page.hxx:98
void setColorBuffer(const std::shared_ptr< IColorBuffer > &pColorBuffer)
Definition: page.hxx:94
void setPage(Page *pPage)
Definition: page.hxx:96
std::shared_ptr< IColorBuffer > mpBuffer
Definition: page.hxx:143
const ::basegfx::B2IPoint & getPos() const
Definition: page.hxx:92
SurfaceRect maRect
Definition: page.hxx:142
void setSourceOffset(const ::basegfx::B2IPoint &rOffset)
Definition: page.hxx:95
::basegfx::B2IPoint maSourceOffset
Definition: page.hxx:144
PageFragment(const SurfaceRect &r, Page *pPage)
Definition: page.hxx:72
const ::basegfx::B2ISize & getSize() const
Definition: page.hxx:93
const SurfaceRect & getRect() const
Definition: page.hxx:91
One page of IRenderModule-provided texture space.
Definition: page.hxx:42
std::shared_ptr< ISurface > mpSurface
Definition: page.hxx:57
bool isValidLocation(const SurfaceRect &r) const
Definition: page.cxx:116
std::shared_ptr< IRenderModule > mpRenderModule
Definition: page.hxx:56
void free(const FragmentSharedPtr &pFragment)
Definition: page.cxx:72
FragmentContainer_t mpFragments
Definition: page.hxx:58
bool insert(SurfaceRect &r)
Definition: page.cxx:85
FragmentSharedPtr allocateSpace(const ::basegfx::B2ISize &rSize)
Definition: page.cxx:46
Page(const std::shared_ptr< IRenderModule > &rRenderModule)
Definition: page.cxx:26
std::vector< FragmentSharedPtr > FragmentContainer_t
Definition: page.hxx:54
void validate()
Definition: page.cxx:32
bool isValid() const
Definition: page.cxx:41
const std::shared_ptr< ISurface > & getSurface() const
Definition: page.hxx:49
bool nakedFragment(const FragmentSharedPtr &pFragment)
Definition: page.cxx:59
std::shared_ptr< PageFragment > FragmentSharedPtr
Definition: page.hxx:35
std::shared_ptr< Page > PageSharedPtr
Definition: page.hxx:64
This implements some equivalent to basegfx::B2IBox, but instead of two BasicBox ranges,...
Definition: surfacerect.hxx:38
::basegfx::B2ISize maSize
Definition: surfacerect.hxx:40
::basegfx::B2IPoint maPos
Definition: surfacerect.hxx:39