mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #2116 from abarth/remove_idl
Remove IDL from engine/core/compositing
This commit is contained in:
commit
decb96b6aa
@ -6,6 +6,8 @@
|
||||
|
||||
#include "gen/sky/bindings/DartGlobal.h"
|
||||
#include "sky/engine/bindings/dart_runtime_hooks.h"
|
||||
#include "sky/engine/core/compositing/Scene.h"
|
||||
#include "sky/engine/core/compositing/SceneBuilder.h"
|
||||
#include "sky/engine/core/painting/painting.h"
|
||||
#include "sky/engine/core/window/window.h"
|
||||
#include "sky/engine/tonic/dart_converter.h"
|
||||
@ -40,6 +42,8 @@ void DartUI::InitForIsolate() {
|
||||
DartRuntimeHooks::RegisterNatives(g_natives);
|
||||
Window::RegisterNatives(g_natives);
|
||||
Painting::RegisterNatives(g_natives);
|
||||
Scene::RegisterNatives(g_natives);
|
||||
SceneBuilder::RegisterNatives(g_natives);
|
||||
}
|
||||
|
||||
DART_CHECK_VALID(Dart_SetNativeResolver(
|
||||
|
||||
@ -346,7 +346,7 @@ def pass_by_value_format(typename, null_check="{null_check}"):
|
||||
DART_TO_CPP_VALUE = {
|
||||
# Basic
|
||||
'Date': 'DartUtilities::dartToDate(args, {index}, exception)',
|
||||
'DOMString': 'DartConverter<String>::FromArguments{null_check}(args, {index}, exception, {auto_scope})',
|
||||
'DOMString': 'DartConverter<String>::FromArguments{null_check}(args, {index}, exception)',
|
||||
'ByteString': 'DartUtilities::dartToByteString{null_check}(args, {index}, exception, {auto_scope})',
|
||||
'ScalarValueString': 'DartUtilities::dartToScalarValueString{null_check}(args, {index}, exception, {auto_scope})',
|
||||
'boolean': 'DartConverter<bool>::FromArguments(args, {index}, exception)',
|
||||
|
||||
@ -6,8 +6,26 @@
|
||||
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkPictureRecorder.h"
|
||||
#include "sky/engine/tonic/dart_args.h"
|
||||
#include "sky/engine/tonic/dart_converter.h"
|
||||
#include "sky/engine/tonic/dart_library_natives.h"
|
||||
|
||||
namespace blink {
|
||||
namespace {
|
||||
|
||||
void DisposeCallback(Dart_NativeArguments args) {
|
||||
DartCall(&Scene::dispose, args);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(Scene);
|
||||
|
||||
void Scene::RegisterNatives(DartLibraryNatives* natives) {
|
||||
natives->Register({
|
||||
{ "Scene_dispose", DisposeCallback, 1, true },
|
||||
});
|
||||
}
|
||||
|
||||
PassRefPtr<Scene> Scene::create(
|
||||
std::unique_ptr<sky::compositor::Layer> rootLayer,
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include "third_party/skia/include/core/SkPicture.h"
|
||||
|
||||
namespace blink {
|
||||
class DartLibraryNatives;
|
||||
|
||||
class Scene : public RefCounted<Scene>, public DartWrappable {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
@ -30,6 +31,8 @@ class Scene : public RefCounted<Scene>, public DartWrappable {
|
||||
|
||||
void dispose();
|
||||
|
||||
static void RegisterNatives(DartLibraryNatives* natives);
|
||||
|
||||
private:
|
||||
explicit Scene(std::unique_ptr<sky::compositor::Layer> rootLayer,
|
||||
uint32_t rasterizerTracingThreshold);
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// An opaque handle to a composited scene.
|
||||
interface Scene {
|
||||
void dispose();
|
||||
};
|
||||
@ -15,8 +15,88 @@
|
||||
#include "sky/compositor/picture_layer.h"
|
||||
#include "sky/compositor/statistics_layer.h"
|
||||
#include "sky/compositor/transform_layer.h"
|
||||
#include "sky/engine/tonic/dart_args.h"
|
||||
#include "sky/engine/tonic/dart_converter.h"
|
||||
#include "sky/engine/tonic/dart_library_natives.h"
|
||||
|
||||
namespace blink {
|
||||
namespace {
|
||||
|
||||
void ConstructorCallback(Dart_NativeArguments args) {
|
||||
DartCallConstructor(&SceneBuilder::create, args);
|
||||
}
|
||||
|
||||
void PushTransformCallback(Dart_NativeArguments args) {
|
||||
DartArgIterator it(args);
|
||||
Float64List matrix4 = it.GetNext<Float64List>();
|
||||
if (it.had_exception())
|
||||
return;
|
||||
ExceptionState es;
|
||||
GetReceiver<SceneBuilder>(args)->pushTransform(matrix4, es);
|
||||
if (es.had_exception())
|
||||
Dart_ThrowException(es.GetDartException(args, true));
|
||||
}
|
||||
|
||||
void PushClipRectCallback(Dart_NativeArguments args) {
|
||||
DartCall(&SceneBuilder::pushClipRect, args);
|
||||
}
|
||||
|
||||
void PushClipRRectCallback(Dart_NativeArguments args) {
|
||||
DartCall(&SceneBuilder::pushClipRRect, args);
|
||||
}
|
||||
|
||||
void PushClipPathCallback(Dart_NativeArguments args) {
|
||||
DartCall(&SceneBuilder::pushClipPath, args);
|
||||
}
|
||||
|
||||
void PushOpacityCallback(Dart_NativeArguments args) {
|
||||
DartCall(&SceneBuilder::pushOpacity, args);
|
||||
}
|
||||
|
||||
void PushColorFilterCallback(Dart_NativeArguments args) {
|
||||
DartCall(&SceneBuilder::pushColorFilter, args);
|
||||
}
|
||||
|
||||
void PopCallback(Dart_NativeArguments args) {
|
||||
DartCall(&SceneBuilder::pop, args);
|
||||
}
|
||||
|
||||
void AddPictureCallback(Dart_NativeArguments args) {
|
||||
DartCall(&SceneBuilder::addPicture, args);
|
||||
}
|
||||
|
||||
void AddStatisticsCallback(Dart_NativeArguments args) {
|
||||
DartCall(&SceneBuilder::addStatistics, args);
|
||||
}
|
||||
|
||||
void SetRasterizerTracingThresholdCallback(Dart_NativeArguments args) {
|
||||
DartCall(&SceneBuilder::setRasterizerTracingThreshold, args);
|
||||
}
|
||||
|
||||
void BuildCallback(Dart_NativeArguments args) {
|
||||
DartCallAndReturn(&SceneBuilder::build, args);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(SceneBuilder);
|
||||
|
||||
void SceneBuilder::RegisterNatives(DartLibraryNatives* natives) {
|
||||
natives->Register({
|
||||
{ "SceneBuilder_constructor", ConstructorCallback, 2, true },
|
||||
{ "SceneBuilder_pushTransform", PushTransformCallback, 2, true },
|
||||
{ "SceneBuilder_pushClipRect", PushClipRectCallback, 2, true },
|
||||
{ "SceneBuilder_pushClipRRect", PushClipRRectCallback, 3, true },
|
||||
{ "SceneBuilder_pushClipPath", PushClipPathCallback, 3, true },
|
||||
{ "SceneBuilder_pushOpacity", PushOpacityCallback, 3, true },
|
||||
{ "SceneBuilder_pushColorFilter", PushColorFilterCallback, 4, true },
|
||||
{ "SceneBuilder_pop", PopCallback, 1, true },
|
||||
{ "SceneBuilder_addPicture", AddPictureCallback, 4, true },
|
||||
{ "SceneBuilder_addStatistics", AddStatisticsCallback, 3, true },
|
||||
{ "SceneBuilder_setRasterizerTracingThreshold", SetRasterizerTracingThresholdCallback, 2, true },
|
||||
{ "SceneBuilder_build", BuildCallback, 1, true },
|
||||
});
|
||||
}
|
||||
|
||||
SceneBuilder::SceneBuilder(const Rect& bounds)
|
||||
: m_rootPaintBounds(bounds.sk_rect)
|
||||
@ -69,7 +149,7 @@ void SceneBuilder::pushOpacity(int alpha, const Rect& bounds)
|
||||
addLayer(std::move(layer));
|
||||
}
|
||||
|
||||
void SceneBuilder::pushColorFilter(SkColor color, SkXfermode::Mode transferMode, const Rect& bounds)
|
||||
void SceneBuilder::pushColorFilter(CanvasColor color, TransferMode transferMode, const Rect& bounds)
|
||||
{
|
||||
std::unique_ptr<sky::compositor::ColorFilterLayer> layer(new sky::compositor::ColorFilterLayer());
|
||||
if (!bounds.is_null)
|
||||
|
||||
@ -40,7 +40,7 @@ public:
|
||||
void pushClipRRect(const RRect& rrect, const Rect& bounds);
|
||||
void pushClipPath(const CanvasPath* path, const Rect& bounds);
|
||||
void pushOpacity(int alpha, const Rect& bounds);
|
||||
void pushColorFilter(SkColor color, SkXfermode::Mode transferMode, const Rect& bounds);
|
||||
void pushColorFilter(CanvasColor color, TransferMode transferMode, const Rect& bounds);
|
||||
void pop();
|
||||
|
||||
void addPicture(const Offset& offset, Picture* picture, const Rect& bounds);
|
||||
@ -50,6 +50,8 @@ public:
|
||||
|
||||
PassRefPtr<Scene> build();
|
||||
|
||||
static void RegisterNatives(DartLibraryNatives* natives);
|
||||
|
||||
private:
|
||||
explicit SceneBuilder(const Rect& bounds);
|
||||
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
// 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.
|
||||
|
||||
[
|
||||
Constructor(Rect bounds),
|
||||
] interface SceneBuilder {
|
||||
[RaisesException] void pushTransform(Float64List matrix4);
|
||||
void pushClipRect(Rect rect);
|
||||
void pushClipRRect(RRect rrect, Rect bounds);
|
||||
void pushClipPath(Path path, Rect bounds);
|
||||
void pushOpacity(long alpha, Rect bounds);
|
||||
void pushColorFilter(Color color, TransferMode transferMode, Rect bounds);
|
||||
void pop();
|
||||
|
||||
void addPicture(Offset offset, Picture picture, Rect bounds);
|
||||
void addStatistics(unsigned long enabledOptions, Rect bounds);
|
||||
void setRasterizerTracingThreshold(unsigned long frameInterval);
|
||||
|
||||
Scene build();
|
||||
};
|
||||
@ -236,8 +236,6 @@ sky_core_files = [
|
||||
]
|
||||
|
||||
core_idl_files = get_path_info([
|
||||
"compositing/Scene.idl",
|
||||
"compositing/SceneBuilder.idl",
|
||||
"painting/Canvas.idl",
|
||||
"painting/ColorFilter.idl",
|
||||
"painting/Drawable.idl",
|
||||
@ -258,6 +256,7 @@ core_idl_files = get_path_info([
|
||||
"abspath")
|
||||
|
||||
core_dart_files = get_path_info([
|
||||
"dart/compositing.dart",
|
||||
"dart/hash_codes.dart",
|
||||
"dart/hooks.dart",
|
||||
"dart/lerp.dart",
|
||||
|
||||
29
sky/engine/core/dart/compositing.dart
Normal file
29
sky/engine/core/dart/compositing.dart
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.
|
||||
|
||||
part of dart_ui;
|
||||
|
||||
abstract class Scene extends NativeFieldWrapperClass2 {
|
||||
void dispose() native "Scene_dispose";
|
||||
}
|
||||
|
||||
class SceneBuilder extends NativeFieldWrapperClass2 {
|
||||
void _constructor(Rect bounds) native "SceneBuilder_constructor";
|
||||
SceneBuilder(Rect bounds) { _constructor(bounds); }
|
||||
|
||||
void pushTransform(Float64List matrix4) native "SceneBuilder_pushTransform";
|
||||
void pushClipRect(Rect rect) native "SceneBuilder_pushClipRect";
|
||||
void pushClipRRect(RRect rrect, Rect bounds) native "SceneBuilder_pushClipRRect";
|
||||
void pushClipPath(Path path, Rect bounds) native "SceneBuilder_pushClipPath";
|
||||
void pushOpacity(int alpha, Rect bounds) native "SceneBuilder_pushOpacity";
|
||||
void pushColorFilter(Color color, TransferMode transferMode, Rect bounds) native "SceneBuilder_pushColorFilter";
|
||||
|
||||
void pop() native "SceneBuilder_pop";
|
||||
|
||||
void addPicture(Offset offset, Picture picture, Rect bounds) native "SceneBuilder_addPicture";
|
||||
void addStatistics(int enabledOptions, Rect bounds) native "SceneBuilder_addStatistics";
|
||||
void setRasterizerTracingThreshold(int frameInterval) native "SceneBuilder_setRasterizerTracingThreshold";
|
||||
|
||||
Scene build() native "SceneBuilder_build";
|
||||
}
|
||||
@ -22,7 +22,7 @@ SkColor DartConverter<CanvasColor>::FromDart(Dart_Handle dart_color) {
|
||||
return static_cast<SkColor>(color);
|
||||
}
|
||||
|
||||
SkColor DartConverter<CanvasColor>::FromArgumentsWithNullCheck(
|
||||
SkColor DartConverter<CanvasColor>::FromArguments(
|
||||
Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
|
||||
@ -13,7 +13,13 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
class CanvasColor {};
|
||||
struct CanvasColor {
|
||||
SkColor color;
|
||||
|
||||
CanvasColor(SkColor color) : color(color) { }
|
||||
CanvasColor() : color() { }
|
||||
operator SkColor() { return color; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DartConverterTypes<CanvasColor> {
|
||||
@ -24,9 +30,14 @@ struct DartConverterTypes<CanvasColor> {
|
||||
template <>
|
||||
struct DartConverter<CanvasColor> {
|
||||
static SkColor FromDart(Dart_Handle handle);
|
||||
static SkColor FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
static SkColor FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
Dart_Handle& exception) {
|
||||
return FromArguments(args, index, exception);
|
||||
}
|
||||
static void SetReturnValue(Dart_NativeArguments args, SkColor val);
|
||||
};
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ Offset DartConverter<Offset>::FromDart(Dart_Handle handle) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Offset DartConverter<Offset>::FromArgumentsWithNullCheck(
|
||||
Offset DartConverter<Offset>::FromArguments(
|
||||
Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
|
||||
@ -20,9 +20,14 @@ class Offset {
|
||||
template <>
|
||||
struct DartConverter<Offset> {
|
||||
static Offset FromDart(Dart_Handle handle);
|
||||
static Offset FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
static Offset FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
return FromArguments(args, index, exception);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -42,9 +42,9 @@ RRect DartConverter<RRect>::FromDart(Dart_Handle dart_rrect) {
|
||||
return result;
|
||||
}
|
||||
|
||||
RRect DartConverter<RRect>::FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
RRect DartConverter<RRect>::FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
Dart_Handle dart_rrect = Dart_GetNativeArgument(args, index);
|
||||
DCHECK(!LogIfError(dart_rrect));
|
||||
return FromDart(dart_rrect);
|
||||
|
||||
@ -20,9 +20,14 @@ class RRect {
|
||||
template <>
|
||||
struct DartConverter<RRect> {
|
||||
static RRect FromDart(Dart_Handle handle);
|
||||
static RRect FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
static RRect FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
Dart_Handle& exception) {
|
||||
return FromArguments(args, index, exception);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -46,9 +46,9 @@ Rect DartConverter<Rect>::FromDart(Dart_Handle dart_rect) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Rect DartConverter<Rect>::FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
Rect DartConverter<Rect>::FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
Dart_Handle dart_rect = Dart_GetNativeArgument(args, index);
|
||||
DCHECK(!LogIfError(dart_rect));
|
||||
return FromDart(dart_rect);
|
||||
|
||||
@ -20,9 +20,14 @@ class Rect {
|
||||
template <>
|
||||
struct DartConverter<Rect> {
|
||||
static Rect FromDart(Dart_Handle handle);
|
||||
static Rect FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
static Rect FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
Dart_Handle& exception) {
|
||||
return FromArguments(args, index, exception);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -10,7 +10,13 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
class TransferMode {};
|
||||
struct TransferMode {
|
||||
SkXfermode::Mode mode;
|
||||
|
||||
TransferMode() : mode() { }
|
||||
TransferMode(SkXfermode::Mode mode) : mode(mode) { }
|
||||
operator SkXfermode::Mode() { return mode; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DartConverter<TransferMode>
|
||||
|
||||
168
sky/engine/tonic/dart_args.h
Normal file
168
sky/engine/tonic/dart_args.h
Normal file
@ -0,0 +1,168 @@
|
||||
// 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_DART_ARGS_H_
|
||||
#define SKY_ENGINE_TONIC_DART_ARGS_H_
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "sky/engine/tonic/dart_converter.h"
|
||||
#include "sky/engine/tonic/dart_wrappable.h"
|
||||
#include "dart/runtime/include/dart_api.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class DartArgIterator {
|
||||
public:
|
||||
explicit DartArgIterator(Dart_NativeArguments args)
|
||||
: args_(args), index_(1), had_exception_(false) { }
|
||||
|
||||
template<typename T>
|
||||
T GetNext() {
|
||||
if (had_exception_)
|
||||
return T();
|
||||
Dart_Handle exception = nullptr;
|
||||
T arg = DartConverter<T>::FromArguments(args_, index_++, exception);
|
||||
if (exception) {
|
||||
had_exception_ = true;
|
||||
Dart_ThrowException(exception);
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
bool had_exception() const { return had_exception_; }
|
||||
|
||||
Dart_NativeArguments args() const { return args_; }
|
||||
|
||||
private:
|
||||
Dart_NativeArguments args_;
|
||||
int index_;
|
||||
bool had_exception_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DartArgIterator);
|
||||
};
|
||||
|
||||
// Classes for generating and storing an argument pack of integer indices
|
||||
// (based on well-known "indices trick", see: http://goo.gl/bKKojn):
|
||||
template <size_t... indices>
|
||||
struct IndicesHolder {};
|
||||
|
||||
template <size_t requested_index, size_t... indices>
|
||||
struct IndicesGenerator {
|
||||
using type = typename IndicesGenerator<requested_index - 1,
|
||||
requested_index - 1,
|
||||
indices...>::type;
|
||||
};
|
||||
|
||||
template <size_t... indices>
|
||||
struct IndicesGenerator<0, indices...> {
|
||||
using type = IndicesHolder<indices...>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class IndicesForSignature {};
|
||||
|
||||
template <typename ResultType,
|
||||
typename... ArgTypes>
|
||||
struct IndicesForSignature<ResultType (*)(ArgTypes...)> {
|
||||
using type = typename IndicesGenerator<sizeof...(ArgTypes)>::type;
|
||||
};
|
||||
|
||||
template <typename C,
|
||||
typename ResultType,
|
||||
typename... ArgTypes>
|
||||
struct IndicesForSignature<ResultType (C::*)(ArgTypes...)> {
|
||||
using type = typename IndicesGenerator<sizeof...(ArgTypes)>::type;
|
||||
};
|
||||
|
||||
template<size_t index, typename ArgType>
|
||||
struct DartArgHolder {
|
||||
using ValueType = typename std::remove_const<
|
||||
typename std::remove_reference<ArgType>::type
|
||||
>::type;
|
||||
|
||||
ValueType value;
|
||||
|
||||
explicit DartArgHolder(DartArgIterator* it)
|
||||
: value(it->GetNext<ValueType>()) {}
|
||||
};
|
||||
|
||||
template <typename IndicesType, typename T>
|
||||
class DartDecoder {
|
||||
};
|
||||
|
||||
template <size_t... indices,
|
||||
typename ResultType,
|
||||
typename... ArgTypes>
|
||||
struct DartDecoder<IndicesHolder<indices...>, ResultType (*)(ArgTypes...)>
|
||||
: public DartArgHolder<indices, ArgTypes>... {
|
||||
using FunctionPtr = ResultType (*)(ArgTypes...);
|
||||
|
||||
DartArgIterator* it_;
|
||||
|
||||
explicit DartDecoder(DartArgIterator* it)
|
||||
: DartArgHolder<indices, ArgTypes>(it)..., it_(it) { }
|
||||
|
||||
ResultType Dispatch(FunctionPtr func) {
|
||||
return (*func)(DartArgHolder<indices, ArgTypes>::value...);
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t... indices,
|
||||
typename C,
|
||||
typename ResultType,
|
||||
typename... ArgTypes>
|
||||
struct DartDecoder<IndicesHolder<indices...>, ResultType (C::*)(ArgTypes...)>
|
||||
: public DartArgHolder<indices, ArgTypes>... {
|
||||
using FunctionPtr = ResultType (C::*)(ArgTypes...);
|
||||
|
||||
DartArgIterator* it_;
|
||||
|
||||
explicit DartDecoder(DartArgIterator* it)
|
||||
: DartArgHolder<indices, ArgTypes>(it)..., it_(it) { }
|
||||
|
||||
ResultType Dispatch(FunctionPtr func) {
|
||||
return (GetReceiver<C>(it_->args())->*func)(
|
||||
DartArgHolder<indices, ArgTypes>::value...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void DartReturn(T result, Dart_NativeArguments args) {
|
||||
DartConverter<T>::SetReturnValue(args, result);
|
||||
}
|
||||
|
||||
template<typename Sig>
|
||||
void DartCall(Sig func, Dart_NativeArguments args) {
|
||||
DartArgIterator it(args);
|
||||
using Indices = typename IndicesForSignature<Sig>::type;
|
||||
DartDecoder<Indices, Sig> decoder(&it);
|
||||
if (it.had_exception())
|
||||
return;
|
||||
decoder.Dispatch(func);
|
||||
}
|
||||
|
||||
template<typename Sig>
|
||||
void DartCallAndReturn(Sig func, Dart_NativeArguments args) {
|
||||
DartArgIterator it(args);
|
||||
using Indices = typename IndicesForSignature<Sig>::type;
|
||||
DartDecoder<Indices, Sig> decoder(&it);
|
||||
if (it.had_exception())
|
||||
return;
|
||||
DartReturn(decoder.Dispatch(func), args);
|
||||
}
|
||||
|
||||
template<typename Sig>
|
||||
void DartCallConstructor(Sig func, Dart_NativeArguments args) {
|
||||
DartArgIterator it(args);
|
||||
using Indices = typename IndicesForSignature<Sig>::type;
|
||||
DartDecoder<Indices, Sig> decoder(&it);
|
||||
if (it.had_exception())
|
||||
return;
|
||||
decoder.Dispatch(func)->AssociateWithDartWrapper(args);
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // SKY_ENGINE_TONIC_DART_ARGS_H_
|
||||
@ -226,8 +226,7 @@ struct DartConverter<String> {
|
||||
|
||||
static String FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception,
|
||||
bool auto_scope = true) {
|
||||
Dart_Handle& exception) {
|
||||
// TODO(abarth): What should we do with auto_scope?
|
||||
void* peer = nullptr;
|
||||
Dart_Handle handle = Dart_GetNativeStringArgument(args, index, &peer);
|
||||
@ -309,8 +308,7 @@ struct DartConverter<Vector<T>> {
|
||||
|
||||
static Vector<ValueType> FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception,
|
||||
bool auto_scope = true) {
|
||||
Dart_Handle& exception) {
|
||||
// TODO(abarth): What should we do with auto_scope?
|
||||
return FromDart(Dart_GetNativeArgument(args, index));
|
||||
}
|
||||
@ -335,8 +333,7 @@ struct DartConverter<DartValue*> {
|
||||
|
||||
static PassRefPtr<DartValue> FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception,
|
||||
bool auto_scope = true) {
|
||||
Dart_Handle& exception) {
|
||||
// TODO(abarth): What should we do with auto_scope?
|
||||
return FromDart(Dart_GetNativeArgument(args, index));
|
||||
}
|
||||
|
||||
@ -65,6 +65,21 @@ class DartWrappable {
|
||||
private: \
|
||||
static const DartWrapperInfo& dart_wrapper_info_
|
||||
|
||||
#define IMPLEMENT_WRAPPERTYPEINFO(ClassName) \
|
||||
static void RefObject(DartWrappable* impl) { \
|
||||
static_cast<ClassName*>(impl)->ref(); \
|
||||
} \
|
||||
static void DerefObject(DartWrappable* impl) { \
|
||||
static_cast<ClassName*>(impl)->deref(); \
|
||||
} \
|
||||
static const DartWrapperInfo kDartWrapperInfo = { \
|
||||
#ClassName, \
|
||||
sizeof(ClassName), \
|
||||
&RefObject, \
|
||||
&DerefObject, \
|
||||
}; \
|
||||
const DartWrapperInfo& ClassName::dart_wrapper_info_ = kDartWrapperInfo; \
|
||||
|
||||
struct DartConverterWrappable {
|
||||
static DartWrappable* FromDart(Dart_Handle handle);
|
||||
static DartWrappable* FromArguments(Dart_NativeArguments args,
|
||||
@ -79,7 +94,7 @@ template<typename T>
|
||||
struct DartConverter<
|
||||
T*,
|
||||
typename base::enable_if<
|
||||
base::is_convertible<T*, DartWrappable*>::value>::type> {
|
||||
base::is_convertible<T*, const DartWrappable*>::value>::type> {
|
||||
static Dart_Handle ToDart(DartWrappable* val) {
|
||||
if (!val)
|
||||
return Dart_Null();
|
||||
@ -134,6 +149,15 @@ struct DartConverter<RefPtr<T>> {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct DartConverter<PassRefPtr<T>> {
|
||||
static void SetReturnValue(Dart_NativeArguments args,
|
||||
PassRefPtr<T> val,
|
||||
bool auto_scope = true) {
|
||||
DartConverter<T*>::SetReturnValue(args, val.get());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline T* GetReceiver(Dart_NativeArguments args) {
|
||||
intptr_t receiver;
|
||||
|
||||
@ -7,6 +7,9 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
Float32List::Float32List()
|
||||
: data_(nullptr), num_elements_(0), dart_handle_(nullptr) {}
|
||||
|
||||
Float32List::Float32List(Dart_Handle list)
|
||||
: data_(nullptr), num_elements_(0), dart_handle_(list) {
|
||||
if (Dart_IsNull(list))
|
||||
@ -32,7 +35,7 @@ Float32List::~Float32List() {
|
||||
Dart_TypedDataReleaseData(dart_handle_);
|
||||
}
|
||||
|
||||
Float32List DartConverter<Float32List>::FromArgumentsWithNullCheck(
|
||||
Float32List DartConverter<Float32List>::FromArguments(
|
||||
Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
|
||||
@ -19,6 +19,7 @@ class Float32List {
|
||||
public:
|
||||
explicit Float32List(Dart_Handle list);
|
||||
Float32List(Float32List&& other);
|
||||
Float32List();
|
||||
~Float32List();
|
||||
|
||||
float& at(intptr_t i)
|
||||
@ -50,10 +51,14 @@ class Float32List {
|
||||
template <>
|
||||
struct DartConverter<Float32List> {
|
||||
static void SetReturnValue(Dart_NativeArguments args, Float32List val);
|
||||
|
||||
static Float32List FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
static Float32List FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
Dart_Handle& exception) {
|
||||
return FromArguments(args, index, exception);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -7,6 +7,9 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
Float64List::Float64List()
|
||||
: data_(nullptr), num_elements_(0), dart_handle_(nullptr) {}
|
||||
|
||||
Float64List::Float64List(Dart_Handle list)
|
||||
: data_(nullptr), num_elements_(0), dart_handle_(list) {
|
||||
if (Dart_IsNull(list))
|
||||
@ -32,7 +35,7 @@ Float64List::~Float64List() {
|
||||
Dart_TypedDataReleaseData(dart_handle_);
|
||||
}
|
||||
|
||||
Float64List DartConverter<Float64List>::FromArgumentsWithNullCheck(
|
||||
Float64List DartConverter<Float64List>::FromArguments(
|
||||
Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
|
||||
@ -19,6 +19,7 @@ class Float64List {
|
||||
public:
|
||||
explicit Float64List(Dart_Handle list);
|
||||
Float64List(Float64List&& other);
|
||||
Float64List();
|
||||
~Float64List();
|
||||
|
||||
double& at(intptr_t i)
|
||||
@ -50,10 +51,14 @@ class Float64List {
|
||||
template <>
|
||||
struct DartConverter<Float64List> {
|
||||
static void SetReturnValue(Dart_NativeArguments args, Float64List val);
|
||||
|
||||
static Float64List FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
static Float64List FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
Dart_Handle& exception) {
|
||||
return FromArguments(args, index, exception);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -7,6 +7,9 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
Int32List::Int32List()
|
||||
: data_(nullptr), num_elements_(0), dart_handle_(nullptr) {}
|
||||
|
||||
Int32List::Int32List(Dart_Handle list)
|
||||
: data_(nullptr), num_elements_(0), dart_handle_(list) {
|
||||
if (Dart_IsNull(list))
|
||||
@ -39,7 +42,7 @@ void Int32List::Release() {
|
||||
}
|
||||
|
||||
|
||||
Int32List DartConverter<Int32List>::FromArgumentsWithNullCheck(
|
||||
Int32List DartConverter<Int32List>::FromArguments(
|
||||
Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
|
||||
@ -19,6 +19,7 @@ class Int32List {
|
||||
public:
|
||||
explicit Int32List(Dart_Handle list);
|
||||
Int32List(Int32List&& other);
|
||||
Int32List();
|
||||
~Int32List();
|
||||
|
||||
int32_t& at(intptr_t i)
|
||||
@ -52,10 +53,14 @@ class Int32List {
|
||||
template <>
|
||||
struct DartConverter<Int32List> {
|
||||
static void SetReturnValue(Dart_NativeArguments args, Int32List val);
|
||||
|
||||
static Int32List FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
static Int32List FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
Dart_Handle& exception) {
|
||||
return FromArguments(args, index, exception);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -7,6 +7,9 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
Uint8List::Uint8List()
|
||||
: data_(nullptr), num_elements_(0), dart_handle_(nullptr) {}
|
||||
|
||||
Uint8List::Uint8List(Dart_Handle list)
|
||||
: data_(nullptr), num_elements_(0), dart_handle_(list) {
|
||||
if (Dart_IsNull(list))
|
||||
@ -32,7 +35,7 @@ Uint8List::~Uint8List() {
|
||||
Dart_TypedDataReleaseData(dart_handle_);
|
||||
}
|
||||
|
||||
Uint8List DartConverter<Uint8List>::FromArgumentsWithNullCheck(
|
||||
Uint8List DartConverter<Uint8List>::FromArguments(
|
||||
Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
|
||||
@ -19,6 +19,7 @@ class Uint8List {
|
||||
public:
|
||||
explicit Uint8List(Dart_Handle list);
|
||||
Uint8List(Uint8List&& other);
|
||||
Uint8List();
|
||||
~Uint8List();
|
||||
|
||||
uint8& at(intptr_t i)
|
||||
@ -50,10 +51,14 @@ class Uint8List {
|
||||
template <>
|
||||
struct DartConverter<Uint8List> {
|
||||
static void SetReturnValue(Dart_NativeArguments args, Uint8List val);
|
||||
|
||||
static Uint8List FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
static Uint8List FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
Dart_Handle& exception) {
|
||||
return FromArguments(args, index, exception);
|
||||
}
|
||||
|
||||
static Dart_Handle ToDart(const uint8_t* buffer, unsigned int length);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user