This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
(MacOS) Add FlutterGLCompositor with support for rendering multiple layers #22782
Merged
RichardJCai
merged 2 commits into
flutter:master
from
RichardJCai:flutter_gl_compositor_11302020
Dec 3, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
shell/platform/darwin/macos/framework/Source/FlutterBackingStoreData.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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/FlutterFrameBufferProvider.h" | ||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolder.h" | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
* FlutterBackingStoreData holds data to be stored in the | ||
* BackingStore's user_data. | ||
*/ | ||
@interface FlutterBackingStoreData : NSObject | ||
|
||
- (nullable instancetype)initWithLayerId:(size_t)layerId | ||
fbProvider:(nonnull FlutterFrameBufferProvider*)fbProvider | ||
ioSurfaceHolder:(nonnull FlutterIOSurfaceHolder*)ioSurfaceHolder; | ||
|
||
/** | ||
* The layer's key value in FlutterGLCompositor's ca_layer_map_. | ||
*/ | ||
@property(nonatomic, readonly) size_t layerId; | ||
|
||
/** | ||
* Provides the fbo for rendering the layer. | ||
*/ | ||
@property(nonnull, nonatomic, readonly) FlutterFrameBufferProvider* frameBufferProvider; | ||
|
||
/** | ||
* Contains the IOSurfaceRef with the layer contents. | ||
*/ | ||
@property(nonnull, nonatomic, readonly) FlutterIOSurfaceHolder* ioSurfaceHolder; | ||
|
||
@end |
24 changes: 24 additions & 0 deletions
24
shell/platform/darwin/macos/framework/Source/FlutterBackingStoreData.mm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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/FlutterBackingStoreData.h" | ||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProvider.h" | ||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolder.h" | ||
|
||
#include <OpenGL/gl.h> | ||
|
||
@implementation FlutterBackingStoreData | ||
|
||
- (nullable instancetype)initWithLayerId:(size_t)layerId | ||
fbProvider:(nonnull FlutterFrameBufferProvider*)fbProvider | ||
ioSurfaceHolder:(nonnull FlutterIOSurfaceHolder*)ioSurfaceHolder { | ||
if (self = [super init]) { | ||
_layerId = layerId; | ||
_frameBufferProvider = fbProvider; | ||
_ioSurfaceHolder = ioSurfaceHolder; | ||
} | ||
return self; | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// 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. | ||
|
||
#include <map> | ||
|
||
#include "flutter/fml/macros.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" | ||
|
||
namespace flutter { | ||
|
||
// FlutterGLCompositor creates and manages the backing stores used for | ||
// 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 { | ||
public: | ||
FlutterGLCompositor(FlutterViewController* view_controller); | ||
|
||
// 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 desctruction_callback field which will | ||
// be called when the embedder collects the backing store. | ||
bool CreateBackingStore(const FlutterBackingStoreConfig* config, | ||
FlutterBackingStore* backing_store_out); | ||
|
||
// Releases the memory for any state used by the backing store. | ||
bool CollectBackingStore(const FlutterBackingStore* backing_store); | ||
|
||
// 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); | ||
|
||
private: | ||
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. | ||
// ca_layer_count_ is also used as a layerId. | ||
size_t ca_layer_count_ = 0; | ||
|
||
// Maps a layer_id (size_t) to a CALayer. | ||
// The layer_id starts at 0 for a given frame | ||
// and increments by 1 for each new CALayer. | ||
std::map<size_t, CALayer*> ca_layer_map_; | ||
|
||
// frame_started_ keeps track of if a layer has been | ||
// created for the frame. | ||
bool frame_started_ = false; | ||
|
||
// Set frame_started_ to true and reset all layer state. | ||
void StartFrame(); | ||
|
||
// Creates a CALayer and adds it to ca_layer_map_ and increments | ||
// ca_layer_count_; Returns the key value (size_t) for the layer in | ||
// ca_layer_map_. | ||
size_t CreateCALayer(); | ||
|
||
FML_DISALLOW_COPY_AND_ASSIGN(FlutterGLCompositor); | ||
}; | ||
|
||
} // namespace flutter |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.