Can't share encoded data if we have any modifiers
Bug: skia:7752 Change-Id: I5aea653b890a203c7e3cda8102bfb3e9abfbc8a4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295917 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
ef0fa43464
commit
cd04356804
@ -174,8 +174,12 @@ bool SkImage_Lazy::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz
|
||||
}
|
||||
|
||||
sk_sp<SkData> SkImage_Lazy::onRefEncoded() const {
|
||||
ScopedGenerator generator(fSharedGenerator);
|
||||
return generator->refEncodedData();
|
||||
// check that we aren't a subset or colortype/etc modification of the original
|
||||
if (fSharedGenerator->fGenerator->uniqueID() == this->uniqueID()) {
|
||||
ScopedGenerator generator(fSharedGenerator);
|
||||
return generator->refEncodedData();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SkImage_Lazy::onIsValid(GrRecordingContext* context) const {
|
||||
|
@ -1502,3 +1502,18 @@ DEF_TEST(image_cubicresampler, reporter) {
|
||||
|
||||
diff(SkImageShader::CubicResamplerMatrix(0, 1.0f/2), gCentripetalCatmulRom);
|
||||
}
|
||||
|
||||
DEF_TEST(image_subset_encode_skbug_7752, reporter) {
|
||||
sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_128.png");
|
||||
const int W = image->width();
|
||||
const int H = image->height();
|
||||
|
||||
auto check_roundtrip = [&](sk_sp<SkImage> img) {
|
||||
auto img2 = SkImage::MakeFromEncoded(img->encodeToData());
|
||||
REPORTER_ASSERT(reporter, ToolUtils::equal_pixels(img.get(), img2.get()));
|
||||
};
|
||||
check_roundtrip(image); // should trivially pass
|
||||
check_roundtrip(image->makeSubset({0, 0, W/2, H/2}));
|
||||
check_roundtrip(image->makeSubset({W/2, H/2, W, H}));
|
||||
check_roundtrip(image->makeColorSpace(SkColorSpace::MakeSRGBLinear()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user