Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: src/gpu/GrRectanizer_pow2.h

Issue 304313002: Add testing for Rectanizer-derived classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Renaming file Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrRectanizer.cpp ('k') | src/gpu/GrRectanizer_pow2.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 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 #ifndef GrRectanizer_pow2_DEFINED
9 #define GrRectanizer_pow2_DEFINED
10
11 #include "GrRectanizer.h"
12
13 class GrRectanizerPow2 : public GrRectanizer {
14 public:
15 GrRectanizerPow2(int w, int h) : INHERITED(w, h) {
16 this->reset();
17 }
18
19 virtual ~GrRectanizerPow2() { }
20
21 virtual void reset() SK_OVERRIDE {
22 fNextStripY = 0;
23 fAreaSoFar = 0;
24 sk_bzero(fRows, sizeof(fRows));
25 }
26
27 virtual bool addRect(int w, int h, GrIPoint16* loc) SK_OVERRIDE;
28
29 virtual float percentFull() const SK_OVERRIDE {
30 return fAreaSoFar / ((float)this->width() * this->height());
31 }
32
33 private:
34 static const int kMIN_HEIGHT_POW2 = 2;
35
36 struct Row {
37 GrIPoint16 fLoc;
38 int fRowHeight;
39
40 bool canAddWidth(int width, int containerWidth) const {
41 return fLoc.fX + width <= containerWidth;
42 }
43 };
44
45 Row fRows[16];
46
47 int fNextStripY;
48 int32_t fAreaSoFar;
49
50 static int HeightToRowIndex(int height) {
51 SkASSERT(height >= kMIN_HEIGHT_POW2);
52 return 32 - SkCLZ(height - 1);
53 }
54
55 bool canAddStrip(int height) const {
56 return fNextStripY + height <= this->height();
57 }
58
59 void initRow(Row* row, int rowHeight) {
60 row->fLoc.set(0, fNextStripY);
61 row->fRowHeight = rowHeight;
62 fNextStripY += rowHeight;
63 }
64
65 typedef GrRectanizer INHERITED;
66 };
67
68 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrRectanizer.cpp ('k') | src/gpu/GrRectanizer_pow2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698