Commit aae4c07a authored by Khushal's avatar Khushal Committed by Commit Bot

blink: Use external memory allocator in tests using MockImageDecoder.

The caller expects the decoder to populate memory in the allocator if
set, but the MockImageDecoder was not doing this. This causes failures
in MSAN where the memory remains unitinitialized.

Fix MockImageDecoder to respect this expectation.

R=chrishtr@chromium.org

Bug: 877497
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I441095eb3fb89c90cf3b9bf592438cd20b126391
Reviewed-on: https://chromium-review.googlesource.com/1188877
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586090}
parent b6718f52
...@@ -165,11 +165,8 @@ bool ImageDecoderWrapper::Decode(ImageDecoderFactory* factory, ...@@ -165,11 +165,8 @@ bool ImageDecoderWrapper::Decode(ImageDecoderFactory* factory,
// If we decoded into external memory, the bitmap should be backed by the // If we decoded into external memory, the bitmap should be backed by the
// pixels passed to the allocator. // pixels passed to the allocator.
#if DCHECK_IS_ON() DCHECK(!decode_to_external_memory ||
if (!decoder->IsForTesting() && decode_to_external_memory) { scaled_size_bitmap.getPixels() == pixels_);
DCHECK_EQ(scaled_size_bitmap.getPixels(), pixels_);
}
#endif
*has_alpha = !scaled_size_bitmap.isOpaque(); *has_alpha = !scaled_size_bitmap.isOpaque();
if (!decode_to_external_memory) { if (!decode_to_external_memory) {
......
...@@ -107,12 +107,18 @@ class MockImageDecoder : public ImageDecoder { ...@@ -107,12 +107,18 @@ class MockImageDecoder : public ImageDecoder {
return ImageDecoder::FrameBytesAtIndex(index); return ImageDecoder::FrameBytesAtIndex(index);
} }
void SetMemoryAllocator(SkBitmap::Allocator*) override { void SetMemoryAllocator(SkBitmap::Allocator* allocator) override {
if (frame_buffer_cache_.IsEmpty()) {
// Ensure that InitializeNewFrame is called, after parsing if
// necessary.
if (!FrameCount())
return;
}
frame_buffer_cache_[0].SetMemoryAllocator(allocator);
client_->MemoryAllocatorSet(); client_->MemoryAllocatorSet();
} }
bool IsForTesting() const override { return true; }
private: private:
void DecodeSize() override {} void DecodeSize() override {}
...@@ -120,6 +126,8 @@ class MockImageDecoder : public ImageDecoder { ...@@ -120,6 +126,8 @@ class MockImageDecoder : public ImageDecoder {
void Decode(size_t index) override { void Decode(size_t index) override {
client_->DecodeRequested(); client_->DecodeRequested();
frame_buffer_cache_[index].ClearPixelData();
InitializeNewFrame(index);
frame_buffer_cache_[index].SetStatus(client_->GetStatus(index)); frame_buffer_cache_[index].SetStatus(client_->GetStatus(index));
} }
......
...@@ -333,8 +333,6 @@ class PLATFORM_EXPORT ImageDecoder { ...@@ -333,8 +333,6 @@ class PLATFORM_EXPORT ImageDecoder {
virtual bool DecodeToYUV() { return false; } virtual bool DecodeToYUV() { return false; }
virtual void SetImagePlanes(std::unique_ptr<ImagePlanes>) {} virtual void SetImagePlanes(std::unique_ptr<ImagePlanes>) {}
virtual bool IsForTesting() const { return false; }
protected: protected:
ImageDecoder(AlphaOption alpha_option, ImageDecoder(AlphaOption alpha_option,
HighBitDepthDecodingOption high_bit_depth_decoding_option, HighBitDepthDecodingOption high_bit_depth_decoding_option,
......
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