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

View File

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

View File

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