浏览代码

stash changes

/zxw-3d_android
xingweizhu 3 年前
当前提交
58677882
共有 3 个文件被更改,包括 131 次插入5 次删除
  1. 12
      engine/src/shell/platform/unity/android/uiwidgets_panel.cc
  2. 80
      engine/src/shell/platform/unity/android/unity_external_texture_gl.cc
  3. 44
      engine/src/shell/platform/unity/android/unity_external_texture_gl.h

12
engine/src/shell/platform/unity/android/uiwidgets_panel.cc


int UIWidgetsPanel::RegisterTexture(void *native_texture_ptr)
{
std::cerr << "registering external texture is not implemented for android" << std::endl;
int texture_identifier = 0;
//int texture_identifier = 0;
int texture_identifier = reinterpret_cast<int>(native_texture_ptr);
// auto* engine = reinterpret_cast<EmbedderEngine*>(engine_);
auto* engine = reinterpret_cast<EmbedderEngine*>(engine_);
// engine->GetShell().GetPlatformView()->RegisterTexture(
// std::make_unique<UnityExternalTextureGL>(
// texture_identifier, native_texture_ptr, surface_manager_.get()));
engine->GetShell().GetPlatformView()->RegisterTexture(
std::make_unique<UnityExternalTextureGL>(
texture_identifier, native_texture_ptr, surface_manager_.get()));
return texture_identifier;
}

80
engine/src/shell/platform/unity/android/unity_external_texture_gl.cc


#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

44
engine/src/shell/platform/unity/android/unity_external_texture_gl.h


#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
正在加载...
取消
保存