提交 d745bd3d 编写于 作者: M Matt Perry

Sky: Add a DartConverterEnum and use that for all our enum needs.

R=abarth@chromium.org, eseidel@chromium.org

Review URL: https://codereview.chromium.org/1170963003.
上级 7cbe385e
......@@ -123,6 +123,7 @@ CPP_SPECIAL_CONVERSION_RULES = {
'Point': 'Point',
'Rect': 'Rect',
'MojoDataPipeConsumer': 'mojo::ScopedDataPipeConsumerHandle',
'TileMode': 'SkShader::TileMode',
'TransferMode': 'SkXfermode::Mode',
'PaintingStyle': 'SkPaint::Style',
}
......@@ -329,8 +330,8 @@ def set_component_dirs(new_component_dirs):
# TODO(terry): Need to fix to handle getter/setters for onEvent.
DART_FIX_ME = 'DART_UNIMPLEMENTED(/* Conversion unimplemented*/);'
def pass_by_value_format(typename):
return 'DartConverter<%s>::FromArguments{null_check}(args, {index}, exception)' % typename
def pass_by_value_format(typename, null_check="{null_check}"):
return 'DartConverter<%s>::FromArguments%s(args, {index}, exception)' % (typename, null_check)
# For a given IDL type, the DartHandle to C++ conversion.
DART_TO_CPP_VALUE = {
......@@ -373,8 +374,9 @@ DART_TO_CPP_VALUE = {
'Float32List': pass_by_value_format('Float32List'),
'Point': pass_by_value_format('Point'),
'Rect': pass_by_value_format('Rect'),
'TransferMode': pass_by_value_format('TransferMode'),
'PaintingStyle': pass_by_value_format('PaintingStyle'),
'TileMode': pass_by_value_format('TileMode', ''),
'TransferMode': pass_by_value_format('TransferMode', ''),
'PaintingStyle': pass_by_value_format('PaintingStyle', ''),
'MojoDataPipeConsumer': pass_by_value_format('mojo::ScopedDataPipeConsumerHandle'),
}
......
......@@ -866,7 +866,6 @@ sky_core_files = [
"painting/PaintingCallback.h",
"painting/PaintingContext.cpp",
"painting/PaintingContext.h",
"painting/PaintingStyle.cpp",
"painting/PaintingStyle.h",
"painting/PaintingTasks.cpp",
"painting/PaintingTasks.h",
......@@ -882,7 +881,6 @@ sky_core_files = [
"painting/RRect.h",
"painting/Shader.cpp",
"painting/Shader.h",
"painting/TransferMode.cpp",
"painting/TransferMode.h",
"rendering/BidiRun.h",
"rendering/BidiRunForLine.cpp",
......
......@@ -14,10 +14,9 @@ PassRefPtr<CanvasGradient> CanvasGradient::create() {
void CanvasGradient::initLinear(const Vector<Point>& end_points,
const Vector<SkColor>& colors,
const Vector<float>& color_stops,
unsigned tile_mode) {
SkShader::TileMode tile_mode) {
ASSERT(end_points.size() == 2);
ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr);
ASSERT(tile_mode < SkShader::kTileModeCount);
SkPoint sk_end_points[2];
for (int i = 0; i < 2; ++i)
sk_end_points[i] = end_points[i].sk_point;
......@@ -25,7 +24,7 @@ void CanvasGradient::initLinear(const Vector<Point>& end_points,
// TODO(mpcomplete): allow setting the TileMode.
SkShader* shader = SkGradientShader::CreateLinear(
sk_end_points, colors.data(), color_stops.data(), colors.size(),
static_cast<SkShader::TileMode>(tile_mode));
tile_mode);
set_shader(adoptRef(shader));
}
......@@ -33,13 +32,12 @@ void CanvasGradient::initRadial(const Point& center,
double radius,
const Vector<SkColor>& colors,
const Vector<float>& color_stops,
unsigned tile_mode) {
SkShader::TileMode tile_mode) {
ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr);
ASSERT(tile_mode < SkShader::kTileModeCount);
SkShader* shader = SkGradientShader::CreateRadial(
center.sk_point, radius, colors.data(), color_stops.data(), colors.size(),
static_cast<SkShader::TileMode>(tile_mode));
tile_mode);
set_shader(adoptRef(shader));
}
......
......@@ -13,6 +13,13 @@
namespace blink {
class TileMode {};
template <>
struct DartConverter<TileMode> : public DartConverterEnum<SkShader::TileMode> {};
COMPILE_ASSERT(SkShader::kTileModeCount == 3, Need_to_update_Gradient_dart);
class CanvasGradient : public Shader {
DEFINE_WRAPPERTYPEINFO();
public:
......@@ -22,12 +29,12 @@ class CanvasGradient : public Shader {
void initLinear(const Vector<Point>& end_points,
const Vector<SkColor>& colors,
const Vector<float>& color_stops,
unsigned tile_mode);
SkShader::TileMode tile_mode);
void initRadial(const Point& center,
double radius,
const Vector<SkColor>& colors,
const Vector<float>& color_stops,
unsigned tile_mode);
SkShader::TileMode tile_mode);
private:
CanvasGradient();
......
......@@ -21,7 +21,7 @@ class Gradient extends _Gradient {
if (endPoints == null || endPoints.length != 2)
throw new ArgumentError("Expected exactly 2 [endPoints].");
validateColorStops(colors, colorStops);
this._initLinear(endPoints, colors, colorStops, tileMode.index);
this._initLinear(endPoints, colors, colorStops, tileMode);
}
Gradient.Radial(Point center,
......@@ -31,7 +31,7 @@ class Gradient extends _Gradient {
[TileMode tileMode = TileMode.clamp])
: super() {
validateColorStops(colors, colorStops);
this._initRadial(center, radius, colors, colorStops, tileMode.index);
this._initRadial(center, radius, colors, colorStops, tileMode);
}
void validateColorStops(List<Color> colors, List<double> colorStops) {
......
......@@ -8,7 +8,7 @@
Constructor()
] interface Gradient : Shader {
void initLinear(Point[] endPoints, Color[] colors, float[] colorStops,
/*TileMode*/unsigned long tileMode);
TileMode tileMode);
void initRadial(Point center, double radius, Color[] colors,
float[] colorStops, /*TileMode*/unsigned long tileMode);
float[] colorStops, TileMode tileMode);
};
// 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/core/painting/PaintingStyle.h"
#include "sky/engine/core/script/dom_dart_state.h"
#include "sky/engine/tonic/dart_builtin.h"
#include "sky/engine/tonic/dart_error.h"
#include "sky/engine/tonic/dart_value.h"
namespace blink {
// If this fails, it's because SkXfermode has changed. We need to change
// PaintingStyle.dart to ensure the PaintingStyle enum is in sync with the C++
// values.
COMPILE_ASSERT(SkPaint::kStyleCount == 3, Need_to_update_PaintingStyle_dart);
// Convert dart_style => SkPaint::Style.
SkPaint::Style DartConverter<PaintingStyle>::FromArgumentsWithNullCheck(
Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
SkPaint::Style result;
Dart_Handle dart_style = Dart_GetNativeArgument(args, index);
DCHECK(!LogIfError(dart_style));
Dart_Handle value =
Dart_GetField(dart_style, DOMDartState::Current()->index_handle());
uint64_t style = 0;
Dart_Handle rv = Dart_IntegerToUint64(value, &style);
DCHECK(!LogIfError(rv));
result = static_cast<SkPaint::Style>(style);
return result;
}
} // namespace blink
......@@ -5,10 +5,7 @@
#ifndef SKY_ENGINE_CORE_PAINTING_PAINTINGSTYLE_H_
#define SKY_ENGINE_CORE_PAINTING_PAINTINGSTYLE_H_
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "sky/engine/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkPaint.h"
namespace blink {
......@@ -16,12 +13,14 @@ namespace blink {
class PaintingStyle {};
template <>
struct DartConverter<PaintingStyle> {
static SkPaint::Style FromArgumentsWithNullCheck(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
struct DartConverter<PaintingStyle> : public DartConverterEnum<SkPaint::Style> {
};
// If this fails, it's because SkPaint::Style has changed. We need to change
// PaintingStyle.dart to ensure the PaintingStyle enum is in sync with the C++
// values.
COMPILE_ASSERT(SkPaint::kStyleCount == 3, Need_to_update_PaintingStyle_dart);
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_PAINTINGSTYLE_H_
// 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/core/painting/TransferMode.h"
#include "sky/engine/core/script/dom_dart_state.h"
#include "sky/engine/tonic/dart_builtin.h"
#include "sky/engine/tonic/dart_error.h"
#include "sky/engine/tonic/dart_value.h"
namespace blink {
// If this fails, it's because SkXfermode has changed. We need to change
// TransferMode.dart to ensure the TransferMode enum is in sync with the C++
// values.
COMPILE_ASSERT(SkXfermode::kLastMode == 28, Need_to_update_TransferMode_dart);
// Convert dart_mode => SkXfermode::Mode.
SkXfermode::Mode DartConverter<TransferMode>::FromArgumentsWithNullCheck(
Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
SkXfermode::Mode result;
Dart_Handle dart_mode = Dart_GetNativeArgument(args, index);
DCHECK(!LogIfError(dart_mode));
Dart_Handle value =
Dart_GetField(dart_mode, DOMDartState::Current()->index_handle());
uint64_t mode = 0;
Dart_Handle rv = Dart_IntegerToUint64(value, &mode);
DCHECK(!LogIfError(rv));
result = static_cast<SkXfermode::Mode>(mode);
return result;
}
} // namespace blink
......@@ -5,10 +5,7 @@
#ifndef SKY_ENGINE_CORE_PAINTING_TRANSFERMODE_H_
#define SKY_ENGINE_CORE_PAINTING_TRANSFERMODE_H_
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "sky/engine/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkXfermode.h"
namespace blink {
......@@ -16,11 +13,13 @@ namespace blink {
class TransferMode {};
template <>
struct DartConverter<TransferMode> {
static SkXfermode::Mode FromArgumentsWithNullCheck(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
};
struct DartConverter<TransferMode>
: public DartConverterEnum<SkXfermode::Mode> {};
// If this fails, it's because SkXfermode has changed. We need to change
// TransferMode.dart to ensure the TransferMode enum is in sync with the C++
// values.
COMPILE_ASSERT(SkXfermode::kLastMode == 28, Need_to_update_TransferMode_dart);
} // namespace blink
......
......@@ -20,10 +20,9 @@ DOMDartState::~DOMDartState() {
void DOMDartState::DidSetIsolate() {
Scope dart_scope(this);
x_handle_.Set(this, Dart_NewStringFromCString("x"));
y_handle_.Set(this, Dart_NewStringFromCString("y"));
index_handle_.Set(this, Dart_NewStringFromCString("index"));
value_handle_.Set(this, Dart_NewStringFromCString("_value"));
x_handle_.Set(this, ToDart("x"));
y_handle_.Set(this, ToDart("y"));
value_handle_.Set(this, ToDart("_value"));
Dart_Handle sky_library = DartBuiltin::LookupLibrary("dart:sky");
color_class_.Set(this, Dart_GetType(sky_library, ToDart("Color"), 0, 0));
......
......@@ -36,7 +36,6 @@ class DOMDartState : public DartState {
// Cached handles to strings used in Dart/C++ conversions.
Dart_Handle x_handle() { return x_handle_.value(); }
Dart_Handle y_handle() { return y_handle_.value(); }
Dart_Handle index_handle() { return index_handle_.value(); }
Dart_Handle value_handle() { return value_handle_.value(); }
Dart_Handle color_class() { return color_class_.value(); }
......@@ -47,7 +46,6 @@ class DOMDartState : public DartState {
DartPersistentValue x_handle_;
DartPersistentValue y_handle_;
DartPersistentValue index_handle_;
DartPersistentValue value_handle_;
DartPersistentValue color_class_;
};
......
......@@ -77,7 +77,7 @@ struct DartConverterInteger {
static T FromDart(Dart_Handle handle) {
int64_t result = 0;
Dart_IntegerToInt64(handle, &result);
return result;
return static_cast<T>(result);
}
static T FromArguments(Dart_NativeArguments args,
......@@ -85,7 +85,7 @@ struct DartConverterInteger {
Dart_Handle& exception) {
int64_t result = 0;
Dart_GetNativeIntegerArgument(args, index, &result);
return result;
return static_cast<T>(result);
}
};
......@@ -158,6 +158,24 @@ struct DartConverter<float> : public DartConverterFloatingPoint<float> {};
template <>
struct DartConverter<double> : public DartConverterFloatingPoint<double> {};
////////////////////////////////////////////////////////////////////////////////
// Enums
template <typename T>
struct DartConverterEnum {
static T FromArguments(Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
Dart_Handle enum_handle = Dart_GetNativeArgument(args, index);
Dart_Handle index_handle =
Dart_GetField(enum_handle, DartState::Current()->index_handle());
uint64_t enum_index = 0;
Dart_IntegerToUint64(index_handle, &enum_index);
return static_cast<T>(enum_index);
}
};
////////////////////////////////////////////////////////////////////////////////
// Strings
......
......@@ -6,6 +6,7 @@
#include "sky/engine/tonic/dart_state.h"
#include "sky/engine/tonic/dart_class_library.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_exception_factory.h"
#include "sky/engine/tonic/dart_string_cache.h"
#include "sky/engine/tonic/dart_timer_heap.h"
......@@ -31,6 +32,14 @@ DartState::DartState()
DartState::~DartState() {
}
void DartState::DidSetIsolateInternal() {
{
Scope dart_scope(this);
index_handle_.Set(this, ToDart("index"));
}
DidSetIsolate();
}
DartState* DartState::From(Dart_Isolate isolate) {
return static_cast<DartState*>(Dart_IsolateData(isolate));
}
......
......@@ -11,6 +11,7 @@
#include "dart/runtime/include/dart_api.h"
#include "sky/engine/tonic/dart_api_scope.h"
#include "sky/engine/tonic/dart_isolate_scope.h"
#include "sky/engine/tonic/dart_persistent_value.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
......@@ -50,7 +51,7 @@ class DartState : public base::SupportsUserData {
void set_isolate(Dart_Isolate isolate) {
CHECK(!isolate_);
isolate_ = isolate;
DidSetIsolate();
DidSetIsolateInternal();
}
DartClassLibrary& class_library() { return *class_library_; }
......@@ -58,9 +59,13 @@ class DartState : public base::SupportsUserData {
DartExceptionFactory& exception_factory() { return *exception_factory_; }
DartTimerHeap& timer_heap() { return *timer_heap_; }
Dart_Handle index_handle() { return index_handle_.value(); }
virtual void DidSetIsolate() {}
private:
void DidSetIsolateInternal();
Dart_Isolate isolate_;
OwnPtr<DartClassLibrary> class_library_;
OwnPtr<DartStringCache> string_cache_;
......@@ -68,6 +73,7 @@ class DartState : public base::SupportsUserData {
OwnPtr<DartTimerHeap> timer_heap_;
base::WeakPtrFactory<DartState> weak_factory_;
DartPersistentValue index_handle_;
DISALLOW_COPY_AND_ASSIGN(DartState);
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册