Coverage Report

Created: 2021-08-22 09:07

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