aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/multipicturedraw.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2016-09-01 11:24:54 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-01 11:24:54 -0700
commitdbfd7ab10883f173f5c1b653a233e18dc6142002 (patch)
treea69ab168400f1d270d6047e1d8edf956cb6e5442 /gm/multipicturedraw.cpp
parent0b629ec73210161a6ba869a44a3c4ffd5a27dab9 (diff)
Replace a lot of 'static const' with 'constexpr' or 'const'.
'static const' means, there must be at most one of these, and initialize it at compile time if possible or runtime if necessary. This leads to unexpected code execution, and TSAN* will complain about races on the guard variables. Generally 'constexpr' or 'const' are better choices. Neither can cause races: they're either intialized at compile time (constexpr) or intialized each time independently (const). This CL prefers constexpr where possible, and uses const where not. It even prefers constexpr over const where they don't make a difference... I want to have lots of examples of constexpr for people to see and mimic. The scoped-to-class static has nothing to do with any of this, and is not changed. * Not yet on the bots, which use an older TSAN. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2300623005 Review-Url: https://codereview.chromium.org/2300623005
Diffstat (limited to 'gm/multipicturedraw.cpp')
-rw-r--r--gm/multipicturedraw.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/gm/multipicturedraw.cpp b/gm/multipicturedraw.cpp
index 83b0d5b86a..d7d81f283f 100644
--- a/gm/multipicturedraw.cpp
+++ b/gm/multipicturedraw.cpp
@@ -12,18 +12,18 @@
#include "SkPictureRecorder.h"
#include "SkSurface.h"
-static const SkScalar kRoot3Over2 = 0.86602545f; // sin(60)
-static const SkScalar kRoot3 = 1.73205081f;
+constexpr SkScalar kRoot3Over2 = 0.86602545f; // sin(60)
+constexpr SkScalar kRoot3 = 1.73205081f;
-static const int kHexSide = 30;
-static const int kNumHexX = 6;
-static const int kNumHexY = 6;
-static const int kPicWidth = kNumHexX * kHexSide;
-static const int kPicHeight = SkScalarCeilToInt((kNumHexY - 0.5f) * 2 * kHexSide * kRoot3Over2);
-static const SkScalar kInset = 20.0f;
-static const int kNumPictures = 4;
+constexpr int kHexSide = 30;
+constexpr int kNumHexX = 6;
+constexpr int kNumHexY = 6;
+constexpr int kPicWidth = kNumHexX * kHexSide;
+constexpr int kPicHeight = (int)((kNumHexY - 0.5f) * 2 * kHexSide * kRoot3Over2 + 0.5f);
+constexpr SkScalar kInset = 20.0f;
+constexpr int kNumPictures = 4;
-static const int kTriSide = 40;
+constexpr int kTriSide = 40;
// Create a hexagon centered at (originX, originY)
static SkPath make_hex_path(SkScalar originX, SkScalar originY) {
@@ -106,7 +106,7 @@ static sk_sp<SkPicture> make_single_layer_hex_plane_picture() {
SkPictureRecorder recorder;
SkRTreeFactory bbhFactory;
- static const SkScalar kBig = 10000.0f;
+ constexpr SkScalar kBig = 10000.0f;
SkCanvas* canvas = recorder.beginRecording(kBig, kBig, &bbhFactory);
canvas->saveLayer(nullptr, nullptr);
@@ -218,7 +218,7 @@ static sk_sp<SkPicture> make_sierpinski_picture() {
SkIntToScalar(kPicHeight),
&bbhFactory);
- static const int kNumLevels = 4;
+ constexpr int kNumLevels = 4;
for (int i = 0; i < kNumLevels; ++i) {
canvas->save();
canvas->translate(kPicWidth/2 - (i+1) * (kTriSide/2.0f), 0.0f);
@@ -336,7 +336,7 @@ static void big_layer(SkCanvas* canvas, const SkPicture* pictures[kNumPictures])
canvas->drawPicture(pictures[3]);
}
-static const PFContentMtd gContentMthds[] = {
+constexpr PFContentMtd gContentMthds[] = {
no_clip,
rect_clip,
rrect_clip,
@@ -391,15 +391,15 @@ static void tiled(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
PFContentMtd pfGen,
const SkPicture* pictures[kNumPictures],
SkTArray<ComposeStep> *composeSteps) {
- static const int kNumTilesX = 2;
- static const int kNumTilesY = 2;
- static const int kTileWidth = kPicWidth / kNumTilesX;
- static const int kTileHeight = kPicHeight / kNumTilesY;
+ const int kNumTilesX = 2;
+ const int kNumTilesY = 2;
+ const int kTileWidth = kPicWidth / kNumTilesX;
+ const int kTileHeight = kPicHeight / kNumTilesY;
SkASSERT(kPicWidth == kNumTilesX * kTileWidth);
SkASSERT(kPicHeight == kNumTilesY * kTileHeight);
- static const SkColor colors[kNumTilesX][kNumTilesY] = {
+ const SkColor colors[kNumTilesX][kNumTilesY] = {
{ SK_ColorCYAN, SK_ColorMAGENTA },
{ SK_ColorYELLOW, SK_ColorGREEN }
};
@@ -426,7 +426,7 @@ static void tiled(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
}
}
-static const PFLayoutMtd gLayoutMthds[] = { simple, tiled };
+constexpr PFLayoutMtd gLayoutMthds[] = { simple, tiled };
namespace skiagm {
/**
@@ -450,7 +450,7 @@ namespace skiagm {
kLast_Content = kBigLayer_Content
};
- static const int kContentCnt = kLast_Content + 1;
+ const int kContentCnt = kLast_Content + 1;
enum Layout {
kSimple_Layout,
@@ -459,7 +459,7 @@ namespace skiagm {
kLast_Layout = kTiled_Layout
};
- static const int kLayoutCnt = kLast_Layout + 1;
+ const int kLayoutCnt = kLast_Layout + 1;
MultiPictureDraw(Content content, Layout layout) : fContent(content), fLayout(layout) {
SkASSERT(SK_ARRAY_COUNT(gLayoutMthds) == kLayoutCnt);
@@ -511,11 +511,11 @@ namespace skiagm {
SkISize onISize() override { return SkISize::Make(kPicWidth, kPicHeight); }
SkString onShortName() override {
- static const char* gContentNames[] = {
+ const char* gContentNames[] = {
"noclip", "rectclip", "rrectclip", "pathclip",
"invpathclip", "sierpinski", "biglayer"
};
- static const char* gLayoutNames[] = { "simple", "tiled" };
+ const char* gLayoutNames[] = { "simple", "tiled" };
SkASSERT(SK_ARRAY_COUNT(gLayoutNames) == kLayoutCnt);
SkASSERT(SK_ARRAY_COUNT(gContentNames) == kContentCnt);