Flutter Engine
Loading...
Searching...
No Matches
typed_list.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 "
tonic/typed_data/typed_list.h
"
6
7
#include <cstring>
8
9
#include "
tonic/logging/dart_error.h
"
10
11
namespace
tonic
{
12
13
template
<Dart_TypedData_Type kTypeName,
typename
ElemType>
14
TypedList<kTypeName, ElemType>::TypedList
()
15
: data_(nullptr), num_elements_(0), dart_handle_(nullptr) {}
16
17
template
<Dart_TypedData_Type kTypeName,
typename
ElemType>
18
TypedList<kTypeName, ElemType>::TypedList
(Dart_Handle list)
19
: data_(nullptr), num_elements_(0), dart_handle_(list) {
20
if
(Dart_IsNull(list))
21
return
;
22
23
Dart_TypedData_Type
type
;
24
Dart_TypedDataAcquireData(list, &
type
,
reinterpret_cast<
void
**
>
(&data_),
25
&num_elements_);
26
TONIC_DCHECK
(!
CheckAndHandleError
(list));
27
if
(
type
!= kTypeName)
28
Dart_ThrowException(
ToDart
(
"Non-genuine TypedData passed to engine."
));
29
}
30
31
template
<Dart_TypedData_Type kTypeName,
typename
ElemType>
32
TypedList<kTypeName, ElemType>::TypedList
(
33
TypedList<kTypeName, ElemType>
&& other)
34
: data_(other.data_),
35
num_elements_(other.num_elements_),
36
dart_handle_(other.dart_handle_) {
37
other.data_ =
nullptr
;
38
other.num_elements_ = 0;
39
other.dart_handle_ =
nullptr
;
40
}
41
42
template
<Dart_TypedData_Type kTypeName,
typename
ElemType>
43
TypedList<kTypeName, ElemType>::~TypedList
() {
44
Release();
45
}
46
47
template
<Dart_TypedData_Type kTypeName,
typename
ElemType>
48
void
TypedList<kTypeName, ElemType>::Release
() {
49
if
(data_) {
50
Dart_TypedDataReleaseData(dart_handle_);
51
data_ =
nullptr
;
52
num_elements_ = 0;
53
dart_handle_ =
nullptr
;
54
}
55
}
56
57
template
<Dart_TypedData_Type kTypeName,
typename
ElemType>
58
TypedList<kTypeName, ElemType>
59
DartConverter<TypedList<kTypeName, ElemType>
>::FromArguments(
60
Dart_NativeArguments
args
,
61
int
index,
62
Dart_Handle& exception) {
63
Dart_Handle list = Dart_GetNativeArgument(
args
, index);
64
TONIC_DCHECK
(!
CheckAndHandleError
(list));
65
return
TypedList<kTypeName, ElemType>
(list);
66
}
67
68
template
<Dart_TypedData_Type kTypeName,
typename
ElemType>
69
void
DartConverter<TypedList<kTypeName, ElemType>
>::SetReturnValue(
70
Dart_NativeArguments
args
,
71
TypedList<kTypeName, ElemType>
val) {
72
Dart_Handle result = val.
dart_handle
();
73
val.
Release
();
// Must release acquired typed data before calling Dart API.
74
Dart_SetReturnValue(
args
, result);
75
}
76
77
template
<Dart_TypedData_Type kTypeName,
typename
ElemType>
78
Dart_Handle
DartConverter<TypedList<kTypeName, ElemType>
>::ToDart(
79
const
ElemType* buffer,
80
unsigned
int
length
) {
81
const
intptr_t buffer_length =
static_cast<
intptr_t
>
(
length
);
82
Dart_Handle array = Dart_NewTypedData(kTypeName, buffer_length);
83
TONIC_DCHECK
(!
CheckAndHandleError
(array));
84
{
85
Dart_TypedData_Type
type
;
86
void
*
data
=
nullptr
;
87
intptr_t data_length = 0;
88
Dart_TypedDataAcquireData(array, &
type
, &
data
, &data_length);
89
TONIC_CHECK
(
type
== kTypeName);
90
TONIC_CHECK
(
data
);
91
TONIC_CHECK
(data_length == buffer_length);
92
std::memmove(
data
, buffer, data_length *
sizeof
(ElemType));
93
Dart_TypedDataReleaseData(array);
94
}
95
return
array;
96
}
97
98
#define TONIC_TYPED_DATA_DEFINE(name, type) \
99
template class TypedList<Dart_TypedData_k##name, type>; \
100
template struct DartConverter<name##List>;
101
102
TONIC_TYPED_DATA_FOREACH
(
TONIC_TYPED_DATA_DEFINE
)
103
104
#undef TONIC_TYPED_DATA_DEFINE
105
106
}
// namespace tonic
type
GLenum type
Definition
blit_command_gles.cc:153
tonic::TypedList
Definition
typed_list.h:19
tonic::TypedList::TypedList
TypedList()
Definition
typed_list.cc:14
tonic::TypedList::~TypedList
~TypedList()
Definition
typed_list.cc:43
tonic::TypedList::dart_handle
Dart_Handle dart_handle() const
Definition
typed_list.h:42
tonic::TypedList::Release
void Release()
Definition
typed_list.cc:48
dart_error.h
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition
fl_event_channel.h:89
length
size_t length
Definition
key_event_handler.cc:41
tonic
Definition
image_filter.h:15
tonic::ToDart
Dart_Handle ToDart(const T &object)
Definition
dart_converter.h:579
tonic::CheckAndHandleError
bool CheckAndHandleError(Dart_Handle handle)
Definition
dart_error.cc:33
tonic::DartConverter
Definition
dart_converter.h:21
data
std::shared_ptr< const fml::Mapping > data
Definition
texture_gles.cc:68
TONIC_CHECK
#define TONIC_CHECK(condition)
Definition
macros.h:23
TONIC_DCHECK
#define TONIC_DCHECK
Definition
macros.h:32
TONIC_TYPED_DATA_DEFINE
#define TONIC_TYPED_DATA_DEFINE(name, type)
Definition
typed_list.cc:98
typed_list.h
TONIC_TYPED_DATA_FOREACH
#define TONIC_TYPED_DATA_FOREACH(F)
Definition
typed_list.h:77
third_party
tonic
typed_data
typed_list.cc
Generated on Thu Nov 6 2025 16:11:30 for Flutter Engine by
1.9.8