Previosly, SkSize had a base class, which prevented it.
Also removes unused SkISize::clampNegToZero() and
SkSize::clampNegToZero().
Change-Id: I7b93b42f6f6381c66e294bbedee99ad53c6c3436
Reviewed-on: https://skia-review.googlesource.com/13187
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
const SkRect ConservativelyContainsBench::kBounds = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
-const SkSize ConservativelyContainsBench::kQueryMin = SkSize::Make(SkIntToScalar(1), SkIntToScalar(1));
-const SkSize ConservativelyContainsBench::kQueryMax = SkSize::Make(SkIntToScalar(40), SkIntToScalar(40));
+const SkSize ConservativelyContainsBench::kQueryMin = {SkIntToScalar(1), SkIntToScalar(1)};
+const SkSize ConservativelyContainsBench::kQueryMax = {SkIntToScalar(40), SkIntToScalar(40)};
const SkRect ConservativelyContainsBench::kBaseRect = SkRect::MakeXYWH(SkIntToScalar(25), SkIntToScalar(25), SkIntToScalar(50), SkIntToScalar(50));
const SkScalar ConservativelyContainsBench::kRRRadii[2] = {SkIntToScalar(5), SkIntToScalar(10)};
SkISize BRDSrc::size() const {
std::unique_ptr<SkBitmapRegionDecoder> brd(create_brd(fPath));
if (brd) {
- return SkISize::Make(SkTMax(1, brd->width() / (int) fSampleSize),
- SkTMax(1, brd->height() / (int) fSampleSize));
+ return {SkTMax(1, brd->width() / (int)fSampleSize),
+ SkTMax(1, brd->height() / (int)fSampleSize)};
}
- return SkISize::Make(0, 0);
+ return {0, 0};
}
static SkString get_scaled_name(const Path& path, float scale) {
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
if (nullptr == codec) {
- return SkISize::Make(0, 0);
+ return {0, 0};
}
auto imageSize = codec->getScaledDimensions(fScale);
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
if (nullptr == codec) {
- return SkISize::Make(0, 0);
+ return {0, 0};
}
return codec->getSampledDimensions(fSampleSize);
}
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
if (nullptr == codec) {
- return SkISize::Make(0, 0);
+ return {0, 0};
}
return codec->getInfo().dimensions();
}
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
if (nullptr == codec) {
- return SkISize::Make(0, 0);
+ return {0, 0};
}
- return SkISize::Make(codec->getInfo().width(), codec->getInfo().height());
+ return {codec->getInfo().width(), codec->getInfo().height()};
}
Name ColorCodecSrc::name() const {
SkISize SKPSrc::size() const {
std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(fPath.c_str());
if (!stream) {
- return SkISize::Make(0,0);
+ return {0, 0};
}
SkPictInfo info;
if (!SkPicture::InternalOnly_StreamIsSKP(stream.get(), &info)) {
- return SkISize::Make(0,0);
+ return {0, 0};
}
SkRect viewport = kSKPViewport;
if (!viewport.intersect(info.fCullRect)) {
- return SkISize::Make(0,0);
+ return {0, 0};
}
return viewport.roundOut().size();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#if defined(SK_XML)
// Used when the image doesn't have an intrinsic size.
-static const SkSize kDefaultSVGSize = SkSize::Make(1000, 1000);
+static const SkSize kDefaultSVGSize = {1000, 1000};
// Used to force-scale tiny fixed-size images.
-static const SkSize kMinimumSVGSize = SkSize::Make(128, 128);
+static const SkSize kMinimumSVGSize = {128, 128};
SVGSrc::SVGSrc(Path path)
: fName(SkOSPath::Basename(path.c_str()))
SkISize SVGSrc::size() const {
if (!fDom) {
- return SkISize::Make(0, 0);
+ return {0, 0};
}
- return SkSize::Make(fDom->containerSize().width() * fScale,
- fDom->containerSize().height() * fScale).toRound();
+ return SkSize{fDom->containerSize().width() * fScale, fDom->containerSize().height() * fScale}
+ .toRound();
}
Name SVGSrc::name() const { return fName; }
SkISize MSKPSrc::size() const { return this->size(0); }
SkISize MSKPSrc::size(int i) const {
- return i >= 0 && i < fPages.count() ? fPages[i].fSize.toCeil() : SkISize::Make(0, 0);
+ return i >= 0 && i < fPages.count() ? fPages[i].fSize.toCeil() : SkISize{0, 0};
}
Error MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); }
SkRect bounds = SkRect::MakeIWH(srcW, srcH);
matrix->mapRect(&bounds);
matrix->postTranslate(-bounds.x(), -bounds.y());
- return SkISize::Make(SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height()));
+ return {SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height())};
}
ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {}
padRight, padBottom);
image_to_bitmap(image.get(), &bitmap);
- const SkTSize<SkScalar> size[] = {
+ const SkSize size[] = {
{ 50, 50, }, // shrink in both axes
{ 50, 200, }, // shrink in X
{ 200, 50, }, // shrink in Y
// amount of bm that should not be stretched (unless we have to)
const SkScalar fixed = SkIntToScalar(fBitmap.width() - fCenter.width());
- const SkTSize<SkScalar> size[] = {
+ const SkSize size[] = {
{ fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes
{ fixed * 4 / 5, fixed * 4 }, // shrink in X
{ fixed * 4, fixed * 4 / 5 }, // shrink in Y
#include "SkScalar.h"
-template <typename T> struct SkTSize {
- T fWidth;
- T fHeight;
-
- static SkTSize Make(T w, T h) {
- SkTSize s;
- s.fWidth = w;
- s.fHeight = h;
- return s;
- }
+struct SkISize {
+ int32_t fWidth;
+ int32_t fHeight;
- static SkTSize MakeEmpty() {
- return {0, 0};
- }
+ static SkISize Make(int32_t w, int32_t h) { return {w, h}; }
- void set(T w, T h) {
- fWidth = w;
- fHeight = h;
- }
+ static SkISize MakeEmpty() { return {0, 0}; }
+
+ void set(int32_t w, int32_t h) { *this = SkISize{w, h}; }
/** Returns true iff fWidth == 0 && fHeight == 0
*/
- bool isZero() const {
- return 0 == fWidth && 0 == fHeight;
- }
+ bool isZero() const { return 0 == fWidth && 0 == fHeight; }
/** Returns true if either widht or height are <= 0 */
- bool isEmpty() const {
- return fWidth <= 0 || fHeight <= 0;
- }
+ bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
/** Set the width and height to 0 */
- void setEmpty() {
- fWidth = fHeight = 0;
- }
+ void setEmpty() { fWidth = fHeight = 0; }
- T width() const { return fWidth; }
- T height() const { return fHeight; }
-
- /** If width or height is < 0, it is set to 0 */
- void clampNegToZero() {
- if (fWidth < 0) {
- fWidth = 0;
- }
- if (fHeight < 0) {
- fHeight = 0;
- }
- }
+ int32_t width() const { return fWidth; }
+ int32_t height() const { return fHeight; }
- bool equals(T w, T h) const {
- return fWidth == w && fHeight == h;
- }
+ bool equals(int32_t w, int32_t h) const { return fWidth == w && fHeight == h; }
};
-template <typename T>
-static inline bool operator==(const SkTSize<T>& a, const SkTSize<T>& b) {
+static inline bool operator==(const SkISize& a, const SkISize& b) {
return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
}
-template <typename T>
-static inline bool operator!=(const SkTSize<T>& a, const SkTSize<T>& b) {
- return !(a == b);
-}
+static inline bool operator!=(const SkISize& a, const SkISize& b) { return !(a == b); }
///////////////////////////////////////////////////////////////////////////////
-typedef SkTSize<int32_t> SkISize;
+struct SkSize {
+ SkScalar fWidth;
+ SkScalar fHeight;
-struct SkSize : public SkTSize<SkScalar> {
- static SkSize Make(SkScalar w, SkScalar h) {
- SkSize s;
- s.fWidth = w;
- s.fHeight = h;
- return s;
- }
+ static SkSize Make(SkScalar w, SkScalar h) { return {w, h}; }
static SkSize Make(const SkISize& src) {
- return Make(SkIntToScalar(src.width()), SkIntToScalar(src.height()));
+ return {SkIntToScalar(src.width()), SkIntToScalar(src.height())};
}
SkSize& operator=(const SkISize& src) {
- this->set(SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight));
- return *this;
+ return *this = SkSize{SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight)};
}
- SkISize toRound() const {
- SkISize s;
- s.set(SkScalarRoundToInt(fWidth), SkScalarRoundToInt(fHeight));
- return s;
- }
+ static SkSize MakeEmpty() { return {0, 0}; }
- SkISize toCeil() const {
- SkISize s;
- s.set(SkScalarCeilToInt(fWidth), SkScalarCeilToInt(fHeight));
- return s;
- }
+ void set(SkScalar w, SkScalar h) { *this = SkSize{w, h}; }
- SkISize toFloor() const {
- SkISize s;
- s.set(SkScalarFloorToInt(fWidth), SkScalarFloorToInt(fHeight));
- return s;
- }
+ /** Returns true iff fWidth == 0 && fHeight == 0
+ */
+ bool isZero() const { return 0 == fWidth && 0 == fHeight; }
+
+ /** Returns true if either widht or height are <= 0 */
+ bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
+
+ /** Set the width and height to 0 */
+ void setEmpty() { *this = SkSize{0, 0}; }
+
+ SkScalar width() const { return fWidth; }
+ SkScalar height() const { return fHeight; }
+
+ bool equals(SkScalar w, SkScalar h) const { return fWidth == w && fHeight == h; }
+
+ SkISize toRound() const { return {SkScalarRoundToInt(fWidth), SkScalarRoundToInt(fHeight)}; }
+
+ SkISize toCeil() const { return {SkScalarCeilToInt(fWidth), SkScalarCeilToInt(fHeight)}; }
+
+ SkISize toFloor() const { return {SkScalarFloorToInt(fWidth), SkScalarFloorToInt(fHeight)}; }
};
+static inline bool operator==(const SkSize& a, const SkSize& b) {
+ return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
+}
+
+static inline bool operator!=(const SkSize& a, const SkSize& b) { return !(a == b); }
#endif
SkISize SkAndroidCodec::getSampledDimensions(int sampleSize) const {
if (!is_valid_sample_size(sampleSize)) {
- return SkISize::Make(0, 0);
+ return {0, 0};
}
// Fast path for when we are not scaling.
SkISize SkAndroidCodec::getSampledSubsetDimensions(int sampleSize, const SkIRect& subset) const {
if (!is_valid_sample_size(sampleSize)) {
- return SkISize::Make(0, 0);
+ return {0, 0};
}
// We require that the input subset is a subset that is supported by SkAndroidCodec.
// are made to the subset.
SkIRect copySubset = subset;
if (!this->getSupportedSubset(©Subset) || copySubset != subset) {
- return SkISize::Make(0, 0);
+ return {0, 0};
}
// If the subset is the entire image, for consistency, use getSampledDimensions().
// This should perhaps call a virtual function, but currently both of our subclasses
// want the same implementation.
- return SkISize::Make(get_scaled_dimension(subset.width(), sampleSize),
- get_scaled_dimension(subset.height(), sampleSize));
+ return {get_scaled_dimension(subset.width(), sampleSize),
+ get_scaled_dimension(subset.height(), sampleSize)};
}
SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void* pixels,
return sigma;
}
-SkBlurImageFilterImpl::SkBlurImageFilterImpl(SkScalar sigmaX,
- SkScalar sigmaY,
- sk_sp<SkImageFilter> input,
- const CropRect* cropRect)
- : INHERITED(&input, 1, cropRect)
- , fSigma(SkSize::Make(sigmaX, sigmaY)) {
-}
+SkBlurImageFilterImpl::SkBlurImageFilterImpl(
+ SkScalar sigmaX, SkScalar sigmaY, sk_sp<SkImageFilter> input, const CropRect* cropRect)
+ : INHERITED(&input, 1, cropRect), fSigma{sigmaX, sigmaY} {}
sk_sp<SkFlattenable> SkBlurImageFilterImpl::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
SkASSERT(1 == count || 2 == count);
SkIRect ir;
rects[0].roundOut(&ir);
- fSizes[0] = SkSize::Make(rects[0].width(), rects[0].height());
+ fSizes[0] = SkSize{rects[0].width(), rects[0].height()};
if (2 == count) {
- fSizes[1] = SkSize::Make(rects[1].width(), rects[1].height());
- fSizes[2] = SkSize::Make(rects[0].x() - rects[1].x(), rects[0].y() - rects[1].y());
+ fSizes[1] = SkSize{rects[1].width(), rects[1].height()};
+ fSizes[2] = SkSize{rects[0].x() - rects[1].x(), rects[0].y() - rects[1].y()};
} else {
- fSizes[1] = SkSize::Make(0, 0);
- fSizes[2] = SkSize::Make(0, 0);
+ fSizes[1] = SkSize{0, 0};
+ fSizes[2] = SkSize{0, 0};
}
- fSizes[3] = SkSize::Make(rects[0].x() - ir.x(), rects[0].y() - ir.y());
+ fSizes[3] = SkSize{rects[0].x() - ir.x(), rects[0].y() - ir.y()};
this->init(&gRectsBlurKeyNamespaceLabel, 0,
sizeof(fSigma) + sizeof(fStyle) + sizeof(fQuality) + sizeof(fSizes));
return resourceIndex;
}
-static SkSize rect_to_size(const SkRect& r) {
- return SkSize::Make(r.width(), r.height());
-}
+static SkSize rect_to_size(const SkRect& r) { return {r.width(), r.height()}; }
static sk_sp<SkImage> color_filter(const SkImageSubset& imageSubset,
SkColorFilter* colorFilter) {
rasterScale *= SkScalarSqrt(kMaxBitmapArea / bitmapArea);
}
- SkISize size = SkISize::Make(SkScalarRoundToInt(rasterScale * bbox.width()),
- SkScalarRoundToInt(rasterScale * bbox.height()));
- SkSize scale = SkSize::Make(SkIntToScalar(size.width()) / shaderRect.width(),
- SkIntToScalar(size.height()) / shaderRect.height());
+ SkISize size = {SkScalarRoundToInt(rasterScale * bbox.width()),
+ SkScalarRoundToInt(rasterScale * bbox.height())};
+ SkSize scale = {SkIntToScalar(size.width()) / shaderRect.width(),
+ SkIntToScalar(size.height()) / shaderRect.height()};
imageDst->allocN32Pixels(size.width(), size.height());
imageDst->eraseColor(SK_ColorTRANSPARENT);
const uint32_t kVersion = 2;
static SkSize join(const SkTArray<SkSize>& sizes) {
- SkSize joined = SkSize::Make(0, 0);
+ SkSize joined = {0, 0};
for (SkSize s : sizes) {
- joined = SkSize::Make(SkTMax(joined.width(), s.width()),
- SkTMax(joined.height(), s.height()));
+ joined = SkSize{SkTMax(joined.width(), s.width()), SkTMax(joined.height(), s.height())};
}
return joined;
}
if (!SkMultiPictureDocumentReadPageSizes(stream, dstArray, dstArrayCount)) {
return false;
}
- SkSize joined = SkSize::Make(0.0f, 0.0f);
+ SkSize joined = {0.0f, 0.0f};
for (int i = 0; i < dstArrayCount; ++i) {
- joined = SkSize::Make(SkTMax(joined.width(), dstArray[i].fSize.width()),
- SkTMax(joined.height(), dstArray[i].fSize.height()));
+ joined = SkSize{SkTMax(joined.width(), dstArray[i].fSize.width()),
+ SkTMax(joined.height(), dstArray[i].fSize.height())};
}
auto picture = SkPicture::MakeFromStream(stream);
// of the point light and the shapes, etc... If we take upper bounds
// on those metrics, the shadow map will be pretty big in any case.
// Thus, just using 4x the width and height seems to work for most scenes.
- return SkISize::Make(width * 4, height * 4);
+ return {width * 4, height * 4};
}
int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width,
SkCanvas* SkXPSDocument::onBeginPage(SkScalar width,
SkScalar height,
const SkRect& trimBox) {
- fDevice.beginSheet(fUnitsPerMeter, fPixelsPerMeter,
- SkSize::Make(width, height));
+ fDevice.beginSheet(fUnitsPerMeter, fPixelsPerMeter, {width, height});
fCanvas.reset(new SkCanvas(&fDevice));
fCanvas->clipRect(trimBox);
fCanvas->translate(trimBox.x(), trimBox.y());
test_path_crbugskia6003();
test_fuzz_crbug_668907();
- SkTSize<SkScalar>::Make(3,4);
+ SkSize::Make(3, 4);
SkPath p, empty;
SkRect bounds, bounds2;
REPORTER_ASSERT(reporter, a.isEmpty());
a.set(5, -5);
REPORTER_ASSERT(reporter, a.isEmpty());
- a.clampNegToZero();
+ a = SkISize{5, 0};
REPORTER_ASSERT(reporter, a.isEmpty());
b.set(5, 0);
REPORTER_ASSERT(reporter, a == b);
REPORTER_ASSERT(reporter, a.isEmpty());
a.set(x, -x);
REPORTER_ASSERT(reporter, a.isEmpty());
- a.clampNegToZero();
+ a = SkSize{x, 0};
REPORTER_ASSERT(reporter, a.isEmpty());
b.set(x, 0);
REPORTER_ASSERT(reporter, a == b);