[Impeller] finish wiring up external textures for macOS embedder. (flutter/engine#55347)
Fixes https://github.com/flutter/flutter/issues/135898 Note that the macOS embedder is still using the apple texture cache object from the SkiaMetalContext. it can't initialize an equivalent ImpellerMetalContext without creating a second copy of the content context and all that jazz, so I'm leaving that as is for now.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
#include "flutter/common/graphics/texture.h"
|
||||
#include "flutter/display_list/image/dl_image.h"
|
||||
#include "flutter/impeller/aiks/aiks_context.h"
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
@@ -29,6 +31,18 @@
|
||||
|
||||
@end
|
||||
|
||||
@interface FlutterDarwinExternalTextureImpellerImageWrapper : NSObject
|
||||
|
||||
+ (sk_sp<flutter::DlImage>)wrapYUVATexture:(nonnull id<MTLTexture>)yTex
|
||||
UVTex:(nonnull id<MTLTexture>)uvTex
|
||||
YUVColorSpace:(impeller::YUVColorSpace)colorSpace
|
||||
aiksContext:(nonnull impeller::AiksContext*)aiksContext;
|
||||
|
||||
+ (sk_sp<flutter::DlImage>)wrapRGBATexture:(nonnull id<MTLTexture>)rgbaTex
|
||||
aiksContext:(nonnull impeller::AiksContext*)aiks_context;
|
||||
|
||||
@end
|
||||
|
||||
@interface FlutterDarwinExternalTextureMetal : NSObject
|
||||
|
||||
- (nullable instancetype)initWithTextureCache:(nonnull CVMetalTextureCacheRef)textureCache
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h"
|
||||
#include "flutter/display_list/image/dl_image.h"
|
||||
#include "impeller/aiks/aiks_context.h"
|
||||
#include "impeller/base/validation.h"
|
||||
#include "impeller/display_list/dl_image_impeller.h"
|
||||
#include "impeller/renderer/backend/metal/texture_mtl.h"
|
||||
@@ -196,29 +197,14 @@ FLUTTER_ASSERT_ARC
|
||||
CVBufferRelease(uvMetalTexture);
|
||||
|
||||
if (_enableImpeller) {
|
||||
impeller::TextureDescriptor yDesc;
|
||||
yDesc.storage_mode = impeller::StorageMode::kHostVisible;
|
||||
yDesc.format = impeller::PixelFormat::kR8UNormInt;
|
||||
yDesc.size = {textureSize.width(), textureSize.height()};
|
||||
yDesc.mip_count = 1;
|
||||
auto yTexture = impeller::TextureMTL::Wrapper(yDesc, yTex);
|
||||
yTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost);
|
||||
|
||||
impeller::TextureDescriptor uvDesc;
|
||||
uvDesc.storage_mode = impeller::StorageMode::kHostVisible;
|
||||
uvDesc.format = impeller::PixelFormat::kR8G8UNormInt;
|
||||
uvDesc.size = {textureSize.width() / 2, textureSize.height() / 2};
|
||||
uvDesc.mip_count = 1;
|
||||
auto uvTexture = impeller::TextureMTL::Wrapper(uvDesc, uvTex);
|
||||
uvTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost);
|
||||
|
||||
impeller::YUVColorSpace yuvColorSpace =
|
||||
_pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
|
||||
? impeller::YUVColorSpace::kBT601LimitedRange
|
||||
: impeller::YUVColorSpace::kBT601FullRange;
|
||||
|
||||
return impeller::DlImageImpeller::MakeFromYUVTextures(context.aiks_context, yTexture, uvTexture,
|
||||
yuvColorSpace);
|
||||
return [FlutterDarwinExternalTextureImpellerImageWrapper wrapYUVATexture:yTex
|
||||
UVTex:uvTex
|
||||
YUVColorSpace:yuvColorSpace
|
||||
aiksContext:context.aiks_context];
|
||||
}
|
||||
|
||||
SkYUVColorSpace colorSpace = _pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
|
||||
@@ -263,14 +249,8 @@ FLUTTER_ASSERT_ARC
|
||||
CVBufferRelease(metalTexture);
|
||||
|
||||
if (_enableImpeller) {
|
||||
impeller::TextureDescriptor desc;
|
||||
desc.storage_mode = impeller::StorageMode::kHostVisible;
|
||||
desc.format = impeller::PixelFormat::kB8G8R8A8UNormInt;
|
||||
desc.size = {textureSize.width(), textureSize.height()};
|
||||
desc.mip_count = 1;
|
||||
auto texture = impeller::TextureMTL::Wrapper(desc, rgbaTex);
|
||||
texture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost);
|
||||
return impeller::DlImageImpeller::Make(texture);
|
||||
return [FlutterDarwinExternalTextureImpellerImageWrapper wrapRGBATexture:rgbaTex
|
||||
aiksContext:context.aiks_context];
|
||||
}
|
||||
|
||||
auto skImage = [FlutterDarwinExternalTextureSkImageWrapper wrapRGBATexture:rgbaTex
|
||||
@@ -342,3 +322,43 @@ FLUTTER_ASSERT_ARC
|
||||
#endif // SLIMPELLER
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation FlutterDarwinExternalTextureImpellerImageWrapper
|
||||
|
||||
+ (sk_sp<flutter::DlImage>)wrapYUVATexture:(id<MTLTexture>)yTex
|
||||
UVTex:(id<MTLTexture>)uvTex
|
||||
YUVColorSpace:(impeller::YUVColorSpace)colorSpace
|
||||
aiksContext:(nonnull impeller::AiksContext*)aiks_context {
|
||||
impeller::TextureDescriptor yDesc;
|
||||
yDesc.storage_mode = impeller::StorageMode::kDevicePrivate;
|
||||
yDesc.format = impeller::PixelFormat::kR8UNormInt;
|
||||
yDesc.size = impeller::ISize(yTex.width, yTex.height);
|
||||
yDesc.mip_count = 1;
|
||||
auto yTexture = impeller::TextureMTL::Wrapper(yDesc, yTex);
|
||||
yTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost);
|
||||
|
||||
impeller::TextureDescriptor uvDesc;
|
||||
uvDesc.storage_mode = impeller::StorageMode::kDevicePrivate;
|
||||
uvDesc.format = impeller::PixelFormat::kR8G8UNormInt;
|
||||
uvDesc.size = impeller::ISize(uvTex.width, uvTex.height);
|
||||
uvDesc.mip_count = 1;
|
||||
auto uvTexture = impeller::TextureMTL::Wrapper(uvDesc, uvTex);
|
||||
uvTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost);
|
||||
;
|
||||
|
||||
return impeller::DlImageImpeller::MakeFromYUVTextures(aiks_context, yTexture, uvTexture,
|
||||
colorSpace);
|
||||
}
|
||||
|
||||
+ (sk_sp<flutter::DlImage>)wrapRGBATexture:(id<MTLTexture>)rgbaTex
|
||||
aiksContext:(nonnull impeller::AiksContext*)aiks_context {
|
||||
impeller::TextureDescriptor desc;
|
||||
desc.storage_mode = impeller::StorageMode::kDevicePrivate;
|
||||
desc.format = impeller::PixelFormat::kB8G8R8A8UNormInt;
|
||||
desc.size = impeller::ISize(rgbaTex.width, rgbaTex.height);
|
||||
desc.mip_count = 1;
|
||||
auto texture = impeller::TextureMTL::Wrapper(desc, rgbaTex);
|
||||
texture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost);
|
||||
return impeller::DlImageImpeller::Make(texture);
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -8,7 +8,11 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/display_list/display_list.h"
|
||||
#include "flutter/display_list/dl_builder.h"
|
||||
#import "flutter/display_list/skia/dl_sk_canvas.h"
|
||||
#include "flutter/fml/synchronization/sync_switch.h"
|
||||
#include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h"
|
||||
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
|
||||
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
|
||||
@@ -16,12 +20,30 @@
|
||||
#include "flutter/shell/platform/embedder/embedder_external_texture_metal.h"
|
||||
#include "flutter/testing/autoreleasepool_test.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "impeller/aiks/aiks_context.h" // nogncheck
|
||||
#include "impeller/entity/mtl/entity_shaders.h" // nogncheck
|
||||
#include "impeller/entity/mtl/framebuffer_blend_shaders.h" // nogncheck
|
||||
#include "impeller/entity/mtl/modern_shaders.h" // nogncheck
|
||||
#include "impeller/renderer/backend/metal/context_mtl.h" // nogncheck
|
||||
#include "third_party/googletest/googletest/include/gtest/gtest.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkSamplingOptions.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
|
||||
|
||||
static std::shared_ptr<impeller::ContextMTL> CreateImpellerContext() {
|
||||
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
|
||||
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
|
||||
impeller_entity_shaders_length),
|
||||
std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_data,
|
||||
impeller_modern_shaders_length),
|
||||
std::make_shared<fml::NonOwnedMapping>(impeller_framebuffer_blend_shaders_data,
|
||||
impeller_framebuffer_blend_shaders_length),
|
||||
};
|
||||
auto sync_switch = std::make_shared<fml::SyncSwitch>(false);
|
||||
return impeller::ContextMTL::Create(shader_mappings, sync_switch, "Impeller Library");
|
||||
}
|
||||
|
||||
@interface TestExternalTexture : NSObject <FlutterTexture>
|
||||
|
||||
- (nonnull instancetype)initWidth:(size_t)width
|
||||
@@ -334,4 +356,252 @@ TEST_F(FlutterEmbedderExternalTextureTest, TestPopulateUnsupportedExternalTextur
|
||||
texture->Paint(context, bounds, /*freeze=*/false, sampling);
|
||||
}
|
||||
|
||||
TEST_F(FlutterEmbedderExternalTextureTest, TestTextureResolutionImpeller) {
|
||||
// Constants.
|
||||
const size_t width = 100;
|
||||
const size_t height = 100;
|
||||
const int64_t texture_id = 1;
|
||||
|
||||
// Set up the surface.
|
||||
auto device = ::MTLCreateSystemDefaultDevice();
|
||||
impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
|
||||
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
||||
|
||||
// Create a texture.
|
||||
MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init];
|
||||
textureDescriptor.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
||||
textureDescriptor.width = width;
|
||||
textureDescriptor.height = height;
|
||||
textureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
|
||||
id<MTLTexture> mtlTexture = [device newTextureWithDescriptor:textureDescriptor];
|
||||
std::vector<FlutterMetalTextureHandle> textures = {
|
||||
(__bridge FlutterMetalTextureHandle)mtlTexture,
|
||||
};
|
||||
|
||||
// Callback to resolve the texture.
|
||||
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
|
||||
size_t h) {
|
||||
EXPECT_TRUE(w == width);
|
||||
EXPECT_TRUE(h == height);
|
||||
|
||||
auto texture = std::make_unique<FlutterMetalExternalTexture>();
|
||||
texture->struct_size = sizeof(FlutterMetalExternalTexture);
|
||||
texture->num_textures = 1;
|
||||
texture->height = h;
|
||||
texture->width = w;
|
||||
texture->pixel_format = FlutterMetalExternalTexturePixelFormat::kRGBA;
|
||||
texture->textures = textures.data();
|
||||
return texture;
|
||||
};
|
||||
|
||||
// Render the texture.
|
||||
std::unique_ptr<flutter::Texture> texture =
|
||||
std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
|
||||
SkRect bounds = SkRect::MakeWH(info.width(), info.height());
|
||||
DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
|
||||
|
||||
DisplayListBuilder builder;
|
||||
flutter::Texture::PaintContext context{
|
||||
.canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context};
|
||||
texture->Paint(context, bounds, /*freeze=*/false, sampling);
|
||||
|
||||
ASSERT_TRUE(mtlTexture != nil);
|
||||
}
|
||||
|
||||
TEST_F(FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureImpeller) {
|
||||
// Constants.
|
||||
const size_t width = 100;
|
||||
const size_t height = 100;
|
||||
const int64_t texture_id = 1;
|
||||
|
||||
// Set up the surface.
|
||||
FlutterDarwinContextMetalSkia* darwinContextMetal =
|
||||
[[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
|
||||
impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
||||
|
||||
// Create a texture.
|
||||
TestExternalTexture* testExternalTexture =
|
||||
[[TestExternalTexture alloc] initWidth:width
|
||||
height:height
|
||||
pixelFormatType:kCVPixelFormatType_32BGRA];
|
||||
FlutterExternalTexture* textureHolder =
|
||||
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
|
||||
// Callback to resolve the texture.
|
||||
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
|
||||
size_t h) {
|
||||
EXPECT_TRUE(w == width);
|
||||
EXPECT_TRUE(h == height);
|
||||
|
||||
auto texture = std::make_unique<FlutterMetalExternalTexture>();
|
||||
[textureHolder populateTexture:texture.get()];
|
||||
|
||||
EXPECT_TRUE(texture->num_textures == 1);
|
||||
EXPECT_TRUE(texture->textures != nullptr);
|
||||
EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kRGBA);
|
||||
return texture;
|
||||
};
|
||||
|
||||
// Render the texture.
|
||||
std::unique_ptr<flutter::Texture> texture =
|
||||
std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
|
||||
SkRect bounds = SkRect::MakeWH(info.width(), info.height());
|
||||
DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
|
||||
|
||||
DisplayListBuilder builder;
|
||||
flutter::Texture::PaintContext context{
|
||||
.canvas = &builder,
|
||||
.gr_context = nullptr,
|
||||
.aiks_context = &aiks_context,
|
||||
};
|
||||
texture->Paint(context, bounds, /*freeze=*/false, sampling);
|
||||
}
|
||||
|
||||
TEST_F(FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureYUVAImpeller) {
|
||||
// Constants.
|
||||
const size_t width = 100;
|
||||
const size_t height = 100;
|
||||
const int64_t texture_id = 1;
|
||||
|
||||
// Set up the surface.
|
||||
FlutterDarwinContextMetalSkia* darwinContextMetal =
|
||||
[[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
|
||||
impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
||||
|
||||
// Create a texture.
|
||||
TestExternalTexture* testExternalTexture =
|
||||
[[TestExternalTexture alloc] initWidth:width
|
||||
height:height
|
||||
pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange];
|
||||
FlutterExternalTexture* textureHolder =
|
||||
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
|
||||
// Callback to resolve the texture.
|
||||
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
|
||||
size_t h) {
|
||||
EXPECT_TRUE(w == width);
|
||||
EXPECT_TRUE(h == height);
|
||||
|
||||
auto texture = std::make_unique<FlutterMetalExternalTexture>();
|
||||
[textureHolder populateTexture:texture.get()];
|
||||
|
||||
EXPECT_TRUE(texture->num_textures == 2);
|
||||
EXPECT_TRUE(texture->textures != nullptr);
|
||||
EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA);
|
||||
EXPECT_TRUE(texture->yuv_color_space ==
|
||||
FlutterMetalExternalTextureYUVColorSpace::kBT601LimitedRange);
|
||||
return texture;
|
||||
};
|
||||
|
||||
// Render the texture.
|
||||
std::unique_ptr<flutter::Texture> texture =
|
||||
std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
|
||||
SkRect bounds = SkRect::MakeWH(info.width(), info.height());
|
||||
DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
|
||||
|
||||
DisplayListBuilder builder;
|
||||
flutter::Texture::PaintContext context{
|
||||
.canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context};
|
||||
texture->Paint(context, bounds, /*freeze=*/false, sampling);
|
||||
}
|
||||
|
||||
TEST_F(FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureYUVA2Impeller) {
|
||||
// Constants.
|
||||
const size_t width = 100;
|
||||
const size_t height = 100;
|
||||
const int64_t texture_id = 1;
|
||||
|
||||
// Set up the surface.
|
||||
FlutterDarwinContextMetalSkia* darwinContextMetal =
|
||||
[[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
|
||||
impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
||||
|
||||
// Create a texture.
|
||||
TestExternalTexture* testExternalTexture =
|
||||
[[TestExternalTexture alloc] initWidth:width
|
||||
height:height
|
||||
pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange];
|
||||
FlutterExternalTexture* textureHolder =
|
||||
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
|
||||
// Callback to resolve the texture.
|
||||
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
|
||||
size_t h) {
|
||||
EXPECT_TRUE(w == width);
|
||||
EXPECT_TRUE(h == height);
|
||||
|
||||
auto texture = std::make_unique<FlutterMetalExternalTexture>();
|
||||
[textureHolder populateTexture:texture.get()];
|
||||
|
||||
EXPECT_TRUE(texture->num_textures == 2);
|
||||
EXPECT_TRUE(texture->textures != nullptr);
|
||||
EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA);
|
||||
EXPECT_TRUE(texture->yuv_color_space ==
|
||||
FlutterMetalExternalTextureYUVColorSpace::kBT601FullRange);
|
||||
return texture;
|
||||
};
|
||||
|
||||
// Render the texture.
|
||||
std::unique_ptr<flutter::Texture> texture =
|
||||
std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
|
||||
SkRect bounds = SkRect::MakeWH(info.width(), info.height());
|
||||
DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
|
||||
|
||||
DisplayListBuilder builder;
|
||||
flutter::Texture::PaintContext context{
|
||||
.canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context};
|
||||
texture->Paint(context, bounds, /*freeze=*/false, sampling);
|
||||
}
|
||||
|
||||
TEST_F(FlutterEmbedderExternalTextureTest, TestPopulateUnsupportedExternalTextureImpeller) {
|
||||
// Constants.
|
||||
const size_t width = 100;
|
||||
const size_t height = 100;
|
||||
const int64_t texture_id = 1;
|
||||
|
||||
// Set up the surface.
|
||||
FlutterDarwinContextMetalSkia* darwinContextMetal =
|
||||
[[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
|
||||
impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
||||
|
||||
// Create a texture.
|
||||
TestExternalTexture* testExternalTexture =
|
||||
[[TestExternalTexture alloc] initWidth:width
|
||||
height:height
|
||||
pixelFormatType:kCVPixelFormatType_420YpCbCr8PlanarFullRange];
|
||||
FlutterExternalTexture* textureHolder =
|
||||
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
|
||||
// Callback to resolve the texture.
|
||||
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
|
||||
size_t h) {
|
||||
EXPECT_TRUE(w == width);
|
||||
EXPECT_TRUE(h == height);
|
||||
|
||||
auto texture = std::make_unique<FlutterMetalExternalTexture>();
|
||||
EXPECT_FALSE([textureHolder populateTexture:texture.get()]);
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
// Render the texture.
|
||||
std::unique_ptr<flutter::Texture> texture =
|
||||
std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
|
||||
SkRect bounds = SkRect::MakeWH(info.width(), info.height());
|
||||
DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
|
||||
|
||||
DisplayListBuilder builder;
|
||||
flutter::Texture::PaintContext context{
|
||||
.canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context};
|
||||
texture->Paint(context, bounds, /*freeze=*/false, sampling);
|
||||
}
|
||||
|
||||
} // namespace flutter::testing
|
||||
|
||||
@@ -38,6 +38,7 @@ void EmbedderExternalTextureGL::Paint(PaintContext& context,
|
||||
last_image_ =
|
||||
ResolveTexture(Id(), //
|
||||
context.gr_context, //
|
||||
context.aiks_context, //
|
||||
SkISize::Make(bounds.width(), bounds.height()) //
|
||||
);
|
||||
}
|
||||
@@ -58,6 +59,7 @@ void EmbedderExternalTextureGL::Paint(PaintContext& context,
|
||||
sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTexture(
|
||||
int64_t texture_id,
|
||||
GrDirectContext* context,
|
||||
impeller::AiksContext* aiks_context,
|
||||
const SkISize& size) {
|
||||
context->flushAndSubmit();
|
||||
context->resetContext(kAll_GrBackendState);
|
||||
|
||||
@@ -28,6 +28,7 @@ class EmbedderExternalTextureGL : public flutter::Texture {
|
||||
|
||||
sk_sp<DlImage> ResolveTexture(int64_t texture_id,
|
||||
GrDirectContext* context,
|
||||
impeller::AiksContext* aiks_context,
|
||||
const SkISize& size);
|
||||
|
||||
// |flutter::Texture|
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "flutter/common/graphics/texture.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
#include "impeller/aiks/aiks_context.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkSize.h"
|
||||
|
||||
@@ -29,6 +30,7 @@ class EmbedderExternalTextureMetal : public flutter::Texture {
|
||||
|
||||
sk_sp<DlImage> ResolveTexture(int64_t texture_id,
|
||||
GrDirectContext* context,
|
||||
impeller::AiksContext* aiks_context,
|
||||
const SkISize& size);
|
||||
|
||||
// |flutter::Texture|
|
||||
|
||||
@@ -37,8 +37,8 @@ void EmbedderExternalTextureMetal::Paint(PaintContext& context,
|
||||
bool freeze,
|
||||
const DlImageSampling sampling) {
|
||||
if (last_image_ == nullptr) {
|
||||
last_image_ =
|
||||
ResolveTexture(Id(), context.gr_context, SkISize::Make(bounds.width(), bounds.height()));
|
||||
last_image_ = ResolveTexture(Id(), context.gr_context, context.aiks_context,
|
||||
SkISize::Make(bounds.width(), bounds.height()));
|
||||
}
|
||||
|
||||
DlCanvas* canvas = context.canvas;
|
||||
@@ -56,6 +56,7 @@ void EmbedderExternalTextureMetal::Paint(PaintContext& context,
|
||||
|
||||
sk_sp<DlImage> EmbedderExternalTextureMetal::ResolveTexture(int64_t texture_id,
|
||||
GrDirectContext* context,
|
||||
impeller::AiksContext* aiks_context,
|
||||
const SkISize& size) {
|
||||
std::unique_ptr<FlutterMetalExternalTexture> texture =
|
||||
external_texture_callback_(texture_id, size.width(), size.height());
|
||||
@@ -63,6 +64,35 @@ sk_sp<DlImage> EmbedderExternalTextureMetal::ResolveTexture(int64_t texture_id,
|
||||
if (!texture) {
|
||||
return nullptr;
|
||||
}
|
||||
if (aiks_context) {
|
||||
switch (texture->pixel_format) {
|
||||
case FlutterMetalExternalTexturePixelFormat::kRGBA: {
|
||||
if (ValidNumTextures(1, texture->num_textures)) {
|
||||
id<MTLTexture> rgbaTex = (__bridge id<MTLTexture>)texture->textures[0];
|
||||
return [FlutterDarwinExternalTextureImpellerImageWrapper wrapRGBATexture:rgbaTex
|
||||
aiksContext:aiks_context];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FlutterMetalExternalTexturePixelFormat::kYUVA: {
|
||||
if (ValidNumTextures(2, texture->num_textures)) {
|
||||
id<MTLTexture> yTex = (__bridge id<MTLTexture>)texture->textures[0];
|
||||
id<MTLTexture> uvTex = (__bridge id<MTLTexture>)texture->textures[1];
|
||||
impeller::YUVColorSpace colorSpace =
|
||||
texture->yuv_color_space ==
|
||||
FlutterMetalExternalTextureYUVColorSpace::kBT601LimitedRange
|
||||
? impeller::YUVColorSpace::kBT601LimitedRange
|
||||
: impeller::YUVColorSpace::kBT601FullRange;
|
||||
return [FlutterDarwinExternalTextureImpellerImageWrapper wrapYUVATexture:yTex
|
||||
UVTex:uvTex
|
||||
YUVColorSpace:colorSpace
|
||||
aiksContext:aiks_context];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<SkImage> image;
|
||||
|
||||
@@ -72,8 +102,8 @@ sk_sp<DlImage> EmbedderExternalTextureMetal::ResolveTexture(int64_t texture_id,
|
||||
id<MTLTexture> rgbaTex = (__bridge id<MTLTexture>)texture->textures[0];
|
||||
image = [FlutterDarwinExternalTextureSkImageWrapper wrapRGBATexture:rgbaTex
|
||||
grContext:context
|
||||
width:size.width()
|
||||
height:size.height()];
|
||||
width:rgbaTex.width
|
||||
height:rgbaTex.height];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user