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");
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data(SkData::MakeFromFileName(pngFilename.c_str()));
|
|
|
|
if (data) {
|
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));
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
SkDEPRECATED_InstallDiscardablePixelRef(SkImageGenerator::NewFromEncoded(data.get()),
|
|
|
|
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
|