Skip to content

Commit

Permalink
Add web ImageShader support for drawVertices. (flutter#25729)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatb authored Apr 23, 2021
1 parent 7676dbc commit 060f108
Show file tree
Hide file tree
Showing 8 changed files with 665 additions and 180 deletions.
2 changes: 1 addition & 1 deletion lib/web_ui/dev/goldens_lock.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
repository: https://github.com/flutter/goldens.git
revision: d885b270d90e031fdda2efd640eb5d6b6fbc9ce5
revision: 449cb88e9ffed446e4e7df9beb73814e5fb11ead
7 changes: 4 additions & 3 deletions lib/web_ui/lib/src/engine/bitmap_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -940,12 +940,13 @@ class BitmapCanvas extends EngineCanvas {
// blendMode. https://github.com/flutter/flutter/issues/40096
// Move rendering to OffscreenCanvas so that transform is preserved
// as well.
assert(paint.shader == null,
'Linear/Radial/SweepGradient and ImageShader not supported yet');
assert(paint.shader == null || paint.shader is ImageShader,
'Linear/Radial/SweepGradient not supported yet');
final Int32List? colors = vertices._colors;
final ui.VertexMode mode = vertices._mode;
html.CanvasRenderingContext2D? ctx = _canvasPool.context;
if (colors == null && paint.style != ui.PaintingStyle.fill) {
if (colors == null && paint.style != ui.PaintingStyle.fill &&
paint.shader == null) {
final Float32List positions = mode == ui.VertexMode.triangles
? vertices._positions
: _convertVertexPositions(mode, vertices._positions);
Expand Down
10 changes: 10 additions & 0 deletions lib/web_ui/lib/src/engine/html/recording_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ class RecordingCanvas {

void drawLine(ui.Offset p1, ui.Offset p2, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
final double paintSpread = math.max(_getPaintSpread(paint), 1.0);
final PaintDrawLine command = PaintDrawLine(p1, p2, paint.paintData);
// TODO(yjbanov): This can be optimized. Currently we create a box around
Expand All @@ -344,6 +345,7 @@ class RecordingCanvas {

void drawPaint(SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
_didDraw = true;
final PaintDrawPaint command = PaintDrawPaint(paint.paintData);
Expand All @@ -353,6 +355,7 @@ class RecordingCanvas {

void drawRect(ui.Rect rect, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
if (paint.shader != null) {
renderStrategy.hasArbitraryPaint = true;
}
Expand All @@ -369,6 +372,7 @@ class RecordingCanvas {

void drawRRect(ui.RRect rrect, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
if (paint.shader != null || !rrect.webOnlyUniformRadii) {
renderStrategy.hasArbitraryPaint = true;
}
Expand All @@ -385,6 +389,7 @@ class RecordingCanvas {

void drawDRRect(ui.RRect outer, ui.RRect inner, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
// Check the inner bounds are contained within the outer bounds
// see: https://cs.chromium.org/chromium/src/third_party/skia/src/core/SkCanvas.cpp?l=1787-1789
ui.Rect innerRect = inner.outerRect;
Expand Down Expand Up @@ -443,6 +448,7 @@ class RecordingCanvas {

void drawOval(ui.Rect rect, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
_didDraw = true;
final double paintSpread = _getPaintSpread(paint);
Expand All @@ -457,6 +463,7 @@ class RecordingCanvas {

void drawCircle(ui.Offset c, double radius, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
_didDraw = true;
final double paintSpread = _getPaintSpread(paint);
Expand All @@ -474,6 +481,7 @@ class RecordingCanvas {

void drawPath(ui.Path path, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
if (paint.shader == null) {
// For Rect/RoundedRect paths use drawRect/drawRRect code paths for
// DomCanvas optimization.
Expand Down Expand Up @@ -510,6 +518,7 @@ class RecordingCanvas {

void drawImage(ui.Image image, ui.Offset offset, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
renderStrategy.hasImageElements = true;
_didDraw = true;
Expand Down Expand Up @@ -547,6 +556,7 @@ class RecordingCanvas {
void drawImageRect(
ui.Image image, ui.Rect src, ui.Rect dst, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! ImageShader, 'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
renderStrategy.hasImageElements = true;
_didDraw = true;
Expand Down
Loading

0 comments on commit 060f108

Please sign in to comment.