Revert "Revert "resources: remove most uses of GetResourcePath()""
This reverts commit cca230055921d2df8708ed6f9abcc2d43468dc7f.
Reason for revert: think I guessed wrong about g32 -- unreverting
Original change's description:
> Revert "resources: remove most uses of GetResourcePath()"
>
> This reverts commit 5093a539def3ae09df324018f2343827009b2e05.
>
> Reason for revert: google3 seems broken
>
> Original change's description:
> > resources: remove most uses of GetResourcePath()
> >
> > Going forward, we will standardize on GetResourceAsData(), which will
> > make it easier to run tests in environments without access to the
> > filesystem.
> >
> > Also: GetResourceAsData() complains when a resource is missing.
> > This is usually an error.
> >
> > Change-Id: Iaf70b71b0ca5ed8cd1a5538a60ef185ae8736188
> > Reviewed-on: https://skia-review.googlesource.com/82642
> > Reviewed-by: Hal Canary <halcanary@google.com>
> > Commit-Queue: Hal Canary <halcanary@google.com>
>
> TBR=halcanary@google.com,scroggo@google.com
>
> Change-Id: Ic5a7c0167c995a672e6b06dc92abe00564432214
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/83001
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Mike Reed <reed@google.com>
TBR=halcanary@google.com,scroggo@google.com,reed@google.com
Change-Id: I5a46e4de61186a8a5eb9cacd3275e24e311d5a07
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/82942
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index ab21e4a..787e854 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -846,9 +846,8 @@
// Test that the RawCodec works also for not asset stream. This will test the code path using
// SkRawBufferedStream instead of SkRawAssetStream.
DEF_TEST(Codec_raw_notseekable, r) {
- const char* path = "images/dng_with_preview.dng";
- SkString fullPath(GetResourcePath(path));
- sk_sp<SkData> data(SkData::MakeFromFileName(fullPath.c_str()));
+ constexpr char path[] = "images/dng_with_preview.dng";
+ sk_sp<SkData> data(GetResourceAsData(path));
if (!data) {
SkDebugf("Missing resource '%s'\n", path);
return;
@@ -865,9 +864,8 @@
// Test that even if webp_parse_header fails to peek enough, it will fall back to read()
// + rewind() and succeed.
DEF_TEST(Codec_webp_peek, r) {
- const char* path = "images/baby_tux.webp";
- SkString fullPath(GetResourcePath(path));
- auto data = SkData::MakeFromFileName(fullPath.c_str());
+ constexpr char path[] = "images/baby_tux.webp";
+ auto data = GetResourceAsData(path);
if (!data) {
SkDebugf("Missing resource '%s'\n", path);
return;
@@ -1003,8 +1001,7 @@
const int dstWidth = subsetWidth / opts.fSampleSize;
const int dstHeight = subsetHeight / opts.fSampleSize;
- sk_sp<SkData> data = SkData::MakeFromFileName(
- GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
+ sk_sp<SkData> data = GetResourceAsData("icc_profiles/HP_ZR30w.icc");
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeICC(data->data(), data->size());
SkImageInfo dstInfo = codec->getInfo().makeWH(dstWidth, dstHeight)
.makeColorType(kN32_SkColorType)
@@ -1386,12 +1383,14 @@
}
static void test_invalid_header(skiatest::Reporter* r, const char* path) {
- SkString resourcePath = GetResourcePath(path);
- auto stream = SkFILEStream::Make(resourcePath.c_str());
+ auto data = GetResourceAsData(path);
+ if (!data) {
+ return;
+ }
+ std::unique_ptr<SkStreamAsset> stream(new SkMemoryStream(std::move(data)));
if (!stream) {
return;
}
-
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
REPORTER_ASSERT(r, !codec);
}
diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp
index 19e1044..d180cda 100644
--- a/tests/ColorSpaceTest.cpp
+++ b/tests/ColorSpaceTest.cpp
@@ -245,14 +245,13 @@
test_serialize(r, SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named).get(), true);
test_serialize(r, SkColorSpace::MakeSRGBLinear().get(), true);
- sk_sp<SkData> monitorData = SkData::MakeFromFileName(
- GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
+ sk_sp<SkData> monitorData = GetResourceAsData("icc_profiles/HP_ZR30w.icc");
test_serialize(r, SkColorSpace::MakeICC(monitorData->data(), monitorData->size()).get(), false);
- monitorData = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str());
+ monitorData = GetResourceAsData("icc_profiles/HP_Z32x.icc");
test_serialize(r, SkColorSpace::MakeICC(monitorData->data(), monitorData->size()).get(), false);
- monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str());
+ monitorData = GetResourceAsData("icc_profiles/upperLeft.icc");
test_serialize(r, SkColorSpace::MakeICC(monitorData->data(), monitorData->size()).get(), false);
- monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str());
+ monitorData = GetResourceAsData("icc_profiles/upperRight.icc");
test_serialize(r, SkColorSpace::MakeICC(monitorData->data(), monitorData->size()).get(), false);
SkColorSpaceTransferFn fn;
@@ -270,14 +269,13 @@
DEF_TEST(ColorSpace_Equals, r) {
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
sk_sp<SkColorSpace> adobe = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named);
- sk_sp<SkData> data = SkData::MakeFromFileName(
- GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
+ sk_sp<SkData> data = GetResourceAsData("icc_profiles/HP_ZR30w.icc");
sk_sp<SkColorSpace> z30 = SkColorSpace::MakeICC(data->data(), data->size());
- data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str());
+ data = GetResourceAsData("icc_profiles/HP_Z32x.icc");
sk_sp<SkColorSpace> z32 = SkColorSpace::MakeICC(data->data(), data->size());
- data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str());
+ data = GetResourceAsData("icc_profiles/upperLeft.icc");
sk_sp<SkColorSpace> upperLeft = SkColorSpace::MakeICC(data->data(), data->size());
- data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str());
+ data = GetResourceAsData("icc_profiles/upperRight.icc");
sk_sp<SkColorSpace> upperRight = SkColorSpace::MakeICC(data->data(), data->size());
SkColorSpaceTransferFn fn;
diff --git a/tests/GifTest.cpp b/tests/GifTest.cpp
index 5219825..0de5fc5 100644
--- a/tests/GifTest.cpp
+++ b/tests/GifTest.cpp
@@ -225,12 +225,12 @@
// Regression test for decoding a gif image with sampleSize of 4, which was
// previously crashing.
DEF_TEST(Gif_Sampled, r) {
- auto stream = SkFILEStream::Make(GetResourcePath("images/test640x479.gif").c_str());
- REPORTER_ASSERT(r, stream);
- if (!stream) {
+ auto data = GetResourceAsData("images/test640x479.gif");
+ REPORTER_ASSERT(r, data);
+ if (!data) {
return;
}
-
+ std::unique_ptr<SkStreamAsset> stream(new SkMemoryStream(std::move(data)));
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromStream(std::move(stream)));
REPORTER_ASSERT(r, codec);
if (!codec) {
diff --git a/tests/ICCTest.cpp b/tests/ICCTest.cpp
index 4bff654..4933155 100644
--- a/tests/ICCTest.cpp
+++ b/tests/ICCTest.cpp
@@ -39,8 +39,7 @@
0.74519f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
};
- sk_sp<SkData> data = SkData::MakeFromFileName(
- GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
+ sk_sp<SkData> data = GetResourceAsData("icc_profiles/HP_ZR30w.icc");
sk_sp<SkICC> z30 = SkICC::Make(data->data(), data->size());
test_to_xyz_d50(r, z30.get(), true, z30Reference);
@@ -49,15 +48,15 @@
0.75368f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
};
- data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str());
+ data = GetResourceAsData("icc_profiles/HP_Z32x.icc");
sk_sp<SkICC> z32 = SkICC::Make(data->data(), data->size());
test_to_xyz_d50(r, z32.get(), true, z32Reference);
- data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str());
+ data = GetResourceAsData("icc_profiles/upperLeft.icc");
sk_sp<SkICC> upperLeft = SkICC::Make(data->data(), data->size());
test_to_xyz_d50(r, upperLeft.get(), false, z32Reference);
- data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str());
+ data = GetResourceAsData("icc_profiles/upperRight.icc");
sk_sp<SkICC> upperRight = SkICC::Make(data->data(), data->size());
test_to_xyz_d50(r, upperRight.get(), false, z32Reference);
}
@@ -82,20 +81,19 @@
referenceFn.fF = 0.0f;
referenceFn.fG = 2.2f;
- sk_sp<SkData> data = SkData::MakeFromFileName(
- GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
+ sk_sp<SkData> data = GetResourceAsData("icc_profiles/HP_ZR30w.icc");
sk_sp<SkICC> z30 = SkICC::Make(data->data(), data->size());
test_is_numerical_transfer_fn(r, z30.get(), true, referenceFn);
- data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str());
+ data = GetResourceAsData("icc_profiles/HP_Z32x.icc");
sk_sp<SkICC> z32 = SkICC::Make(data->data(), data->size());
test_is_numerical_transfer_fn(r, z32.get(), true, referenceFn);
- data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str());
+ data = GetResourceAsData("icc_profiles/upperLeft.icc");
sk_sp<SkICC> upperLeft = SkICC::Make(data->data(), data->size());
test_is_numerical_transfer_fn(r, upperLeft.get(), false, referenceFn);
- data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str());
+ data = GetResourceAsData("icc_profiles/upperRight.icc");
sk_sp<SkICC> upperRight = SkICC::Make(data->data(), data->size());
test_is_numerical_transfer_fn(r, upperRight.get(), false, referenceFn);
}
diff --git a/tests/ImageIsOpaqueTest.cpp b/tests/ImageIsOpaqueTest.cpp
index 9b4837a..38f9b6a 100644
--- a/tests/ImageIsOpaqueTest.cpp
+++ b/tests/ImageIsOpaqueTest.cpp
@@ -40,14 +40,13 @@
}
DEF_TEST(ImageInfo_flattening, reporter) {
- sk_sp<SkData> data =
- SkData::MakeFromFileName(GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
+ sk_sp<SkData> data = GetResourceAsData("icc_profiles/HP_ZR30w.icc");
sk_sp<SkColorSpace> space0 = SkColorSpace::MakeICC(data->data(), data->size());
- data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str());
+ data = GetResourceAsData("icc_profiles/HP_Z32x.icc");
sk_sp<SkColorSpace> space1 = SkColorSpace::MakeICC(data->data(), data->size());
- data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str());
+ data = GetResourceAsData("icc_profiles/upperLeft.icc");
sk_sp<SkColorSpace> space2 = SkColorSpace::MakeICC(data->data(), data->size());
- data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str());
+ data = GetResourceAsData("icc_profiles/upperRight.icc");
sk_sp<SkColorSpace> space3 = SkColorSpace::MakeICC(data->data(), data->size());
sk_sp<SkColorSpace> spaces[] = {
diff --git a/tests/PDFJpegEmbedTest.cpp b/tests/PDFJpegEmbedTest.cpp
index b62b166..aaac2b9 100644
--- a/tests/PDFJpegEmbedTest.cpp
+++ b/tests/PDFJpegEmbedTest.cpp
@@ -32,8 +32,7 @@
static sk_sp<SkData> load_resource(
skiatest::Reporter* r, const char* test, const char* filename) {
- SkString path(GetResourcePath(filename));
- sk_sp<SkData> data(SkData::MakeFromFileName(path.c_str()));
+ sk_sp<SkData> data = GetResourceAsData(filename);
if (!data) {
INFOF(r, "\n%s: Resource '%s' can not be found.\n",
test, filename);
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index 4cf605a..2543870 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -358,8 +358,8 @@
static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
{
// Load typeface from file to test CreateFromFile with index.
- SkString filename = GetResourcePath("/fonts/test.ttc");
- sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFile(filename.c_str(), 1));
+ auto data = GetResourceAsData("fonts/test.ttc");
+ auto typeface = SkTypeface::MakeFromStream(new SkMemoryStream(std::move(data)), 1);
if (!typeface) {
INFOF(reporter, "Could not run fontstream test because test.ttc not found.");
} else {
@@ -369,7 +369,7 @@
{
// Load typeface as stream to create with axis settings.
- std::unique_ptr<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Distortable.ttf"));
+ std::unique_ptr<SkStreamAsset> distortable(GetResourceAsStream("fonts/Distortable.ttf"));
if (!distortable) {
INFOF(reporter, "Could not run fontstream test because Distortable.ttf not found.");
} else {