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