aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
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 /samplecode
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
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleApp.cpp40
-rw-r--r--samplecode/SamplePicture.cpp23
-rw-r--r--samplecode/SampleSubpixelTranslate.cpp15
-rw-r--r--samplecode/SampleUnpremul.cpp4
4 files changed, 38 insertions, 44 deletions
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);