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"
|
|
|
|
#include "SkCanvas.h"
|
2015-04-09 19:43:10 +00:00
|
|
|
#include "SkCodec.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkData.h"
|
|
|
|
#include "SkGPipe.h"
|
|
|
|
#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) {}
|
|
|
|
};
|
|
|
|
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-01-15 18:56:12 +00:00
|
|
|
struct Src {
|
|
|
|
// All Srcs must be thread safe.
|
|
|
|
virtual ~Src() {}
|
|
|
|
virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0;
|
|
|
|
virtual SkISize size() const = 0;
|
|
|
|
virtual Name name() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2015-01-15 18:56:12 +00:00
|
|
|
// Sinks in the same enclave (except kAnyThread_Enclave) will run serially on the same thread.
|
|
|
|
virtual int enclave() const = 0;
|
|
|
|
|
|
|
|
// File extension for the content draw() outputs, e.g. "png", "pdf".
|
|
|
|
virtual const char* fileExtension() const = 0;
|
|
|
|
};
|
|
|
|
|
2015-02-20 15:21:05 +00:00
|
|
|
enum { kAnyThread_Enclave, kGPU_Enclave };
|
|
|
|
static const int kNumEnclaves = kGPU_Enclave + 1;
|
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-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 {
|
|
|
|
kNormal_Mode,
|
|
|
|
kScanline_Mode,
|
|
|
|
};
|
2015-04-09 19:43:10 +00:00
|
|
|
enum DstColorType {
|
|
|
|
kGetFromCanvas_DstColorType,
|
|
|
|
kIndex8_Always_DstColorType,
|
|
|
|
kGrayscale_Always_DstColorType,
|
|
|
|
};
|
|
|
|
CodecSrc(Path, Mode, DstColorType);
|
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-03-19 13:03:39 +00:00
|
|
|
private:
|
2015-04-09 19:43:10 +00:00
|
|
|
Path fPath;
|
|
|
|
Mode fMode;
|
|
|
|
DstColorType fDstColorType;
|
2015-03-19 13:03:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
class ImageSrc : public Src {
|
|
|
|
public:
|
2015-01-30 21:22:23 +00:00
|
|
|
// divisor == 0 means decode the whole image
|
|
|
|
// divisor > 0 means decode in subsets, dividing into a divisor x divisor grid.
|
|
|
|
explicit ImageSrc(Path path, int divisor = 0);
|
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-30 21:22:23 +00:00
|
|
|
const int fDivisor;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
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;
|
|
|
|
int enclave() const override { return kAnyThread_Enclave; }
|
|
|
|
const char* fileExtension() const override { return ""; }
|
2015-02-13 23:11:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
class GPUSink : public Sink {
|
|
|
|
public:
|
2015-01-15 20:46:02 +00:00
|
|
|
GPUSink(GrContextFactory::GLContextType, GrGLStandard, int samples, bool dfText, 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;
|
|
|
|
int enclave() const override;
|
|
|
|
const char* fileExtension() const override { return "png"; }
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
|
|
|
GrContextFactory::GLContextType fContextType;
|
|
|
|
GrGLStandard fGpuAPI;
|
|
|
|
int fSampleCount;
|
|
|
|
bool fUseDFText;
|
2015-01-15 20:46:02 +00:00
|
|
|
bool fThreaded;
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PDFSink : public Sink {
|
|
|
|
public:
|
|
|
|
PDFSink();
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
int enclave() const override { return kAnyThread_Enclave; }
|
|
|
|
const char* fileExtension() const override { return "pdf"; }
|
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;
|
|
|
|
int enclave() const override { return kAnyThread_Enclave; }
|
|
|
|
const char* fileExtension() const override { return "xps"; }
|
2015-03-03 17:13:09 +00:00
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
class RasterSink : public Sink {
|
|
|
|
public:
|
|
|
|
explicit RasterSink(SkColorType);
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
int enclave() const override { return kAnyThread_Enclave; }
|
|
|
|
const char* fileExtension() const override { return "png"; }
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
|
|
|
SkColorType fColorType;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
int enclave() const override { return kAnyThread_Enclave; }
|
|
|
|
const char* fileExtension() const override { return "skp"; }
|
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;
|
|
|
|
int enclave() const override { return kAnyThread_Enclave; }
|
|
|
|
const char* fileExtension() const override { return "svg"; }
|
2015-02-01 04:00:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
|
|
|
class ViaMatrix : public Sink {
|
|
|
|
public:
|
|
|
|
ViaMatrix(SkMatrix, Sink*);
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
int enclave() const override { return fSink->enclave(); }
|
|
|
|
const char* fileExtension() const override { return fSink->fileExtension(); }
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
|
|
|
SkMatrix fMatrix;
|
|
|
|
SkAutoTDelete<Sink> fSink;
|
|
|
|
};
|
|
|
|
|
2015-02-17 19:13:33 +00:00
|
|
|
class ViaUpright : public Sink {
|
|
|
|
public:
|
|
|
|
ViaUpright(SkMatrix, Sink*);
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
int enclave() const override { return fSink->enclave(); }
|
|
|
|
const char* fileExtension() const override { return fSink->fileExtension(); }
|
2015-02-17 19:13:33 +00:00
|
|
|
private:
|
|
|
|
SkMatrix fMatrix;
|
|
|
|
SkAutoTDelete<Sink> fSink;
|
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
class ViaPipe : public Sink {
|
|
|
|
public:
|
2015-01-21 21:18:51 +00:00
|
|
|
explicit ViaPipe(Sink*);
|
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;
|
|
|
|
int enclave() const override { return fSink->enclave(); }
|
|
|
|
const char* fileExtension() const override { return fSink->fileExtension(); }
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
|
|
|
SkAutoTDelete<Sink> fSink;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ViaSerialization : public Sink {
|
|
|
|
public:
|
|
|
|
explicit ViaSerialization(Sink*);
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
int enclave() const override { return fSink->enclave(); }
|
|
|
|
const char* fileExtension() const override { return fSink->fileExtension(); }
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
|
|
|
SkAutoTDelete<Sink> fSink;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ViaTiles : public Sink {
|
|
|
|
public:
|
|
|
|
ViaTiles(int w, int h, SkBBHFactory*, Sink*);
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
int enclave() const override { return fSink->enclave(); }
|
|
|
|
const char* fileExtension() const override { return fSink->fileExtension(); }
|
2015-01-15 18:56:12 +00:00
|
|
|
private:
|
|
|
|
const int fW, fH;
|
|
|
|
SkAutoTDelete<SkBBHFactory> fFactory;
|
|
|
|
SkAutoTDelete<Sink> fSink;
|
|
|
|
};
|
|
|
|
|
2015-04-07 15:30:32 +00:00
|
|
|
class ViaSecondPicture : public Sink {
|
|
|
|
public:
|
|
|
|
explicit ViaSecondPicture(Sink*);
|
|
|
|
|
|
|
|
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
|
|
|
int enclave() const override { return fSink->enclave(); }
|
|
|
|
const char* fileExtension() const override { return fSink->fileExtension(); }
|
|
|
|
private:
|
|
|
|
SkAutoTDelete<Sink> fSink;
|
|
|
|
};
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
} // namespace DM
|
|
|
|
|
|
|
|
#endif//DMSrcSink_DEFINED
|