mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This patch allows embedders to split the Flutter layer tree into multiple chunks. These chunks are meant to be composed one on top of another. This gives embedders a chance to interleave their own contents between these chunks. The Flutter embedder API already provides hooks for the specification of textures for the Flutter engine to compose within its own hierarchy (for camera feeds, video, etc..). However, not all embedders can render the contents of such sources into textures the Flutter engine can accept. Moreover, this composition model may have overheads that are non-trivial for certain use cases. In such cases, the embedder may choose to specify multiple render target for Flutter to render into instead of just one. The use of this API allows embedders to perform composition very similar to the iOS embedder. This composition model is used on that platform for the embedding of UIKit view such and web view and map views within the Flutter hierarchy. However, do note that iOS also has threading configurations that are currently not available to custom embedders. The embedder API updates in this patch are ABI stable and existing embedders will continue to work are normal. For embedders that want to enable this composition mode, the API is designed to make it easy to opt into the same in an incremental manner. Rendering of contents into the “root” rendering surface remains unchanged. However, now the application can push “platform views” via a scene builder. These platform views need to handled by a FlutterCompositor specified in a new field at the end of the FlutterProjectArgs struct. When a new platform view in introduced within the layer tree, the compositor will ask the embedder to create a new render target for that platform view. Render targets can currently be OpenGL framebuffers, OpenGL textures or software buffers. The type of the render target returned by the embedder must be compatible with the root render surface. That is, if the root render surface is an OpenGL framebuffer, the render target for each platform view must either be a texture or a framebuffer in the same OpenGL context. New render target types as well as root renderers for newer APIs like Metal & Vulkan can and will be added in the future. The addition of these APIs will be done in an ABI & API stable manner. As Flutter renders frames, it gives the embedder a callback with information about the position of the various platform views in the effective hierarchy. The embedder is then meant to put the contents of the render targets that it setup and had previously given to the engine onto the screen (of course interleaving the contents of the platform views). Unit-tests have been added that test not only the structure and properties of layer hierarchy given to the compositor, but also the contents of the texels rendered by a test compositor using both the OpenGL and software rendering backends. Fixes b/132812775 Fixes flutter/flutter#35410
79 lines
3.3 KiB
C++
79 lines
3.3 KiB
C++
// 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.
|
|
|
|
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_RENDER_TARGET_H_
|
|
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_RENDER_TARGET_H_
|
|
|
|
#include "flutter/fml/closure.h"
|
|
#include "flutter/fml/macros.h"
|
|
#include "flutter/shell/platform/embedder/embedder.h"
|
|
#include "third_party/skia/include/core/SkCanvas.h"
|
|
#include "third_party/skia/include/core/SkSurface.h"
|
|
|
|
namespace flutter {
|
|
|
|
//------------------------------------------------------------------------------
|
|
/// @brief Describes a surface whose backing store is managed by the
|
|
/// embedder. The type of surface depends on the client rendering
|
|
/// API used. The embedder is notified of the collection of this
|
|
/// render target via a callback.
|
|
///
|
|
class EmbedderRenderTarget {
|
|
public:
|
|
//----------------------------------------------------------------------------
|
|
/// @brief Creates a render target whose backing store is managed by the
|
|
/// embedder. The way this render target is exposed to the engine
|
|
/// is via an SkSurface and a callback that is invoked by this
|
|
/// object in its destructor.
|
|
///
|
|
/// @param[in] backing_store The backing store describing this render
|
|
/// target.
|
|
/// @param[in] render_surface The surface for this target.
|
|
/// @param[in] on_release The callback to invoke (eventually forwarded
|
|
/// to the embedder) when the backing store is no
|
|
/// longer required by the engine.
|
|
///
|
|
EmbedderRenderTarget(FlutterBackingStore backing_store,
|
|
sk_sp<SkSurface> render_surface,
|
|
fml::closure on_release);
|
|
|
|
//----------------------------------------------------------------------------
|
|
/// @brief Destroys this instance of the render target and invokes the
|
|
/// callback for the embedder to release its resource associated
|
|
/// with the particular backing store.
|
|
///
|
|
~EmbedderRenderTarget();
|
|
|
|
//----------------------------------------------------------------------------
|
|
/// @brief A render surface the rasterizer can use to draw into the
|
|
/// backing store of this render target.
|
|
///
|
|
/// @return The render surface.
|
|
///
|
|
sk_sp<SkSurface> GetRenderSurface();
|
|
|
|
//----------------------------------------------------------------------------
|
|
/// @brief The embedder backing store descriptor. This is the descriptor
|
|
/// that was given to the engine by the embedder. This descriptor
|
|
/// may contain context the embedder can use to associate it
|
|
/// resources with the compositor layers when they are given back
|
|
/// to it in present callback. The engine does not use this in any
|
|
/// way.
|
|
///
|
|
/// @return The backing store.
|
|
///
|
|
const FlutterBackingStore* GetBackingStore() const;
|
|
|
|
private:
|
|
FlutterBackingStore backing_store_;
|
|
sk_sp<SkSurface> render_surface_;
|
|
fml::closure on_release_;
|
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderRenderTarget);
|
|
};
|
|
|
|
} // namespace flutter
|
|
|
|
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_RENDER_TARGET_H_
|