Flutter Linux Embedder
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 
10 #include "flutter/shell/platform/linux/testing/fl_test.h"
11 #include "gtest/gtest.h"
12 
13 #include <epoxy/gl.h>
14 
15 static constexpr uint32_t kBufferWidth = 4u;
16 static constexpr uint32_t kBufferHeight = 4u;
17 static constexpr uint32_t kRealBufferWidth = 2u;
18 static constexpr uint32_t kRealBufferHeight = 2u;
19 
20 G_DECLARE_FINAL_TYPE(FlTestPixelBufferTexture,
21  fl_test_pixel_buffer_texture,
22  FL,
23  TEST_PIXEL_BUFFER_TEXTURE,
24  FlPixelBufferTexture)
25 
26 /// A simple texture with fixed contents.
27 struct _FlTestPixelBufferTexture {
28  FlPixelBufferTexture parent_instance;
29 };
30 
31 G_DEFINE_TYPE(FlTestPixelBufferTexture,
32  fl_test_pixel_buffer_texture,
33  fl_pixel_buffer_texture_get_type())
34 
35 static gboolean fl_test_pixel_buffer_texture_copy_pixels(
36  FlPixelBufferTexture* texture,
37  const uint8_t** out_buffer,
38  uint32_t* width,
39  uint32_t* height,
40  GError** error) {
41  EXPECT_TRUE(FL_IS_TEST_PIXEL_BUFFER_TEXTURE(texture));
42 
43  // RGBA
44  static const uint8_t buffer[] = {0x0a, 0x1a, 0x2a, 0x3a, 0x4a, 0x5a,
45  0x6a, 0x7a, 0x8a, 0x9a, 0xaa, 0xba,
46  0xca, 0xda, 0xea, 0xfa};
47  EXPECT_EQ(*width, kBufferWidth);
48  EXPECT_EQ(*height, kBufferHeight);
49  *out_buffer = buffer;
52 
53  return TRUE;
54 }
55 
57  FlTestPixelBufferTextureClass* klass) {
58  FL_PIXEL_BUFFER_TEXTURE_CLASS(klass)->copy_pixels =
59  fl_test_pixel_buffer_texture_copy_pixels;
60 }
61 
62 static void fl_test_pixel_buffer_texture_init(FlTestPixelBufferTexture* self) {}
63 
64 static FlTestPixelBufferTexture* fl_test_pixel_buffer_texture_new() {
65  return FL_TEST_PIXEL_BUFFER_TEXTURE(
66  g_object_new(fl_test_pixel_buffer_texture_get_type(), nullptr));
67 }
68 
69 // Test that getting the texture ID works.
70 TEST(FlPixelBufferTextureTest, TextureID) {
71  g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_pixel_buffer_texture_new());
72  fl_texture_set_id(texture, 42);
73  EXPECT_EQ(fl_texture_get_id(texture), static_cast<int64_t>(42));
74 }
75 
76 // Test that populating an OpenGL texture works.
77 TEST(FlPixelBufferTextureTest, PopulateTexture) {
78  g_autoptr(FlPixelBufferTexture) texture =
79  FL_PIXEL_BUFFER_TEXTURE(fl_test_pixel_buffer_texture_new());
80  FlutterOpenGLTexture opengl_texture = {0};
81  g_autoptr(GError) error = nullptr;
83  texture, kBufferWidth, kBufferHeight, &opengl_texture, &error));
84  EXPECT_EQ(error, nullptr);
85  EXPECT_EQ(opengl_texture.width, kRealBufferWidth);
86  EXPECT_EQ(opengl_texture.height, kRealBufferHeight);
87 }
kRealBufferWidth
static constexpr uint32_t kRealBufferWidth
Definition: fl_pixel_buffer_texture_test.cc:17
kBufferWidth
static constexpr uint32_t kBufferWidth
Definition: fl_pixel_buffer_texture_test.cc:15
fl_pixel_buffer_texture.h
fl_test_pixel_buffer_texture_new
static FlTestPixelBufferTexture * fl_test_pixel_buffer_texture_new()
Definition: fl_pixel_buffer_texture_test.cc:64
kBufferHeight
static constexpr uint32_t kBufferHeight
Definition: fl_pixel_buffer_texture_test.cc:16
fl_texture_set_id
void fl_texture_set_id(FlTexture *self, int64_t id)
Definition: fl_texture.cc:15
kRealBufferHeight
static constexpr uint32_t kRealBufferHeight
Definition: fl_pixel_buffer_texture_test.cc:18
G_DEFINE_TYPE
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
G_DECLARE_FINAL_TYPE
G_DECLARE_FINAL_TYPE(FlTestPixelBufferTexture, fl_test_pixel_buffer_texture, FL, TEST_PIXEL_BUFFER_TEXTURE, FlPixelBufferTexture) struct _FlTestPixelBufferTexture
A simple texture with fixed contents.
Definition: fl_pixel_buffer_texture_test.cc:20
TEST
TEST(FlPixelBufferTextureTest, TextureID)
Definition: fl_pixel_buffer_texture_test.cc:70
out_buffer
const uint8_t ** out_buffer
Definition: fl_pixel_buffer_texture_test.cc:37
fl_pixel_buffer_texture_populate
gboolean fl_pixel_buffer_texture_populate(FlPixelBufferTexture *texture, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
Definition: fl_pixel_buffer_texture.cc:71
fl_test_pixel_buffer_texture_init
static void fl_test_pixel_buffer_texture_init(FlTestPixelBufferTexture *self)
Definition: fl_pixel_buffer_texture_test.cc:62
fl_texture_registrar.h
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_texture_get_id
G_MODULE_EXPORT int64_t fl_texture_get_id(FlTexture *self)
Definition: fl_texture.cc:20
FL
FL
Definition: fl_binary_messenger.cc:27
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
fl_pixel_buffer_texture_private.h
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_texture_private.h
fl_test_pixel_buffer_texture_class_init
static void fl_test_pixel_buffer_texture_class_init(FlTestPixelBufferTextureClass *klass)
Definition: fl_pixel_buffer_texture_test.cc:56
fl_texture_registrar_private.h
buffer
static const uint8_t buffer[]
Definition: fl_pixel_buffer_texture_test.cc:44
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38