|
| 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 | +} |
0 commit comments