forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore support for pixel buffer textures (#322)
* Organize build dependencies * Support pixel type external textures
- Loading branch information
Showing
6 changed files
with
230 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "external_texture_pixel_egl.h" | ||
|
||
#include <EGL/egl.h> | ||
#include <EGL/eglext.h> | ||
#include <GLES3/gl32.h> | ||
|
||
namespace flutter { | ||
|
||
bool ExternalTexturePixelEGL::PopulateTexture( | ||
size_t width, | ||
size_t height, | ||
FlutterOpenGLTexture* opengl_texture) { | ||
if (!CopyPixelBuffer(width, height)) { | ||
return false; | ||
} | ||
|
||
// Populate the texture object used by the engine. | ||
opengl_texture->target = GL_TEXTURE_2D; | ||
opengl_texture->name = state_->gl_texture; | ||
opengl_texture->format = GL_RGBA8; | ||
opengl_texture->destruction_callback = nullptr; | ||
opengl_texture->user_data = nullptr; | ||
opengl_texture->width = width; | ||
opengl_texture->height = height; | ||
return true; | ||
} | ||
|
||
ExternalTexturePixelEGL::ExternalTexturePixelEGL( | ||
FlutterDesktopPixelBufferTextureCallback texture_callback, | ||
void* user_data) | ||
: ExternalTexture(), | ||
texture_callback_(texture_callback), | ||
user_data_(user_data) {} | ||
|
||
bool ExternalTexturePixelEGL::CopyPixelBuffer(size_t& width, size_t& height) { | ||
if (!texture_callback_) { | ||
return false; | ||
} | ||
|
||
const FlutterDesktopPixelBuffer* pixel_buffer = | ||
texture_callback_(width, height, user_data_); | ||
|
||
if (!pixel_buffer || !pixel_buffer->buffer) { | ||
return false; | ||
} | ||
|
||
width = pixel_buffer->width; | ||
height = pixel_buffer->height; | ||
|
||
if (state_->gl_texture == 0) { | ||
glGenTextures(1, static_cast<GLuint*>(&state_->gl_texture)); | ||
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(state_->gl_texture)); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
} else { | ||
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(state_->gl_texture)); | ||
} | ||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, | ||
pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, | ||
pixel_buffer->buffer); | ||
return true; | ||
} | ||
|
||
} // namespace flutter |
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,35 @@ | ||
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EGL_H | ||
#define EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EGL_H | ||
|
||
#include "flutter/shell/platform/common/public/flutter_texture_registrar.h" | ||
#include "flutter/shell/platform/embedder/embedder.h" | ||
#include "flutter/shell/platform/tizen/external_texture.h" | ||
|
||
namespace flutter { | ||
|
||
class ExternalTexturePixelEGL : public ExternalTexture { | ||
public: | ||
ExternalTexturePixelEGL( | ||
FlutterDesktopPixelBufferTextureCallback texture_callback, | ||
void* user_data); | ||
|
||
~ExternalTexturePixelEGL() = default; | ||
|
||
bool PopulateTexture(size_t width, | ||
size_t height, | ||
FlutterOpenGLTexture* opengl_texture) override; | ||
|
||
bool CopyPixelBuffer(size_t& width, size_t& height); | ||
|
||
private: | ||
FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr; | ||
void* user_data_ = nullptr; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EGL_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,71 @@ | ||
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "external_texture_pixel_evas_gl.h" | ||
|
||
#include "tizen_evas_gl_helper.h" | ||
extern Evas_GL* g_evas_gl; | ||
EVAS_GL_GLOBAL_GLES2_DECLARE(); | ||
|
||
namespace flutter { | ||
|
||
bool ExternalTexturePixelEvasGL::PopulateTexture( | ||
size_t width, | ||
size_t height, | ||
FlutterOpenGLTexture* opengl_texture) { | ||
if (!CopyPixelBuffer(width, height)) { | ||
return false; | ||
} | ||
|
||
// Populate the texture object used by the engine. | ||
opengl_texture->target = GL_TEXTURE_2D; | ||
opengl_texture->name = state_->gl_texture; | ||
opengl_texture->format = GL_RGBA8; | ||
opengl_texture->destruction_callback = nullptr; | ||
opengl_texture->user_data = nullptr; | ||
opengl_texture->width = width; | ||
opengl_texture->height = height; | ||
return true; | ||
} | ||
|
||
ExternalTexturePixelEvasGL::ExternalTexturePixelEvasGL( | ||
FlutterDesktopPixelBufferTextureCallback texture_callback, | ||
void* user_data) | ||
: ExternalTexture(), | ||
texture_callback_(texture_callback), | ||
user_data_(user_data) {} | ||
|
||
bool ExternalTexturePixelEvasGL::CopyPixelBuffer(size_t& width, | ||
size_t& height) { | ||
if (!texture_callback_) { | ||
return false; | ||
} | ||
|
||
const FlutterDesktopPixelBuffer* pixel_buffer = | ||
texture_callback_(width, height, user_data_); | ||
|
||
if (!pixel_buffer || !pixel_buffer->buffer) { | ||
return false; | ||
} | ||
|
||
width = pixel_buffer->width; | ||
height = pixel_buffer->height; | ||
|
||
if (state_->gl_texture == 0) { | ||
glGenTextures(1, static_cast<GLuint*>(&state_->gl_texture)); | ||
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(state_->gl_texture)); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
} else { | ||
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(state_->gl_texture)); | ||
} | ||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, | ||
pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, | ||
pixel_buffer->buffer); | ||
return true; | ||
} | ||
|
||
} // namespace flutter |
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,35 @@ | ||
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EVAS_GL_H | ||
#define EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EVAS_GL_H | ||
|
||
#include "flutter/shell/platform/common/public/flutter_texture_registrar.h" | ||
#include "flutter/shell/platform/embedder/embedder.h" | ||
#include "flutter/shell/platform/tizen/external_texture.h" | ||
|
||
namespace flutter { | ||
|
||
class ExternalTexturePixelEvasGL : public ExternalTexture { | ||
public: | ||
ExternalTexturePixelEvasGL( | ||
FlutterDesktopPixelBufferTextureCallback texture_callback, | ||
void* user_data); | ||
|
||
~ExternalTexturePixelEvasGL() = default; | ||
|
||
bool PopulateTexture(size_t width, | ||
size_t height, | ||
FlutterOpenGLTexture* opengl_texture) override; | ||
|
||
bool CopyPixelBuffer(size_t& width, size_t& height); | ||
|
||
private: | ||
FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr; | ||
void* user_data_ = nullptr; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EVAS_GL_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