Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Skip empty platform view overlays.#11427

Merged
amirh merged 3 commits intoflutter:masterfrom
amirh:skip_empty_overlays
Aug 26, 2019
Merged

Skip empty platform view overlays.#11427
amirh merged 3 commits intoflutter:masterfrom
amirh:skip_empty_overlays

Conversation

@amirh
Copy link
Contributor

@amirh amirh commented Aug 24, 2019

This change sets up a "spying canvas" to try and detect empty canvases.
When using platform views with a custom embedder, if a platform view
overlay canvas is known to be empty we skip creating a compositor layer
for that overlay.

This change sets up a "spying canvas" to try and detect empty canvases.
When using platform views with a custom embedder, if a platform view
overlay canvas is known to be empty we skip creating a compositor layer
for that overlay.
@amirh amirh force-pushed the skip_empty_overlays branch from d67d1fd to fb66d03 Compare August 24, 2019 01:49
Copy link
Contributor

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

Other than a test to make sure we don't ask the embedder for a backing store unnecessarily, everything else looks good. All other comments are nits.

// This is used to determine whether anything was drawn into
// a canvas so it is possible to implement optimizations that
// are specific to empty canvases.
class CanvasSpy {
Copy link
Contributor

Choose a reason for hiding this comment

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

The comments won't end up in doxygen generated docs. See shell.h for a prototype.

Ditto for all other comment blocks.

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

SkPixmap actual;
SkPixmap expected;

actual_surface->peekPixels(&actual);
Copy link
Contributor

Choose a reason for hiding this comment

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

These calls can fail. ASSERT_TRUE on the result.

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

actual_surface->peekPixels(&actual);
expected_surface->peekPixels(&expected);

const auto size = actual.rowBytes() * actual.height();
Copy link
Contributor

Choose a reason for hiding this comment

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

ASSERT_NE(size, 0) to make sure earlier failures on the peek don't result in this test passing.

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

return n_way_canvas_.get();
}

DidDrawCanvas::DidDrawCanvas(int width, int height) : INHERITED(width, height) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use Skia's internal non-namespaced macros or the typedef pattern. Please use the superclass name directly instead of using INHERITED.

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

}

DidDrawCanvas::DidDrawCanvas(int width, int height) : INHERITED(width, height) {
did_draw_ = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Prefer defaulting this to false in the header and get rid of this. That way, if/when we add more ctors, we don't have to remember to default all scalars.

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

~DidDrawCanvas() override;
bool DidDrawIntoCanvas();

protected:
Copy link
Contributor

Choose a reason for hiding this comment

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

We are not going to subclass this further. Please make this private and mark the class final. This will also make it a compiler error if the base class adds new pure virtual methods that we haven't overriden.

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

bool onDoSaveBehind(const SkRect*) override;
void willRestore() override;

void didConcat(const SkMatrix&) override;
Copy link
Contributor

Choose a reason for hiding this comment

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

We mention the class/interface that defines the method being overriden. So, // | SkCanvasVirtualEnforcer<SkNoDrawCanvas>| here and in the implementation for all overrides.

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

presented_layers.push_back(
MakeLayer(params, presented_platform_views.at(view_id)));

if (!pending_canvas_spies_[view_id]->DidDrawIntoCanvas()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use .at() instead of .[] when you know you don't want to insert a default constructed map element. We know this is safe because of the DCHECK added above.

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

if (!pending_canvas_spies_[view_id]->DidDrawIntoCanvas()) {
// Nothing was drawn into the overlay canvas, we don't need to composite
// it.
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Test this continue. We should upgrade the embedder test compositor to make sure we track the number of backing stores being requested of the the embedder. Then assert that we don't ask for extra backing stores. If we forgot or later moved this continue, no test would fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an assertion for the number of backing stores in the test.

Side note that EmbedderTest.CompositorMustBeAbleToRenderWithPlatformLayerOnBottom would have failed if we removed this continue.

Copy link
Contributor Author

@amirh amirh left a comment

Choose a reason for hiding this comment

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

Thanks, PTAL.

return n_way_canvas_.get();
}

DidDrawCanvas::DidDrawCanvas(int width, int height) : INHERITED(width, height) {
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

}

DidDrawCanvas::DidDrawCanvas(int width, int height) : INHERITED(width, height) {
did_draw_ = false;
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

// This is used to determine whether anything was drawn into
// a canvas so it is possible to implement optimizations that
// are specific to empty canvases.
class CanvasSpy {
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

~DidDrawCanvas() override;
bool DidDrawIntoCanvas();

protected:
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

bool onDoSaveBehind(const SkRect*) override;
void willRestore() override;

void didConcat(const SkMatrix&) override;
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

SkPixmap actual;
SkPixmap expected;

actual_surface->peekPixels(&actual);
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

actual_surface->peekPixels(&actual);
expected_surface->peekPixels(&expected);

const auto size = actual.rowBytes() * actual.height();
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

presented_layers.push_back(
MakeLayer(params, presented_platform_views.at(view_id)));

if (!pending_canvas_spies_[view_id]->DidDrawIntoCanvas()) {
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

if (!pending_canvas_spies_[view_id]->DidDrawIntoCanvas()) {
// Nothing was drawn into the overlay canvas, we don't need to composite
// it.
continue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an assertion for the number of backing stores in the test.

Side note that EmbedderTest.CompositorMustBeAbleToRenderWithPlatformLayerOnBottom would have failed if we removed this continue.

@amirh amirh merged commit a34f9a8 into flutter:master Aug 26, 2019
@amirh amirh deleted the skip_empty_overlays branch August 26, 2019 18:40
@chinmaygarde
Copy link
Contributor

I am going to close b/139737705.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 26, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Aug 26, 2019
[email protected]:flutter/engine.git/compare/11e3ade157db...ba1a303

git log 11e3ade..ba1a303 --no-merges --oneline
2019-08-26 [email protected] Patch buttons for chromebook touchpad (flutter/engine#11420)
2019-08-26 [email protected] Skip empty platform view overlays. (flutter/engine#11427)


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
@liyuqian
Copy link
Contributor

@amirh : this looks like a performance optimization. Is there a known benchmark that covers this performance? Or is there a manual performance test process that's documented somewhere?

@chinmaygarde
Copy link
Contributor

This optimization is guaranteed by the engine and made available to the embedder. This is tested in the the CanvasSpyUnittests Amir added in this patch and enabled in EmbedderTest.CompositorMustBeAbleToRenderWithPlatformLayerOnBottom.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants