Flutter Engine
The Flutter Engine
vertices.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/lib/ui/painting/vertices.h"
6
7#include <algorithm>
8
9#include "flutter/lib/ui/ui_dart_state.h"
12
13namespace flutter {
14
16
17Vertices::Vertices() {}
18
20
21bool Vertices::init(Dart_Handle vertices_handle,
22 DlVertexMode vertex_mode,
23 Dart_Handle positions_handle,
24 Dart_Handle texture_coordinates_handle,
25 Dart_Handle colors_handle,
26 Dart_Handle indices_handle) {
28
29 tonic::Float32List positions(positions_handle);
30 tonic::Float32List texture_coordinates(texture_coordinates_handle);
31 tonic::Int32List colors(colors_handle);
32 tonic::Uint16List indices(indices_handle);
33
34 if (!positions.data()) {
35 return false;
36 }
37
39 if (texture_coordinates.data()) {
41 }
42 if (colors.data()) {
44 }
45 DlVertices::Builder builder(vertex_mode, positions.num_elements() / 2, flags,
46 indices.num_elements());
47
48 if (!builder.is_valid()) {
49 return false;
50 }
51
52 // positions are required for SkVertices::Builder
53 builder.store_vertices(positions.data());
54
55 if (texture_coordinates.data()) {
56 // SkVertices::Builder assumes equal numbers of elements
57 FML_DCHECK(positions.num_elements() == texture_coordinates.num_elements());
58 builder.store_texture_coordinates(texture_coordinates.data());
59 }
60
61 if (colors.data()) {
62 // SkVertices::Builder assumes equal numbers of elements
63 FML_DCHECK(positions.num_elements() / 2 == colors.num_elements());
64 builder.store_colors(reinterpret_cast<const SkColor*>(colors.data()));
65 }
66
67 if (indices.data() && indices.num_elements() > 0) {
68 builder.store_indices(indices.data());
69 }
70
71 positions.Release();
72 texture_coordinates.Release();
73 colors.Release();
74 indices.Release();
75
76 auto vertices = fml::MakeRefCounted<Vertices>();
77 vertices->vertices_ = builder.build();
78 vertices->AssociateWithDartWrapper(vertices_handle);
79
80 return true;
81}
82
84 vertices_.reset();
86}
87
88} // namespace flutter
uint32_t SkColor
Definition: SkColor.h:37
A utility class to build up a |DlVertices| object one set of data at a time.
Definition: dl_vertices.h:75
static constexpr Flags kHasColors
Definition: dl_vertices.h:98
static constexpr Flags kHasTextureCoordinates
Definition: dl_vertices.h:97
static void ThrowIfUIOperationsProhibited()
~Vertices() override
Definition: vertices.cc:19
const DlVertices * vertices() const
Definition: vertices.h:29
static bool init(Dart_Handle vertices_handle, DlVertexMode vertex_mode, Dart_Handle positions_handle, Dart_Handle texture_coordinates_handle, Dart_Handle colors_handle, Dart_Handle indices_handle)
Definition: vertices.cc:21
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
FlutterSemanticsFlag flags
#define FML_DCHECK(condition)
Definition: logging.h:103
PODArray< SkColor > colors
Definition: SkRecords.h:276
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, FlutterGpuTestClass)
DlVertexMode
Defines the way in which the vertices of a DlVertices object are separated into triangles into which ...
Definition: dl_vertices.h:20
flags to indicate/promise which of the optional texture coordinates or colors will be supplied during...
Definition: dl_vertices.h:80