GrRectanizer_skyline.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2014 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef GrRectanizer_skyline_DEFINED
  8. #define GrRectanizer_skyline_DEFINED
  9. #include "include/private/SkTDArray.h"
  10. #include "src/gpu/GrRectanizer.h"
  11. // Pack rectangles and track the current silhouette
  12. // Based, in part, on Jukka Jylanki's work at http://clb.demon.fi
  13. class GrRectanizerSkyline : public GrRectanizer {
  14. public:
  15. GrRectanizerSkyline(int w, int h) : INHERITED(w, h) {
  16. this->reset();
  17. }
  18. ~GrRectanizerSkyline() override { }
  19. void reset() override {
  20. fAreaSoFar = 0;
  21. fSkyline.reset();
  22. SkylineSegment* seg = fSkyline.append(1);
  23. seg->fX = 0;
  24. seg->fY = 0;
  25. seg->fWidth = this->width();
  26. }
  27. bool addRect(int w, int h, SkIPoint16* loc) override;
  28. float percentFull() const override {
  29. return fAreaSoFar / ((float)this->width() * this->height());
  30. }
  31. private:
  32. struct SkylineSegment {
  33. int fX;
  34. int fY;
  35. int fWidth;
  36. };
  37. SkTDArray<SkylineSegment> fSkyline;
  38. int32_t fAreaSoFar;
  39. // Can a width x height rectangle fit in the free space represented by
  40. // the skyline segments >= 'skylineIndex'? If so, return true and fill in
  41. // 'y' with the y-location at which it fits (the x location is pulled from
  42. // 'skylineIndex's segment.
  43. bool rectangleFits(int skylineIndex, int width, int height, int* y) const;
  44. // Update the skyline structure to include a width x height rect located
  45. // at x,y.
  46. void addSkylineLevel(int skylineIndex, int x, int y, int width, int height);
  47. typedef GrRectanizer INHERITED;
  48. };
  49. #endif