From 534cc4c569d88c1cfa5f10d3ecf475a90278f597 Mon Sep 17 00:00:00 2001 From: mtklein Date: Mon, 11 Aug 2014 10:09:34 -0700 Subject: De-parameterize SkNextDatumFunction. Just a simple refactor to make it clear we're only using this one method and this one type. BUG=skia: R=robertphillips@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/465523002 --- src/core/SkTileGrid.cpp | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'src/core/SkTileGrid.cpp') diff --git a/src/core/SkTileGrid.cpp b/src/core/SkTileGrid.cpp index c86e78928c..2d6f3b1209 100644 --- a/src/core/SkTileGrid.cpp +++ b/src/core/SkTileGrid.cpp @@ -7,9 +7,9 @@ */ #include "SkTileGrid.h" +#include "SkPictureStateTree.h" -SkTileGrid::SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGridInfo& info, - SkTileGridNextDatumFunctionPtr nextDatumFunction) { +SkTileGrid::SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGridInfo& info) { fXTileCount = xTileCount; fYTileCount = yTileCount; fInfo = info; @@ -21,7 +21,6 @@ SkTileGrid::SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory:: fInsertionCount = 0; fGridBounds = SkIRect::MakeXYWH(0, 0, fInfo.fTileInterval.width() * fXTileCount, fInfo.fTileInterval.height() * fYTileCount); - fNextDatumFunction = nextDatumFunction; fTileData = SkNEW_ARRAY(SkTDArray, fTileCount); } @@ -69,6 +68,43 @@ void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) { fInsertionCount++; } +static void* next_datum(const SkTDArray** tileData, + SkAutoSTArray& tileIndices) { + SkPictureStateTree::Draw* minVal = NULL; + int tileCount = tileIndices.count(); + int minIndex = tileCount; + int maxIndex = 0; + // Find the next Datum; track where it's found so we reduce the size of the second loop. + for (int tile = 0; tile < tileCount; ++tile) { + int pos = tileIndices[tile]; + if (pos != SkTileGrid::kTileFinished) { + SkPictureStateTree::Draw* candidate = (SkPictureStateTree::Draw*)(*tileData[tile])[pos]; + if (NULL == minVal || (*candidate) < (*minVal)) { + minVal = candidate; + minIndex = tile; + maxIndex = tile; + } else if (!((*minVal) < (*candidate))) { + // We don't require operator==; if !(candidate= tileData[tile]->count()) { + tileIndices[tile] = SkTileGrid::kTileFinished; + } + } + } + return minVal; + } + return NULL; +} + void SkTileGrid::search(const SkIRect& query, SkTDArray* results) const { SkIRect adjustedQuery = query; // The inset is to counteract the outset that was applied in 'insert' @@ -109,8 +145,7 @@ void SkTileGrid::search(const SkIRect& query, SkTDArray* results) const { ++tile; } } - void *nextElement; - while(NULL != (nextElement = fNextDatumFunction(tileRange, curPositions))) { + while(void* nextElement = next_datum(tileRange, curPositions)) { results->push(nextElement); } } -- cgit v1.2.3