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
diff --git a/bench/ETCBitmapBench.cpp b/bench/ETCBitmapBench.cpp
index e9aee76..d5f32db 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 d1f0639..4c5d077 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 @@
 
 template BenchRegistry* BenchRegistry::gHead;
 
-const char* SkBenchmark::gResourcePath;
-
 SkBenchmark::SkBenchmark() {
     fForceAlpha = 0xFF;
     fForceAA = true;
@@ -51,16 +51,6 @@
     }
 }
 
-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 e86c81b..012d0fd 100644
--- a/bench/SkBenchmark.h
+++ b/bench/SkBenchmark.h
@@ -102,9 +102,6 @@
         fClearMask = clearMask;
     }
 
-    static void SetResourcePath(const char*);
-    static SkString GetResourcePath();
-
 protected:
     virtual void setupPaint(SkPaint* paint);
 
@@ -122,7 +119,6 @@
     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 b84cf78..46acb9f 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 078a2e8..b82dd01 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -255,7 +255,6 @@
               "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 @@
             }
         }
     }
-    // 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 0de6616..fde057d 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -226,9 +226,6 @@
 #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 2d0c275..a1a12dc 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 @@
 
 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 39c70bd..cf45008 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 @@
     }
 
     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 76dc66c..6465d00 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 @@
 
     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 d7b9307..a911b83 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 @@
 }
 
 class DownsampleBitmapGM : public skiagm::GM {
-
 public:
     SkBitmap    fBM;
     SkString    fName;
@@ -172,12 +172,12 @@
       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 42c152f..e0a59b0 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 @@
 
     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 @@
     }
 
     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 9b7450e..641133c 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 @@
 
 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 351fb2a..d73318d 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 @@
       }
 
       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 4acb2c3..1987c95 100644
--- a/gm/filterindiabox.cpp
+++ b/gm/filterindiabox.cpp
@@ -6,15 +6,15 @@
  */
 
 #include "gm.h"
-#include "SkGradientShader.h"
 
-#include "SkTypeface.h"
-#include "SkImageDecoder.h"
-#include "SkStream.h"
-
-#include "SkImageEncoder.h"
-#include "SkBitmapScaler.h"
+#include "Resources.h"
 #include "SkBitmapProcState.h"
+#include "SkBitmapScaler.h"
+#include "SkGradientShader.h"
+#include "SkImageDecoder.h"
+#include "SkImageEncoder.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 @@
       }
 
       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 8da45c5..57c5c5d 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 @@
     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 90fe47b..70a9025 100644
--- a/gm/gm.h
+++ b/gm/gm.h
@@ -90,9 +90,6 @@
         // 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 @@
         }
 
     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 42aed54..364e771 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 @@
 #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 @@
     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 @@
         !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 @@
         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 d4dda70..abfc8b7 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': [
+        'animator.gyp:animator',
+        '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',
-        'animator.gyp:animator',
-        'xml.gyp:xml',
-        'experimental.gyp:experimental',
-        'pdf.gyp:pdf',
         '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 a5e0cd6..6ec972f 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 fd8f74d..0b0054b 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 0000000..48e96c3
--- /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 556143f..2a7dddd 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 9cea461..7af70f7 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 eee379c..264b17c 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 @@
         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 @@
     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 9c965e4..ecc5941 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 afb31c1..41a0f15 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 @@
       : 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 c84e1d4..ab99ecb 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 @@
 //////////////////////////////////////////////////////////////////////////////
 
 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 bc87aaa..23625b3 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) {
     // 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 3b9c194..89db399 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 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 @@
 }
 
 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 @@
 
 // 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 @@
  *  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 @@
         #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 5cec2bf..e9c4217 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 @@
  * 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 b904d5a..20afd45 100644
--- a/tests/Test.cpp
+++ b/tests/Test.cpp
@@ -41,8 +41,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-const char* Test::gResourcePath;
-
 Test::Test() : fReporter(NULL), fPassed(true) {}
 
 Test::~Test() {
@@ -122,11 +120,3 @@
     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 90d072e..fc18900 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -62,9 +62,6 @@
 
         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 @@
         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 f70a7fa..f4b67c9 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(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 @@
     SetupCrashHandler();
     SkCommandLineFlags::SetUsage("");
     SkCommandLineFlags::Parse(argc, argv);
-    Test::SetResourcePath(FLAGS_resourcePath[0]);
 
 #if SK_ENABLE_INST_COUNT
     if (FLAGS_leaks) {
@@ -158,7 +157,7 @@
         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 0000000..756d14a
--- /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 0000000..a10612b
--- /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