Flutter Engine
The Flutter Engine
mock_texture_registrar.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/testing/mock_texture_registrar.h"
6
9 FlTexture* texture;
11};
12
14 FlTextureRegistrarInterface* iface);
15
17 FlMockTextureRegistrar,
18 fl_mock_texture_registrar,
19 G_TYPE_OBJECT,
20 G_IMPLEMENT_INTERFACE(fl_texture_registrar_get_type(),
22
23static gboolean register_texture(FlTextureRegistrar* registrar,
24 FlTexture* texture) {
25 FlMockTextureRegistrar* self = FL_MOCK_TEXTURE_REGISTRAR(registrar);
26 if (self->texture != nullptr) {
27 return FALSE;
28 }
29 self->texture = FL_TEXTURE(g_object_ref(texture));
30 return TRUE;
31}
32
33static FlTexture* lookup_texture(FlTextureRegistrar* registrar,
34 int64_t texture_id) {
35 FlMockTextureRegistrar* self = FL_MOCK_TEXTURE_REGISTRAR(registrar);
36 if (self->texture != nullptr &&
37 fl_texture_get_id(self->texture) == texture_id) {
38 return self->texture;
39 }
40 return nullptr;
41}
42
43static gboolean mark_texture_frame_available(FlTextureRegistrar* registrar,
44 FlTexture* texture) {
45 FlMockTextureRegistrar* self = FL_MOCK_TEXTURE_REGISTRAR(registrar);
46 if (lookup_texture(registrar, fl_texture_get_id(texture)) == nullptr) {
47 return FALSE;
48 }
49 self->frame_available = TRUE;
50 return TRUE;
51}
52
53static gboolean unregister_texture(FlTextureRegistrar* registrar,
54 FlTexture* texture) {
55 FlMockTextureRegistrar* self = FL_MOCK_TEXTURE_REGISTRAR(registrar);
56 if (self->texture != texture) {
57 return FALSE;
58 }
59
60 g_clear_object(&self->texture);
61
62 return TRUE;
63}
64
66 FlTextureRegistrarInterface* iface) {
67 iface->register_texture = register_texture;
68 iface->lookup_texture = lookup_texture;
69 iface->mark_texture_frame_available = mark_texture_frame_available;
70 iface->unregister_texture = unregister_texture;
71}
72
73static void fl_mock_texture_registrar_dispose(GObject* object) {
74 FlMockTextureRegistrar* self = FL_MOCK_TEXTURE_REGISTRAR(object);
75 g_clear_object(&self->texture);
76 G_OBJECT_CLASS(fl_mock_texture_registrar_parent_class)->dispose(object);
77}
78
80 FlMockTextureRegistrarClass* klass) {
81 G_OBJECT_CLASS(klass)->dispose = fl_mock_texture_registrar_dispose;
82}
83
84static void fl_mock_texture_registrar_init(FlMockTextureRegistrar* self) {}
85
86FlMockTextureRegistrar* fl_mock_texture_registrar_new() {
87 return FL_MOCK_TEXTURE_REGISTRAR(
88 g_object_new(fl_mock_texture_registrar_get_type(), nullptr));
89}
90
91FlTexture* fl_mock_texture_registrar_get_texture(FlMockTextureRegistrar* self) {
92 return self->texture;
93}
94
96 FlMockTextureRegistrar* self) {
97 return self->frame_available;
98}
G_MODULE_EXPORT int64_t fl_texture_get_id(FlTexture *self)
Definition: fl_texture.cc:20
static gboolean register_texture(FlTextureRegistrar *registrar, FlTexture *texture)
return FALSE
FlTexture * fl_mock_texture_registrar_get_texture(FlMockTextureRegistrar *self)
static gboolean mark_texture_frame_available(FlTextureRegistrar *registrar, FlTexture *texture)
FlTexture * texture
static void fl_mock_texture_registrar_dispose(GObject *object)
static void fl_mock_texture_registrar_class_init(FlMockTextureRegistrarClass *klass)
static void fl_mock_texture_registrar_iface_init(FlTextureRegistrarInterface *iface)
return TRUE
static void fl_mock_texture_registrar_init(FlMockTextureRegistrar *self)
static FlTexture * lookup_texture(FlTextureRegistrar *registrar, int64_t texture_id)
FlMockTextureRegistrar * fl_mock_texture_registrar_new()
G_DEFINE_TYPE_WITH_CODE(FlMockTextureRegistrar, fl_mock_texture_registrar, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(fl_texture_registrar_get_type(), fl_mock_texture_registrar_iface_init)) static gboolean register_texture(FlTextureRegistrar *registrar
static gboolean unregister_texture(FlTextureRegistrar *registrar, FlTexture *texture)
gboolean fl_mock_texture_registrar_get_frame_available(FlMockTextureRegistrar *self)
int64_t texture_id