Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Unified Diff: third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp

Issue 2918443003: Remove redundant reading and writing of data about SharedBuffer.
Patch Set: benchmark Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp b/third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp
index 88ac3e771e05cb8f64908183d9df2afa248f1885..a1e195ba7d9dc211655f9815ddf0b11e28505248 100644
--- a/third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp
+++ b/third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp
@@ -27,6 +27,7 @@
#include <memory>
#include "platform/SharedBuffer.h"
+#include "platform/SharedBufferStep.h"
#include "platform/graphics/ImageFrameGenerator.h"
#include "platform/image-decoders/ImageDecoder.h"
#include "platform/image-decoders/SegmentReader.h"
@@ -39,19 +40,42 @@ namespace blink {
DecodingImageGenerator::DecodingImageGenerator(
PassRefPtr<ImageFrameGenerator> frame_generator,
const SkImageInfo& info,
- PassRefPtr<SegmentReader> data,
+ PassRefPtr<SegmentReader> reader,
bool all_data_received,
size_t index,
uint32_t unique_id)
: SkImageGenerator(info, unique_id),
frame_generator_(std::move(frame_generator)),
- data_(std::move(data)),
+ reader_(std::move(reader)),
+ all_data_received_(all_data_received),
+ frame_index_(index),
+ can_yuv_decode_(false) {}
+
+DecodingImageGenerator::DecodingImageGenerator(
+ PassRefPtr<ImageFrameGenerator> frame_generator,
+ const SkImageInfo& info,
+ PassRefPtr<SharedBuffer::ThreadSafeStepper> stepper,
+ bool all_data_received,
+ size_t index,
+ uint32_t unique_id)
+ : SkImageGenerator(info, unique_id),
+ frame_generator_(std::move(frame_generator)),
+ stepper_(std::move(stepper)),
all_data_received_(all_data_received),
frame_index_(index),
can_yuv_decode_(false) {}
DecodingImageGenerator::~DecodingImageGenerator() {}
+PassRefPtr<SegmentReader> DecodingImageGenerator::encoded_data() const {
+ if (reader_) {
+ return reader_;
+ }
+
+ RefPtr<SharedBufferStep> step = stepper_->current_step();
+ return SegmentReader::CreateFromSharedBufferStep(step);
+}
+
SkData* DecodingImageGenerator::onRefEncodedData() {
TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData");
@@ -59,7 +83,7 @@ SkData* DecodingImageGenerator::onRefEncodedData() {
// serializers, which want the data even if it requires copying, and even
// if the data is incomplete. (Otherwise they would potentially need to
// decode the partial image in order to re-encode it.)
- return data_->GetAsSkData().release();
+ return encoded_data()->GetAsSkData().release();
}
bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info,
@@ -100,8 +124,9 @@ bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info,
}
PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID());
- const bool decoded = frame_generator_->DecodeAndScale(
- data_.Get(), all_data_received_, frame_index_, decode_info, pixels,
+ RefPtr<SegmentReader> data = encoded_data();
+ bool decoded = frame_generator_->DecodeAndScale(
+ data.Get(), all_data_received_, frame_index_, decode_info, pixels,
row_bytes, alpha_option);
PlatformInstrumentation::DidDecodeLazyPixelRef();
@@ -132,7 +157,8 @@ bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info,
if (color_space)
*color_space = kJPEG_SkYUVColorSpace;
- return frame_generator_->GetYUVComponentSizes(data_.Get(), size_info);
+ RefPtr<SegmentReader> data = encoded_data();
+ return frame_generator_->GetYUVComponentSizes(data.Get(), size_info);
}
bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& size_info,
@@ -146,8 +172,9 @@ bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& size_info,
static_cast<int>(frame_index_));
PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID());
+ RefPtr<SegmentReader> data = encoded_data();
bool decoded =
- frame_generator_->DecodeToYUV(data_.Get(), frame_index_, size_info.fSizes,
+ frame_generator_->DecodeToYUV(data.Get(), frame_index_, size_info.fSizes,
planes, size_info.fWidthBytes);
PlatformInstrumentation::DidDecodeLazyPixelRef();

Powered by Google App Engine
This is Rietveld 408576698