| Flutter Linux Embedder |

fl_texture_gl_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
5 #include "flutter/shell/platform/linux/fl_texture_gl_private.h"
6 #include "flutter/shell/platform/linux/fl_texture_private.h"
7 #include "flutter/shell/platform/linux/fl_texture_registrar_private.h"
8 #include "flutter/shell/platform/linux/public/flutter_linux/fl_texture.h"
9 #include "flutter/shell/platform/linux/public/flutter_linux/fl_texture_registrar.h"
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(FlTestTexture,
21 fl_test_texture,
22 FL,
23 TEST_TEXTURE,
24 FlTextureGL)
25
26 /// A simple texture.
27 struct _FlTestTexture {
28 FlTextureGL parent_instance;
29 };
30
31 G_DEFINE_TYPE(FlTestTexture, fl_test_texture, fl_texture_gl_get_type())
32
33 static gboolean fl_test_texture_populate(FlTextureGL* texture,
34 uint32_t* target,
35 uint32_t* name,
36 uint32_t* width,
37 uint32_t* height,
38 GError** error) {
39 EXPECT_TRUE(FL_IS_TEST_TEXTURE(texture));
40
41 EXPECT_EQ(*width, kBufferWidth);
42 EXPECT_EQ(*height, kBufferHeight);
43 *target = GL_TEXTURE_2D;
44 *name = 1;
45 *width = kRealBufferWidth;
46 *height = kRealBufferHeight;
47
48 return TRUE;
49 }
50
51 static void fl_test_texture_class_init(FlTestTextureClass* klass) {
52 FL_TEXTURE_GL_CLASS(klass)->populate = fl_test_texture_populate;
53 }
54
55 static void fl_test_texture_init(FlTestTexture* self) {}
56
57 static FlTestTexture* fl_test_texture_new() {
58 return FL_TEST_TEXTURE(g_object_new(fl_test_texture_get_type(), nullptr));
59 }
60
61 // Test that getting the texture ID works.
62 TEST(FlTextureGLTest, TextureID) {
63 g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_texture_new());
64 fl_texture_set_id(texture, 42);
65 EXPECT_EQ(fl_texture_get_id(texture), static_cast<int64_t>(42));
66 }
67
68 // Test that populating an OpenGL texture works.
69 TEST(FlTextureGLTest, PopulateTexture) {
70 g_autoptr(FlTextureGL) texture = FL_TEXTURE_GL(fl_test_texture_new());
71 FlutterOpenGLTexture opengl_texture = {0};
72 g_autoptr(GError) error = nullptr;
73 EXPECT_TRUE(fl_texture_gl_populate(texture, kBufferWidth, kBufferHeight,
74 &opengl_texture, &error));
75 EXPECT_EQ(error, nullptr);
76 EXPECT_EQ(opengl_texture.width, kRealBufferWidth);
77 EXPECT_EQ(opengl_texture.height, kRealBufferHeight);
78 }
G_DECLARE_FINAL_TYPE
G_DECLARE_FINAL_TYPE(FlTestTexture, fl_test_texture, FL, TEST_TEXTURE, FlTextureGL) struct _FlTestTexture
A simple texture.
Definition: fl_texture_gl_test.cc:20
fl_texture_gl_private.h
kBufferHeight
static constexpr uint32_t kBufferHeight
Definition: fl_texture_gl_test.cc:16
fl_test_texture_populate
static gboolean fl_test_texture_populate(FlTextureGL *texture, uint32_t *target, uint32_t *name, uint32_t *width, uint32_t *height, GError **error)
Definition: fl_texture_gl_test.cc:33
fl_test_texture_class_init
static void fl_test_texture_class_init(FlTestTextureClass *klass)
Definition: fl_texture_gl_test.cc:51
fl_texture_set_id
void fl_texture_set_id(FlTexture *self, int64_t id)
Definition: fl_texture.cc:15
fl_test_texture_init
static void fl_test_texture_init(FlTestTexture *self)
Definition: fl_texture_gl_test.cc:55
fl_texture_registrar.h
G_DEFINE_TYPE
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
Definition: fl_basic_message_channel.cc:37
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
kBufferWidth
static constexpr uint32_t kBufferWidth
Definition: fl_texture_gl_test.cc:15
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
fl_texture_gl_populate
gboolean fl_texture_gl_populate(FlTextureGL *self, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
Definition: fl_texture_gl.cc:50
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_texture_private.h
target
uint32_t * target
Definition: fl_texture_registrar_test.cc:40
kRealBufferHeight
static constexpr uint32_t kRealBufferHeight
Definition: fl_texture_gl_test.cc:18
fl_texture_registrar_private.h
fl_texture.h
TEST
TEST(FlTextureGLTest, TextureID)
Definition: fl_texture_gl_test.cc:62
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
fl_test_texture_new
static FlTestTexture * fl_test_texture_new()
Definition: fl_texture_gl_test.cc:57
kRealBufferWidth
static constexpr uint32_t kRealBufferWidth
Definition: fl_texture_gl_test.cc:17