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