commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrRectanizer_pow2.h" |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 9 | |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 10 | bool GrRectanizerPow2::addRect(int width, int height, SkIPoint16* loc) { |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 11 | if ((unsigned)width > (unsigned)this->width() || |
| 12 | (unsigned)height > (unsigned)this->height()) { |
| 13 | return false; |
| 14 | } |
| 15 | |
robertphillips | 901e96d | 2014-06-02 07:15:18 -0700 | [diff] [blame] | 16 | int32_t area = width * height; // computed here since height will be modified |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 17 | |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 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) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 58 | // return new GrRectanizerPow2 (width, height); |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 59 | //} |