Commit 64d84817 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Return a Vector instead of a pointer to one from PictureSnapshot::Replay.

For consistency and efficiency.

While here, move the StringBuilder::ReserveCapacity call at the use before the
actual usage of the StringBuilder (presently it has no effect).

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I197140cc0b77d12bd236e908e844eacf39fa6697
Reviewed-on: https://chromium-review.googlesource.com/1106605Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568828}
parent 6e190d09
......@@ -522,14 +522,15 @@ Response InspectorLayerTreeAgent::replaySnapshot(const String& snapshot_id,
Response response = GetSnapshotById(snapshot_id, snapshot);
if (!response.isSuccess())
return response;
std::unique_ptr<Vector<char>> base64_data = snapshot->Replay(
Vector<char> base64_data = snapshot->Replay(
from_step.fromMaybe(0), to_step.fromMaybe(0), scale.fromMaybe(1.0));
if (!base64_data)
if (base64_data.IsEmpty())
return Response::Error("Image encoding failed");
static constexpr char kUrlPrefix[] = "data:image/png;base64,";
StringBuilder url;
url.Append("data:image/png;base64,");
url.ReserveCapacity(url.length() + base64_data->size());
url.Append(base64_data->begin(), base64_data->size());
url.ReserveCapacity(sizeof(kUrlPrefix) + base64_data.size());
url.Append(kUrlPrefix);
url.Append(base64_data.begin(), base64_data.size());
*data_url = url.ToString();
return Response::OK();
}
......
......@@ -88,9 +88,9 @@ bool PictureSnapshot::IsEmpty() const {
return picture_->cullRect().isEmpty();
}
std::unique_ptr<Vector<char>> PictureSnapshot::Replay(unsigned from_step,
unsigned to_step,
double scale) const {
Vector<char> PictureSnapshot::Replay(unsigned from_step,
unsigned to_step,
double scale) const {
const SkIRect bounds = picture_->cullRect().roundOut();
int width = ceil(scale * bounds.width());
int height = ceil(scale * bounds.height());
......@@ -113,7 +113,7 @@ std::unique_ptr<Vector<char>> PictureSnapshot::Replay(unsigned from_step,
canvas.ResetStepCount();
picture_->playback(&canvas, &canvas);
}
std::unique_ptr<Vector<char>> base64_data = std::make_unique<Vector<char>>();
Vector<char> base64_data;
Vector<char> encoded_image;
SkPixmap src;
......@@ -127,10 +127,10 @@ std::unique_ptr<Vector<char>> PictureSnapshot::Replay(unsigned from_step,
if (!ImageEncoder::Encode(
reinterpret_cast<Vector<unsigned char>*>(&encoded_image), src,
options)) {
return nullptr;
return Vector<char>();
}
Base64Encode(encoded_image, *base64_data);
Base64Encode(encoded_image, base64_data);
return base64_data;
}
......
......@@ -60,9 +60,9 @@ class PLATFORM_EXPORT PictureSnapshot : public RefCounted<PictureSnapshot> {
PictureSnapshot(sk_sp<const SkPicture>);
std::unique_ptr<Vector<char>> Replay(unsigned from_step = 0,
unsigned to_step = 0,
double scale = 1.0) const;
Vector<char> Replay(unsigned from_step = 0,
unsigned to_step = 0,
double scale = 1.0) const;
Vector<Vector<TimeDelta>> Profile(unsigned min_iterations,
TimeDelta min_duration,
const FloatRect* clip_rect) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment