• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #ifndef skgpu_RectanizerSkyline_DEFINED
9 #define skgpu_RectanizerSkyline_DEFINED
10 
11 #include "include/private/base/SkTDArray.h"
12 #include "src/gpu/Rectanizer.h"
13 
14 namespace skgpu {
15 
16 // Pack rectangles and track the current silhouette
17 // Based, in part, on Jukka Jylanki's work at http://clb.demon.fi
18 //
19 // Mark this class final in an effort to avoid the vtable when this subclass is used explicitly.
20 class RectanizerSkyline final : public Rectanizer {
21 public:
RectanizerSkyline(int w,int h)22     RectanizerSkyline(int w, int h) : Rectanizer(w, h) {
23         this->reset();
24     }
25 
~RectanizerSkyline()26     ~RectanizerSkyline() final { }
27 
reset()28     void reset() final {
29         fAreaSoFar = 0;
30         fSkyline.clear();
31         fSkyline.push_back(SkylineSegment{0, 0, this->width()});
32     }
33 
34     bool addRect(int w, int h, SkIPoint16* loc) final;
35 
percentFull()36     float percentFull() const final {
37         return fAreaSoFar / ((float)this->width() * this->height());
38     }
39 
40 private:
41     struct SkylineSegment {
42         int  fX;
43         int  fY;
44         int  fWidth;
45     };
46 
47     SkTDArray<SkylineSegment> fSkyline;
48 
49     int32_t fAreaSoFar;
50 
51     // Can a width x height rectangle fit in the free space represented by
52     // the skyline segments >= 'skylineIndex'? If so, return true and fill in
53     // 'y' with the y-location at which it fits (the x location is pulled from
54     // 'skylineIndex's segment.
55     bool rectangleFits(int skylineIndex, int width, int height, int* y) const;
56     // Update the skyline structure to include a width x height rect located
57     // at x,y.
58     void addSkylineLevel(int skylineIndex, int x, int y, int width, int height);
59 };
60 
61 } // End of namespace skgpu
62 
63 #endif
64