Add FlutterCompositor base class (flutter/engine#25570)
This commit is contained in:
@@ -1110,6 +1110,8 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterBacki
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponderUnittests.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureUnittests.mm
|
||||
|
||||
@@ -61,6 +61,8 @@ source_set("flutter_framework_source") {
|
||||
"framework/Source/FlutterBackingStoreData.mm",
|
||||
"framework/Source/FlutterChannelKeyResponder.h",
|
||||
"framework/Source/FlutterChannelKeyResponder.mm",
|
||||
"framework/Source/FlutterCompositor.h",
|
||||
"framework/Source/FlutterCompositor.mm",
|
||||
"framework/Source/FlutterDartProject.mm",
|
||||
"framework/Source/FlutterDartProject_Internal.h",
|
||||
"framework/Source/FlutterEmbedderKeyResponder.h",
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// 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_COMPOSITOR_H_
|
||||
#define FLUTTER_COMPOSITOR_H_
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
// FlutterCompositor creates and manages the backing stores used for
|
||||
// rendering Flutter content and presents Flutter content and Platform views.
|
||||
// Platform views are not yet supported.
|
||||
class FlutterCompositor {
|
||||
public:
|
||||
FlutterCompositor(FlutterViewController* view_controller);
|
||||
|
||||
virtual ~FlutterCompositor() = default;
|
||||
|
||||
// Creates a BackingStore and saves updates the backing_store_out
|
||||
// data with the new BackingStore data.
|
||||
// If the backing store is being requested for the first time
|
||||
// for a given frame, we do not create a new backing store but
|
||||
// rather return the backing store associated with the
|
||||
// FlutterView's FlutterSurfaceManager.
|
||||
//
|
||||
// Any additional state allocated for the backing store and
|
||||
// saved as user_data in the backing store must be collected
|
||||
// in the backing_store's destruction_callback field which will
|
||||
// be called when the embedder collects the backing store.
|
||||
virtual bool CreateBackingStore(const FlutterBackingStoreConfig* config,
|
||||
FlutterBackingStore* backing_store_out) = 0;
|
||||
|
||||
// Releases the memory for any state used by the backing store.
|
||||
virtual bool CollectBackingStore(
|
||||
const FlutterBackingStore* backing_store) = 0;
|
||||
|
||||
// Presents the FlutterLayers by updating FlutterView(s) using the
|
||||
// layer content.
|
||||
// Present sets frame_started_ to false.
|
||||
virtual bool Present(const FlutterLayer** layers, size_t layers_count) = 0;
|
||||
|
||||
using PresentCallback = std::function<bool()>;
|
||||
|
||||
// PresentCallback is called at the end of the Present function.
|
||||
void SetPresentCallback(const PresentCallback& present_callback);
|
||||
|
||||
protected:
|
||||
__weak const FlutterViewController* view_controller_;
|
||||
|
||||
PresentCallback present_callback_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(FlutterCompositor);
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_COMPOSITOR_H_
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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.
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
FlutterCompositor::FlutterCompositor(FlutterViewController* view_controller) {
|
||||
FML_CHECK(view_controller != nullptr) << "FlutterViewController* cannot be nullptr";
|
||||
|
||||
view_controller_ = view_controller;
|
||||
}
|
||||
|
||||
void FlutterCompositor::SetPresentCallback(
|
||||
const FlutterCompositor::PresentCallback& present_callback) {
|
||||
present_callback_ = present_callback;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
@@ -5,8 +5,9 @@
|
||||
#include <map>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/platform/darwin/macos/framework/Source/FlutterBackingStoreData.h"
|
||||
#include "flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h"
|
||||
#include "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
|
||||
#include "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
#include "third_party/skia/include/gpu/GrDirectContext.h"
|
||||
|
||||
@@ -16,11 +17,13 @@ namespace flutter {
|
||||
// rendering Flutter content and presents Flutter content and Platform views.
|
||||
// Platform views are not yet supported.
|
||||
// FlutterGLCompositor is created and destroyed by FlutterEngine.
|
||||
class FlutterGLCompositor {
|
||||
class FlutterGLCompositor : public FlutterCompositor {
|
||||
public:
|
||||
FlutterGLCompositor(FlutterViewController* view_controller,
|
||||
NSOpenGLContext* opengl_context);
|
||||
|
||||
virtual ~FlutterGLCompositor() = default;
|
||||
|
||||
// Creates a BackingStore and saves updates the backing_store_out
|
||||
// data with the new BackingStore data.
|
||||
// If the backing store is being requested for the first time
|
||||
@@ -33,25 +36,18 @@ class FlutterGLCompositor {
|
||||
// in the backing_store's destruction_callback field which will
|
||||
// be called when the embedder collects the backing store.
|
||||
bool CreateBackingStore(const FlutterBackingStoreConfig* config,
|
||||
FlutterBackingStore* backing_store_out);
|
||||
FlutterBackingStore* backing_store_out) override;
|
||||
|
||||
// Releases the memory for any state used by the backing store.
|
||||
bool CollectBackingStore(const FlutterBackingStore* backing_store);
|
||||
bool CollectBackingStore(const FlutterBackingStore* backing_store) override;
|
||||
|
||||
// Presents the FlutterLayers by updating FlutterView(s) using the
|
||||
// layer content.
|
||||
// Present sets frame_started_ to false.
|
||||
bool Present(const FlutterLayer** layers, size_t layers_count);
|
||||
|
||||
using PresentCallback = std::function<bool()>;
|
||||
|
||||
// PresentCallback is called at the end of the Present function.
|
||||
void SetPresentCallback(const PresentCallback& present_callback);
|
||||
bool Present(const FlutterLayer** layers, size_t layers_count) override;
|
||||
|
||||
private:
|
||||
__weak const FlutterViewController* view_controller_;
|
||||
const NSOpenGLContext* open_gl_context_;
|
||||
PresentCallback present_callback_;
|
||||
|
||||
// Count for how many CALayers have been created for a frame.
|
||||
// Resets when a frame is finished.
|
||||
|
||||
@@ -21,10 +21,7 @@ namespace flutter {
|
||||
|
||||
FlutterGLCompositor::FlutterGLCompositor(FlutterViewController* view_controller,
|
||||
NSOpenGLContext* opengl_context)
|
||||
: open_gl_context_(opengl_context) {
|
||||
FML_CHECK(view_controller != nullptr) << "FlutterViewController* cannot be nullptr";
|
||||
view_controller_ = view_controller;
|
||||
}
|
||||
: FlutterCompositor(view_controller), open_gl_context_(opengl_context) {}
|
||||
|
||||
bool FlutterGLCompositor::CreateBackingStore(const FlutterBackingStoreConfig* config,
|
||||
FlutterBackingStore* backing_store_out) {
|
||||
@@ -117,11 +114,6 @@ bool FlutterGLCompositor::Present(const FlutterLayer** layers, size_t layers_cou
|
||||
return present_callback_();
|
||||
}
|
||||
|
||||
void FlutterGLCompositor::SetPresentCallback(
|
||||
const FlutterGLCompositor::PresentCallback& present_callback) {
|
||||
present_callback_ = present_callback;
|
||||
}
|
||||
|
||||
void FlutterGLCompositor::StartFrame() {
|
||||
// First reset all the state.
|
||||
ca_layer_count_ = 0;
|
||||
|
||||
Reference in New Issue
Block a user