Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e4ddb8a

Browse files
reed-at-googleSkia Commit-Bot
authored andcommitted
Revert "Specialize SkRectanzier to SkRectanizerSkyline"
This reverts commit 77e1f84. Reason for revert: breaking google3 roll? 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> TBR=mtklein@google.com,herb@google.com Change-Id: I2573534f3ea95c98d089f9c19b027564e77015db No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/266116 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
1 parent 20d0f92 commit e4ddb8a

File tree

12 files changed

+307
-48
lines changed

12 files changed

+307
-48
lines changed

bench/RectanizerBench.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "include/private/SkTDArray.h"
1111
#include "include/utils/SkRandom.h"
1212

13-
#include "src/core/SkMathPriv.h"
14-
#include "src/gpu/GrRectanizerSkyline.h"
13+
#include "src/gpu/GrRectanizer_pow2.h"
14+
#include "src/gpu/GrRectanizer_skyline.h"
1515

1616
/**
1717
* This bench exercises Ganesh' GrRectanizer classes. It exercises the following
@@ -29,6 +29,7 @@ class RectanizerBench : public Benchmark {
2929
static const int kHeight = 1024;
3030

3131
enum RectanizerType {
32+
kPow2_RectanizerType,
3233
kSkyline_RectanizerType,
3334
};
3435

@@ -40,9 +41,15 @@ class RectanizerBench : public Benchmark {
4041

4142
RectanizerBench(RectanizerType rectanizerType, RectType rectType)
4243
: fName("rectanizer_")
44+
, fRectanizerType(rectanizerType)
4345
, fRectType(rectType) {
4446

45-
fName.append("skyline_");
47+
if (kPow2_RectanizerType == fRectanizerType) {
48+
fName.append("pow2_");
49+
} else {
50+
SkASSERT(kSkyline_RectanizerType == fRectanizerType);
51+
fName.append("skyline_");
52+
}
4653

4754
if (kRand_RectType == fRectType) {
4855
fName.append("rand");
@@ -66,7 +73,12 @@ class RectanizerBench : public Benchmark {
6673
void onDelayedSetup() override {
6774
SkASSERT(nullptr == fRectanizer.get());
6875

69-
fRectanizer.reset(new GrRectanizerSkyline(kWidth, kHeight));
76+
if (kPow2_RectanizerType == fRectanizerType) {
77+
fRectanizer.reset(new GrRectanizerPow2(kWidth, kHeight));
78+
} else {
79+
SkASSERT(kSkyline_RectanizerType == fRectanizerType);
80+
fRectanizer.reset(new GrRectanizerSkyline(kWidth, kHeight));
81+
}
7082
}
7183

7284
void onDraw(int loops, SkCanvas* canvas) override {
@@ -99,14 +111,21 @@ class RectanizerBench : public Benchmark {
99111

100112
private:
101113
SkString fName;
114+
RectanizerType fRectanizerType;
102115
RectType fRectType;
103-
std::unique_ptr<GrRectanizerSkyline> fRectanizer;
116+
std::unique_ptr<GrRectanizer> fRectanizer;
104117

105118
typedef Benchmark INHERITED;
106119
};
107120

108121
//////////////////////////////////////////////////////////////////////////////
109122

123+
DEF_BENCH(return new RectanizerBench(RectanizerBench::kPow2_RectanizerType,
124+
RectanizerBench::kRand_RectType);)
125+
DEF_BENCH(return new RectanizerBench(RectanizerBench::kPow2_RectanizerType,
126+
RectanizerBench::kRandPow2_RectType);)
127+
DEF_BENCH(return new RectanizerBench(RectanizerBench::kPow2_RectanizerType,
128+
RectanizerBench::kSmallPow2_RectType);)
110129
DEF_BENCH(return new RectanizerBench(RectanizerBench::kSkyline_RectanizerType,
111130
RectanizerBench::kRand_RectType);)
112131
DEF_BENCH(return new RectanizerBench(RectanizerBench::kSkyline_RectanizerType,

gn/gpu.gni

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ skia_gpu_sources = [
147147
"$_src/gpu/GrProxyProvider.h",
148148
"$_src/gpu/GrRecordingContext.cpp",
149149
"$_src/gpu/GrRecordingContextPriv.h",
150-
"$_src/gpu/GrRectanizerSkyline.cpp",
151-
"$_src/gpu/GrRectanizerSkyline.h",
150+
"$_src/gpu/GrRectanizer.h",
151+
"$_src/gpu/GrRectanizer_pow2.cpp",
152+
"$_src/gpu/GrRectanizer_pow2.h",
153+
"$_src/gpu/GrRectanizer_skyline.cpp",
154+
"$_src/gpu/GrRectanizer_skyline.h",
152155
"$_src/gpu/GrRenderTarget.cpp",
153156
"$_src/gpu/GrRenderTarget.h",
154157
"$_src/gpu/GrRenderTargetPriv.h",

samplecode/SampleRectanizer.cpp

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
#include "include/core/SkPaint.h"
1111
#include "include/utils/SkRandom.h"
1212
#include "samplecode/Sample.h"
13-
#include "src/core/SkMathPriv.h"
1413
#include "src/utils/SkUTF.h"
1514
#if SK_SUPPORT_GPU
16-
#include "src/gpu/GrRectanizerSkyline.h"
15+
#include "src/gpu/GrRectanizer_pow2.h"
16+
#include "src/gpu/GrRectanizer_skyline.h"
1717

1818
// This slide visualizes the various GrRectanizer-derived classes behavior
1919
// for various input sets
20+
// 'j' will cycle through the various rectanizers
21+
// Pow2 -> GrRectanizerPow2
22+
// Skyline -> GrRectanizerSkyline
2023
// 'h' will cycle through the various rect sets
2124
// Rand -> random rects from 2-256
2225
// Pow2Rand -> random power of 2 sized rects from 2-256
2326
// SmallPow2 -> 128x128 rects
2427
class RectanizerView : public Sample {
25-
static constexpr int kWidth = 1024;
26-
static constexpr int kHeight = 1024;
2728
public:
2829
RectanizerView()
2930
: fCurRandRect(0)
@@ -46,7 +47,10 @@ class RectanizerView : public Sample {
4647

4748
fCurRects = &fRects[0];
4849

49-
fRectanizers.emplace_back(kWidth, kHeight);
50+
fRectanizers.push_back(
51+
std::unique_ptr<GrRectanizer>(new GrRectanizerPow2(kWidth, kHeight)));
52+
fRectanizers.push_back(
53+
std::unique_ptr<GrRectanizer>(new GrRectanizerSkyline(kWidth, kHeight)));
5054
}
5155

5256
protected:
@@ -58,6 +62,9 @@ class RectanizerView : public Sample {
5862
// Only consider events for single char keys
5963
if (1 == size) {
6064
switch (utf8[0]) {
65+
case kCycleRectanizerKey:
66+
this->cycleRectanizer();
67+
return true;
6168
case kCycleRectsKey:
6269
this->cycleRects();
6370
return true;
@@ -70,9 +77,9 @@ class RectanizerView : public Sample {
7077

7178
void onDrawContent(SkCanvas* canvas) override {
7279
if (fCurRandRect < kNumRandRects) {
73-
if (fRectanizers[fCurRectanizer].addRect((*fCurRects)[fCurRandRect].fWidth,
74-
(*fCurRects)[fCurRandRect].fHeight,
75-
&fRectLocations[fCurRandRect])) {
80+
if (fRectanizers[fCurRectanizer]->addRect((*fCurRects)[fCurRandRect].fWidth,
81+
(*fCurRects)[fCurRandRect].fHeight,
82+
&fRectLocations[fCurRandRect])) {
7683
++fCurRandRect;
7784
}
7885
}
@@ -102,34 +109,52 @@ class RectanizerView : public Sample {
102109

103110
SkString str;
104111

105-
str.printf("%s-%s: tot Area: %ld (%.2f) numTextures: %d/%d",
112+
str.printf("%s-%s: tot Area: %ld %%full: %.2f (%.2f) numTextures: %d/%d",
106113
this->getRectanizerName(),
107114
this->getRectsName(),
108115
totArea,
116+
100.0f * fRectanizers[fCurRectanizer]->percentFull(),
109117
100.0f * totArea / ((float)kWidth*kHeight),
110118
fCurRandRect,
111119
kNumRandRects);
112120
canvas->drawString(str, 50, kHeight + 50, blackBigFont, SkPaint());
113121

122+
str.printf("Press \'j\' to toggle rectanizer");
123+
canvas->drawString(str, 50, kHeight + 100, blackBigFont, SkPaint());
124+
114125
str.printf("Press \'h\' to toggle rects");
115126
canvas->drawString(str, 50, kHeight + 150, blackBigFont, SkPaint());
116127
}
117128

118129
private:
130+
static const int kWidth = 1024;
131+
static const int kHeight = 1024;
119132
static const int kNumRandRects = 200;
133+
static const char kCycleRectanizerKey = 'j';
120134
static const char kCycleRectsKey = 'h';
121135
static const int kMinRectSize = 2;
122136
static const int kMaxRectSize = 256;
123137

124-
int fCurRandRect;
125-
SkTDArray<SkISize> fRects[3];
126-
SkTDArray<SkISize>* fCurRects;
127-
SkTDArray<SkIPoint16> fRectLocations;
128-
SkTArray<GrRectanizerSkyline> fRectanizers;
129-
int fCurRectanizer;
138+
int fCurRandRect;
139+
SkTDArray<SkISize> fRects[3];
140+
SkTDArray<SkISize>* fCurRects;
141+
SkTDArray<SkIPoint16> fRectLocations;
142+
SkTArray<std::unique_ptr<GrRectanizer>> fRectanizers;
143+
int fCurRectanizer;
130144

131145
const char* getRectanizerName() const {
132-
return "Skyline";
146+
if (!fCurRectanizer) {
147+
return "Pow2";
148+
} else {
149+
return "Skyline";
150+
}
151+
}
152+
153+
void cycleRectanizer() {
154+
fCurRectanizer = (fCurRectanizer + 1) % fRectanizers.count();
155+
156+
fRectanizers[fCurRectanizer]->reset();
157+
fCurRandRect = 0;
133158
}
134159

135160
const char* getRectsName() const {
@@ -151,7 +176,7 @@ class RectanizerView : public Sample {
151176
fCurRects = &fRects[0];
152177
}
153178

154-
fRectanizers[fCurRectanizer].reset();
179+
fRectanizers[fCurRectanizer]->reset();
155180
fCurRandRect = 0;
156181
}
157182

src/gpu/GrDrawOpAtlas.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "src/gpu/GrOnFlushResourceProvider.h"
1616
#include "src/gpu/GrOpFlushState.h"
1717
#include "src/gpu/GrProxyProvider.h"
18+
#include "src/gpu/GrRectanizer.h"
1819
#include "src/gpu/GrResourceProvider.h"
1920
#include "src/gpu/GrResourceProviderPriv.h"
2021
#include "src/gpu/GrSurfaceProxyPriv.h"
@@ -102,7 +103,7 @@ GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX
102103
, fHeight(height)
103104
, fX(offX)
104105
, fY(offY)
105-
, fRectanizer(width, height)
106+
, fRects(nullptr)
106107
, fOffset(SkIPoint16::Make(fX * fWidth, fY * fHeight))
107108
, fColorType(colorType)
108109
, fBytesPerPixel(GrColorTypeBytesPerPixel(colorType))
@@ -119,12 +120,17 @@ GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX
119120

120121
GrDrawOpAtlas::Plot::~Plot() {
121122
sk_free(fData);
123+
delete fRects;
122124
}
123125

124126
bool GrDrawOpAtlas::Plot::addSubImage(int width, int height, const void* image, SkIPoint16* loc) {
125127
SkASSERT(width <= fWidth && height <= fHeight);
126128

127-
if (!fRectanizer.addRect(width, height, loc)) {
129+
if (!fRects) {
130+
fRects = GrRectanizer::Factory(fWidth, fHeight);
131+
}
132+
133+
if (!fRects->addRect(width, height, loc)) {
128134
return false;
129135
}
130136

@@ -186,7 +192,9 @@ void GrDrawOpAtlas::Plot::uploadToTexture(GrDeferredTextureUploadWritePixelsFn&
186192
}
187193

188194
void GrDrawOpAtlas::Plot::resetRects() {
189-
fRectanizer.reset();
195+
if (fRects) {
196+
fRects->reset();
197+
}
190198

191199
fGenID++;
192200
fID = CreateId(fPageIndex, fPlotIndex, fGenID);

src/gpu/GrDrawOpAtlas.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
#include "src/core/SkIPoint16.h"
1717
#include "src/core/SkTInternalLList.h"
1818

19-
#include "src/gpu/GrRectanizerSkyline.h"
2019
#include "src/gpu/ops/GrDrawOp.h"
2120

2221
class GrOnFlushResourceProvider;
22+
class GrRectanizer;
2323

2424

2525
/**
@@ -357,7 +357,7 @@ class GrDrawOpAtlas {
357357
const int fHeight;
358358
const int fX;
359359
const int fY;
360-
GrRectanizerSkyline fRectanizer;
360+
GrRectanizer* fRects;
361361
const SkIPoint16 fOffset; // the offset of the plot in the backing texture
362362
const GrColorType fColorType;
363363
const size_t fBytesPerPixel;

src/gpu/GrRectanizer.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2010 Google Inc.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#ifndef GrRectanizer_DEFINED
9+
#define GrRectanizer_DEFINED
10+
11+
#include "include/gpu/GrTypes.h"
12+
13+
struct SkIPoint16;
14+
15+
class GrRectanizer {
16+
public:
17+
GrRectanizer(int width, int height) : fWidth(width), fHeight(height) {
18+
SkASSERT(width >= 0);
19+
SkASSERT(height >= 0);
20+
}
21+
22+
virtual ~GrRectanizer() {}
23+
24+
virtual void reset() = 0;
25+
26+
int width() const { return fWidth; }
27+
int height() const { return fHeight; }
28+
29+
// Attempt to add a rect. Return true on success; false on failure. If
30+
// successful the position in the atlas is returned in 'loc'.
31+
virtual bool addRect(int width, int height, SkIPoint16* loc) = 0;
32+
virtual float percentFull() const = 0;
33+
34+
/**
35+
* Our factory, which returns the subclass du jour
36+
*/
37+
static GrRectanizer* Factory(int width, int height);
38+
39+
private:
40+
int fWidth;
41+
int fHeight;
42+
};
43+
44+
#endif

src/gpu/GrRectanizer_pow2.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2010 Google Inc.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include "src/gpu/GrRectanizer_pow2.h"
9+
10+
bool GrRectanizerPow2::addRect(int width, int height, SkIPoint16* loc) {
11+
if ((unsigned)width > (unsigned)this->width() ||
12+
(unsigned)height > (unsigned)this->height()) {
13+
return false;
14+
}
15+
16+
int32_t area = width * height; // computed here since height will be modified
17+
18+
height = GrNextPow2(height);
19+
if (height < kMIN_HEIGHT_POW2) {
20+
height = kMIN_HEIGHT_POW2;
21+
}
22+
23+
Row* row = &fRows[HeightToRowIndex(height)];
24+
SkASSERT(row->fRowHeight == 0 || row->fRowHeight == height);
25+
26+
if (0 == row->fRowHeight) {
27+
if (!this->canAddStrip(height)) {
28+
return false;
29+
}
30+
this->initRow(row, height);
31+
} else {
32+
if (!row->canAddWidth(width, this->width())) {
33+
if (!this->canAddStrip(height)) {
34+
return false;
35+
}
36+
// that row is now "full", so retarget our Row record for
37+
// another one
38+
this->initRow(row, height);
39+
}
40+
}
41+
42+
SkASSERT(row->fRowHeight == height);
43+
SkASSERT(row->canAddWidth(width, this->width()));
44+
*loc = row->fLoc;
45+
row->fLoc.fX += width;
46+
47+
SkASSERT(row->fLoc.fX <= this->width());
48+
SkASSERT(row->fLoc.fY <= this->height());
49+
SkASSERT(fNextStripY <= this->height());
50+
fAreaSoFar += area;
51+
return true;
52+
}
53+
54+
///////////////////////////////////////////////////////////////////////////////
55+
56+
// factory is now in GrRectanizer_skyline.cpp
57+
//GrRectanizer* GrRectanizer::Factory(int width, int height) {
58+
// return new GrRectanizerPow2 (width, height);
59+
//}

0 commit comments

Comments
 (0)