这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Refactor gradient renderer to produce image. Implement gradient based Shadermask #24029

Merged
merged 33 commits into from
Feb 20, 2021

Conversation

ferhatb
Copy link
Contributor

@ferhatb ferhatb commented Jan 28, 2021

Implements Shadermask for html and canvaskit rendering backends.

Issue: flutter/flutter#44152
flutter/flutter#75495

Will unblock work for flutter/flutter#52967

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@ferhatb ferhatb mentioned this pull request Jan 28, 2021
14 tasks
@chinmaygarde chinmaygarde added the platform-web Code specifically for the web engine label Feb 4, 2021
@ferhatb ferhatb changed the title WIP : Refactor gradient renderer to produce image. Implement gradient based Shadermask Refactor gradient renderer to produce image. Implement gradient based Shadermask Feb 10, 2021
@ferhatb ferhatb requested a review from yjbanov February 10, 2021 22:13
/// Renders a rectangle using given program into an image resource.
///
/// Browsers that support OffscreenCanvas and the transferToImageBitmap api
/// will return ImageBitmap, otherwise will return CanvasElement.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dartdoc seems wrong. The function returns an image URL in all circumstances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -195,6 +198,31 @@ class _WebGlRenderer implements _GlRenderer {
/// Browsers that support OffscreenCanvas and the transferToImageBitmap api
/// will return ImageBitmap, otherwise will return CanvasElement.
Object? drawRect(ui.Rect targetRect, _GlContext gl, _GlProgram glProgram,
NormalizedGradient gradient, int widthInPixels, int heightInPixels, ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the trailing comma?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

/// Browsers that support OffscreenCanvas and the transferToImageBitmap api
/// will return ImageBitmap, otherwise will return CanvasElement.
String drawRectToImageUrl(ui.Rect targetRect, _GlContext gl, _GlProgram glProgram,
NormalizedGradient gradient, int widthInPixels, int heightInPixels, ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the trailing comma?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

this.shader,
this.maskRect,
this.blendMode,
) : super(oldLayer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something's off in the indent here

Copy link
Contributor Author

@ferhatb ferhatb Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. ran dartfmt on file.

@@ -190,7 +180,7 @@ class GradientLinear extends EngineGradient {
_GlContext gl = _OffScreenCanvas.supported
? _GlContext.fromOffscreenCanvas(offScreenCanvas._canvas!)
: _GlContext.fromCanvas(offScreenCanvas._glCanvas!,
webGLVersion == WebGLVersion.webgl1);
webGLVersion == WebGLVersion.webgl1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


/// Returns image data in data url format.
String toImageUrl() {
html.CanvasElement canvas = html.CanvasElement(width: _widthInPixels, height: _heightInPixels);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How often is this called? If a lot, we should either cache and reuse the canvas element, or set the width/height to 0 so that we don't run iOS Safari out of memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what's done :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nvm, you do set the dimensions to 0

final ui.BlendMode blendMode;
html.Element? _shaderElement;
html.Element? _imageElement;
bool containerVisible = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this field used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

final ui.Rect maskRect;
final ui.BlendMode blendMode;
html.Element? _shaderElement;
html.Element? _imageElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only see this element being removed and set to null? Is it used for anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was for future ImageShader. removed for now.

@override
html.Element createElement() {
html.Element element = defaultCreateElement('flt-shader-mask');
html.Element container = html.Element.tag('flt-mask-interior');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the interior element necessary? We typically use it in clipping layers when the clipping element changes the coordinate system. I'm not sure this layer has this problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes otherwise we can't host svg resource.

(swapLayers
? '<feBlend in="SourceGraphic" in2="image" mode="$feBlend"/>'
: '<feBlend in="image" in2="SourceGraphic" mode="$feBlend"/>'),
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all blend modes covered by tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -0,0 +1,99 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this file is called shader_mask_golden_test.dart, but the HTML equivalent is called shadermask_golden_test.dart. Let's keep them consistent? (probably shader_mask is better because the class is ShaderMask as opposed to Shadermask)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ferhatb ferhatb merged commit 57c5777 into flutter:master Feb 20, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 22, 2021
mzdm added a commit to mzdm/virtual_traveller_flutter that referenced this pull request Feb 23, 2021
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
chriscraws pushed a commit to chriscraws/engine that referenced this pull request Mar 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants