Skip to content

Call ClearColor once to remove noise #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 deletions shell/platform/tizen/external_texture_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#undef EFL_BETA_API_SUPPORT
#include <Ecore.h>
#include <Elementary.h>
#include <Evas_GL.h>
extern Evas_GL* kEvasGl;
extern Evas_GL_API* kEvasGLApi;
#include <Evas_GL_GLES3_Helpers.h>
extern Evas_GL* g_evas_gl;
EVAS_GL_GLOBAL_GLES3_DECLARE();
#endif

#include <atomic>
Expand All @@ -41,7 +41,7 @@ ExternalTextureGL::~ExternalTextureGL() {
#ifndef FLUTTER_TIZEN_EVASGL
glDeleteTextures(1, &state_->gl_texture);
#else
kEvasGLApi->glDeleteTextures(1, &state_->gl_texture);
glDeleteTextures(1, &state_->gl_texture);
#endif
}
state_.release();
Expand Down Expand Up @@ -95,12 +95,12 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier(
(PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR");
const EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE,
EGL_NONE};
EGLImageKHR eglSrcImage = n_eglCreateImageKHR(
EGLImageKHR egl_src_image = n_eglCreateImageKHR(
eglGetCurrentDisplay(), EGL_NO_CONTEXT, EGL_NATIVE_SURFACE_TIZEN,
(EGLClientBuffer)texture_tbm_surface_, attrs);

if (!eglSrcImage) {
FT_LOGE("eglSrcImage create fail!!, errorcode == %d", eglGetError());
if (!egl_src_image) {
FT_LOGE("egl_src_image create fail!!, errorcode == %d", eglGetError());
mutex_.unlock();
return false;
}
Expand All @@ -121,43 +121,40 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier(
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES =
(PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress(
"glEGLImageTargetTexture2DOES");
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, eglSrcImage);
if (eglSrcImage) {
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_src_image);
if (egl_src_image) {
PFNEGLDESTROYIMAGEKHRPROC n_eglDestoryImageKHR =
(PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR");
n_eglDestoryImageKHR(eglGetCurrentDisplay(), eglSrcImage);
n_eglDestoryImageKHR(eglGetCurrentDisplay(), egl_src_image);
}
#else
int eglImgAttr[] = {EVAS_GL_IMAGE_PRESERVED, GL_TRUE, 0};
EvasGLImage eglSrcImage = kEvasGLApi->evasglCreateImageForContext(
kEvasGl, evas_gl_current_context_get(kEvasGl),
EvasGLImage egl_src_image = evasglCreateImageForContext(
g_evas_gl, evas_gl_current_context_get(g_evas_gl),
EVAS_GL_NATIVE_SURFACE_TIZEN, (void*)(intptr_t)texture_tbm_surface_,
eglImgAttr);
if (!eglSrcImage) {
// FT_LOGE("eglSrcImage create fail!!, errorcode == %d", eglGetError());
if (!egl_src_image) {
// FT_LOGE("egl_src_image create fail!!, errorcode == %d", eglGetError());
mutex_.unlock();
return false;
}
if (state_->gl_texture == 0) {
kEvasGLApi->glGenTextures(1, &state_->gl_texture);
kEvasGLApi->glBindTexture(GL_TEXTURE_EXTERNAL_OES, state_->gl_texture);
glGenTextures(1, &state_->gl_texture);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, state_->gl_texture);
// set the texture wrapping parameters
kEvasGLApi->glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_BORDER);
kEvasGLApi->glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_BORDER);
// set texture filtering parameters
kEvasGLApi->glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
kEvasGLApi->glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
kEvasGLApi->glBindTexture(GL_TEXTURE_EXTERNAL_OES, state_->gl_texture);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, state_->gl_texture);
}
kEvasGLApi->glEvasGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
eglSrcImage);
if (eglSrcImage) {
kEvasGLApi->evasglDestroyImage(eglSrcImage);
glEvasGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_src_image);
if (egl_src_image) {
evasglDestroyImage(egl_src_image);
}

#endif
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/tizen/tizen_embedder_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ TizenEmbedderEngine::TizenEmbedderEngine(
tizen_renderer = std::make_unique<TizenRendererEvasGL>(
*this, window_properties.x, window_properties.y, window_properties.width,
window_properties.height);
// clear once to remove noise
tizen_renderer->OnMakeCurrent();
tizen_renderer->ClearColor(0, 0, 0, 0);
tizen_renderer->OnPresent();
#else
#ifdef FLUTTER_TIZEN_4
tizen_renderer = std::make_unique<TizenRendererEcoreWl>(
Expand Down
57 changes: 28 additions & 29 deletions shell/platform/tizen/tizen_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
Evas_GL* kEvasGl = nullptr;
Evas_GL_API* kEvasGLApi = nullptr;
#include <Evas_GL_GLES3_Helpers.h>
Evas_GL* g_evas_gl = nullptr;
EVAS_GL_GLOBAL_GLES3_DEFINE();
#endif

#include "flutter/shell/platform/tizen/tizen_log.h"
Expand Down Expand Up @@ -467,6 +468,11 @@ void TizenRenderer::DestoryEglSurface() {
}
#else

void TizenRenderer::ClearColor(float r, float g, float b, float a) {
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
}

bool TizenRenderer::OnMakeCurrent() {
if (!IsValid()) {
FT_LOGE("Invalid TizenRenderer");
Expand All @@ -475,7 +481,7 @@ bool TizenRenderer::OnMakeCurrent() {
if (evas_gl_make_current(evas_gl_, gl_surface_, gl_context_) != EINA_TRUE) {
return false;
}
evas_object_image_pixels_dirty_set((Evas_Object*)GetImageHandle(),EINA_TRUE);
evas_object_image_pixels_dirty_set((Evas_Object*)GetImageHandle(), EINA_TRUE);
return true;
}

Expand Down Expand Up @@ -523,13 +529,12 @@ uint32_t TizenRenderer::OnGetFBO() {
return 0;
}

#define GL_FUNC(FunctionName) \
else if (strcmp(name, #FunctionName) == 0) { \
return reinterpret_cast<void*>(evas_glGlapi->FunctionName); \
#define GL_FUNC(FunctionName) \
else if (strcmp(name, #FunctionName) == 0) { \
return reinterpret_cast<void*>(FunctionName); \
}
void* TizenRenderer::OnProcResolver(const char* name) {
auto address =
evas_gl_proc_address_get(evas_gl_, name);
auto address = evas_gl_proc_address_get(evas_gl_, name);
if (address != nullptr) {
return reinterpret_cast<void*>(address);
}
Expand Down Expand Up @@ -646,7 +651,7 @@ void* TizenRenderer::OnProcResolver(const char* name) {

bool TizenRenderer::InitializeRenderer(int32_t x, int32_t y, int32_t w,
int32_t h) {
if (!SetupEvasGL(x,y,w, h)) {
if (!SetupEvasGL(x, y, w, h)) {
FT_LOGE("SetupEvasGL fail");
return false;
}
Expand All @@ -658,21 +663,19 @@ bool TizenRenderer::InitializeRenderer(int32_t x, int32_t y, int32_t w,
bool TizenRenderer::IsValid() { return is_valid_; }

bool TizenRenderer::SetupEvasGL(int32_t x, int32_t y, int32_t w, int32_t h) {
evas_gl_ = evas_gl_new(
evas_object_evas_get((Evas_Object*)SetupEvasWindow(x, y, w, h)));

evas_gl_ = evas_gl_new(evas_object_evas_get((Evas_Object*)SetupEvasWindow(x, y, w, h)));

if(!evas_gl_){
if (!evas_gl_) {
FT_LOGE("SetupEvasWindow fail");
return false;
}

evas_glGlapi = evas_gl_api_get(evas_gl_);
kEvasGl = evas_gl_;
kEvasGLApi = evas_glGlapi;
g_evas_gl = evas_gl_;

gl_config_ = evas_gl_config_new();
gl_config_->color_format = EVAS_GL_RGBA_8888;
gl_config_->depth_bits = EVAS_GL_DEPTH_BIT_24;
gl_config_->depth_bits = EVAS_GL_DEPTH_NONE;
gl_config_->stencil_bits = EVAS_GL_STENCIL_NONE;
gl_config_->options_bits = EVAS_GL_OPTIONS_NONE;

Expand All @@ -683,24 +686,20 @@ bool TizenRenderer::SetupEvasGL(int32_t x, int32_t y, int32_t w, int32_t h) {
// EVAS_GL_OPTIONS_DIRECT_MEMORY_OPTIMIZE |
// EVAS_GL_OPTIONS_CLIENT_SIDE_ROTATION);

gl_context_ =
evas_gl_context_version_create(evas_gl_, NULL, EVAS_GL_GLES_2_X);
gl_resource_context_ =
evas_gl_context_version_create(evas_gl_, NULL, EVAS_GL_GLES_2_X);

gl_context_ = evas_gl_context_create(evas_gl_, NULL);
gl_resource_context_ = evas_gl_context_create(evas_gl_, gl_context_);
EVAS_GL_GLOBAL_GLES3_USE(g_evas_gl, gl_context_);
gl_surface_ = evas_gl_surface_create(evas_gl_, gl_config_, w, h);

gl_resource_surface_ =
evas_gl_pbuffer_surface_create(evas_gl_, gl_config_, w, h, NULL);

Evas_Native_Surface ns;
evas_gl_native_surface_get(evas_gl_, gl_surface_, &ns);
evas_object_image_native_surface_set((Evas_Object*)GetImageHandle(),
&ns);
pixelDirtyCallback_ = [](void* data, Evas_Object* o) {
};
evas_object_image_pixels_get_callback_set(
(Evas_Object*)GetImageHandle(), pixelDirtyCallback_, NULL);
evas_object_image_native_surface_set((Evas_Object*)GetImageHandle(), &ns);
pixelDirtyCallback_ = [](void* data, Evas_Object* o) {};
evas_object_image_pixels_get_callback_set((Evas_Object*)GetImageHandle(),
pixelDirtyCallback_, NULL);
return true;
}

Expand All @@ -710,8 +709,8 @@ void TizenRenderer::DestoryRenderer() {
}

void TizenRenderer::DestoryEvasGL() {
evas_gl_surface_destroy(evas_gl_,gl_surface_);
evas_gl_surface_destroy(evas_gl_,gl_resource_surface_);
evas_gl_surface_destroy(evas_gl_, gl_surface_);
evas_gl_surface_destroy(evas_gl_, gl_resource_surface_);

evas_gl_context_destroy(evas_gl_, gl_context_);
evas_gl_context_destroy(evas_gl_, gl_resource_context_);
Expand Down
11 changes: 6 additions & 5 deletions shell/platform/tizen/tizen_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#undef EFL_BETA_API_SUPPORT
#include <Ecore.h>
#include <Elementary.h>
#include <Evas_GL.h>
#else
#include <EGL/egl.h>
#endif
Expand All @@ -27,6 +26,10 @@ class TizenRenderer {

TizenRenderer(TizenRenderer::Delegate& deleget);
virtual ~TizenRenderer();

#ifdef FLUTTER_TIZEN_EVASGL
void ClearColor(float r, float g, float b, float a);
#endif
bool OnMakeCurrent();
bool OnClearCurrent();
bool OnMakeResourceCurrent();
Expand Down Expand Up @@ -59,12 +62,11 @@ class TizenRenderer {
void DestoryEglSurface();
bool SetupEglSurface();
#else
virtual void* SetupEvasWindow(int32_t x, int32_t y, int32_t w,
int32_t h) = 0;
virtual void* SetupEvasWindow(int32_t x, int32_t y, int32_t w, int32_t h) = 0;
virtual void DestoryEvasWindow() = 0;
virtual void* GetImageHandle() = 0;

bool SetupEvasGL(int32_t x, int32_t y,int32_t w, int32_t h);
bool SetupEvasGL(int32_t x, int32_t y, int32_t w, int32_t h);
void DestoryEvasGL();
#endif
void DestoryRenderer();
Expand All @@ -75,7 +77,6 @@ class TizenRenderer {
#ifdef FLUTTER_TIZEN_EVASGL
Evas_GL_Config* gl_config_;
Evas_GL* evas_gl_{nullptr};
Evas_GL_API* evas_glGlapi{nullptr};

Evas_GL_Context* gl_context_;
Evas_GL_Context* gl_resource_context_;
Expand Down