forked from flutter-tizen/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tizen] Support EmbedderExternalTextureGL for impeller (flutter-tizen…
- Loading branch information
1 parent
c5150d3
commit ab84814
Showing
7 changed files
with
256 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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; | ||
} | ||
|
||
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 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 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 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