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 skgpu_RectanizerSkyline_DEFINED
9 #define skgpu_RectanizerSkyline_DEFINED
11 #include "include/private/SkTDArray.h"
12 #include "src/gpu/Rectanizer.h"
16 // Pack rectangles and track the current silhouette
17 // Based, in part, on Jukka Jylanki's work at http://clb.demon.fi
19 // Mark this class final in an effort to avoid the vtable when this subclass is used explicitly.
20 class RectanizerSkyline final : public Rectanizer {
22 RectanizerSkyline(int w, int h) : Rectanizer(w, h) {
26 ~RectanizerSkyline() final { }
31 SkylineSegment* seg = fSkyline.append(1);
34 seg->fWidth = this->width();
37 bool addRect(int w, int h, SkIPoint16* loc) final;
39 float percentFull() const final {
40 return fAreaSoFar / ((float)this->width() * this->height());
44 struct SkylineSegment {
50 SkTDArray<SkylineSegment> fSkyline;
54 // Can a width x height rectangle fit in the free space represented by
55 // the skyline segments >= 'skylineIndex'? If so, return true and fill in
56 // 'y' with the y-location at which it fits (the x location is pulled from
57 // 'skylineIndex's segment.
58 bool rectangleFits(int skylineIndex, int width, int height, int* y) const;
59 // Update the skyline structure to include a width x height rect located
61 void addSkylineLevel(int skylineIndex, int x, int y, int width, int height);
64 } // End of namespace skgpu