xingweizhu
3 年前
当前提交
58677882
共有 3 个文件被更改,包括 131 次插入 和 5 次删除
-
12engine/src/shell/platform/unity/android/uiwidgets_panel.cc
-
80engine/src/shell/platform/unity/android/unity_external_texture_gl.cc
-
44engine/src/shell/platform/unity/android/unity_external_texture_gl.h
|
|||
#include "unity_external_texture_gl.h"
|
|||
|
|||
#include <EGL/egl.h>
|
|||
#include <EGL/eglext.h>
|
|||
#include <EGL/eglext_angle.h>
|
|||
#include <GLES2/gl2.h>
|
|||
#include <GLES2/gl2ext.h>
|
|||
|
|||
#include "flutter/fml/logging.h"
|
|||
#include "include/gpu/GrBackendSurface.h"
|
|||
#include "include/gpu/GrContext.h"
|
|||
#include "include/gpu/gl/GrGLTypes.h"
|
|||
#include "src/gpu/gl/GrGLDefines.h"
|
|||
#include "uiwidgets_system.h"
|
|||
|
|||
namespace uiwidgets { |
|||
|
|||
UnityExternalTextureGL::UnityExternalTextureGL( |
|||
int64_t texture_identifier, void* native_texture_ptr, |
|||
UnitySurfaceManager* unity_surface_manager) |
|||
: Texture(texture_identifier), |
|||
unity_surface_manager_(unity_surface_manager) { |
|||
auto* graphics = UIWidgetsSystem::GetInstancePtr() |
|||
->GetUnityInterfaces() |
|||
->Get<IUnityGraphics>(); |
|||
UnityGfxRenderer renderer = graphics->GetRenderer(); |
|||
FML_DCHECK(renderer == kUnityGfxRendererOpenGLES20 || renderer == kUnityGfxRendererOpenGLES30); |
|||
gl_texture_ = texture_identifier; |
|||
} |
|||
|
|||
UnityExternalTextureGL::~UnityExternalTextureGL() { |
|||
last_image_ = nullptr; |
|||
if (gl_texture_) { |
|||
glDeleteTextures(1, &gl_texture_); |
|||
gl_texture_ = 0; |
|||
} |
|||
|
|||
eglDestroyImageKHR(unity_surface_manager_->GetEGLDisplay(), egl_image_); |
|||
d3d11_texture_->Release(); |
|||
} |
|||
|
|||
// |flutter::Texture|
|
|||
void UnityExternalTextureGL::Paint(SkCanvas& canvas, const SkRect& bounds, |
|||
bool freeze, GrContext* context) { |
|||
if (!last_image_) { |
|||
GrGLTextureInfo texture_info; |
|||
texture_info.fTarget = GR_GL_TEXTURE_2D; |
|||
texture_info.fID = gl_texture_; |
|||
texture_info.fFormat = GR_GL_RGBA8; |
|||
|
|||
GrBackendTexture backend_tex = GrBackendTexture( |
|||
bounds.width(), bounds.height(), GrMipMapped::kNo, texture_info); |
|||
|
|||
last_image_ = SkImage::MakeFromTexture( |
|||
context, backend_tex, kBottomLeft_GrSurfaceOrigin, |
|||
kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr); |
|||
} |
|||
|
|||
if (last_image_) { |
|||
if (bounds != SkRect::Make(last_image_->bounds())) { |
|||
canvas.drawImageRect(last_image_, bounds, nullptr); |
|||
} else { |
|||
canvas.drawImage(last_image_, bounds.x(), bounds.y()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// |flutter::Texture|
|
|||
void UnityExternalTextureGL::OnGrContextCreated() {} |
|||
|
|||
// |flutter::Texture|
|
|||
void UnityExternalTextureGL::OnGrContextDestroyed() {} |
|||
|
|||
// |flutter::Texture|
|
|||
void UnityExternalTextureGL::MarkNewFrameAvailable() {} |
|||
|
|||
// |flutter::Texture|
|
|||
void UnityExternalTextureGL::OnTextureUnregistered() {} |
|||
|
|||
} // namespace uiwidgets
|
|
|||
#pragma once |
|||
|
|||
#include "flow/texture.h" |
|||
#include "flutter/fml/macros.h" |
|||
#include "include/core/SkImage.h" |
|||
#include "include/core/SkSize.h" |
|||
#include "unity_surface_manager.h" |
|||
|
|||
namespace uiwidgets { |
|||
|
|||
class UnityExternalTextureGL : public Texture { |
|||
public: |
|||
UnityExternalTextureGL(int64_t texture_identifier, void* native_texture_ptr, |
|||
UnitySurfaceManager* unity_surface_manager); |
|||
|
|||
~UnityExternalTextureGL() override; |
|||
|
|||
private: |
|||
UnitySurfaceManager* unity_surface_manager_; |
|||
bool gr_context_created_ = false; |
|||
|
|||
GLuint gl_texture_; |
|||
sk_sp<SkImage> last_image_; |
|||
|
|||
// |flutter::Texture| |
|||
void Paint(SkCanvas& canvas, const SkRect& bounds, bool freeze, |
|||
GrContext* context) 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(UnityExternalTextureGL); |
|||
}; |
|||
|
|||
} // namespace uiwidgets |
撰写
预览
正在加载...
取消
保存
Reference in new issue