mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Canvas.concat takes a 16-element Float32List instead of an array.
The array should be in column-major format, in the format used by vector_math.dart. R=abarth@chromium.org Review URL: https://codereview.chromium.org/1155193004
This commit is contained in:
parent
08b2a30e0f
commit
8afcb0fe2d
@ -116,6 +116,7 @@ CPP_SPECIAL_CONVERSION_RULES = {
|
||||
'unrestricted float': 'float',
|
||||
# Pass these by value, not pointer.
|
||||
'Color': 'SkColor',
|
||||
'Float32List': 'Float32List',
|
||||
'Point': 'Point',
|
||||
'Rect': 'Rect',
|
||||
'TransferMode': 'SkXfermode::Mode',
|
||||
@ -363,6 +364,7 @@ DART_TO_CPP_VALUE = {
|
||||
|
||||
# Pass-by-value types.
|
||||
'Color': pass_by_value_format('CanvasColor'),
|
||||
'Float32List': pass_by_value_format('Float32List'),
|
||||
'Point': pass_by_value_format('{implemented_as}'),
|
||||
'Rect': pass_by_value_format('{implemented_as}'),
|
||||
'TransferMode': pass_by_value_format('TransferMode'),
|
||||
|
||||
@ -83,14 +83,27 @@ void Canvas::skew(float sx, float sy)
|
||||
m_canvas->skew(sx, sy);
|
||||
}
|
||||
|
||||
void Canvas::concat(const Vector<float>& matrix)
|
||||
void Canvas::concat(const Float32List& matrix4)
|
||||
{
|
||||
if (!m_canvas)
|
||||
return;
|
||||
ASSERT(m_displayList->isRecording());
|
||||
ASSERT(matrix.size() == 9);
|
||||
ASSERT(matrix4.data());
|
||||
|
||||
// TODO(mpcomplete): how can we raise an error in this case?
|
||||
if (matrix4.num_elements() != 16)
|
||||
return;
|
||||
|
||||
SkMatrix sk_matrix;
|
||||
sk_matrix.set9(matrix.data());
|
||||
// Mappings from SkMatrix-index to input-index.
|
||||
static const int kMappings[] = {
|
||||
0, 4, 12,
|
||||
1, 5, 13,
|
||||
3, 7, 15,
|
||||
};
|
||||
for (intptr_t i = 0; i < 9; ++i)
|
||||
sk_matrix[i] = matrix4.data()[kMappings[i]];
|
||||
|
||||
m_canvas->concat(sk_matrix);
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "sky/engine/core/painting/Rect.h"
|
||||
#include "sky/engine/platform/graphics/DisplayList.h"
|
||||
#include "sky/engine/tonic/dart_wrappable.h"
|
||||
#include "sky/engine/tonic/float32_list.h"
|
||||
#include "sky/engine/wtf/PassRefPtr.h"
|
||||
#include "sky/engine/wtf/RefCounted.h"
|
||||
|
||||
@ -37,7 +38,7 @@ public:
|
||||
void scale(float sx, float sy);
|
||||
void rotateDegrees(float degrees);
|
||||
void skew(float sx, float sy);
|
||||
void concat(const Vector<float>& matrix);
|
||||
void concat(const Float32List& matrix4);
|
||||
|
||||
void clipRect(const Rect& rect);
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ interface Canvas {
|
||||
void scale(float sx, float sy);
|
||||
void rotateDegrees(float degrees);
|
||||
void skew(float sx, float sy);
|
||||
void concat(float[] matrix9);
|
||||
void concat(Float32List matrix4);
|
||||
|
||||
void clipRect(Rect rect);
|
||||
|
||||
|
||||
@ -42,6 +42,8 @@ source_set("tonic") {
|
||||
"dart_wrappable.cc",
|
||||
"dart_wrappable.h",
|
||||
"dart_wrapper_info.h",
|
||||
"float32_list.cc",
|
||||
"float32_list.h",
|
||||
"mojo_converter.h",
|
||||
]
|
||||
|
||||
|
||||
47
engine/tonic/float32_list.cc
Normal file
47
engine/tonic/float32_list.cc
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "sky/engine/config.h"
|
||||
#include "sky/engine/tonic/dart_error.h"
|
||||
#include "sky/engine/tonic/float32_list.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
Float32List::Float32List(Dart_Handle list)
|
||||
: data_(nullptr), num_elements_(0), dart_handle_(list) {
|
||||
if (Dart_IsNull(list))
|
||||
return;
|
||||
|
||||
Dart_TypedData_Type type;
|
||||
Dart_TypedDataAcquireData(
|
||||
list, &type, reinterpret_cast<void**>(&data_), &num_elements_);
|
||||
DCHECK(!LogIfError(list));
|
||||
ASSERT(type == Dart_TypedData_kFloat32);
|
||||
}
|
||||
|
||||
Float32List::Float32List(Float32List&& other)
|
||||
: data_(other.data_),
|
||||
num_elements_(other.num_elements_),
|
||||
dart_handle_(other.dart_handle_) {
|
||||
other.data_ = nullptr;
|
||||
other.dart_handle_ = nullptr;
|
||||
}
|
||||
|
||||
Float32List::~Float32List() {
|
||||
if (data_)
|
||||
Dart_TypedDataReleaseData(dart_handle_);
|
||||
}
|
||||
|
||||
Float32List DartConverter<Float32List>::FromArgumentsWithNullCheck(
|
||||
Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
Dart_Handle list = Dart_GetNativeArgument(args, index);
|
||||
DCHECK(!LogIfError(list));
|
||||
|
||||
Float32List result(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
44
engine/tonic/float32_list.h
Normal file
44
engine/tonic/float32_list.h
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SKY_ENGINE_TONIC_FLOAT32_LIST_H_
|
||||
#define SKY_ENGINE_TONIC_FLOAT32_LIST_H_
|
||||
|
||||
#include "dart/runtime/include/dart_api.h"
|
||||
#include "sky/engine/tonic/dart_converter.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
// A simple wrapper around a Dart Float32List. It uses Dart_TypedDataAcquireData
|
||||
// to obtain a raw pointer to the data, which is released when this object is
|
||||
// destroyed.
|
||||
//
|
||||
// This is designed to be used with DartConverter only.
|
||||
class Float32List {
|
||||
public:
|
||||
explicit Float32List(Dart_Handle list);
|
||||
Float32List(Float32List&& other);
|
||||
~Float32List();
|
||||
|
||||
const float* data() const { return data_; }
|
||||
intptr_t num_elements() const { return num_elements_; }
|
||||
|
||||
private:
|
||||
float* data_;
|
||||
intptr_t num_elements_;
|
||||
Dart_Handle dart_handle_;
|
||||
|
||||
Float32List(const Float32List& other) = delete;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DartConverter<Float32List> {
|
||||
static Float32List FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // SKY_ENGINE_TONIC_FLOAT32_LIST_H_
|
||||
@ -8,6 +8,7 @@ div {
|
||||
<div id="canvas" />
|
||||
<script>
|
||||
import 'dart:math' as math;
|
||||
import 'dart:typed_data';
|
||||
import 'dart:sky';
|
||||
|
||||
void main() {
|
||||
@ -29,11 +30,12 @@ void main() {
|
||||
paint);
|
||||
|
||||
// Scale x and y by 0.5.
|
||||
var scaleMatrix = [
|
||||
0.5, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0,
|
||||
0.0, 0.0, 1.0
|
||||
];
|
||||
var scaleMatrix = new Float32List.fromList([
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0,
|
||||
]);
|
||||
context.concat(scaleMatrix);
|
||||
paint.color = const Color.fromARGB(128, 0, 255, 0);
|
||||
context.drawCircle(0.0, 0.0, radius, paint);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user