Reland "Clean up Test's resourcePath code."
This relands commit 91359bed48
(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
This commit is contained in:
parent
4d517fdbb1
commit
880914c35c
@ -89,8 +89,9 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
SkData *loadPKM() {
|
SkData *loadPKM() {
|
||||||
SkString filename = SkOSPath::SkPathJoin(
|
SkString resourcePath = GetResourcePath();
|
||||||
INHERITED::GetResourcePath().c_str(), "mandrill_128.pkm");
|
SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(),
|
||||||
|
"mandrill_128.pkm");
|
||||||
|
|
||||||
// Expand the data
|
// Expand the data
|
||||||
SkAutoDataUnref fileData(SkData::NewFromFileName(filename.c_str()));
|
SkAutoDataUnref fileData(SkData::NewFromFileName(filename.c_str()));
|
||||||
|
@ -12,7 +12,7 @@ const char* SkTriState::Name[] = { "default", "true", "false" };
|
|||||||
|
|
||||||
template BenchRegistry* BenchRegistry::gHead;
|
template BenchRegistry* BenchRegistry::gHead;
|
||||||
|
|
||||||
SkString SkBenchmark::gResourcePath;
|
const char* SkBenchmark::gResourcePath;
|
||||||
|
|
||||||
SkBenchmark::SkBenchmark() {
|
SkBenchmark::SkBenchmark() {
|
||||||
fForceAlpha = 0xFF;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -107,9 +107,8 @@ public:
|
|||||||
fClearMask = clearMask;
|
fClearMask = clearMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetResourcePath(const char* resPath) { gResourcePath.set(resPath); }
|
static void SetResourcePath(const char*);
|
||||||
|
static SkString GetResourcePath();
|
||||||
static SkString& GetResourcePath() { return gResourcePath; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setupPaint(SkPaint* paint);
|
virtual void setupPaint(SkPaint* paint);
|
||||||
@ -129,7 +128,7 @@ private:
|
|||||||
bool fForceFilter;
|
bool fForceFilter;
|
||||||
SkTriState::State fDither;
|
SkTriState::State fDither;
|
||||||
uint32_t fOrMask, fClearMask;
|
uint32_t fOrMask, fClearMask;
|
||||||
static SkString gResourcePath;
|
static const char* gResourcePath;
|
||||||
|
|
||||||
typedef SkRefCnt INHERITED;
|
typedef SkRefCnt INHERITED;
|
||||||
};
|
};
|
||||||
|
@ -45,13 +45,14 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void onPreDraw() SK_OVERRIDE {
|
virtual void onPreDraw() SK_OVERRIDE {
|
||||||
const char* resPath = GetResourcePath().c_str();
|
SkString resourcePath = GetResourcePath();
|
||||||
if (NULL == resPath) {
|
if (resourcePath.isEmpty()) {
|
||||||
fValid = false;
|
fValid = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkString fullPath = SkOSPath::SkPathJoin(resPath, fFilename.c_str());
|
SkString fullPath = SkOSPath::SkPathJoin(resourcePath.c_str(),
|
||||||
|
fFilename.c_str());
|
||||||
SkFILEStream fileStream(fullPath.c_str());
|
SkFILEStream fileStream(fullPath.c_str());
|
||||||
fValid = fileStream.isValid() && fileStream.getLength() > 0;
|
fValid = fileStream.isValid() && fileStream.getLength() > 0;
|
||||||
if (fValid) {
|
if (fValid) {
|
||||||
|
@ -30,8 +30,7 @@ protected:
|
|||||||
|
|
||||||
virtual void onDraw(SkCanvas* canvas) {
|
virtual void onDraw(SkCanvas* canvas) {
|
||||||
SkBitmap bm, bm4444;
|
SkBitmap bm, bm4444;
|
||||||
SkString filename = SkOSPath::SkPathJoin(
|
SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_512.png");
|
||||||
INHERITED::gResourcePath.c_str(), "mandrill_512.png");
|
|
||||||
if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm,
|
if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm,
|
||||||
SkBitmap::kARGB_8888_Config,
|
SkBitmap::kARGB_8888_Config,
|
||||||
SkImageDecoder::kDecodePixels_Mode)) {
|
SkImageDecoder::kDecodePixels_Mode)) {
|
||||||
|
@ -93,8 +93,7 @@ protected:
|
|||||||
|
|
||||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||||
SkBitmap bm;
|
SkBitmap bm;
|
||||||
SkString filename = SkOSPath::SkPathJoin(
|
SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_128.");
|
||||||
INHERITED::gResourcePath.c_str(), "mandrill_128.");
|
|
||||||
filename.append(this->fileExtension());
|
filename.append(this->fileExtension());
|
||||||
|
|
||||||
SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str()));
|
SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str()));
|
||||||
@ -169,8 +168,7 @@ protected:
|
|||||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||||
|
|
||||||
SkBitmap bm;
|
SkBitmap bm;
|
||||||
SkString filename = SkOSPath::SkPathJoin(
|
SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_128.pkm");
|
||||||
INHERITED::gResourcePath.c_str(), "mandrill_128.pkm");
|
|
||||||
|
|
||||||
SkAutoDataUnref fileData(SkData::NewFromFileName(filename.c_str()));
|
SkAutoDataUnref fileData(SkData::NewFromFileName(filename.c_str()));
|
||||||
if (NULL == fileData) {
|
if (NULL == fileData) {
|
||||||
|
@ -28,8 +28,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void onOnceBeforeDraw() SK_OVERRIDE {
|
virtual void onOnceBeforeDraw() SK_OVERRIDE {
|
||||||
// Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
|
// Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
|
||||||
SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str(),
|
SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "plane.png");
|
||||||
"plane.png");
|
|
||||||
SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
|
SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
|
||||||
if (NULL != data.get()) {
|
if (NULL != data.get()) {
|
||||||
// Create a cache which will boot the pixels out anytime the
|
// Create a cache which will boot the pixels out anytime the
|
||||||
|
12
gm/gm.cpp
12
gm/gm.cpp
@ -6,9 +6,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gm.h"
|
#include "gm.h"
|
||||||
|
|
||||||
using namespace skiagm;
|
using namespace skiagm;
|
||||||
|
|
||||||
SkString GM::gResourcePath;
|
const char* GM::gResourcePath;
|
||||||
|
|
||||||
GM::GM() {
|
GM::GM() {
|
||||||
fMode = kGM_Mode;
|
fMode = kGM_Mode;
|
||||||
@ -17,6 +18,7 @@ GM::GM() {
|
|||||||
fHaveCalledOnceBeforeDraw = false;
|
fHaveCalledOnceBeforeDraw = false;
|
||||||
fStarterMatrix.reset();
|
fStarterMatrix.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
GM::~GM() {}
|
GM::~GM() {}
|
||||||
|
|
||||||
void GM::draw(SkCanvas* canvas) {
|
void GM::draw(SkCanvas* canvas) {
|
||||||
@ -64,5 +66,13 @@ void GM::drawSizeBounds(SkCanvas* canvas, SkColor color) {
|
|||||||
canvas->drawRect(r, paint);
|
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
|
// need to explicitly declare this, or we get some weird infinite loop llist
|
||||||
template GMRegistry* SkTRegistry<GM*(*)(void*)>::gHead;
|
template GMRegistry* SkTRegistry<GM*(*)(void*)>::gHead;
|
||||||
|
11
gm/gm.h
11
gm/gm.h
@ -96,13 +96,8 @@ namespace skiagm {
|
|||||||
// GM's getISize bounds.
|
// GM's getISize bounds.
|
||||||
void drawSizeBounds(SkCanvas*, SkColor);
|
void drawSizeBounds(SkCanvas*, SkColor);
|
||||||
|
|
||||||
static void SetResourcePath(const char* resourcePath) {
|
static void SetResourcePath(const char*);
|
||||||
gResourcePath = resourcePath;
|
static SkString GetResourcePath();
|
||||||
}
|
|
||||||
|
|
||||||
static SkString& GetResourcePath() {
|
|
||||||
return gResourcePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isCanvasDeferred() const { return fCanvasIsDeferred; }
|
bool isCanvasDeferred() const { return fCanvasIsDeferred; }
|
||||||
void setCanvasIsDeferred(bool isDeferred) {
|
void setCanvasIsDeferred(bool isDeferred) {
|
||||||
@ -115,7 +110,7 @@ namespace skiagm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static SkString gResourcePath;
|
static const char* gResourcePath;
|
||||||
|
|
||||||
virtual void onOnceBeforeDraw() {}
|
virtual void onOnceBeforeDraw() {}
|
||||||
virtual void onDraw(SkCanvas*) = 0;
|
virtual void onDraw(SkCanvas*) = 0;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Google Inc.
|
* Copyright 2011 Google Inc.
|
||||||
*
|
*
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Test.h"
|
#include "Test.h"
|
||||||
|
|
||||||
#include "SkCommandLineFlags.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() : fReporter(NULL), fPassed(true) {}
|
||||||
|
|
||||||
Test::~Test() {
|
Test::~Test() {
|
||||||
@ -121,8 +123,9 @@ SkString Test::GetTmpDir() {
|
|||||||
return SkString(tmpDir);
|
return SkString(tmpDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* gResourcePath = NULL;
|
void Test::SetResourcePath(const char* resourcePath) {
|
||||||
void Test::SetResourcePath(const char* resourcePath) { gResourcePath = resourcePath; }
|
gResourcePath = resourcePath;
|
||||||
|
}
|
||||||
|
|
||||||
SkString Test::GetResourcePath() {
|
SkString Test::GetResourcePath() {
|
||||||
return SkString(gResourcePath);
|
return SkString(gResourcePath);
|
||||||
|
@ -73,6 +73,8 @@ namespace skiatest {
|
|||||||
virtual void onRun(Reporter*) = 0;
|
virtual void onRun(Reporter*) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static const char* gResourcePath;
|
||||||
|
|
||||||
Reporter* fReporter;
|
Reporter* fReporter;
|
||||||
SkString fName;
|
SkString fName;
|
||||||
bool fPassed;
|
bool fPassed;
|
||||||
|
Loading…
Reference in New Issue
Block a user