forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 17
[Tizen] Support EmbedderExternalTextureGL for impeller #368
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
Merged
JSUYA
merged 5 commits into
flutter-tizen:flutter-3.22.2
from
xiaowei-guan:flutter-3.22.2
Jul 8, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2d70966
[Tizen] Support embedder texture for impeller
xiaowei-guan a8d3cad
Move update size code to ResolveTexture method
xiaowei-guan ea8373f
Fix spelling errors
xiaowei-guan c1f2b65
Merge remote-tracking branch 'upstream/flutter-3.22.2' into flutter-3…
xiaowei-guan f5ed1e0
Add macro definition when creating EmbedderExternalTextureGLImpeller
xiaowei-guan 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
160 changes: 160 additions & 0 deletions
160
shell/platform/embedder/embedder_external_texture_gl_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,160 @@ | ||
| // 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_gl_impeller.h" | ||
|
|
||
| #include "flutter/fml/logging.h" | ||
| #include "flutter/impeller/display_list/dl_image_impeller.h" | ||
| #include "flutter/impeller/renderer/backend/gles/context_gles.h" | ||
| #include "flutter/impeller/renderer/backend/gles/texture_gles.h" | ||
| #include "impeller/aiks/aiks_context.h" | ||
| #include "impeller/renderer/backend/gles/gles.h" | ||
| #include "include/core/SkCanvas.h" | ||
| #include "include/core/SkPaint.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| EmbedderExternalTextureGLImpeller::EmbedderExternalTextureGLImpeller( | ||
| int64_t texture_identifier, | ||
| const EmbedderExternalTextureGL::ExternalTextureCallback& callback) | ||
| : Texture(texture_identifier), external_texture_callback_(callback) { | ||
| FML_DCHECK(external_texture_callback_); | ||
| } | ||
|
|
||
| EmbedderExternalTextureGLImpeller::~EmbedderExternalTextureGLImpeller() = | ||
| default; | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureGLImpeller::Paint(PaintContext& context, | ||
| const SkRect& bounds, | ||
| bool freeze, | ||
| const DlImageSampling sampling) { | ||
| if (last_image_ == nullptr) { | ||
| last_image_ = | ||
| ResolveTexture(Id(), // | ||
| context, // | ||
| 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_, {bounds.x(), bounds.y()}, sampling, paint); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureGLImpeller::OnGrContextCreated() {} | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureGLImpeller::OnGrContextDestroyed() {} | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureGLImpeller::MarkNewFrameAvailable() { | ||
| last_image_ = nullptr; | ||
| } | ||
|
|
||
| // |flutter::Texture| | ||
| void EmbedderExternalTextureGLImpeller::OnTextureUnregistered() {} | ||
|
|
||
| sk_sp<DlImage> EmbedderExternalTextureGLImpeller::ResolveTexture( | ||
| int64_t texture_id, | ||
| PaintContext& context, | ||
| const SkISize& size) { | ||
| std::unique_ptr<FlutterOpenGLTexture> texture = | ||
| external_texture_callback_(texture_id, size.width(), size.height()); | ||
| if (!texture) { | ||
| return nullptr; | ||
| } | ||
| size_t width = size.width(); | ||
| size_t height = size.height(); | ||
| if (texture->width != 0 && texture->height != 0) { | ||
| width = texture->width; | ||
| height = texture->height; | ||
| } | ||
| if (texture->impeller_texture_type == | ||
| FlutterGLImpellerTextureType::kFlutterGLImpellerTexturePixelBuffer) { | ||
| return ResolvePixelBufferTexture(texture.get(), context, | ||
| SkISize::Make(width, height)); | ||
| } else { | ||
| return ResolveGpuSurfaceTexture(texture.get(), context, | ||
| SkISize::Make(width, height)); | ||
| } | ||
| } | ||
|
|
||
| sk_sp<DlImage> EmbedderExternalTextureGLImpeller::ResolvePixelBufferTexture( | ||
| FlutterOpenGLTexture* texture, | ||
| PaintContext& context, | ||
| const SkISize& size) { | ||
| impeller::TextureDescriptor desc; | ||
| desc.type = impeller::TextureType::kTexture2D; | ||
| impeller::AiksContext* aiks_context = context.aiks_context; | ||
| const auto& gl_context = | ||
| impeller::ContextGLES::Cast(*aiks_context->GetContext()); | ||
| desc.storage_mode = impeller::StorageMode::kDevicePrivate; | ||
| desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt; | ||
| desc.size = {static_cast<int>(size.width()), static_cast<int>(size.height())}; | ||
| desc.mip_count = 1; | ||
|
|
||
| auto textureGLES = | ||
| std::make_shared<impeller::TextureGLES>(gl_context.GetReactor(), desc); | ||
| if (!textureGLES->SetContents(texture->buffer, texture->buffer_size)) { | ||
| if (texture->destruction_callback) { | ||
| texture->destruction_callback(texture->user_data); | ||
| } | ||
| return nullptr; | ||
| } | ||
| if (texture->destruction_callback) { | ||
| texture->destruction_callback(texture->user_data); | ||
| } | ||
| return impeller::DlImageImpeller::Make(textureGLES); | ||
| } | ||
|
|
||
| sk_sp<DlImage> EmbedderExternalTextureGLImpeller::ResolveGpuSurfaceTexture( | ||
| FlutterOpenGLTexture* texture, | ||
| PaintContext& context, | ||
| const SkISize& size) { | ||
| impeller::TextureDescriptor desc; | ||
| desc.type = impeller::TextureType::kTextureExternalOES; | ||
| impeller::AiksContext* aiks_context = context.aiks_context; | ||
| const auto& gl_context = | ||
| impeller::ContextGLES::Cast(*aiks_context->GetContext()); | ||
| desc.storage_mode = impeller::StorageMode::kDevicePrivate; | ||
| desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt; | ||
| desc.size = {static_cast<int>(size.width()), static_cast<int>(size.height())}; | ||
| desc.mip_count = 1; | ||
| auto textureGLES = std::make_shared<impeller::TextureGLES>( | ||
| gl_context.GetReactor(), desc, | ||
| impeller::TextureGLES::IsWrapped::kWrapped); | ||
| textureGLES->SetCoordinateSystem( | ||
| impeller::TextureCoordinateSystem::kUploadFromHost); | ||
| if (!textureGLES->Bind()) { | ||
| if (texture->destruction_callback) { | ||
| texture->destruction_callback(texture->user_data); | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
||
| if (!texture->bind_callback(texture->user_data)) { | ||
| if (texture->destruction_callback) { | ||
| texture->destruction_callback(texture->user_data); | ||
| } | ||
| return nullptr; | ||
| } | ||
JSUYA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (texture->destruction_callback) { | ||
| texture->destruction_callback(texture->user_data); | ||
| } | ||
|
|
||
| return impeller::DlImageImpeller::Make(textureGLES); | ||
| } | ||
|
|
||
| } // namespace flutter | ||
62 changes: 62 additions & 0 deletions
62
shell/platform/embedder/embedder_external_texture_gl_impeller.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,62 @@ | ||
| // 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_GL_IMPELLER_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_TEXTURE_GL_IMPELLER_H_ | ||
|
|
||
| #include "flutter/common/graphics/texture.h" | ||
| #include "flutter/fml/macros.h" | ||
| #include "flutter/shell/platform/embedder/embedder.h" | ||
| #include "flutter/shell/platform/embedder/embedder_external_texture_gl.h" | ||
| #include "third_party/skia/include/core/SkSize.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| class EmbedderExternalTextureGLImpeller : public flutter::Texture { | ||
| public: | ||
| EmbedderExternalTextureGLImpeller( | ||
| int64_t texture_identifier, | ||
| const EmbedderExternalTextureGL::ExternalTextureCallback& callback); | ||
|
|
||
| ~EmbedderExternalTextureGLImpeller(); | ||
|
|
||
| private: | ||
| const EmbedderExternalTextureGL::ExternalTextureCallback& | ||
| external_texture_callback_; | ||
| sk_sp<DlImage> last_image_; | ||
|
|
||
| sk_sp<DlImage> ResolveTexture(int64_t texture_id, | ||
| PaintContext& context, | ||
| const SkISize& size); | ||
| sk_sp<DlImage> ResolveGpuSurfaceTexture(FlutterOpenGLTexture* texture, | ||
| PaintContext& context, | ||
| const SkISize& size); | ||
| sk_sp<DlImage> ResolvePixelBufferTexture(FlutterOpenGLTexture* texture, | ||
| PaintContext& context, | ||
| 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(EmbedderExternalTextureGLImpeller); | ||
| }; | ||
|
|
||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_TEXTURE_GL_IMPELLER_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
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
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.