Skip to content

Commit 7ef6a20

Browse files
xiaowei-guanswift-kim
authored andcommitted
Texture API change (#86)
* Add platfrom surface buffer structure * Support GPU buffer texture * Change file permission * Add FlutterDesktopGpuBufferTextureConfig in FlutterDesktopTextureInfo. * Add buffer parameter at Destruction callback * Change class name ExternalTextureGL to ExternalTextureSurfaceGL * Fix wild pointer issue * Convert unique_ptr to shared_ptr when create external texture * Fix arm64 build error
1 parent 9ad3ccf commit 7ef6a20

13 files changed

+434
-266
lines changed

shell/platform/tizen/BUILD.gn

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ source_set("flutter_engine") {
2626

2727
_public_headers = [
2828
"public/flutter_platform_view.h",
29-
"public/flutter_tizen_texture_registrar.h",
3029
"public/flutter_tizen.h",
3130
]
3231

@@ -95,9 +94,11 @@ template("embedder_for_profile") {
9594
"channels/platform_view_channel.cc",
9695
"channels/settings_channel.cc",
9796
"channels/text_input_channel.cc",
98-
"external_texture_gl.cc",
97+
"external_texture_pixel_gl.cc",
98+
"external_texture_surface_gl.cc",
9999
"flutter_tizen.cc",
100100
"flutter_tizen_engine.cc",
101+
"flutter_tizen_texture_registrar.cc",
101102
"key_event_handler.cc",
102103
"tizen_event_loop.cc",
103104
"tizen_log.cc",
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef EMBEDDER_EXTERNAL_TEXTURE_H_
6+
#define EMBEDDER_EXTERNAL_TEXTURE_H_
7+
8+
#include <atomic>
9+
#include <memory>
10+
#include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h"
11+
#include "flutter/shell/platform/embedder/embedder.h"
12+
13+
#ifdef TIZEN_RENDERER_EVAS_GL
14+
#undef EFL_BETA_API_SUPPORT
15+
#include <Evas_GL.h>
16+
#else
17+
#include <GLES2/gl2.h>
18+
#endif
19+
20+
struct ExternalTextureGLState {
21+
GLuint gl_texture;
22+
};
23+
24+
static std::atomic_long next_texture_id = {1};
25+
26+
// An adaptation class of flutter engine and external texture interface.
27+
class ExternalTexture : public std::enable_shared_from_this<ExternalTexture> {
28+
public:
29+
ExternalTexture()
30+
: state_(std::make_unique<ExternalTextureGLState>()),
31+
texture_id_(next_texture_id++) {}
32+
virtual ~ExternalTexture() = default;
33+
34+
/**
35+
* Returns the unique id for the ExternalTextureGL instance.
36+
*/
37+
int64_t TextureId() { return (int64_t)texture_id_; }
38+
39+
virtual bool PopulateTexture(size_t width,
40+
size_t height,
41+
FlutterOpenGLTexture* opengl_texture) = 0;
42+
virtual void OnDestruction(){};
43+
44+
protected:
45+
std::unique_ptr<ExternalTextureGLState> state_;
46+
const long texture_id_{0};
47+
};
48+
49+
#endif // EMBEDDER_EXTERNAL_TEXTURE_H_

shell/platform/tizen/external_texture_gl.h

-53
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/shell/platform/tizen/external_texture_pixel_gl.h"
6+
7+
#ifdef TIZEN_RENDERER_EVAS_GL
8+
#undef EFL_BETA_API_SUPPORT
9+
#include <Evas_GL_GLES3_Helpers.h>
10+
extern Evas_GL* g_evas_gl;
11+
EVAS_GL_GLOBAL_GLES3_DECLARE();
12+
#else
13+
#include <EGL/egl.h>
14+
#include <EGL/eglext.h>
15+
#include <GLES2/gl2ext.h>
16+
#include <GLES3/gl32.h>
17+
#endif
18+
19+
bool ExternalTexturePixelGL::PopulateTexture(
20+
size_t width,
21+
size_t height,
22+
FlutterOpenGLTexture* opengl_texture) {
23+
if (!CopyPixelBuffer(width, height)) {
24+
return false;
25+
}
26+
27+
// Populate the texture object used by the engine.
28+
opengl_texture->target = GL_TEXTURE_2D;
29+
opengl_texture->name = state_->gl_texture;
30+
opengl_texture->format = GL_RGBA8;
31+
opengl_texture->destruction_callback = nullptr;
32+
opengl_texture->user_data = nullptr;
33+
opengl_texture->width = width;
34+
opengl_texture->height = height;
35+
return true;
36+
}
37+
38+
ExternalTexturePixelGL::ExternalTexturePixelGL(
39+
FlutterDesktopPixelBufferTextureCallback texture_callback,
40+
void* user_data)
41+
: ExternalTexture(),
42+
texture_callback_(texture_callback),
43+
user_data_(user_data) {}
44+
45+
bool ExternalTexturePixelGL::CopyPixelBuffer(size_t& width, size_t& height) {
46+
const FlutterDesktopPixelBuffer* pixel_buffer =
47+
texture_callback_(width, height, user_data_);
48+
49+
if (!pixel_buffer || !pixel_buffer->buffer) {
50+
return false;
51+
}
52+
53+
width = pixel_buffer->width;
54+
height = pixel_buffer->height;
55+
56+
if (state_->gl_texture == 0) {
57+
glGenTextures(1, &state_->gl_texture);
58+
glBindTexture(GL_TEXTURE_2D, state_->gl_texture);
59+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
60+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
61+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
62+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
63+
} else {
64+
glBindTexture(GL_TEXTURE_2D, state_->gl_texture);
65+
}
66+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width,
67+
pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
68+
pixel_buffer->buffer);
69+
return true;
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef EMBEDDER_EXTERNAL_TEXTURE_PIXEL_GL_H
6+
#define EMBEDDER_EXTERNAL_TEXTURE_PIXEL_GL_H
7+
8+
#include <memory>
9+
10+
#include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h"
11+
#include "flutter/shell/platform/embedder/embedder.h"
12+
#include "flutter/shell/platform/tizen/external_texture.h"
13+
14+
// An adaptation class of flutter engine and external texture interface.
15+
class ExternalTexturePixelGL : public ExternalTexture {
16+
public:
17+
ExternalTexturePixelGL(
18+
FlutterDesktopPixelBufferTextureCallback texture_callback,
19+
void* user_data);
20+
21+
~ExternalTexturePixelGL() = default;
22+
23+
bool PopulateTexture(size_t width,
24+
size_t height,
25+
FlutterOpenGLTexture* opengl_texture) override;
26+
27+
bool CopyPixelBuffer(size_t& width, size_t& height);
28+
29+
private:
30+
FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr;
31+
void* user_data_ = nullptr;
32+
};
33+
34+
#endif // EMBEDDER_EXTERNAL_TEXTURE_PIXEL_GL_H

0 commit comments

Comments
 (0)