-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Implement ClipOp.difference #21901
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
repository: https://github.com/flutter/goldens.git | ||
revision: 672510dc52daa5b059081f6990582bccdb4ea48f | ||
revision: 1556280d6f1d70fac9ddff9b38639757e105b4b0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ abstract class EngineCanvas { | |
|
||
void transform(Float32List matrix4); | ||
|
||
void clipRect(ui.Rect rect); | ||
void clipRect(ui.Rect rect, ui.ClipOp clipOp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add comment here since it's a public method, or we can add the comments to the implementing classes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point all comments were removed so we didn't have to keep them in sync. |
||
|
||
void clipRRect(ui.RRect rrect); | ||
|
||
|
@@ -222,7 +222,7 @@ mixin SaveStackTracking on EngineCanvas { | |
/// | ||
/// Classes that override this method must call `super.clipRect()`. | ||
@override | ||
void clipRect(ui.Rect rect) { | ||
void clipRect(ui.Rect rect, ui.ClipOp op) { | ||
_clipStack ??= <_SaveClipEntry>[]; | ||
_clipStack!.add(_SaveClipEntry.rect(rect, _currentTransform.clone())); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// @dart = 2.6 | ||
import 'package:test/bootstrap/browser.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:ui/ui.dart'; | ||
import 'package:ui/src/engine.dart'; | ||
import 'screenshot.dart'; | ||
|
||
void main() { | ||
internalBootstrapBrowserTest(() => testMain); | ||
} | ||
|
||
void testMain() async { | ||
setUp(() async { | ||
debugEmulateFlutterTesterEnvironment = true; | ||
}); | ||
|
||
/// Regression test for https://github.com/flutter/flutter/issues/64734. | ||
test('Clips using difference', () async { | ||
final Rect region = const Rect.fromLTRB(0, 0, 400, 300); | ||
final RecordingCanvas canvas = RecordingCanvas(region); | ||
final Rect titleRect = Rect.fromLTWH(20, 0, 50, 20); | ||
final Paint paint = Paint() | ||
..style = PaintingStyle.stroke | ||
..color = const Color(0xff000000) | ||
..strokeWidth = 1; | ||
canvas.save(); | ||
try { | ||
final Rect borderRect = Rect.fromLTRB(0, 10, region.width, region.height); | ||
canvas.clipRect(titleRect, ClipOp.difference); | ||
canvas.drawRect(borderRect, paint); | ||
} finally { | ||
canvas.restore(); | ||
} | ||
canvas..drawRect(titleRect, paint); | ||
await canvasScreenshot(canvas, 'clip_op_difference', | ||
region: const Rect.fromLTRB(0, 0, 420, 360)); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its a start to dedup a lot of test code. There are only 4 tests using scuba and DomCanvas soon going away. BitmapCanvas will write out DOM nodes for rects etc soon as well and desire to run canvaskit+html tests in a uniform way. Plan to move scuba bits into screenshot and clean things up across all tests. |
||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// @dart = 2.6 | ||
import 'dart:html' as html; | ||
import 'package:ui/ui.dart' as ui; | ||
import 'package:ui/src/engine.dart'; | ||
import 'package:web_engine_tester/golden_tester.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
/// Commit a recording canvas to a bitmap, and compare with the expected. | ||
Future<void> canvasScreenshot(RecordingCanvas rc, String fileName, | ||
{ui.Rect region = const ui.Rect.fromLTWH(0, 0, 600, 800), | ||
double maxDiffRatePercent = 0.0, bool write: false}) async { | ||
final EngineCanvas engineCanvas = BitmapCanvas(region); | ||
|
||
rc.endRecording(); | ||
rc.apply(engineCanvas, region); | ||
|
||
// Wrap in <flt-scene> so that our CSS selectors kick in. | ||
final html.Element sceneElement = html.Element.tag('flt-scene'); | ||
try { | ||
sceneElement.append(engineCanvas.rootElement); | ||
html.document.body.append(sceneElement); | ||
await matchGoldenFile('$fileName.png', | ||
region: region, maxDiffRatePercent: maxDiffRatePercent, write: write); | ||
} finally { | ||
// The page is reused across tests, so remove the element after taking the | ||
// Scuba screenshot. | ||
sceneElement.remove(); | ||
} | ||
} | ||
|
||
/// Configures the test to use bundled Roboto and Ahem fonts to avoid golden | ||
/// screenshot differences due to differences in the preinstalled system fonts. | ||
void setUpStableTestFonts() { | ||
setUp(() async { | ||
await ui.webOnlyInitializePlatform(); | ||
ui.webOnlyFontCollection.debugRegisterTestFonts(); | ||
await ui.webOnlyFontCollection.ensureFontsLoaded(); | ||
}); | ||
} |
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.
I'm curious why you did the opposite check here compared to the above. Should we keep them consistent?
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.