91359bed48
Reason for revert: Some benchmarks are written in a way that makes this change unsafe (e.g. const char* resPath = GetResourcePath().c_str(); in SkipZeroesBench) and Valgrind and ASAN caught that. We can try again after a more careful cleanup of GetResourcePath(). Original issue's description: > Clean up resourcePath code. > > 1) Make the implementation of SetResourcePath/GetResourcePath of GM and SkBenchmark match with the one in Test. > 2) Make gResourcePath a static pointer to const char and move it inside the classes. > > BUG=None > TEST=make tests && out/Debug/tests > make gm && out/Debug/gm > make bench && out/Debug/bench > R=mtklein@google.com > > Committed: https://skia.googlesource.com/skia/+/52e4f413ffe2d281f9e90ff2147db08083ffcba7 R=tfarina@chromium.org TBR=tfarina@chromium.org NOTREECHECKS=true NOTRY=true BUG=None Author: mtklein@google.com Review URL: https://codereview.chromium.org/320733002
75 lines
2.1 KiB
C++
75 lines
2.1 KiB
C++
/*
|
|
* Copyright 2012 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "gm.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkData.h"
|
|
#include "SkDecodingImageGenerator.h"
|
|
#include "SkDiscardableMemoryPool.h"
|
|
#include "SkDiscardablePixelRef.h"
|
|
#include "SkImageDecoder.h"
|
|
#include "SkImageGeneratorPriv.h"
|
|
#include "SkOSFile.h"
|
|
#include "SkStream.h"
|
|
|
|
namespace skiagm {
|
|
|
|
/**
|
|
* Draw a PNG created by SkBitmapFactory.
|
|
*/
|
|
class FactoryGM : public GM {
|
|
public:
|
|
FactoryGM() {}
|
|
|
|
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");
|
|
SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
|
|
if (NULL != data.get()) {
|
|
// Create a cache which will boot the pixels out anytime the
|
|
// bitmap is unlocked.
|
|
SkAutoTUnref<SkDiscardableMemoryPool> pool(
|
|
SkDiscardableMemoryPool::Create(1));
|
|
SkAssertResult(SkInstallDiscardablePixelRef(
|
|
SkDecodingImageGenerator::Create(
|
|
data, SkDecodingImageGenerator::Options()),
|
|
&fBitmap, pool));
|
|
}
|
|
}
|
|
|
|
virtual SkString onShortName() {
|
|
return SkString("factory");
|
|
}
|
|
|
|
virtual SkISize onISize() {
|
|
return make_isize(640, 480);
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
canvas->drawBitmap(fBitmap, 0, 0);
|
|
}
|
|
|
|
// Skip cross process pipe due to https://code.google.com/p/skia/issues/detail?id=1520
|
|
virtual uint32_t onGetFlags() const {
|
|
return INHERITED::onGetFlags() | kSkipPipeCrossProcess_Flag;
|
|
}
|
|
|
|
private:
|
|
SkBitmap fBitmap;
|
|
|
|
typedef GM INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
static GM* MyFactory(void*) { return new FactoryGM; }
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
} // namespace skiagm
|