209 Commits

Author SHA1 Message Date
Amir Hardon
117dbfaeb1 Add a no-op platform view layer. (flutter/engine#6505)
This will be used for embedding UIViews on iOS.

Landing a no-op layer as a first incremental step to keep PRs small.
2018-10-12 19:40:21 -07:00
liyuqian
c03a3795d3 Reland "Share engine layers with the framework" (#6412) (flutter/engine#6468)
This reverts commit c5df60b6a186467803e021ac4dfbb26f0cebb08b.

This should land after https://github.com/flutter/engine/pull/6442

* Add pragma vm:entry-point

Otherwise, an object may be both null and an instance of EnginieLayer at
the same time in Dart.
2018-10-12 07:45:42 -07:00
liyuqian
80d2237fe5 Reland "Allow raster caching any layer subtree (#6442)" (flutter/engine#6507)
* Revert "Revert "Allow raster caching any layer subtree (#6442)" (#6506)"

This reverts commit 0ec9ea75fe7ff9e2121b06fe7d7c9d9751778c65.

* Use raw pointer for RasterCacheKey

So we won't depend on whether it's a std::unique_ptr or std::shared_ptr.
2018-10-11 15:09:09 -07:00
liyuqian
0ec9ea75fe Revert "Allow raster caching any layer subtree (#6442)" (flutter/engine#6506)
Reverts flutter/engine#6442

container_layer.h file is not synced which broke the bots
2018-10-11 14:18:22 -07:00
liyuqian
397c02b215 Allow raster caching any layer subtree (flutter/engine#6442)
We first test this with OpacityLayer. This test alone (without retained rendering) should have ~30% speedup as we'll have fewer render target switches by snapshoting in the Preroll instead of saveLayer in the Paint.

In my local flutter_gallery transition perf tests, the average frame time drops from ~16ms to ~12ms.

https://github.com/flutter/flutter/issues/21756
2018-10-11 13:24:33 -07:00
liyuqian
c5df60b6a1 Revert "Share engine layers with the framework" (flutter/engine#6412)
Reverts flutter/engine#6406

We need to fix the SkiaGPUObject issue of the raster cache SkImage before merging this PR.
2018-10-02 16:51:47 -07:00
liyuqian
aef666755c Share engine layers with the framework (flutter/engine#6406)
To make the PR minimal, we currently only share the engine layer when `pushPhysicalShape` (for Fuchsia) or `pushOffset` (for `RepaintBoundary` and `Opacity`) are called. They should be sufficient for our short-term perf goal. In the future, we can incrementally share more engine layers with the framework.

https://github.com/flutter/flutter/issues/21756
2018-10-02 14:02:10 -07:00
Mehmet Fidanboylu
59fa9a1a48 SkImageFilter needs to be imported in the header (flutter/engine#6296) 2018-09-20 16:45:23 -07:00
Jason Simmons
ea656290b1 Ensure that Layer::AutoSaveLayer objects are not immediately destructed (flutter/engine#6264)
Fixes https://github.com/flutter/flutter/issues/20859
2018-09-17 11:43:41 -07:00
liyuqian
2db3d26f4a Remove LayerBuilder and DefaultLayerBuilder (flutter/engine#6256)
This essentially reverts https://github.com/flutter/engine/pull/4197/
as no one is (or soon will be) implementing an alternative LayerBuilder.
Let's just put everything in SceneBuilder to reduce the YAGNI
(you aren't gonna need it) smell. This will also make retained rendering
API changes much easier.
2018-09-14 15:13:00 -07:00
Gary Qian
c6d0a2117a Improve performance of performance overlay by caching. (flutter/engine#6225)
Cache a SkSurface with previously drawn shapes so that we do not need to draw them again in future frames.

On Nexus 5X test device, old render time for just the overlay was 1.3ms-3.0ms and this version improves to 0.9ms-1.3ms running flutter gallery in profile mode.
2018-09-11 16:13:23 -07:00
liyuqian
1e470cc27b Remove root_surface_transformation from PaintContext (flutter/engine#6213)
It should be sufficient to provide the matrix to preroll.
2018-09-11 15:29:08 -07:00
Gary Qian
bf774ef85b Always save canvas and correctly pass antialias boolean in ClipRects. (flutter/engine#6199) 2018-09-07 14:02:39 -07:00
Eric
9a5581563f Reset the raster cache when the compositor context is created. (flutter/engine#6150) 2018-09-06 17:11:17 -07:00
Zachary Anderson
ea32eeb822 [fuchsia] Plumb root_surface_transformation in scene_update_context (flutter/engine#6187)
* [fuchsia] Plumb root_surface_transformation in scene_update_context

To fix the Fuchsia build.

* Update scene_update_context.cc
2018-09-06 12:35:12 -07:00
Gary Qian
cba6b65789 Use double multiplication by a scale instead of 3 divides for speed. (flutter/engine#6154) 2018-09-04 10:54:52 -07:00
Gary Qian
6cc612b7b3 Revert "Use Skia normalize again after Skia precision fix. (#6121)" (flutter/engine#6122)
This reverts commit 7d6d2fd49f6d5be0ae6d9583a887cabdab4bbb7d.
2018-09-04 10:21:30 -07:00
Gary Qian
7d6d2fd49f Use Skia normalize again after Skia precision fix. (flutter/engine#6121)
* Fix tilt by using custom normalize impl to avoid strange skia normalize behavior

* Use Skia normalize again after Skia fix.
2018-08-30 11:18:01 -07:00
Gary Qian
980d18ee57 Fix tilt by using custom normalize impl to avoid strange skia normalize behavior (flutter/engine#6106) 2018-08-29 10:36:35 -07:00
Chinmay Garde
1fcba44904 Allow embedders to set the root surface transformation. (flutter/engine#6085) 2018-08-28 14:13:49 -07:00
liyuqian
bc75dc5d85 Call drawPath without clip if possible (flutter/engine#5952)
It turns out that Skia is much slower at drawing paint inside a clipped
path than directly drawing that path. (Average frame time of 22ms vs
18ms in flutter_galary transition test.)
2018-08-07 14:47:32 -07:00
amirh
9d38d63147 Allow freezing a texture. (flutter/engine#5938)
This is needed to avoid jank when resizing an embedded Android view.
See
https://github.com/flutter/flutter/issues/19572#issuecomment-410400724
2018-08-07 14:43:19 -07:00
liyuqian
970df7c987 Call drawPaint instead of drawPath if there's clip (flutter/engine#5937)
If we want to avoid the bleeding edge artifact (flutter/flutter#18057 (comment)) using saveLayer, we have to call drawPaint instead of drawPath as anti-aliased drawPath will always have such artifacts.

This is discovered when I try to add golden tests for such bleeding artifacts using our new Clip enum. Here's the updated golden files: flutter/goldens@cb1fa8a?short_path=57b30ce#diff-57b30cea9b10b7ca689009854e12d70e
2018-08-03 17:00:00 -07:00
Chinmay Garde
3e5e79b737 Fix sundry Fuchsia build issues after the tonic/fxl migration. (flutter/engine#5920) 2018-08-01 13:29:45 -07:00
Chinmay Garde
6ab2c166fd Remove all dependencies on Garnet. (flutter/engine#5869) 2018-07-26 12:49:34 -07:00
Chinmay Garde
62289623fc Remove //flutter/glue and use FML directly. (flutter/engine#5862) 2018-07-25 13:20:48 -07:00
liyuqian
2c526e8068 Rename clip mode to clip behavior (flutter/engine#5853)
* Rename clip mode to clip behavior

So we're consistent across flutter/flutter and flutter/engine

* Clang format
2018-07-25 09:57:10 -07:00
Joshua Seaton
967a473c6d [fml][fxl] Migrate AutoResetWaitableEvent to fml version. (flutter/engine#5808)
Thanks Jason for the speedy review
2018-07-20 10:12:38 -07:00
liyuqian
9f3465f4c3 Add ClipMode to ClipPath/ClipRRect and PhysicalShape layers (flutter/engine#5647)
For flutter/flutter#18057
2018-07-13 12:38:16 -07:00
Jonah Williams
6eab9d08be Remove cullRect calculation on TransformLayers with a perspective transform. (flutter/engine#5693) 2018-07-09 12:52:10 -07:00
Adam Barth
10e5400c52 [fuchsia] Update gn label for fuchsia.ui.scenic (flutter/engine#5673)
The gn label for this target changed.
2018-07-03 21:08:28 -07:00
mikejurka
0eac86cbd8 [fuchsia] Update scenic lib path. (flutter/engine#5649) 2018-06-29 17:24:47 -07:00
mikejurka
c0caf150a3 [fuchsia] Rename scenic_lib => scenic (flutter/engine#5648)
TEST=Compiled and ran flutter app on Fuchsia, verified it rendered and responded to input.
2018-06-29 17:06:55 -07:00
liyuqian
a4a4fc0cd4 Improve perf overlay performance. (flutter/engine#5571)
1. Mark perf overlay path as volatile
2. Set sample_margin_width = 0 to get a bar graph instead of saw-tooth.

Previously, the perf overlay itself could be a significant performance
hit and that makes it difficult to profile flutter app.
2018-06-19 16:42:21 -07:00
liyuqian
fe69e3eea1 Call SkAutoCanvasRestore with doSave = true (flutter/engine#5432)
Although we do have a save before this SkAutoCanvasRestore so we
can theoretically send in doSave = false, it's safer to set doSave
to true to prevent future breakage.

As discussed with mtklein@google.com and reed@google.com, saving
canvas is very cheap in Skia so this should have no performance
impact. Skia is also considering remove doSave argument from
SkAutoCanvasRestore and always save the canvas.
2018-05-31 16:41:58 -07:00
cary-clark
937d250db6 call existing ostream operator for SkMatrix (flutter/engine#5427)
This permits removing the call to SkMatrix::toString(), which is deprecated.
2018-05-31 09:55:57 -04:00
liyuqian
949ece5d45 Remove unnecessary saveLayer (flutter/engine#5420)
saveLayer is slow so we should avoid it as much as possible. If
there are artifacts without saveLayer, then we should report that
to Skia for the fix instead of slowing the performance with
saveLayer.

This PQ makes average rasterizer time drop from 25ms to 18ms in
flutter_gallery transitions perf test on a Nexus 5X.

This partially fixes flutter/flutter#13736 .
We probably still need some work in the opacity layer to squize
all the performance improvements.
2018-05-30 12:50:12 -07:00
liyuqian
4537391c78 Use drawImage for picture layer cache (flutter/engine#5315)
Fixes
1. https://github.com/flutter/flutter/issues/12148
2. most part of https://github.com/flutter/flutter/issues/17731 except some tiny AA diffs.
2018-05-23 16:53:20 -07:00
P.Y. Laligand
a133efee8f [fuchsia] Use the real name for the GFX library... (flutter/engine#5346) 2018-05-23 12:09:23 -07:00
P.Y. Laligand
2d104dae40 [fuchsia] Updated references to the gfx FIDL library. (flutter/engine#5341) 2018-05-23 10:25:33 -07:00
cary-clark
0e82a0b583 remove Skia toString() use (flutter/engine#5326)
Skia toString() is not maintained; the debugger that used it has been replaced. 
Replace usage with equivalent implementation.
2018-05-21 09:04:51 -04:00
Todd Volkert
300f7fa815 Clear the raster cache result when bypassing raster cache. (flutter/engine#5300)
https://github.com/flutter/flutter/issues/17448
2018-05-17 23:50:07 -07:00
cary-clark
fc240c57ab rename obsolete SkColor.h macro (flutter/engine#5175)
change SkColorSetARGBInline to SkColorSetARGB. SkColorSetARGBInline is deprecated and will be deleted from Skia.
2018-05-04 13:44:44 -04:00
Chinmay Garde
602b9b7c33 Add disabled failing test for floating point errors on matrix decomposition. (flutter/engine#5076) 2018-04-24 16:02:38 -07:00
Chinmay Garde
aa8636c3fc Implement Scene::toImage for creating a raster image representation of a scene. (flutter/engine#5021) 2018-04-18 12:42:16 -07:00
Chinmay Garde
82c5c8feda Re-land "Support multiple shells in a single process. (#4932)" (flutter/engine#4998)
* Re-land "Support multiple shells in a single process. (#4932)"

This reverts commit a9dd1abd80f9c5148c74d606302171fa260365ca.
2018-04-13 13:48:15 -07:00
Vyacheslav Egorov
a9dd1abd80 Revert "Re-land "Support multiple shells in a single process. (#4932)" (#4977)" (flutter/engine#4981)
This reverts commit e27940623b550f50fece0740ea3d6e9cb259fdae.
2018-04-12 18:28:55 +02:00
Chinmay Garde
e27940623b Re-land "Support multiple shells in a single process. (#4932)" (flutter/engine#4977)
This reverts commit a1befb4f3090141d738fc2b801e5454d96047121.
2018-04-11 15:41:23 -07:00
Chinmay Garde
a1befb4f30 Revert "Support multiple shells in a single process. (#4932)" (flutter/engine#4964)
This reverts commit 077d29581c35a08a076c5aeb5186855975756b55.
2018-04-10 15:28:43 -07:00
Chinmay Garde
077d29581c Support multiple shells in a single process. (flutter/engine#4932)
* Support multiple shells in a single process.

The Flutter Engine currently works by initializing a singleton shell
instance. This shell has to be created on the platform thread. The shell
is responsible for creating the 3 main threads used by Flutter (UI, IO,
GPU) as well as initializing the Dart VM. The shell, references to task
runners of the main threads as well as all snapshots used for VM
initialization are stored in singleton objects. The Flutter shell only
creates the threads, rasterizers, contexts, etc. to fully support a
single Flutter application. Current support for multiple Flutter
applications is achieved by making multiple applications share the same
resources (via the platform views mechanism).

This scheme has the following limitations:

* The shell is a singleton and there is no way to tear it down. Once you
  run a Flutter application in a process, all resources managed by it
  will remain referenced till process termination.
* The threads on which the shell performs its operations are all
  singletons. These threads are never torn down and multiple Flutter
  applications (if present) have to compete with one another on these
  threads.
* Resources referenced by the Dart VM are leaked because the VM isn't
  shutdown even when there are no more Flutter views.
* The shell as a target does not compile on Fuchsia. The Fuchsia content
  handler uses specific dependencies of the shell to rebuild all the
  shell dependencies on its own. This leads to differences in frame
  scheduling, VM setup, service protocol endpoint setup, tracing, etc..
  Fuchsia is very much a second class citizen in this world.
* Since threads and message loops are managed by the engine, the engine
  has to know about threading and platform message loop interop on each
  supported platform.

Specific updates in this patch:

* The shell is no longer a singleton and the embedder holds the unique
  reference to the shell.
* Shell setup and teardown is deterministic.
* Threads are no longer managed by the shell. Instead, the shell is
  given a task runner configuration by the embedder.
* Since the shell does not own its threads, the embedder can control
  threads and the message loops operating on these threads. The shell is
  only given references to the task runners that execute tasks on these
  threads.
* The shell only needs task runner references. These references can be
  to the same task runner. So, if the embedder thinks that a particular
  Flutter application would not need all the threads, it can pass
  references to the same task runner. This effectively makes Flutter
  application run in single threaded mode. There are some places in the
  shell that make synchronous calls, these sites have been updated to
  ensure that they don’t deadlock.
* The test runner and the headless Dart code runner are now Flutter
  applications that are effectively single threaded (since they don’t
  have rendering concerns of big-boy Flutter application).
* The embedder has to guarantee that the threads and outlive the shell.
  It is easy for the embedder to make that guarantee because shell
  termination is deterministic.
* The embedder can create as many shell as it wants. Typically it
  creates a shell per Flutter application with its own task runner
  configuration. Most embedders obtain these task runners from threads
  dedicated to the shell. But, it is entirely possible that the embedder
  can obtain these task runners from a thread pool.
* There can only be one Dart VM in the process. The numerous shell
  interact with one another to manage the VM lifecycle. Once the last
  shell goes away, the VM does as well and hence all resources
  associated with the VM are collected.
* The shell as a target can now compile and run on Fuchsia. The current
  content handler has been removed from the Flutter engine source tree
  and a new implementation has been written that uses the new shell
  target.
* Isolate management has been significantly overhauled. There are no
  owning references to Dart isolates within the shell. The VM owns the
  only strong reference to the Dart isolate. The isolate that has window
  bindings is now called the root isolate. Child isolates can now be
  created from the root isolate and their bindings and thread
  configurations are now inherited from the root isolate.
* Terminating the shell terminates its root isolates as well as all the
  isolates spawned by this isolate. This is necessary be shell shutdown
  is deterministic and the embedder is free to collect the threads on
  which the isolates execute their tasks (and listen for mircrotasks
  flushes on).
* Launching the root isolate is now significantly overhauled. The shell
  side (non-owning) reference to an isolate is now a little state
  machine and illegal state transitions should be impossible (barring
  construction issues). This is the only way to manage Dart isolates in
  the shell (the shell does not use the C API is dart_api.h anymore).
* Once an isolate is launched, it must be prepared (and hence move to
  the ready phase) by associating a snapshot with the same. This
  snapshot can either be a precompiled snapshot, kernel snapshot, script
  snapshot or source file. Depending on the kind of data specified as a
  snapshot as well as the capabilities of the VM running in the process,
  isolate preparation can fail preparation with the right message.
* Asset management has been significantly overhauled. All asset
  resolution goes through an abstract asset resolver interface. An asset
  manager implements this interface and manages one or more child asset
  resolvers. These asset resolvers typically resolve assets from
  directories, ZIP files (legacy FLX assets if provided), APK bundles,
  FDIO namespaces, etc…
* Each launch of the shell requires a separate and fully configured
  asset resolver. This is necessary because launching isolates for the
  engine may require resolving snapshots as assets from the asset
  resolver. Asset resolvers can be shared by multiple launch instances
  in multiple shells and need to be thread safe.
* References to the command line object have been removed from the
  shell. Instead, the shell only takes a settings object that may be
  configured from the command line. This makes it easy for embedders and
  platforms that don’t have a command line (Fuchsia) to configure the
  shell. Consequently, there is only one spot where the various switches
  are read from the command line (by the embedder and not the shell) to
  form the settings object.
* All platform now respect the log tag (this was done only by Android
  till now) and each shell instance have its own log tag. This makes
  logs from multiple Flutter application in the same process (mainly
  Fuchsia) more easily decipherable.
* The per shell IO task runner now has a new component that is
  unfortunately named the IOManager. This component manages the IO
  GrContext (used for asynchronous texture uploads) that cooperates with
  the GrContext on the GPU task runner associated with the shell. The
  IOManager is also responsible for flushing tasks that collect Skia
  objects that reference GPU resources during deterministic shell
  shutdown.
* The embedder now has to be careful to only enable Blink on a single
  instance of the shell. Launching the legacy text layout and rendering
  engine multiple times is will trip assertions. The entirety of this
  runtime has been separated out into a separate object and can be
  removed in one go when the migration to libtxt is complete.
* There is a new test target for the various C++ objects that the shell
  uses to interact with the Dart VM (the shell no longer use the C API
  in dart_api.h). This allows engine developers to test VM/Isolate
  initialization and teardown without having the setup a full shell
  instance.
* There is a new test target for the testing a single shell instances
  without having to configure and launch an entire VM and associated
  root isolate.
* Mac, Linux & Windows used to have different target that created the
  flutter_tester referenced by the tool. This has now been converted
  into a single target that compiles on all platforms.
* WeakPointers vended by the fml::WeakPtrFactory(notice the difference
  between the same class in the fxl namespace) add threading checks on
  each use. This is enabled by getting rid of the “re-origination”
  feature of the WeakPtrFactory in the fxl namespace. The side effect of
  this is that all non-thread safe components have to be created, used
  and destroyed on the same thread. Numerous thread safety issues were
  caught by this extra assertion and have now been fixed.
  * Glossary of components that are only safe on a specific thread (and
    have the fml variants of the WeakPtrFactory):
    * Platform Thread: Shell
    * UI Thread: Engine, RuntimeDelegate, DartIsolate, Animator
    * GPU Thread: Rasterizer, Surface
    * IO Thread: IOManager

This patch was reviewed in smaller chunks in the following pull
requests. All comments from the pulls requests has been incorporated
into this patch:

* flutter/assets: https://github.com/flutter/engine/pull/4829
* flutter/common: https://github.com/flutter/engine/pull/4830
* flutter/content_handler: https://github.com/flutter/engine/pull/4831
* flutter/flow: https://github.com/flutter/engine/pull/4832
* flutter/fml: https://github.com/flutter/engine/pull/4833
* flutter/lib/snapshot: https://github.com/flutter/engine/pull/4834
* flutter/lib/ui: https://github.com/flutter/engine/pull/4835
* flutter/runtime: https://github.com/flutter/engine/pull/4836
* flutter/shell: https://github.com/flutter/engine/pull/4837
* flutter/synchronization: https://github.com/flutter/engine/pull/4838
* flutter/testing: https://github.com/flutter/engine/pull/4839
2018-04-10 14:57:02 -07:00