-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Perform no shader warm-up by default (#87126)"
This reverts commit 32c2e2b.
- Loading branch information
Showing
7 changed files
with
265 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2014 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. | ||
|
||
// This example shows the draw operations to warm up the GPU shaders by default. | ||
|
||
import 'dart:ui' as ui; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
Future<void> beginFrame(Duration timeStamp) async { | ||
// PAINT | ||
final ui.PictureRecorder recorder = ui.PictureRecorder(); | ||
const ui.Rect paintBounds = ui.Rect.fromLTRB(0, 0, 1000, 1000); | ||
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds); | ||
final ui.Paint backgroundPaint = ui.Paint()..color = Colors.white; | ||
canvas.drawRect(paintBounds, backgroundPaint); | ||
await const DefaultShaderWarmUp( | ||
drawCallSpacing: 80.0, | ||
canvasSize: ui.Size(1024, 1024), | ||
).warmUpOnCanvas(canvas); | ||
final ui.Picture picture = recorder.endRecording(); | ||
|
||
// COMPOSITE | ||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder() | ||
..pushClipRect(paintBounds) | ||
..addPicture(ui.Offset.zero, picture) | ||
..pop(); | ||
ui.window.render(sceneBuilder.build()); | ||
} | ||
|
||
Future<void> main() async { | ||
ui.window.onBeginFrame = beginFrame; | ||
ui.window.scheduleFrame(); | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/layers/test/smoketests/raw/shader_warm_up_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2014 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. | ||
|
||
// ignore: deprecated_member_use | ||
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf; | ||
|
||
import '../../../raw/shader_warm_up.dart' as demo; | ||
|
||
void main() { | ||
test('layers smoketest for raw/shader_warm_up.dart', () { | ||
demo.main(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2014 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. | ||
|
||
import 'dart:ui' as ui; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/painting.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
class TestCanvas implements Canvas { | ||
TestCanvas(); | ||
|
||
final List<Invocation> invocations = <Invocation>[]; | ||
|
||
@override | ||
void noSuchMethod(Invocation invocation) { | ||
invocations.add(invocation); | ||
} | ||
} | ||
|
||
void main() { | ||
test('DefaultShaderWarmUp has expected canvas invocations', () { | ||
final TestCanvas canvas = TestCanvas(); | ||
const DefaultShaderWarmUp s = DefaultShaderWarmUp(); | ||
s.warmUpOnCanvas(canvas); | ||
|
||
bool hasDrawRectAfterClipRRect = false; | ||
for (int i = 0; i < canvas.invocations.length - 1; i += 1) { | ||
if (canvas.invocations[i].memberName == #clipRRect && canvas.invocations[i + 1].memberName == #drawRect) { | ||
hasDrawRectAfterClipRRect = true; | ||
break; | ||
} | ||
} | ||
|
||
expect(hasDrawRectAfterClipRRect, true); | ||
}); | ||
|
||
test('ShaderWarmUp.execute disposes the image and picture', () async { | ||
const DefaultShaderWarmUp shaderWarmUp = DefaultShaderWarmUp(); | ||
late ui.Picture capturedPicture; | ||
late ui.Image capturedImage; | ||
debugCaptureShaderWarmUpPicture = (ui.Picture picture) { | ||
capturedPicture = picture; | ||
expect(picture.approximateBytesUsed, greaterThan(0)); | ||
return true; | ||
}; | ||
debugCaptureShaderWarmUpImage = (ui.Image image) { | ||
capturedImage = image; | ||
expect(image.width, 100); | ||
expect(image.height, 100); | ||
return true; | ||
}; | ||
await shaderWarmUp.execute(); | ||
expect( | ||
() => capturedPicture.approximateBytesUsed, | ||
throwsA(isA<String>().having((String message) => message, 'message', 'Object has been disposed.')), | ||
); | ||
expect(capturedImage.debugDisposed, true); | ||
}, skip: kIsWeb); // Browser doesn't support approximateBytesUsed and doesn't rasterize the picture at this time. | ||
} |