add constexpr to SkRect, SkIRect Make functions

Also, doing so exposed a couple of unused
variables in tests.

R: bsalomon@google.com
Bug: skia: 6898
Change-Id: I7b065e26a838fe55a1d772bcefaef5325e1baa61
Reviewed-on: https://skia-review.googlesource.com/55680
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Cary Clark <caryclark@skia.org>
This commit is contained in:
Cary Clark 2017-10-05 11:27:53 -04:00 committed by Skia Commit-Bot
parent 2a769859f0
commit 583dd2bbc0
3 changed files with 16 additions and 34 deletions

View File

@ -24,10 +24,8 @@ struct SK_API SkIRect {
int32_t fRight;
int32_t fBottom;
static SkIRect SK_WARN_UNUSED_RESULT MakeEmpty() {
SkIRect r;
r.setEmpty();
return r;
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty() {
return SkIRect{0, 0, 0, 0};
}
static SkIRect SK_WARN_UNUSED_RESULT MakeLargest() {
@ -36,28 +34,20 @@ struct SK_API SkIRect {
return r;
}
static SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h) {
SkIRect r;
r.set(0, 0, w, h);
return r;
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h) {
return SkIRect{0, 0, w, h};
}
static SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size) {
SkIRect r;
r.set(0, 0, size.width(), size.height());
return r;
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size) {
return SkIRect{0, 0, size.fWidth, size.fHeight};
}
static SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b) {
SkIRect rect;
rect.set(l, t, r, b);
return rect;
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b) {
return SkIRect{l, t, r, b};
}
static SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h) {
SkIRect r;
r.set(x, y, x + w, y + h);
return r;
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h) {
return SkIRect{x, y, x + w, y + h};
}
int left() const { return fLeft; }
@ -421,10 +411,8 @@ struct SK_API SkRect {
return r;
}
static SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h) {
SkRect r;
r.set(0, 0, w, h);
return r;
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h) {
return SkRect{0, 0, w, h};
}
static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h) {
@ -433,10 +421,8 @@ struct SK_API SkRect {
return r;
}
static SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size) {
SkRect r;
r.set(0, 0, size.width(), size.height());
return r;
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size) {
return SkRect{0, 0, size.fWidth, size.fHeight};
}
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
@ -444,10 +430,8 @@ struct SK_API SkRect {
return SkRect {l, t, r, b};
}
static SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h) {
SkRect r;
r.set(x, y, x + w, y + h);
return r;
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h) {
return SkRect {x, y, x + w, y + h};
}
SK_ATTR_DEPRECATED("use Make()")

View File

@ -23,7 +23,6 @@
#include "SkHalf.h"
static const int DEV_W = 100, DEV_H = 100;
static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
template <typename T>
void runFPTest(skiatest::Reporter* reporter, GrContext* context,

View File

@ -20,7 +20,6 @@
#include "GrTextureProxy.h"
static const int DEV_W = 10, DEV_H = 10;
static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
static const uint8_t TOL = 0x4;
static void check_component(skiatest::Reporter* reporter, uint8_t control, uint8_t test) {