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 
10 #include "flutter/shell/platform/linux/testing/fl_test.h"
11 #include "flutter/shell/platform/linux/testing/linux_test.h"
12 #include "gtest/gtest.h"
13 
14 #include <epoxy/gl.h>
15 
16 static constexpr uint32_t kBufferWidth = 4u;
17 static constexpr uint32_t kBufferHeight = 4u;
18 static constexpr uint32_t kRealBufferWidth = 2u;
19 static constexpr uint32_t kRealBufferHeight = 2u;
20 
21 G_DECLARE_FINAL_TYPE(FlTestTexture,
22  fl_test_texture,
23  FL,
24  TEST_TEXTURE,
25  FlTextureGL)
26 
27 /// A simple texture.
28 struct _FlTestTexture {
29  FlTextureGL parent_instance;
30 };
31 
32 G_DEFINE_TYPE(FlTestTexture, fl_test_texture, fl_texture_gl_get_type())
33 
34 static gboolean fl_test_texture_populate(FlTextureGL* texture,
35  uint32_t* target,
36  uint32_t* name,
37  uint32_t* width,
38  uint32_t* height,
39  GError** error) {
40  EXPECT_TRUE(FL_IS_TEST_TEXTURE(texture));
41 
42  EXPECT_EQ(*width, kBufferWidth);
43  EXPECT_EQ(*height, kBufferHeight);
44  *target = GL_TEXTURE_2D;
45  *name = 1;
48 
49  return TRUE;
50 }
51 
52 static void fl_test_texture_class_init(FlTestTextureClass* klass) {
53  FL_TEXTURE_GL_CLASS(klass)->populate = fl_test_texture_populate;
54 }
55 
56 static void fl_test_texture_init(FlTestTexture* self) {}
57 
58 static FlTestTexture* fl_test_texture_new() {
59  return FL_TEST_TEXTURE(g_object_new(fl_test_texture_get_type(), nullptr));
60 }
61 
62 class FlTextureGLTest : public flutter::testing::LinuxTest {
63  protected:
64  void SetUp() override { texture = FL_TEXTURE_GL(fl_test_texture_new()); }
65 
66  ~FlTextureGLTest() { g_clear_object(&texture); }
67 
68  FlTextureGL* texture = nullptr;
69 };
70 
71 // Test that getting the texture ID works.
72 TEST_F(FlTextureGLTest, TextureID) {
73  fl_texture_set_id(FL_TEXTURE(texture), 42);
74  EXPECT_EQ(fl_texture_get_id(FL_TEXTURE(texture)), static_cast<int64_t>(42));
75 }
76 
77 // Test that populating an OpenGL texture works.
78 TEST_F(FlTextureGLTest, PopulateTexture) {
79  FlutterOpenGLTexture opengl_texture = {0};
80  g_autoptr(GError) error = nullptr;
82  &opengl_texture, &error));
83  EXPECT_EQ(error, nullptr);
84  EXPECT_EQ(opengl_texture.width, kRealBufferWidth);
85  EXPECT_EQ(opengl_texture.height, kRealBufferHeight);
86 }
FlTextureGL * texture
void SetUp() override
g_autoptr(FlEngine) engine
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
FlFramebuffer double double int int height
FlFramebuffer double double int width
return TRUE
const uint8_t uint32_t uint32_t GError ** error
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
gboolean fl_texture_gl_populate(FlTextureGL *self, uint32_t width, uint32_t height, FlutterOpenGLTexture *opengl_texture, GError **error)
static constexpr uint32_t kBufferWidth
G_DECLARE_FINAL_TYPE(FlTestTexture, fl_test_texture, FL, TEST_TEXTURE, FlTextureGL) struct _FlTestTexture
A simple texture.
static constexpr uint32_t kRealBufferHeight
static void fl_test_texture_class_init(FlTestTextureClass *klass)
static constexpr uint32_t kBufferHeight
TEST_F(FlTextureGLTest, TextureID)
static constexpr uint32_t kRealBufferWidth
static gboolean fl_test_texture_populate(FlTextureGL *texture, uint32_t *target, uint32_t *name, uint32_t *width, uint32_t *height, GError **error)
static void fl_test_texture_init(FlTestTexture *self)
static FlTestTexture * fl_test_texture_new()
uint32_t * target