Reland "Specialize SkRectanzier to SkRectanizerSkyline"
This is a reland of 77e1f84a84
Original change's description:
> Specialize SkRectanzier to SkRectanizerSkyline
>
> It looks like the pow2 rectanizer has never been used. Remove
> the unneeded abstraction for rectanizer everywhere.
>
> Change-Id: Iba33f1c6faf37201d03928ce8409751c212480a0
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265983
> Commit-Queue: Herb Derby <herb@google.com>
> Reviewed-by: Mike Klein <mtklein@google.com>
Change-Id: I09729ba2b0e4b8b1a229fef4b95e65195b33fdc7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/266180
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
parent
26df65c8fb
commit
73c75877bd
@ -10,8 +10,8 @@
|
||||
#include "include/private/SkTDArray.h"
|
||||
#include "include/utils/SkRandom.h"
|
||||
|
||||
#include "src/gpu/GrRectanizer_pow2.h"
|
||||
#include "src/gpu/GrRectanizer_skyline.h"
|
||||
#include "src/core/SkMathPriv.h"
|
||||
#include "src/gpu/GrRectanizerSkyline.h"
|
||||
|
||||
/**
|
||||
* This bench exercises Ganesh' GrRectanizer classes. It exercises the following
|
||||
@ -29,7 +29,6 @@ public:
|
||||
static const int kHeight = 1024;
|
||||
|
||||
enum RectanizerType {
|
||||
kPow2_RectanizerType,
|
||||
kSkyline_RectanizerType,
|
||||
};
|
||||
|
||||
@ -41,15 +40,9 @@ public:
|
||||
|
||||
RectanizerBench(RectanizerType rectanizerType, RectType rectType)
|
||||
: fName("rectanizer_")
|
||||
, fRectanizerType(rectanizerType)
|
||||
, fRectType(rectType) {
|
||||
|
||||
if (kPow2_RectanizerType == fRectanizerType) {
|
||||
fName.append("pow2_");
|
||||
} else {
|
||||
SkASSERT(kSkyline_RectanizerType == fRectanizerType);
|
||||
fName.append("skyline_");
|
||||
}
|
||||
fName.append("skyline_");
|
||||
|
||||
if (kRand_RectType == fRectType) {
|
||||
fName.append("rand");
|
||||
@ -73,12 +66,7 @@ protected:
|
||||
void onDelayedSetup() override {
|
||||
SkASSERT(nullptr == fRectanizer.get());
|
||||
|
||||
if (kPow2_RectanizerType == fRectanizerType) {
|
||||
fRectanizer.reset(new GrRectanizerPow2(kWidth, kHeight));
|
||||
} else {
|
||||
SkASSERT(kSkyline_RectanizerType == fRectanizerType);
|
||||
fRectanizer.reset(new GrRectanizerSkyline(kWidth, kHeight));
|
||||
}
|
||||
fRectanizer.reset(new GrRectanizerSkyline(kWidth, kHeight));
|
||||
}
|
||||
|
||||
void onDraw(int loops, SkCanvas* canvas) override {
|
||||
@ -111,21 +99,14 @@ protected:
|
||||
|
||||
private:
|
||||
SkString fName;
|
||||
RectanizerType fRectanizerType;
|
||||
RectType fRectType;
|
||||
std::unique_ptr<GrRectanizer> fRectanizer;
|
||||
std::unique_ptr<GrRectanizerSkyline> fRectanizer;
|
||||
|
||||
typedef Benchmark INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_BENCH(return new RectanizerBench(RectanizerBench::kPow2_RectanizerType,
|
||||
RectanizerBench::kRand_RectType);)
|
||||
DEF_BENCH(return new RectanizerBench(RectanizerBench::kPow2_RectanizerType,
|
||||
RectanizerBench::kRandPow2_RectType);)
|
||||
DEF_BENCH(return new RectanizerBench(RectanizerBench::kPow2_RectanizerType,
|
||||
RectanizerBench::kSmallPow2_RectType);)
|
||||
DEF_BENCH(return new RectanizerBench(RectanizerBench::kSkyline_RectanizerType,
|
||||
RectanizerBench::kRand_RectType);)
|
||||
DEF_BENCH(return new RectanizerBench(RectanizerBench::kSkyline_RectanizerType,
|
||||
|
@ -147,11 +147,8 @@ skia_gpu_sources = [
|
||||
"$_src/gpu/GrProxyProvider.h",
|
||||
"$_src/gpu/GrRecordingContext.cpp",
|
||||
"$_src/gpu/GrRecordingContextPriv.h",
|
||||
"$_src/gpu/GrRectanizer.h",
|
||||
"$_src/gpu/GrRectanizer_pow2.cpp",
|
||||
"$_src/gpu/GrRectanizer_pow2.h",
|
||||
"$_src/gpu/GrRectanizer_skyline.cpp",
|
||||
"$_src/gpu/GrRectanizer_skyline.h",
|
||||
"$_src/gpu/GrRectanizerSkyline.cpp",
|
||||
"$_src/gpu/GrRectanizerSkyline.h",
|
||||
"$_src/gpu/GrRenderTarget.cpp",
|
||||
"$_src/gpu/GrRenderTarget.h",
|
||||
"$_src/gpu/GrRenderTargetPriv.h",
|
||||
|
@ -10,21 +10,20 @@
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/utils/SkRandom.h"
|
||||
#include "samplecode/Sample.h"
|
||||
#include "src/core/SkMathPriv.h"
|
||||
#include "src/utils/SkUTF.h"
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "src/gpu/GrRectanizer_pow2.h"
|
||||
#include "src/gpu/GrRectanizer_skyline.h"
|
||||
#include "src/gpu/GrRectanizerSkyline.h"
|
||||
|
||||
// This slide visualizes the various GrRectanizer-derived classes behavior
|
||||
// for various input sets
|
||||
// 'j' will cycle through the various rectanizers
|
||||
// Pow2 -> GrRectanizerPow2
|
||||
// Skyline -> GrRectanizerSkyline
|
||||
// 'h' will cycle through the various rect sets
|
||||
// Rand -> random rects from 2-256
|
||||
// Pow2Rand -> random power of 2 sized rects from 2-256
|
||||
// SmallPow2 -> 128x128 rects
|
||||
class RectanizerView : public Sample {
|
||||
static constexpr int kWidth = 1024;
|
||||
static constexpr int kHeight = 1024;
|
||||
public:
|
||||
RectanizerView()
|
||||
: fCurRandRect(0)
|
||||
@ -47,10 +46,7 @@ public:
|
||||
|
||||
fCurRects = &fRects[0];
|
||||
|
||||
fRectanizers.push_back(
|
||||
std::unique_ptr<GrRectanizer>(new GrRectanizerPow2(kWidth, kHeight)));
|
||||
fRectanizers.push_back(
|
||||
std::unique_ptr<GrRectanizer>(new GrRectanizerSkyline(kWidth, kHeight)));
|
||||
fRectanizers.emplace_back(kWidth, kHeight);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -62,9 +58,6 @@ protected:
|
||||
// Only consider events for single char keys
|
||||
if (1 == size) {
|
||||
switch (utf8[0]) {
|
||||
case kCycleRectanizerKey:
|
||||
this->cycleRectanizer();
|
||||
return true;
|
||||
case kCycleRectsKey:
|
||||
this->cycleRects();
|
||||
return true;
|
||||
@ -77,9 +70,9 @@ protected:
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
if (fCurRandRect < kNumRandRects) {
|
||||
if (fRectanizers[fCurRectanizer]->addRect((*fCurRects)[fCurRandRect].fWidth,
|
||||
(*fCurRects)[fCurRandRect].fHeight,
|
||||
&fRectLocations[fCurRandRect])) {
|
||||
if (fRectanizers[fCurRectanizer].addRect((*fCurRects)[fCurRandRect].fWidth,
|
||||
(*fCurRects)[fCurRandRect].fHeight,
|
||||
&fRectLocations[fCurRandRect])) {
|
||||
++fCurRandRect;
|
||||
}
|
||||
}
|
||||
@ -109,52 +102,34 @@ protected:
|
||||
|
||||
SkString str;
|
||||
|
||||
str.printf("%s-%s: tot Area: %ld %%full: %.2f (%.2f) numTextures: %d/%d",
|
||||
str.printf("%s-%s: tot Area: %ld (%.2f) numTextures: %d/%d",
|
||||
this->getRectanizerName(),
|
||||
this->getRectsName(),
|
||||
totArea,
|
||||
100.0f * fRectanizers[fCurRectanizer]->percentFull(),
|
||||
100.0f * totArea / ((float)kWidth*kHeight),
|
||||
fCurRandRect,
|
||||
kNumRandRects);
|
||||
canvas->drawString(str, 50, kHeight + 50, blackBigFont, SkPaint());
|
||||
|
||||
str.printf("Press \'j\' to toggle rectanizer");
|
||||
canvas->drawString(str, 50, kHeight + 100, blackBigFont, SkPaint());
|
||||
|
||||
str.printf("Press \'h\' to toggle rects");
|
||||
canvas->drawString(str, 50, kHeight + 150, blackBigFont, SkPaint());
|
||||
}
|
||||
|
||||
private:
|
||||
static const int kWidth = 1024;
|
||||
static const int kHeight = 1024;
|
||||
static const int kNumRandRects = 200;
|
||||
static const char kCycleRectanizerKey = 'j';
|
||||
static const char kCycleRectsKey = 'h';
|
||||
static const int kMinRectSize = 2;
|
||||
static const int kMaxRectSize = 256;
|
||||
|
||||
int fCurRandRect;
|
||||
SkTDArray<SkISize> fRects[3];
|
||||
SkTDArray<SkISize>* fCurRects;
|
||||
SkTDArray<SkIPoint16> fRectLocations;
|
||||
SkTArray<std::unique_ptr<GrRectanizer>> fRectanizers;
|
||||
int fCurRectanizer;
|
||||
int fCurRandRect;
|
||||
SkTDArray<SkISize> fRects[3];
|
||||
SkTDArray<SkISize>* fCurRects;
|
||||
SkTDArray<SkIPoint16> fRectLocations;
|
||||
SkTArray<GrRectanizerSkyline> fRectanizers;
|
||||
int fCurRectanizer;
|
||||
|
||||
const char* getRectanizerName() const {
|
||||
if (!fCurRectanizer) {
|
||||
return "Pow2";
|
||||
} else {
|
||||
return "Skyline";
|
||||
}
|
||||
}
|
||||
|
||||
void cycleRectanizer() {
|
||||
fCurRectanizer = (fCurRectanizer + 1) % fRectanizers.count();
|
||||
|
||||
fRectanizers[fCurRectanizer]->reset();
|
||||
fCurRandRect = 0;
|
||||
return "Skyline";
|
||||
}
|
||||
|
||||
const char* getRectsName() const {
|
||||
@ -176,7 +151,7 @@ private:
|
||||
fCurRects = &fRects[0];
|
||||
}
|
||||
|
||||
fRectanizers[fCurRectanizer]->reset();
|
||||
fRectanizers[fCurRectanizer].reset();
|
||||
fCurRandRect = 0;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "src/gpu/GrOnFlushResourceProvider.h"
|
||||
#include "src/gpu/GrOpFlushState.h"
|
||||
#include "src/gpu/GrProxyProvider.h"
|
||||
#include "src/gpu/GrRectanizer.h"
|
||||
#include "src/gpu/GrResourceProvider.h"
|
||||
#include "src/gpu/GrResourceProviderPriv.h"
|
||||
#include "src/gpu/GrSurfaceProxyPriv.h"
|
||||
@ -103,7 +102,7 @@ GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX
|
||||
, fHeight(height)
|
||||
, fX(offX)
|
||||
, fY(offY)
|
||||
, fRects(nullptr)
|
||||
, fRectanizer(width, height)
|
||||
, fOffset(SkIPoint16::Make(fX * fWidth, fY * fHeight))
|
||||
, fColorType(colorType)
|
||||
, fBytesPerPixel(GrColorTypeBytesPerPixel(colorType))
|
||||
@ -120,17 +119,12 @@ GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX
|
||||
|
||||
GrDrawOpAtlas::Plot::~Plot() {
|
||||
sk_free(fData);
|
||||
delete fRects;
|
||||
}
|
||||
|
||||
bool GrDrawOpAtlas::Plot::addSubImage(int width, int height, const void* image, SkIPoint16* loc) {
|
||||
SkASSERT(width <= fWidth && height <= fHeight);
|
||||
|
||||
if (!fRects) {
|
||||
fRects = GrRectanizer::Factory(fWidth, fHeight);
|
||||
}
|
||||
|
||||
if (!fRects->addRect(width, height, loc)) {
|
||||
if (!fRectanizer.addRect(width, height, loc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -192,9 +186,7 @@ void GrDrawOpAtlas::Plot::uploadToTexture(GrDeferredTextureUploadWritePixelsFn&
|
||||
}
|
||||
|
||||
void GrDrawOpAtlas::Plot::resetRects() {
|
||||
if (fRects) {
|
||||
fRects->reset();
|
||||
}
|
||||
fRectanizer.reset();
|
||||
|
||||
fGenID++;
|
||||
fID = CreateId(fPageIndex, fPlotIndex, fGenID);
|
||||
|
@ -16,10 +16,10 @@
|
||||
#include "src/core/SkIPoint16.h"
|
||||
#include "src/core/SkTInternalLList.h"
|
||||
|
||||
#include "src/gpu/GrRectanizerSkyline.h"
|
||||
#include "src/gpu/ops/GrDrawOp.h"
|
||||
|
||||
class GrOnFlushResourceProvider;
|
||||
class GrRectanizer;
|
||||
|
||||
|
||||
/**
|
||||
@ -357,7 +357,7 @@ private:
|
||||
const int fHeight;
|
||||
const int fX;
|
||||
const int fY;
|
||||
GrRectanizer* fRects;
|
||||
GrRectanizerSkyline fRectanizer;
|
||||
const SkIPoint16 fOffset; // the offset of the plot in the backing texture
|
||||
const GrColorType fColorType;
|
||||
const size_t fBytesPerPixel;
|
||||
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef GrRectanizer_DEFINED
|
||||
#define GrRectanizer_DEFINED
|
||||
|
||||
#include "include/gpu/GrTypes.h"
|
||||
|
||||
struct SkIPoint16;
|
||||
|
||||
class GrRectanizer {
|
||||
public:
|
||||
GrRectanizer(int width, int height) : fWidth(width), fHeight(height) {
|
||||
SkASSERT(width >= 0);
|
||||
SkASSERT(height >= 0);
|
||||
}
|
||||
|
||||
virtual ~GrRectanizer() {}
|
||||
|
||||
virtual void reset() = 0;
|
||||
|
||||
int width() const { return fWidth; }
|
||||
int height() const { return fHeight; }
|
||||
|
||||
// Attempt to add a rect. Return true on success; false on failure. If
|
||||
// successful the position in the atlas is returned in 'loc'.
|
||||
virtual bool addRect(int width, int height, SkIPoint16* loc) = 0;
|
||||
virtual float percentFull() const = 0;
|
||||
|
||||
/**
|
||||
* Our factory, which returns the subclass du jour
|
||||
*/
|
||||
static GrRectanizer* Factory(int width, int height);
|
||||
|
||||
private:
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
};
|
||||
|
||||
#endif
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "src/core/SkIPoint16.h"
|
||||
#include "src/gpu/GrRectanizer_skyline.h"
|
||||
#include "src/gpu/GrRectanizerSkyline.h"
|
||||
|
||||
bool GrRectanizerSkyline::addRect(int width, int height, SkIPoint16* loc) {
|
||||
if ((unsigned)width > (unsigned)this->width() ||
|
||||
@ -114,8 +114,3 @@ void GrRectanizerSkyline::addSkylineLevel(int skylineIndex, int x, int y, int wi
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrRectanizer* GrRectanizer::Factory(int width, int height) {
|
||||
return new GrRectanizerSkyline(width, height);
|
||||
}
|
@ -5,23 +5,21 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef GrRectanizer_skyline_DEFINED
|
||||
#define GrRectanizer_skyline_DEFINED
|
||||
#ifndef GrRectanizerSkyline_DEFINED
|
||||
#define GrRectanizerSkyline_DEFINED
|
||||
|
||||
#include "include/private/SkTDArray.h"
|
||||
#include "src/gpu/GrRectanizer.h"
|
||||
#include "src/core/SkIPoint16.h"
|
||||
|
||||
// Pack rectangles and track the current silhouette
|
||||
// Based, in part, on Jukka Jylanki's work at http://clb.demon.fi
|
||||
class GrRectanizerSkyline : public GrRectanizer {
|
||||
class GrRectanizerSkyline {
|
||||
public:
|
||||
GrRectanizerSkyline(int w, int h) : INHERITED(w, h) {
|
||||
GrRectanizerSkyline(int w, int h) : fWidth{w}, fHeight{h} {
|
||||
this->reset();
|
||||
}
|
||||
|
||||
~GrRectanizerSkyline() override { }
|
||||
|
||||
void reset() override {
|
||||
void reset() {
|
||||
fAreaSoFar = 0;
|
||||
fSkyline.reset();
|
||||
SkylineSegment* seg = fSkyline.append(1);
|
||||
@ -30,11 +28,10 @@ public:
|
||||
seg->fWidth = this->width();
|
||||
}
|
||||
|
||||
bool addRect(int w, int h, SkIPoint16* loc) override;
|
||||
bool addRect(int w, int h, SkIPoint16* loc);
|
||||
|
||||
float percentFull() const override {
|
||||
return fAreaSoFar / ((float)this->width() * this->height());
|
||||
}
|
||||
int width() const { return fWidth; }
|
||||
int height() const { return fHeight; }
|
||||
|
||||
private:
|
||||
struct SkylineSegment {
|
||||
@ -43,10 +40,6 @@ private:
|
||||
int fWidth;
|
||||
};
|
||||
|
||||
SkTDArray<SkylineSegment> fSkyline;
|
||||
|
||||
int32_t fAreaSoFar;
|
||||
|
||||
// Can a width x height rectangle fit in the free space represented by
|
||||
// the skyline segments >= 'skylineIndex'? If so, return true and fill in
|
||||
// 'y' with the y-location at which it fits (the x location is pulled from
|
||||
@ -56,7 +49,10 @@ private:
|
||||
// at x,y.
|
||||
void addSkylineLevel(int skylineIndex, int x, int y, int width, int height);
|
||||
|
||||
typedef GrRectanizer INHERITED;
|
||||
SkTDArray<SkylineSegment> fSkyline;
|
||||
int32_t fAreaSoFar;
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // GrRectanizerSkyline_DEFINED
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "src/gpu/GrRectanizer_pow2.h"
|
||||
|
||||
bool GrRectanizerPow2::addRect(int width, int height, SkIPoint16* loc) {
|
||||
if ((unsigned)width > (unsigned)this->width() ||
|
||||
(unsigned)height > (unsigned)this->height()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t area = width * height; // computed here since height will be modified
|
||||
|
||||
height = GrNextPow2(height);
|
||||
if (height < kMIN_HEIGHT_POW2) {
|
||||
height = kMIN_HEIGHT_POW2;
|
||||
}
|
||||
|
||||
Row* row = &fRows[HeightToRowIndex(height)];
|
||||
SkASSERT(row->fRowHeight == 0 || row->fRowHeight == height);
|
||||
|
||||
if (0 == row->fRowHeight) {
|
||||
if (!this->canAddStrip(height)) {
|
||||
return false;
|
||||
}
|
||||
this->initRow(row, height);
|
||||
} else {
|
||||
if (!row->canAddWidth(width, this->width())) {
|
||||
if (!this->canAddStrip(height)) {
|
||||
return false;
|
||||
}
|
||||
// that row is now "full", so retarget our Row record for
|
||||
// another one
|
||||
this->initRow(row, height);
|
||||
}
|
||||
}
|
||||
|
||||
SkASSERT(row->fRowHeight == height);
|
||||
SkASSERT(row->canAddWidth(width, this->width()));
|
||||
*loc = row->fLoc;
|
||||
row->fLoc.fX += width;
|
||||
|
||||
SkASSERT(row->fLoc.fX <= this->width());
|
||||
SkASSERT(row->fLoc.fY <= this->height());
|
||||
SkASSERT(fNextStripY <= this->height());
|
||||
fAreaSoFar += area;
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// factory is now in GrRectanizer_skyline.cpp
|
||||
//GrRectanizer* GrRectanizer::Factory(int width, int height) {
|
||||
// return new GrRectanizerPow2 (width, height);
|
||||
//}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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 "include/private/SkMalloc.h"
|
||||
#include "src/core/SkIPoint16.h"
|
||||
#include "src/core/SkMathPriv.h"
|
||||
#include "src/gpu/GrRectanizer.h"
|
||||
|
||||
// This Rectanizer quantizes the incoming rects to powers of 2. Each power
|
||||
// of two can have, at most, one active row/shelf. Once a row/shelf for
|
||||
// a particular power of two gets full its fRows entry is recycled to point
|
||||
// to a new row.
|
||||
// The skyline algorithm almost always provides a better packing.
|
||||
class GrRectanizerPow2 : public GrRectanizer {
|
||||
public:
|
||||
GrRectanizerPow2(int w, int h) : INHERITED(w, h) {
|
||||
this->reset();
|
||||
}
|
||||
|
||||
~GrRectanizerPow2() override {}
|
||||
|
||||
void reset() override {
|
||||
fNextStripY = 0;
|
||||
fAreaSoFar = 0;
|
||||
sk_bzero(fRows, sizeof(fRows));
|
||||
}
|
||||
|
||||
bool addRect(int w, int h, SkIPoint16* loc) override;
|
||||
|
||||
float percentFull() const override {
|
||||
return fAreaSoFar / ((float)this->width() * this->height());
|
||||
}
|
||||
|
||||
private:
|
||||
static const int kMIN_HEIGHT_POW2 = 2;
|
||||
static const int kMaxExponent = 16;
|
||||
|
||||
struct Row {
|
||||
SkIPoint16 fLoc;
|
||||
// fRowHeight is actually known by this struct's position in fRows
|
||||
// but it is used to signal if there exists an open row of this height
|
||||
int fRowHeight;
|
||||
|
||||
bool canAddWidth(int width, int containerWidth) const {
|
||||
return fLoc.fX + width <= containerWidth;
|
||||
}
|
||||
};
|
||||
|
||||
Row fRows[kMaxExponent]; // 0-th entry will be unused
|
||||
|
||||
int fNextStripY;
|
||||
int32_t fAreaSoFar;
|
||||
|
||||
static int HeightToRowIndex(int height) {
|
||||
SkASSERT(height >= kMIN_HEIGHT_POW2);
|
||||
int index = 32 - SkCLZ(height - 1);
|
||||
SkASSERT(index < kMaxExponent);
|
||||
return index;
|
||||
}
|
||||
|
||||
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
|
@ -13,7 +13,7 @@
|
||||
#include "src/gpu/GrCaps.h"
|
||||
#include "src/gpu/GrOnFlushResourceProvider.h"
|
||||
#include "src/gpu/GrProxyProvider.h"
|
||||
#include "src/gpu/GrRectanizer_skyline.h"
|
||||
#include "src/gpu/GrRectanizerSkyline.h"
|
||||
#include "src/gpu/GrRenderTarget.h"
|
||||
#include "src/gpu/GrRenderTargetContext.h"
|
||||
#include "src/gpu/GrTextureProxy.h"
|
||||
|
@ -8,28 +8,25 @@
|
||||
#include "include/core/SkSize.h"
|
||||
#include "include/private/SkTDArray.h"
|
||||
#include "include/utils/SkRandom.h"
|
||||
#include "src/gpu/GrRectanizer_pow2.h"
|
||||
#include "src/gpu/GrRectanizer_skyline.h"
|
||||
#include "src/gpu/GrRectanizerSkyline.h"
|
||||
#include "tests/Test.h"
|
||||
|
||||
static const int kWidth = 1024;
|
||||
static const int kHeight = 1024;
|
||||
|
||||
// Basic test of a GrRectanizer-derived class' functionality
|
||||
static void test_rectanizer_basic(skiatest::Reporter* reporter, GrRectanizer* rectanizer) {
|
||||
static void test_rectanizer_basic(skiatest::Reporter* reporter, GrRectanizerSkyline* rectanizer) {
|
||||
REPORTER_ASSERT(reporter, kWidth == rectanizer->width());
|
||||
REPORTER_ASSERT(reporter, kHeight == rectanizer->height());
|
||||
|
||||
SkIPoint16 loc;
|
||||
|
||||
REPORTER_ASSERT(reporter, rectanizer->addRect(50, 50, &loc));
|
||||
REPORTER_ASSERT(reporter, rectanizer->percentFull() > 0.0f);
|
||||
rectanizer->reset();
|
||||
REPORTER_ASSERT(reporter, rectanizer->percentFull() == 0.0f);
|
||||
}
|
||||
|
||||
static void test_rectanizer_inserts(skiatest::Reporter*,
|
||||
GrRectanizer* rectanizer,
|
||||
GrRectanizerSkyline* rectanizer,
|
||||
const SkTDArray<SkISize>& rects) {
|
||||
int i;
|
||||
for (i = 0; i < rects.count(); ++i) {
|
||||
@ -49,13 +46,6 @@ static void test_skyline(skiatest::Reporter* reporter, const SkTDArray<SkISize>&
|
||||
test_rectanizer_inserts(reporter, &skylineRectanizer, rects);
|
||||
}
|
||||
|
||||
static void test_pow2(skiatest::Reporter* reporter, const SkTDArray<SkISize>& rects) {
|
||||
GrRectanizerPow2 pow2Rectanizer(kWidth, kHeight);
|
||||
|
||||
test_rectanizer_basic(reporter, &pow2Rectanizer);
|
||||
test_rectanizer_inserts(reporter, &pow2Rectanizer, rects);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(GpuRectanizer, reporter, factory) {
|
||||
SkTDArray<SkISize> rects;
|
||||
SkRandom rand;
|
||||
@ -66,5 +56,4 @@ DEF_GPUTEST(GpuRectanizer, reporter, factory) {
|
||||
}
|
||||
|
||||
test_skyline(reporter, rects);
|
||||
test_pow2(reporter, rects);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user