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