From c846f4a96bcde1ffeaf17afc1469db6f2cbd1ad3 Mon Sep 17 00:00:00 2001 From: tfarina Date: Tue, 1 Jul 2014 12:35:49 -0700 Subject: [PATCH] Cleanup usage of GetResourcePath() after commit bcbc1788b478b1e54079318ad073e8490aa66fae. There was a clean up opportunity left over after https://skia.googlesource.com/skia/+/bcbc1788b478b1e54079318ad073e8490aa66fae, that could make use of the default parameter of GetResourcePath() function to make some call sites cleaner. We decided to make it in a separate CL to make reviewer's and author's life easier, so we could catch errors and/or mistakes easily. BUG=None TEST=make all && out/Debug/dm && out/Debug/SampleApp R=mtklein@google.com Author: tfarina@chromium.org Review URL: https://codereview.chromium.org/351133003 --- bench/ETCBitmapBench.cpp | 9 +++------ gm/cmykjpeg.cpp | 10 ++-------- gm/coloremoji.cpp | 4 +--- gm/copyTo4444.cpp | 5 ++--- gm/downsamplebitmap.cpp | 5 +---- gm/etc1bitmap.cpp | 10 +++------- gm/factory.cpp | 5 ++--- gm/filterbitmap.cpp | 5 +---- gm/filterindiabox.cpp | 5 +---- samplecode/SamplePicture.cpp | 5 ++--- samplecode/SampleSubpixelTranslate.cpp | 9 ++------- tests/ImageDecodingTest.cpp | 9 +++------ tests/KtxTest.cpp | 7 +++---- 13 files changed, 26 insertions(+), 62 deletions(-) diff --git a/bench/ETCBitmapBench.cpp b/bench/ETCBitmapBench.cpp index e5ec44f2de..529f5f69da 100644 --- a/bench/ETCBitmapBench.cpp +++ b/bench/ETCBitmapBench.cpp @@ -89,13 +89,10 @@ protected: SkAutoDataUnref fPKMData; private: - SkData *loadPKM() { - SkString resourcePath = GetResourcePath(); - SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), - "mandrill_128.pkm"); - + SkData* loadPKM() { + SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); // Expand the data - SkAutoDataUnref fileData(SkData::NewFromFileName(filename.c_str())); + SkAutoDataUnref fileData(SkData::NewFromFileName(pkmFilename.c_str())); if (NULL == fileData) { SkDebugf("Could not open the file. Did you forget to set the resourcePath?\n"); return NULL; diff --git a/gm/cmykjpeg.cpp b/gm/cmykjpeg.cpp index a1a12dc388..5371fe2133 100644 --- a/gm/cmykjpeg.cpp +++ b/gm/cmykjpeg.cpp @@ -26,14 +26,8 @@ protected: // parameters to the "decode" call bool dither = false; - SkString resourcePath = GetResourcePath(); - if (!resourcePath.endsWith("/") && !resourcePath.endsWith("\\")) { - resourcePath.append("/"); - } - - resourcePath.append("CMYK.jpg"); - - SkFILEStream stream(resourcePath.c_str()); + SkString jpgFilename = GetResourcePath("CMYK.jpg"); + SkFILEStream stream(jpgFilename.c_str()); if (!stream.isValid()) { SkDebugf("Could not find CMYK.jpg, please set --resourcePath correctly.\n"); return; diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp index cf4500819a..7fe54f515f 100644 --- a/gm/coloremoji.cpp +++ b/gm/coloremoji.cpp @@ -29,9 +29,7 @@ protected: } virtual void onOnceBeforeDraw() SK_OVERRIDE { - SkString filename = GetResourcePath(); - filename.append("/Funkster.ttf"); - + SkString filename = GetResourcePath("/Funkster.ttf"); SkAutoTUnref stream(new SkFILEStream(filename.c_str())); if (!stream->isValid()) { SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n"); diff --git a/gm/copyTo4444.cpp b/gm/copyTo4444.cpp index 6465d00212..635cc7b834 100644 --- a/gm/copyTo4444.cpp +++ b/gm/copyTo4444.cpp @@ -32,9 +32,8 @@ protected: virtual void onDraw(SkCanvas* canvas) { SkBitmap bm, bm4444; - SkString resourcePath = GetResourcePath(); - SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_512.png"); - if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm, kN32_SkColorType, + SkString pngFilename = GetResourcePath("mandrill_512.png"); + if (!SkImageDecoder::DecodeFile(pngFilename.c_str(), &bm, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode)) { SkDebugf("Could not decode the file. Did you forget to set the " "resourcePath?\n"); diff --git a/gm/downsamplebitmap.cpp b/gm/downsamplebitmap.cpp index a911b83b9f..f24c92b6e5 100644 --- a/gm/downsamplebitmap.cpp +++ b/gm/downsamplebitmap.cpp @@ -172,11 +172,8 @@ class DownsampleBitmapImageGM: public DownsampleBitmapGM { int fSize; virtual void make_bitmap() SK_OVERRIDE { - SkString resourcePath = GetResourcePath(); - resourcePath.append("/"); - resourcePath.append(fFilename); - SkImageDecoder* codec = NULL; + SkString resourcePath = GetResourcePath(fFilename.c_str()); SkFILEStream stream(resourcePath.c_str()); if (stream.isValid()) { codec = SkImageDecoder::Factory(&stream); diff --git a/gm/etc1bitmap.cpp b/gm/etc1bitmap.cpp index e0a59b0c4f..2241c848c3 100644 --- a/gm/etc1bitmap.cpp +++ b/gm/etc1bitmap.cpp @@ -95,10 +95,8 @@ protected: virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { SkBitmap bm; - SkString resourcePath = GetResourcePath(); - SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128."); + SkString filename = GetResourcePath("mandrill_128."); filename.append(this->fileExtension()); - SkAutoTUnref fileData(SkData::NewFromFileName(filename.c_str())); if (NULL == fileData) { SkDebugf("Could not open the file. Did you forget to set the resourcePath?\n"); @@ -170,10 +168,8 @@ protected: virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { SkBitmap bm; - SkString resourcePath = GetResourcePath(); - SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128.pkm"); - - SkAutoDataUnref fileData(SkData::NewFromFileName(filename.c_str())); + SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); + SkAutoDataUnref fileData(SkData::NewFromFileName(pkmFilename.c_str())); if (NULL == fileData) { SkDebugf("Could not open the file. Did you forget to set the resourcePath?\n"); return; diff --git a/gm/factory.cpp b/gm/factory.cpp index 641133c440..608c049dc3 100644 --- a/gm/factory.cpp +++ b/gm/factory.cpp @@ -29,10 +29,9 @@ public: protected: virtual void onOnceBeforeDraw() SK_OVERRIDE { - SkString resourcePath = GetResourcePath(); // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo - SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "plane.png"); - SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str())); + SkString pngFilename = GetResourcePath("plane.png"); + SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str())); if (NULL != data.get()) { // Create a cache which will boot the pixels out anytime the // bitmap is unlocked. diff --git a/gm/filterbitmap.cpp b/gm/filterbitmap.cpp index d73318d31c..0d4b4b4a4b 100644 --- a/gm/filterbitmap.cpp +++ b/gm/filterbitmap.cpp @@ -194,11 +194,8 @@ class FilterBitmapImageGM: public FilterBitmapGM { } void makeBitmap() SK_OVERRIDE { - SkString resourcePath = GetResourcePath(); - resourcePath.append("/"); - resourcePath.append(fFilename); - SkImageDecoder* codec = NULL; + SkString resourcePath = GetResourcePath(fFilename.c_str()); SkFILEStream stream(resourcePath.c_str()); if (stream.isValid()) { codec = SkImageDecoder::Factory(&stream); diff --git a/gm/filterindiabox.cpp b/gm/filterindiabox.cpp index 1987c95bf7..c3316b4ea2 100644 --- a/gm/filterindiabox.cpp +++ b/gm/filterindiabox.cpp @@ -104,11 +104,8 @@ protected: } void makeBitmap() { - SkString resourcePath = GetResourcePath(); - resourcePath.append("/"); - resourcePath.append(fFilename); - SkImageDecoder* codec = NULL; + SkString resourcePath = GetResourcePath(fFilename.c_str()); SkFILEStream stream(resourcePath.c_str()); if (stream.isValid()) { codec = SkImageDecoder::Factory(&stream); diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp index ecc59415a0..28256e5675 100644 --- a/samplecode/SamplePicture.cpp +++ b/samplecode/SamplePicture.cpp @@ -37,9 +37,8 @@ static SkBitmap load_bitmap() { SkBitmap bm; - SkString resourcePath = GetResourcePath(); - SkString path = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_512.png"); - SkAutoDataUnref data(SkData::NewFromFileName(path.c_str())); + SkString pngFilename = GetResourcePath("mandrill_512.png"); + SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str())); if (data.get() != NULL) { SkInstallDiscardablePixelRef(SkDecodingImageGenerator::Create( data, SkDecodingImageGenerator::Options()), &bm); diff --git a/samplecode/SampleSubpixelTranslate.cpp b/samplecode/SampleSubpixelTranslate.cpp index 41a0f156c1..4652bc37ad 100644 --- a/samplecode/SampleSubpixelTranslate.cpp +++ b/samplecode/SampleSubpixelTranslate.cpp @@ -24,13 +24,9 @@ public: SubpixelTranslateView(const char imageFilename[], float horizontalVelocity, float verticalVelocity) - : fFilename(imageFilename), - fHorizontalVelocity(horizontalVelocity), + : fHorizontalVelocity(horizontalVelocity), fVerticalVelocity(verticalVelocity) { - SkString resourcePath = GetResourcePath(); - resourcePath.append("/"); - resourcePath.append(fFilename); - + SkString resourcePath = GetResourcePath(imageFilename); SkImageDecoder* codec = NULL; SkFILEStream stream(resourcePath.c_str()); if (stream.isValid()) { @@ -50,7 +46,6 @@ public: protected: SkBitmap fBM; - SkString fFilename; SkScalar fSize; float fHorizontalVelocity, fVerticalVelocity; diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp index 89db3990e4..d070f615b3 100644 --- a/tests/ImageDecodingTest.cpp +++ b/tests/ImageDecodingTest.cpp @@ -503,12 +503,9 @@ static SkPixelRef* install_pixel_ref(SkBitmap* bitmap, * SkInstallDiscardablePixelRef functions. */ DEF_TEST(ImprovedBitmapFactory, reporter) { - SkString resourcePath = GetResourcePath(); - SkString path = SkOSPath::SkPathJoin( - resourcePath.c_str(), "randPixels.png"); - SkAutoTUnref stream( - SkStream::NewFromFile(path.c_str())); - if (sk_exists(path.c_str())) { + SkString pngFilename = GetResourcePath("randPixels.png"); + SkAutoTUnref stream(SkStream::NewFromFile(pngFilename.c_str())); + if (sk_exists(pngFilename.c_str())) { SkBitmap bm; SkAssertResult(bm.setInfo(SkImageInfo::MakeN32Premul(1, 1))); REPORTER_ASSERT(reporter, diff --git a/tests/KtxTest.cpp b/tests/KtxTest.cpp index e9c4217ead..83a3546bec 100644 --- a/tests/KtxTest.cpp +++ b/tests/KtxTest.cpp @@ -141,12 +141,11 @@ DEF_TEST(KtxReadUnpremul, reporter) { * the PKM to the KTX should produce an identical KTX to the one we have on file) */ DEF_TEST(KtxReexportPKM, reporter) { - SkString resourcePath = GetResourcePath(); - SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128.pkm"); + SkString pkmFilename = GetResourcePath("mandrill_128.pkm"); // Load PKM file into a bitmap SkBitmap etcBitmap; - SkAutoTUnref fileData(SkData::NewFromFileName(filename.c_str())); + SkAutoTUnref fileData(SkData::NewFromFileName(pkmFilename.c_str())); REPORTER_ASSERT(reporter, NULL != fileData); bool installDiscardablePixelRefSuccess = @@ -161,7 +160,7 @@ DEF_TEST(KtxReexportPKM, reporter) { REPORTER_ASSERT(reporter, NULL != ktxDataPtr); // See is this data is identical to data in existing ktx file. - SkString ktxFilename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128.ktx"); + SkString ktxFilename = GetResourcePath("mandrill_128.ktx"); SkAutoDataUnref oldKtxData(SkData::NewFromFileName(ktxFilename.c_str())); REPORTER_ASSERT(reporter, oldKtxData->equals(newKtxData)); }