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