Reland "Clean up Test's resourcePath code."
authortfarina <tfarina@chromium.org>
Mon, 9 Jun 2014 19:05:34 +0000 (12:05 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 9 Jun 2014 19:05:34 +0000 (12:05 -0700)
This relands commit 91359bed48bc006a4319da86eb26db3b2e6d4afb (Clean up
Test's resourcePath code."

BUG=None
TEST=make dm && out/Debug/dm
R=mtklein@google.com

Author: tfarina@chromium.org

Review URL: https://codereview.chromium.org/321723002

bench/ETCBitmapBench.cpp
bench/SkBenchmark.cpp
bench/SkBenchmark.h
bench/SkipZeroesBench.cpp
gm/copyTo4444.cpp
gm/etc1bitmap.cpp
gm/factory.cpp
gm/gm.cpp
gm/gm.h
tests/Test.cpp
tests/Test.h

index 4b9cd6e..e9aee76 100644 (file)
@@ -89,8 +89,9 @@ protected:
 
 private:
     SkData *loadPKM() {
-        SkString filename = SkOSPath::SkPathJoin(
-            INHERITED::GetResourcePath().c_str(), "mandrill_128.pkm");
+        SkString resourcePath = GetResourcePath();
+        SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(),
+                                                 "mandrill_128.pkm");
 
         // Expand the data
         SkAutoDataUnref fileData(SkData::NewFromFileName(filename.c_str()));
index d995415..1f12ed3 100644 (file)
@@ -12,7 +12,7 @@ const char* SkTriState::Name[] = { "default", "true", "false" };
 
 template BenchRegistry* BenchRegistry::gHead;
 
-SkString SkBenchmark::gResourcePath;
+const char* SkBenchmark::gResourcePath;
 
 SkBenchmark::SkBenchmark() {
     fForceAlpha = 0xFF;
@@ -55,6 +55,13 @@ void SkBenchmark::setupPaint(SkPaint* paint) {
     }
 }
 
+void SkBenchmark::SetResourcePath(const char* resourcePath) {
+    gResourcePath = resourcePath;
+}
+
+SkString SkBenchmark::GetResourcePath() {
+    return SkString(gResourcePath);
+}
 
 ///////////////////////////////////////////////////////////////////////////////
 
index bf28689..00a816c 100644 (file)
@@ -107,9 +107,8 @@ public:
         fClearMask = clearMask;
     }
 
-    static void SetResourcePath(const char* resPath) { gResourcePath.set(resPath); }
-
-    static SkString& GetResourcePath() { return gResourcePath; }
+    static void SetResourcePath(const char*);
+    static SkString GetResourcePath();
 
 protected:
     virtual void setupPaint(SkPaint* paint);
@@ -129,7 +128,7 @@ private:
     bool    fForceFilter;
     SkTriState::State  fDither;
     uint32_t    fOrMask, fClearMask;
-    static  SkString gResourcePath;
+    static const char* gResourcePath;
 
     typedef SkRefCnt INHERITED;
 };
