Reverts "[skwasm] use temporary RawPaint objects (#54917)" (flutter/engine#55018)
Reverts: flutter/engine#54917 Initiated by: jonahwilliams Reason for reverting: failing on framework -> engine roll https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20web_skwasm_tests_7_last/10571/overview Original PR Author: yjbanov Reviewed By: {eyebrowsoffire} This change reverts the following previous change: Same as https://github.com/flutter/engine/pull/54818, but for Skwasm. Addresses the `Paint` issue in https://github.com/flutter/flutter/issues/153678 in Skwasm
This commit is contained in:
@@ -29,29 +29,27 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
|
||||
@override
|
||||
void saveLayer(ui.Rect? bounds, ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
paint as SkwasmPaint;
|
||||
if (bounds != null) {
|
||||
withStackScope((StackScope s) {
|
||||
canvasSaveLayer(_handle, s.convertRectToNative(bounds), paintHandle, nullptr);
|
||||
canvasSaveLayer(_handle, s.convertRectToNative(bounds), paint.handle, nullptr);
|
||||
});
|
||||
} else {
|
||||
canvasSaveLayer(_handle, nullptr, paintHandle, nullptr);
|
||||
canvasSaveLayer(_handle, nullptr, paint.handle, nullptr);
|
||||
}
|
||||
paintDispose(paintHandle);
|
||||
}
|
||||
|
||||
@override
|
||||
void saveLayerWithFilter(ui.Rect? bounds, ui.Paint paint, ui.ImageFilter imageFilter) {
|
||||
final SkwasmImageFilter nativeFilter = SkwasmImageFilter.fromUiFilter(imageFilter);
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
paint as SkwasmPaint;
|
||||
if (bounds != null) {
|
||||
withStackScope((StackScope s) {
|
||||
canvasSaveLayer(_handle, s.convertRectToNative(bounds), paintHandle, nativeFilter.handle);
|
||||
canvasSaveLayer(_handle, s.convertRectToNative(bounds), paint.handle, nativeFilter.handle);
|
||||
});
|
||||
} else {
|
||||
canvasSaveLayer(_handle, nullptr, paintHandle, nativeFilter.handle);
|
||||
canvasSaveLayer(_handle, nullptr, paint.handle, nativeFilter.handle);
|
||||
}
|
||||
paintDispose(paintHandle);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -113,78 +111,71 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
|
||||
@override
|
||||
void drawLine(ui.Offset p1, ui.Offset p2, ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawLine(_handle, p1.dx, p1.dy, p2.dx, p2.dy, paintHandle);
|
||||
paintDispose(paintHandle);
|
||||
paint as SkwasmPaint;
|
||||
canvasDrawLine(_handle, p1.dx, p1.dy, p2.dx, p2.dy, paint.handle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawPaint(ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawPaint(_handle, paintHandle);
|
||||
paintDispose(paintHandle);
|
||||
paint as SkwasmPaint;
|
||||
canvasDrawPaint(_handle, paint.handle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawRect(ui.Rect rect, ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
paint as SkwasmPaint;
|
||||
withStackScope((StackScope s) {
|
||||
canvasDrawRect(
|
||||
_handle,
|
||||
s.convertRectToNative(rect),
|
||||
paintHandle
|
||||
paint.handle
|
||||
);
|
||||
});
|
||||
paintDispose(paintHandle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawRRect(ui.RRect rrect, ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
paint as SkwasmPaint;
|
||||
withStackScope((StackScope s) {
|
||||
canvasDrawRRect(
|
||||
_handle,
|
||||
s.convertRRectToNative(rrect),
|
||||
paintHandle
|
||||
paint.handle
|
||||
);
|
||||
});
|
||||
paintDispose(paintHandle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawDRRect(ui.RRect outer, ui.RRect inner, ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
paint as SkwasmPaint;
|
||||
withStackScope((StackScope s) {
|
||||
canvasDrawDRRect(
|
||||
_handle,
|
||||
s.convertRRectToNative(outer),
|
||||
s.convertRRectToNative(inner),
|
||||
paintHandle
|
||||
paint.handle
|
||||
);
|
||||
});
|
||||
paintDispose(paintHandle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawOval(ui.Rect rect, ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
paint as SkwasmPaint;
|
||||
withStackScope((StackScope s) {
|
||||
canvasDrawOval(_handle, s.convertRectToNative(rect), paintHandle);
|
||||
canvasDrawOval(_handle, s.convertRectToNative(rect), paint.handle);
|
||||
});
|
||||
paintDispose(paintHandle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawCircle(ui.Offset center, double radius, ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawCircle(_handle, center.dx, center.dy, radius, paintHandle);
|
||||
paintDispose(paintHandle);
|
||||
paint as SkwasmPaint;
|
||||
canvasDrawCircle(_handle, center.dx, center.dy, radius, paint.handle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawArc(ui.Rect rect, double startAngle, double sweepAngle,
|
||||
bool useCenter, ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
paint as SkwasmPaint;
|
||||
withStackScope((StackScope s) {
|
||||
canvasDrawArc(
|
||||
_handle,
|
||||
@@ -192,79 +183,64 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
ui.toDegrees(startAngle),
|
||||
ui.toDegrees(sweepAngle),
|
||||
useCenter,
|
||||
paintHandle,
|
||||
paint.handle
|
||||
);
|
||||
});
|
||||
paintDispose(paintHandle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawPath(ui.Path path, ui.Paint paint) {
|
||||
paint as SkwasmPaint;
|
||||
path as SkwasmPath;
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawPath(_handle, path.handle, paintHandle);
|
||||
paintDispose(paintHandle);
|
||||
canvasDrawPath(_handle, path.handle, paint.handle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawImage(ui.Image image, ui.Offset offset, ui.Paint paint) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
void drawImage(ui.Image image, ui.Offset offset, ui.Paint paint) =>
|
||||
canvasDrawImage(
|
||||
_handle,
|
||||
(image as SkwasmImage).handle,
|
||||
offset.dx,
|
||||
offset.dy,
|
||||
paintHandle,
|
||||
(paint as SkwasmPaint).handle,
|
||||
paint.filterQuality.index,
|
||||
);
|
||||
paintDispose(paintHandle);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawImageRect(
|
||||
ui.Image image,
|
||||
ui.Rect src,
|
||||
ui.Rect dst,
|
||||
ui.Paint paint,
|
||||
) {
|
||||
withStackScope((StackScope scope) {
|
||||
final Pointer<Float> sourceRect = scope.convertRectToNative(src);
|
||||
final Pointer<Float> destRect = scope.convertRectToNative(dst);
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawImageRect(
|
||||
_handle,
|
||||
(image as SkwasmImage).handle,
|
||||
sourceRect,
|
||||
destRect,
|
||||
paintHandle,
|
||||
paint.filterQuality.index,
|
||||
);
|
||||
paintDispose(paintHandle);
|
||||
});
|
||||
}
|
||||
ui.Paint paint) => withStackScope((StackScope scope) {
|
||||
final Pointer<Float> sourceRect = scope.convertRectToNative(src);
|
||||
final Pointer<Float> destRect = scope.convertRectToNative(dst);
|
||||
canvasDrawImageRect(
|
||||
_handle,
|
||||
(image as SkwasmImage).handle,
|
||||
sourceRect,
|
||||
destRect,
|
||||
(paint as SkwasmPaint).handle,
|
||||
paint.filterQuality.index,
|
||||
);
|
||||
});
|
||||
|
||||
@override
|
||||
void drawImageNine(
|
||||
ui.Image image,
|
||||
ui.Rect center,
|
||||
ui.Rect dst,
|
||||
ui.Paint paint,
|
||||
) {
|
||||
withStackScope((StackScope scope) {
|
||||
final Pointer<Int32> centerRect = scope.convertIRectToNative(center);
|
||||
final Pointer<Float> destRect = scope.convertRectToNative(dst);
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawImageNine(
|
||||
_handle,
|
||||
(image as SkwasmImage).handle,
|
||||
centerRect,
|
||||
destRect,
|
||||
paintHandle,
|
||||
paint.filterQuality.index,
|
||||
);
|
||||
paintDispose(paintHandle);
|
||||
});
|
||||
}
|
||||
ui.Paint paint) => withStackScope((StackScope scope) {
|
||||
final Pointer<Int32> centerRect = scope.convertIRectToNative(center);
|
||||
final Pointer<Float> destRect = scope.convertRectToNative(dst);
|
||||
canvasDrawImageNine(
|
||||
_handle,
|
||||
(image as SkwasmImage).handle,
|
||||
centerRect,
|
||||
destRect,
|
||||
(paint as SkwasmPaint).handle,
|
||||
paint.filterQuality.index,
|
||||
);
|
||||
});
|
||||
|
||||
@override
|
||||
void drawPicture(ui.Picture picture) {
|
||||
@@ -288,15 +264,13 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
ui.Paint paint
|
||||
) => withStackScope((StackScope scope) {
|
||||
final RawPointArray rawPoints = scope.convertPointArrayToNative(points);
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawPoints(
|
||||
_handle,
|
||||
pointMode.index,
|
||||
rawPoints,
|
||||
points.length,
|
||||
paintHandle,
|
||||
(paint as SkwasmPaint).handle,
|
||||
);
|
||||
paintDispose(paintHandle);
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -306,15 +280,13 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
ui.Paint paint
|
||||
) => withStackScope((StackScope scope) {
|
||||
final RawPointArray rawPoints = scope.convertDoublesToNative(points);
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawPoints(
|
||||
_handle,
|
||||
pointMode.index,
|
||||
rawPoints,
|
||||
points.length ~/ 2,
|
||||
paintHandle,
|
||||
(paint as SkwasmPaint).handle,
|
||||
);
|
||||
paintDispose(paintHandle);
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -322,16 +294,12 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
ui.Vertices vertices,
|
||||
ui.BlendMode blendMode,
|
||||
ui.Paint paint,
|
||||
) {
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawVertices(
|
||||
_handle,
|
||||
(vertices as SkwasmVertices).handle,
|
||||
blendMode.index,
|
||||
paintHandle,
|
||||
);
|
||||
paintDispose(paintHandle);
|
||||
}
|
||||
) => canvasDrawVertices(
|
||||
_handle,
|
||||
(vertices as SkwasmVertices).handle,
|
||||
blendMode.index,
|
||||
(paint as SkwasmPaint).handle,
|
||||
);
|
||||
|
||||
@override
|
||||
void drawAtlas(
|
||||
@@ -351,7 +319,6 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
final RawRect rawCullRect = cullRect != null
|
||||
? scope.convertRectToNative(cullRect)
|
||||
: nullptr;
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawAtlas(
|
||||
_handle,
|
||||
(atlas as SkwasmImage).handle,
|
||||
@@ -361,9 +328,8 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
transforms.length,
|
||||
(blendMode ?? ui.BlendMode.src).index,
|
||||
rawCullRect,
|
||||
paintHandle,
|
||||
(paint as SkwasmPaint).handle,
|
||||
);
|
||||
paintDispose(paintHandle);
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -384,7 +350,6 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
final RawRect rawCullRect = cullRect != null
|
||||
? scope.convertRectToNative(cullRect)
|
||||
: nullptr;
|
||||
final paintHandle = (paint as SkwasmPaint).toRawPaint();
|
||||
canvasDrawAtlas(
|
||||
_handle,
|
||||
(atlas as SkwasmImage).handle,
|
||||
@@ -394,9 +359,8 @@ class SkwasmCanvas implements SceneCanvas {
|
||||
rstTransforms.length ~/ 4,
|
||||
(blendMode ?? ui.BlendMode.src).index,
|
||||
rawCullRect,
|
||||
paintHandle,
|
||||
(paint as SkwasmPaint).handle,
|
||||
);
|
||||
paintDispose(paintHandle);
|
||||
});
|
||||
|
||||
@override
|
||||
|
||||
@@ -8,73 +8,31 @@ import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/src/engine/skwasm/skwasm_impl.dart';
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
class SkwasmPaint implements ui.Paint {
|
||||
SkwasmPaint();
|
||||
class SkwasmPaint extends SkwasmObjectWrapper<RawPaint> implements ui.Paint {
|
||||
SkwasmPaint() : super(paintCreate(), _registry);
|
||||
|
||||
/// Creates the C++ side paint object based on the current state of this
|
||||
/// paint object, and returns it with ownership.
|
||||
///
|
||||
/// It is the responsibility of the caller to dispose of the returned handle
|
||||
/// when it's no longer needed.
|
||||
PaintHandle toRawPaint() {
|
||||
final rawPaint = paintCreate(
|
||||
isAntiAlias,
|
||||
blendMode.index,
|
||||
_colorValue,
|
||||
style.index,
|
||||
strokeWidth,
|
||||
strokeCap.index,
|
||||
strokeJoin.index,
|
||||
strokeMiterLimit,
|
||||
);
|
||||
// Must be kept in sync with the default in paint.cc.
|
||||
static const double _kStrokeMiterLimitDefault = 4.0;
|
||||
|
||||
_maybeSetEffectiveColorFilter(rawPaint);
|
||||
// Must be kept in sync with the default in paint.cc.
|
||||
static const int _kColorDefault = 0xFF000000;
|
||||
|
||||
final shaderHandle = _shader?.handle;
|
||||
if (shaderHandle != null) {
|
||||
paintSetShader(rawPaint, shaderHandle);
|
||||
}
|
||||
// Must be kept in sync with the default in paint.cc.
|
||||
static final int _kBlendModeDefault = ui.BlendMode.srcOver.index;
|
||||
|
||||
final localMaskFilter = maskFilter;
|
||||
if (localMaskFilter != null) {
|
||||
final nativeFilter = SkwasmMaskFilter.fromUiMaskFilter(localMaskFilter);
|
||||
paintSetMaskFilter(rawPaint, nativeFilter.handle);
|
||||
nativeFilter.dispose();
|
||||
}
|
||||
static final SkwasmFinalizationRegistry<RawPaint> _registry =
|
||||
SkwasmFinalizationRegistry<RawPaint>(paintDispose);
|
||||
|
||||
final filter = imageFilter;
|
||||
if (filter != null) {
|
||||
final nativeImageFilter = SkwasmImageFilter.fromUiFilter(filter);
|
||||
paintSetImageFilter(rawPaint, nativeImageFilter.handle);
|
||||
nativeImageFilter.dispose();
|
||||
}
|
||||
ui.BlendMode _cachedBlendMode = ui.BlendMode.srcOver;
|
||||
|
||||
return rawPaint;
|
||||
}
|
||||
SkwasmShader? _shader;
|
||||
ui.ImageFilter? _imageFilter;
|
||||
|
||||
/// If `invertColors` is true or `colorFilter` is not null, sets the
|
||||
/// appropriate Skia color filter. Otherwise, does nothing.
|
||||
void _maybeSetEffectiveColorFilter(Pointer<RawPaint> handle) {
|
||||
final nativeFilter = _colorFilter != null
|
||||
? SkwasmColorFilter.fromEngineColorFilter(_colorFilter!)
|
||||
: null;
|
||||
if (invertColors) {
|
||||
if (nativeFilter != null) {
|
||||
final composedFilter = SkwasmColorFilter.composed(
|
||||
_invertColorFilter,
|
||||
nativeFilter,
|
||||
);
|
||||
nativeFilter.dispose();
|
||||
paintSetColorFilter(handle, composedFilter.handle);
|
||||
composedFilter.dispose();
|
||||
} else {
|
||||
paintSetColorFilter(handle, _invertColorFilter.handle);
|
||||
}
|
||||
} else if (nativeFilter != null) {
|
||||
paintSetColorFilter(handle, nativeFilter.handle);
|
||||
nativeFilter.dispose();
|
||||
}
|
||||
}
|
||||
EngineColorFilter? _colorFilter;
|
||||
|
||||
ui.MaskFilter? _maskFilter;
|
||||
|
||||
bool _invertColors = false;
|
||||
|
||||
static final SkwasmColorFilter _invertColorFilter = SkwasmColorFilter.fromEngineColorFilter(
|
||||
const EngineColorFilter.matrix(<double>[
|
||||
@@ -86,71 +44,143 @@ class SkwasmPaint implements ui.Paint {
|
||||
);
|
||||
|
||||
@override
|
||||
ui.BlendMode blendMode = _kBlendModeDefault;
|
||||
|
||||
// Must be kept in sync with the default in paint.cc.
|
||||
static const ui.BlendMode _kBlendModeDefault = ui.BlendMode.srcOver;
|
||||
|
||||
@override
|
||||
ui.PaintingStyle style = ui.PaintingStyle.fill;
|
||||
|
||||
@override
|
||||
double strokeWidth = 0.0;
|
||||
|
||||
@override
|
||||
ui.StrokeCap strokeCap = ui.StrokeCap.butt;
|
||||
|
||||
@override
|
||||
ui.StrokeJoin strokeJoin = ui.StrokeJoin.miter;
|
||||
|
||||
@override
|
||||
bool isAntiAlias = true;
|
||||
|
||||
@override
|
||||
ui.Color get color => ui.Color(_colorValue);
|
||||
@override
|
||||
set color(ui.Color value) {
|
||||
_colorValue = value.value;
|
||||
ui.BlendMode get blendMode {
|
||||
return _cachedBlendMode;
|
||||
}
|
||||
|
||||
static const int _kColorDefault = 0xFF000000;
|
||||
int _colorValue = _kColorDefault;
|
||||
@override
|
||||
set blendMode(ui.BlendMode blendMode) {
|
||||
if (_cachedBlendMode != blendMode) {
|
||||
_cachedBlendMode = blendMode;
|
||||
paintSetBlendMode(handle, blendMode.index);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
double strokeMiterLimit = _kStrokeMiterLimitDefault;
|
||||
static const double _kStrokeMiterLimitDefault = 4.0;
|
||||
ui.PaintingStyle get style => ui.PaintingStyle.values[paintGetStyle(handle)];
|
||||
|
||||
@override
|
||||
set style(ui.PaintingStyle style) => paintSetStyle(handle, style.index);
|
||||
|
||||
@override
|
||||
double get strokeWidth => paintGetStrokeWidth(handle);
|
||||
|
||||
@override
|
||||
set strokeWidth(double width) => paintSetStrokeWidth(handle, width);
|
||||
|
||||
@override
|
||||
ui.StrokeCap get strokeCap => ui.StrokeCap.values[paintGetStrokeCap(handle)];
|
||||
|
||||
@override
|
||||
set strokeCap(ui.StrokeCap cap) => paintSetStrokeCap(handle, cap.index);
|
||||
|
||||
@override
|
||||
ui.StrokeJoin get strokeJoin => ui.StrokeJoin.values[paintGetStrokeJoin(handle)];
|
||||
|
||||
@override
|
||||
set strokeJoin(ui.StrokeJoin join) => paintSetStrokeJoin(handle, join.index);
|
||||
|
||||
@override
|
||||
bool get isAntiAlias => paintGetAntiAlias(handle);
|
||||
|
||||
@override
|
||||
set isAntiAlias(bool value) => paintSetAntiAlias(handle, value);
|
||||
|
||||
@override
|
||||
ui.Color get color => ui.Color(paintGetColorInt(handle));
|
||||
|
||||
@override
|
||||
set color(ui.Color color) => paintSetColorInt(handle, color.value);
|
||||
|
||||
@override
|
||||
double get strokeMiterLimit => paintGetMiterLimit(handle);
|
||||
|
||||
@override
|
||||
set strokeMiterLimit(double limit) => paintSetMiterLimit(handle, limit);
|
||||
|
||||
@override
|
||||
ui.Shader? get shader => _shader;
|
||||
|
||||
@override
|
||||
set shader(ui.Shader? uiShader) {
|
||||
uiShader as SkwasmShader?;
|
||||
_shader = uiShader;
|
||||
final SkwasmShader? skwasmShader = uiShader as SkwasmShader?;
|
||||
_shader = skwasmShader;
|
||||
final ShaderHandle shaderHandle =
|
||||
skwasmShader != null ? skwasmShader.handle : nullptr;
|
||||
paintSetShader(handle, shaderHandle);
|
||||
}
|
||||
SkwasmShader? _shader;
|
||||
|
||||
@override
|
||||
ui.FilterQuality filterQuality = ui.FilterQuality.none;
|
||||
|
||||
@override
|
||||
ui.ImageFilter? imageFilter;
|
||||
ui.ImageFilter? get imageFilter => _imageFilter;
|
||||
|
||||
@override
|
||||
set imageFilter(ui.ImageFilter? filter) {
|
||||
_imageFilter = filter;
|
||||
|
||||
final SkwasmImageFilter? nativeImageFilter = filter != null
|
||||
? SkwasmImageFilter.fromUiFilter(filter)
|
||||
: null;
|
||||
paintSetImageFilter(handle, nativeImageFilter != null ? nativeImageFilter.handle : nullptr);
|
||||
}
|
||||
|
||||
@override
|
||||
ui.ColorFilter? get colorFilter => _colorFilter;
|
||||
|
||||
void _setEffectiveColorFilter() {
|
||||
final SkwasmColorFilter? nativeFilter = _colorFilter != null
|
||||
? SkwasmColorFilter.fromEngineColorFilter(_colorFilter!) : null;
|
||||
if (_invertColors) {
|
||||
if (nativeFilter != null) {
|
||||
final SkwasmColorFilter composedFilter = SkwasmColorFilter.composed(_invertColorFilter, nativeFilter);
|
||||
nativeFilter.dispose();
|
||||
paintSetColorFilter(handle, composedFilter.handle);
|
||||
composedFilter.dispose();
|
||||
} else {
|
||||
paintSetColorFilter(handle, _invertColorFilter.handle);
|
||||
}
|
||||
} else if (nativeFilter != null) {
|
||||
paintSetColorFilter(handle, nativeFilter.handle);
|
||||
nativeFilter.dispose();
|
||||
} else {
|
||||
paintSetColorFilter(handle, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
set colorFilter(ui.ColorFilter? filter) {
|
||||
_colorFilter = filter as EngineColorFilter?;
|
||||
_setEffectiveColorFilter();
|
||||
}
|
||||
|
||||
EngineColorFilter? _colorFilter;
|
||||
@override
|
||||
ui.MaskFilter? get maskFilter => _maskFilter;
|
||||
|
||||
@override
|
||||
ui.MaskFilter? maskFilter;
|
||||
set maskFilter(ui.MaskFilter? filter) {
|
||||
_maskFilter = filter;
|
||||
if (filter == null) {
|
||||
paintSetMaskFilter(handle, nullptr);
|
||||
} else {
|
||||
final SkwasmMaskFilter nativeFilter = SkwasmMaskFilter.fromUiMaskFilter(filter);
|
||||
paintSetMaskFilter(handle, nativeFilter.handle);
|
||||
nativeFilter.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool invertColors = false;
|
||||
bool get invertColors => _invertColors;
|
||||
|
||||
@override
|
||||
set invertColors(bool invertColors) {
|
||||
if (_invertColors == invertColors) {
|
||||
return;
|
||||
}
|
||||
_invertColors = invertColors;
|
||||
_setEffectiveColorFilter();
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -187,7 +217,7 @@ class SkwasmPaint implements ui.Paint {
|
||||
result.write('$semicolon$color');
|
||||
semicolon = '; ';
|
||||
}
|
||||
if (blendMode.index != _kBlendModeDefault.index) {
|
||||
if (blendMode.index != _kBlendModeDefault) {
|
||||
result.write('$semicolon$blendMode');
|
||||
semicolon = '; ';
|
||||
}
|
||||
|
||||
@@ -398,14 +398,10 @@ class SkwasmTextStyle implements ui.TextStyle {
|
||||
skStringFree(localeHandle);
|
||||
}
|
||||
if (background != null) {
|
||||
final backgroundPaint = (background! as SkwasmPaint).toRawPaint();
|
||||
textStyleSetBackground(handle, backgroundPaint);
|
||||
paintDispose(backgroundPaint);
|
||||
textStyleSetBackground(handle, (background! as SkwasmPaint).handle);
|
||||
}
|
||||
if (foreground != null) {
|
||||
final foregroundPaint = (foreground! as SkwasmPaint).toRawPaint();
|
||||
textStyleSetForeground(handle, foregroundPaint);
|
||||
paintDispose(foregroundPaint);
|
||||
textStyleSetForeground(handle, (foreground! as SkwasmPaint).handle);
|
||||
}
|
||||
if (shadows != null) {
|
||||
for (final ui.Shadow shadow in shadows!) {
|
||||
|
||||
@@ -13,32 +13,57 @@ final class RawPaint extends Opaque {}
|
||||
|
||||
typedef PaintHandle = Pointer<RawPaint>;
|
||||
|
||||
typedef _PaintCreateInitSignature = PaintHandle Function(
|
||||
Bool,
|
||||
Int,
|
||||
Int,
|
||||
Int,
|
||||
Float,
|
||||
Int,
|
||||
Int,
|
||||
Float,
|
||||
);
|
||||
|
||||
@Native<_PaintCreateInitSignature>(symbol: 'paint_create', isLeaf: true)
|
||||
external PaintHandle paintCreate(
|
||||
bool isAntiAlias,
|
||||
int blendMode,
|
||||
int color,
|
||||
int style,
|
||||
double strokeWidth,
|
||||
int strokeCap,
|
||||
int strokeJoin,
|
||||
double strokeMiterLimit,
|
||||
);
|
||||
@Native<PaintHandle Function()>(symbol: 'paint_create', isLeaf: true)
|
||||
external PaintHandle paintCreate();
|
||||
|
||||
@Native<Void Function(PaintHandle)>(symbol: 'paint_dispose', isLeaf: true)
|
||||
external void paintDispose(PaintHandle paint);
|
||||
|
||||
@Native<Void Function(PaintHandle, Int)>(symbol: 'paint_setBlendMode', isLeaf: true)
|
||||
external void paintSetBlendMode(PaintHandle paint, int blendMode);
|
||||
|
||||
@Native<Void Function(PaintHandle, Int)>(symbol: 'paint_setStyle', isLeaf: true)
|
||||
external void paintSetStyle(PaintHandle paint, int paintStyle);
|
||||
|
||||
@Native<Int Function(PaintHandle)>(symbol: 'paint_getStyle', isLeaf: true)
|
||||
external int paintGetStyle(PaintHandle paint);
|
||||
|
||||
@Native<Void Function(PaintHandle, Float)>(symbol: 'paint_setStrokeWidth', isLeaf: true)
|
||||
external void paintSetStrokeWidth(PaintHandle paint, double strokeWidth);
|
||||
|
||||
@Native<Float Function(PaintHandle)>(symbol: 'paint_getStrokeWidth', isLeaf: true)
|
||||
external double paintGetStrokeWidth(PaintHandle paint);
|
||||
|
||||
@Native<Void Function(PaintHandle, Int)>(symbol: 'paint_setStrokeCap', isLeaf: true)
|
||||
external void paintSetStrokeCap(PaintHandle paint, int cap);
|
||||
|
||||
@Native<Int Function(PaintHandle)>(symbol: 'paint_getStrokeCap', isLeaf: true)
|
||||
external int paintGetStrokeCap(PaintHandle paint);
|
||||
|
||||
@Native<Void Function(PaintHandle, Int)>(symbol: 'paint_setStrokeJoin', isLeaf: true)
|
||||
external void paintSetStrokeJoin(PaintHandle paint, int join);
|
||||
|
||||
@Native<Int Function(PaintHandle)>(symbol: 'paint_getStrokeJoin', isLeaf: true)
|
||||
external int paintGetStrokeJoin(PaintHandle paint);
|
||||
|
||||
@Native<Void Function(PaintHandle, Bool)>(symbol: 'paint_setAntiAlias', isLeaf: true)
|
||||
external void paintSetAntiAlias(PaintHandle paint, bool antiAlias);
|
||||
|
||||
@Native<Bool Function(PaintHandle)>(symbol: 'paint_getAntiAlias', isLeaf: true)
|
||||
external bool paintGetAntiAlias(PaintHandle paint);
|
||||
|
||||
@Native<Void Function(PaintHandle, Uint32)>(symbol: 'paint_setColorInt', isLeaf: true)
|
||||
external void paintSetColorInt(PaintHandle paint, int color);
|
||||
|
||||
@Native<Uint32 Function(PaintHandle)>(symbol: 'paint_getColorInt', isLeaf: true)
|
||||
external int paintGetColorInt(PaintHandle paint);
|
||||
|
||||
@Native<Void Function(PaintHandle, Float)>(symbol: 'paint_setMiterLimit', isLeaf: true)
|
||||
external void paintSetMiterLimit(PaintHandle paint, double miterLimit);
|
||||
|
||||
@Native<Float Function(PaintHandle)>(symbol: 'paint_getMiterLimit', isLeaf: true)
|
||||
external double paintGetMiterLimit(PaintHandle paint);
|
||||
|
||||
@Native<Void Function(PaintHandle, ShaderHandle)>(symbol: 'paint_setShader', isLeaf: true)
|
||||
external void paintSetShader(PaintHandle handle, ShaderHandle shader);
|
||||
|
||||
|
||||
@@ -12,23 +12,11 @@
|
||||
|
||||
using namespace Skwasm;
|
||||
|
||||
SKWASM_EXPORT SkPaint* paint_create(bool isAntiAlias,
|
||||
SkBlendMode blendMode,
|
||||
SkColor color,
|
||||
SkPaint::Style style,
|
||||
SkScalar strokeWidth,
|
||||
SkPaint::Cap strokeCap,
|
||||
SkPaint::Join strokeJoin,
|
||||
SkScalar strokeMiterLimit) {
|
||||
SKWASM_EXPORT SkPaint* paint_create() {
|
||||
auto paint = new SkPaint();
|
||||
paint->setAntiAlias(isAntiAlias);
|
||||
paint->setBlendMode(blendMode);
|
||||
paint->setStyle(style);
|
||||
paint->setStrokeWidth(strokeWidth);
|
||||
paint->setStrokeCap(strokeCap);
|
||||
paint->setStrokeJoin(strokeJoin);
|
||||
paint->setColor(color);
|
||||
paint->setStrokeMiter(strokeMiterLimit);
|
||||
|
||||
// Antialias defaults to true in flutter.
|
||||
paint->setAntiAlias(true);
|
||||
return paint;
|
||||
}
|
||||
|
||||
@@ -36,6 +24,68 @@ SKWASM_EXPORT void paint_dispose(SkPaint* paint) {
|
||||
delete paint;
|
||||
}
|
||||
|
||||
SKWASM_EXPORT void paint_setBlendMode(SkPaint* paint, SkBlendMode mode) {
|
||||
paint->setBlendMode(mode);
|
||||
}
|
||||
|
||||
// No getter for blend mode, as it's non trivial. Cache on the dart side.
|
||||
|
||||
SKWASM_EXPORT void paint_setStyle(SkPaint* paint, SkPaint::Style style) {
|
||||
paint->setStyle(style);
|
||||
}
|
||||
|
||||
SKWASM_EXPORT SkPaint::Style paint_getStyle(SkPaint* paint) {
|
||||
return paint->getStyle();
|
||||
}
|
||||
|
||||
SKWASM_EXPORT void paint_setStrokeWidth(SkPaint* paint, SkScalar width) {
|
||||
paint->setStrokeWidth(width);
|
||||
}
|
||||
|
||||
SKWASM_EXPORT SkScalar paint_getStrokeWidth(SkPaint* paint) {
|
||||
return paint->getStrokeWidth();
|
||||
}
|
||||
|
||||
SKWASM_EXPORT void paint_setStrokeCap(SkPaint* paint, SkPaint::Cap cap) {
|
||||
paint->setStrokeCap(cap);
|
||||
}
|
||||
|
||||
SKWASM_EXPORT SkPaint::Cap paint_getStrokeCap(SkPaint* paint) {
|
||||
return paint->getStrokeCap();
|
||||
}
|
||||
|
||||
SKWASM_EXPORT void paint_setStrokeJoin(SkPaint* paint, SkPaint::Join join) {
|
||||
paint->setStrokeJoin(join);
|
||||
}
|
||||
|
||||
SKWASM_EXPORT SkPaint::Join paint_getStrokeJoin(SkPaint* paint) {
|
||||
return paint->getStrokeJoin();
|
||||
}
|
||||
|
||||
SKWASM_EXPORT void paint_setAntiAlias(SkPaint* paint, bool antiAlias) {
|
||||
paint->setAntiAlias(antiAlias);
|
||||
}
|
||||
|
||||
SKWASM_EXPORT bool paint_getAntiAlias(SkPaint* paint) {
|
||||
return paint->isAntiAlias();
|
||||
}
|
||||
|
||||
SKWASM_EXPORT void paint_setColorInt(SkPaint* paint, SkColor colorInt) {
|
||||
paint->setColor(colorInt);
|
||||
}
|
||||
|
||||
SKWASM_EXPORT SkColor paint_getColorInt(SkPaint* paint) {
|
||||
return paint->getColor();
|
||||
}
|
||||
|
||||
SKWASM_EXPORT void paint_setMiterLimit(SkPaint* paint, SkScalar miterLimit) {
|
||||
paint->setStrokeMiter(miterLimit);
|
||||
}
|
||||
|
||||
SKWASM_EXPORT SkScalar paint_getMiterLimit(SkPaint* paint) {
|
||||
return paint->getStrokeMiter();
|
||||
}
|
||||
|
||||
SKWASM_EXPORT void paint_setShader(SkPaint* paint, SkShader* shader) {
|
||||
paint->setShader(sk_ref_sp<SkShader>(shader));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user