aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar tfarina <tfarina@chromium.org>2014-06-18 14:32:48 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-06-18 14:32:49 -0700
commitbcbc1788b478b1e54079318ad073e8490aa66fae (patch)
tree5492557ad07a5917364b69721788bc5ec471954a
parent6518eaaefac27a823c55c16c12b3c698f09aabf5 (diff)
Refactor how we handle resources path in Tests.
This idea emerged while doing https://codereview.chromium.org/321723002/ (commit 880914c35c8f7fc2e9c57134134c883baf66e538). BUG=None TEST=make tests && out/Debug/tests R=mtklein@google.com Author: tfarina@chromium.org Review URL: https://codereview.chromium.org/346453002
-rw-r--r--bench/ETCBitmapBench.cpp1
-rw-r--r--bench/SkBenchmark.cpp14
-rw-r--r--bench/SkBenchmark.h4
-rw-r--r--bench/SkipZeroesBench.cpp1
-rw-r--r--bench/benchmain.cpp5
-rw-r--r--dm/DM.cpp3
-rw-r--r--gm/cmykjpeg.cpp13
-rw-r--r--gm/coloremoji.cpp5
-rw-r--r--gm/copyTo4444.cpp5
-rw-r--r--gm/downsamplebitmap.cpp14
-rw-r--r--gm/etc1bitmap.cpp9
-rw-r--r--gm/factory.cpp5
-rw-r--r--gm/filterbitmap.cpp15
-rw-r--r--gm/filterindiabox.cpp22
-rw-r--r--gm/gm.cpp12
-rw-r--r--gm/gm.h5
-rw-r--r--gm/gmmain.cpp16
-rw-r--r--gyp/SampleApp.gyp15
-rw-r--r--gyp/bench.gyp1
-rw-r--r--gyp/gm.gyp12
-rw-r--r--gyp/resources.gyp25
-rw-r--r--gyp/tests.gypi4
-rw-r--r--gyp/tools.gyp2
-rw-r--r--samplecode/SampleApp.cpp40
-rw-r--r--samplecode/SamplePicture.cpp23
-rw-r--r--samplecode/SampleSubpixelTranslate.cpp15
-rw-r--r--samplecode/SampleUnpremul.cpp4
-rw-r--r--tests/FontHostTest.cpp3
-rw-r--r--tests/ImageDecodingTest.cpp11
-rw-r--r--tests/KtxTest.cpp3
-rw-r--r--tests/Test.cpp10
-rw-r--r--tests/Test.h5
-rw-r--r--tests/skia_test.cpp5
-rw-r--r--tools/Resources.cpp17
-rw-r--r--tools/Resources.h15
35 files changed, 184 insertions, 175 deletions
diff --git a/bench/ETCBitmapBench.cpp b/bench/ETCBitmapBench.cpp
index e9aee76a4a..d5f32db3e0 100644
--- a/bench/ETCBitmapBench.cpp
+++ b/bench/ETCBitmapBench.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "Resources.h"
#include "SkBenchmark.h"
#include "SkCanvas.h"
#include "SkData.h"
diff --git a/bench/SkBenchmark.cpp b/bench/SkBenchmark.cpp
index d1f0639e06..4c5d077b53 100644
--- a/bench/SkBenchmark.cpp
+++ b/bench/SkBenchmark.cpp
@@ -4,7 +4,9 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "SkBenchmark.h"
+
#include "SkPaint.h"
#include "SkParse.h"
@@ -12,8 +14,6 @@ const char* SkTriState::Name[] = { "default", "true", "false" };
template BenchRegistry* BenchRegistry::gHead;
-const char* SkBenchmark::gResourcePath;
-
SkBenchmark::SkBenchmark() {
fForceAlpha = 0xFF;
fForceAA = true;
@@ -51,16 +51,6 @@ void SkBenchmark::setupPaint(SkPaint* paint) {
}
}
-void SkBenchmark::SetResourcePath(const char* resourcePath) {
- gResourcePath = resourcePath;
-}
-
-SkString SkBenchmark::GetResourcePath() {
- return SkString(gResourcePath);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
SkIPoint SkBenchmark::onGetSize() {
return SkIPoint::Make(640, 480);
}
diff --git a/bench/SkBenchmark.h b/bench/SkBenchmark.h
index e86c81b8ec..012d0fd0b0 100644
--- a/bench/SkBenchmark.h
+++ b/bench/SkBenchmark.h
@@ -102,9 +102,6 @@ public:
fClearMask = clearMask;
}
- static void SetResourcePath(const char*);
- static SkString GetResourcePath();
-
protected:
virtual void setupPaint(SkPaint* paint);
@@ -122,7 +119,6 @@ private:
bool fForceFilter;
SkTriState::State fDither;
uint32_t fOrMask, fClearMask;
- static const char* gResourcePath;
typedef SkRefCnt INHERITED;
};
diff --git a/bench/SkipZeroesBench.cpp b/bench/SkipZeroesBench.cpp
index b84cf78169..46acb9f1b2 100644
--- a/bench/SkipZeroesBench.cpp
+++ b/bench/SkipZeroesBench.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "Resources.h"
#include "SkBenchmark.h"
#include "SkBitmap.h"
#include "SkData.h"
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index 078a2e80e0..b82dd017b0 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -255,7 +255,6 @@ DEFINE_double(error, 0.01,
"Ratio of subsequent bench measurements must drop within 1±error to converge.");
DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops.");
DEFINE_bool2(verbose, v, false, "Print more.");
-DEFINE_string2(resourcePath, i, "resources", "directory for test resources.");
DEFINE_string(outResultsFile, "", "If given, the results will be written to the file in JSON format.");
DEFINE_bool(dryRun, false, "Don't actually run the tests, just print what would have been done.");
@@ -347,10 +346,6 @@ int tool_main(int argc, char** argv) {
}
}
}
- // Set the resource path.
- if (!FLAGS_resourcePath.isEmpty()) {
- SkBenchmark::SetResourcePath(FLAGS_resourcePath[0]);
- }
#if SK_SUPPORT_GPU
for (int i = 0; i < configs.count(); ++i) {
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 0de661677a..fde057d03f 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -226,9 +226,6 @@ int tool_main(int argc, char** argv) {
#if SK_ENABLE_INST_COUNT
gPrintInstCount = FLAGS_leaks;
#endif
- GM::SetResourcePath(FLAGS_resources[0]);
- SkBenchmark::SetResourcePath(FLAGS_resources[0]);
- Test::SetResourcePath(FLAGS_resources[0]);
SkTArray<SkString> configs;
for (int i = 0; i < FLAGS_config.count(); i++) {
diff --git a/gm/cmykjpeg.cpp b/gm/cmykjpeg.cpp
index 2d0c275b8d..a1a12dc388 100644
--- a/gm/cmykjpeg.cpp
+++ b/gm/cmykjpeg.cpp
@@ -6,6 +6,8 @@
*/
#include "gm.h"
+
+#include "Resources.h"
#include "SkCanvas.h"
#include "SkImageDecoder.h"
#include "SkStream.h"
@@ -21,18 +23,17 @@ public:
protected:
virtual void onOnceBeforeDraw() SK_OVERRIDE {
-
// parameters to the "decode" call
bool dither = false;
- SkString filename(INHERITED::gResourcePath);
- if (!filename.endsWith("/") && !filename.endsWith("\\")) {
- filename.append("/");
+ SkString resourcePath = GetResourcePath();
+ if (!resourcePath.endsWith("/") && !resourcePath.endsWith("\\")) {
+ resourcePath.append("/");
}
- filename.append("CMYK.jpg");
+ resourcePath.append("CMYK.jpg");
- SkFILEStream stream(filename.c_str());
+ SkFILEStream stream(resourcePath.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 39c70bd707..cf4500819a 100644
--- a/gm/coloremoji.cpp
+++ b/gm/coloremoji.cpp
@@ -6,6 +6,8 @@
*/
#include "gm.h"
+
+#include "Resources.h"
#include "SkCanvas.h"
#include "SkStream.h"
#include "SkTypeface.h"
@@ -27,8 +29,7 @@ protected:
}
virtual void onOnceBeforeDraw() SK_OVERRIDE {
-
- SkString filename(INHERITED::gResourcePath);
+ SkString filename = GetResourcePath();
filename.append("/Funkster.ttf");
SkAutoTUnref<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
diff --git a/gm/copyTo4444.cpp b/gm/copyTo4444.cpp
index 76dc66ca7c..6465d00212 100644
--- a/gm/copyTo4444.cpp
+++ b/gm/copyTo4444.cpp
@@ -6,6 +6,8 @@
*/
#include "gm.h"
+
+#include "Resources.h"
#include "SkCanvas.h"
#include "SkImageDecoder.h"
#include "SkOSFile.h"
@@ -30,7 +32,8 @@ protected:
virtual void onDraw(SkCanvas* canvas) {
SkBitmap bm, bm4444;
- SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_512.png");
+ SkString resourcePath = GetResourcePath();
+ SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_512.png");
if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm, kN32_SkColorType,
SkImageDecoder::kDecodePixels_Mode)) {
SkDebugf("Could not decode the file. Did you forget to set the "
diff --git a/gm/downsamplebitmap.cpp b/gm/downsamplebitmap.cpp
index d7b93072c8..a911b83b9f 100644
--- a/gm/downsamplebitmap.cpp
+++ b/gm/downsamplebitmap.cpp
@@ -6,8 +6,9 @@
*/
#include "gm.h"
-#include "SkGradientShader.h"
+#include "Resources.h"
+#include "SkGradientShader.h"
#include "SkTypeface.h"
#include "SkImageDecoder.h"
#include "SkStream.h"
@@ -18,7 +19,6 @@ static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty
}
class DownsampleBitmapGM : public skiagm::GM {
-
public:
SkBitmap fBM;
SkString fName;
@@ -172,12 +172,12 @@ class DownsampleBitmapImageGM: public DownsampleBitmapGM {
int fSize;
virtual void make_bitmap() SK_OVERRIDE {
- SkString path(skiagm::GM::gResourcePath);
- path.append("/");
- path.append(fFilename);
+ SkString resourcePath = GetResourcePath();
+ resourcePath.append("/");
+ resourcePath.append(fFilename);
- SkImageDecoder *codec = NULL;
- SkFILEStream stream(path.c_str());
+ SkImageDecoder* codec = NULL;
+ SkFILEStream stream(resourcePath.c_str());
if (stream.isValid()) {
codec = SkImageDecoder::Factory(&stream);
}
diff --git a/gm/etc1bitmap.cpp b/gm/etc1bitmap.cpp
index 42c152f887..e0a59b0c4f 100644
--- a/gm/etc1bitmap.cpp
+++ b/gm/etc1bitmap.cpp
@@ -6,6 +6,8 @@
*/
#include "gm.h"
+
+#include "Resources.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDecodingImageGenerator.h"
@@ -93,7 +95,8 @@ protected:
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkBitmap bm;
- SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_128.");
+ SkString resourcePath = GetResourcePath();
+ SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128.");
filename.append(this->fileExtension());
SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str()));
@@ -166,9 +169,9 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
-
SkBitmap bm;
- SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_128.pkm");
+ SkString resourcePath = GetResourcePath();
+ SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128.pkm");
SkAutoDataUnref fileData(SkData::NewFromFileName(filename.c_str()));
if (NULL == fileData) {
diff --git a/gm/factory.cpp b/gm/factory.cpp
index 9b7450e3a3..641133c440 100644
--- a/gm/factory.cpp
+++ b/gm/factory.cpp
@@ -6,6 +6,8 @@
*/
#include "gm.h"
+
+#include "Resources.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDecodingImageGenerator.h"
@@ -27,8 +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(INHERITED::gResourcePath, "plane.png");
+ SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "plane.png");
SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
if (NULL != data.get()) {
// Create a cache which will boot the pixels out anytime the
diff --git a/gm/filterbitmap.cpp b/gm/filterbitmap.cpp
index 351fb2aaf7..d73318d31c 100644
--- a/gm/filterbitmap.cpp
+++ b/gm/filterbitmap.cpp
@@ -6,11 +6,12 @@
*/
#include "gm.h"
-#include "SkGradientShader.h"
-#include "SkTypeface.h"
+#include "Resources.h"
+#include "SkGradientShader.h"
#include "SkImageDecoder.h"
#include "SkStream.h"
+#include "SkTypeface.h"
static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style style) {
SkSafeUnref(paint->setTypeface(SkTypeface::CreateFromName(name, style)));
@@ -193,12 +194,12 @@ class FilterBitmapImageGM: public FilterBitmapGM {
}
void makeBitmap() SK_OVERRIDE {
- SkString path(skiagm::GM::gResourcePath);
- path.append("/");
- path.append(fFilename);
+ SkString resourcePath = GetResourcePath();
+ resourcePath.append("/");
+ resourcePath.append(fFilename);
- SkImageDecoder *codec = NULL;
- SkFILEStream stream(path.c_str());
+ SkImageDecoder* codec = NULL;
+ SkFILEStream stream(resourcePath.c_str());
if (stream.isValid()) {
codec = SkImageDecoder::Factory(&stream);
}
diff --git a/gm/filterindiabox.cpp b/gm/filterindiabox.cpp
index 4acb2c3a71..1987c95bf7 100644
--- a/gm/filterindiabox.cpp
+++ b/gm/filterindiabox.cpp
@@ -6,15 +6,15 @@
*/
#include "gm.h"
-#include "SkGradientShader.h"
-#include "SkTypeface.h"
+#include "Resources.h"
+#include "SkBitmapProcState.h"
+#include "SkBitmapScaler.h"
+#include "SkGradientShader.h"
#include "SkImageDecoder.h"
-#include "SkStream.h"
-
#include "SkImageEncoder.h"
-#include "SkBitmapScaler.h"
-#include "SkBitmapProcState.h"
+#include "SkStream.h"
+#include "SkTypeface.h"
static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) {
SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()),
@@ -104,12 +104,12 @@ protected:
}
void makeBitmap() {
- SkString path(skiagm::GM::gResourcePath);
- path.append("/");
- path.append(fFilename);
+ SkString resourcePath = GetResourcePath();
+ resourcePath.append("/");
+ resourcePath.append(fFilename);
- SkImageDecoder *codec = NULL;
- SkFILEStream stream(path.c_str());
+ SkImageDecoder* codec = NULL;
+ SkFILEStream stream(resourcePath.c_str());
if (stream.isValid()) {
codec = SkImageDecoder::Factory(&stream);
}
diff --git a/gm/gm.cpp b/gm/gm.cpp
index 8da45c5fcb..57c5c5ded6 100644
--- a/gm/gm.cpp
+++ b/gm/gm.cpp
@@ -9,8 +9,6 @@
using namespace skiagm;
-const char* GM::gResourcePath;
-
GM::GM() {
fMode = kGM_Mode;
fBGColor = SK_ColorWHITE;
@@ -66,13 +64,5 @@ void GM::drawSizeBounds(SkCanvas* canvas, SkColor color) {
canvas->drawRect(r, paint);
}
-void GM::SetResourcePath(const char* resourcePath) {
- gResourcePath = resourcePath;
-}
-
-SkString GM::GetResourcePath() {
- return SkString(gResourcePath);
-}
-
// need to explicitly declare this, or we get some weird infinite loop llist
-template GMRegistry* SkTRegistry<GM*(*)(void*)>::gHead;
+template GMRegistry* GMRegistry::gHead;
diff --git a/gm/gm.h b/gm/gm.h
index 90fe47bd41..70a902542e 100644
--- a/gm/gm.h
+++ b/gm/gm.h
@@ -90,9 +90,6 @@ namespace skiagm {
// GM's getISize bounds.
void drawSizeBounds(SkCanvas*, SkColor);
- static void SetResourcePath(const char*);
- static SkString GetResourcePath();
-
bool isCanvasDeferred() const { return fCanvasIsDeferred; }
void setCanvasIsDeferred(bool isDeferred) {
fCanvasIsDeferred = isDeferred;
@@ -104,8 +101,6 @@ namespace skiagm {
}
protected:
- static const char* gResourcePath;
-
virtual void onOnceBeforeDraw() {}
virtual void onDraw(SkCanvas*) = 0;
virtual void onDrawBackground(SkCanvas*);
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 42aed548d1..364e771a36 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -18,6 +18,8 @@
#include "gm_expectations.h"
#include "system_preferences.h"
#include "CrashHandler.h"
+#include "Resources.h"
+#include "SamplePipeControllers.h"
#include "SkBitmap.h"
#include "SkColorPriv.h"
#include "SkCommandLineFlags.h"
@@ -43,7 +45,6 @@
#include "SkSurface.h"
#include "SkTArray.h"
#include "SkTDict.h"
-#include "SamplePipeControllers.h"
#ifdef SK_DEBUG
static const bool kDebugOnly = true;
@@ -1458,7 +1459,6 @@ DEFINE_bool(replay, false, "Exercise the SkPicture replay test pass.");
#if SK_SUPPORT_GPU
DEFINE_bool(resetGpuContext, false, "Reset the GrContext prior to running each GM.");
#endif
-DEFINE_string2(resourcePath, i, "resources", "Directory that stores image resources.");
DEFINE_bool(rtree, false, "Exercise the R-Tree variant of SkPicture test pass.");
DEFINE_bool(serialize, false, "Exercise the SkPicture serialization & deserialization test pass.");
DEFINE_bool(simulatePipePlaybackFailure, false, "Simulate a rendering failure in pipe mode only.");
@@ -2203,13 +2203,6 @@ static bool parse_flags_gmmain_paths(GMMain* gmmain) {
return true;
}
-static bool parse_flags_resource_path() {
- if (FLAGS_resourcePath.count() == 1) {
- GM::SetResourcePath(FLAGS_resourcePath[0]);
- }
- return true;
-}
-
static bool parse_flags_jpeg_quality() {
if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) {
SkDebugf("%s\n", "pdfJpegQuality must be in [-1 .. 100] range.");
@@ -2261,7 +2254,6 @@ int tool_main(int argc, char** argv) {
!parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) ||
#endif
!parse_flags_tile_grid_replay_scales(&tileGridReplayScales) ||
- !parse_flags_resource_path() ||
!parse_flags_jpeg_quality() ||
!parse_flags_configs(&configs, grFactory) ||
!parse_flags_pdf_rasterizers(configs, &pdfRasterizers) ||
@@ -2283,8 +2275,8 @@ int tool_main(int argc, char** argv) {
if (FLAGS_writePicturePath.count() == 1) {
SkDebugf("writing pictures to %s\n", FLAGS_writePicturePath[0]);
}
- if (FLAGS_resourcePath.count() == 1) {
- SkDebugf("reading resources from %s\n", FLAGS_resourcePath[0]);
+ if (!GetResourcePath().isEmpty()) {
+ SkDebugf("reading resources from %s\n", GetResourcePath().c_str());
}
}
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp
index d4dda70049..abfc8b77f9 100644
--- a/gyp/SampleApp.gyp
+++ b/gyp/SampleApp.gyp
@@ -19,7 +19,6 @@
'../samplecode', # To pull SampleApp.h and SampleCode.h
'../src/pipe/utils', # For TiledPipeController
'../src/utils/debugger',
- '../tools',
],
'includes': [
'gmslides.gypi',
@@ -135,7 +134,7 @@
# Lua
'../src/utils/SkLuaCanvas.cpp',
'../src/utils/SkLua.cpp',
-
+
# tools
'../tools/sk_tool_utils.cpp',
],
@@ -145,15 +144,17 @@
'../samplecode/SampleFontCache.cpp',
],
'dependencies': [
- 'skia_lib.gyp:skia_lib',
- 'views.gyp:views',
'animator.gyp:animator',
- 'xml.gyp:xml',
+ 'etc1.gyp:libetc1',
'experimental.gyp:experimental',
+ 'flags.gyp:flags',
+ 'lua.gyp:lua',
'pdf.gyp:pdf',
+ 'resources.gyp:resources',
+ 'skia_lib.gyp:skia_lib',
+ 'views.gyp:views',
'views_animated.gyp:views_animated',
- 'lua.gyp:lua',
- 'etc1.gyp:libetc1',
+ 'xml.gyp:xml',
],
'conditions' : [
[ 'sample_pdf_file_viewer == 1', {
diff --git a/gyp/bench.gyp b/gyp/bench.gyp
index a5e0cd6918..6ec972f328 100644
--- a/gyp/bench.gyp
+++ b/gyp/bench.gyp
@@ -14,6 +14,7 @@
'etc1.gyp:libetc1',
'flags.gyp:flags',
'jsoncpp.gyp:jsoncpp',
+ 'resources.gyp:resources',
'skia_lib.gyp:skia_lib',
],
'sources': [
diff --git a/gyp/gm.gyp b/gyp/gm.gyp
index fd8f74d621..0b0054b701 100644
--- a/gyp/gm.gyp
+++ b/gyp/gm.gyp
@@ -31,11 +31,10 @@
'type': 'executable',
'include_dirs' : [
'../src/core',
- '../src/images',
'../src/effects',
- '../src/pipe/utils/',
- '../src/utils/',
- '../tools',
+ '../src/images',
+ '../src/pipe/utils',
+ '../src/utils',
],
'includes': [
'gmslides.gypi',
@@ -48,12 +47,13 @@
'../src/pipe/utils/SamplePipeControllers.cpp',
],
'dependencies': [
- 'skia_lib.gyp:skia_lib',
+ 'etc1.gyp:libetc1',
'flags.gyp:flags',
'gm.gyp:gm_expectations',
'jsoncpp.gyp:jsoncpp',
'pdf.gyp:pdf',
- 'etc1.gyp:libetc1',
+ 'resources.gyp:resources',
+ 'skia_lib.gyp:skia_lib',
],
'conditions': [
['skia_android_framework', {
diff --git a/gyp/resources.gyp b/gyp/resources.gyp
new file mode 100644
index 0000000000..48e96c3cc5
--- /dev/null
+++ b/gyp/resources.gyp
@@ -0,0 +1,25 @@
+# Copyright 2014 Google Inc.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'resources',
+ 'type': 'static_library',
+ 'sources': [
+ '../tools/Resources.cpp',
+ '../tools/Resources.h',
+ ],
+ 'dependencies': [
+ 'flags.gyp:flags',
+ 'skia_lib.gyp:skia_lib',
+ ],
+ 'direct_dependent_settings': {
+ 'include_dirs': [
+ '../tools/',
+ ],
+ },
+ },
+ ]
+}
diff --git a/gyp/tests.gypi b/gyp/tests.gypi
index 556143f279..2a7dddd4ff 100644
--- a/gyp/tests.gypi
+++ b/gyp/tests.gypi
@@ -11,17 +11,17 @@
'../src/pipe/utils',
'../src/utils',
'../src/utils/debugger',
- '../tools/',
# Needed for TDStackNesterTest.
'../experimental/PdfViewer',
'../experimental/PdfViewer/src',
],
'dependencies': [
- 'skia_lib.gyp:skia_lib',
'experimental.gyp:experimental',
'flags.gyp:flags',
'pdf.gyp:pdf',
+ 'resources.gyp:resources',
+ 'skia_lib.gyp:skia_lib',
'tools.gyp:picture_utils',
],
'sources': [
diff --git a/gyp/tools.gyp b/gyp/tools.gyp
index 9cea4617e1..7af70f782f 100644
--- a/gyp/tools.gyp
+++ b/gyp/tools.gyp
@@ -476,7 +476,7 @@
],
'direct_dependent_settings': {
'include_dirs': [
- '../tools/',
+ '../tools/',
],
},
},
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index eee379cf8b..264b17c632 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -7,12 +7,19 @@
#include "SampleApp.h"
-#include "SkData.h"
+#include "OverView.h"
+#include "SampleCode.h"
+#include "SamplePipeControllers.h"
#include "SkCanvas.h"
+#include "SkCommandLineFlags.h"
+#include "SkData.h"
#include "SkDevice.h"
+#include "SkGPipe.h"
#include "SkGraphics.h"
-#include "SkImageDecoder.h"
#include "SkImageEncoder.h"
+#include "SkOSFile.h"
+#include "SkPDFDevice.h"
+#include "SkPDFDocument.h"
#include "SkPaint.h"
#include "SkPicture.h"
#include "SkPictureRecorder.h"
@@ -20,10 +27,10 @@
#include "SkSurface.h"
#include "SkTSort.h"
#include "SkTime.h"
-#include "SkWindow.h"
-
-#include "SampleCode.h"
#include "SkTypeface.h"
+#include "SkWindow.h"
+#include "TransitionView.h"
+#include "sk_tool_utils.h"
#if SK_SUPPORT_GPU
#include "gl/GrGLInterface.h"
@@ -35,17 +42,6 @@
class GrContext;
#endif
-#include "SkOSFile.h"
-#include "SkPDFDevice.h"
-#include "SkPDFDocument.h"
-#include "SkStream.h"
-
-#include "SkGPipe.h"
-#include "SamplePipeControllers.h"
-#include "OverView.h"
-#include "TransitionView.h"
-#include "sk_tool_utils.h"
-
extern SampleView* CreateSamplePictFileView(const char filename[]);
class PictFileFactory : public SkViewFactory {
@@ -783,18 +779,14 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : NULL, compareSampleTitle);
}
- const char* resourcePath = "resources"; // same default as tests
fMSAASampleCount = 0;
+ SkCommandLineFlags::Parse(argc, argv);
+
const char* const commandName = argv[0];
char* const* stop = argv + argc;
for (++argv; argv < stop; ++argv) {
- if (!strcmp(*argv, "-i") || !strcmp(*argv, "--resourcePath")) {
- argv++;
- if (argv < stop && **argv) {
- resourcePath = *argv;
- }
- } else if (strcmp(*argv, "--slide") == 0) {
+ if (strcmp(*argv, "--slide") == 0) {
argv++;
if (argv < stop && **argv) {
fCurrIndex = findByTitle(*argv);
@@ -965,8 +957,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
this->setVisibleP(true);
this->setClipToBounds(false);
- skiagm::GM::SetResourcePath(resourcePath);
-
this->loadView((*fSamples[fCurrIndex])());
fPDFData = NULL;
diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp
index 9c965e4308..ecc59415a0 100644
--- a/samplecode/SamplePicture.cpp
+++ b/samplecode/SamplePicture.cpp
@@ -5,12 +5,16 @@
* found in the LICENSE file.
*/
+#include "gm.h"
+
+#include "Resources.h"
#include "SampleCode.h"
+#include "SkCanvas.h"
+#include "SkColorFilter.h"
+#include "SkColorPriv.h"
#include "SkData.h"
#include "SkDecodingImageGenerator.h"
#include "SkDumpCanvas.h"
-#include "SkView.h"
-#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkGraphics.h"
#include "SkImageDecoder.h"
@@ -21,23 +25,20 @@
#include "SkRandom.h"
#include "SkRegion.h"
#include "SkShader.h"
-#include "SkUtils.h"
-#include "SkColorPriv.h"
-#include "SkColorFilter.h"
+#include "SkStream.h"
#include "SkTime.h"
#include "SkTypeface.h"
-#include "SkXfermode.h"
-#include "SkStream.h"
+#include "SkUtils.h"
+#include "SkView.h"
#include "SkXMLParser.h"
-
-#include "gm.h"
+#include "SkXfermode.h"
///////////////////////////////////////////////////////////////////////////////
static SkBitmap load_bitmap() {
SkBitmap bm;
- SkString directory = skiagm::GM::GetResourcePath();
- SkString path = SkOSPath::SkPathJoin(directory.c_str(), "mandrill_512.png");
+ SkString resourcePath = GetResourcePath();
+ SkString path = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_512.png");
SkAutoDataUnref data(SkData::NewFromFileName(path.c_str()));
if (data.get() != NULL) {
SkInstallDiscardablePixelRef(SkDecodingImageGenerator::Create(
diff --git a/samplecode/SampleSubpixelTranslate.cpp b/samplecode/SampleSubpixelTranslate.cpp
index afb31c162c..41a0f156c1 100644
--- a/samplecode/SampleSubpixelTranslate.cpp
+++ b/samplecode/SampleSubpixelTranslate.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2014 Google Inc.
*
@@ -7,10 +6,12 @@
*/
#include "gm.h"
+
+#include "Resources.h"
#include "SampleCode.h"
#include "SkBlurMaskFilter.h"
-#include "SkColorPriv.h"
#include "SkCanvas.h"
+#include "SkColorPriv.h"
#include "SkImageDecoder.h"
#include "SkRandom.h"
#include "SkStream.h"
@@ -26,12 +27,12 @@ public:
: fFilename(imageFilename),
fHorizontalVelocity(horizontalVelocity),
fVerticalVelocity(verticalVelocity) {
- SkString path(skiagm::GM::GetResourcePath());
- path.append("/");
- path.append(fFilename);
+ SkString resourcePath = GetResourcePath();
+ resourcePath.append("/");
+ resourcePath.append(fFilename);
- SkImageDecoder *codec = NULL;
- SkFILEStream stream(path.c_str());
+ SkImageDecoder* codec = NULL;
+ SkFILEStream stream(resourcePath.c_str());
if (stream.isValid()) {
codec = SkImageDecoder::Factory(&stream);
}
diff --git a/samplecode/SampleUnpremul.cpp b/samplecode/SampleUnpremul.cpp
index c84e1d44e8..ab99ecb8ce 100644
--- a/samplecode/SampleUnpremul.cpp
+++ b/samplecode/SampleUnpremul.cpp
@@ -6,6 +6,8 @@
*/
#include "gm.h"
+
+#include "Resources.h"
#include "SampleCode.h"
#include "SkBlurMask.h"
#include "SkBlurDrawLooper.h"
@@ -199,6 +201,6 @@ private:
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() {
- return new UnpremulView(skiagm::GM::GetResourcePath());
+ return new UnpremulView(GetResourcePath());
}
static SkViewRegister reg(MyFactory);
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
index bc87aaa754..23625b3874 100644
--- a/tests/FontHostTest.cpp
+++ b/tests/FontHostTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "Resources.h"
#include "SkEndian.h"
#include "SkFontStream.h"
#include "SkOSFile.h"
@@ -149,7 +150,7 @@ static void test_fontstream(skiatest::Reporter* reporter, SkStream* stream) {
static void test_fontstream(skiatest::Reporter* reporter) {
// This test cannot run if there is no resource path.
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (resourcePath.isEmpty()) {
SkDebugf("Could not run fontstream test because resourcePath not specified.");
return;
diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp
index 3b9c194929..89db3990e4 100644
--- a/tests/ImageDecodingTest.cpp
+++ b/tests/ImageDecodingTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "Resources.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkColor.h"
@@ -148,7 +149,7 @@ static void compare_unpremul(skiatest::Reporter* reporter, const SkString& filen
static void test_unpremul(skiatest::Reporter* reporter) {
// This test cannot run if there is no resource path.
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (resourcePath.isEmpty()) {
SkDebugf("Could not run unpremul test because resourcePath not specified.");
return;
@@ -230,7 +231,7 @@ static void test_alphaType(skiatest::Reporter* reporter, const SkString& filenam
}
DEF_TEST(ImageDecoding_alphaType, reporter) {
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (resourcePath.isEmpty()) {
SkDebugf("Could not run alphaType test because resourcePath not specified.");
return;
@@ -253,7 +254,7 @@ DEF_TEST(ImageDecoding_alphaType, reporter) {
// Using known images, test that decoding into unpremul and premul behave as expected.
DEF_TEST(ImageDecoding_unpremul, reporter) {
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (resourcePath.isEmpty()) {
SkDebugf("Could not run unpremul test because resourcePath not specified.");
return;
@@ -502,7 +503,7 @@ static SkPixelRef* install_pixel_ref(SkBitmap* bitmap,
* SkInstallDiscardablePixelRef functions.
*/
DEF_TEST(ImprovedBitmapFactory, reporter) {
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
SkString path = SkOSPath::SkPathJoin(
resourcePath.c_str(), "randPixels.png");
SkAutoTUnref<SkStreamRewindable> stream(
@@ -676,7 +677,7 @@ DEF_TEST(ImageDecoderOptions, reporter) {
#endif
};
- SkString resourceDir = skiatest::Test::GetResourcePath();
+ SkString resourceDir = GetResourcePath();
if (!sk_exists(resourceDir.c_str())) {
return;
}
diff --git a/tests/KtxTest.cpp b/tests/KtxTest.cpp
index 5cec2bf297..e9c4217ead 100644
--- a/tests/KtxTest.cpp
+++ b/tests/KtxTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "Resources.h"
#include "SkBitmap.h"
#include "SkData.h"
#include "SkDecodingImageGenerator.h"
@@ -140,7 +141,7 @@ 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 = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128.pkm");
// Load PKM file into a bitmap
diff --git a/tests/Test.cpp b/tests/Test.cpp
index b904d5a76d..20afd45561 100644
--- a/tests/Test.cpp
+++ b/tests/Test.cpp
@@ -41,8 +41,6 @@ void Reporter::endTest(Test* test) {
///////////////////////////////////////////////////////////////////////////////
-const char* Test::gResourcePath;
-
Test::Test() : fReporter(NULL), fPassed(true) {}
Test::~Test() {
@@ -122,11 +120,3 @@ SkString Test::GetTmpDir() {
const char* tmpDir = FLAGS_tmpDir.isEmpty() ? NULL : FLAGS_tmpDir[0];
return SkString(tmpDir);
}
-
-void Test::SetResourcePath(const char* resourcePath) {
- gResourcePath = resourcePath;
-}
-
-SkString Test::GetResourcePath() {
- return SkString(gResourcePath);
-}
diff --git a/tests/Test.h b/tests/Test.h
index 90d072ef66..fc1890096e 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -62,9 +62,6 @@ namespace skiatest {
static SkString GetTmpDir();
- static void SetResourcePath(const char*);
- static SkString GetResourcePath();
-
virtual bool isGPUTest() const { return false; }
virtual void setGrContextFactory(GrContextFactory* factory) {}
@@ -73,8 +70,6 @@ namespace skiatest {
virtual void onRun(Reporter*) = 0;
private:
- static const char* gResourcePath;
-
Reporter* fReporter;
SkString fName;
bool fPassed;
diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp
index f70a7fab62..f4b67c9bc4 100644
--- a/tests/skia_test.cpp
+++ b/tests/skia_test.cpp
@@ -7,6 +7,7 @@
#include "CrashHandler.h"
#include "OverwriteLine.h"
+#include "Resources.h"
#include "SkCommandLineFlags.h"
#include "SkGraphics.h"
#include "SkOSFile.h"
@@ -40,7 +41,6 @@ DEFINE_bool(cpu, true, "whether or not to run CPU tests.");
DEFINE_bool(gpu, true, "whether or not to run GPU tests.");
DEFINE_int32(threads, SkThreadPool::kThreadPerCore,
"Run threadsafe tests on a threadpool with this many threads.");
-DEFINE_string2(resourcePath, i, "resources", "directory for test resources.");
// need to explicitly declare this, or we get some weird infinite loop llist
template TestRegistry* TestRegistry::gHead;
@@ -136,7 +136,6 @@ int tool_main(int argc, char** argv) {
SetupCrashHandler();
SkCommandLineFlags::SetUsage("");
SkCommandLineFlags::Parse(argc, argv);
- Test::SetResourcePath(FLAGS_resourcePath[0]);
#if SK_ENABLE_INST_COUNT
if (FLAGS_leaks) {
@@ -158,7 +157,7 @@ int tool_main(int argc, char** argv) {
if (!tmpDir.isEmpty()) {
header.appendf(" --tmpDir %s", tmpDir.c_str());
}
- SkString resourcePath = Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (!resourcePath.isEmpty()) {
header.appendf(" --resourcePath %s", resourcePath.c_str());
}
diff --git a/tools/Resources.cpp b/tools/Resources.cpp
new file mode 100644
index 0000000000..756d14ad3a
--- /dev/null
+++ b/tools/Resources.cpp
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Resources.h"
+
+#include "SkCommandLineFlags.h"
+#include "SkOSFile.h"
+
+DEFINE_string2(resourcePath, i, "resources", "Directory with test resources: images, fonts, etc.");
+
+SkString GetResourcePath(const char* resource) {
+ return SkOSPath::SkPathJoin(FLAGS_resourcePath[0], resource);
+}
diff --git a/tools/Resources.h b/tools/Resources.h
new file mode 100644
index 0000000000..a10612b78d
--- /dev/null
+++ b/tools/Resources.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef Resources_DEFINED
+#define Resources_DEFINED
+
+#include "SkString.h"
+
+SkString GetResourcePath(const char* resource = "");
+
+#endif // Resources_DEFINED