Flutter Engine
The Flutter Engine
Rectanizer.h
Go to the documentation of this file.
1/*
2 * Copyright 2010 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_Rectanizer_DEFINED
9#define skgpu_Rectanizer_DEFINED
10
11#include "src/core/SkIPoint16.h"
12
13namespace skgpu {
14
16public:
17 Rectanizer(int width, int height) : fWidth(width), fHeight(height) {
18 SkASSERT(width >= 0);
19 SkASSERT(height >= 0);
20 }
21
22 virtual ~Rectanizer() {}
23
24 virtual void reset() = 0;
25
26 int width() const { return fWidth; }
27 int height() const { return fHeight; }
28
29 // Attempt to add a rect. Return true on success; false on failure. If
30 // successful the position in the atlas is returned in 'loc'.
31 virtual bool addRect(int width, int height, SkIPoint16* loc) = 0;
32 virtual float percentFull() const = 0;
33
34 bool addPaddedRect(int width, int height, int16_t padding, SkIPoint16* loc) {
35 if (this->addRect(width + 2*padding, height + 2*padding, loc)) {
36 loc->fX += padding;
37 loc->fY += padding;
38 return true;
39 }
40 return false;
41 }
42
43 /**
44 * Our factory, which returns the subclass du jour
45 */
46 static Rectanizer* Factory(int width, int height);
47
48private:
49 const int fWidth;
50 const int fHeight;
51};
52
53} // End of namespace skgpu
54
55#endif
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual void reset()=0
static Rectanizer * Factory(int width, int height)
int width() const
Definition: Rectanizer.h:26
virtual ~Rectanizer()
Definition: Rectanizer.h:22
int height() const
Definition: Rectanizer.h:27
bool addPaddedRect(int width, int height, int16_t padding, SkIPoint16 *loc)
Definition: Rectanizer.h:34
virtual float percentFull() const =0
virtual bool addRect(int width, int height, SkIPoint16 *loc)=0
Rectanizer(int width, int height)
Definition: Rectanizer.h:17
Definition: GpuTools.h:21
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