1
2 /*
3 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #include "GrRectanizer_pow2.h"
10
addRect(int width,int height,SkIPoint16 * loc)11 bool GrRectanizerPow2::addRect(int width, int height, SkIPoint16* loc) {
12 if ((unsigned)width > (unsigned)this->width() ||
13 (unsigned)height > (unsigned)this->height()) {
14 return false;
15 }
16
17 int32_t area = width * height; // computed here since height will be modified
18
19 height = GrNextPow2(height);
20 if (height < kMIN_HEIGHT_POW2) {
21 height = kMIN_HEIGHT_POW2;
22 }
23
24 Row* row = &fRows[HeightToRowIndex(height)];
25 SkASSERT(row->fRowHeight == 0 || row->fRowHeight == height);
26
27 if (0 == row->fRowHeight) {
28 if (!this->canAddStrip(height)) {
29 return false;
30 }
31 this->initRow(row, height);
32 } else {
33 if (!row->canAddWidth(width, this->width())) {
34 if (!this->canAddStrip(height)) {
35 return false;
36 }
37 // that row is now "full", so retarget our Row record for
38 // another one
39 this->initRow(row, height);
40 }
41 }
42
43 SkASSERT(row->fRowHeight == height);
44 SkASSERT(row->canAddWidth(width, this->width()));
45 *loc = row->fLoc;
46 row->fLoc.fX += width;
47
48 SkASSERT(row->fLoc.fX <= this->width());
49 SkASSERT(row->fLoc.fY <= this->height());
50 SkASSERT(fNextStripY <= this->height());
51 fAreaSoFar += area;
52 return true;
53 }
54
55 ///////////////////////////////////////////////////////////////////////////////
56
57 // factory is now in GrRectanizer_skyline.cpp
58 //GrRectanizer* GrRectanizer::Factory(int width, int height) {
59 // return new GrRectanizerPow2 (width, height);
60 //}
61