-
Notifications
You must be signed in to change notification settings - Fork 6k
Add texture support for macOS shell. #8507
Changes from 13 commits
5302cf8
2953e13
4b422b3
fa3f8b0
a222a4a
668e656
97f1e91
cd636b4
799e9c1
52b1417
e49c549
7589f46
2c60631
42b7502
dbcdf16
9b15427
e4ff652
ba2efa3
9c19bac
6ff0a76
ec8083a
ff49e14
ee09e69
0f06004
09156bf
235314a
650c00a
d4c0be8
cda947c
e78d2e1
eb3bf39
d622f01
ec70d4a
2871956
9b63c65
4962f91
b20be2c
067e8a1
27c6f94
5f6833f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
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. This appears to be identical to FlutterTexture.h other than the prefixes; now that macOS is in the same repo as iOS the goal is to share code whenever possible (and move away from the FLE prefix). You can just add that file to the (If you want to add these comments to FlutterTexture.h, ideally as a separate PR, that would be great, since the existing file isn't commented at all.) 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. @chinmaygarde @stuartmorgan 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. You should be able to specify that the texture target is GL_TEXTURE_RECTANGLE by specifying the target property of FlutterOpenGLTexture. All the copying ought to be unnecessarily inefficient. |
||
// 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 <CoreVideo/CoreVideo.h> | ||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
* Implement a texture object for the FLE plugin side. | ||
*/ | ||
@protocol FLETexture <NSObject> | ||
|
||
/** | ||
* When the texture on the platform side is ready, | ||
* the flutter engine will copy the texture buffer | ||
* using copyPixelBuffer. | ||
*/ | ||
- (nullable CVPixelBufferRef)copyPixelBuffer:(size_t)width height:(size_t)height; | ||
|
||
@end | ||
|
||
/** | ||
* The protocol for an object managing registration for texture. | ||
*/ | ||
@protocol FLETextureRegistrar <NSObject> | ||
|
||
/** | ||
* Register a |texture| object and return a textureID. | ||
*/ | ||
- (int64_t)registerTexture:(nonnull id<FLETexture>)texture; | ||
|
||
/** | ||
* Mark a texture buffer is ready. | ||
*/ | ||
- (void)textureFrameAvailable:(int64_t)textureID; | ||
|
||
/** | ||
* Unregister an existing Texture object. | ||
*/ | ||
- (void)unregisterTexture:(int64_t)textureID; | ||
|
||
@end |
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 <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 FLETexture object and handle the texture copy request the | ||
* flutter engine. | ||
*/ | ||
@interface FLEExternalTextureGL : NSObject | ||
|
||
/** | ||
* Initializes a texture adapter with |texture| return a instance. | ||
*/ | ||
- (nonnull instancetype)initWithFLETexture:(nonnull id<FLETexture>)texture; | ||
|
||
/** | ||
* Accepts texture buffer copy request from the flutter engine. | ||
* When the user side marks the textureId as available, the flutter engine will | ||
* callback to this method and ask for populate the |openGLTexture| object, | ||
* such as the texture type and the format of the pixel buffer and the texture object. | ||
*/ | ||
- (BOOL)populateTextureWithWidth:(size_t)width | ||
height:(size_t)height | ||
openGLTexture:(nonnull FlutterOpenGLTexture*)openGLTexture; | ||
|
||
/** | ||
* Returns the ID for the FLETexture instance. | ||
*/ | ||
- (int64_t)textureID; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// 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/AppKit.h> | ||
#import <CoreVideo/CoreVideo.h> | ||
#import <OpenGL/gl.h> | ||
|
||
static void OnGLTextureRelease(CVPixelBufferRef pixelBuffer) { | ||
CVPixelBufferRelease(pixelBuffer); | ||
} | ||
|
||
@implementation FLEExternalTextureGL { | ||
/** | ||
* OpenGL texture cache. | ||
*/ | ||
CVOpenGLTextureCacheRef _openGLTextureCache; | ||
/** | ||
* The pixel buffer copied from the user side will be released | ||
* when the flutter engine renders it. | ||
*/ | ||
CVPixelBufferRef _pixelBuffer; | ||
/** | ||
* User side texture object, used to copy pixel buffer. | ||
*/ | ||
id<FLETexture> _texture; | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
- (instancetype)initWithFLETexture:(id<FLETexture>)texture { | ||
self = [super init]; | ||
if (self) { | ||
_texture = texture; | ||
} | ||
return self; | ||
} | ||
|
||
- (int64_t)textureID { | ||
return reinterpret_cast<int64_t>(self); | ||
} | ||
|
||
- (BOOL)populateTextureWithWidth:(size_t)width | ||
height:(size_t)height | ||
openGLTexture:(FlutterOpenGLTexture*)openGLTexture { | ||
// Copy the pixel buffer from the FLETexture instance implemented on the user side. | ||
_pixelBuffer = [_texture copyPixelBuffer:width height:height]; | ||
|
||
if (!_pixelBuffer) { | ||
return NO; | ||
} | ||
|
||
// Create the opengl texture cache if necessary. | ||
if (!_openGLTextureCache) { | ||
CGLContextObj context = [NSOpenGLContext currentContext].CGLContextObj; | ||
CGLPixelFormatObj format = CGLGetPixelFormat(context); | ||
if (CVOpenGLTextureCacheCreate(kCFAllocatorDefault, NULL, context, format, NULL, | ||
&_openGLTextureCache) != kCVReturnSuccess) { | ||
NSLog(@"Could not create texture cache."); | ||
CVPixelBufferRelease(_pixelBuffer); | ||
return NO; | ||
} | ||
} | ||
|
||
// Try to clear the cache of OpenGL textures to save memory. | ||
CVOpenGLTextureCacheFlush(_openGLTextureCache, 0); | ||
|
||
CVOpenGLTextureRef cvOpenGLTexture = NULL; | ||
if (CVOpenGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault, _openGLTextureCache, | ||
_pixelBuffer, NULL, | ||
&cvOpenGLTexture) != kCVReturnSuccess) { | ||
CVPixelBufferRelease(_pixelBuffer); | ||
return NO; | ||
} | ||
CVPixelBufferRelease(_pixelBuffer); | ||
cloudwebrtc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
openGLTexture->target = static_cast<uint32_t>(CVOpenGLTextureGetTarget(cvOpenGLTexture)); | ||
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. @cloudwebrtc Are you saying that CVOpenGLTextureGetTarget is not returning GL_TEXTURE_RECTANGLE? I am a little bit confused. There should be no issues with having to convert to GL_TEXTURE_2D here. 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. @chinmaygarde See CVOpenGLTextureGetTarget from the code context
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
index d003dc9397..04357e2a4c 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.cpp
+++ b/src/sksl/SkSLGLSLCodeGenerator.cpp
@@ -656,7 +656,7 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
proj = false;
break;
case SpvDimRect:
- dim = "Rect";
+ dim = "2DRect";
proj = false;
break;
case SpvDimBuffer: Then I can see the texture display, but the picture is not correct.
shell/platform/embedder/embedder.h#L214 Typedef bool (*TextureFrameCallback)(void* /* user data */,
Int64_t /* texture identifier */,
Size_t /* width */,
Size_t /* height */,
FlutterOpenGLTexture* /* texture out */); Looks like this: I am not sure that the type of dim in SpvDimRect is a bug in skia on macos. |
||
openGLTexture->name = static_cast<uint32_t>(CVOpenGLTextureGetName(cvOpenGLTexture)); | ||
openGLTexture->format = static_cast<uint32_t>(GL_RGBA8); | ||
openGLTexture->destruction_callback = (VoidCallback)OnGLTextureRelease; | ||
openGLTexture->user_data = cvOpenGLTexture; | ||
return YES; | ||
} | ||
|
||
- (void)dealloc { | ||
CVOpenGLTextureCacheRelease(_openGLTextureCache); | ||
} | ||
|
||
@end |
Uh oh!
There was an error while loading. Please reload this page.