Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Revert "[metal] Darwin unified external metal textures" #24223

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -969,8 +969,6 @@ FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_cod
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.h
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Flutter.podspec
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/Flutter.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h
Expand Down
2 changes: 0 additions & 2 deletions common/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,4 @@ if (is_ios || is_mac) {
"-Werror=undeclared-selector",
]
flutter_cflags_objcc = flutter_cflags_objc
flutter_cflags_objc_arc = flutter_cflags_objc + [ "-fobjc-arc" ]
flutter_cflags_objcc_arc = flutter_cflags_objc_arc
}
4 changes: 2 additions & 2 deletions common/graphics/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace flutter {

class Texture {
public:
explicit Texture(int64_t id); // Called from UI or raster thread.
virtual ~Texture(); // Called from raster thread.
Texture(int64_t id); // Called from UI or raster thread.
virtual ~Texture(); // Called from raster thread.

// Called from raster thread.
virtual void Paint(SkCanvas& canvas,
Expand Down
9 changes: 2 additions & 7 deletions shell/platform/darwin/graphics/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@ assert(is_ios || is_mac)
import("//flutter/common/config.gni")

source_set("graphics") {
cflags_objc = flutter_cflags_objc_arc
cflags_objcc = flutter_cflags_objcc_arc
cflags_objc = flutter_cflags_objc
cflags_objcc = flutter_cflags_objcc

sources = [
"FlutterDarwinContextMetal.h",
"FlutterDarwinContextMetal.mm",
"FlutterDarwinExternalTextureMetal.h",
"FlutterDarwinExternalTextureMetal.mm",
]

deps = [
"//flutter/common/graphics",
"//flutter/fml",
"//flutter/shell/platform/darwin/common:framework_shared",
]

libs = [ "CoreVideo.framework" ]

public_deps = [ "//third_party/skia" ]

public_configs = [ "//flutter:config" ]
Expand Down
15 changes: 0 additions & 15 deletions shell/platform/darwin/graphics/FlutterDarwinContextMetal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
#ifndef SHELL_PLATFORM_DARWIN_GRAPHICS_DARWIN_CONTEXT_METAL_H_
#define SHELL_PLATFORM_DARWIN_GRAPHICS_DARWIN_CONTEXT_METAL_H_

#import <CoreVideo/CVMetalTextureCache.h>
#import <Foundation/Foundation.h>
#import <Metal/Metal.h>

#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -32,13 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithMTLDevice:(id<MTLDevice>)device
commandQueue:(id<MTLCommandQueue>)commandQueue;

/**
* Creates an external texture with the specified ID and contents.
*/
- (FlutterDarwinExternalTextureMetal*)
createExternalTextureWithIdentifier:(int64_t)textureID
texture:(NSObject<FlutterTexture>*)texture;

/**
* MTLDevice that is backing this context.s
*/
Expand All @@ -60,11 +50,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property(nonatomic, readonly) sk_sp<GrDirectContext> resourceContext;

/*
* Texture cache for external textures.
*/
@property(nonatomic, readonly) CVMetalTextureCacheRef textureCache;

@end

NS_ASSUME_NONNULL_END
Expand Down
38 changes: 7 additions & 31 deletions shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

#include "flutter/common/graphics/persistent_cache.h"
#include "flutter/fml/logging.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"

FLUTTER_ASSERT_ARC

static GrContextOptions CreateMetalGrContextOptions() {
GrContextOptions options = {};
if (flutter::PersistentCache::cache_sksl()) {
Expand All @@ -36,39 +33,32 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)device

if (!_device) {
FML_DLOG(ERROR) << "Could not acquire Metal device.";
[self release];
return nil;
}

_commandQueue = commandQueue;

if (!_commandQueue) {
FML_DLOG(ERROR) << "Could not create Metal command queue.";
[self release];
return nil;
}

[_commandQueue setLabel:@"Flutter Main Queue"];

CVReturn cvReturn = CVMetalTextureCacheCreate(kCFAllocatorDefault, // allocator
nil, // cache attributes (nil default)
_device, // metal device
nil, // texture attributes (nil default)
&_textureCache // [out] cache
);
if (cvReturn != kCVReturnSuccess) {
FML_DLOG(ERROR) << "Could not create Metal texture cache.";
return nil;
}

auto contextOptions = CreateMetalGrContextOptions();

// Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
// when the GrDirectContext is collected.
_mainContext = GrDirectContext::MakeMetal(
(__bridge_retained void*)_device, (__bridge_retained void*)_commandQueue, contextOptions);
_resourceContext = _mainContext;
_mainContext =
GrDirectContext::MakeMetal([_device retain], [_commandQueue retain], contextOptions);
_resourceContext =
GrDirectContext::MakeMetal([_device retain], [_commandQueue retain], contextOptions);

if (!_mainContext || !_resourceContext) {
FML_DLOG(ERROR) << "Could not create Skia Metal contexts.";
[self release];
return nil;
}

Expand All @@ -77,18 +67,4 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)device
return self;
}

- (void)dealloc {
if (_textureCache) {
CFRelease(_textureCache);
}
}

- (FlutterDarwinExternalTextureMetal*)
createExternalTextureWithIdentifier:(int64_t)textureID
texture:(NSObject<FlutterTexture>*)texture {
return [[FlutterDarwinExternalTextureMetal alloc] initWithTextureCache:_textureCache
textureID:textureID
texture:texture];
}

@end
34 changes: 0 additions & 34 deletions shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h

This file was deleted.

Loading