Do not resolve external textures unless there is new frame available (flutter/engine#27508)
This commit is contained in:
@@ -27,12 +27,12 @@ void EmbedderExternalTextureGL::Paint(SkCanvas& canvas,
|
||||
bool freeze,
|
||||
GrDirectContext* context,
|
||||
const SkSamplingOptions& sampling) {
|
||||
if (auto image =
|
||||
ResolveTexture(Id(), //
|
||||
context, //
|
||||
SkISize::Make(bounds.width(), bounds.height()) //
|
||||
)) {
|
||||
last_image_ = image;
|
||||
if (last_image_ == nullptr) {
|
||||
last_image_ =
|
||||
ResolveTexture(Id(), //
|
||||
context, //
|
||||
SkISize::Make(bounds.width(), bounds.height()) //
|
||||
);
|
||||
}
|
||||
|
||||
if (last_image_) {
|
||||
@@ -102,7 +102,9 @@ void EmbedderExternalTextureGL::OnGrContextCreated() {}
|
||||
void EmbedderExternalTextureGL::OnGrContextDestroyed() {}
|
||||
|
||||
// |flutter::Texture|
|
||||
void EmbedderExternalTextureGL::MarkNewFrameAvailable() {}
|
||||
void EmbedderExternalTextureGL::MarkNewFrameAvailable() {
|
||||
last_image_ = nullptr;
|
||||
}
|
||||
|
||||
// |flutter::Texture|
|
||||
void EmbedderExternalTextureGL::OnTextureUnregistered() {}
|
||||
|
||||
@@ -36,8 +36,8 @@ void EmbedderExternalTextureMetal::Paint(SkCanvas& canvas,
|
||||
bool freeze,
|
||||
GrDirectContext* context,
|
||||
const SkSamplingOptions& sampling) {
|
||||
if (auto image = ResolveTexture(Id(), context, SkISize::Make(bounds.width(), bounds.height()))) {
|
||||
last_image_ = image;
|
||||
if (last_image_ == nullptr) {
|
||||
last_image_ = ResolveTexture(Id(), context, SkISize::Make(bounds.width(), bounds.height()));
|
||||
}
|
||||
|
||||
if (last_image_) {
|
||||
@@ -100,7 +100,9 @@ void EmbedderExternalTextureMetal::OnGrContextCreated() {}
|
||||
void EmbedderExternalTextureMetal::OnGrContextDestroyed() {}
|
||||
|
||||
// |flutter::Texture|
|
||||
void EmbedderExternalTextureMetal::MarkNewFrameAvailable() {}
|
||||
void EmbedderExternalTextureMetal::MarkNewFrameAvailable() {
|
||||
last_image_ = nullptr;
|
||||
}
|
||||
|
||||
// |flutter::Texture|
|
||||
void EmbedderExternalTextureMetal::OnTextureUnregistered() {}
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
#include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h"
|
||||
#include "flutter/shell/platform/embedder/tests/embedder_unittests_util.h"
|
||||
#include "flutter/testing/assertions_skia.h"
|
||||
#include "flutter/testing/test_gl_surface.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
#include "third_party/skia/src/gpu/gl/GrGLDefines.h"
|
||||
#include "third_party/tonic/converter/dart_converter.h"
|
||||
|
||||
namespace flutter {
|
||||
@@ -3617,5 +3619,56 @@ TEST_F(EmbedderTest, CreateInvalidBackingstoreOpenGLFramebuffer) {
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
TEST_F(EmbedderTest, ExternalTextureGLRefreshedTooOften) {
|
||||
TestGLSurface surface(SkISize::Make(100, 100));
|
||||
auto context = surface.GetGrContext();
|
||||
|
||||
typedef void (*glGenTexturesProc)(uint32_t n, uint32_t * textures);
|
||||
glGenTexturesProc glGenTextures;
|
||||
|
||||
glGenTextures = reinterpret_cast<glGenTexturesProc>(
|
||||
surface.GetProcAddress("glGenTextures"));
|
||||
|
||||
uint32_t name;
|
||||
glGenTextures(1, &name);
|
||||
|
||||
bool resolve_called = false;
|
||||
|
||||
EmbedderExternalTextureGL::ExternalTextureCallback callback(
|
||||
[&](int64_t, size_t, size_t) {
|
||||
resolve_called = true;
|
||||
auto res = std::make_unique<FlutterOpenGLTexture>();
|
||||
res->target = GR_GL_TEXTURE_2D;
|
||||
res->name = name;
|
||||
res->format = GR_GL_RGBA8;
|
||||
res->user_data = nullptr;
|
||||
res->destruction_callback = [](void*) {};
|
||||
res->width = res->height = 100;
|
||||
return res;
|
||||
});
|
||||
EmbedderExternalTextureGL texture(1, callback);
|
||||
|
||||
auto skia_surface = surface.GetOnscreenSurface();
|
||||
auto canvas = skia_surface->getCanvas();
|
||||
|
||||
Texture* texture_ = &texture;
|
||||
texture_->Paint(*canvas, SkRect::MakeXYWH(0, 0, 100, 100), false,
|
||||
context.get(), SkSamplingOptions(SkFilterMode::kLinear));
|
||||
|
||||
EXPECT_TRUE(resolve_called);
|
||||
resolve_called = false;
|
||||
|
||||
texture_->Paint(*canvas, SkRect::MakeXYWH(0, 0, 100, 100), false,
|
||||
context.get(), SkSamplingOptions(SkFilterMode::kLinear));
|
||||
|
||||
EXPECT_FALSE(resolve_called);
|
||||
|
||||
texture_->MarkNewFrameAvailable();
|
||||
texture_->Paint(*canvas, SkRect::MakeXYWH(0, 0, 100, 100), false,
|
||||
context.get(), SkSamplingOptions(SkFilterMode::kLinear));
|
||||
|
||||
EXPECT_TRUE(resolve_called);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
@@ -434,5 +434,52 @@ TEST_F(EmbedderTest, CreateInvalidBackingstoreMetalTexture) {
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
TEST_F(EmbedderTest, ExternalTextureMetalRefreshedTooOften) {
|
||||
EmbedderTestContextMetal& context = reinterpret_cast<EmbedderTestContextMetal&>(
|
||||
GetEmbedderContext(EmbedderTestContextType::kMetalContext));
|
||||
|
||||
TestMetalContext* metal_context = context.GetTestMetalContext();
|
||||
auto metal_texture = metal_context->CreateMetalTexture(SkISize::Make(100, 100));
|
||||
|
||||
std::vector<FlutterMetalTextureHandle> textures{metal_texture.texture};
|
||||
|
||||
bool resolve_called = false;
|
||||
|
||||
EmbedderExternalTextureMetal::ExternalTextureCallback callback([&](int64_t id, size_t, size_t) {
|
||||
resolve_called = true;
|
||||
auto res = std::make_unique<FlutterMetalExternalTexture>();
|
||||
res->struct_size = sizeof(FlutterMetalExternalTexture);
|
||||
res->width = res->height = 100;
|
||||
res->pixel_format = FlutterMetalExternalTexturePixelFormat::kRGBA;
|
||||
res->textures = textures.data();
|
||||
res->num_textures = 1;
|
||||
return res;
|
||||
});
|
||||
EmbedderExternalTextureMetal texture(1, callback);
|
||||
|
||||
auto surface = TestMetalSurface::Create(*metal_context, SkISize::Make(100, 100));
|
||||
auto skia_surface = surface->GetSurface();
|
||||
auto canvas = skia_surface->getCanvas();
|
||||
|
||||
Texture* texture_ = &texture;
|
||||
texture_->Paint(*canvas, SkRect::MakeXYWH(0, 0, 100, 100), false, surface->GetGrContext().get(),
|
||||
SkSamplingOptions(SkFilterMode::kLinear));
|
||||
|
||||
EXPECT_TRUE(resolve_called);
|
||||
resolve_called = false;
|
||||
|
||||
texture_->Paint(*canvas, SkRect::MakeXYWH(0, 0, 100, 100), false, surface->GetGrContext().get(),
|
||||
SkSamplingOptions(SkFilterMode::kLinear));
|
||||
|
||||
EXPECT_FALSE(resolve_called);
|
||||
|
||||
texture_->MarkNewFrameAvailable();
|
||||
|
||||
texture_->Paint(*canvas, SkRect::MakeXYWH(0, 0, 100, 100), false, surface->GetGrContext().get(),
|
||||
SkSamplingOptions(SkFilterMode::kLinear));
|
||||
|
||||
EXPECT_TRUE(resolve_called);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
Reference in New Issue
Block a user