DirtyRectangles.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 
  2. #ifndef DFPSR_DIRTY_RECTANGLES
  3. #define DFPSR_DIRTY_RECTANGLES
  4. #include "../../DFPSR/includeFramework.h"
  5. namespace dsr {
  6. class DirtyRectangles {
  7. private:
  8. int32_t width = 0;
  9. int32_t height = 0;
  10. List<IRect> dirtyRectangles;
  11. public:
  12. DirtyRectangles() {}
  13. // Call before rendering to let the dirty rectangles know if the resolution changed
  14. void setTargetResolution(int32_t width, int32_t height) {
  15. if (this->width != width || this->height != height) {
  16. this->width = width;
  17. this->height = height;
  18. this->allDirty();
  19. }
  20. }
  21. public:
  22. IRect getTargetBound() const {
  23. return IRect(0, 0, this->width, this->height);
  24. }
  25. // Call when everything needs an update
  26. void allDirty() {
  27. this->dirtyRectangles.clear();
  28. this->dirtyRectangles.push(getTargetBound());
  29. }
  30. void noneDirty() {
  31. this->dirtyRectangles.clear();
  32. }
  33. void makeRegionDirty(IRect newRegion) {
  34. newRegion = IRect::cut(newRegion, getTargetBound());
  35. if (newRegion.hasArea()) {
  36. for (int i = 0; i < this->dirtyRectangles.length(); i++) {
  37. if (IRect::touches(this->dirtyRectangles[i], newRegion)) {
  38. // Merge with any existing bound
  39. newRegion = IRect::merge(newRegion, this->dirtyRectangles[i]);
  40. this->dirtyRectangles.remove(i);
  41. // Restart the search for overlaps with a larger region
  42. i = -1;
  43. }
  44. }
  45. this->dirtyRectangles.push(newRegion);
  46. }
  47. }
  48. int64_t getRectangleCount() const {
  49. return dirtyRectangles.length();
  50. }
  51. IRect getRectangle(int64_t index) const {
  52. return this->dirtyRectangles[index];
  53. }
  54. };
  55. }
  56. #endif