aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrRectanizer_pow2.h
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-29 18:46:38 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-29 18:46:38 +0000
commitad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97 (patch)
treea361fd03d14a6ce289c36b5c5d276f63f554461f /src/gpu/GrRectanizer_pow2.h
parentd3c6b3f1c89ad1336830957a1e9b235dd86910f2 (diff)
Add testing for Rectanizer-derived classes
This in preparation for expanding the Rectanizer API for removing rects and adding a new derived class R=jvanverth@google.com Author: robertphillips@google.com Review URL: https://codereview.chromium.org/304313002 git-svn-id: http://skia.googlecode.com/svn/trunk@14972 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrRectanizer_pow2.h')
-rw-r--r--src/gpu/GrRectanizer_pow2.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/gpu/GrRectanizer_pow2.h b/src/gpu/GrRectanizer_pow2.h
new file mode 100644
index 0000000000..c2e45655f1
--- /dev/null
+++ b/src/gpu/GrRectanizer_pow2.h
@@ -0,0 +1,68 @@
+/*
+* Copyright 2014 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#ifndef GrRectanizer_pow2_DEFINED
+#define GrRectanizer_pow2_DEFINED
+
+#include "GrRectanizer.h"
+
+class GrRectanizerPow2 : public GrRectanizer {
+public:
+ GrRectanizerPow2(int w, int h) : INHERITED(w, h) {
+ this->reset();
+ }
+
+ virtual ~GrRectanizerPow2() { }
+
+ virtual void reset() SK_OVERRIDE {
+ fNextStripY = 0;
+ fAreaSoFar = 0;
+ sk_bzero(fRows, sizeof(fRows));
+ }
+
+ virtual bool addRect(int w, int h, GrIPoint16* loc) SK_OVERRIDE;
+
+ virtual float percentFull() const SK_OVERRIDE {
+ return fAreaSoFar / ((float)this->width() * this->height());
+ }
+
+private:
+ static const int kMIN_HEIGHT_POW2 = 2;
+
+ struct Row {
+ GrIPoint16 fLoc;
+ int fRowHeight;
+
+ bool canAddWidth(int width, int containerWidth) const {
+ return fLoc.fX + width <= containerWidth;
+ }
+ };
+
+ Row fRows[16];
+
+ int fNextStripY;
+ int32_t fAreaSoFar;
+
+ static int HeightToRowIndex(int height) {
+ SkASSERT(height >= kMIN_HEIGHT_POW2);
+ return 32 - SkCLZ(height - 1);
+ }
+
+ bool canAddStrip(int height) const {
+ return fNextStripY + height <= this->height();
+ }
+
+ void initRow(Row* row, int rowHeight) {
+ row->fLoc.set(0, fNextStripY);
+ row->fRowHeight = rowHeight;
+ fNextStripY += rowHeight;
+ }
+
+ typedef GrRectanizer INHERITED;
+};
+
+#endif