Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
fl_pixel_buffer_texture_test.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
12#include "gtest/gtest.h"
13
14#include <epoxy/gl.h>
15
16static constexpr uint32_t kBufferWidth = 4u;
17static constexpr uint32_t kBufferHeight = 4u;
18static constexpr uint32_t kRealBufferWidth = 2u;
19static constexpr uint32_t kRealBufferHeight = 2u;
20
21G_DECLARE_FINAL_TYPE(FlTestPixelBufferTexture,
22 fl_test_pixel_buffer_texture,
23 FL,
24 TEST_PIXEL_BUFFER_TEXTURE,
25 FlPixelBufferTexture)
26
27/// A simple texture with fixed contents.
28struct _FlTestPixelBufferTexture {
29 FlPixelBufferTexture parent_instance;
30};
31
32G_DEFINE_TYPE(FlTestPixelBufferTexture,
33 fl_test_pixel_buffer_texture,
34 fl_pixel_buffer_texture_get_type())
35
36static gboolean fl_test_pixel_buffer_texture_copy_pixels(
37 FlPixelBufferTexture* texture,
38 const uint8_t** out_buffer,
39 uint32_t* width,
40 uint32_t* height,
41 GError** error) {
42 EXPECT_TRUE(FL_IS_TEST_PIXEL_BUFFER_TEXTURE(texture));
43
44 // RGBA
45 static const uint8_t buffer[] = {0x0a, 0x1a, 0x2a, 0x3a, 0x4a, 0x5a,
46 0x6a, 0x7a, 0x8a, 0x9a, 0xaa, 0xba,
47 0xca, 0xda, 0xea, 0xfa};
48 EXPECT_EQ(*width, kBufferWidth);
49 EXPECT_EQ(*height, kBufferHeight);
53
54 return TRUE;
55}
56
58 FlTestPixelBufferTextureClass* klass) {
59 FL_PIXEL_BUFFER_TEXTURE_CLASS(klass)->copy_pixels =
60 fl_test_pixel_buffer_texture_copy_pixels;
61}
62
63static void fl_test_pixel_buffer_texture_init(FlTestPixelBufferTexture* self) {}
64
65static FlTestPixelBufferTexture* fl_test_pixel_buffer_texture_new() {
66 return FL_TEST_PIXEL_BUFFER_TEXTURE(
67 g_object_new(fl_test_pixel_buffer_texture_get_type(), nullptr));
68}
69
71 protected:
72 void SetUp() override {
73 texture = FL_PIXEL_BUFFER_TEXTURE(fl_test_pixel_buffer_texture_new());
74 }
75
76 ~FlPixelBufferTextureTest() { g_clear_object(&texture); }
77
78 FlPixelBufferTexture* texture = nullptr;
79};
80
81// Test that getting the texture ID works.
83 fl_texture_set_id(FL_TEXTURE(texture), 42);
84 EXPECT_EQ(fl_texture_get_id(FL_TEXTURE(texture)), static_cast<int64_t>(42));
85}
86
87// Test that populating an OpenGL texture works.
89 FlutterOpenGLTexture opengl_texture = {0};
90 g_autoptr(GError) error = nullptr;
92 texture, kBufferWidth, kBufferHeight, &opengl_texture, &error));
93 EXPECT_EQ(error, nullptr);
94 EXPECT_EQ(opengl_texture.width, kRealBufferWidth);
95 EXPECT_EQ(opengl_texture.height, kRealBufferHeight);
96}
g_autoptr(FlEngine) engine
gboolean fl_pixel_buffer_texture_populate(FlPixelBufferTexture *texture, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
static void fl_test_pixel_buffer_texture_init(FlTestPixelBufferTexture *self)
static constexpr uint32_t kBufferWidth
const uint8_t uint32_t uint32_t * height
G_DEFINE_TYPE(FlTestPixelBufferTexture, fl_test_pixel_buffer_texture, fl_pixel_buffer_texture_get_type()) static gboolean fl_test_pixel_buffer_texture_copy_pixels(FlPixelBufferTexture *texture
const uint8_t uint32_t * width
static FlTestPixelBufferTexture * fl_test_pixel_buffer_texture_new()
static constexpr uint32_t kRealBufferHeight
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
static constexpr uint32_t kBufferHeight
const uint8_t ** out_buffer
G_DECLARE_FINAL_TYPE(FlTestPixelBufferTexture, fl_test_pixel_buffer_texture, FL, TEST_PIXEL_BUFFER_TEXTURE, FlPixelBufferTexture) struct _FlTestPixelBufferTexture
A simple texture with fixed contents.
TEST_F(FlPixelBufferTextureTest, TextureID)
static constexpr uint32_t kRealBufferWidth
static void fl_test_pixel_buffer_texture_class_init(FlTestPixelBufferTextureClass *klass)
G_MODULE_EXPORT int64_t fl_texture_get_id(FlTexture *self)
Definition fl_texture.cc:20
void fl_texture_set_id(FlTexture *self, int64_t id)
Definition fl_texture.cc:15
FlTexture * texture
size_t height
Height of the texture.
Definition embedder.h:536