Skip to content

Texture api change #86

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3b7f88c
Add platfrom surface buffer structor
xiaowei-guan May 8, 2021
f6d12da
Texture api change(draft)
xiaowei-guan May 11, 2021
7874e37
Merge branch 'flutter-2.0.1-tizen' into flutter-2.0.1-tizen-texture-2
xiaowei-guan May 11, 2021
3f7dabf
Revert code to original
xiaowei-guan May 11, 2021
08aaed6
Support GPU buffer texture
xiaowei-guan May 13, 2021
f3bf70f
Change file permission
xiaowei-guan May 13, 2021
4abc488
Add FlutterDesktopGpuBufferTextureConfig in FlutterDesktopTextureInfo.
xiaowei-guan May 14, 2021
77442be
Add buffer parameter at Destruction callback
xiaowei-guan May 18, 2021
4b8106c
Change class name ExternalTextureGL to ExternalTextureSurfaceGL
xiaowei-guan May 19, 2021
18ab87f
Remove not used code
xiaowei-guan May 20, 2021
f792f4e
Fix wild pointer issue
xiaowei-guan May 21, 2021
3576fd8
Convert unique_ptr to shared_ptr when create external texture
xiaowei-guan May 24, 2021
624b0d7
Merge branch 'flutter-2.0.1-tizen' into flutter-2.0.1-tizen-texture-2
xiaowei-guan May 24, 2021
0f5f923
Code format
xiaowei-guan May 24, 2021
240302a
Fix arm64 build error
xiaowei-guan May 24, 2021
c6b1970
Remove not used file
xiaowei-guan May 24, 2021
275201f
Remove unnecessary headers
xiaowei-guan May 25, 2021
4a56f3a
Refactor based on comments
xiaowei-guan May 25, 2021
d662053
Refactor based on comments
xiaowei-guan May 25, 2021
b91ffe3
Fix code review issue
xiaowei-guan May 26, 2021
a7cda29
Fix code review issue
xiaowei-guan May 26, 2021
4849389
Fix code review issue
xiaowei-guan May 26, 2021
00afe06
Remove warning log
xiaowei-guan May 27, 2021
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
20 changes: 20 additions & 0 deletions shell/platform/common/cpp/client_wrapper/core_implementations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ int64_t TextureRegistrarImpl::RegisterTexture(TextureVariant* texture) {
return buffer;
};

