|
5 | 5 | #include "flutter/shell/platform/embedder/embedder_external_texture_gl.h" |
6 | 6 |
|
7 | 7 | #include "flutter/fml/logging.h" |
8 | | -#include "include/core/SkCanvas.h" |
| 8 | +#include "impeller/core/texture_descriptor.h" |
| 9 | +#include "impeller/display_list/aiks_context.h" |
| 10 | +#include "impeller/display_list/dl_image_impeller.h" |
| 11 | +#include "impeller/geometry/size.h" |
| 12 | +#include "impeller/renderer/backend/gles/context_gles.h" |
| 13 | +#include "impeller/renderer/backend/gles/handle_gles.h" |
| 14 | +#include "impeller/renderer/backend/gles/texture_gles.h" |
| 15 | + |
9 | 16 | #include "include/core/SkPaint.h" |
10 | 17 | #include "third_party/skia/include/core/SkAlphaType.h" |
11 | 18 | #include "third_party/skia/include/core/SkColorSpace.h" |
@@ -62,6 +69,17 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTexture( |
62 | 69 | GrDirectContext* context, |
63 | 70 | impeller::AiksContext* aiks_context, |
64 | 71 | const SkISize& size) { |
| 72 | + if (!!aiks_context) { |
| 73 | + return ResolveTextureImpeller(texture_id, aiks_context, size); |
| 74 | + } else { |
| 75 | + return ResolveTextureSkia(texture_id, context, size); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureSkia( |
| 80 | + int64_t texture_id, |
| 81 | + GrDirectContext* context, |
| 82 | + const SkISize& size) { |
65 | 83 | context->flushAndSubmit(); |
66 | 84 | context->resetContext(kAll_GrBackendState); |
67 | 85 | std::unique_ptr<FlutterOpenGLTexture> texture = |
@@ -110,6 +128,49 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTexture( |
110 | 128 | return DlImage::Make(std::move(image)); |
111 | 129 | } |
112 | 130 |
|
| 131 | +sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller( |
| 132 | + int64_t texture_id, |
| 133 | + impeller::AiksContext* aiks_context, |
| 134 | + const SkISize& size) { |
| 135 | + std::unique_ptr<FlutterOpenGLTexture> texture = |
| 136 | + external_texture_callback_(texture_id, size.width(), size.height()); |
| 137 | + |
| 138 | + if (!texture) { |
| 139 | + return nullptr; |
| 140 | + } |
| 141 | + |
| 142 | + impeller::TextureDescriptor desc; |
| 143 | + desc.size = impeller::ISize(texture->width, texture->height); |
| 144 | + |
| 145 | + impeller::ContextGLES& context = |
| 146 | + impeller::ContextGLES::Cast(*aiks_context->GetContext()); |
| 147 | + impeller::HandleGLES handle = context.GetReactor()->CreateHandle( |
| 148 | + impeller::HandleType::kTexture, texture->target); |
| 149 | + std::shared_ptr<impeller::TextureGLES> image = |
| 150 | + std::make_shared<impeller::TextureGLES>(context.GetReactor(), desc, |
| 151 | + handle); |
| 152 | + |
| 153 | + if (!image) { |
| 154 | + // In case Skia rejects the image, call the release proc so that |
| 155 | + // embedders can perform collection of intermediates. |
| 156 | + if (texture->destruction_callback) { |
| 157 | + texture->destruction_callback(texture->user_data); |
| 158 | + } |
| 159 | + FML_LOG(ERROR) << "Could not create external texture"; |
| 160 | + return nullptr; |
| 161 | + } |
| 162 | + if (texture->destruction_callback && |
| 163 | + !context.GetReactor()->RegisterCleanupCallback( |
| 164 | + handle, |
| 165 | + [callback = texture->destruction_callback, |
| 166 | + user_data = texture->user_data]() { callback(user_data); })) { |
| 167 | + FML_LOG(ERROR) << "Could not register destruction callback"; |
| 168 | + return nullptr; |
| 169 | + } |
| 170 | + |
| 171 | + return impeller::DlImageImpeller::Make(image); |
| 172 | +} |
| 173 | + |
113 | 174 | // |flutter::Texture| |
114 | 175 | void EmbedderExternalTextureGL::OnGrContextCreated() {} |
115 | 176 |
|
|
0 commit comments