blob: 1d0328a8fb496ec104ae2c2c2d4d9c40bf167991 [file] [log] [blame]
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +00001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrRectanizer_pow2.h"
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +00009
robertphillipsd5373412014-06-02 10:20:14 -070010bool GrRectanizerPow2::addRect(int width, int height, SkIPoint16* loc) {
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000011 if ((unsigned)width > (unsigned)this->width() ||
12 (unsigned)height > (unsigned)this->height()) {
13 return false;
14 }
15
robertphillips901e96d2014-06-02 07:15:18 -070016 int32_t area = width * height; // computed here since height will be modified
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000017
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000018 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) {
halcanary385fe4d2015-08-26 13:07:48 -070058// return new GrRectanizerPow2 (width, height);
commit-bot@chromium.orgad854bf2014-05-29 18:46:38 +000059//}