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"
|
2014-06-18 21:32:48 +00:00
|
|
|
|
|
|
|
#include "Resources.h"
|
2012-11-29 21:05:37 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkData.h"
|
2013-12-05 18:31:42 +00:00
|
|
|
#include "SkDiscardableMemoryPool.h"
|
|
|
|
#include "SkDiscardablePixelRef.h"
|
2014-05-27 14:14:22 +00:00
|
|
|
#include "SkImageGeneratorPriv.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:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2012-11-29 21:05:37 +00:00
|
|
|
// Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
|
2014-07-01 19:35:49 +00:00
|
|
|
SkString pngFilename = GetResourcePath("plane.png");
|
|
|
|
SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str()));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (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(
|
2014-04-04 16:43:38 +00:00
|
|
|
SkDiscardableMemoryPool::Create(1));
|
2015-09-25 13:56:57 +00:00
|
|
|
SkAssertResult(SkDEPRECATED_InstallDiscardablePixelRef(
|
|
|
|
SkImageGenerator::NewFromEncoded(data),
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr, &fBitmap, pool));
|
2012-11-29 21:05:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-22 19:48:26 +00:00
|
|
|
SkString onShortName() override {
|
2012-11-29 21:05:37 +00:00
|
|
|
return SkString("factory");
|
|
|
|
}
|
|
|
|
|
2015-06-22 19:48:26 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(640, 480);
|
2012-11-29 21:05:37 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 19:48:26 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2012-11-29 21:05:37 +00:00
|
|
|
canvas->drawBitmap(fBitmap, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkBitmap fBitmap;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new FactoryGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
} // namespace skiagm
|