[macos] Release the copied pixel buffer after texture creation (flutter/engine#25548)

This commit is contained in:
Kaushik Iska
2021-04-12 13:54:14 -07:00
committed by GitHub
parent 0cf406f7e9
commit 76f3f23faf
4 changed files with 21 additions and 8 deletions

View File

@@ -39,6 +39,12 @@ NS_ASSUME_NONNULL_BEGIN
createExternalTextureWithIdentifier:(int64_t)textureID
texture:(NSObject<FlutterTexture>*)texture;
/**
* Creates a GrDirectContext with the provided `MTLDevice` and `MTLCommandQueue`.
*/
+ (sk_sp<GrDirectContext>)createGrContext:(id<MTLDevice>)device
commandQueue:(id<MTLCommandQueue>)commandQueue;
/**
* MTLDevice that is backing this context.s
*/

View File

@@ -76,6 +76,12 @@ static GrContextOptions CreateMetalGrContextOptions() {
auto contextOptions = CreateMetalGrContextOptions();
id<MTLDevice> device = _device;
id<MTLCommandQueue> commandQueue = _commandQueue;
return [FlutterDarwinContextMetal createGrContext:device commandQueue:commandQueue];
}
+ (sk_sp<GrDirectContext>)createGrContext:(id<MTLDevice>)device
commandQueue:(id<MTLCommandQueue>)commandQueue {
auto contextOptions = CreateMetalGrContextOptions();
// Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
// when the GrDirectContext is collected.
return GrDirectContext::MakeMetal((__bridge_retained void*)device,

View File

@@ -4,6 +4,8 @@
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h"
#include "flutter/fml/platform/darwin/cf_utils.h"
@implementation FlutterExternalTextureMetal {
FlutterDarwinContextMetal* _darwinMetalContext;
@@ -31,7 +33,7 @@
- (BOOL)populateTexture:(FlutterMetalExternalTexture*)textureOut {
// Copy the pixel buffer from the FlutterTexture instance implemented on the user side.
CVPixelBufferRef pixelBuffer = [_texture copyPixelBuffer];
fml::CFRef<CVPixelBufferRef> pixelBuffer([_texture copyPixelBuffer]);
if (!pixelBuffer) {
return NO;

View File

@@ -5,11 +5,11 @@
#include "flutter/shell/platform/embedder/embedder_surface_metal.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
FLUTTER_ASSERT_NOT_ARC
namespace flutter {
EmbedderSurfaceMetal::EmbedderSurfaceMetal(
@@ -20,12 +20,11 @@ EmbedderSurfaceMetal::EmbedderSurfaceMetal(
: GPUSurfaceMetalDelegate(MTLRenderTargetType::kMTLTexture),
metal_dispatch_table_(metal_dispatch_table),
external_view_embedder_(external_view_embedder) {
auto darwin_metal_context =
fml::scoped_nsobject<FlutterDarwinContextMetal>{[[[FlutterDarwinContextMetal alloc]
initWithMTLDevice:(id<MTLDevice>)device
commandQueue:(id<MTLCommandQueue>)command_queue] retain]};
main_context_ = darwin_metal_context.get().mainContext;
resource_context_ = darwin_metal_context.get().resourceContext;
main_context_ = [FlutterDarwinContextMetal createGrContext:(id<MTLDevice>)device
commandQueue:(id<MTLCommandQueue>)command_queue];
resource_context_ =
[FlutterDarwinContextMetal createGrContext:(id<MTLDevice>)device
commandQueue:(id<MTLCommandQueue>)command_queue];
valid_ = main_context_ && resource_context_;
}