提交 326e2324 编写于 作者: M Matt Perry

Add a Color class to dart:sky.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1161273004
上级 3a7e97e6
......@@ -114,7 +114,9 @@ CPP_SPECIAL_CONVERSION_RULES = {
'boolean': 'bool',
'unrestricted double': 'double',
'unrestricted float': 'float',
'Rect': 'Rect', # Pass Rect by value, not pointer.
# Pass these by value, not pointer.
'Rect': 'Rect',
'Color': 'CanvasColor',
}
......@@ -354,6 +356,7 @@ DART_TO_CPP_VALUE = {
# We should handle it automatically, but map to a String for now.
'StorageType': 'DartUtilities::dartToString(args, {index}, exception, {auto_scope})',
'Rect': 'DartConverter<{implemented_as}>::FromArguments{null_check}(args, {index}, exception)',
'Color': 'DartConverter<CanvasColor>::FromArguments{null_check}(args, {index}, exception)',
}
......@@ -618,6 +621,7 @@ DART_SET_RETURN_VALUE = {
# Typed arrays don't have special Dart* classes for Dart.
'ArrayBuffer': 'Dart_SetReturnValue(args, DartUtilities::arrayBufferToDart({cpp_value}))',
'TypedList': 'Dart_SetReturnValue(args, DartUtilities::arrayBufferViewToDart({cpp_value}))',
'Color': 'DartConverter<CanvasColor>::SetReturnValue(args, {cpp_value})',
}
......
......@@ -837,6 +837,8 @@ sky_core_files = [
"page/SpellCheckerClient.h",
"painting/Canvas.cpp",
"painting/Canvas.h",
"painting/CanvasColor.cpp",
"painting/CanvasColor.h",
"painting/CanvasImage.cpp",
"painting/CanvasImage.h",
"painting/CanvasPath.cpp",
......@@ -1148,6 +1150,7 @@ core_idl_files = get_path_info([
"abspath")
core_dart_files = get_path_info([
"painting/Color.dart",
"painting/Point.dart",
"painting/Rect.dart",
"painting/Size.dart",
......
// 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/CanvasColor.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 {
// Convert dart_color => SkColor.
CanvasColor DartConverter<CanvasColor, void>::FromArgumentsWithNullCheck(
Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
CanvasColor result;
Dart_Handle dart_color = Dart_GetNativeArgument(args, index);
DCHECK(!LogIfError(dart_color));
Dart_Handle value =
Dart_GetField(dart_color, DOMDartState::Current()->value_handle());
uint64_t color = 0;
Dart_Handle rv = Dart_IntegerToUint64(value, &color);
DCHECK(!LogIfError(rv));
DCHECK(color <= 0xffffffff);
result.sk_color = static_cast<SkColor>(color);
return result;
}
void DartConverter<CanvasColor, void>::SetReturnValue(
Dart_NativeArguments args, unsigned val) {
Dart_Handle color_class = DOMDartState::Current()->color_class();
Dart_Handle constructor_args[] = { ToDart(val) };
Dart_SetReturnValue(args,
Dart_New(color_class, Dart_Null(), 1, constructor_args));
}
} // namespace blink
// 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_CORE_PAINTING_CANVASCOLOR_H_
#define SKY_ENGINE_CORE_PAINTING_CANVASCOLOR_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 "third_party/skia/include/core/SkColor.h"
namespace blink {
class CanvasColor {
public:
SkColor sk_color;
};
template<>
struct DartConverter<CanvasColor, void> {
static CanvasColor FromArgumentsWithNullCheck(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
static void SetReturnValue(Dart_NativeArguments args, unsigned val);
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_CANVASCOLOR_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.
part of dart.sky;
class Color {
final int _value;
int get value => _value;
const Color(this._value);
const Color.fromARGB(int a, int r, int g, int b) :
_value = (((a & 0xff) << 24) |
((r & 0xff) << 16) |
((g & 0xff) << 8) |
((b & 0xff) << 0));
}
......@@ -5,6 +5,7 @@
#ifndef SKY_ENGINE_CORE_PAINTING_PAINT_H_
#define SKY_ENGINE_CORE_PAINTING_PAINT_H_
#include "sky/engine/core/painting/CanvasColor.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
......@@ -29,6 +30,7 @@ public:
unsigned color() const { return m_paint.getColor(); }
void setColor(unsigned color) { m_paint.setColor(color); }
void setColor(CanvasColor color) { m_paint.setColor(color.sk_color); }
void setARGB(unsigned a, unsigned r, unsigned g, unsigned b)
{
......
......@@ -6,8 +6,9 @@
Constructor(),
] interface Paint {
attribute boolean isAntiAlias;
attribute unsigned long color;
attribute Color color;
// TODO(mpcomplete): remove this in favor of assigning to |color|.
void setARGB(unsigned long a, unsigned long r, unsigned long g, unsigned long b);
void setDrawLooper(DrawLooper looper);
void setColorFilter(ColorFilter filter);
......
......@@ -7,6 +7,7 @@
#include "sky/engine/core/dom/Document.h"
#include "sky/engine/core/script/dart_loader.h"
#include "sky/engine/tonic/dart_builtin.h"
namespace blink {
......@@ -22,6 +23,9 @@ void DOMDartState::DidSetIsolate() {
x_handle_.Set(this, Dart_NewStringFromCString("x"));
y_handle_.Set(this, Dart_NewStringFromCString("y"));
value_handle_.Set(this, Dart_NewStringFromCString("_value"));
Dart_Handle sky_library = DartBuiltin::LookupLibrary("dart:sky");
color_class_.Set(this, Dart_GetType(sky_library, ToDart("Color"), 0, 0));
}
DOMDartState* DOMDartState::Current() {
......
......@@ -35,6 +35,7 @@ class DOMDartState : public DartState {
Dart_Handle x_handle() { return x_handle_.value(); }
Dart_Handle y_handle() { return y_handle_.value(); }
Dart_Handle value_handle() { return value_handle_.value(); }
Dart_Handle color_class() { return color_class_.value(); }
private:
RefPtr<Document> document_;
......@@ -43,6 +44,7 @@ class DOMDartState : public DartState {
DartPersistentValue x_handle_;
DartPersistentValue y_handle_;
DartPersistentValue value_handle_;
DartPersistentValue color_class_;
};
} // namespace blink
......
......@@ -22,7 +22,7 @@ void main() {
context.clipRect(new Rect.fromLTRB(0.0, 0.0, context.width, radius));
context.translate(mid.x, mid.y);
paint.setARGB(128, 255, 0, 255);
paint.color = const Color.fromARGB(128, 255, 0, 255);
context.rotateDegrees(45.0);
context.drawRect(new Rect.fromLTRB(-radius, -radius, radius, radius),
......@@ -35,7 +35,7 @@ void main() {
0.0, 0.0, 1.0
];
context.concat(scaleMatrix);
paint.setARGB(128, 0, 255, 0);
paint.color = const Color.fromARGB(128, 0, 255, 0);
context.drawCircle(0.0, 0.0, radius, paint);
context.restore();
......@@ -46,19 +46,19 @@ void main() {
new DrawLooperLayerInfo()
..setOffset(150.0, 0.0)..setPaintBits(-1)..setColorMode(1),
(Paint layerPaint) {
layerPaint.setARGB(128, 255, 255, 0);
layerPaint.color = const Color.fromARGB(128, 255, 255, 0);
layerPaint.setColorFilter(new ColorFilter(0x770000ff, 5));
})
..addLayerOnTop(
new DrawLooperLayerInfo()..setOffset(75.0, 75.0)..setColorMode(1),
(Paint layerPaint) {
layerPaint.setARGB(128, 255, 0, 0);
layerPaint.color = const Color.fromARGB(128, 255, 0, 0);
})
..addLayerOnTop(
new DrawLooperLayerInfo()..setOffset(225.0, 75.0),
(Paint layerPaint) {
// Since this layer uses a DST color mode, this has no effect.
layerPaint.setARGB(128, 255, 0, 0);
layerPaint.color = const Color.fromARGB(128, 255, 0, 0);
});
paint.setDrawLooper(builder.build());
context.drawCircle(0.0, 0.0, radius, paint);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册