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
Add texture support for macOS shell. #8507
Merged
Merged
Changes from 4 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
5302cf8
Merge pull request #1 from flutter/master
cloudwebrtc 2953e13
Merge remote-tracking branch 'upstream/master'
cloudwebrtc 4b422b3
Add texture support for macOS shell.
cloudwebrtc fa3f8b0
code format.
cloudwebrtc a222a4a
Add missing file.
cloudwebrtc 668e656
Update FLETexture.h
cloudwebrtc 97f1e91
Update FLEPluginRegistrar.h
cloudwebrtc cd636b4
Restore header file order.
cloudwebrtc 799e9c1
Update code styles and comments.
cloudwebrtc 52b1417
Rename textureId to textureID.
cloudwebrtc e49c549
Update comment for FLEExternalTextureGL.h.
cloudwebrtc 7589f46
Update comments and partial code.
cloudwebrtc 2c60631
Rename the texture in some methods to disambiguate.
cloudwebrtc 42b7502
Merge remote-tracking branch 'upstream/master'
cloudwebrtc dbcdf16
Merge branch 'master' into macos_texture
cloudwebrtc 9b15427
Fix errors caused by merge master conflicts.
cloudwebrtc e4ff652
Merge remote-tracking branch 'upstream/master' into macos_texture
cloudwebrtc ba2efa3
Merge remote-tracking branch 'upstream/master' into macos_texture
cloudwebrtc 9c19bac
clang format.
cloudwebrtc 6ff0a76
gn format.
cloudwebrtc ec8083a
Add files to licenses_flutter.
cloudwebrtc ff49e14
Merge remote-tracking branch 'upstream/master' into macos_texture
cloudwebrtc ee09e69
clang-format.
cloudwebrtc 0f06004
Update.
cloudwebrtc 09156bf
Use shared FlutterTexture.h.
cloudwebrtc 235314a
clang-format.
cloudwebrtc 650c00a
Fixed FlutterTexture.h import path for ios.
cloudwebrtc d4c0be8
Update.
cloudwebrtc cda947c
clang-format.
cloudwebrtc e78d2e1
Change _pixelBuffer to a local variable.
cloudwebrtc eb3bf39
Add missing static on a local constant
stuartmorgan-g d622f01
Fix variable naming inconsistency
stuartmorgan-g ec70d4a
Merge branch 'master' into macos_texture
cloudwebrtc 2871956
Use drawImageRect to draw textures of undesired size.
cloudwebrtc 9b63c65
Merge branch 'macos_texture' of https://github.com/cloudwebrtc/flutte…
cloudwebrtc 4962f91
clang-format.
cloudwebrtc b20be2c
Fixed CI errors.
cloudwebrtc 067e8a1
update.
cloudwebrtc 27c6f94
clang-format.
cloudwebrtc 5f6833f
Merge remote-tracking branch 'upstream/master' into macos_texture
cloudwebrtc 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
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
34 changes: 34 additions & 0 deletions
34
shell/platform/darwin/macos/framework/Source/FLEExternalTextureGL.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,34 @@ | ||
// 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 <Foundation/Foundation.h> | ||
|
||
#import "flutter/shell/platform/darwin/macos/framework/Headers/FLETexture.h" | ||
#import "flutter/shell/platform/embedder/embedder.h" | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Used to bridge external FLETexture objects, | ||
* so the implementer only needs to return the CVPixelBufferRef object, | ||
* which will make the interface consistent with the FlutterTexture. | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
@interface FLEExternalTextureGL : NSObject | ||
|
||
/** | ||
* Initializes a texture adapter with |fleTexture|. | ||
*/ | ||
- (nonnull instancetype)initWithFLETexture:(nonnull id<FLETexture>)fleTexture; | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Accept texture rendering notifications from the flutter engine. | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
- (BOOL)populateTextureWidth:(size_t)width | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
height:(size_t)height | ||
texture:(nonnull FlutterOpenGLTexture*)texture; | ||
|
||
/** | ||
* The texture id. | ||
*/ | ||
- (int64_t)textureId; | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@end |
86 changes: 86 additions & 0 deletions
86
shell/platform/darwin/macos/framework/Source/FLEExternalTextureGL.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,86 @@ | ||
// 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/FLEExternalTextureGL.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're moving away from using FLE as a prefix, and this code isn't part of an unstable public API surface, you can use Flutter rather than FLE as the prefix for this class, so that it doesn't need to be renamed later. |
||
|
||
#import <AppKit/NSOpenGL.h> | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#import <CoreVideo/CVOpenGLBuffer.h> | ||
#import <CoreVideo/CVOpenGLTextureCache.h> | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#import <OpenGL/gl.h> | ||
|
||
@implementation FLEExternalTextureGL { | ||
CVOpenGLTextureCacheRef _textureCache; | ||
CVPixelBufferRef _pixelBuffer; | ||
id<FLETexture> _fleTexture; | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
- (instancetype)initWithFLETexture:(id<FLETexture>)fleTexture { | ||
self = [super init]; | ||
|
||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (self) { | ||
_fleTexture = fleTexture; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
static void OnGLTextureRelease(CVPixelBufferRef pixelBuffer) { | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CVPixelBufferRelease(pixelBuffer); | ||
} | ||
|
||
- (int64_t)textureId { | ||
return (NSInteger)(self); | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
- (BOOL)populateTextureWidth:(size_t)width | ||
height:(size_t)height | ||
texture:(FlutterOpenGLTexture*)texture { | ||
if (_fleTexture == NULL) { | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return NO; | ||
} | ||
|
||
// Copy image buffer from external texture. | ||
_pixelBuffer = [_fleTexture copyPixelBuffer:width height:height]; | ||
|
||
if (_pixelBuffer == NULL) { | ||
return NO; | ||
} | ||
|
||
// Create the texture cache if necessary. | ||
if (_textureCache == NULL) { | ||
CGLContextObj context = [NSOpenGLContext currentContext].CGLContextObj; | ||
CGLPixelFormatObj format = CGLGetPixelFormat(context); | ||
if (CVOpenGLTextureCacheCreate(kCFAllocatorDefault, NULL, context, format, NULL, | ||
&_textureCache) != kCVReturnSuccess) { | ||
NSLog(@"Could not create texture cache."); | ||
CVPixelBufferRelease(_pixelBuffer); | ||
return NO; | ||
} | ||
} | ||
|
||
// Try to clear the cache of OpenGL textures to save memory. | ||
CVOpenGLTextureCacheFlush(_textureCache, 0); | ||
|
||
CVOpenGLTextureRef openGLTexture = NULL; | ||
if (CVOpenGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault, _textureCache, _pixelBuffer, | ||
NULL, &openGLTexture) != kCVReturnSuccess) { | ||
CVPixelBufferRelease(_pixelBuffer); | ||
return NO; | ||
} | ||
|
||
texture->target = CVOpenGLTextureGetTarget(openGLTexture); | ||
texture->name = CVOpenGLTextureGetName(openGLTexture); | ||
texture->format = GL_RGBA8; | ||
texture->destruction_callback = (VoidCallback)&OnGLTextureRelease; | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
texture->user_data = openGLTexture; | ||
|
||
CVPixelBufferRelease(_pixelBuffer); | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return YES; | ||
} | ||
|
||
- (void)dealloc { | ||
CVOpenGLTextureCacheRelease(_textureCache); | ||
} | ||
|
||
@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
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.