Revert of DM: fix --config $VIA-pdf
to not crash (patchset #3 id:40001 of https://codereview.chromium.org/1513323002/ )
Reason for revert: I believe that this is breaking master-skia in Android. Original issue's description: > DM: fix `--config $VIA-pdf` to not crash > > Committed: https://skia.googlesource.com/skia/+/6bce4177cb72faac9c10d01d57e17168ae7ecadf TBR=mtklein@google.com,halcanary@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/1513053004
This commit is contained in:
parent
7d2e2fadbd
commit
62d3b10110
@ -643,7 +643,7 @@ static Sink* create_sink(const char* tag) {
|
||||
}
|
||||
|
||||
static Sink* create_via(const char* tag, Sink* wrapped) {
|
||||
#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(t, __VA_ARGS__); }
|
||||
#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
|
||||
VIA("twice", ViaTwice, wrapped);
|
||||
VIA("pipe", ViaPipe, wrapped);
|
||||
VIA("serialize", ViaSerialization, wrapped);
|
||||
|
@ -992,21 +992,19 @@ Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) con
|
||||
// passing the Sink draw() arguments, a size, and a function draws into an SkCanvas.
|
||||
// Several examples below.
|
||||
|
||||
static Error draw_to_canvas(Name name, Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkString* log,
|
||||
static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkString* log,
|
||||
SkISize size, std::function<Error(SkCanvas*)> draw) {
|
||||
class ProxySrc : public Src {
|
||||
public:
|
||||
ProxySrc(SkISize size, Name name, std::function<Error(SkCanvas*)> draw)
|
||||
: fSize(size), fName(name), fDraw(draw) {}
|
||||
ProxySrc(SkISize size, std::function<Error(SkCanvas*)> draw) : fSize(size), fDraw(draw) {}
|
||||
Error draw(SkCanvas* canvas) const override { return fDraw(canvas); }
|
||||
Name name() const override { return fName; }
|
||||
Name name() const override { sk_throw(); return ""; } // Won't be called.
|
||||
SkISize size() const override { return fSize; }
|
||||
private:
|
||||
SkISize fSize;
|
||||
Name fName;
|
||||
std::function<Error(SkCanvas*)> fDraw;
|
||||
};
|
||||
return sink->draw(ProxySrc(size, name, draw), bitmap, stream, log);
|
||||
return sink->draw(ProxySrc(size, draw), bitmap, stream, log);
|
||||
}
|
||||
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
@ -1018,13 +1016,12 @@ static SkISize auto_compute_translate(SkMatrix* matrix, int srcW, int srcH) {
|
||||
return SkISize::Make(SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height()));
|
||||
}
|
||||
|
||||
ViaMatrix::ViaMatrix(Name name, SkMatrix matrix, Sink* sink) : Via(name, sink), fMatrix(matrix) {}
|
||||
ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {}
|
||||
|
||||
Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
||||
SkMatrix matrix = fMatrix;
|
||||
SkISize size = auto_compute_translate(&matrix, src.size().width(), src.size().height());
|
||||
Name name = this->decorateName(src);
|
||||
return draw_to_canvas(name, fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
||||
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
||||
canvas->concat(matrix);
|
||||
return src.draw(canvas);
|
||||
});
|
||||
@ -1032,7 +1029,7 @@ Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStr
|
||||
|
||||
// Undoes any flip or 90 degree rotate without changing the scale of the bitmap.
|
||||
// This should be pixel-preserving.
|
||||
ViaUpright::ViaUpright(Name name, SkMatrix matrix, Sink* sink) : Via(name, sink), fMatrix(matrix) {}
|
||||
ViaUpright::ViaUpright(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {}
|
||||
|
||||
Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
||||
Error err = fSink->draw(src, bitmap, stream, log);
|
||||
@ -1069,8 +1066,7 @@ Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt
|
||||
|
||||
Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
||||
auto size = src.size();
|
||||
Name name = this->decorateName(src);
|
||||
return draw_to_canvas(name, fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
||||
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
||||
PipeController controller(canvas, &SkImageDecoder::DecodeMemory);
|
||||
SkGPipeWriter pipe;
|
||||
const uint32_t kFlags = 0;
|
||||
@ -1079,8 +1075,7 @@ Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin
|
||||
}
|
||||
|
||||
Error ViaRemote::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
||||
Name name = this->decorateName(src);
|
||||
return draw_to_canvas(name, fSink, bitmap, stream, log, src.size(), [&](SkCanvas* target) {
|
||||
return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* target) {
|
||||
SkAutoTDelete<SkRemote::Encoder> decoder(SkRemote::NewDecoder(target));
|
||||
SkAutoTDelete<SkRemote::Encoder> cache(fCache ? SkRemote::NewCachingEncoder(decoder)
|
||||
: nullptr);
|
||||
@ -1108,9 +1103,8 @@ Error ViaSerialization::draw(
|
||||
pic->serialize(&wStream);
|
||||
SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
|
||||
SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream, &lazy_decode_bitmap));
|
||||
Name name = this->decorateName(src);
|
||||
|
||||
return draw_to_canvas(name, fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
||||
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
||||
canvas->drawPicture(deserialized);
|
||||
return "";
|
||||
});
|
||||
@ -1118,8 +1112,8 @@ Error ViaSerialization::draw(
|
||||
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
ViaTiles::ViaTiles(Name name, int w, int h, SkBBHFactory* factory, Sink* sink)
|
||||
: Via(name, sink)
|
||||
ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink)
|
||||
: Via(sink)
|
||||
, fW(w)
|
||||
, fH(h)
|
||||
, fFactory(factory) {}
|
||||
@ -1134,9 +1128,8 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri
|
||||
return err;
|
||||
}
|
||||
SkAutoTUnref<SkPicture> pic(recorder.endRecordingAsPicture());
|
||||
Name name = this->decorateName(src);
|
||||
|
||||
return draw_to_canvas(name, fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) {
|
||||
return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) {
|
||||
const int xTiles = (size.width() + fW - 1) / fW,
|
||||
yTiles = (size.height() + fH - 1) / fH;
|
||||
SkMultiPictureDraw mpd(xTiles*yTiles);
|
||||
@ -1178,8 +1171,7 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri
|
||||
Error ViaSecondPicture::draw(
|
||||
const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
||||
auto size = src.size();
|
||||
Name name = this->decorateName(src);
|
||||
return draw_to_canvas(name, fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
|
||||
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
|
||||
SkPictureRecorder recorder;
|
||||
SkAutoTUnref<SkPicture> pic;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
@ -1199,8 +1191,7 @@ Error ViaSecondPicture::draw(
|
||||
|
||||
// Draw the Src twice. This can help exercise caching.
|
||||
Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
||||
Name name = this->decorateName(src);
|
||||
return draw_to_canvas(name, fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) -> Error {
|
||||
return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) -> Error {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
SkAutoCanvasRestore acr(canvas, true/*save now*/);
|
||||
canvas->clear(SK_ColorTRANSPARENT);
|
||||
@ -1252,8 +1243,7 @@ struct DrawsAsSingletonPictures {
|
||||
Error ViaSingletonPictures::draw(
|
||||
const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
||||
auto size = src.size();
|
||||
Name name = this->decorateName(src);
|
||||
return draw_to_canvas(name, fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
|
||||
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
|
||||
// Use low-level (Skia-private) recording APIs so we can read the SkRecord.
|
||||
SkRecord skr;
|
||||
SkRecorder recorder(&skr, size.width(), size.height());
|
||||
|
@ -289,25 +289,21 @@ public:
|
||||
|
||||
class Via : public Sink {
|
||||
public:
|
||||
explicit Via(Name name, Sink* sink) : fName(name), fSink(sink) {}
|
||||
explicit Via(Sink* sink) : fSink(sink) {}
|
||||
const char* fileExtension() const override { return fSink->fileExtension(); }
|
||||
int enclave() const override { return fSink->enclave(); }
|
||||
Name decorateName(const Src& src) const {
|
||||
return SkStringPrintf("%s-%s", src.name().c_str(), fName.c_str());
|
||||
}
|
||||
SinkFlags flags() const override {
|
||||
SinkFlags flags = fSink->flags();
|
||||
flags.approach = SinkFlags::kIndirect;
|
||||
return flags;
|
||||
}
|
||||
protected:
|
||||
Name fName;
|
||||
SkAutoTDelete<Sink> fSink;
|
||||
};
|
||||
|
||||
class ViaMatrix : public Via {
|
||||
public:
|
||||
ViaMatrix(Name, SkMatrix, Sink*);
|
||||
ViaMatrix(SkMatrix, Sink*);
|
||||
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
private:
|
||||
const SkMatrix fMatrix;
|
||||
@ -315,7 +311,7 @@ private:
|
||||
|
||||
class ViaUpright : public Via {
|
||||
public:
|
||||
ViaUpright(Name, SkMatrix, Sink*);
|
||||
ViaUpright(SkMatrix, Sink*);
|
||||
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
private:
|
||||
const SkMatrix fMatrix;
|
||||
@ -323,13 +319,13 @@ private:
|
||||
|
||||
class ViaPipe : public Via {
|
||||
public:
|
||||
explicit ViaPipe(Name name, Sink* sink) : Via(name, sink) {}
|
||||
explicit ViaPipe(Sink* sink) : Via(sink) {}
|
||||
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
};
|
||||
|
||||
class ViaRemote : public Via {
|
||||
public:
|
||||
ViaRemote(Name name, bool cache, Sink* sink) : Via(name, sink), fCache(cache) {}
|
||||
ViaRemote(bool cache, Sink* sink) : Via(sink), fCache(cache) {}
|
||||
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
private:
|
||||
bool fCache;
|
||||
@ -337,13 +333,13 @@ private:
|
||||
|
||||
class ViaSerialization : public Via {
|
||||
public:
|
||||
explicit ViaSerialization(Name name, Sink* sink) : Via(name, sink) {}
|
||||
explicit ViaSerialization(Sink* sink) : Via(sink) {}
|
||||
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
};
|
||||
|
||||
class ViaTiles : public Via {
|
||||
public:
|
||||
ViaTiles(Name, int w, int h, SkBBHFactory*, Sink*);
|
||||
ViaTiles(int w, int h, SkBBHFactory*, Sink*);
|
||||
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
private:
|
||||
const int fW, fH;
|
||||
@ -352,19 +348,19 @@ private:
|
||||
|
||||
class ViaSecondPicture : public Via {
|
||||
public:
|
||||
explicit ViaSecondPicture(Name name, Sink* sink) : Via(name, sink) {}
|
||||
explicit ViaSecondPicture(Sink* sink) : Via(sink) {}
|
||||
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
};
|
||||
|
||||
class ViaSingletonPictures : public Via {
|
||||
public:
|
||||
explicit ViaSingletonPictures(Name name, Sink* sink) : Via(name, sink) {}
|
||||
explicit ViaSingletonPictures(Sink* sink) : Via(sink) {}
|
||||
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
};
|
||||
|
||||
class ViaTwice : public Via {
|
||||
public:
|
||||
explicit ViaTwice(Name name, Sink* sink) : Via(name, sink) {}
|
||||
explicit ViaTwice(Sink* sink) : Via(sink) {}
|
||||
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user