2015-03-25 14:11:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
#ifndef DMSrcSink_DEFINED
|
|
|
|
#define DMSrcSink_DEFINED
|
|
|
|
|
|
|
|
#include "DMGpuSupport.h"
|
|
|
|
#include "SkBBHFactory.h"
|
|
|
|
#include "SkBBoxHierarchy.h"
|
|
|
|
#include "SkBitmap.h"
|
2015-11-06 16:56:32 +00:00
|
|
|
#include "SkBitmapRegionDecoder.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkCanvas.h"
|
2018-03-09 14:01:53 +00:00
|
|
|
#include "SkCommonFlagsConfig.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkData.h"
|
2017-04-03 20:06:42 +00:00
|
|
|
#include "SkMultiPictureDocument.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "gm.h"
|
|
|
|
|
2017-02-18 21:50:45 +00:00
|
|
|
//#define TEST_VIA_SVG
|
|
|
|
|
2018-01-16 22:04:30 +00:00
|
|
|
namespace skottie { class Animation; }
|
2017-12-31 16:08:42 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
namespace DM {
|
|
|
|
|
|
|
|
// This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...).
|
|
|
|
struct ImplicitString : public SkString {
|
|
|
|
template <typename T>
|
|
|
|
ImplicitString(const T& s) : SkString(s) {}
|
2015-09-01 21:57:57 +00:00
|
|
|
ImplicitString() : SkString("") {}
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
typedef ImplicitString Name;
|
2015-01-30 19:42:31 +00:00
|
|
|
typedef ImplicitString Path;
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-03-05 16:40:28 +00:00
|
|
|
class Error {
|
|
|
|
public:
|
|
|
|
Error(const SkString& s) : fMsg(s), fFatal(!this->isEmpty()) {}
|
|
|
|
Error(const char* s) : fMsg(s), fFatal(!this->isEmpty()) {}
|
|
|
|
|
|
|
|
Error(const Error&) = default;
|
|
|
|
Error& operator=(const Error&) = default;
|
|
|
|
|
|
|
|
static Error Nonfatal(const SkString& s) { return Nonfatal(s.c_str()); }
|
|
|
|
static Error Nonfatal(const char* s) {
|
|
|
|
Error e(s);
|
|
|
|
e.fFatal = false;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* c_str() const { return fMsg.c_str(); }
|
|
|
|
bool isEmpty() const { return fMsg.isEmpty(); }
|
|
|
|
bool isFatal() const { return fFatal; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fMsg;
|
|
|
|
bool fFatal;
|
|
|
|
};
|
|
|
|
|
2015-07-31 13:43:04 +00:00
|
|
|
struct SinkFlags {
|
2017-03-07 14:08:36 +00:00
|
|
|
enum Type { kNull, kGPU, kVector, kRaster } type;
|
|
|
|
enum Approach { kDirect, kIndirect } approach;
|
|
|
|
enum Multisampled { kNotMultisampled, kMultisampled } multisampled;
|
|
|
|
SinkFlags(Type t, Approach a, Multisampled ms = kNotMultisampled)
|
|
|
|
: type(t), approach(a), multisampled(ms) {}
|
2015-07-31 13:43:04 +00:00
|
|
|
};
|
2015-07-29 13:37:28 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
struct Src {
|
|
|
|
virtual ~Src() {}
|
|
|
|
virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0;
|
|
|
|
virtual SkISize size() const = 0;
|
|
|
|
virtual Name name() const = 0;
|
2015-05-27 20:23:23 +00:00
|
|
|
virtual void modifyGrContextOptions(GrContextOptions* options) const {}
|
2015-07-31 13:43:04 +00:00
|
|
|
virtual bool veto(SinkFlags) const { return false; }
|
2016-02-08 20:39:59 +00:00
|
|
|
|
2016-06-02 19:41:14 +00:00
|
|
|
virtual int pageCount() const { return 1; }
|
|
|
|
virtual Error SK_WARN_UNUSED_RESULT draw(int, SkCanvas* canvas) const {
|
|
|
|
return this->draw(canvas);
|
|
|
|
}
|
|
|
|
virtual SkISize size(int) const { return this->size(); }
|
2016-02-08 20:39:59 +00:00
|
|
|
// Force Tasks using this Src to run on the main thread?
|
|
|
|
virtual bool serial() const { return false; }
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Sink {
|
|
|
|
virtual ~Sink() {}
|
2015-02-03 02:26:03 +00:00
|
|
|
// You may write to either the bitmap or stream. If you write to log, we'll print that out.
|
|
|
|
virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log)
|
|
|
|
const = 0;
|
2016-02-08 20:39:59 +00:00
|
|
|
|
|
|
|
// Force Tasks using this Sink to run on the main thread?
|
|
|
|
virtual bool serial() const { return false; }
|
2015-01-15 18:56:12 +00:00
|
|
|
|
|
|
|
// File extension for the content draw() outputs, e.g. "png", "pdf".
|
|
|
|
virtual const char* fileExtension() const = 0;
|
2015-07-31 13:43:04 +00:00
|
|
|
|
|
|
|
virtual SinkFlags flags() const = 0;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
|
|
|
class GMSrc : public Src {
|
|
|
|
public:
|
|
|
|
explicit GMSrc(skiagm::GMRegistry::Factory);
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
Name name() const override;
|
2015-05-27 20:23:23 +00:00
|
|
|
void modifyGrContextOptions(GrContextOptions* options) const override;
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
|
|
|
skiagm::GMRegistry::Factory fFactory;
|
|
|
|
};
|
|
|
|
|
2015-03-19 13:03:39 +00:00
|
|
|
class CodecSrc : public Src {
|
|
|
|
public:
|
2015-03-25 20:48:49 +00:00
|
|
|
enum Mode {
|
2015-09-01 21:57:57 +00:00
|
|
|
kCodec_Mode,
|
2016-01-13 17:31:39 +00:00
|
|
|
// We choose to test only one mode with zero initialized memory.
|
|
|
|
// This will exercise all of the interesting cases in SkSwizzler
|
|
|
|
// without doubling the size of our test suite.
|
|
|
|
kCodecZeroInit_Mode,
|
2015-03-25 20:48:49 +00:00
|
|
|
kScanline_Mode,
|
2015-06-11 21:27:27 +00:00
|
|
|
kStripe_Mode, // Tests the skipping of scanlines
|
2016-02-22 20:27:46 +00:00
|
|
|
kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization
|
2015-07-22 14:16:20 +00:00
|
|
|
kSubset_Mode, // For codecs that support subsets directly.
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
kAnimated_Mode, // For codecs that support animation.
|
2015-03-25 20:48:49 +00:00
|
|
|
};
|
2015-04-09 19:43:10 +00:00
|
|
|
enum DstColorType {
|
|
|
|
kGetFromCanvas_DstColorType,
|
|
|
|
kGrayscale_Always_DstColorType,
|
2016-04-22 23:27:24 +00:00
|
|
|
kNonNative8888_Always_DstColorType,
|
2015-04-09 19:43:10 +00:00
|
|
|
};
|
2016-02-03 17:42:42 +00:00
|
|
|
CodecSrc(Path, Mode, DstColorType, SkAlphaType, float);
|
2015-03-19 13:03:39 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
Name name() const override;
|
2015-07-31 13:43:04 +00:00
|
|
|
bool veto(SinkFlags) const override;
|
2016-02-08 23:09:48 +00:00
|
|
|
bool serial() const override { return fRunSerially; }
|
2015-03-19 13:03:39 +00:00
|
|
|
private:
|
2015-09-01 21:57:57 +00:00
|
|
|
Path fPath;
|
|
|
|
Mode fMode;
|
|
|
|
DstColorType fDstColorType;
|
2016-02-03 17:42:42 +00:00
|
|
|
SkAlphaType fDstAlphaType;
|
2015-09-01 21:57:57 +00:00
|
|
|
float fScale;
|
2016-02-08 23:09:48 +00:00
|
|
|
bool fRunSerially;
|
2015-03-19 13:03:39 +00:00
|
|
|
};
|
|
|
|
|
2015-10-21 17:27:10 +00:00
|
|
|
class AndroidCodecSrc : public Src {
|
|
|
|
public:
|
2016-05-16 16:04:13 +00:00
|
|
|
AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize);
|
2015-10-21 17:27:10 +00:00
|
|
|
|
|
|
|
Error draw(SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
Name name() const override;
|
|
|
|
bool veto(SinkFlags) const override;
|
2016-02-08 23:09:48 +00:00
|
|
|
bool serial() const override { return fRunSerially; }
|
2015-10-21 17:27:10 +00:00
|
|
|
private:
|
|
|
|
Path fPath;
|
|
|
|
CodecSrc::DstColorType fDstColorType;
|
2016-02-03 17:42:42 +00:00
|
|
|
SkAlphaType fDstAlphaType;
|
2015-10-21 17:27:10 +00:00
|
|
|
int fSampleSize;
|
2016-02-08 23:09:48 +00:00
|
|
|
bool fRunSerially;
|
2015-10-21 17:27:10 +00:00
|
|
|
};
|
|
|
|
|
2015-09-08 22:35:32 +00:00
|
|
|
// Allows for testing of various implementations of Android's BitmapRegionDecoder
|
|
|
|
class BRDSrc : public Src {
|
|
|
|
public:
|
|
|
|
enum Mode {
|
|
|
|
// Decode the entire image as one region.
|
|
|
|
kFullImage_Mode,
|
|
|
|
// Splits the image into multiple regions using a divisor and decodes the regions
|
|
|
|
// separately. Also, this test adds a border of a few pixels to each of the regions
|
|
|
|
// that it is decoding. This tests the behavior when a client asks for a region that
|
|
|
|
// does not fully fit in the image.
|
|
|
|
kDivisor_Mode,
|
|
|
|
};
|
|
|
|
|
2016-05-18 13:23:57 +00:00
|
|
|
BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t);
|
2015-09-08 22:35:32 +00:00
|
|
|
|
|
|
|
Error draw(SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
Name name() const override;
|
|
|
|
bool veto(SinkFlags) const override;
|
|
|
|
private:
|
|
|
|
Path fPath;
|
|
|
|
Mode fMode;
|
|
|
|
CodecSrc::DstColorType fDstColorType;
|
|
|
|
uint32_t fSampleSize;
|
|
|
|
};
|
2015-03-19 13:03:39 +00:00
|
|
|
|
2016-03-09 22:20:58 +00:00
|
|
|
class ImageGenSrc : public Src {
|
|
|
|
public:
|
|
|
|
enum Mode {
|
|
|
|
kCodec_Mode, // Use CodecImageGenerator
|
|
|
|
kPlatform_Mode, // Uses CG or WIC
|
|
|
|
};
|
|
|
|
ImageGenSrc(Path, Mode, SkAlphaType, bool);
|
|
|
|
|
|
|
|
Error draw(SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
Name name() const override;
|
|
|
|
bool veto(SinkFlags) const override;
|
|
|
|
bool serial() const override { return fRunSerially; }
|
|
|
|
private:
|
|
|
|
Path fPath;
|
|
|
|
Mode fMode;
|
|
|
|
SkAlphaType fDstAlphaType;
|
|
|
|
bool fIsGpu;
|
|
|
|
bool fRunSerially;
|
|
|
|
};
|
|
|
|
|
2016-04-29 16:38:40 +00:00
|
|
|
class ColorCodecSrc : public Src {
|
|
|
|
public:
|
|
|
|
enum Mode {
|
|
|
|
// Mimic legacy behavior and apply no color correction.
|
|
|
|
kBaseline_Mode,
|
2016-05-23 17:21:17 +00:00
|
|
|
|
|
|
|
// Color correct images into a specific dst color space. If you happen to have this
|
|
|
|
// monitor, you're in luck! The unmarked outputs of this test should display
|
|
|
|
// correctly on this monitor in the Chrome browser. If not, it's useful to know
|
|
|
|
// that this monitor has a profile that is fairly similar to Adobe RGB.
|
|
|
|
kDst_HPZR30w_Mode,
|
2016-06-01 21:47:18 +00:00
|
|
|
|
2016-06-20 13:07:45 +00:00
|
|
|
kDst_sRGB_Mode,
|
2016-04-29 16:38:40 +00:00
|
|
|
};
|
|
|
|
|
2016-07-15 20:54:38 +00:00
|
|
|
ColorCodecSrc(Path, Mode, SkColorType);
|
2016-04-29 16:38:40 +00:00
|
|
|
|
|
|
|
Error draw(SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
Name name() const override;
|
|
|
|
bool veto(SinkFlags) const override;
|
|
|
|
private:
|
|
|
|
Path fPath;
|
|
|
|
Mode fMode;
|
2016-07-15 20:54:38 +00:00
|
|
|
SkColorType fColorType;
|
2016-04-29 16:38:40 +00:00
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
class SKPSrc : public Src {
|
|
|
|
public:
|
2015-01-30 19:42:31 +00:00
|
|
|
explicit SKPSrc(Path path);
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
Name name() const override;
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
2015-01-30 19:42:31 +00:00
|
|
|
Path fPath;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
2017-08-30 16:06:35 +00:00
|
|
|
|
2017-12-31 22:02:26 +00:00
|
|
|
#if !defined(SK_BUILD_FOR_GOOGLE3)
|
2018-01-16 22:04:30 +00:00
|
|
|
class SkottieSrc final : public Src {
|
2017-12-31 16:08:42 +00:00
|
|
|
public:
|
2018-01-16 22:04:30 +00:00
|
|
|
explicit SkottieSrc(Path path);
|
2017-12-31 16:08:42 +00:00
|
|
|
|
|
|
|
Error draw(SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
Name name() const override;
|
|
|
|
bool veto(SinkFlags) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Generates a kTileCount x kTileCount filmstrip with evenly distributed frames.
|
2018-02-23 16:10:22 +00:00
|
|
|
static constexpr int kTileCount = 5;
|
2017-12-31 16:08:42 +00:00
|
|
|
|
2018-02-23 16:10:22 +00:00
|
|
|
Name fName;
|
|
|
|
SkISize fTileSize = SkISize::MakeEmpty();
|
|
|
|
sk_sp<skottie::Animation> fAnimation;
|
2017-12-31 16:08:42 +00:00
|
|
|
};
|
2017-12-31 22:02:26 +00:00
|
|
|
#endif
|
2017-12-31 16:08:42 +00:00
|
|
|
|
2016-08-04 02:53:36 +00:00
|
|
|
#if defined(SK_XML)
|
2016-09-17 14:26:26 +00:00
|
|
|
} // namespace DM
|
|
|
|
|
|
|
|
class SkSVGDOM;
|
|
|
|
|
|
|
|
namespace DM {
|
|
|
|
|
2016-08-04 02:53:36 +00:00
|
|
|
class SVGSrc : public Src {
|
|
|
|
public:
|
|
|
|
explicit SVGSrc(Path path);
|
|
|
|
|
|
|
|
Error draw(SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
Name name() const override;
|
2016-08-16 21:23:29 +00:00
|
|
|
bool veto(SinkFlags) const override;
|
2016-08-04 02:53:36 +00:00
|
|
|
|
|
|
|
private:
|
2016-11-08 15:13:45 +00:00
|
|
|
Name fName;
|
|
|
|
sk_sp<SkSVGDOM> fDom;
|
|
|
|
SkScalar fScale;
|
2016-08-04 02:53:36 +00:00
|
|
|
|
|
|
|
typedef Src INHERITED;
|
|
|
|
};
|
|
|
|
#endif // SK_XML
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2016-06-02 19:41:14 +00:00
|
|
|
class MSKPSrc : public Src {
|
|
|
|
public:
|
|
|
|
explicit MSKPSrc(Path path);
|
|
|
|
|
|
|
|
int pageCount() const override;
|
|
|
|
Error draw(SkCanvas* c) const override;
|
|
|
|
Error draw(int, SkCanvas*) const override;
|
|
|
|
SkISize size() const override;
|
|
|
|
SkISize size(int) const override;
|
|
|
|
Name name() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Path fPath;
|
2017-04-03 20:06:42 +00:00
|
|
|
mutable SkTArray<SkDocumentPage> fPages;
|
2016-06-02 19:41:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-02-13 23:11:10 +00:00
|
|
|
class NullSink : public Sink {
|
|
|
|
public:
|
|
|
|
NullSink() {}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
const char* fileExtension() const override { return ""; }
|
2015-07-31 13:43:04 +00:00
|
|
|
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; }
|
2015-02-13 23:11:10 +00:00
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
class GPUSink : public Sink {
|
|
|
|
public:
|
2016-04-05 18:06:27 +00:00
|
|
|
GPUSink(sk_gpu_test::GrContextFactory::ContextType,
|
2018-03-09 14:01:53 +00:00
|
|
|
sk_gpu_test::GrContextFactory::ContextOverrides,
|
|
|
|
SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText,
|
2017-07-17 15:31:31 +00:00
|
|
|
SkColorType colorType, SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace,
|
2017-08-21 20:48:46 +00:00
|
|
|
bool threaded, const GrContextOptions& grCtxOptions);
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
2017-08-30 14:02:10 +00:00
|
|
|
Error onDraw(const Src&, SkBitmap*, SkWStream*, SkString*,
|
|
|
|
const GrContextOptions& baseOptions) const;
|
|
|
|
|
2018-03-09 18:17:30 +00:00
|
|
|
sk_gpu_test::GrContextFactory::ContextType contextType() const { return fContextType; }
|
|
|
|
const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() {
|
|
|
|
return fContextOverrides;
|
|
|
|
}
|
|
|
|
SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; }
|
|
|
|
bool useDIText() const { return fUseDIText; }
|
2016-02-08 20:39:59 +00:00
|
|
|
bool serial() const override { return !fThreaded; }
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* fileExtension() const override { return "png"; }
|
2017-03-07 14:08:36 +00:00
|
|
|
SinkFlags flags() const override {
|
2018-02-03 01:32:49 +00:00
|
|
|
SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled
|
2017-03-08 16:38:45 +00:00
|
|
|
: SinkFlags::kNotMultisampled;
|
|
|
|
return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms };
|
2017-03-07 14:08:36 +00:00
|
|
|
}
|
2017-08-30 14:02:10 +00:00
|
|
|
const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; }
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
2017-02-21 19:36:05 +00:00
|
|
|
sk_gpu_test::GrContextFactory::ContextType fContextType;
|
|
|
|
sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides;
|
2018-03-09 14:01:53 +00:00
|
|
|
SkCommandLineConfigGpu::SurfType fSurfType;
|
2017-02-21 19:36:05 +00:00
|
|
|
int fSampleCount;
|
|
|
|
bool fUseDIText;
|
|
|
|
SkColorType fColorType;
|
2017-07-17 15:31:31 +00:00
|
|
|
SkAlphaType fAlphaType;
|
2017-02-21 19:36:05 +00:00
|
|
|
sk_sp<SkColorSpace> fColorSpace;
|
|
|
|
bool fThreaded;
|
2017-08-21 20:48:46 +00:00
|
|
|
GrContextOptions fBaseContextOptions;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
2017-08-30 14:02:10 +00:00
|
|
|
class GPUThreadTestingSink : public GPUSink {
|
|
|
|
public:
|
|
|
|
GPUThreadTestingSink(sk_gpu_test::GrContextFactory::ContextType,
|
2018-03-09 14:01:53 +00:00
|
|
|
sk_gpu_test::GrContextFactory::ContextOverrides,
|
|
|
|
SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText,
|
2017-08-30 14:02:10 +00:00
|
|
|
SkColorType colorType, SkAlphaType alphaType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace, bool threaded,
|
|
|
|
const GrContextOptions& grCtxOptions);
|
|
|
|
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
|
2017-08-30 18:50:22 +00:00
|
|
|
const char* fileExtension() const override {
|
|
|
|
// Suppress writing out results from this config - we just want to do our matching test
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-08-30 14:02:10 +00:00
|
|
|
private:
|
|
|
|
std::unique_ptr<SkExecutor> fExecutor;
|
|
|
|
|
|
|
|
typedef GPUSink INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
class PDFSink : public Sink {
|
|
|
|
public:
|
2017-07-20 19:36:00 +00:00
|
|
|
PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {}
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
const char* fileExtension() const override { return "pdf"; }
|
2015-07-31 13:43:04 +00:00
|
|
|
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
|
2016-04-27 14:45:18 +00:00
|
|
|
bool fPDFA;
|
2017-07-20 19:36:00 +00:00
|
|
|
SkScalar fRasterDpi;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
2015-03-03 17:13:09 +00:00
|
|
|
class XPSSink : public Sink {
|
|
|
|
public:
|
|
|
|
XPSSink();
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
const char* fileExtension() const override { return "xps"; }
|
2015-07-31 13:43:04 +00:00
|
|
|
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
|
2015-03-03 17:13:09 +00:00
|
|
|
};
|
|
|
|
|
2016-09-13 15:09:45 +00:00
|
|
|
class PipeSink : public Sink {
|
|
|
|
public:
|
|
|
|
PipeSink();
|
2017-03-10 14:55:51 +00:00
|
|
|
|
2016-09-13 15:09:45 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
const char* fileExtension() const override { return "skpipe"; }
|
|
|
|
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
|
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
class RasterSink : public Sink {
|
|
|
|
public:
|
2016-06-16 20:03:24 +00:00
|
|
|
explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
const char* fileExtension() const override { return "png"; }
|
2015-07-31 13:43:04 +00:00
|
|
|
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
|
2018-02-23 06:13:36 +00:00
|
|
|
protected:
|
|
|
|
void allocPixels(const Src& src, SkBitmap*) const;
|
|
|
|
|
2016-06-16 20:03:24 +00:00
|
|
|
SkColorType fColorType;
|
|
|
|
sk_sp<SkColorSpace> fColorSpace;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
2018-02-23 06:13:36 +00:00
|
|
|
class ThreadedSink : public RasterSink {
|
|
|
|
public:
|
|
|
|
explicit ThreadedSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<SkExecutor> fExecutor;
|
|
|
|
};
|
|
|
|
|
2015-01-28 19:35:18 +00:00
|
|
|
class SKPSink : public Sink {
|
|
|
|
public:
|
|
|
|
SKPSink();
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
const char* fileExtension() const override { return "skp"; }
|
2015-07-31 13:43:04 +00:00
|
|
|
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
|
2015-01-28 19:35:18 +00:00
|
|
|
};
|
|
|
|
|
2016-10-25 14:33:27 +00:00
|
|
|
class DebugSink : public Sink {
|
|
|
|
public:
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
const char* fileExtension() const override { return "json"; }
|
|
|
|
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
|
|
|
|
};
|
|
|
|
|
2015-02-01 04:00:58 +00:00
|
|
|
class SVGSink : public Sink {
|
|
|
|
public:
|
2018-03-02 21:54:21 +00:00
|
|
|
SVGSink(int pageIndex = 0);
|
2015-02-01 04:00:58 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
const char* fileExtension() const override { return "svg"; }
|
2015-07-31 13:43:04 +00:00
|
|
|
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
|
2018-03-02 21:54:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int fPageIndex;
|
2015-02-01 04:00:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-05-06 14:54:07 +00:00
|
|
|
class Via : public Sink {
|
2015-01-15 18:56:12 +00:00
|
|
|
public:
|
2015-12-10 23:14:27 +00:00
|
|
|
explicit Via(Sink* sink) : fSink(sink) {}
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* fileExtension() const override { return fSink->fileExtension(); }
|
2016-02-08 20:39:59 +00:00
|
|
|
bool serial() const override { return fSink->serial(); }
|
2015-07-31 13:43:04 +00:00
|
|
|
SinkFlags flags() const override {
|
|
|
|
SinkFlags flags = fSink->flags();
|
|
|
|
flags.approach = SinkFlags::kIndirect;
|
|
|
|
return flags;
|
|
|
|
}
|
2015-05-06 14:54:07 +00:00
|
|
|
protected:
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<Sink> fSink;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
2015-05-06 14:54:07 +00:00
|
|
|
class ViaMatrix : public Via {
|
2015-02-17 19:13:33 +00:00
|
|
|
public:
|
2015-12-10 23:14:27 +00:00
|
|
|
ViaMatrix(SkMatrix, Sink*);
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
2015-02-17 19:13:33 +00:00
|
|
|
private:
|
2015-05-06 14:54:07 +00:00
|
|
|
const SkMatrix fMatrix;
|
2015-02-17 19:13:33 +00:00
|
|
|
};
|
|
|
|
|
2015-05-06 14:54:07 +00:00
|
|
|
class ViaUpright : public Via {
|
2015-01-15 18:56:12 +00:00
|
|
|
public:
|
2015-12-10 23:14:27 +00:00
|
|
|
ViaUpright(SkMatrix, Sink*);
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
2015-05-06 14:54:07 +00:00
|
|
|
const SkMatrix fMatrix;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
2015-05-06 14:54:07 +00:00
|
|
|
class ViaSerialization : public Via {
|
|
|
|
public:
|
2015-12-10 23:14:27 +00:00
|
|
|
explicit ViaSerialization(Sink* sink) : Via(sink) {}
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
2016-01-08 18:19:35 +00:00
|
|
|
class ViaPicture : public Via {
|
|
|
|
public:
|
|
|
|
explicit ViaPicture(Sink* sink) : Via(sink) {}
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
2016-07-08 15:43:27 +00:00
|
|
|
};
|
|
|
|
|
2016-09-13 15:09:45 +00:00
|
|
|
class ViaPipe : public Via {
|
|
|
|
public:
|
|
|
|
explicit ViaPipe(Sink* sink) : Via(sink) {}
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
};
|
|
|
|
|
2015-05-06 14:54:07 +00:00
|
|
|
class ViaTiles : public Via {
|
2015-01-15 18:56:12 +00:00
|
|
|
public:
|
2015-12-10 23:14:27 +00:00
|
|
|
ViaTiles(int w, int h, SkBBHFactory*, Sink*);
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
|
|
|
const int fW, fH;
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkBBHFactory> fFactory;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
2018-03-27 12:06:57 +00:00
|
|
|
class ViaDDL : public Via {
|
|
|
|
public:
|
|
|
|
ViaDDL(int numDivisions, Sink* sink);
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
private:
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
class PromiseImageHelper;
|
|
|
|
class TileData;
|
|
|
|
|
|
|
|
const int fNumDivisions;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2017-02-17 22:06:11 +00:00
|
|
|
class ViaSVG : public Via {
|
|
|
|
public:
|
|
|
|
explicit ViaSVG(Sink* sink) : Via(sink) {}
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
};
|
|
|
|
|
SkLite*
SkLiteRecorder, a new SkCanvas, fills out SkLiteDL, a new SkDrawable.
This SkDrawable is a display list similar to SkRecord and SkBigPicture / SkRecordedDrawable, but with a few new design points inspired by Android and slimming paint:
1) SkLiteDL is structured as one big contiguous array rather than the two layer structure of SkRecord. This trades away flexibility and large-op-count performance for better data locality for small to medium size pictures.
2) We keep a global freelist of SkLiteDLs, both reusing the SkLiteDL struct itself and its contiguous byte array. This keeps the expected number of mallocs per display list allocation <1 (really, ~0) for cyclical use cases.
These two together mean recording is faster. Measuring against the code we use at head, SkLiteRecorder trends about ~3x faster across various size pictures, matching speed at 0 draws and beating the special-case 1-draw pictures we have today. (I.e. we won't need those special case implementations anymore, because they're slower than this new generic code.) This new strategy records 10 drawRects() in about the same time the old strategy took for 2.
This strategy stays the winner until at least 500 drawRect()s on my laptop, where I stopped checking.
A simpler alternative to freelisting is also possible (but not implemented here), where we allow the client to manually reset() an SkLiteDL for reuse when its refcnt is 1. That's essentially what we're doing with the freelist, except tracking what's available for reuse globally instead of making the client do it.
This code is not fully capable yet, but most of the key design points are there. The internal structure of SkLiteDL is the area I expect to be most volatile (anything involving Op), but its interface and the whole of SkLiteRecorder ought to be just about done.
You can run nanobench --match picture_overhead as a demo. Everything it exercises is fully fleshed out, so what it tests is an apples-to-apples comparison as far as recording costs go. I have not yet compared playback performance.
It should be simple to wrap this into an SkPicture subclass if we want.
I won't start proposing we replace anything old with anything new quite yet until I have more ducks in a row, but this does look pretty promising (similar to the SkRecord over old SkPicture change a couple years ago) and I'd like to land, experiment, iterate, especially with an eye toward Android.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2213333002
Review-Url: https://codereview.chromium.org/2213333002
2016-08-06 19:51:51 +00:00
|
|
|
class ViaLite : public Via {
|
|
|
|
public:
|
|
|
|
explicit ViaLite(Sink* sink) : Via(sink) {}
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
};
|
|
|
|
|
2017-03-10 14:55:51 +00:00
|
|
|
class ViaCSXform : public Via {
|
|
|
|
public:
|
2017-03-18 15:36:52 +00:00
|
|
|
explicit ViaCSXform(Sink*, sk_sp<SkColorSpace>, bool colorSpin);
|
2017-03-10 14:55:51 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
private:
|
|
|
|
sk_sp<SkColorSpace> fCS;
|
2017-03-18 15:36:52 +00:00
|
|
|
bool fColorSpin;
|
2017-03-10 14:55:51 +00:00
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
} // namespace DM
|
|
|
|
|
|
|
|
#endif//DMSrcSink_DEFINED
|