Flutter Engine
The Flutter Engine
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
15static constexpr uint32_t kBufferWidth = 4u;
16static constexpr uint32_t kBufferHeight = 4u;
17static constexpr uint32_t kRealBufferWidth = 2u;
18static constexpr uint32_t kRealBufferHeight = 2u;
19
21 fl_test_texture,
22 FL,
23 TEST_TEXTURE,
24 FlTextureGL)
25
26/// A simple texture.
27struct _FlTestTexture {
28 FlTextureGL parent_instance;
29};
30
31G_DEFINE_TYPE(FlTestTexture, fl_test_texture, fl_texture_gl_get_type())
32
33static 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;
47
48 return TRUE;
49}
50
51static void fl_test_texture_class_init(FlTestTextureClass* klass) {
52 FL_TEXTURE_GL_CLASS(klass)->populate = fl_test_texture_populate;
53}
54
55static void fl_test_texture_init(FlTestTexture* self) {}
56
57static 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.
62TEST(FlTextureGLTest, TextureID) {
63 g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_texture_new());
65 EXPECT_EQ(fl_texture_get_id(texture), static_cast<int64_t>(42));
66}
67
68// Test that populating an OpenGL texture works.
69TEST(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;
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_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
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)
TEST(FlTextureGLTest, TextureID)
static constexpr uint32_t kBufferWidth
G_DECLARE_FINAL_TYPE(FlTestTexture, fl_test_texture, FL, TEST_TEXTURE, FlTextureGL) struct _FlTestTexture
A simple texture.
static FlTestTexture * fl_test_texture_new()
static constexpr uint32_t kRealBufferHeight
static void fl_test_texture_class_init(FlTestTextureClass *klass)
static constexpr uint32_t kBufferHeight
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)
uint32_t * target
FlTexture * texture
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
int32_t height
int32_t width
size_t height
Height of the texture.
Definition: embedder.h:386
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678