SkPDF Create working move constructor for inner classes

BUG=chromium:592330,chromium:592702

Review URL: https://codereview.chromium.org/1774633002
This commit is contained in:
halcanary 2016-03-07 12:39:14 -08:00 committed by Commit bot
parent f9deeb66d0
commit d7b2885b90
2 changed files with 22 additions and 9 deletions

View File

@ -1416,15 +1416,15 @@ void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device,
SkScalar scalarY = SkIntToScalar(y);
for (const RectWithData& l : pdfDevice->fLinkToURLs) {
SkRect r = l.rect.makeOffset(scalarX, scalarY);
fLinkToURLs.emplace_back(r, l.data);
fLinkToURLs.emplace_back(r, l.data.get());
}
for (const RectWithData& l : pdfDevice->fLinkToDestinations) {
SkRect r = l.rect.makeOffset(scalarX, scalarY);
fLinkToDestinations.emplace_back(r, l.data);
fLinkToDestinations.emplace_back(r, l.data.get());
}
for (const NamedDestination& d : pdfDevice->fNamedDestinations) {
SkPoint p = d.point + SkPoint::Make(scalarX, scalarY);
fNamedDestinations.emplace_back(d.nameData, p);
fNamedDestinations.emplace_back(d.nameData.get(), p);
}
if (pdfDevice->isContentEmpty()) {
@ -1699,12 +1699,13 @@ void SkPDFDevice::appendAnnotations(SkPDFArray* array) const {
for (const RectWithData& rectWithURL : fLinkToURLs) {
SkRect r;
fInitialTransform.mapRect(&r, rectWithURL.rect);
array->appendObject(create_link_to_url(rectWithURL.data, r));
array->appendObject(create_link_to_url(rectWithURL.data.get(), r));
}
for (const RectWithData& linkToDestination : fLinkToDestinations) {
SkRect r;
fInitialTransform.mapRect(&r, linkToDestination.rect);
array->appendObject(create_link_named_dest(linkToDestination.data, r));
array->appendObject(
create_link_named_dest(linkToDestination.data.get(), r));
}
}

View File

@ -202,18 +202,30 @@ protected:
private:
struct RectWithData {
SkRect rect;
SkData* data;
sk_sp<SkData> data;
RectWithData(const SkRect& rect, SkData* data)
: rect(rect), data(SkRef(data)) {}
~RectWithData() { data->unref(); }
RectWithData(RectWithData&& other)
: rect(other.rect), data(std::move(other.data)) {}
RectWithData& operator=(RectWithData&& other) {
rect = other.rect;
data = std::move(other.data);
return *this;
}
};
struct NamedDestination {
SkData* nameData;
sk_sp<SkData> nameData;
SkPoint point;
NamedDestination(SkData* nameData, const SkPoint& point)
: nameData(SkRef(nameData)), point(point) {}
~NamedDestination() { nameData->unref(); }
NamedDestination(NamedDestination&& other)
: nameData(std::move(other.nameData)), point(other.point) {}
NamedDestination& operator=(NamedDestination&& other) {
nameData = std::move(other.nameData);
point = other.point;
return *this;
}
};
// TODO(vandebo): push most of SkPDFDevice's state into a core object in