| Flutter Windows Embedder |

external_texture_pixelbuffer.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. 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/windows/external_texture_pixelbuffer.h"
6
7 namespace flutter {
8
9 ExternalTexturePixelBuffer::ExternalTexturePixelBuffer(
10 const FlutterDesktopPixelBufferTextureCallback texture_callback,
11 void* user_data,
12 std::shared_ptr<egl::ProcTable> gl)
13 : texture_callback_(texture_callback),
14 user_data_(user_data),
15 gl_(std::move(gl)) {}
16
17 ExternalTexturePixelBuffer::~ExternalTexturePixelBuffer() {
18 if (gl_texture_ != 0) {
19 gl_->DeleteTextures(1, &gl_texture_);
20 }
21 }
22
23 bool ExternalTexturePixelBuffer::PopulateTexture(
24 size_t width,
25 size_t height,
26 FlutterOpenGLTexture* opengl_texture) {
27 if (!CopyPixelBuffer(width, height)) {
28 return false;
29 }
30
31 // Populate the texture object used by the engine.
32 opengl_texture->target = GL_TEXTURE_2D;
33 opengl_texture->name = gl_texture_;
34 opengl_texture->format = GL_RGBA8_OES;
35 opengl_texture->destruction_callback = nullptr;
36 opengl_texture->user_data = nullptr;
37 opengl_texture->width = width;
38 opengl_texture->height = height;
39
40 return true;
41 }
42
43 bool ExternalTexturePixelBuffer::CopyPixelBuffer(size_t& width,
44 size_t& height) {
45 const FlutterDesktopPixelBuffer* pixel_buffer =
46 texture_callback_(width, height, user_data_);
47 if (!pixel_buffer || !pixel_buffer->buffer) {
48 return false;
49 }
50 width = pixel_buffer->width;
51 height = pixel_buffer->height;
52
53 if (gl_texture_ == 0) {
54 gl_->GenTextures(1, &gl_texture_);
55
56 gl_->BindTexture(GL_TEXTURE_2D, gl_texture_);
57 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
58 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
59 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
60 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
61
62 } else {
63 gl_->BindTexture(GL_TEXTURE_2D, gl_texture_);
64 }
65 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width,
66 pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
67 pixel_buffer->buffer);
68 if (pixel_buffer->release_callback) {
69 pixel_buffer->release_callback(pixel_buffer->release_context);
70 }
71 return true;
72 }
73
74 } // namespace flutter
external_texture_pixelbuffer.h
flutter::ExternalTexturePixelBuffer::PopulateTexture
bool PopulateTexture(size_t width, size_t height, FlutterOpenGLTexture *opengl_texture) override
Definition: external_texture_pixelbuffer.cc:23
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:53
FlutterDesktopPixelBuffer
Definition: flutter_texture_registrar.h:56
FlutterDesktopPixelBuffer::release_context
void * release_context
Definition: flutter_texture_registrar.h:66
flutter
Definition: accessibility_bridge_windows.cc:11
FlutterDesktopPixelBufferTextureCallback
const typedef FlutterDesktopPixelBuffer *(* FlutterDesktopPixelBufferTextureCallback)(size_t width, size_t height, void *user_data)
Definition: flutter_texture_registrar.h:116
FlutterDesktopPixelBuffer::buffer
const uint8_t * buffer
Definition: flutter_texture_registrar.h:58
flutter::ExternalTexturePixelBuffer::ExternalTexturePixelBuffer
ExternalTexturePixelBuffer(const FlutterDesktopPixelBufferTextureCallback texture_callback, void *user_data, std::shared_ptr< egl::ProcTable > gl)
Definition: external_texture_pixelbuffer.cc:9
FlutterDesktopPixelBuffer::width
size_t width
Definition: flutter_texture_registrar.h:60
flutter::ExternalTexturePixelBuffer::~ExternalTexturePixelBuffer
virtual ~ExternalTexturePixelBuffer()
Definition: external_texture_pixelbuffer.cc:17
FlutterDesktopPixelBuffer::release_callback
void(* release_callback)(void *release_context)
Definition: flutter_texture_registrar.h:64
FlutterDesktopPixelBuffer::height
size_t height
Definition: flutter_texture_registrar.h:62
texture_callback
FlutterDesktopPixelBufferTextureCallback texture_callback
Definition: texture_registrar_unittests.cc:26