2012-11-29 21:05:37 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2013-12-05 18:31:42 +00:00
|
|
|
#include "SkDecodingImageGenerator.h"
|
|
|
|
#include "SkDiscardableMemoryPool.h"
|
|
|
|
#include "SkDiscardablePixelRef.h"
|
2013-02-22 21:38:35 +00:00
|
|
|
#include "SkImageDecoder.h"
|
2013-05-28 16:45:07 +00:00
|
|
|
#include "SkOSFile.h"
|
2012-11-29 21:05:37 +00:00
|
|
|
#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
|
2013-05-28 16:45:07 +00:00
|
|
|
SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath.c_str(),
|
|
|
|
"plane.png");
|
2013-12-05 18:31:42 +00:00
|
|
|
SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
|
|
|
|
if (NULL != data.get()) {
|
2013-02-22 21:38:35 +00:00
|
|
|
// Create a cache which will boot the pixels out anytime the
|
|
|
|
// bitmap is unlocked.
|
2013-12-05 18:31:42 +00:00
|
|
|
SkAutoTUnref<SkDiscardableMemoryPool> pool(
|
|
|
|
SkNEW_ARGS(SkDiscardableMemoryPool, (1)));
|
|
|
|
SkAssertResult(SkDecodingImageGenerator::Install(data,
|
|
|
|
&fBitmap, pool));
|
2012-11-29 21:05:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkString onShortName() {
|
|
|
|
return SkString("factory");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() {
|
|
|
|
return make_isize(640, 480);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
canvas->drawBitmap(fBitmap, 0, 0);
|
|
|
|
}
|
|
|
|
|
2013-08-16 19:18:12 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2012-11-29 21:05:37 +00:00
|
|
|
private:
|
|
|
|
SkBitmap fBitmap;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new FactoryGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|