提交 2e693b17 编写于 作者: A Adam Barth

Remove IDL from Shader subclasses

- Gradient
- ImageShader
上级 610ab574
......@@ -8,10 +8,12 @@
#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/CanvasGradient.h"
#include "sky/engine/core/painting/ColorFilter.h"
#include "sky/engine/core/painting/MaskFilter.h"
#include "sky/engine/core/painting/DrawLooperLayerInfo.h"
#include "sky/engine/core/painting/ImageShader.h"
#include "sky/engine/core/painting/LayerDrawLooperBuilder.h"
#include "sky/engine/core/painting/MaskFilter.h"
#include "sky/engine/core/painting/painting.h"
#include "sky/engine/core/text/Paragraph.h"
#include "sky/engine/core/text/ParagraphBuilder.h"
......@@ -45,10 +47,12 @@ const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
void DartUI::InitForIsolate() {
if (!g_natives) {
g_natives = new DartLibraryNatives();
CanvasGradient::RegisterNatives(g_natives);
ColorFilter::RegisterNatives(g_natives);
DartRuntimeHooks::RegisterNatives(g_natives);
DrawLooperLayerInfo::RegisterNatives(g_natives);
ImageShader::RegisterNatives(g_natives);
LayerDrawLooperBuilder::RegisterNatives(g_natives);
ColorFilter::RegisterNatives(g_natives);
MaskFilter::RegisterNatives(g_natives);
Painting::RegisterNatives(g_natives);
Paragraph::RegisterNatives(g_natives);
......
......@@ -235,13 +235,10 @@ sky_core_files = [
core_idl_files = get_path_info([
"painting/Canvas.idl",
"painting/Gradient.idl",
"painting/Image.idl",
"painting/ImageShader.idl",
"painting/Path.idl",
"painting/Picture.idl",
"painting/PictureRecorder.idl",
"painting/Shader.idl",
],
"abspath")
......@@ -256,8 +253,6 @@ core_dart_files = get_path_info([
"dart/window.dart",
"painting/Color.dart",
"painting/FilterQuality.dart",
"painting/Gradient.dart",
"painting/ImageShader.dart",
"painting/Offset.dart",
"painting/OffsetBase.dart",
"painting/Paint.dart",
......
......@@ -83,3 +83,76 @@ class ColorFilter extends NativeFieldWrapperClass2 {
_constructor(color, transferMode);
}
}
abstract class Shader extends NativeFieldWrapperClass2 {
}
/// Defines what happens at the edge of the gradient.
enum TileMode {
/// Edge is clamped to the final color.
clamp,
/// Edge is repeated from first color to last.
repeated,
/// Edge is mirrored from last color to first.
mirror
}
void _validateColorStops(List<Color> colors, List<double> colorStops) {
if (colorStops != null && (colors == null || colors.length != colorStops.length)) {
throw new ArgumentError(
"[colors] and [colorStops] parameters must be equal length.");
}
}
class Gradient extends Shader {
void _constructor() native "Gradient_constructor";
void _initLinear(List<Point> endPoints, List<Color> colors, List<double> colorStops, int tileMode) native "Gradient_initLinear";
void _initRadial(Point center, double radius, List<Color> colors, List<double> colorStops, int tileMode) native "Gradient_initRadial";
/// Creates a linear gradient from [endPoint[0]] to [endPoint[1]]. If
/// [colorStops] is provided, [colorStops[i]] is a number from 0 to 1 that
/// specifies where [color[i]] begins in the gradient.
// TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead?
Gradient.linear(List<Point> endPoints,
List<Color> colors,
[List<double> colorStops = null,
TileMode tileMode = TileMode.clamp]) {
_constructor();
if (endPoints == null || endPoints.length != 2)
throw new ArgumentError("Expected exactly 2 [endPoints].");
_validateColorStops(colors, colorStops);
_initLinear(endPoints, colors, colorStops, tileMode.index);
}
/// Creates a radial gradient centered at [center] that ends at [radius]
/// distance from the center. If [colorStops] is provided, [colorStops[i]] is
/// a number from 0 to 1 that specifies where [color[i]] begins in the
/// gradient.
Gradient.radial(Point center,
double radius,
List<Color> colors,
[List<double> colorStops = null,
TileMode tileMode = TileMode.clamp]) {
_constructor();
_validateColorStops(colors, colorStops);
_initRadial(center, radius, colors, colorStops, tileMode.index);
}
}
class ImageShader extends Shader {
void _constructor() native "ImageShader_constructor";
void _initWithImage(Image image, int tmx, int tmy, Float64List matrix4) native "ImageShader_initWithImage";
ImageShader(Image image, TileMode tmx, TileMode tmy, Float64List matrix4) {
if (image == null)
throw new ArgumentError("[image] argument cannot be null");
if (tmx == null)
throw new ArgumentError("[tmx] argument cannot be null");
if (tmy == null)
throw new ArgumentError("[tmy] argument cannot be null");
if (matrix4 == null)
throw new ArgumentError("[matrix4] argument cannot be null");
_initWithImage(image, tmx.index, tmy.index, matrix4);
}
}
......@@ -18,7 +18,7 @@ struct CanvasColor {
CanvasColor(SkColor color) : color(color) { }
CanvasColor() : color() { }
operator SkColor() { return color; }
operator SkColor() const { return color; }
};
template <>
......
......@@ -4,8 +4,34 @@
#include "sky/engine/core/painting/CanvasGradient.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_library_natives.h"
namespace blink {
typedef CanvasGradient Gradient; // Because the C++ name doesn't match the Dart name.
static void Gradient_constructor(Dart_NativeArguments args) {
DartCallConstructor(&CanvasGradient::create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(Gradient);
#define FOR_EACH_BINDING(V) \
V(Gradient, initLinear) \
V(Gradient, initRadial)
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
void CanvasGradient::RegisterNatives(DartLibraryNatives* natives) {
natives->Register({
{ "Gradient_constructor", Gradient_constructor, 1, true },
FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
PassRefPtr<CanvasGradient> CanvasGradient::create() {
return adoptRef(new CanvasGradient());
}
......
......@@ -12,16 +12,15 @@
#include "third_party/skia/include/effects/SkGradientShader.h"
namespace blink {
class TileMode {};
class DartLibraryNatives;
template <>
struct DartConverter<TileMode> : public DartConverterEnum<SkShader::TileMode> {};
struct DartConverter<SkShader::TileMode> : public DartConverterInteger<SkShader::TileMode> {};
COMPILE_ASSERT(SkShader::kTileModeCount == 3, Need_to_update_Gradient_dart);
COMPILE_ASSERT(SkShader::kTileModeCount == 3, Need_to_update_TileMode_enum);
class CanvasGradient : public Shader {
DEFINE_WRAPPERTYPEINFO();
DEFINE_WRAPPERTYPEINFO();
public:
~CanvasGradient() override;
static PassRefPtr<CanvasGradient> create();
......@@ -30,12 +29,15 @@ class CanvasGradient : public Shader {
const Vector<SkColor>& colors,
const Vector<float>& color_stops,
SkShader::TileMode tile_mode);
void initRadial(const Point& center,
double radius,
const Vector<SkColor>& colors,
const Vector<float>& color_stops,
SkShader::TileMode tile_mode);
static void RegisterNatives(DartLibraryNatives* natives);
private:
CanvasGradient();
};
......
// 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;
/// Defines what happens at the edge of the gradient.
enum TileMode {
/// Edge is clamped to the final color.
clamp,
/// Edge is repeated from first color to last.
repeated,
/// Edge is mirrored from last color to first.
mirror
}
/// Extends the generated _Gradient interface via the PrivateDart attribute.
class Gradient extends _Gradient {
/// Creates a linear gradient from [endPoint[0]] to [endPoint[1]]. If
/// [colorStops] is provided, [colorStops[i]] is a number from 0 to 1 that
/// specifies where [color[i]] begins in the gradient.
// TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead?
Gradient.linear(List<Point> endPoints,
List<Color> colors,
[List<double> colorStops = null,
TileMode tileMode = TileMode.clamp])
: super() {
if (endPoints == null || endPoints.length != 2)
throw new ArgumentError("Expected exactly 2 [endPoints].");
validateColorStops(colors, colorStops);
this._initLinear(endPoints, colors, colorStops, tileMode);
}
/// Creates a radial gradient centered at [center] that ends at [radius]
/// distance from the center. If [colorStops] is provided, [colorStops[i]] is
/// a number from 0 to 1 that specifies where [color[i]] begins in the
/// gradient.
Gradient.radial(Point center,
double radius,
List<Color> colors,
[List<double> colorStops = null,
TileMode tileMode = TileMode.clamp])
: super() {
validateColorStops(colors, colorStops);
this._initRadial(center, radius, colors, colorStops, tileMode);
}
void validateColorStops(List<Color> colors, List<double> colorStops) {
if (colorStops != null && (colors == null || colors.length != colorStops.length)) {
throw new ArgumentError(
"[colors] and [colorStops] parameters must be equal length.");
}
}
}
// 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.
[
ImplementedAs=CanvasGradient,
PrivateDart,
Constructor()
] interface Gradient : Shader {
void initLinear(Point[] endPoints, Color[] colors, float[] colorStops,
TileMode tileMode);
void initRadial(Point center, double radius, Color[] colors,
float[] colorStops, TileMode tileMode);
};
......@@ -4,8 +4,40 @@
#include "sky/engine/core/painting/ImageShader.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_library_natives.h"
namespace blink {
static void ImageShader_constructor(Dart_NativeArguments args) {
DartCallConstructor(&ImageShader::create, args);
}
static void ImageShader_initWithImage(Dart_NativeArguments args) {
DartArgIterator it(args);
CanvasImage* image = it.GetNext<CanvasImage*>();
SkShader::TileMode tmx = it.GetNext<SkShader::TileMode>();
SkShader::TileMode tmy = it.GetNext<SkShader::TileMode>();
Float64List matrix4 = it.GetNext<Float64List>();
if (it.had_exception())
return;
ExceptionState es;
GetReceiver<ImageShader>(args)->initWithImage(image, tmx, tmy, matrix4, es);
if (es.had_exception())
Dart_ThrowException(es.GetDartException(args, true));
}
IMPLEMENT_WRAPPERTYPEINFO(ImageShader);
void ImageShader::RegisterNatives(DartLibraryNatives* natives) {
natives->Register({
{ "ImageShader_constructor", ImageShader_constructor, 1, true },
{ "ImageShader_initWithImage", ImageShader_initWithImage, 5, true },
});
}
PassRefPtr<ImageShader> ImageShader::create() {
return adoptRef(new ImageShader());
}
......
// 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;
class ImageShader extends _ImageShader {
ImageShader(Image image, TileMode tmx, TileMode tmy, Float64List matrix4) {
if (image == null)
throw new ArgumentError("[image] argument cannot be null");
if (tmx == null)
throw new ArgumentError("[tmx] argument cannot be null");
if (tmy == null)
throw new ArgumentError("[tmy] argument cannot be null");
if (matrix4 == null)
throw new ArgumentError("[matrix4] argument cannot be null");
this._initWithImage(image, tmx, tmy, matrix4);
}
}
......@@ -16,6 +16,7 @@
#include "third_party/skia/include/core/SkMatrix.h"
namespace blink {
class DartLibraryNatives;
class ImageShader : public Shader {
DEFINE_WRAPPERTYPEINFO();
......@@ -29,6 +30,8 @@ class ImageShader : public Shader {
const Float64List& matrix4,
ExceptionState& es);
static void RegisterNatives(DartLibraryNatives* natives);
private:
ImageShader();
};
......
// 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.
[
PrivateDart,
Constructor()
] interface ImageShader : Shader {
[RaisesException] void initWithImage(Image image, TileMode tmx, TileMode tmy, Float64List matrix4);
};
......@@ -29,7 +29,7 @@ Point DartConverter<Point>::FromDart(Dart_Handle handle) {
return result;
}
Point DartConverter<Point>::FromArgumentsWithNullCheck(
Point DartConverter<Point>::FromArguments(
Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
......
......@@ -20,9 +20,14 @@ class Point {
template <>
struct DartConverter<Point> {
static Point FromDart(Dart_Handle handle);
static Point FromArguments(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
static Point FromArgumentsWithNullCheck(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
Dart_Handle& exception) {
return FromArguments(args, index, exception);
}
};
} // namespace blink
......
......@@ -6,6 +6,8 @@
namespace blink {
IMPLEMENT_WRAPPERTYPEINFO(Shader);
Shader::Shader(PassRefPtr<SkShader> shader)
: shader_(shader) {
}
......
// 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.
interface Shader {
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册