|
| 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 "external_texture_pixel_evas_gl.h" |
| 6 | + |
| 7 | +#include "tizen_evas_gl_helper.h" |
| 8 | +extern Evas_GL* g_evas_gl; |
| 9 | +EVAS_GL_GLOBAL_GLES2_DECLARE(); |
| 10 | + |
| 11 | +namespace flutter { |
| 12 | + |
| 13 | +bool ExternalTexturePixelEvasGL::PopulateTexture( |
| 14 | + size_t width, |
| 15 | + size_t height, |
| 16 | + FlutterOpenGLTexture* opengl_texture) { |
| 17 | + if (!CopyPixelBuffer(width, height)) { |
| 18 | + return false; |
| 19 | + } |
| 20 | + |
| 21 | + // Populate the texture object used by the engine. |
| 22 | + opengl_texture->target = GL_TEXTURE_2D; |
| 23 | + opengl_texture->name = state_->gl_texture; |
| 24 | + opengl_texture->format = GL_RGBA8; |
| 25 | + opengl_texture->destruction_callback = nullptr; |
| 26 | + opengl_texture->user_data = nullptr; |
| 27 | + opengl_texture->width = width; |
| 28 | + opengl_texture->height = height; |
| 29 | + return true; |
| 30 | +} |
| 31 | + |
| 32 | +ExternalTexturePixelEvasGL::ExternalTexturePixelEvasGL( |
| 33 | + FlutterDesktopPixelBufferTextureCallback texture_callback, |
| 34 | + void* user_data) |
| 35 | + : ExternalTexture(), |
| 36 | + texture_callback_(texture_callback), |
| 37 | + user_data_(user_data) {} |
| 38 | + |
| 39 | +bool ExternalTexturePixelEvasGL::CopyPixelBuffer(size_t& width, |
| 40 | + size_t& height) { |
| 41 | + if (!texture_callback_) { |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + const FlutterDesktopPixelBuffer* pixel_buffer = |
| 46 | + texture_callback_(width, height, user_data_); |
| 47 | + |
| 48 | + if (!pixel_buffer || !pixel_buffer->buffer) { |
| 49 | + return false; |
| 50 | + } |
| 51 | + |
| 52 | + width = pixel_buffer->width; |
| 53 | + height = pixel_buffer->height; |
| 54 | + |
| 55 | + if (state_->gl_texture == 0) { |
| 56 | + glGenTextures(1, static_cast<GLuint*>(&state_->gl_texture)); |
| 57 | + glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(state_->gl_texture)); |
| 58 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); |
| 59 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); |
| 60 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 61 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 62 | + } else { |
| 63 | + glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(state_->gl_texture)); |
| 64 | + } |
| 65 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, |
| 66 | + pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 67 | + pixel_buffer->buffer); |
| 68 | + return true; |
| 69 | +} |
| 70 | + |
| 71 | +} // namespace flutter |
0 commit comments