Skip to content

Commit

Permalink
Fix bug of SkSVGCanvas::Make
Browse files Browse the repository at this point in the history
The method `SkSVGCanvas::Make(const SkRect& bounds, SkWStream* writer)`
passes a pointer to a stack-allocated object to the returned SkCanvas.

TBR=
Change-Id: Ica7933adc59764a69eb2fb6312df91ffffd5627b
Reviewed-on: https://skia-review.googlesource.com/c/192040
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
  • Loading branch information
KDr2 authored and Skia Commit-Bot committed Feb 14, 2019
1 parent 09c01e9 commit e77142e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ Yandex LLC <*@yandex-team.ru>
Kaloyan Donev <kdonev@gmail.com>
Yong-Hwan Baek <meisterdevhwan@gmail.com>
Alexander Khovansky <alx.khovansky@gmail.com>
Zhuo Qingliang <zhuo.dev@gmail.com>
2 changes: 1 addition & 1 deletion include/svg/SkSVGCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SK_API SkSVGCanvas {
static std::unique_ptr<SkCanvas> Make(const SkRect& bounds, SkWStream*);

// Internal only.
static std::unique_ptr<SkCanvas> Make(const SkRect& bounds, SkXMLWriter*);
static std::unique_ptr<SkCanvas> Make(const SkRect& bounds, SkXMLWriter*, bool ownsWriter=false);
};

#endif
8 changes: 4 additions & 4 deletions src/svg/SkSVGCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
#include "SkMakeUnique.h"
#include "SkXMLWriter.h"

std::unique_ptr<SkCanvas> SkSVGCanvas::Make(const SkRect& bounds, SkXMLWriter* writer) {
std::unique_ptr<SkCanvas> SkSVGCanvas::Make(const SkRect& bounds, SkXMLWriter* writer, bool ownsWriter) {
// TODO: pass full bounds to the device
SkISize size = bounds.roundOut().size();
sk_sp<SkBaseDevice> device(SkSVGDevice::Create(size, writer));
sk_sp<SkBaseDevice> device(SkSVGDevice::Create(size, writer, ownsWriter));

return skstd::make_unique<SkCanvas>(device);
}

std::unique_ptr<SkCanvas> SkSVGCanvas::Make(const SkRect& bounds, SkWStream* writer) {
SkXMLStreamWriter xmlWriter(writer);
return Make(bounds, &xmlWriter);
SkXMLStreamWriter *xmlWriter = new SkXMLStreamWriter(writer);
return Make(bounds, xmlWriter, true);
}
10 changes: 7 additions & 3 deletions src/svg/SkSVGDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,18 +634,19 @@ void SkSVGDevice::AutoElement::addTextAttributes(const SkFont& font) {
}
}

SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkXMLWriter* writer) {
SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkXMLWriter* writer, bool ownsWriter) {
if (!writer) {
return nullptr;
}

return new SkSVGDevice(size, writer);
return new SkSVGDevice(size, writer, ownsWriter);
}

SkSVGDevice::SkSVGDevice(const SkISize& size, SkXMLWriter* writer)
SkSVGDevice::SkSVGDevice(const SkISize& size, SkXMLWriter* writer, bool ownsWriter)
: INHERITED(SkImageInfo::MakeUnknown(size.fWidth, size.fHeight),
SkSurfaceProps(0, kUnknown_SkPixelGeometry))
, fWriter(writer)
, fOwnsWriter(ownsWriter)
, fResourceBucket(new ResourceBucket)
{
SkASSERT(writer);
Expand All @@ -662,6 +663,9 @@ SkSVGDevice::SkSVGDevice(const SkISize& size, SkXMLWriter* writer)
}

SkSVGDevice::~SkSVGDevice() {
if (fOwnsWriter && fWriter) {
delete fWriter;
}
}

void SkSVGDevice::drawPaint(const SkPaint& paint) {
Expand Down
5 changes: 3 additions & 2 deletions src/svg/SkSVGDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SkXMLWriter;

class SkSVGDevice : public SkClipStackDevice {
public:
static SkBaseDevice* Create(const SkISize& size, SkXMLWriter* writer);
static SkBaseDevice* Create(const SkISize& size, SkXMLWriter* writer, bool ownsWriter=false);

protected:
void drawPaint(const SkPaint& paint) override;
Expand All @@ -42,7 +42,7 @@ class SkSVGDevice : public SkClipStackDevice {
const SkPaint&) override;

private:
SkSVGDevice(const SkISize& size, SkXMLWriter* writer);
SkSVGDevice(const SkISize& size, SkXMLWriter* writer, bool ownsWriter=false);
~SkSVGDevice() override;

struct MxCp;
Expand All @@ -52,6 +52,7 @@ class SkSVGDevice : public SkClipStackDevice {
class ResourceBucket;

SkXMLWriter* fWriter;
bool fOwnsWriter;
std::unique_ptr<AutoElement> fRootElement;
std::unique_ptr<ResourceBucket> fResourceBucket;

Expand Down

0 comments on commit e77142e

Please sign in to comment.