mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Make DisplayList DispatchHelpers prevent against extra restore calls (flutter/engine#34247)
This commit is contained in:
parent
a4bd8e47ca
commit
b2861bd9b7
@ -107,6 +107,7 @@ FILE: ../../../flutter/display_list/display_list_tile_mode.h
|
||||
FILE: ../../../flutter/display_list/display_list_unittests.cc
|
||||
FILE: ../../../flutter/display_list/display_list_utils.cc
|
||||
FILE: ../../../flutter/display_list/display_list_utils.h
|
||||
FILE: ../../../flutter/display_list/display_list_utils_unittests.cc
|
||||
FILE: ../../../flutter/display_list/display_list_vertices.cc
|
||||
FILE: ../../../flutter/display_list/display_list_vertices.h
|
||||
FILE: ../../../flutter/display_list/display_list_vertices_unittests.cc
|
||||
|
||||
@ -99,6 +99,7 @@ if (enable_unittests) {
|
||||
"display_list_paint_unittests.cc",
|
||||
"display_list_path_effect_unittests.cc",
|
||||
"display_list_unittests.cc",
|
||||
"display_list_utils_unittests.cc",
|
||||
"display_list_vertices_unittests.cc",
|
||||
]
|
||||
|
||||
|
||||
@ -33,6 +33,9 @@ void SkPaintDispatchHelper::save_opacity(SkScalar child_opacity) {
|
||||
set_opacity(child_opacity);
|
||||
}
|
||||
void SkPaintDispatchHelper::restore_opacity() {
|
||||
if (save_stack_.empty()) {
|
||||
return;
|
||||
}
|
||||
set_opacity(save_stack_.back().opacity);
|
||||
save_stack_.pop_back();
|
||||
}
|
||||
@ -163,6 +166,9 @@ void SkMatrixDispatchHelper::save() {
|
||||
saved_.push_back(matrix_);
|
||||
}
|
||||
void SkMatrixDispatchHelper::restore() {
|
||||
if (saved_.empty()) {
|
||||
return;
|
||||
}
|
||||
matrix_ = saved_.back();
|
||||
matrix33_ = matrix_.asM33();
|
||||
saved_.pop_back();
|
||||
@ -233,6 +239,9 @@ void ClipBoundsDispatchHelper::save() {
|
||||
}
|
||||
}
|
||||
void ClipBoundsDispatchHelper::restore() {
|
||||
if (saved_.empty()) {
|
||||
return;
|
||||
}
|
||||
bounds_ = saved_.back();
|
||||
saved_.pop_back();
|
||||
has_clip_ = (bounds_.fLeft <= bounds_.fRight && //
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/display_list/display_list_utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
class MockDispatchHelper final : public virtual Dispatcher,
|
||||
public virtual SkPaintDispatchHelper,
|
||||
public virtual SkMatrixDispatchHelper,
|
||||
public virtual ClipBoundsDispatchHelper,
|
||||
public virtual IgnoreDrawDispatchHelper {
|
||||
public:
|
||||
void save() override {
|
||||
SkPaintDispatchHelper::save_opacity(0.5f);
|
||||
SkMatrixDispatchHelper::save();
|
||||
ClipBoundsDispatchHelper::save();
|
||||
}
|
||||
|
||||
void restore() override {
|
||||
SkPaintDispatchHelper::restore_opacity();
|
||||
SkMatrixDispatchHelper::restore();
|
||||
ClipBoundsDispatchHelper::restore();
|
||||
}
|
||||
};
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/100176.
|
||||
TEST(DisplayListUtils, OverRestore) {
|
||||
MockDispatchHelper helper;
|
||||
helper.save();
|
||||
helper.restore();
|
||||
// There should be a protection here for over-restore to keep the program from
|
||||
// crashing.
|
||||
helper.restore();
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
Loading…
x
Reference in New Issue
Block a user