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
diff --git a/src/gpu/GrRectanizer_skyline.h b/src/gpu/GrRectanizer_skyline.h
new file mode 100644
index 0000000..d2dfe57
--- /dev/null
+++ b/src/gpu/GrRectanizer_skyline.h
@@ -0,0 +1,56 @@
+/*
+* 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_skyline_DEFINED
+#define GrRectanizer_skyline_DEFINED
+
+#include "GrRectanizer.h"
+#include "SkTDArray.h"
+
+// Pack rectangles and track the current silhouette
+// Based in part on Jukka Jylänki's work at http://clb.demon.fi
+class GrRectanizerSkyline : public GrRectanizer {
+public:
+ GrRectanizerSkyline(int w, int h) : INHERITED(w, h) {
+ this->reset();
+ }
+
+ virtual ~GrRectanizerSkyline() { }
+
+ virtual void reset() SK_OVERRIDE{
+ fAreaSoFar = 0;
+ fSkyline.reset();
+ SkylineSegment* seg = fSkyline.append(1);
+ seg->fX = 0;
+ seg->fY = 0;
+ seg->fWidth = this->width();
+ }
+
+ 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:
+ struct SkylineSegment {
+ int fX;
+ int fY;
+ int fWidth;
+ };
+
+ SkTDArray<SkylineSegment> fSkyline;
+
+ int32_t fAreaSoFar;
+
+ bool rectangleFits(int skylineIndex, int width, int height, int* y) const;
+ void addSkylineLevel(int skylineIndex, int x, int y, int width, int height);
+
+ typedef GrRectanizer INHERITED;
+};
+
+#endif