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 #include "src/gpu/RectanizerPow2.h"
9
10 namespace skgpu {
11
addRect(int width,int height,SkIPoint16 * loc)12 bool RectanizerPow2::addRect(int width, int height, SkIPoint16* loc) {
13 if ((unsigned)width > (unsigned)this->width() ||
14 (unsigned)height > (unsigned)this->height()) {
15 return false;
16 }
17
18 int32_t area = width * height; // computed here since height will be modified
19
20 // SkNextPow2 is undefined for inputs <= 0. If small values happen
21 // to creep in here, round them all up to the minimum power of 2.
22 static_assert(kMIN_HEIGHT_POW2 > 0);
23 static_assert(kMIN_HEIGHT_POW2 == SkNextPow2_portable(kMIN_HEIGHT_POW2));
24 if (height < kMIN_HEIGHT_POW2) {
25 height = kMIN_HEIGHT_POW2;
26 } else {
27 height = SkNextPow2(height);
28 }
29
30
31 Row* row = &fRows[HeightToRowIndex(height)];
32 SkASSERT(row->fRowHeight == 0 || row->fRowHeight == height);
33
34 if (0 == row->fRowHeight) {
35 if (!this->canAddStrip(height)) {
36 return false;
37 }
38 this->initRow(row, height);
39 } else {
40 if (!row->canAddWidth(width, this->width())) {
41 if (!this->canAddStrip(height)) {
42 return false;
43 }
44 // that row is now "full", so retarget our Row record for
45 // another one
46 this->initRow(row, height);
47 }
48 }
49
50 SkASSERT(row->fRowHeight == height);
51 SkASSERT(row->canAddWidth(width, this->width()));
52 *loc = row->fLoc;
53 row->fLoc.fX += width;
54
55 SkASSERT(row->fLoc.fX <= this->width());
56 SkASSERT(row->fLoc.fY <= this->height());
57 SkASSERT(fNextStripY <= this->height());
58 fAreaSoFar += area;
59 return true;
60 }
61
62 ///////////////////////////////////////////////////////////////////////////////
63
64 // factory is now in RectanizerSkyline.cpp
65 //Rectanizer* Rectanizer::Factory(int width, int height) {
66 // return new RectanizerPow2(width, height);
67 //}
68
69 } // End of namespace skgpu
70