Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
skgpu::RectanizerSkyline Class Referencefinal

#include <RectanizerSkyline.h>

Inheritance diagram for skgpu::RectanizerSkyline:
skgpu::Rectanizer

Public Member Functions

 RectanizerSkyline (int w, int h)
 
 ~RectanizerSkyline () final
 
void reset () final
 
bool addRect (int w, int h, SkIPoint16 *loc) final
 
float percentFull () const final
 
- Public Member Functions inherited from skgpu::Rectanizer
 Rectanizer (int width, int height)
 
virtual ~Rectanizer ()
 
virtual void reset ()=0
 
int width () const
 
int height () const
 
virtual bool addRect (int width, int height, SkIPoint16 *loc)=0
 
virtual float percentFull () const =0
 
bool addPaddedRect (int width, int height, int16_t padding, SkIPoint16 *loc)
 

Additional Inherited Members

- Static Public Member Functions inherited from skgpu::Rectanizer
static RectanizerFactory (int width, int height)
 

Detailed Description

Definition at line 24 of file RectanizerSkyline.h.

Constructor & Destructor Documentation

◆ RectanizerSkyline()

skgpu::RectanizerSkyline::RectanizerSkyline ( int  w,
int  h 
)
inline

Definition at line 26 of file RectanizerSkyline.h.

26 : Rectanizer(w, h) {
27 this->reset();
28 }
Rectanizer(int width, int height)
Definition: Rectanizer.h:17
SkScalar w
SkScalar h

◆ ~RectanizerSkyline()

skgpu::RectanizerSkyline::~RectanizerSkyline ( )
inlinefinal

Definition at line 30 of file RectanizerSkyline.h.

30{ }

Member Function Documentation

◆ addRect()

bool skgpu::RectanizerSkyline::addRect ( int  w,
int  h,
SkIPoint16 loc 
)
finalvirtual

Implements skgpu::Rectanizer.

Definition at line 17 of file RectanizerSkyline.cpp.

17 {
18 if ((unsigned)width > (unsigned)this->width() ||
19 (unsigned)height > (unsigned)this->height()) {
20 return false;
21 }
22
23 // find position for new rectangle
24 int bestWidth = this->width() + 1;
25 int bestX = 0;
26 int bestY = this->height() + 1;
27 int bestIndex = -1;
28 for (int i = 0; i < fSkyline.size(); ++i) {
29 int y;
30 if (this->rectangleFits(i, width, height, &y)) {
31 // minimize y position first, then width of skyline
32 if (y < bestY || (y == bestY && fSkyline[i].fWidth < bestWidth)) {
33 bestIndex = i;
34 bestWidth = fSkyline[i].fWidth;
35 bestX = fSkyline[i].fX;
36 bestY = y;
37 }
38 }
39 }
40
41 // add rectangle to skyline
42 if (-1 != bestIndex) {
43 this->addSkylineLevel(bestIndex, bestX, bestY, width, height);
44 loc->fX = bestX;
45 loc->fY = bestY;
46
47 fAreaSoFar += width*height;
48 return true;
49 }
50
51 loc->fX = 0;
52 loc->fY = 0;
53 return false;
54}
int size() const
Definition: SkTDArray.h:138
int width() const
Definition: Rectanizer.h:26
int height() const
Definition: Rectanizer.h:27
double y
int16_t fY
y-axis value used by SkIPoint16
Definition: SkIPoint16.h:20
int16_t fX
x-axis value used by SkIPoint16
Definition: SkIPoint16.h:18

◆ percentFull()

float skgpu::RectanizerSkyline::percentFull ( ) const
inlinefinalvirtual

Implements skgpu::Rectanizer.

Definition at line 40 of file RectanizerSkyline.h.

40 {
41 return fAreaSoFar / ((float)this->width() * this->height());
42 }

◆ reset()

void skgpu::RectanizerSkyline::reset ( )
inlinefinalvirtual

Implements skgpu::Rectanizer.

Definition at line 32 of file RectanizerSkyline.h.

32 {
33 fAreaSoFar = 0;
34 fSkyline.clear();
35 fSkyline.push_back(SkylineSegment{0, 0, this->width()});
36 }
void push_back(const T &v)
Definition: SkTDArray.h:219
void clear()
Definition: SkTDArray.h:175

The documentation for this class was generated from the following files: