Skip to content

Commit

Permalink
Remove SkMin32/SkMax32
Browse files Browse the repository at this point in the history
Use std::max and std::min instead

Change-Id: I7fd2626ea9ea8ea09c709ff962523ca3de2f8a16
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/269136
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
  • Loading branch information
brianosman authored and Skia Commit-Bot committed Feb 6, 2020
1 parent 18b90bc commit 7f36405
Show file tree
Hide file tree
Showing 44 changed files with 89 additions and 97 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This file includes a list of high level updates for each milestone release.
Milestone 82

<Insert new notes here- top is most recent.>
* Removed SkMax32 and SkMin32.
* Removed SkMaxScalar and SkMinScalar.

* SkColorSetA now warns if the result is unused.
Expand Down
2 changes: 1 addition & 1 deletion bench/AlternatingColorPatternBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void makebm(SkBitmap* bm, int w, int h) {
bm->eraseColor(SK_ColorTRANSPARENT);

SkCanvas canvas(*bm);
SkScalar s = SkIntToScalar(SkMin32(w, h));
SkScalar s = SkIntToScalar(std::min(w, h));
static const SkPoint kPts0[] = { { 0, 0 }, { s, s } };
static const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } };
static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
Expand Down
2 changes: 1 addition & 1 deletion bench/BitmapBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class BitmapBench : public Benchmark {
p.setAntiAlias(true);
p.setColor(SK_ColorRED);
canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2,
SkIntToScalar(SkMin32(w, h))*3/8, p);
SkIntToScalar(std::min(w, h))*3/8, p);

SkRect r;
r.setWH(SkIntToScalar(w), SkIntToScalar(h));
Expand Down
2 changes: 1 addition & 1 deletion bench/BitmapRectBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void draw_into_bitmap(const SkBitmap& bm) {
p.setAntiAlias(true);
p.setColor(SK_ColorRED);
canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2,
SkIntToScalar(SkMin32(w, h))*3/8, p);
SkIntToScalar(std::min(w, h))*3/8, p);

SkRect r;
r.setWH(SkIntToScalar(w), SkIntToScalar(h));
Expand Down
2 changes: 1 addition & 1 deletion bench/ChartBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ChartBench : public Benchmark {

SkScalar height = SkIntToScalar(fSize.fHeight);
if (sizeChanged) {
int dataPointCount = SkMax32(fSize.fWidth / kPixelsPerTick + 1, 2);
int dataPointCount = std::max(fSize.fWidth / kPixelsPerTick + 1, 2);

SkRandom random;
for (int i = 0; i < kNumGraphs; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion bench/FontCacheBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class FontCacheEfficiency : public Benchmark {
int glyphs = 0;
const uint16_t* array = gUniqueGlyphIDs;
while (*array != gUniqueGlyphIDs_Sentinel) {
int count = SkMin32(count_glyphs(array), limit);
int count = std::min(count_glyphs(array), limit);
collisions += count_collisions(array, count, gRec[i].fHasher, hashMask);
glyphs += count;
array += count + 1; // skip the sentinel
Expand Down
2 changes: 1 addition & 1 deletion bench/RepeatTileBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void draw_into_bitmap(const SkBitmap& bm) {
p.setAntiAlias(true);
p.setColor(SK_ColorRED);
canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2,
SkIntToScalar(SkMin32(w, h))*3/8, p);
SkIntToScalar(std::min(w, h))*3/8, p);

SkRect r;
r.setWH(SkIntToScalar(w), SkIntToScalar(h));
Expand Down
4 changes: 2 additions & 2 deletions gm/fontmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class FontMgrGM : public skiagm::GM {
font.setSize(17);

SkFontMgr* fm = fFM.get();
int count = SkMin32(fm->countFamilies(), MAX_FAMILIES);
int count = std::min(fm->countFamilies(), MAX_FAMILIES);

for (int i = 0; i < count; ++i) {
SkString familyName;
Expand Down Expand Up @@ -316,7 +316,7 @@ class FontMgrBoundsGM : public skiagm::GM {
const SkColor boundsColors[2] = { SK_ColorRED, SK_ColorBLUE };

SkFontMgr* fm = fFM.get();
int count = SkMin32(fm->countFamilies(), 32);
int count = std::min(fm->countFamilies(), 32);

int index = 0;
SkScalar x = 0, y = 0;
Expand Down
2 changes: 1 addition & 1 deletion gm/modecolorfilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ModeColorFilterGM : public GM {

SkPaint paint;
int idx = 0;
const int kRectsPerRow = SkMax32(this->getISize().fWidth / kRectWidth, 1);
const int kRectsPerRow = std::max(this->getISize().fWidth / kRectWidth, 1);
for (size_t cfm = 0; cfm < SK_ARRAY_COUNT(modes); ++cfm) {
for (size_t cfc = 0; cfc < SK_ARRAY_COUNT(colors); ++cfc) {
paint.setColorFilter(SkColorFilters::Blend(colors[cfc], modes[cfm]));
Expand Down
2 changes: 1 addition & 1 deletion gm/shadertext3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void makebm(SkBitmap* bm, int w, int h) {
bm->eraseColor(SK_ColorTRANSPARENT);

SkCanvas canvas(*bm);
SkScalar s = SkIntToScalar(SkMin32(w, h));
SkScalar s = SkIntToScalar(std::min(w, h));
const SkPoint kPts0[] = { { 0, 0 }, { s, s } };
const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } };
const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
Expand Down
2 changes: 1 addition & 1 deletion gm/stringart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class StringArtGM : public skiagm::GM {

void onDraw(SkCanvas* canvas) override {
SkScalar angle = kAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
SkScalar size = SkIntToScalar(SkMin32(kWidth, kHeight));
SkScalar size = SkIntToScalar(std::min(kWidth, kHeight));
SkPoint center = SkPoint::Make(SkScalarHalf(kWidth), SkScalarHalf(kHeight));
SkScalar length = 5;
SkScalar step = angle;
Expand Down
4 changes: 2 additions & 2 deletions include/core/SkRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ struct SK_API SkIRect {
@return sorted SkIRect
*/
SkIRect makeSorted() const {
return MakeLTRB(SkMin32(fLeft, fRight), SkMin32(fTop, fBottom),
SkMax32(fLeft, fRight), SkMax32(fTop, fBottom));
return MakeLTRB(std::min(fLeft, fRight), std::min(fTop, fBottom),
std::max(fLeft, fRight), std::max(fTop, fBottom));
}
};

Expand Down
12 changes: 0 additions & 12 deletions include/core/SkTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,6 @@ template <typename T> static inline T SkTAbs(T value) {
return value;
}

static inline int32_t SkMax32(int32_t a, int32_t b) {
if (a < b)
a = b;
return a;
}

static inline int32_t SkMin32(int32_t a, int32_t b) {
if (a > b)
a = b;
return a;
}

template <typename T> constexpr const T& SkTMin(const T& a, const T& b) {
return (a < b) ? a : b;
}
Expand Down
3 changes: 2 additions & 1 deletion include/private/SkTDArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "include/private/SkMalloc.h"
#include "include/private/SkTo.h"

#include <algorithm>
#include <initializer_list>
#include <utility>

Expand Down Expand Up @@ -253,7 +254,7 @@ template <typename T> class SkTDArray {
if (index >= fCount) {
return 0;
}
int count = SkMin32(max, fCount - index);
int count = std::min(max, fCount - index);
memcpy(dst, fArray + index, sizeof(T) * count);
return count;
}
Expand Down
2 changes: 1 addition & 1 deletion samplecode/SampleChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ChartView : public Sample {
SkScalar height = SkIntToScalar(fSize.fHeight);

if (sizeChanged) {
int dataPointCount = SkMax32(fSize.fWidth / kPixelsPerTick + 1, 2);
int dataPointCount = std::max(fSize.fWidth / kPixelsPerTick + 1, 2);

for (int i = 0; i < kNumGraphs; ++i) {
SkScalar y = (kNumGraphs - i) * (height - ySpread) / (kNumGraphs + 1);
Expand Down
18 changes: 9 additions & 9 deletions src/core/SkAAClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct SkAAClip::RunHead {
int segments = 0;
while (width > 0) {
segments += 1;
int n = SkMin32(width, 255);
int n = std::min(width, 255);
width -= n;
}
return segments * 2; // each segment is row[0] + row[1] (n + alpha)
Expand All @@ -106,7 +106,7 @@ struct SkAAClip::RunHead {
yoff->fOffset = 0;
uint8_t* row = head->data();
while (width > 0) {
int n = SkMin32(width, 255);
int n = std::min(width, 255);
row[0] = n;
row[1] = 0xFF;
width -= n;
Expand Down Expand Up @@ -722,8 +722,8 @@ bool SkAAClip::setRegion(const SkRegion& rgn) {
SkTDArray<YOffset> yArray;
SkTDArray<uint8_t> xArray;

yArray.setReserve(SkMin32(bounds.height(), 1024));
xArray.setReserve(SkMin32(bounds.width(), 512) * 128);
yArray.setReserve(std::min(bounds.height(), 1024));
xArray.setReserve(std::min(bounds.width(), 512) * 128);

SkRegion::Iterator iter(rgn);
int prevRight = 0;
Expand Down Expand Up @@ -1496,7 +1496,7 @@ static void operatorX(SkAAClip::Builder& builder, int lastY,
}
} else {
left = leftA; // or leftB, since leftA == leftB
rite = leftA = leftB = SkMin32(riteA, riteB);
rite = leftA = leftB = std::min(riteA, riteB);
alphaA = iterA.alpha();
alphaB = iterB.alpha();
}
Expand Down Expand Up @@ -1571,7 +1571,7 @@ static void operateY(SkAAClip::Builder& builder, const SkAAClip& A,
}
} else {
top = topA; // or topB, since topA == topB
bot = topA = topB = SkMin32(botA, botB);
bot = topA = topB = std::min(botA, botB);
rowA = iterA.data();
rowB = iterB.data();
}
Expand Down Expand Up @@ -1894,7 +1894,7 @@ static void merge(const uint8_t* SK_RESTRICT row, int rowN,
SkASSERT(srcN > 0);

unsigned newAlpha = SkMulDiv255Round(srcAA[0], row[1]);
int minN = SkMin32(srcN, rowN);
int minN = std::min(srcN, rowN);
dstRuns[0] = minN;
dstRuns += minN;
dstAA[0] = newAlpha;
Expand Down Expand Up @@ -2005,7 +2005,7 @@ void mergeT(const void* inSrc, int srcN, const uint8_t* SK_RESTRICT row, int row
SkASSERT(rowN > 0);
SkASSERT(srcN > 0);

int n = SkMin32(rowN, srcN);
int n = std::min(rowN, srcN);
unsigned rowA = row[1];
if (0xFF == rowA) {
small_memcpy(dst, src, n * sizeof(T));
Expand Down Expand Up @@ -2142,7 +2142,7 @@ void SkAAClipBlitter::blitMask(const SkMask& origMask, const SkIRect& clip) {
int localStopY SK_INIT_TO_AVOID_WARNING;
const uint8_t* row = fAAClip->findRow(y, &localStopY);
// findRow returns last Y, not stop, so we add 1
localStopY = SkMin32(localStopY + 1, stopY);
localStopY = std::min(localStopY + 1, stopY);

int initialCount;
row = fAAClip->findX(row, clip.fLeft, &initialCount);
Expand Down
6 changes: 3 additions & 3 deletions src/core/SkBitmapProcState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static void Clamp_S32_D32_nofilter_trans_shaderproc(const void* sIn,

// clamp to the left
if (ix < 0) {
int n = SkMin32(-ix, count);
int n = std::min(-ix, count);
sk_memset32(colors, row[0], n);
count -= n;
if (0 == count) {
Expand All @@ -328,7 +328,7 @@ static void Clamp_S32_D32_nofilter_trans_shaderproc(const void* sIn,
}
// copy the middle
if (ix <= maxX) {
int n = SkMin32(maxX - ix + 1, count);
int n = std::min(maxX - ix + 1, count);
memcpy(colors, row + ix, n * sizeof(SkPMColor));
count -= n;
if (0 == count) {
Expand Down Expand Up @@ -378,7 +378,7 @@ static void Repeat_S32_D32_nofilter_trans_shaderproc(const void* sIn,

ix = sk_int_mod(ix, stopX);
for (;;) {
int n = SkMin32(stopX - ix, count);
int n = std::min(stopX - ix, count);
memcpy(colors, row + ix, n * sizeof(SkPMColor));
count -= n;
if (0 == count) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/SkColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ static inline SkScalar ByteDivToScalar(int numer, U8CPU denom) {
void SkRGBToHSV(U8CPU r, U8CPU g, U8CPU b, SkScalar hsv[3]) {
SkASSERT(hsv);

unsigned min = SkMin32(r, SkMin32(g, b));
unsigned max = SkMax32(r, SkMax32(g, b));
unsigned min = std::min(r, std::min(g, b));
unsigned max = std::max(r, std::max(g, b));
unsigned delta = max - min;

SkScalar v = ByteToScalar(max);
Expand Down
4 changes: 2 additions & 2 deletions src/core/SkDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,8 @@ bool SkDraw::ComputeMaskBounds(const SkRect& devPathBounds, const SkIRect* clipB
// quality of large filters like blurs, and the corresponding memory
// requests.
static const int MAX_MARGIN = 128;
if (!bounds->intersect(clipBounds->makeOutset(SkMin32(margin.fX, MAX_MARGIN),
SkMin32(margin.fY, MAX_MARGIN)))) {
if (!bounds->intersect(clipBounds->makeOutset(std::min(margin.fX, MAX_MARGIN),
std::min(margin.fY, MAX_MARGIN)))) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/SkEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static SkFDot6 cubic_delta_from_line(SkFDot6 a, SkFDot6 b, SkFDot6 c, SkFDot6 d)
SkFDot6 oneThird = (a*8 - b*15 + 6*c + d) * 19 >> 9;
SkFDot6 twoThird = (a + 6*b - c*15 + d*8) * 19 >> 9;

return SkMax32(SkAbs32(oneThird), SkAbs32(twoThird));
return std::max(SkAbs32(oneThird), SkAbs32(twoThird));
}

bool SkCubicEdge::setCubicWithoutUpdate(const SkPoint pts[4], int shift, bool sortY) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/SkMaskFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void draw_nine_clipped(const SkMask& mask, const SkIRect& outerR,
// top
r.setLTRB(innerR.left(), outerR.top(), innerR.right(), innerR.top());
if (r.intersect(clipR)) {
int startY = SkMax32(0, r.top() - outerR.top());
int startY = std::max(0, r.top() - outerR.top());
int stopY = startY + r.height();
int width = r.width();
for (int y = startY; y < stopY; ++y) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/SkPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ int SkPath::getPoints(SkPoint dst[], int max) const {

SkASSERT(max >= 0);
SkASSERT(!max || dst);
int count = SkMin32(max, fPathRef->countPoints());
int count = std::min(max, fPathRef->countPoints());
sk_careful_memcpy(dst, fPathRef->points(), count * sizeof(SkPoint));
return fPathRef->countPoints();
}
Expand All @@ -500,7 +500,7 @@ int SkPath::getVerbs(uint8_t dst[], int max) const {

SkASSERT(max >= 0);
SkASSERT(!max || dst);
int count = SkMin32(max, fPathRef->countVerbs());
int count = std::min(max, fPathRef->countVerbs());
if (count) {
memcpy(dst, fPathRef->verbsBegin(), count);
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/SkRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

bool SkIRect::intersect(const SkIRect& a, const SkIRect& b) {
SkIRect tmp = {
SkMax32(a.fLeft, b.fLeft),
SkMax32(a.fTop, b.fTop),
SkMin32(a.fRight, b.fRight),
SkMin32(a.fBottom, b.fBottom)
std::max(a.fLeft, b.fLeft),
std::max(a.fTop, b.fTop),
std::min(a.fRight, b.fRight),
std::min(a.fBottom, b.fBottom)
};
if (tmp.isEmpty()) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/core/SkRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ static int operate(const SkRegionPriv::RunType a_runs[],
assert_sentinel(b_top, false);
assert_sentinel(b_bot, false);

RgnOper oper(SkMin32(a_top, b_top), dst, op);
RgnOper oper(std::min(a_top, b_top), dst, op);

int prevBot = SkRegion_kRunTypeSentinel; // so we fail the first test

Expand Down Expand Up @@ -1527,10 +1527,10 @@ bool SkRegion::Spanerator::next(int* left, int* right) {
SkASSERT(runs[1] > fLeft);

if (left) {
*left = SkMax32(fLeft, runs[0]);
*left = std::max(fLeft, runs[0]);
}
if (right) {
*right = SkMin32(fRight, runs[1]);
*right = std::min(fRight, runs[1]);
}
fRuns = runs + 2;
return true;
Expand Down
8 changes: 4 additions & 4 deletions src/core/SkRegion_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,16 @@ bool SkRegion::setPath(const SkPath& path, const SkRegion& clip) {
int clipTop, clipBot;
int clipTransitions = clip.count_runtype_values(&clipTop, &clipBot);

int top = SkMax32(pathTop, clipTop);
int bot = SkMin32(pathBot, clipBot);
int top = std::max(pathTop, clipTop);
int bot = std::min(pathBot, clipBot);
if (top >= bot) {
return check_inverse_on_empty_return(this, path, clip);
}

SkRgnBuilder builder;

if (!builder.init(bot - top,
SkMax32(pathTransitions, clipTransitions),
std::max(pathTransitions, clipTransitions),
path.isInverseFillType())) {
// can't allocate working space, so return false
return this->setEmpty();
Expand Down Expand Up @@ -413,7 +413,7 @@ struct Edge {
}

int top() const {
return SkMin32(fY0, fY1);
return std::min(fY0, fY1);
}
};

Expand Down
Loading

0 comments on commit 7f36405

Please sign in to comment.