forked from firka/flutter
iOS platform view opacity (flutter/engine#9667)
This commit is contained in:
@@ -30,6 +30,11 @@ void MutatorsStack::PushTransform(const SkMatrix& matrix) {
|
||||
vector_.push_back(element);
|
||||
};
|
||||
|
||||
void MutatorsStack::PushOpacity(const int& alpha) {
|
||||
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(alpha);
|
||||
vector_.push_back(element);
|
||||
};
|
||||
|
||||
void MutatorsStack::Pop() {
|
||||
vector_.pop_back();
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
enum MutatorType { clip_rect, clip_rrect, clip_path, transform };
|
||||
enum MutatorType { clip_rect, clip_rrect, clip_path, transform, opacity };
|
||||
|
||||
// Stores mutation information like clipping or transform.
|
||||
//
|
||||
@@ -42,6 +42,9 @@ class Mutator {
|
||||
case transform:
|
||||
matrix_ = other.matrix_;
|
||||
break;
|
||||
case opacity:
|
||||
alpha_ = other.alpha_;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -53,12 +56,15 @@ class Mutator {
|
||||
: type_(clip_path), path_(new SkPath(path)) {}
|
||||
explicit Mutator(const SkMatrix& matrix)
|
||||
: type_(transform), matrix_(matrix) {}
|
||||
explicit Mutator(const int& alpha) : type_(opacity), alpha_(alpha) {}
|
||||
|
||||
const MutatorType& GetType() const { return type_; }
|
||||
const SkRect& GetRect() const { return rect_; }
|
||||
const SkRRect& GetRRect() const { return rrect_; }
|
||||
const SkPath& GetPath() const { return *path_; }
|
||||
const SkMatrix& GetMatrix() const { return matrix_; }
|
||||
const int& GetAlpha() const { return alpha_; }
|
||||
float GetAlphaFloat() const { return (alpha_ / 255.0); }
|
||||
|
||||
bool operator==(const Mutator& other) const {
|
||||
if (type_ != other.type_) {
|
||||
@@ -73,6 +79,8 @@ class Mutator {
|
||||
return *path_ == *other.path_;
|
||||
case transform:
|
||||
return matrix_ == other.matrix_;
|
||||
case opacity:
|
||||
return alpha_ == other.alpha_;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -98,6 +106,7 @@ class Mutator {
|
||||
SkRRect rrect_;
|
||||
SkMatrix matrix_;
|
||||
SkPath* path_;
|
||||
int alpha_;
|
||||
};
|
||||
|
||||
}; // Mutator
|
||||
@@ -119,6 +128,7 @@ class MutatorsStack {
|
||||
void PushClipRRect(const SkRRect& rrect);
|
||||
void PushClipPath(const SkPath& path);
|
||||
void PushTransform(const SkMatrix& matrix);
|
||||
void PushOpacity(const int& alpha);
|
||||
|
||||
// Removes the `Mutator` on the top of the stack
|
||||
// and destroys it.
|
||||
|
||||
@@ -37,7 +37,12 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
EnsureSingleChild();
|
||||
SkMatrix child_matrix = matrix;
|
||||
child_matrix.postTranslate(offset_.fX, offset_.fY);
|
||||
context->mutators_stack.PushTransform(
|
||||
SkMatrix::MakeTrans(offset_.fX, offset_.fY));
|
||||
context->mutators_stack.PushOpacity(alpha_);
|
||||
ContainerLayer::Preroll(context, child_matrix);
|
||||
context->mutators_stack.Pop();
|
||||
context->mutators_stack.Pop();
|
||||
set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY));
|
||||
// See |EnsureSingleChild|.
|
||||
FML_DCHECK(layers().size() == 1);
|
||||
|
||||
@@ -42,7 +42,7 @@ TEST(MutatorsStack, PushClipRRect) {
|
||||
}
|
||||
|
||||
TEST(MutatorsStack, PushClipPath) {
|
||||
flutter::MutatorsStack stack;
|
||||
MutatorsStack stack;
|
||||
SkPath path;
|
||||
stack.PushClipPath(path);
|
||||
auto iter = stack.Bottom();
|
||||
@@ -60,6 +60,15 @@ TEST(MutatorsStack, PushTransform) {
|
||||
ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
|
||||
}
|
||||
|
||||
TEST(MutatorsStack, PushOpacity) {
|
||||
MutatorsStack stack;
|
||||
int alpha = 240;
|
||||
stack.PushOpacity(alpha);
|
||||
auto iter = stack.Bottom();
|
||||
ASSERT_TRUE(iter->get()->GetType() == MutatorType::opacity);
|
||||
ASSERT_TRUE(iter->get()->GetAlpha() == 240);
|
||||
}
|
||||
|
||||
TEST(MutatorsStack, Pop) {
|
||||
MutatorsStack stack;
|
||||
SkMatrix matrix;
|
||||
@@ -113,6 +122,8 @@ TEST(MutatorsStack, Equality) {
|
||||
stack.PushClipRRect(rrect);
|
||||
SkPath path;
|
||||
stack.PushClipPath(path);
|
||||
int alpha = 240;
|
||||
stack.PushOpacity(alpha);
|
||||
|
||||
MutatorsStack stackOther;
|
||||
SkMatrix matrixOther = SkMatrix::MakeScale(1, 1);
|
||||
@@ -123,6 +134,8 @@ TEST(MutatorsStack, Equality) {
|
||||
stackOther.PushClipRRect(rrectOther);
|
||||
SkPath otherPath;
|
||||
stackOther.PushClipPath(otherPath);
|
||||
int otherAlpha = 240;
|
||||
stackOther.PushOpacity(otherAlpha);
|
||||
|
||||
ASSERT_TRUE(stack == stackOther);
|
||||
}
|
||||
@@ -148,6 +161,10 @@ TEST(Mutator, Initialization) {
|
||||
Mutator mutator4 = Mutator(matrix);
|
||||
ASSERT_TRUE(mutator4.GetType() == MutatorType::transform);
|
||||
ASSERT_TRUE(mutator4.GetMatrix() == matrix);
|
||||
|
||||
int alpha = 240;
|
||||
Mutator mutator5 = Mutator(alpha);
|
||||
ASSERT_TRUE(mutator5.GetType() == MutatorType::opacity);
|
||||
}
|
||||
|
||||
TEST(Mutator, CopyConstructor) {
|
||||
@@ -171,6 +188,11 @@ TEST(Mutator, CopyConstructor) {
|
||||
Mutator mutator4 = Mutator(matrix);
|
||||
Mutator copy4 = Mutator(mutator4);
|
||||
ASSERT_TRUE(mutator4 == copy4);
|
||||
|
||||
int alpha = 240;
|
||||
Mutator mutator5 = Mutator(alpha);
|
||||
Mutator copy5 = Mutator(mutator5);
|
||||
ASSERT_TRUE(mutator5 == copy5);
|
||||
}
|
||||
|
||||
TEST(Mutator, Equality) {
|
||||
@@ -195,6 +217,10 @@ TEST(Mutator, Equality) {
|
||||
flutter::Mutator otherMutator4 = flutter::Mutator(path);
|
||||
ASSERT_TRUE(mutator4 == otherMutator4);
|
||||
ASSERT_FALSE(mutator2 == mutator);
|
||||
int alpha = 240;
|
||||
Mutator mutator5 = Mutator(alpha);
|
||||
Mutator otherMutator5 = Mutator(alpha);
|
||||
ASSERT_TRUE(mutator5 == otherMutator5);
|
||||
}
|
||||
|
||||
TEST(Mutator, UnEquality) {
|
||||
@@ -204,6 +230,12 @@ TEST(Mutator, UnEquality) {
|
||||
matrix.setIdentity();
|
||||
Mutator notEqualMutator = Mutator(matrix);
|
||||
ASSERT_TRUE(notEqualMutator != mutator);
|
||||
|
||||
int alpha = 240;
|
||||
int alpha2 = 241;
|
||||
Mutator mutator2 = Mutator(alpha);
|
||||
Mutator otherMutator2 = Mutator(alpha2);
|
||||
ASSERT_TRUE(mutator2 != otherMutator2);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
@@ -278,6 +278,9 @@ void FlutterPlatformViewsController::ApplyMutators(const MutatorsStack& mutators
|
||||
head = clipView;
|
||||
break;
|
||||
}
|
||||
case opacity:
|
||||
embedded_view.alpha = (*iter)->GetAlphaFloat() * embedded_view.alpha;
|
||||
break;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
@@ -299,6 +302,7 @@ void FlutterPlatformViewsController::CompositeWithParams(int view_id,
|
||||
UIView* touchInterceptor = touch_interceptors_[view_id].get();
|
||||
touchInterceptor.layer.transform = CATransform3DIdentity;
|
||||
touchInterceptor.frame = frame;
|
||||
touchInterceptor.alpha = 1;
|
||||
|
||||
int currentClippingCount = CountClips(params.mutatorsStack);
|
||||
int previousClippingCount = clip_count_[view_id];
|
||||
|
||||
Reference in New Issue
Block a user