提交 9f640454 编写于 作者: M Matt Perry

Sky: Allow clients to specify tile mode for gradients (repeating or mirror).

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1166223004.
上级 9f337a62
...@@ -13,9 +13,11 @@ PassRefPtr<CanvasGradient> CanvasGradient::create() { ...@@ -13,9 +13,11 @@ PassRefPtr<CanvasGradient> CanvasGradient::create() {
void CanvasGradient::initLinear(const Vector<Point>& end_points, void CanvasGradient::initLinear(const Vector<Point>& end_points,
const Vector<SkColor>& colors, const Vector<SkColor>& colors,
const Vector<float>& color_stops) { const Vector<float>& color_stops,
unsigned tile_mode) {
ASSERT(end_points.size() == 2); ASSERT(end_points.size() == 2);
ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr);
ASSERT(tile_mode < SkShader::kTileModeCount);
SkPoint sk_end_points[2]; SkPoint sk_end_points[2];
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
sk_end_points[i] = end_points[i].sk_point; sk_end_points[i] = end_points[i].sk_point;
...@@ -23,19 +25,21 @@ void CanvasGradient::initLinear(const Vector<Point>& end_points, ...@@ -23,19 +25,21 @@ void CanvasGradient::initLinear(const Vector<Point>& end_points,
// TODO(mpcomplete): allow setting the TileMode. // TODO(mpcomplete): allow setting the TileMode.
SkShader* shader = SkGradientShader::CreateLinear( SkShader* shader = SkGradientShader::CreateLinear(
sk_end_points, colors.data(), color_stops.data(), colors.size(), sk_end_points, colors.data(), color_stops.data(), colors.size(),
SkShader::kClamp_TileMode); static_cast<SkShader::TileMode>(tile_mode));
set_shader(adoptRef(shader)); set_shader(adoptRef(shader));
} }
void CanvasGradient::initRadial(const Point& center, void CanvasGradient::initRadial(const Point& center,
double radius, double radius,
const Vector<SkColor>& colors, const Vector<SkColor>& colors,
const Vector<float>& color_stops) { const Vector<float>& color_stops,
unsigned tile_mode) {
ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr);
ASSERT(tile_mode < SkShader::kTileModeCount);
SkShader* shader = SkGradientShader::CreateRadial( SkShader* shader = SkGradientShader::CreateRadial(
center.sk_point, radius, colors.data(), color_stops.data(), colors.size(), center.sk_point, radius, colors.data(), color_stops.data(), colors.size(),
SkShader::kClamp_TileMode); static_cast<SkShader::TileMode>(tile_mode));
set_shader(adoptRef(shader)); set_shader(adoptRef(shader));
} }
......
...@@ -21,11 +21,13 @@ class CanvasGradient : public Shader { ...@@ -21,11 +21,13 @@ class CanvasGradient : public Shader {
void initLinear(const Vector<Point>& end_points, void initLinear(const Vector<Point>& end_points,
const Vector<SkColor>& colors, const Vector<SkColor>& colors,
const Vector<float>& color_stops); const Vector<float>& color_stops,
unsigned tile_mode);
void initRadial(const Point& center, void initRadial(const Point& center,
double radius, double radius,
const Vector<SkColor>& colors, const Vector<SkColor>& colors,
const Vector<float>& color_stops); const Vector<float>& color_stops,
unsigned tile_mode);
private: private:
CanvasGradient(); CanvasGradient();
......
...@@ -4,26 +4,34 @@ ...@@ -4,26 +4,34 @@
part of dart.sky; part of dart.sky;
enum TileMode {
clamp,
repeated,
mirror
}
// Extends the generated _Gradient interface via the PrivateDart attribute. // Extends the generated _Gradient interface via the PrivateDart attribute.
class Gradient extends _Gradient { class Gradient extends _Gradient {
// TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead? // TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead?
Gradient.Linear(List<Point> endPoints, Gradient.Linear(List<Point> endPoints,
List<Color> colors, List<Color> colors,
List<double> colorStops) List<double> colorStops,
[TileMode tileMode = TileMode.clamp])
: super() { : super() {
if (endPoints == null || endPoints.length != 2) if (endPoints == null || endPoints.length != 2)
throw new ArgumentError("Expected exactly 2 [endPoints]."); throw new ArgumentError("Expected exactly 2 [endPoints].");
validateColorStops(colors, colorStops); validateColorStops(colors, colorStops);
this._initLinear(endPoints, colors, colorStops); this._initLinear(endPoints, colors, colorStops, tileMode.index);
} }
Gradient.Radial(Point center, Gradient.Radial(Point center,
double radius, double radius,
List<Color> colors, List<Color> colors,
List<double> colorStops) List<double> colorStops,
[TileMode tileMode = TileMode.clamp])
: super() { : super() {
validateColorStops(colors, colorStops); validateColorStops(colors, colorStops);
this._initRadial(center, radius, colors, colorStops); this._initRadial(center, radius, colors, colorStops, tileMode.index);
} }
void validateColorStops(List<Color> colors, List<double> colorStops) { void validateColorStops(List<Color> colors, List<double> colorStops) {
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
PrivateDart, PrivateDart,
Constructor() Constructor()
] interface Gradient : Shader { ] interface Gradient : Shader {
void initLinear(Point[] endPoints, Color[] colors, float[] colorStops); void initLinear(Point[] endPoints, Color[] colors, float[] colorStops,
/*TileMode*/unsigned long tileMode);
void initRadial(Point center, double radius, Color[] colors, void initRadial(Point center, double radius, Color[] colors,
float[] colorStops); float[] colorStops, /*TileMode*/unsigned long tileMode);
}; };
...@@ -68,9 +68,9 @@ void main() { ...@@ -68,9 +68,9 @@ void main() {
..setPaintBits(-1), ..setPaintBits(-1),
(Paint layerPaint) { (Paint layerPaint) {
Gradient redYellow = new Gradient.Radial( Gradient redYellow = new Gradient.Radial(
new Point(0.0, 0.0), radius, new Point(0.0, 0.0), radius/3.0,
[const Color(0xFFFFFF00), const Color(0xFFFF0000)], [const Color(0xFFFFFF00), const Color(0xFFFF0000)],
null); null, TileMode.mirror);
layerPaint.setShader(redYellow); layerPaint.setShader(redYellow);
}) })
..addLayerOnTop( ..addLayerOnTop(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册