[Impeller] Return an empty contents in Paint::CreateContents if a runtime effect sampler is invalid (#165165)
Callers of Paint::CreateContents expect that the result is not null. See https://github.com/flutter/flutter/issues/165119
This commit is contained in:
@@ -108,5 +108,33 @@ TEST_P(AiksTest, CanRenderRuntimeEffectFilter) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
|
||||
}
|
||||
|
||||
TEST_P(AiksTest, RuntimeEffectWithInvalidSamplerDoesNotCrash) {
|
||||
ScopedValidationDisable disable_validation;
|
||||
|
||||
// Create a sampler that is not usable as an input to the runtime effect.
|
||||
std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
|
||||
flutter::DlColor::kRed()};
|
||||
const float stops[2] = {0.0, 1.0};
|
||||
auto linear = flutter::DlColorSource::MakeLinear({0.0, 0.0}, {300.0, 300.0},
|
||||
2, colors.data(), stops,
|
||||
flutter::DlTileMode::kClamp);
|
||||
std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
|
||||
linear,
|
||||
};
|
||||
|
||||
auto uniform_data = std::make_shared<std::vector<uint8_t>>();
|
||||
uniform_data->resize(sizeof(Vector2));
|
||||
|
||||
DlPaint paint;
|
||||
paint.setColorSource(
|
||||
MakeRuntimeEffect(this, "runtime_stage_filter_example.frag.iplr",
|
||||
uniform_data, sampler_inputs));
|
||||
|
||||
DisplayListBuilder builder;
|
||||
builder.DrawPaint(paint);
|
||||
|
||||
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@@ -218,11 +218,17 @@ std::shared_ptr<ColorSourceContents> Paint::CreateContents() const {
|
||||
|
||||
for (auto& sampler : samplers) {
|
||||
if (sampler == nullptr) {
|
||||
return nullptr;
|
||||
VALIDATION_LOG << "Runtime effect sampler is null";
|
||||
auto contents = std::make_shared<SolidColorContents>();
|
||||
contents->SetColor(Color::BlackTransparent());
|
||||
return contents;
|
||||
}
|
||||
auto* image = sampler->asImage();
|
||||
if (!sampler->asImage()) {
|
||||
return nullptr;
|
||||
VALIDATION_LOG << "Runtime effect sampler is not an image";
|
||||
auto contents = std::make_shared<SolidColorContents>();
|
||||
contents->SetColor(Color::BlackTransparent());
|
||||
return contents;
|
||||
}
|
||||
FML_DCHECK(image->image()->impeller_texture());
|
||||
texture_inputs.push_back({
|
||||
|
||||
@@ -877,6 +877,9 @@ impeller_Play_AiksTest_ReleasesTextureOnTeardown_Vulkan.png
|
||||
impeller_Play_AiksTest_RotateColorFilteredPath_Metal.png
|
||||
impeller_Play_AiksTest_RotateColorFilteredPath_OpenGLES.png
|
||||
impeller_Play_AiksTest_RotateColorFilteredPath_Vulkan.png
|
||||
impeller_Play_AiksTest_RuntimeEffectWithInvalidSamplerDoesNotCrash_Metal.png
|
||||
impeller_Play_AiksTest_RuntimeEffectWithInvalidSamplerDoesNotCrash_OpenGLES.png
|
||||
impeller_Play_AiksTest_RuntimeEffectWithInvalidSamplerDoesNotCrash_Vulkan.png
|
||||
impeller_Play_AiksTest_SaveLayerDrawsBehindSubsequentEntities_Metal.png
|
||||
impeller_Play_AiksTest_SaveLayerDrawsBehindSubsequentEntities_OpenGLES.png
|
||||
impeller_Play_AiksTest_SaveLayerDrawsBehindSubsequentEntities_Vulkan.png
|
||||
|
||||
Reference in New Issue
Block a user