Remove static initializers in SkCodec
Bug: 768878
Switch const declarations to constexpr where appropriate. Speculative
fix for crbug.com/768878.
Change-Id: I7fc356e623ce7a0f2b87e92e9a8ed95d5c423d79
Reviewed-on: https://skia-review.googlesource.com/54101
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Chris Blume <cblume@chromium.org>
diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp
index c245f1d..cd23680 100644
--- a/src/codec/SkAndroidCodec.cpp
+++ b/src/codec/SkAndroidCodec.cpp
@@ -42,7 +42,7 @@
return 0.5f * SkTAbs(a.fX*b.fY + b.fX*c.fY - a.fX*c.fY - c.fX*b.fY - b.fX*a.fY);
}
-static const float kSRGB_D50_GamutArea = 0.084f;
+static constexpr float kSRGB_D50_GamutArea = 0.084f;
static bool is_wide_gamut(const SkColorSpace* colorSpace) {
// Determine if the source image has a gamut that is wider than sRGB. If so, we
diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp
index 60785ba..d97dff0 100644
--- a/src/codec/SkBmpCodec.cpp
+++ b/src/codec/SkBmpCodec.cpp
@@ -81,17 +81,17 @@
}
// Header size constants
-static const uint32_t kBmpHeaderBytes = 14;
-static const uint32_t kBmpHeaderBytesPlusFour = kBmpHeaderBytes + 4;
-static const uint32_t kBmpOS2V1Bytes = 12;
-static const uint32_t kBmpOS2V2Bytes = 64;
-static const uint32_t kBmpInfoBaseBytes = 16;
-static const uint32_t kBmpInfoV1Bytes = 40;
-static const uint32_t kBmpInfoV2Bytes = 52;
-static const uint32_t kBmpInfoV3Bytes = 56;
-static const uint32_t kBmpInfoV4Bytes = 108;
-static const uint32_t kBmpInfoV5Bytes = 124;
-static const uint32_t kBmpMaskBytes = 12;
+static constexpr uint32_t kBmpHeaderBytes = 14;
+static constexpr uint32_t kBmpHeaderBytesPlusFour = kBmpHeaderBytes + 4;
+static constexpr uint32_t kBmpOS2V1Bytes = 12;
+static constexpr uint32_t kBmpOS2V2Bytes = 64;
+static constexpr uint32_t kBmpInfoBaseBytes = 16;
+static constexpr uint32_t kBmpInfoV1Bytes = 40;
+static constexpr uint32_t kBmpInfoV2Bytes = 52;
+static constexpr uint32_t kBmpInfoV3Bytes = 56;
+static constexpr uint32_t kBmpInfoV4Bytes = 108;
+static constexpr uint32_t kBmpInfoV5Bytes = 124;
+static constexpr uint32_t kBmpMaskBytes = 12;
static BmpHeaderType get_header_type(size_t infoBytes) {
if (infoBytes >= kBmpInfoBaseBytes) {
diff --git a/src/codec/SkBmpCodec.h b/src/codec/SkBmpCodec.h
index 651f1be..3196ae1 100644
--- a/src/codec/SkBmpCodec.h
+++ b/src/codec/SkBmpCodec.h
@@ -102,8 +102,8 @@
* BMPs are typically encoded as BGRA/BGR so this is a more efficient choice
* than RGBA.
*/
- static const SkColorType kXformSrcColorType = kBGRA_8888_SkColorType;
- static const auto kXformSrcColorFormat = SkColorSpaceXform::kBGRA_8888_ColorFormat;
+ static constexpr SkColorType kXformSrcColorType = kBGRA_8888_SkColorType;
+ static constexpr auto kXformSrcColorFormat = SkColorSpaceXform::kBGRA_8888_ColorFormat;
private:
diff --git a/src/codec/SkBmpRLECodec.cpp b/src/codec/SkBmpRLECodec.cpp
index bd4624e..18c0a79 100644
--- a/src/codec/SkBmpRLECodec.cpp
+++ b/src/codec/SkBmpRLECodec.cpp
@@ -338,10 +338,10 @@
const int height = dstInfo.height();
// Set RLE flags
- static const uint8_t RLE_ESCAPE = 0;
- static const uint8_t RLE_EOL = 0;
- static const uint8_t RLE_EOF = 1;
- static const uint8_t RLE_DELTA = 2;
+ constexpr uint8_t RLE_ESCAPE = 0;
+ constexpr uint8_t RLE_EOL = 0;
+ constexpr uint8_t RLE_EOF = 1;
+ constexpr uint8_t RLE_DELTA = 2;
// Destination parameters
int x = 0;
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index 214b157..9b55790 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -32,7 +32,7 @@
std::unique_ptr<SkCodec> (*MakeFromStream)(std::unique_ptr<SkStream>, SkCodec::Result*);
};
-static const DecoderProc gDecoderProcs[] = {
+static constexpr DecoderProc gDecoderProcs[] = {
#ifdef SK_HAS_JPEG_LIBRARY
{ SkJpegCodec::IsJpeg, SkJpegCodec::MakeFromStream },
#endif
diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp
index 970cc98..17c8617 100644
--- a/src/codec/SkGifCodec.cpp
+++ b/src/codec/SkGifCodec.cpp
@@ -156,8 +156,8 @@
return fReader->loopCount();
}
-static const SkColorType kXformSrcColorType = kRGBA_8888_SkColorType;
-static const SkAlphaType kXformAlphaType = kUnpremul_SkAlphaType;
+static constexpr SkColorType kXformSrcColorType = kRGBA_8888_SkColorType;
+static constexpr SkAlphaType kXformAlphaType = kUnpremul_SkAlphaType;
void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, int frameIndex) {
SkColorType colorTableColorType = dstInfo.colorType();
diff --git a/src/codec/SkIcoCodec.cpp b/src/codec/SkIcoCodec.cpp
index 74affe6..fcd3189 100644
--- a/src/codec/SkIcoCodec.cpp
+++ b/src/codec/SkIcoCodec.cpp
@@ -29,8 +29,8 @@
std::unique_ptr<SkCodec> SkIcoCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
Result* result) {
// Header size constants
- static const uint32_t kIcoDirectoryBytes = 6;
- static const uint32_t kIcoDirEntryBytes = 16;
+ constexpr uint32_t kIcoDirectoryBytes = 6;
+ constexpr uint32_t kIcoDirEntryBytes = 16;
// Read the directory header
std::unique_ptr<uint8_t[]> dirBuffer(new uint8_t[kIcoDirectoryBytes]);
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index 33c316a..be5c9f7 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -30,7 +30,7 @@
}
bool SkJpegCodec::IsJpeg(const void* buffer, size_t bytesRead) {
- static const uint8_t jpegSig[] = { 0xFF, 0xD8, 0xFF };
+ constexpr uint8_t jpegSig[] = { 0xFF, 0xD8, 0xFF };
return bytesRead >= 3 && !memcmp(buffer, jpegSig, sizeof(jpegSig));
}
@@ -51,7 +51,7 @@
}
const uint8_t* data = marker->data;
- static const uint8_t kExifSig[] { 'E', 'x', 'i', 'f', '\0' };
+ constexpr uint8_t kExifSig[] { 'E', 'x', 'i', 'f', '\0' };
if (memcmp(data, kExifSig, sizeof(kExifSig))) {
return false;
}
diff --git a/src/codec/SkMasks.cpp b/src/codec/SkMasks.cpp
index ac97a39..79892ed 100644
--- a/src/codec/SkMasks.cpp
+++ b/src/codec/SkMasks.cpp
@@ -14,7 +14,7 @@
* Used to convert 1-7 bit color components into 8-bit color components
*
*/
-const static uint8_t n_bit_to_8_bit_lookup_table[] = {
+static constexpr uint8_t n_bit_to_8_bit_lookup_table[] = {
// 1 bit
0, 255,
// 2 bits
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 6799565..1c88b47 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -244,7 +244,7 @@
return true;
}
-static const SkColorType kXformSrcColorType = kRGBA_8888_SkColorType;
+static constexpr SkColorType kXformSrcColorType = kRGBA_8888_SkColorType;
// Note: SkColorTable claims to store SkPMColors, which is not necessarily the case here.
bool SkPngCodec::createColorTable(const SkImageInfo& dstInfo) {
diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp
index 8d865da..84bb097 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -154,14 +154,14 @@
static void swizzle_bit_to_f16(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
- static const uint64_t kWhite = (((uint64_t) SK_Half1) << 0) |
- (((uint64_t) SK_Half1) << 16) |
- (((uint64_t) SK_Half1) << 32) |
- (((uint64_t) SK_Half1) << 48);
- static const uint64_t kBlack = (((uint64_t) 0) << 0) |
- (((uint64_t) 0) << 16) |
- (((uint64_t) 0) << 32) |
- (((uint64_t) SK_Half1) << 48);
+ constexpr uint64_t kWhite = (((uint64_t) SK_Half1) << 0) |
+ (((uint64_t) SK_Half1) << 16) |
+ (((uint64_t) SK_Half1) << 32) |
+ (((uint64_t) SK_Half1) << 48);
+ constexpr uint64_t kBlack = (((uint64_t) 0) << 0) |
+ (((uint64_t) 0) << 16) |
+ (((uint64_t) 0) << 32) |
+ (((uint64_t) SK_Half1) << 48);
uint64_t* SK_RESTRICT dst = (uint64_t*) dstRow;