flutter_flutter/shell/platform/embedder/embedder_external_view_embedder.h
Adlai Holler c57aff1800
Use the GrDirectContext factories instead of deprecated GrContext ones (#19962)
This is part of a larger effort to expose the difference between GrDirectContext,
which runs on the GPU thread and can directly perform operations like uploading
textures, and GrRecordingContext, which can only queue up work to be delivered
to the GrDirectContext later.
2020-07-28 13:32:09 -07:00

121 lines
4.7 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_EXTERNAL_VIEW_EMBEDDER_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_EMBEDDER_H_
#include <map>
#include <unordered_map>
#include "flutter/flow/embedded_views.h"
#include "flutter/fml/hash_combine.h"
#include "flutter/fml/macros.h"
#include "flutter/shell/platform/embedder/embedder_external_view.h"
#include "flutter/shell/platform/embedder/embedder_render_target_cache.h"
namespace flutter {
//------------------------------------------------------------------------------
/// @brief The external view embedder used by the generic embedder API.
/// This class acts a proxy between the rasterizer and the embedder
/// when the rasterizer is rendering into multiple layers. It asks
/// the embedder for the render targets for the various layers the
/// rasterizer is rendering into, recycles the render targets as
/// necessary and converts rasterizer specific metadata into an
/// embedder friendly format so that it can present the layers
/// on-screen.
///
class EmbedderExternalViewEmbedder final : public ExternalViewEmbedder {
public:
using CreateRenderTargetCallback =
std::function<std::unique_ptr<EmbedderRenderTarget>(
GrDirectContext* context,
const FlutterBackingStoreConfig& config)>;
using PresentCallback =
std::function<bool(const std::vector<const FlutterLayer*>& layers)>;
using SurfaceTransformationCallback = std::function<SkMatrix(void)>;
//----------------------------------------------------------------------------
/// @brief Creates an external view embedder used by the generic embedder
/// API.
///
/// @param[in] create_render_target_callback
/// The render target callback used to
/// request the render target for a layer.
/// @param[in] present_callback The callback used to forward a
/// collection of layers (backed by
/// fulfilled render targets) to the
/// embedder for presentation.
///
EmbedderExternalViewEmbedder(
const CreateRenderTargetCallback& create_render_target_callback,
const PresentCallback& present_callback);
//----------------------------------------------------------------------------
/// @brief Collects the external view embedder.
///
~EmbedderExternalViewEmbedder() override;
//----------------------------------------------------------------------------
/// @brief Sets the surface transformation callback used by the external
/// view embedder to ask the platform for the per frame root
/// surface transformation.
///
/// @param[in] surface_transformation_callback The surface transformation
/// callback
///
void SetSurfaceTransformationCallback(
SurfaceTransformationCallback surface_transformation_callback);
private:
// |ExternalViewEmbedder|
void CancelFrame() override;
// |ExternalViewEmbedder|
void BeginFrame(
SkISize frame_size,
GrDirectContext* context,
double device_pixel_ratio,
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) override;
// |ExternalViewEmbedder|
void PrerollCompositeEmbeddedView(
int view_id,
std::unique_ptr<EmbeddedViewParams> params) override;
// |ExternalViewEmbedder|
std::vector<SkCanvas*> GetCurrentCanvases() override;
// |ExternalViewEmbedder|
SkCanvas* CompositeEmbeddedView(int view_id) override;
// |ExternalViewEmbedder|
void SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) override;
// |ExternalViewEmbedder|
SkCanvas* GetRootCanvas() override;
private:
const CreateRenderTargetCallback create_render_target_callback_;
const PresentCallback present_callback_;
SurfaceTransformationCallback surface_transformation_callback_;
SkISize pending_frame_size_ = SkISize::Make(0, 0);
double pending_device_pixel_ratio_ = 1.0;
SkMatrix pending_surface_transformation_;
EmbedderExternalView::PendingViews pending_views_;
std::vector<EmbedderExternalView::ViewIdentifier> composition_order_;
EmbedderRenderTargetCache render_target_cache_;
void Reset();
SkMatrix GetSurfaceTransformation() const;
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderExternalViewEmbedder);
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_EMBEDDER_H_