1ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org/* 2901e96df6916e6f8ba95a4ea85a2ceac31e7d633robertphillips * Copyright 2014 Google Inc. 3901e96df6916e6f8ba95a4ea85a2ceac31e7d633robertphillips * 4901e96df6916e6f8ba95a4ea85a2ceac31e7d633robertphillips * Use of this source code is governed by a BSD-style license that can be 5901e96df6916e6f8ba95a4ea85a2ceac31e7d633robertphillips * found in the LICENSE file. 6901e96df6916e6f8ba95a4ea85a2ceac31e7d633robertphillips */ 7ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 8ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org#ifndef GrRectanizer_skyline_DEFINED 9ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org#define GrRectanizer_skyline_DEFINED 10ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 11ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org#include "GrRectanizer.h" 12ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org#include "SkTDArray.h" 13ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 14ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org// Pack rectangles and track the current silhouette 15901e96df6916e6f8ba95a4ea85a2ceac31e7d633robertphillips// Based, in part, on Jukka Jylanki's work at http://clb.demon.fi 16ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.orgclass GrRectanizerSkyline : public GrRectanizer { 17ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.orgpublic: 18ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org GrRectanizerSkyline(int w, int h) : INHERITED(w, h) { 19ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org this->reset(); 20ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org } 21ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 22ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org virtual ~GrRectanizerSkyline() { } 23ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 24ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org virtual void reset() SK_OVERRIDE{ 25ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org fAreaSoFar = 0; 26ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org fSkyline.reset(); 27ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org SkylineSegment* seg = fSkyline.append(1); 28ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org seg->fX = 0; 29ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org seg->fY = 0; 30ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org seg->fWidth = this->width(); 31ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org } 32ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 33d537341e16524d1e22ac5e6c8b9c8f274ba1833crobertphillips virtual bool addRect(int w, int h, SkIPoint16* loc) SK_OVERRIDE; 34ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 354cbf8e3dce10ef0d06e5ef95ea88b084bbad2553robertphillips virtual float percentFull() const SK_OVERRIDE { 36ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org return fAreaSoFar / ((float)this->width() * this->height()); 37ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org } 38ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 39ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.orgprivate: 40ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org struct SkylineSegment { 41ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org int fX; 42ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org int fY; 43ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org int fWidth; 44ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org }; 45ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 46ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org SkTDArray<SkylineSegment> fSkyline; 47ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 48ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org int32_t fAreaSoFar; 49ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 504cbf8e3dce10ef0d06e5ef95ea88b084bbad2553robertphillips // Can a width x height rectangle fit in the free space represented by 514cbf8e3dce10ef0d06e5ef95ea88b084bbad2553robertphillips // the skyline segments >= 'skylineIndex'? If so, return true and fill in 524cbf8e3dce10ef0d06e5ef95ea88b084bbad2553robertphillips // 'y' with the y-location at which it fits (the x location is pulled from 534cbf8e3dce10ef0d06e5ef95ea88b084bbad2553robertphillips // 'skylineIndex's segment. 54ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org bool rectangleFits(int skylineIndex, int width, int height, int* y) const; 554cbf8e3dce10ef0d06e5ef95ea88b084bbad2553robertphillips // Update the skyline structure to include a width x height rect located 564cbf8e3dce10ef0d06e5ef95ea88b084bbad2553robertphillips // at x,y. 57ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org void addSkylineLevel(int skylineIndex, int x, int y, int width, int height); 58ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 59ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org typedef GrRectanizer INHERITED; 60ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org}; 61ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org 62ad854bf9c0d2029cf0730e50ac7f7ddbe32d1c97commit-bot@chromium.org#endif 63