DirtyRectangles.h 1.5 KB

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