blob: 2d443cab8c6661ef0a06d36c67255dbe7964f223 [file] [log] [blame]
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +00001
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"
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000010
robertphillipsd5373412014-06-02 10:20:14 -070011bool GrRectanizerPow2::addRect(int width, int height, SkIPoint16* loc) {
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000012 if ((unsigned)width > (unsigned)this->width() ||
13 (unsigned)height > (unsigned)this->height()) {
14 return false;
15 }
16
robertphillips901e96d2014-06-02 07:15:18 -070017 int32_t area = width * height; // computed here since height will be modified
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000018
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000019 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 SkNEW_ARGS(GrRectanizerPow2, (width, height));
60//}