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