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"
|
|
|
|
#include "SkData.h"
|
2016-06-02 19:41:14 +00:00
|
|
|
#include "SkMultiPictureDocumentReader.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
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 {
|
|
|
|
enum { kNull, kGPU, kVector, kRaster } type;
|
|
|
|
enum { kDirect, kIndirect } approach;
|
|
|
|
};
|
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.
|
2015-03-25 20:48:49 +00:00
|
|
|
};
|
2015-04-09 19:43:10 +00:00
|
|
|
enum DstColorType {
|
|
|
|
kGetFromCanvas_DstColorType,
|
|
|
|
kIndex8_Always_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-06-06 15:20:37 +00:00
|
|
|
#if defined(SK_TEST_QCMS)
|
2016-06-01 21:47:18 +00:00
|
|
|
// Use QCMS for color correction.
|
|
|
|
kQCMS_HPZR30w_Mode,
|
|
|
|
#endif
|
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
|
|
|
};
|
|
|
|
|
2016-08-04 02:53:36 +00:00
|
|
|
#if defined(SK_XML)
|
|
|
|
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:
|
|
|
|
Path fPath;
|
|
|
|
|
|
|
|
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;
|
|
|
|
SkMultiPictureDocumentReader fReader;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
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,
|
|
|
|
sk_gpu_test::GrContextFactory::ContextOptions,
|
2016-06-16 20:03:24 +00:00
|
|
|
int samples, bool diText, SkColorType colorType, sk_sp<SkColorSpace> colorSpace,
|
2016-03-10 15:49:08 +00:00
|
|
|
bool threaded);
|
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;
|
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"; }
|
2015-07-31 13:43:04 +00:00
|
|
|
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect }; }
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
2016-04-05 18:06:27 +00:00
|
|
|
sk_gpu_test::GrContextFactory::ContextType fContextType;
|
|
|
|
sk_gpu_test::GrContextFactory::ContextOptions fContextOptions;
|
2016-03-31 01:56:19 +00:00
|
|
|
int fSampleCount;
|
|
|
|
bool fUseDIText;
|
|
|
|
SkColorType fColorType;
|
2016-06-16 20:03:24 +00:00
|
|
|
sk_sp<SkColorSpace> fColorSpace;
|
2016-03-31 01:56:19 +00:00
|
|
|
bool fThreaded;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PDFSink : public Sink {
|
|
|
|
public:
|
2016-04-27 14:45:18 +00:00
|
|
|
PDFSink(bool pdfa = false) : fPDFA(pdfa) {}
|
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;
|
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();
|
|
|
|
|
|
|
|
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 }; }
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
2016-06-16 20:03:24 +00:00
|
|
|
SkColorType fColorType;
|
|
|
|
sk_sp<SkColorSpace> fColorSpace;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-02-01 04:00:58 +00:00
|
|
|
class SVGSink : public Sink {
|
|
|
|
public:
|
|
|
|
SVGSink();
|
|
|
|
|
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 }; }
|
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:
|
2015-01-15 18:56:12 +00:00
|
|
|
SkAutoTDelete<Sink> fSink;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2016-07-08 15:43:27 +00:00
|
|
|
class ViaDefer : public Via {
|
|
|
|
public:
|
|
|
|
explicit ViaDefer(Sink* sink) : Via(sink) {}
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
2016-01-08 18:19:35 +00:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
SkAutoTDelete<SkBBHFactory> fFactory;
|
|
|
|
};
|
|
|
|
|
2015-05-06 14:54:07 +00:00
|
|
|
class ViaSecondPicture : public Via {
|
2015-04-07 15:30:32 +00:00
|
|
|
public:
|
2015-12-10 23:14:27 +00:00
|
|
|
explicit ViaSecondPicture(Sink* sink) : Via(sink) {}
|
2015-04-07 15:30:32 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
};
|
|
|
|
|
2015-05-06 14:54:07 +00:00
|
|
|
class ViaSingletonPictures : public Via {
|
2015-05-05 19:59:56 +00:00
|
|
|
public:
|
2015-12-10 23:14:27 +00:00
|
|
|
explicit ViaSingletonPictures(Sink* sink) : Via(sink) {}
|
2015-05-05 19:59:56 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
};
|
|
|
|
|
2015-05-06 18:35:40 +00:00
|
|
|
class ViaTwice : public Via {
|
|
|
|
public:
|
2015-12-10 23:14:27 +00:00
|
|
|
explicit ViaTwice(Sink* sink) : Via(sink) {}
|
2015-05-06 18:35:40 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
};
|
|
|
|
|
2016-02-03 19:53:18 +00:00
|
|
|
class ViaMojo : public Via {
|
|
|
|
public:
|
|
|
|
explicit ViaMojo(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;
|
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
} // namespace DM
|
|
|
|
|
|
|
|
#endif//DMSrcSink_DEFINED
|