-
Notifications
You must be signed in to change notification settings - Fork 6k
Refactor BitmapCanvas, lazily allocate canvas, fix image composition bug. #15153
Conversation
String _prevFilter = 'none'; | ||
Object _prevFillStyle; | ||
Object _prevStrokeStyle; | ||
int _canvasPositionX, _canvasPositionY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like other fields, docs here would be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
final RRect outer = | ||
RRect.fromRectAndCorners(const Rect.fromLTRB(10, 20, 30, 40)); | ||
final RRect inner = | ||
RRect.fromRectAndCorners(const Rect.fromLTRB(12, 22, 28, 38)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the above two indents are off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
// Fill a virtually infinite rect with the color. | ||
void fill() { | ||
html.CanvasRenderingContext2D ctx = context; | ||
ctx.beginPath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this here but not in drawColor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
html.CanvasRenderingContext2D ctx = context; | ||
contextHandle.blendMode = blendMode; | ||
contextHandle.fillStyle = color.toCssString(); | ||
contextHandle.strokeStyle = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still missing how a filter
applied in a drawPaint
won't leak into drawColor
🤔
Example:
c.drawPaint(... pass Paint with filter...);
// at this point, because we didn't reset the previous paint the `filter` is still there.
c.drawColor(... some color and blend mode ...);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Added filter = 'none';
ui.StrokeCap _currentStrokeCap = ui.StrokeCap.butt; | ||
ui.StrokeJoin _currentStrokeJoin = ui.StrokeJoin.miter; | ||
Object _currentFillStyle; | ||
Object _currentStrokeStyle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please leave a comment explaining why the above two fields need to be Object
?
context.fillStyle = ''; | ||
_currentFillStyle = context.fillStyle; | ||
context.strokeStyle = ''; | ||
_currentStrokeStyle = context.strokeStyle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please leave a comment explaining why you have to write an empty string then read it back from context
rather than assign an empty string to everything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dnoe.
}); | ||
|
||
test('Inner RRect > Outer RRect', () { | ||
underTest.drawDRRect(rrect, rrect.inflate(1), somePaint); | ||
underTest.apply(mockCanvas); | ||
// Expect nothing to be called | ||
expect(mockCanvas.methodCallLog.length, equals(0)); | ||
expect(mockCanvas.methodCallLog.length, equals(1)); | ||
expect(mockCanvas.methodCallLog.toString(), contains('endOfPaint')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a shorter version
expect(mockCanvas.methodCallLog.single.methodName, 'endOfPaint');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
// Regression test for https://github.com/flutter/flutter/issues/44845 | ||
// Circle should draw on top of image not below. | ||
test('Paints on top of image', () async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you forget to include a test that tests [circle, image] sequence? I saw the test included in the goldens, but it's not in this PR 🤔
Merging on infra failure due to XCode install |
flutter/engine@3f52888...a50f1ef git log 3f52888..a50f1ef --first-parent --oneline 2020-01-08 [email protected] Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (flutter/engine#15118) 2020-01-07 [email protected] Refactor BitmapCanvas, lazily allocate canvas, fix image composition bug. (flutter/engine#15153) 2020-01-07 [email protected] Recover when browser throws on ImageElement.decode due to too many images (flutter/engine#15160) 2020-01-07 [email protected] Fix RectHeightStyle::kMax ascent computation bug (flutter/engine#15106) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
flutter/engine@3f52888...a50f1ef git log 3f52888..a50f1ef --first-parent --oneline 2020-01-08 [email protected] Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (flutter/engine#15118) 2020-01-07 [email protected] Refactor BitmapCanvas, lazily allocate canvas, fix image composition bug. (flutter/engine#15153) 2020-01-07 [email protected] Recover when browser throws on ImageElement.decode due to too many images (flutter/engine#15160) 2020-01-07 [email protected] Fix RectHeightStyle::kMax ascent computation bug (flutter/engine#15106) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
…bug. (flutter#15153) * Refactor BitmapCanvas. Fix image compositing bug. Allocate canvas lazily * Fix recording canvas test by restoring context save * Update recording canvas test for drawColor to show multiply blend
Added endOfPaint call on recording canvas to allow bitmap canvas to dispose after reuse.
Moved all immediate canvas calls from BitmapCanvas into CanvasPool.
Reduced context updates by creating ContextHandle class.
Added regression tests for drawing on top of image in a single Picture.
Fixes flutter/flutter#44845
Fixes flutter/flutter#48032
Fixes flutter/flutter#44585