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] Start of Dart GPU prototype #42228
Merged
Merged
Changes from all commits
Commits
Show all changes
6 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| // 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. | ||
|
|
||
| // ignore_for_file: public_member_api_docs | ||
|
|
||
| part of dart.ui; | ||
|
|
||
| class GpuContextException implements Exception { | ||
| GpuContextException(this.message); | ||
| String message; | ||
|
|
||
| @override | ||
| String toString() { | ||
| return 'GpuContextException: $message'; | ||
| } | ||
| } | ||
|
|
||
| enum BlendOperation { add, subtract, reverseSubtract } | ||
|
|
||
| enum BlendFactor { | ||
| zero, | ||
| one, | ||
| sourceColor, | ||
| oneMinusSourceColor, | ||
| sourceAlpha, | ||
| oneMinusSourceAlpha, | ||
| destinationColor, | ||
| oneMinusDestinationColor, | ||
| destinationAlpha, | ||
| oneMinusDestinationAlpha, | ||
| sourceAlphaSaturated, | ||
| blendColor, | ||
| oneMinusBlendColor, | ||
| blendAlpha, | ||
| oneMinusBlendAlpha, | ||
| } | ||
|
|
||
| class BlendOptions { | ||
| const BlendOptions({ | ||
| this.colorOperation = BlendOperation.add, | ||
| this.sourceColorFactor = BlendFactor.one, | ||
| this.destinationColorFactor = BlendFactor.oneMinusSourceAlpha, | ||
| this.alphaOperation = BlendOperation.add, | ||
| this.sourceAlphaFactor = BlendFactor.one, | ||
| this.destinationAlphaFactor = BlendFactor.oneMinusSourceAlpha, | ||
| }); | ||
|
|
||
| final BlendOperation colorOperation; | ||
| final BlendFactor sourceColorFactor; | ||
| final BlendFactor destinationColorFactor; | ||
| final BlendOperation alphaOperation; | ||
| final BlendFactor sourceAlphaFactor; | ||
| final BlendFactor destinationAlphaFactor; | ||
| } | ||
|
|
||
| enum StencilOperation { | ||
| keep, | ||
| zero, | ||
| setToReferenceValue, | ||
| incrementClamp, | ||
| decrementClamp, | ||
| invert, | ||
| incrementWrap, | ||
| decrementWrap, | ||
| } | ||
|
|
||
| enum CompareFunction { | ||
| never, | ||
| always, | ||
| less, | ||
| equal, | ||
| lessEqual, | ||
| greater, | ||
| notEqual, | ||
| greaterEqual, | ||
| } | ||
|
|
||
| class StencilOptions { | ||
| const StencilOptions({ | ||
| this.operation = StencilOperation.incrementClamp, | ||
| this.compare = CompareFunction.always, | ||
| }); | ||
|
|
||
| final StencilOperation operation; | ||
| final CompareFunction compare; | ||
| } | ||
|
|
||
| enum ShaderType { | ||
| unknown, | ||
| voidType, | ||
| booleanType, | ||
| signedByteType, | ||
| unsignedByteType, | ||
| signedShortType, | ||
| unsignedShortType, | ||
| signedIntType, | ||
| unsignedIntType, | ||
| signedInt64Type, | ||
| unsignedInt64Type, | ||
| atomicCounterType, | ||
| halfFloatType, | ||
| floatType, | ||
| doubleType, | ||
| structType, | ||
| imageType, | ||
| sampledImageType, | ||
| samplerType, | ||
| } | ||
|
|
||
| class VertexAttribute { | ||
| const VertexAttribute({ | ||
| this.name = '', | ||
| this.location = 0, | ||
| this.set = 0, | ||
| this.binding = 0, | ||
| this.type = ShaderType.floatType, | ||
| this.elements = 2, | ||
| }); | ||
|
|
||
| final String name; | ||
| final int location; | ||
| final int set; | ||
| final int binding; | ||
| final ShaderType type; | ||
| final int elements; | ||
| } | ||
|
|
||
| class UniformSlot { | ||
| const UniformSlot({ | ||
| this.name = '', | ||
| this.set = 0, | ||
| this.extRes0 = 0, | ||
| this.binding = 0, | ||
| }); | ||
|
|
||
| final String name; | ||
| final int set; | ||
| final int extRes0; | ||
| final int binding; | ||
| } | ||
|
|
||
| class GpuShader {} | ||
|
|
||
| class RasterPipeline {} | ||
|
|
||
| /// A handle to a graphics context. Used to create and manage GPU resources. | ||
| /// | ||
| /// To obtain the default graphics context, use [getGpuContext]. | ||
| class GpuContext extends NativeFieldWrapperClass1 { | ||
| /// Creates a new graphics context that corresponds to the default Impeller | ||
| /// context. | ||
| GpuContext._createDefault() { | ||
| final String error = _initializeDefault(); | ||
| if (error.isNotEmpty) { | ||
| throw GpuContextException(error); | ||
| } | ||
| } | ||
|
|
||
| //registerShaderLibrary() async | ||
|
|
||
| Future<RasterPipeline> createRasterPipeline({ | ||
| required GpuShader vertex, | ||
| required GpuShader fragment, | ||
| BlendOptions blendOptions = const BlendOptions(), | ||
| StencilOptions stencilOptions = const StencilOptions(), | ||
| List<VertexAttribute> vertexLayout = const <VertexAttribute>[], | ||
| List<UniformSlot> uniformLayout = const <UniformSlot>[], | ||
| }) async { | ||
| return RasterPipeline(); | ||
| } | ||
|
|
||
| /// Associates the default Impeller context with this GpuContext. | ||
| @Native<Handle Function(Handle)>(symbol: 'GpuContext::InitializeDefault') | ||
| external String _initializeDefault(); | ||
| } | ||
|
|
||
| GpuContext? _defaultGpuContext; | ||
|
|
||
| /// Returns the default graphics context. | ||
| GpuContext getGpuContext() { | ||
| _defaultGpuContext ??= GpuContext._createDefault(); | ||
| return _defaultGpuContext!; | ||
| } |
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,54 @@ | ||
| // 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/lib/ui/gpu/context.h" | ||
|
|
||
| #include <memory> | ||
| #include <sstream> | ||
|
|
||
| #include "flutter/fml/log_level.h" | ||
| #include "flutter/fml/logging.h" | ||
| #include "flutter/fml/make_copyable.h" | ||
| #include "flutter/fml/memory/ref_ptr.h" | ||
| #include "flutter/lib/ui/ui_dart_state.h" | ||
| #include "third_party/tonic/dart_wrappable.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| IMPLEMENT_WRAPPERTYPEINFO(ui, GpuContext); | ||
|
|
||
| std::string GpuContext::InitializeDefault(Dart_Handle wrapper) { | ||
| auto dart_state = UIDartState::Current(); | ||
| if (!dart_state->IsImpellerEnabled()) { | ||
| return "The GpuContext API requires the Impeller rendering backend to be " | ||
| "enabled."; | ||
| } | ||
|
|
||
| // Grab the Impeller context from the IO manager. | ||
|
|
||
| std::promise<std::shared_ptr<impeller::Context>> context_promise; | ||
| auto impeller_context_future = context_promise.get_future(); | ||
| dart_state->GetTaskRunners().GetIOTaskRunner()->PostTask( | ||
| fml::MakeCopyable([promise = std::move(context_promise), | ||
| io_manager = dart_state->GetIOManager()]() mutable { | ||
| promise.set_value(io_manager ? io_manager->GetImpellerContext() | ||
| : nullptr); | ||
| })); | ||
|
|
||
| auto impeller_context = impeller_context_future.get(); | ||
| if (!impeller_context) { | ||
| return "Unable to retrieve the Impeller context."; | ||
| } | ||
| auto res = fml::MakeRefCounted<GpuContext>(impeller_context); | ||
| res->AssociateWithDartWrapper(wrapper); | ||
|
|
||
| return ""; | ||
| } | ||
|
|
||
| GpuContext::GpuContext(std::shared_ptr<impeller::Context> context) | ||
| : context_(std::move(context)) {} | ||
|
|
||
| GpuContext::~GpuContext() = default; | ||
|
|
||
| } // namespace flutter |
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.
fml::MessageLoop::GetCurrentis an API only meant to be used on the embedder and we can't know if the call is made on the embedder unless you clarify. You can just define FML_USED_ON_EMBEDDER at the very top of the file and the deprecated declaration warning will go away :)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.
Ah, makes sense. Done.