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
Allow external texture sources when using the Metal backend. #17154
Merged
fluttergithubbot
merged 1 commit into
flutter:master
from
chinmaygarde:external_textures
Mar 23, 2020
Merged
Changes from all commits
Commits
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
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,63 @@ | ||
| // 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. | ||
|
|
||
| #include "flutter/fml/platform/darwin/cf_utils.h" | ||
| #include "flutter/testing/testing.h" | ||
|
|
||
| namespace fml { | ||
| namespace testing { | ||
|
|
||
| TEST(CFTest, CanCreateRefs) { | ||
| CFRef<CFMutableStringRef> string(CFStringCreateMutable(kCFAllocatorDefault, 100u)); | ||
| // Cast | ||
| ASSERT_TRUE(static_cast<bool>(string)); | ||
| ASSERT_TRUE(string); | ||
|
|
||
| const auto ref_count = CFGetRetainCount(string); | ||
|
|
||
| // Copy & Reset | ||
| { | ||
| CFRef<CFMutableStringRef> string2 = string; | ||
| ASSERT_TRUE(string2); | ||
| ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string)); | ||
| ASSERT_EQ(CFGetRetainCount(string2), CFGetRetainCount(string)); | ||
|
|
||
| string2.Reset(); | ||
| ASSERT_FALSE(string2); | ||
| ASSERT_EQ(ref_count, CFGetRetainCount(string)); | ||
| } | ||
|
|
||
| // Release | ||
| { | ||
| auto string3 = string; | ||
| ASSERT_TRUE(string3); | ||
| ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string)); | ||
| auto raw_string3 = string3.Release(); | ||
| ASSERT_FALSE(string3); | ||
| ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string)); | ||
| CFRelease(raw_string3); | ||
| ASSERT_EQ(ref_count, CFGetRetainCount(string)); | ||
| } | ||
|
|
||
| // Move | ||
| { | ||
| auto string_source = string; | ||
| ASSERT_TRUE(string_source); | ||
| auto string_move = std::move(string_source); | ||
| ASSERT_FALSE(string_source); | ||
| ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string)); | ||
| string_move.Reset(); | ||
| ASSERT_EQ(ref_count, CFGetRetainCount(string)); | ||
| } | ||
|
|
||
| // Move assign. | ||
| { | ||
| auto string_move_assign = std::move(string); | ||
| ASSERT_FALSE(string); | ||
| ASSERT_EQ(ref_count, CFGetRetainCount(string_move_assign)); | ||
| } | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace fml |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,20 +5,21 @@ | |
| #include "flutter/shell/platform/darwin/ios/ios_context_metal.h" | ||
|
|
||
| #include "flutter/fml/logging.h" | ||
| #include "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| IOSContextMetal::IOSContextMetal() { | ||
| device_.reset([MTLCreateSystemDefaultDevice() retain]); | ||
| if (!device_) { | ||
| FML_LOG(ERROR) << "Could not acquire Metal device."; | ||
| FML_DLOG(ERROR) << "Could not acquire Metal device."; | ||
| return; | ||
| } | ||
|
|
||
| main_queue_.reset([device_ newCommandQueue]); | ||
|
|
||
| if (!main_queue_) { | ||
| FML_LOG(ERROR) << "Could not create Metal command queue."; | ||
| FML_DLOG(ERROR) << "Could not create Metal command queue."; | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -30,10 +31,23 @@ | |
| resource_context_ = GrContext::MakeMetal([device_ retain], [main_queue_ retain]); | ||
|
|
||
| if (!main_context_ || !resource_context_) { | ||
| FML_LOG(ERROR) << "Could not create Skia Metal contexts."; | ||
| FML_DLOG(ERROR) << "Could not create Skia Metal contexts."; | ||
| return; | ||
| } | ||
|
|
||
| CVMetalTextureCacheRef texture_cache_raw = NULL; | ||
| auto cv_return = CVMetalTextureCacheCreate(kCFAllocatorDefault, // allocator | ||
| NULL, // cache attributes (NULL default) | ||
|
Contributor
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. clang format doesn't line these up?
Member
Author
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. Apparently not. I don't format code so its got to be |
||
| device_.get(), // 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); | ||
|
|
||
| is_valid_ = false; | ||
| } | ||
|
|
||
|
|
@@ -83,4 +97,11 @@ | |
| return true; | ||
| } | ||
|
|
||
| // |IOSContext| | ||
| std::unique_ptr<Texture> IOSContextMetal::CreateExternalTexture( | ||
| int64_t texture_id, | ||
| fml::scoped_nsobject<NSObject<FlutterTexture>> texture) { | ||
| return std::make_unique<IOSExternalTextureMetal>(texture_id, texture_cache_, std::move(texture)); | ||
| } | ||
|
|
||
| } // namespace flutter | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we on C++ 17 everywhere we have to compile? Particularly google3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.