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/lib/ui/painting/rrect.h"
6
7 #include "flutter/fml/logging.h"
8
9 using namespace flutter;
10
11 namespace tonic {
12
13 // Construct an SkRRect from a Dart RRect object.
14 // The Dart RRect is a Float32List containing
15 // [left, top, right, bottom, xRadius, yRadius]
FromDart(Dart_Handle value)16 RRect DartConverter<flutter::RRect>::FromDart(Dart_Handle value) {
17 Float32List buffer(value);
18
19 RRect result;
20 result.is_null = true;
21 if (buffer.data() == nullptr)
22 return result;
23
24 SkVector radii[4] = {{buffer[4], buffer[5]},
25 {buffer[6], buffer[7]},
26 {buffer[8], buffer[9]},
27 {buffer[10], buffer[11]}};
28
29 result.sk_rrect.setRectRadii(
30 SkRect::MakeLTRB(buffer[0], buffer[1], buffer[2], buffer[3]), radii);
31
32 result.is_null = false;
33 return result;
34 }
35
FromArguments(Dart_NativeArguments args,int index,Dart_Handle & exception)36 RRect DartConverter<flutter::RRect>::FromArguments(Dart_NativeArguments args,
37 int index,
38 Dart_Handle& exception) {
39 Dart_Handle value = Dart_GetNativeArgument(args, index);
40 FML_DCHECK(!LogIfError(value));
41 return FromDart(value);
42 }
43
44 } // namespace tonic
45