Flutter Engine
The Flutter Engine
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
7namespace flutter {
8
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
18 if (gl_texture_ != 0) {
19 gl_->DeleteTextures(1, &gl_texture_);
20 }
21}
22
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
43bool 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
bool PopulateTexture(size_t width, size_t height, FlutterOpenGLTexture *opengl_texture) override
ExternalTexturePixelBuffer(const FlutterDesktopPixelBufferTextureCallback texture_callback, void *user_data, std::shared_ptr< egl::ProcTable > gl)
const FlutterDesktopPixelBuffer *(* FlutterDesktopPixelBufferTextureCallback)(size_t width, size_t height, void *user_data)
gl
Definition: malisc.py:41
Definition: ref_ptr.h:256
int32_t height
int32_t width
void(* release_callback)(void *release_context)
uint32_t name
The name of the texture.
Definition: embedder.h:371
VoidCallback destruction_callback
Definition: embedder.h:378
void * user_data
User data to be returned on the invocation of the destruction callback.
Definition: embedder.h:375
size_t height
Height of the texture.
Definition: embedder.h:386
uint32_t format
The texture format (example GL_RGBA8).
Definition: embedder.h:373
void * user_data
FlutterDesktopPixelBufferTextureCallback texture_callback