Overte C++ Documentation
PageManager.h
1 //
2 // Created by Sam Gateau on 10/8/2014.
3 // Split from Resource.h/Resource.cpp by Bradley Austin Davis on 2016/08/07
4 // Copyright 2014 High Fidelity, Inc.
5 //
6 // Distributed under the Apache License, Version 2.0.
7 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
8 //
9 #ifndef hifi_gpu_PageManager_h
10 #define hifi_gpu_PageManager_h
11 
12 #include "Forward.h"
13 
14 #include <vector>
15 
16 namespace gpu {
17 
18 struct PageManager {
19  static const Size DEFAULT_PAGE_SIZE = 4096;
20 
21  // Currently only one flag... 'dirty'
22  enum Flag {
23  DIRTY = 0x01,
24  };
25 
26  using FlagType = uint8_t;
27 
28  // A list of flags
29  using Vector = std::vector<FlagType>;
30  // A list of pages
31  using Pages = std::vector<Size>;
32 
33  Vector _pages;
34  uint8 _flags{ 0 };
35  const Size _pageSize;
36 
37  PageManager(Size pageSize = DEFAULT_PAGE_SIZE);
38  PageManager& operator=(const PageManager& other);
39 
40  operator bool() const;
41  bool operator()(uint8 desiredFlags) const;
42  void markPage(Size index, uint8 markFlags = DIRTY);
43  void markRegion(Size offset, Size bytes, uint8 markFlags = DIRTY);
44  Size getPageCount(uint8_t desiredFlags = DIRTY) const;
45  Size getSize(uint8_t desiredFlags = DIRTY) const;
46  void setPageCount(Size count);
47  Size getRequiredPageCount(Size size) const;
48  Size getRequiredSize(Size size) const;
49  Size accommodate(Size size);
50  // Get pages with the specified flags, optionally clearing the flags as we go
51  Pages getMarkedPages(uint8_t desiredFlags = DIRTY, bool clear = true);
52  bool getNextTransferBlock(Size& outOffset, Size& outSize, Size& currentPage);
53 };
54 
55 };
56 
57 #endif