forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: software-mode external texture support for D3D11-hooked apps #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
guide-nhant
wants to merge
3
commits into
sbi_fx_pc/flutter_3.29.3
from
sbi_fx_pc/flutter_3.29.3-patch
Closed
Changes from all commits
Commits
Show all changes
3 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
104 changes: 104 additions & 0 deletions
104
engine/src/flutter/shell/platform/embedder/embedder_external_texture_software.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,104 @@ | ||
| // 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/embedder/embedder_external_texture_software.h" | ||
|
|
||
| #include "flutter/fml/logging.h" | ||
| #include "third_party/skia/include/core/SkAlphaType.h" | ||
| #include "third_party/skia/include/core/SkCanvas.h" | ||
| #include "third_party/skia/include/core/SkColorType.h" | ||
| #include "third_party/skia/include/core/SkImage.h" | ||
| #include "third_party/skia/include/core/SkImageInfo.h" | ||
| #include "third_party/skia/include/core/SkPixmap.h" | ||
| #include "third_party/skia/include/core/SkSize.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| EmbedderExternalTextureSoftware::EmbedderExternalTextureSoftware( | ||
| int64_t texture_identifier, | ||
| const ExternalTextureCallback& callback) | ||
| : Texture(texture_identifier), external_texture_callback_(callback) { | ||
| FML_DCHECK(external_texture_callback_); | ||
| } | ||
|
|
||
| EmbedderExternalTextureSoftware::~EmbedderExternalTextureSoftware() = default; | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureSoftware::Paint(PaintContext& context, | ||
| const SkRect& bounds, | ||
| bool freeze, | ||
| const DlImageSampling sampling) { | ||
| if (last_image_ == nullptr) { | ||
| last_image_ = | ||
| ResolveTexture(Id(), // | ||
| SkISize::Make(bounds.width(), bounds.height()) // | ||
| ); | ||
| } | ||
|
|
||
| DlCanvas* canvas = context.canvas; | ||
| const DlPaint* paint = context.paint; | ||
|
|
||
| if (last_image_) { | ||
| SkRect image_bounds = SkRect::Make(last_image_->bounds()); | ||
| if (bounds != image_bounds) { | ||
| canvas->DrawImageRect(last_image_, image_bounds, bounds, sampling, paint); | ||
| } else { | ||
| canvas->DrawImage(last_image_, SkPoint{bounds.x(), bounds.y()}, sampling, | ||
| paint); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| sk_sp<DlImage> EmbedderExternalTextureSoftware::ResolveTexture( | ||
| int64_t texture_id, | ||
| const SkISize& size) { | ||
| std::unique_ptr<FlutterSoftwarePixelBuffer> pixel_buffer = | ||
| external_texture_callback_(texture_id, size.width(), size.height()); | ||
|
|
||
| if (!pixel_buffer || !pixel_buffer->buffer || pixel_buffer->width == 0 || | ||
| pixel_buffer->height == 0) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| SkImageInfo info = SkImageInfo::Make( | ||
| static_cast<int>(pixel_buffer->width), | ||
| static_cast<int>(pixel_buffer->height), kRGBA_8888_SkColorType, | ||
| kPremul_SkAlphaType); | ||
| SkPixmap pixmap(info, pixel_buffer->buffer, | ||
| pixel_buffer->width * 4 /* row bytes (RGBA) */); | ||
|
|
||
| // Copy the pixels into a Skia-owned SkImage so we can release the source | ||
| // buffer immediately. RasterFromPixmapCopy allocates and copies; for very | ||
| // high frame rates we could alternatively use RasterFromPixmap with a | ||
| // release proc to avoid the copy, but that requires more careful lifetime | ||
| // management with the embedder's pixel buffer ownership model. | ||
| sk_sp<SkImage> image = SkImages::RasterFromPixmapCopy(pixmap); | ||
|
|
||
| if (pixel_buffer->release_callback) { | ||
| pixel_buffer->release_callback(pixel_buffer->release_context); | ||
| } | ||
|
|
||
| if (!image) { | ||
| FML_LOG(ERROR) << "Could not create software external texture image."; | ||
| return nullptr; | ||
| } | ||
|
|
||
| return DlImage::Make(std::move(image)); | ||
| } | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureSoftware::OnGrContextCreated() {} | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureSoftware::OnGrContextDestroyed() {} | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureSoftware::MarkNewFrameAvailable() { | ||
| last_image_ = nullptr; | ||
| } | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureSoftware::OnTextureUnregistered() {} | ||
|
|
||
| } // namespace flutter | ||
58 changes: 58 additions & 0 deletions
58
engine/src/flutter/shell/platform/embedder/embedder_external_texture_software.h
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,58 @@ | ||
| // 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. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_TEXTURE_SOFTWARE_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_TEXTURE_SOFTWARE_H_ | ||
|
|
||
| #include "flutter/common/graphics/texture.h" | ||
| #include "flutter/fml/macros.h" | ||
| #include "flutter/shell/platform/embedder/embedder.h" | ||
| #include "third_party/skia/include/core/SkSize.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| // External texture implementation for software rendering mode. | ||
| // Wraps a CPU pixel buffer as a Skia raster image — no GL required. | ||
| // Mirrors EmbedderExternalTextureGL but bypasses the OpenGL pipeline so | ||
| // embedders can render external textures while Flutter is in software mode. | ||
| class EmbedderExternalTextureSoftware : public flutter::Texture { | ||
| public: | ||
| using ExternalTextureCallback = std::function< | ||
| std::unique_ptr<FlutterSoftwarePixelBuffer>(int64_t, size_t, size_t)>; | ||
|
|
||
| EmbedderExternalTextureSoftware(int64_t texture_identifier, | ||
| const ExternalTextureCallback& callback); | ||
|
|
||
| ~EmbedderExternalTextureSoftware() override; | ||
|
|
||
| private: | ||
| const ExternalTextureCallback& external_texture_callback_; | ||
| sk_sp<DlImage> last_image_; | ||
|
|
||
| sk_sp<DlImage> ResolveTexture(int64_t texture_id, const SkISize& size); | ||
|
|
||
| // |flutter::Texture| | ||
| void Paint(PaintContext& context, | ||
| const SkRect& bounds, | ||
| bool freeze, | ||
| const DlImageSampling sampling) override; | ||
|
|
||
| // |flutter::Texture| | ||
| void OnGrContextCreated() override; | ||
|
|
||
| // |flutter::Texture| | ||
| void OnGrContextDestroyed() override; | ||
|
|
||
| // |flutter::Texture| | ||
| void MarkNewFrameAvailable() override; | ||
|
|
||
| // |flutter::Texture| | ||
| void OnTextureUnregistered() override; | ||
|
|
||
| FML_DISALLOW_COPY_AND_ASSIGN(EmbedderExternalTextureSoftware); | ||
| }; | ||
|
|
||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_TEXTURE_SOFTWARE_H_ |
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.
Uh oh!
There was an error while loading. Please reload this page.