2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrRectanizer_skyline_DEFINED
9 #define GrRectanizer_skyline_DEFINED
11 #include "GrRectanizer.h"
12 #include "SkTDArray.h"
14 // Pack rectangles and track the current silhouette
15 // Based, in part, on Jukka Jylanki's work at http://clb.demon.fi
16 class GrRectanizerSkyline : public GrRectanizer {
18 GrRectanizerSkyline(int w, int h) : INHERITED(w, h) {
22 virtual ~GrRectanizerSkyline() { }
24 void reset() override{
27 SkylineSegment* seg = fSkyline.append(1);
30 seg->fWidth = this->width();
33 bool addRect(int w, int h, SkIPoint16* loc) override;
35 float percentFull() const override {
36 return fAreaSoFar / ((float)this->width() * this->height());
40 struct SkylineSegment {
46 SkTDArray<SkylineSegment> fSkyline;
50 // Can a width x height rectangle fit in the free space represented by
51 // the skyline segments >= 'skylineIndex'? If so, return true and fill in
52 // 'y' with the y-location at which it fits (the x location is pulled from
53 // 'skylineIndex's segment.
54 bool rectangleFits(int skylineIndex, int width, int height, int* y) const;
55 // Update the skyline structure to include a width x height rect located
57 void addSkylineLevel(int skylineIndex, int x, int y, int width, int height);
59 typedef GrRectanizer INHERITED;