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
[Impeller] Wire-up AndroidSurfaceImpellerVulkan #37249
Merged
auto-submit
merged 2 commits into
flutter:main
from
iskakaushik:wire-android-surface-impeller-1
Nov 3, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
119 changes: 119 additions & 0 deletions
119
shell/platform/android/android_surface_vulkan_impeller.cc
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,119 @@ | ||
// 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/shell/platform/android/android_surface_vulkan_impeller.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "flutter/fml/concurrent_message_loop.h" | ||
#include "flutter/fml/logging.h" | ||
#include "flutter/fml/memory/ref_ptr.h" | ||
#include "flutter/impeller/renderer/backend/vulkan/context_vk.h" | ||
#include "flutter/shell/gpu/gpu_surface_vulkan_impeller.h" | ||
#include "flutter/vulkan/vulkan_native_surface_android.h" | ||
#include "impeller/entity/vk/entity_shaders_vk.h" | ||
|
||
namespace flutter { | ||
|
||
std::shared_ptr<impeller::Context> CreateImpellerContext( | ||
const fml::RefPtr<vulkan::VulkanProcTable>& proc_table, | ||
const std::shared_ptr<fml::ConcurrentMessageLoop>& concurrent_loop) { | ||
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = { | ||
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data, | ||
impeller_entity_shaders_vk_length), | ||
}; | ||
|
||
PFN_vkGetInstanceProcAddr instance_proc_addr = | ||
proc_table->NativeGetInstanceProcAddr(); | ||
|
||
auto context = | ||
impeller::ContextVK::Create(instance_proc_addr, // | ||
shader_mappings, // | ||
nullptr, // | ||
concurrent_loop->GetTaskRunner(), // | ||
"Android Impeller Vulkan Lib" // | ||
); | ||
|
||
return context; | ||
} | ||
|
||
AndroidSurfaceVulkanImpeller::AndroidSurfaceVulkanImpeller( | ||
const std::shared_ptr<AndroidContext>& android_context, | ||
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) | ||
: AndroidSurface(android_context), | ||
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()), | ||
workers_(fml::ConcurrentMessageLoop::Create()) { | ||
impeller_context_ = CreateImpellerContext(proc_table_, workers_); | ||
is_valid_ = | ||
proc_table_->HasAcquiredMandatoryProcAddresses() && impeller_context_; | ||
} | ||
|
||
AndroidSurfaceVulkanImpeller::~AndroidSurfaceVulkanImpeller() = default; | ||
|
||
bool AndroidSurfaceVulkanImpeller::IsValid() const { | ||
return is_valid_; | ||
} | ||
|
||
void AndroidSurfaceVulkanImpeller::TeardownOnScreenContext() { | ||
// Nothing to do. | ||
} | ||
|
||
std::unique_ptr<Surface> AndroidSurfaceVulkanImpeller::CreateGPUSurface( | ||
GrDirectContext* gr_context) { | ||
if (!IsValid()) { | ||
return nullptr; | ||
} | ||
|
||
if (!native_window_ || !native_window_->IsValid()) { | ||
return nullptr; | ||
} | ||
|
||
std::unique_ptr<GPUSurfaceVulkanImpeller> gpu_surface = | ||
std::make_unique<GPUSurfaceVulkanImpeller>(impeller_context_); | ||
|
||
if (!gpu_surface->IsValid()) { | ||
return nullptr; | ||
} | ||
|
||
return gpu_surface; | ||
} | ||
|
||
bool AndroidSurfaceVulkanImpeller::OnScreenSurfaceResize(const SkISize& size) { | ||
return true; | ||
} | ||
|
||
bool AndroidSurfaceVulkanImpeller::ResourceContextMakeCurrent() { | ||
FML_DLOG(ERROR) << "The vulkan backend does not support resource contexts."; | ||
return false; | ||
} | ||
|
||
bool AndroidSurfaceVulkanImpeller::ResourceContextClearCurrent() { | ||
FML_DLOG(ERROR) << "The vulkan backend does not support resource contexts."; | ||
return false; | ||
} | ||
|
||
bool AndroidSurfaceVulkanImpeller::SetNativeWindow( | ||
fml::RefPtr<AndroidNativeWindow> window) { | ||
native_window_ = std::move(window); | ||
bool success = native_window_ && native_window_->IsValid(); | ||
|
||
if (success) { | ||
auto& context_vk = impeller::ContextVK::Cast(*impeller_context_); | ||
auto surface = context_vk.CreateAndroidSurface(native_window_->handle()); | ||
|
||
if (!surface) { | ||
FML_LOG(ERROR) << "Could not create a vulkan surface."; | ||
return false; | ||
} | ||
|
||
context_vk.SetupSwapchain(std::move(surface)); | ||
return true; | ||
} | ||
|
||
native_window_ = nullptr; | ||
return false; | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include "flutter/fml/concurrent_message_loop.h" | ||
#include "flutter/fml/macros.h" | ||
#include "flutter/impeller/renderer/context.h" | ||
#include "flutter/shell/platform/android/surface/android_native_window.h" | ||
#include "flutter/shell/platform/android/surface/android_surface.h" | ||
#include "flutter/vulkan/procs/vulkan_proc_table.h" | ||
|
||
namespace flutter { | ||
|
||
class AndroidSurfaceVulkanImpeller : public AndroidSurface { | ||
public: | ||
AndroidSurfaceVulkanImpeller( | ||
const std::shared_ptr<AndroidContext>& android_context, | ||
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade); | ||
|
||
~AndroidSurfaceVulkanImpeller() override; | ||
|
||
// |AndroidSurface| | ||
bool IsValid() const override; | ||
|
||
// |AndroidSurface| | ||
std::unique_ptr<Surface> CreateGPUSurface( | ||
GrDirectContext* gr_context) override; | ||
|
||
// |AndroidSurface| | ||
void TeardownOnScreenContext() override; | ||
|
||
// |AndroidSurface| | ||
bool OnScreenSurfaceResize(const SkISize& size) override; | ||
|
||
// |AndroidSurface| | ||
bool ResourceContextMakeCurrent() override; | ||
|
||
// |AndroidSurface| | ||
bool ResourceContextClearCurrent() override; | ||
|
||
// |AndroidSurface| | ||
bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) override; | ||
|
||
private: | ||
fml::RefPtr<vulkan::VulkanProcTable> proc_table_; | ||
fml::RefPtr<AndroidNativeWindow> native_window_; | ||
std::shared_ptr<fml::ConcurrentMessageLoop> workers_; | ||
std::shared_ptr<impeller::Context> impeller_context_; | ||
bool is_valid_ = false; | ||
|
||
FML_DISALLOW_COPY_AND_ASSIGN(AndroidSurfaceVulkanImpeller); | ||
}; | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -436,10 +436,10 @@ def to_gn_args(args): | |
gn_args['skia_use_metal'] = True | ||
gn_args['shell_enable_metal'] = True | ||
|
||
# Enable Vulkan on all platforms except for Android and iOS. This is just | ||
# Enable Vulkan on all platforms except for iOS. This is just | ||
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. 🥳 |
||
# to save on mobile binary size, as there's no reason the Vulkan embedder | ||
# features can't work on these platforms. | ||
if args.target_os not in ['android', 'ios']: | ||
if args.target_os not in ['ios']: | ||
gn_args['skia_use_vulkan'] = True | ||
gn_args['skia_use_vma'] = False | ||
gn_args['shell_enable_vulkan'] = True | ||
|
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.
Hmm,
false
is a preprocessor define? TIL