// 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/ios/ios_context_metal.h" #include "flutter/common/graphics/persistent_cache.h" #include "flutter/fml/logging.h" #import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.h" #import "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h" #include "third_party/skia/include/gpu/GrContextOptions.h" namespace flutter { IOSContextMetal::IOSContextMetal() { darwin_context_metal_ = fml::scoped_nsobject{ [[[FlutterDarwinContextMetal alloc] initWithDefaultMTLDevice] retain]}; if (!darwin_context_metal_) { return; } main_command_queue_.reset([darwin_context_metal_.get().commandQueue retain]); CVMetalTextureCacheRef texture_cache_raw = NULL; auto cv_return = CVMetalTextureCacheCreate(kCFAllocatorDefault, // allocator NULL, // cache attributes (NULL default) darwin_context_metal_.get().device, // metal device NULL, // texture attributes (NULL default) &texture_cache_raw // [out] cache ); if (cv_return != kCVReturnSuccess) { FML_DLOG(ERROR) << "Could not create Metal texture cache."; return; } texture_cache_.Reset(texture_cache_raw); } IOSContextMetal::~IOSContextMetal() = default; fml::scoped_nsobject IOSContextMetal::GetDarwinContext() const { return darwin_context_metal_; } sk_sp IOSContextMetal::GetMainContext() const { return darwin_context_metal_.get().mainContext; } sk_sp IOSContextMetal::GetResourceContext() const { return darwin_context_metal_.get().resourceContext; } // |IOSContext| sk_sp IOSContextMetal::CreateResourceContext() { return darwin_context_metal_.get().resourceContext; } // |IOSContext| std::unique_ptr IOSContextMetal::MakeCurrent() { // This only makes sense for context that need to be bound to a specific thread. return std::make_unique(true); } // |IOSContext| std::unique_ptr IOSContextMetal::CreateExternalTexture( int64_t texture_id, fml::scoped_nsobject> texture) { return std::make_unique( fml::scoped_nsobject{ [[darwin_context_metal_ createExternalTextureWithIdentifier:texture_id texture:texture] retain]}); } } // namespace flutter