提交 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() {
void CanvasGradient::initLinear(const Vector<Point>& end_points,
const Vector<SkColor>& colors,
const Vector<float>& color_stops) {
const Vector<float>& color_stops,
unsigned 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;
......@@ -23,19 +25,21 @@ 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(),
SkShader::kClamp_TileMode);
static_cast<SkShader::TileMode>(tile_mode));
set_shader(adoptRef(shader));
}
void CanvasGradient::initRadial(const Point& center,
double radius,
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(tile_mode < SkShader::kTileModeCount);
SkShader* shader = SkGradientShader::CreateRadial(
center.sk_point, radius, colors.data(), color_stops.data(), colors.size(),
SkShader::kClamp_TileMode);
static_cast<SkShader::TileMode>(tile_mode));
set_shader(adoptRef(shader));
}
......
......@@ -21,11 +21,13 @@ class CanvasGradient : public Shader {
void initLinear(const Vector<Point>& end_points,
const Vector<SkColor>& colors,
const Vector<float>& color_stops);
const Vector<float>& color_stops,
unsigned tile_mode);
void initRadial(const Point& center,
double radius,
const Vector<SkColor>& colors,
const Vector<float>& color_stops);
const Vector<float>& color_stops,
unsigned tile_mode);
private:
CanvasGradient();
......
......@@ -4,26 +4,34 @@
part of dart.sky;
enum TileMode {
clamp,
repeated,
mirror
}
// Extends the generated _Gradient interface via the PrivateDart attribute.
class Gradient extends _Gradient {
// TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead?
Gradient.Linear(List<Point> endPoints,
List<Color> colors,
List<double> colorStops)
List<double> colorStops,
[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);
this._initLinear(endPoints, colors, colorStops, tileMode.index);
}
Gradient.Radial(Point center,
double radius,
List<Color> colors,
List<double> colorStops)
List<double> colorStops,
[TileMode tileMode = TileMode.clamp])
: super() {
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) {
......
......@@ -7,7 +7,8 @@
PrivateDart,
Constructor()
] 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,
float[] colorStops);
float[] colorStops, /*TileMode*/unsigned long tileMode);
};
......@@ -68,9 +68,9 @@ void main() {
..setPaintBits(-1),
(Paint layerPaint) {
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)],
null);
null, TileMode.mirror);
layerPaint.setShader(redYellow);
})
..addLayerOnTop(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册