Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / gpu / RectanizerSkyline.h
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/SkTDArray.h"
12 #include "src/gpu/Rectanizer.h"
13
14 namespace skgpu {
15
16 // Pack rectangles and track the current silhouette
17 // Based, in part, on Jukka Jylanki's work at http://clb.demon.fi
18 //
19 // Mark this class final in an effort to avoid the vtable when this subclass is used explicitly.
20 class RectanizerSkyline final : public Rectanizer {
21 public:
22     RectanizerSkyline(int w, int h) : Rectanizer(w, h) {
23         this->reset();
24     }
25
26     ~RectanizerSkyline() final { }
27
28     void reset() final {
29         fAreaSoFar = 0;
30         fSkyline.reset();
31         SkylineSegment* seg = fSkyline.append(1);
32         seg->fX = 0;
33         seg->fY = 0;
34         seg->fWidth = this->width();
35     }
36
37     bool addRect(int w, int h, SkIPoint16* loc) final;
38
39     float percentFull() const final {
40         return fAreaSoFar / ((float)this->width() * this->height());
41     }
42
43 private:
44     struct SkylineSegment {
45         int  fX;
46         int  fY;
47         int  fWidth;
48     };
49
50     SkTDArray<SkylineSegment> fSkyline;
51
52     int32_t fAreaSoFar;
53
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
60     // at x,y.
61     void addSkylineLevel(int skylineIndex, int x, int y, int width, int height);
62 };
63
64 } // End of namespace skgpu
65
66 #endif