index 3d846bf..b84cf78 100644 (file)
@@ -45,13 +45,14 @@ protected:
     }
 
     virtual void onPreDraw() SK_OVERRIDE {
-        const char* resPath = GetResourcePath().c_str();
-        if (NULL == resPath) {
+        SkString resourcePath = GetResourcePath();
+        if (resourcePath.isEmpty()) {
             fValid = false;
             return;
         }
 
-        SkString fullPath = SkOSPath::SkPathJoin(resPath, fFilename.c_str());
+        SkString fullPath = SkOSPath::SkPathJoin(resourcePath.c_str(),
+                                                 fFilename.c_str());
         SkFILEStream fileStream(fullPath.c_str());
         fValid = fileStream.isValid() && fileStream.getLength() > 0;
         if (fValid) {
index 7e2c279..6233301 100644 (file)
@@ -30,8 +30,7 @@ protected:
 
     virtual void onDraw(SkCanvas* canvas) {
         SkBitmap bm, bm4444;
-        SkString filename = SkOSPath::SkPathJoin(
-                INHERITED::gResourcePath.c_str(), "mandrill_512.png");
+        SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_512.png");
         if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm,
                                         SkBitmap::kARGB_8888_Config,
                                         SkImageDecoder::kDecodePixels_Mode)) {
index cdf8617..ce0aa7d 100644 (file)
@@ -93,8 +93,7 @@ protected:
 
     virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
         SkBitmap bm;
-        SkString filename = SkOSPath::SkPathJoin(
-                INHERITED::gResourcePath.c_str(), "mandrill_128.");
+        SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_128.");
         filename.append(this->fileExtension());
 
         SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str()));
@@ -169,8 +168,7 @@ protected:
     virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
 
         SkBitmap bm;
-        SkString filename = SkOSPath::SkPathJoin(
-                INHERITED::gResourcePath.c_str(), "mandrill_128.pkm");
+        SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_128.pkm");
 
         SkAutoDataUnref fileData(SkData::NewFromFileName(filename.c_str()));
         if (NULL == fileData) {
index bd79c9d..aa643a2 100644 (file)
@@ -28,8 +28,7 @@ public:
 protected:
     virtual void onOnceBeforeDraw() SK_OVERRIDE {
         // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
-        SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str(),
-                                                 "plane.png");
+        SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "plane.png");
         SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
         if (NULL != data.get()) {
             // Create a cache which will boot the pixels out anytime the
index 803874f..8da45c5 100644 (file)
--- a/gm/gm.cpp
+++ b/gm/gm.cpp
@@ -6,9 +6,10 @@
  */
 
 #include "gm.h"
+
 using namespace skiagm;
 
-SkString GM::gResourcePath;
+const char* GM::gResourcePath;
 
 GM::GM() {
     fMode = kGM_Mode;
@@ -17,6 +18,7 @@ GM::GM() {
     fHaveCalledOnceBeforeDraw = false;
     fStarterMatrix.reset();
 }
+
 GM::~GM() {}
 
 void GM::draw(SkCanvas* canvas) {
@@ -64,5 +66,13 @@ 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;
diff --git a/gm/gm.h b/gm/gm.h
index 90de96f..a48976b 100644 (file)
--- a/gm/gm.h
+++ b/gm/gm.h
@@ -96,13 +96,8 @@ namespace skiagm {
         // GM's getISize bounds.
         void drawSizeBounds(SkCanvas*, SkColor);
 
-        static void SetResourcePath(const char* resourcePath) {
-            gResourcePath = resourcePath;
-        }
-
-        static SkString& GetResourcePath() {
-            return gResourcePath;
-        }
+        static void SetResourcePath(const char*);
+        static SkString GetResourcePath();
 
         bool isCanvasDeferred() const { return fCanvasIsDeferred; }
         void setCanvasIsDeferred(bool isDeferred) {
@@ -115,7 +110,7 @@ namespace skiagm {
         }
 
     protected:
-        static SkString gResourcePath;
+        static const char* gResourcePath;
 
         virtual void onOnceBeforeDraw() {}
         virtual void onDraw(SkCanvas*) = 0;
index e57427a..b904d5a 100644 (file)
@@ -1,10 +1,10 @@
-
 /*
  * Copyright 2011 Google Inc.
  *
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #include "Test.h"
 
 #include "SkCommandLineFlags.h"
@@ -41,6 +41,8 @@ void Reporter::endTest(Test* test) {
 
 ///////////////////////////////////////////////////////////////////////////////
 
+const char* Test::gResourcePath;
+
 Test::Test() : fReporter(NULL), fPassed(true) {}
 
 Test::~Test() {
@@ -121,8 +123,9 @@ SkString Test::GetTmpDir() {
     return SkString(tmpDir);
 }
 
-static const char* gResourcePath = NULL;
-void Test::SetResourcePath(const char* resourcePath) { gResourcePath = resourcePath; }
+void Test::SetResourcePath(const char* resourcePath) {
+    gResourcePath = resourcePath;
+}
 
 SkString Test::GetResourcePath() {
     return SkString(gResourcePath);
index 4d2cf2b..90d072e 100644 (file)
@@ -73,6 +73,8 @@ namespace skiatest {
         virtual void onRun(Reporter*) = 0;
 
     private:
+        static const char* gResourcePath;
+
         Reporter*   fReporter;
         SkString    fName;
         bool        fPassed;