Coverage Report

Created: 2024-09-14 07:19

/src/skia/src/gpu/RectanizerSkyline.h
Line
Count
Source (jump to first uncovered line)
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
#include <cstdint>
15
16
struct SkIPoint16;
17
18
namespace 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.
24
class RectanizerSkyline final : public Rectanizer {
25
public:
26
30.5k
    RectanizerSkyline(int w, int h) : Rectanizer(w, h) {
27
30.5k
        this->reset();
28
30.5k
    }
29
30
30.5k
    ~RectanizerSkyline() final { }
31
32
31.3k
    void reset() final {
33
31.3k
        fAreaSoFar = 0;
34
31.3k
        fSkyline.clear();
35
31.3k
        fSkyline.push_back(SkylineSegment{0, 0, this->width()});
36
31.3k
    }
37
38
    bool addRect(int w, int h, SkIPoint16* loc) final;
39
40
0
    float percentFull() const final {
41
0
        return fAreaSoFar / ((float)this->width() * this->height());
42
0
    }
43
44
private:
45
    struct SkylineSegment {
46
        int  fX;
47
        int  fY;
48
        int  fWidth;
49
    };
50
51
    SkTDArray<SkylineSegment> fSkyline;
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