return SkISize::Make(SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height()));
}
-ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink) {}
+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;
// Undoes any flip or 90 degree rotate without changing the scale of the bitmap.
// This should be pixel-preserving.
-ViaUpright::ViaUpright(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink) {}
+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);
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-ViaPipe::ViaPipe(Sink* sink) : fSink(sink) {}
-
Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
auto size = src.size();
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-ViaDeferred::ViaDeferred(Sink* sink) : fSink(sink) {}
-
Error ViaDeferred::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
// We draw via a deferred canvas into a surface that's compatible with the original canvas,
// then snap that surface as an image and draw it into the original canvas.
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {}
-
Error ViaSerialization::draw(
const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
// Record our Src into a picture.
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink)
- : fW(w)
+ : Via(sink)
+ , fW(w)
, fH(h)
- , fFactory(factory)
- , fSink(sink) {}
+ , fFactory(factory) {}
Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
auto size = src.size();
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-ViaSecondPicture::ViaSecondPicture(Sink* sink) : fSink(sink) {}
-
// Draw the Src into two pictures, then draw the second picture into the wrapped Sink.
// This tests that any shortcuts we may take while recording that second picture are legal.
Error ViaSecondPicture::draw(
void operator()(const SkRecords::SaveLayer& op) { this->draw(op, fCanvas); }
};
-ViaSingletonPictures::ViaSingletonPictures(Sink* sink) : fSink(sink) {}
-
// Record Src into a picture, then record it into a macro picture with a sub-picture for each draw.
// Then play back that macro picture into our wrapped sink.
Error ViaSingletonPictures::draw(
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-class ViaMatrix : public Sink {
+class Via : public Sink {
public:
- ViaMatrix(SkMatrix, Sink*);
-
- Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
- int enclave() const override { return fSink->enclave(); }
+ explicit Via(Sink* sink) : fSink(sink) {}
const char* fileExtension() const override { return fSink->fileExtension(); }
-private:
- SkMatrix fMatrix;
+ int enclave() const override { return fSink->enclave(); }
+protected:
SkAutoTDelete<Sink> fSink;
};
-class ViaUpright : public Sink {
+class ViaMatrix : public Via {
public:
- ViaUpright(SkMatrix, Sink*);
-
+ ViaMatrix(SkMatrix, 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:
- SkMatrix fMatrix;
- SkAutoTDelete<Sink> fSink;
+ const SkMatrix fMatrix;
};
-class ViaPipe : public Sink {
+class ViaUpright : public Via {
public:
- explicit ViaPipe(Sink*);
-
+ ViaUpright(SkMatrix, 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;
+ const SkMatrix fMatrix;
};
-class ViaDeferred : public Sink {
+class ViaPipe : public Via {
public:
- explicit ViaDeferred(Sink*);
-
+ explicit ViaPipe(Sink* sink) : Via(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;
};
-class ViaSerialization : public Sink {
+class ViaDeferred : public Via {
public:
- explicit ViaSerialization(Sink*);
+ explicit ViaDeferred(Sink* sink) : Via(sink) {}
+ Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
+};
+class ViaSerialization : public Via {
+public:
+ explicit ViaSerialization(Sink* sink) : Via(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;
};
-class ViaTiles : public Sink {
+class ViaTiles : public Via {
public:
ViaTiles(int w, int h, SkBBHFactory*, 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:
const int fW, fH;
SkAutoTDelete<SkBBHFactory> fFactory;
- SkAutoTDelete<Sink> fSink;
};
-class ViaSecondPicture : public Sink {
+class ViaSecondPicture : public Via {
public:
- explicit ViaSecondPicture(Sink*);
-
+ explicit ViaSecondPicture(Sink* sink) : Via(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;
};
-class ViaSingletonPictures : public Sink {
+class ViaSingletonPictures : public Via {
public:
- explicit ViaSingletonPictures(Sink*);
-
+ explicit ViaSingletonPictures(Sink* sink) : Via(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;
};
} // namespace DM