diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 093f8c362c..d5e25a91ec 100755 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -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 diff --git a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn index dfb5d736fa..872c4a681d 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn @@ -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", diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h new file mode 100644 index 0000000000..aae5f0a439 --- /dev/null +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.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 + +#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; + + // 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_ diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm new file mode 100644 index 0000000000..3f5057ab0a --- /dev/null +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm @@ -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 diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h index fb06edf29c..a5e8c37091 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h @@ -5,8 +5,9 @@ #include #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; - - // 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. diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.mm index 42c770786d..97e1c9d7f2 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.mm @@ -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;