int64_t texture_id = FlutterDesktopTextureRegistrarRegisterExternalTexture(
texture_registrar_ref_, &info);
return texture_id;
} else if (auto gpu_buffer_texture = std::get_if<GpuBufferTexture>(texture)) {
FlutterDesktopTextureInfo info = {};
info.type = kFlutterDesktopGpuBufferTexture;
info.gpu_buffer_config.user_data = gpu_buffer_texture;
info.gpu_buffer_config.callback =
[](size_t width, size_t height,
void* user_data) -> const FlutterDesktopGpuBuffer* {
auto texture = static_cast<GpuBufferTexture*>(user_data);
auto buffer = texture->ObtainGpuBuffer(width, height);
return buffer;
};

info.gpu_buffer_config.destruction_callback = [](void* user_data) -> void {
auto texture = static_cast<GpuBufferTexture*>(user_data);
texture->Destruct();
};

int64_t texture_id = FlutterDesktopTextureRegistrarRegisterExternalTexture(
texture_registrar_ref_, &info);
return texture_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,50 @@ class PixelBufferTexture {
const CopyBufferCallback copy_buffer_callback_;
};

// A gpu buffer texture.
class GpuBufferTexture {
public:
// A callback used for retrieving gpu buffers.
typedef std::function<const FlutterDesktopGpuBuffer*(size_t width,
size_t height)>
ObtainGpuBufferCallback;

typedef std::function<void(void* buffer)> DestructGpuBufferCallback;

// Creates a gpu buffer texture that uses the provided |obtain_buffer_cb| to
// retrieve the buffer.
// As the callback is usually invoked from the render thread, the callee must
// take care of proper synchronization. It also needs to be ensured that the
// returned buffer isn't released prior to unregistering this texture.
GpuBufferTexture(ObtainGpuBufferCallback obtain_buffer_callback,
DestructGpuBufferCallback destruction_callback)
: obtain_gpu_buffer_callback_(obtain_buffer_callback),
destruct_gpu_buffer_callback_(destruction_callback),
buffer_(nullptr) {}

// Returns the callback-provided FlutterDesktopGpuBuffer that contains the
// actual gpu buffer pointer. The intended surface size is specified by
// |width| and |height|.
const FlutterDesktopGpuBuffer* ObtainGpuBuffer(size_t width, size_t height) {
const FlutterDesktopGpuBuffer* flutter_buffer =
obtain_gpu_buffer_callback_(width, height);
if (flutter_buffer) {
buffer_ = const_cast<void*>(flutter_buffer->buffer);
}
return flutter_buffer;
}

void Destruct() { destruct_gpu_buffer_callback_(buffer_); }

private:
const ObtainGpuBufferCallback obtain_gpu_buffer_callback_;
const DestructGpuBufferCallback destruct_gpu_buffer_callback_;
void* buffer_;
};

// The available texture variants.
// Only PixelBufferTexture is currently implemented.
// Other variants are expected to be added in the future.
typedef std::variant<PixelBufferTexture> TextureVariant;
// Only PixelBufferTexture and GpuBufferTexture are currently implemented.
typedef std::variant<PixelBufferTexture, GpuBufferTexture> TextureVariant;

// An object keeping track of external textures.
//
Expand Down
32 changes: 31 additions & 1 deletion shell/platform/common/cpp/public/flutter_texture_registrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ typedef struct FlutterDesktopTextureRegistrar*
// Additional types may be added in the future.
typedef enum {
// A Pixel buffer-based texture.
kFlutterDesktopPixelBufferTexture
kFlutterDesktopPixelBufferTexture,
// A Gpu buffer-based texture.
kFlutterDesktopGpuBufferTexture
} FlutterDesktopTextureType;

// An image buffer object.
Expand All @@ -36,6 +38,16 @@ typedef struct {
size_t height;
} FlutterDesktopPixelBuffer;

// An image buffer object.
typedef struct {
// The gpu data buffer.
const void* buffer;
// Width of the gpu buffer.
size_t width;
// Height of the gpu buffer.
size_t height;
} FlutterDesktopGpuBuffer;

// The pixel buffer copy callback definition provided to
// the Flutter engine to copy the texture.
// It is invoked with the intended surface size specified by |width| and
Expand All @@ -50,6 +62,13 @@ typedef const FlutterDesktopPixelBuffer* (
size_t height,
void* user_data);

typedef const FlutterDesktopGpuBuffer* (
*FlutterDesktopGpuBufferTextureCallback)(size_t width,
size_t height,
void* user_data);

typedef void (*FlutterDesktopGpuBufferDestructionCallback)(void* user_data);

// An object used to configure pixel buffer textures.
typedef struct {
// The callback used by the engine to copy the pixel buffer object.
Expand All @@ -58,10 +77,21 @@ typedef struct {
void* user_data;
} FlutterDesktopPixelBufferTextureConfig;

// An object used to configure GPU buffer textures.
typedef struct {
// The callback used by the engine to obtain the GPU buffer object.
FlutterDesktopGpuBufferTextureCallback callback;
// The callback used by the engine to destruct the GPU buffer object.
FlutterDesktopGpuBufferDestructionCallback destruction_callback;
// Opaque data that will get passed to the provided |callback|.
void* user_data;
} FlutterDesktopGPUBufferTextureConfig;

typedef struct {
FlutterDesktopTextureType type;
union {
FlutterDesktopPixelBufferTextureConfig pixel_buffer_config;
FlutterDesktopGPUBufferTextureConfig gpu_buffer_config;
};
} FlutterDesktopTextureInfo;

Expand Down
5 changes: 3 additions & 2 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ source_set("flutter_engine") {

_public_headers = [
"public/flutter_platform_view.h",
"public/flutter_tizen_texture_registrar.h",
"public/flutter_tizen.h",
]

Expand Down Expand Up @@ -95,9 +94,11 @@ template("embedder_for_profile") {
"channels/platform_view_channel.cc",
"channels/settings_channel.cc",
"channels/text_input_channel.cc",
"external_texture_gl.cc",
"external_texture_pixel_gl.cc",
"external_texture_surface_gl.cc",
"flutter_tizen.cc",
"flutter_tizen_engine.cc",
"flutter_tizen_texture_registrar.cc",
"key_event_handler.cc",
"tizen_event_loop.cc",
"tizen_log.cc",
Expand Down
49 changes: 49 additions & 0 deletions shell/platform/tizen/external_texture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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_H_
#define EMBEDDER_EXTERNAL_TEXTURE_H_

#include <atomic>
#include <memory>
#include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h"
#include "flutter/shell/platform/embedder/embedder.h"

#ifdef TIZEN_RENDERER_EVAS_GL
#undef EFL_BETA_API_SUPPORT
#include <Evas_GL.h>
#else
#include <GLES2/gl2.h>
#endif

struct ExternalTextureGLState {
GLuint gl_texture;
};

static std::atomic_long next_texture_id = {1};

// An adaptation class of flutter engine and external texture interface.
class ExternalTexture : public std::enable_shared_from_this<ExternalTexture> {
public:
ExternalTexture()
: state_(std::make_unique<ExternalTextureGLState>()),
texture_id_(next_texture_id++) {}
virtual ~ExternalTexture() = default;

/**
* Returns the unique id for the ExternalTextureGL instance.
*/
int64_t TextureId() { return (int64_t)texture_id_; }

virtual bool PopulateTexture(size_t width,
size_t height,
FlutterOpenGLTexture* opengl_texture) = 0;
virtual void OnDestruction(){};

protected:
std::unique_ptr<ExternalTextureGLState> state_;
const long texture_id_{0};
};

#endif // EMBEDDER_EXTERNAL_TEXTURE_H_
53 changes: 0 additions & 53 deletions shell/platform/tizen/external_texture_gl.h

This file was deleted.

70 changes: 70 additions & 0 deletions shell/platform/tizen/external_texture_pixel_gl.cc
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 "flutter/shell/platform/tizen/external_texture_pixel_gl.h"

#ifdef TIZEN_RENDERER_EVAS_GL
#undef EFL_BETA_API_SUPPORT
#include <Evas_GL_GLES3_Helpers.h>
extern Evas_GL* g_evas_gl;
EVAS_GL_GLOBAL_GLES3_DECLARE();
#else
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl32.h>
#endif

bool ExternalTexturePixelGL::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;
}

ExternalTexturePixelGL::ExternalTexturePixelGL(
FlutterDesktopPixelBufferTextureCallback texture_callback,
void* user_data)
: ExternalTexture(),
texture_callback_(texture_callback),
user_data_(user_data) {}

bool ExternalTexturePixelGL::CopyPixelBuffer(size_t& width, size_t& height) {
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, &state_->gl_texture);
glBindTexture(GL_TEXTURE_2D, 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, 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;
}
34 changes: 34 additions & 0 deletions shell/platform/tizen/external_texture_pixel_gl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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_GL_H
#define EMBEDDER_EXTERNAL_TEXTURE_PIXEL_GL_H

#include <memory>

#include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/tizen/external_texture.h"

// An adaptation class of flutter engine and external texture interface.
class ExternalTexturePixelGL : public ExternalTexture {
public:
ExternalTexturePixelGL(
FlutterDesktopPixelBufferTextureCallback texture_callback,
void* user_data);

~ExternalTexturePixelGL() = 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;
};

#endif // EMBEDDER_EXTERNAL_TEXTURE_PIXEL_GL_H
Loading