Let pushColorFilter accept all types of ColorFilters (flutter/engine#9641)
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
ColorFilterLayer::ColorFilterLayer(SkColor color, SkBlendMode blend_mode)
|
||||
: color_(color), blend_mode_(blend_mode) {}
|
||||
ColorFilterLayer::ColorFilterLayer(sk_sp<SkColorFilter> filter)
|
||||
: filter_(std::move(filter)) {}
|
||||
|
||||
ColorFilterLayer::~ColorFilterLayer() = default;
|
||||
|
||||
@@ -16,7 +16,7 @@ void ColorFilterLayer::Paint(PaintContext& context) const {
|
||||
FML_DCHECK(needs_painting());
|
||||
|
||||
SkPaint paint;
|
||||
paint.setColorFilter(SkColorFilters::Blend(color_, blend_mode_));
|
||||
paint.setColorFilter(filter_);
|
||||
|
||||
Layer::AutoSaveLayer save =
|
||||
Layer::AutoSaveLayer::Create(context, paint_bounds(), &paint);
|
||||
|
||||
@@ -7,18 +7,19 @@
|
||||
|
||||
#include "flutter/flow/layers/container_layer.h"
|
||||
|
||||
#include "third_party/skia/include/core/SkColorFilter.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class ColorFilterLayer : public ContainerLayer {
|
||||
public:
|
||||
ColorFilterLayer(SkColor color, SkBlendMode blend_mode);
|
||||
ColorFilterLayer(sk_sp<SkColorFilter> filter);
|
||||
~ColorFilterLayer() override;
|
||||
|
||||
void Paint(PaintContext& context) const override;
|
||||
|
||||
private:
|
||||
SkColor color_;
|
||||
SkBlendMode blend_mode_;
|
||||
sk_sp<SkColorFilter> filter_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ColorFilterLayer);
|
||||
};
|
||||
|
||||
@@ -387,13 +387,14 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
|
||||
/// {@macro dart.ui.sceneBuilder.oldLayerVsRetained}
|
||||
///
|
||||
/// See [pop] for details about the operation stack.
|
||||
ColorFilterEngineLayer pushColorFilter(Color color, BlendMode blendMode, { ColorFilterEngineLayer oldLayer }) {
|
||||
ColorFilterEngineLayer pushColorFilter(ColorFilter filter, { ColorFilterEngineLayer oldLayer }) {
|
||||
assert(filter != null);
|
||||
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushColorFilter'));
|
||||
final ColorFilterEngineLayer layer = ColorFilterEngineLayer._(_pushColorFilter(color.value, blendMode.index));
|
||||
final ColorFilterEngineLayer layer = ColorFilterEngineLayer._(_pushColorFilter(filter._toNativeColorFilter()));
|
||||
assert(_debugPushLayer(layer));
|
||||
return layer;
|
||||
}
|
||||
EngineLayer _pushColorFilter(int color, int blendMode) native 'SceneBuilder_pushColorFilter';
|
||||
EngineLayer _pushColorFilter(_ColorFilter filter) native 'SceneBuilder_pushColorFilter';
|
||||
|
||||
/// Pushes a backdrop filter operation onto the operation stack.
|
||||
///
|
||||
|
||||
@@ -141,10 +141,10 @@ fml::RefPtr<EngineLayer> SceneBuilder::pushOpacity(int alpha,
|
||||
return EngineLayer::MakeRetained(layer);
|
||||
}
|
||||
|
||||
fml::RefPtr<EngineLayer> SceneBuilder::pushColorFilter(int color,
|
||||
int blendMode) {
|
||||
auto layer = std::make_shared<flutter::ColorFilterLayer>(
|
||||
static_cast<SkColor>(color), static_cast<SkBlendMode>(blendMode));
|
||||
fml::RefPtr<EngineLayer> SceneBuilder::pushColorFilter(
|
||||
const ColorFilter* color_filter) {
|
||||
auto layer =
|
||||
std::make_shared<flutter::ColorFilterLayer>(color_filter->filter());
|
||||
PushLayer(layer);
|
||||
return EngineLayer::MakeRetained(layer);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "flutter/lib/ui/compositing/scene.h"
|
||||
#include "flutter/lib/ui/dart_wrapper.h"
|
||||
#include "flutter/lib/ui/painting/color_filter.h"
|
||||
#include "flutter/lib/ui/painting/engine_layer.h"
|
||||
#include "flutter/lib/ui/painting/image_filter.h"
|
||||
#include "flutter/lib/ui/painting/path.h"
|
||||
@@ -48,7 +49,7 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
|
||||
fml::RefPtr<EngineLayer> pushClipPath(const CanvasPath* path,
|
||||
int clipBehavior);
|
||||
fml::RefPtr<EngineLayer> pushOpacity(int alpha, double dx = 0, double dy = 0);
|
||||
fml::RefPtr<EngineLayer> pushColorFilter(int color, int blendMode);
|
||||
fml::RefPtr<EngineLayer> pushColorFilter(const ColorFilter* color_filter);
|
||||
fml::RefPtr<EngineLayer> pushBackdropFilter(ImageFilter* filter);
|
||||
fml::RefPtr<EngineLayer> pushShaderMask(Shader* shader,
|
||||
double maskRectLeft,
|
||||
|
||||
@@ -2500,8 +2500,8 @@ class ColorFilter {
|
||||
/// matrix is in row-major order and the translation column is specified in
|
||||
/// unnormalized, 0...255, space.
|
||||
const ColorFilter.matrix(List<double> matrix)
|
||||
: assert(matrix != null),
|
||||
assert(matrix.length == 20),
|
||||
: assert(matrix != null, 'Color Matrix argument was null.'),
|
||||
assert(matrix.length == 20, 'Color Matrix must have 20 entries.'),
|
||||
_color = null,
|
||||
_blendMode = null,
|
||||
_matrix = matrix,
|
||||
|
||||
@@ -273,9 +273,6 @@ void main() {
|
||||
testNoSharing((SceneBuilder builder, EngineLayer oldLayer) {
|
||||
return builder.pushOpacity(100, oldLayer: oldLayer);
|
||||
});
|
||||
testNoSharing((SceneBuilder builder, EngineLayer oldLayer) {
|
||||
return builder.pushColorFilter(const Color.fromARGB(0, 0, 0, 0), BlendMode.color, oldLayer: oldLayer);
|
||||
});
|
||||
testNoSharing((SceneBuilder builder, EngineLayer oldLayer) {
|
||||
return builder.pushBackdropFilter(ImageFilter.blur(), oldLayer: oldLayer);
|
||||
});
|
||||
@@ -294,6 +291,38 @@ void main() {
|
||||
testNoSharing((SceneBuilder builder, EngineLayer oldLayer) {
|
||||
return builder.pushPhysicalShape(path: Path(), color: const Color.fromARGB(0, 0, 0, 0), oldLayer: oldLayer);
|
||||
});
|
||||
testNoSharing((SceneBuilder builder, EngineLayer oldLayer) {
|
||||
return builder.pushColorFilter(
|
||||
const ColorFilter.mode(
|
||||
Color.fromARGB(0, 0, 0, 0),
|
||||
BlendMode.color,
|
||||
),
|
||||
oldLayer: oldLayer,
|
||||
);
|
||||
});
|
||||
testNoSharing((SceneBuilder builder, EngineLayer oldLayer) {
|
||||
return builder.pushColorFilter(
|
||||
const ColorFilter.matrix(<double>[
|
||||
1, 0, 0, 0, 0,
|
||||
0, 1, 0, 0, 0,
|
||||
0, 0, 1, 0, 0,
|
||||
0, 0, 0, 1, 0,
|
||||
]),
|
||||
oldLayer: oldLayer,
|
||||
);
|
||||
});
|
||||
testNoSharing((SceneBuilder builder, EngineLayer oldLayer) {
|
||||
return builder.pushColorFilter(
|
||||
const ColorFilter.linearToSrgbGamma(),
|
||||
oldLayer: oldLayer,
|
||||
);
|
||||
});
|
||||
testNoSharing((SceneBuilder builder, EngineLayer oldLayer) {
|
||||
return builder.pushColorFilter(
|
||||
const ColorFilter.srgbToLinearGamma(),
|
||||
oldLayer: oldLayer,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user