提交 8e475a95 编写于 作者: A Adam Barth 提交者: GitHub

Move most of //sky/engine/core/painting to //flutter/lib/ui/painting (#2752)

These parts don't depend on engine anymore. Also reformat them to match Google
C++ style.
上级 be96958c
# Copyright 2016 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.
source_set("ui") {
sources = [
"painting/color_filter.cc",
"painting/color_filter.h",
"painting/gradient.cc",
"painting/gradient.h",
"painting/image.cc",
"painting/image_filter.cc",
"painting/image_filter.h",
"painting/image.h",
"painting/image_shader.cc",
"painting/image_shader.h",
"painting/mask_filter.cc",
"painting/mask_filter.h",
"painting/matrix.cc",
"painting/matrix.h",
"painting/path.cc",
"painting/path.h",
"painting/picture.cc",
"painting/picture.h",
"painting/rrect.cc",
"painting/rrect.h",
"painting/shader.cc",
"painting/shader.h",
]
deps = [
"//base",
"//flutter/tonic",
"//skia",
]
}
......@@ -4,6 +4,7 @@
dart_ui_files = [
"//flutter/lib/ui/geometry.dart",
"//flutter/lib/ui/painting.dart",
"//flutter/lib/ui/ui.dart",
]
......
......@@ -4,6 +4,413 @@
part of dart_ui;
Color _scaleAlpha(Color a, double factor) {
return a.withAlpha((a.alpha * factor).round());
}
/// An immutable 32 bit color value in ARGB
class Color {
/// Construct a color from the lower 32 bits of an int.
///
/// Bits 24-31 are the alpha value.
/// Bits 16-23 are the red value.
/// Bits 8-15 are the green value.
/// Bits 0-7 are the blue value.
const Color(int value) : _value = (value & 0xFFFFFFFF);
/// Construct a color from the lower 8 bits of four integers.
const Color.fromARGB(int a, int r, int g, int b) :
_value = ((((a & 0xff) << 24) |
((r & 0xff) << 16) |
((g & 0xff) << 8) |
((b & 0xff) << 0)) & 0xFFFFFFFF);
/// A 32 bit value representing this color.
///
/// Bits 24-31 are the alpha value.
/// Bits 16-23 are the red value.
/// Bits 8-15 are the green value.
/// Bits 0-7 are the blue value.
int get value => _value;
final int _value;
/// The alpha channel of this color in an 8 bit value.
int get alpha => (0xff000000 & _value) >> 24;
/// The alpha channel of this color as a double.
double get opacity => alpha / 0xFF;
/// The red channel of this color in an 8 bit value.
int get red => (0x00ff0000 & _value) >> 16;
/// The green channel of this color in an 8 bit value.
int get green => (0x0000ff00 & _value) >> 8;
/// The blue channel of this color in an 8 bit value.
int get blue => (0x000000ff & _value) >> 0;
/// Returns a new color that matches this color with the alpha channel
/// replaced with a (which ranges from 0 to 255).
Color withAlpha(int a) {
return new Color.fromARGB(a, red, green, blue);
}
/// Returns a new color that matches this color with the alpha channel
/// replaced with the given opacity (which ranges from 0.0 to 1.0).
Color withOpacity(double opacity) {
assert(opacity >= 0.0 && opacity <= 1.0);
return withAlpha((255.0 * opacity).round());
}
/// Returns a new color that matches this color with the red channel replaced
/// with r.
Color withRed(int r) {
return new Color.fromARGB(alpha, r, green, blue);
}
/// Returns a new color that matches this color with the green channel
/// replaced with g.
Color withGreen(int g) {
return new Color.fromARGB(alpha, red, g, blue);
}
/// Returns a new color that matches this color with the blue channel replaced
/// with b.
Color withBlue(int b) {
return new Color.fromARGB(alpha, red, green, b);
}
/// Linearly interpolate between two colors
///
/// If either color is null, this function linearly interpolates from a
/// transparent instance of the other color.
static Color lerp(Color a, Color b, double t) {
if (a == null && b == null)
return null;
if (a == null)
return _scaleAlpha(b, t);
if (b == null)
return _scaleAlpha(a, 1.0 - t);
return new Color.fromARGB(
lerpDouble(a.alpha, b.alpha, t).toInt(),
lerpDouble(a.red, b.red, t).toInt(),
lerpDouble(a.green, b.green, t).toInt(),
lerpDouble(a.blue, b.blue, t).toInt()
);
}
@override
bool operator ==(dynamic other) {
if (other is! Color)
return false;
final Color typedOther = other;
return value == typedOther.value;
}
@override
int get hashCode => _value.hashCode;
@override
String toString() => "Color(0x${_value.toRadixString(16).padLeft(8, '0')})";
}
/// Algorithms to use when painting on the canvas.
///
/// When drawing a shape or image onto a canvas, different algorithms
/// can be used to blend the pixels. The image below shows the effects
/// of these modes.
///
/// [![Open Skia fiddle to view image.](https://flutter.io/images/transfer_mode.png)](https://fiddle.skia.org/c/864acd0659c7a866ea7296a3184b8bdd)
///
/// See [Paint.transferMode].
enum TransferMode {
// This list comes from Skia's SkXfermode.h and the values (order) should be
// kept in sync.
// See: https://skia.org/user/api/skpaint#SkXfermode
clear,
src,
dst,
srcOver,
dstOver,
srcIn,
dstIn,
srcOut,
dstOut,
srcATop,
dstATop,
xor,
plus,
modulate,
// Following blend modes are defined in the CSS Compositing standard.
screen, // The last coeff mode.
overlay,
darken,
lighten,
colorDodge,
colorBurn,
hardLight,
softLight,
difference,
exclusion,
multiply, // The last separable mode.
hue,
saturation,
color,
luminosity,
}
/// Quality levels for image filters.
///
/// See [Paint.filterQuality].
enum FilterQuality {
// This list comes from Skia's SkFilterQuality.h and the values (order) should
// be kept in sync.
/// Fastest possible filtering, albeit also the lowest quality.
///
/// Typically this implies nearest-neighbour filtering.
none,
/// Better quality than [none], faster than [medium].
///
/// Typically this implies bilinear interpolation.
low,
/// Better quality than [low], faster than [high].
///
/// Typically this implies a combination of bilinear interpolation and
/// pyramidal parametric prefiltering (mipmaps).
medium,
/// Best possible quality filtering, albeit also the slowest.
///
/// Typically this implies bicubic interpolation or better.
high,
}
/// Styles to use for line endings.
///
/// See [Paint.strokeCap].
enum StrokeCap {
/// Begin and end contours with a flat edge and no extension.
butt,
/// Begin and end contours with a semi-circle extension.
round,
/// Begin and end contours with a half square extension. This is
/// similar to extending each contour by half the stroke width (as
/// given by [Paint.strokeWidth]).
square,
}
/// Strategies for painting shapes and paths on a canvas.
///
/// See [Paint.style].
enum PaintingStyle {
// This list comes from Skia's SkPaint.h and the values (order) should be kept
// in sync.
/// Apply the [Paint] to the inside of the shape. For example, when
/// applied to the [Paint.drawCircle] call, this results in a disc
/// of the given size being painted.
fill,
/// Apply the [Paint] to the edge of the shape. For example, when
/// applied to the [Paint.drawCircle] call, this results is a hoop
/// of the given size being painted. The line drawn on the edge will
/// be the width given by the [Paint.strokeWidth] property.
stroke,
/// Apply the [Paint] to the inside of the shape and the edge of the
/// shape at the same time. The resulting drawing is similar to what
/// would be achieved by inflating the shape by half the stroke
/// width (as given by [Paint.strokeWidth]), and then using [fill].
strokeAndFill,
}
/// A description of the style to use when drawing on a [Canvas].
///
/// Most APIs on [Canvas] take a [Paint] object to describe the style
/// to use for that operation.
class Paint {
/// Whether to paint inside shapes, the edges of shapes, or both.
///
/// If null, defaults to [PaintingStyle.fill].
PaintingStyle style;
static const PaintingStyle _kDefaultStyle = PaintingStyle.fill;
/// How wide to make edges drawn when [style] is set to
/// [PaintingStyle.stroke] or [PaintingStyle.strokeAndFill]. The
/// width is given in logical pixels measured in the direction
/// orthogonal to the direction of the path.
///
/// The values null and 0.0 correspond to a hairline width.
double strokeWidth;
static const double _kDefaultStrokeWidth = 0.0;
/// The kind of finish to place on the end of lines drawn when
/// [style] is set to [PaintingStyle.stroke] or
/// [PaintingStyle.strokeAndFill].
///
/// If null, defaults to [StrokeCap.butt], i.e. no caps.
StrokeCap strokeCap;
static const StrokeCap _kDefaultStrokeCap = StrokeCap.butt;
/// Whether to apply anti-aliasing to lines and images drawn on the
/// canvas.
///
/// Defaults to true. The value null is treated as false.
bool isAntiAlias = true;
/// The color to use when stroking or filling a shape.
///
/// Defaults to black.
///
/// See also:
///
/// * [style], which controls whether to stroke or fill (or both).
/// * [colorFilter], which overrides [color].
/// * [shader], which overrides [color] with more elaborate effects.
///
/// This color is not used when compositing. To colorize a layer, use
/// [colorFilter].
Color color = _kDefaultPaintColor;
static const Color _kDefaultPaintColor = const Color(0xFF000000);
/// A mask filter (for example, a blur) to apply to a shape after it has been
/// drawn but before it has been composited into the image.
///
/// See [MaskFilter] for details.
MaskFilter maskFilter;
/// Controls the performance vs quality trade-off to use when applying
/// filters, such as [maskFilter], or when drawing images, as with
/// [Canvas.drawImageRect] or [Canvas.drawImageNine].
// TODO(ianh): verify that the image drawing methods actually respect this
FilterQuality filterQuality;
/// The shader to use when stroking or filling a shape.
///
/// When this is null, the [color] is used instead.
///
/// See also:
///
/// * [Gradient], a shader that paints a color gradient.
/// * [ImageShader], a shader that tiles an [Image].
/// * [colorFilter], which overrides [shader].
/// * [color], which is used if [shader] and [colorFilter] are null.
Shader shader;
/// A color filter to apply when a shape is drawn or when a layer is
/// composited.
///
/// See [ColorFilter] for details.
///
/// When a shape is being drawn, [colorFilter] overrides [color] and [shader].
ColorFilter colorFilter;
/// A transfer mode to apply when a shape is drawn or a layer is composited.
///
/// The source colors are from the shape being drawn (e.g. from
/// [Canvas.drawPath]) or layer being composited (the graphics that were drawn
/// between the [Canvas.saveLayer] and [Canvas.restore] calls), after applying
/// the [colorFilter], if any.
///
/// The destination colors are from the background onto which the shape or
/// layer is being composited.
///
/// If null, defaults to [TransferMode.srcOver].
TransferMode transferMode;
static const TransferMode _kDefaultTransferMode = TransferMode.srcOver;
// Must match PaintFields enum in Paint.cpp.
dynamic get _value {
// The most common usage is a Paint with no options besides a color and
// anti-aliasing. In this case, save time by just returning the color
// as an int.
if ((style == null || style == _kDefaultStyle) &&
(strokeWidth == null || strokeWidth == _kDefaultStrokeWidth) &&
(strokeCap == null || strokeCap == _kDefaultStrokeCap) &&
isAntiAlias &&
color != null &&
(transferMode == null || transferMode == _kDefaultTransferMode) &&
colorFilter == null &&
maskFilter == null &&
filterQuality == null &&
shader == null) {
return color.value;
}
return <dynamic>[
style?.index,
strokeWidth,
strokeCap?.index,
isAntiAlias,
color.value,
transferMode?.index,
colorFilter,
maskFilter,
filterQuality?.index,
shader,
];
}
@override
String toString() {
StringBuffer result = new StringBuffer();
String semicolon = '';
result.write('Paint(');
if (style == PaintingStyle.stroke || style == PaintingStyle.strokeAndFill) {
result.write('$style');
if (strokeWidth != null && strokeWidth != 0.0)
result.write(' $strokeWidth');
else
result.write(' hairline');
if (strokeCap != null && strokeCap != _kDefaultStrokeCap)
result.write(' $strokeCap');
semicolon = '; ';
}
if (isAntiAlias != true) {
result.write('${semicolon}antialias off');
semicolon = '; ';
}
if (color != _kDefaultPaintColor) {
if (color != null)
result.write('$semicolon$color');
else
result.write('${semicolon}no color');
semicolon = '; ';
}
if (transferMode != null) {
result.write('$semicolon$transferMode');
semicolon = '; ';
}
if (colorFilter != null) {
result.write('${semicolon}colorFilter: $colorFilter');
semicolon = '; ';
}
if (maskFilter != null) {
result.write('${semicolon}maskFilter: $maskFilter');
semicolon = '; ';
}
if (filterQuality != null) {
result.write('${semicolon}filterQuality: $filterQuality');
semicolon = '; ';
}
if (shader != null)
result.write('${semicolon}shader: $shader');
result.write(')');
return result.toString();
}
}
/// Opaque handle to raw decoded image data (pixels).
///
/// To obtain an Image object, use the [decodeImageFromDataPipe] or
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/ColorFilter.h"
#include "flutter/lib/ui/painting/color_filter.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
......@@ -12,7 +12,7 @@
namespace blink {
static void ColorFilter_constructor(Dart_NativeArguments args) {
DartCallConstructor(&ColorFilter::create, args);
DartCallConstructor(&ColorFilter::Create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(ui, ColorFilter);
......@@ -23,7 +23,7 @@ void ColorFilter::RegisterNatives(DartLibraryNatives* natives) {
});
}
scoped_refptr<ColorFilter> ColorFilter::create(int color,
scoped_refptr<ColorFilter> ColorFilter::Create(int color,
int transfer_mode) {
return new ColorFilter(SkColorFilter::MakeModeFilter(
static_cast<SkColor>(color),
......@@ -31,7 +31,7 @@ scoped_refptr<ColorFilter> ColorFilter::create(int color,
}
ColorFilter::ColorFilter(sk_sp<SkColorFilter> filter)
: filter_(filter) {
: filter_(std::move(filter)) {
}
ColorFilter::~ColorFilter() {
......
......@@ -2,8 +2,8 @@
// 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_COLORFILTER_H_
#define SKY_ENGINE_CORE_PAINTING_COLORFILTER_H_
#ifndef FLUTTER_LIB_UI_PAINTING_COLOR_FILTER_H_
#define FLUTTER_LIB_UI_PAINTING_COLOR_FILTER_H_
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
......@@ -16,9 +16,9 @@ class ColorFilter : public base::RefCountedThreadSafe<ColorFilter>, public DartW
DEFINE_WRAPPERTYPEINFO();
public:
~ColorFilter() override;
static scoped_refptr<ColorFilter> create(int color, int transfer_mode);
static scoped_refptr<ColorFilter> Create(int color, int transfer_mode);
sk_sp<SkColorFilter> filter() { return filter_; }
const sk_sp<SkColorFilter>& filter() { return filter_; }
static void RegisterNatives(DartLibraryNatives* natives);
......@@ -30,4 +30,4 @@ class ColorFilter : public base::RefCountedThreadSafe<ColorFilter>, public DartW
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_COLORFILTER_H_
#endif // FLUTTER_LIB_UI_PAINTING_COLOR_FILTER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/CanvasGradient.h"
#include "flutter/lib/ui/painting/gradient.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
......@@ -14,7 +14,7 @@ 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);
DartCallConstructor(&CanvasGradient::Create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(ui, Gradient);
......@@ -32,7 +32,7 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
scoped_refptr<CanvasGradient> CanvasGradient::create() {
scoped_refptr<CanvasGradient> CanvasGradient::Create() {
return new CanvasGradient();
}
......@@ -54,8 +54,8 @@ void CanvasGradient::initLinear(const Float32List& end_points,
tile_mode));
}
void CanvasGradient::initRadial(double centerX,
double centerY,
void CanvasGradient::initRadial(double center_x,
double center_y,
double radius,
const Int32List& colors,
const Float32List& color_stops,
......@@ -65,7 +65,7 @@ void CanvasGradient::initRadial(double centerX,
static_assert(sizeof(SkColor) == sizeof(int32_t), "SkColor doesn't use int32_t.");
set_shader(SkGradientShader::MakeRadial(
SkPoint::Make(centerX, centerY),
SkPoint::Make(center_x, center_y),
radius,
reinterpret_cast<const SkColor*>(colors.data()),
color_stops.data(),
......
......@@ -2,20 +2,21 @@
// 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_CANVASGRADIENT_H_
#define SKY_ENGINE_CORE_PAINTING_CANVASGRADIENT_H_
#ifndef FLUTTER_LIB_UI_PAINTING_GRADIENT_H_
#define FLUTTER_LIB_UI_PAINTING_GRADIENT_H_
#include "flutter/lib/ui/painting/shader.h"
#include "flutter/tonic/dart_wrappable.h"
#include "flutter/tonic/float32_list.h"
#include "flutter/tonic/int32_list.h"
#include "sky/engine/core/painting/Shader.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
namespace blink {
class DartLibraryNatives;
template <>
struct DartConverter<SkShader::TileMode> : public DartConverterInteger<SkShader::TileMode> {};
struct DartConverter<SkShader::TileMode>
: public DartConverterInteger<SkShader::TileMode> {};
static_assert(SkShader::kTileModeCount == 3, "Need to update tile mode enum");
......@@ -23,15 +24,15 @@ class CanvasGradient : public Shader {
DEFINE_WRAPPERTYPEINFO();
public:
~CanvasGradient() override;
static scoped_refptr<CanvasGradient> create();
static scoped_refptr<CanvasGradient> Create();
void initLinear(const Float32List& end_points,
const Int32List& colors,
const Float32List& color_stops,
SkShader::TileMode tile_mode);
void initRadial(double centerX,
double centerY,
void initRadial(double center_x,
double center_y,
double radius,
const Int32List& colors,
const Float32List& color_stops,
......@@ -45,4 +46,4 @@ class CanvasGradient : public Shader {
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_CANVASGRADIENT_H_
#endif // FLUTTER_LIB_UI_PAINTING_GRADIENT_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/CanvasImage.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
......@@ -34,14 +34,6 @@ CanvasImage::CanvasImage() {
CanvasImage::~CanvasImage() {
}
int CanvasImage::width() {
return image_->width();
}
int CanvasImage::height() {
return image_->height();
}
void CanvasImage::dispose() {
ClearDartWrapper();
}
......
......@@ -2,8 +2,8 @@
// 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_CANVASIMAGE_H_
#define SKY_ENGINE_CORE_PAINTING_CANVASIMAGE_H_
#ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_H_
#define FLUTTER_LIB_UI_PAINTING_IMAGE_H_
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
......@@ -17,14 +17,14 @@ class CanvasImage final : public base::RefCountedThreadSafe<CanvasImage>,
DEFINE_WRAPPERTYPEINFO();
public:
~CanvasImage() override;
static scoped_refptr<CanvasImage> create() { return new CanvasImage(); }
static scoped_refptr<CanvasImage> Create() { return new CanvasImage(); }
int width();
int height();
int width() { return image_->width(); }
int height() { return image_->height(); }
void dispose();
sk_sp<SkImage> image() const { return image_; }
void setImage(sk_sp<SkImage> image) { image_ = image; }
const sk_sp<SkImage>& image() const { return image_; }
void set_image(sk_sp<SkImage> image) { image_ = std::move(image); }
static void RegisterNatives(DartLibraryNatives* natives);
......@@ -36,4 +36,4 @@ class CanvasImage final : public base::RefCountedThreadSafe<CanvasImage>,
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_CANVASIMAGE_H_
#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/ImageFilter.h"
#include "flutter/lib/ui/painting/image_filter.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
......@@ -15,7 +15,7 @@
namespace blink {
static void ImageFilter_constructor(Dart_NativeArguments args) {
DartCallConstructor(&ImageFilter::create, args);
DartCallConstructor(&ImageFilter::Create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(ui, ImageFilter);
......@@ -34,7 +34,7 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
scoped_refptr<ImageFilter> ImageFilter::create() {
scoped_refptr<ImageFilter> ImageFilter::Create() {
return new ImageFilter();
}
......@@ -49,11 +49,11 @@ void ImageFilter::initImage(CanvasImage* image) {
}
void ImageFilter::initPicture(Picture* picture) {
filter_ = SkPictureImageFilter::Make(picture->toSkia());
filter_ = SkPictureImageFilter::Make(picture->picture());
}
void ImageFilter::initBlur(double sigmaX, double sigmaY) {
filter_ = SkBlurImageFilter::Make(sigmaX, sigmaY, nullptr);
void ImageFilter::initBlur(double sigma_x, double sigma_y) {
filter_ = SkBlurImageFilter::Make(sigma_x, sigma_y, nullptr);
}
} // namespace blink
......@@ -2,28 +2,29 @@
// 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_IMAGE_FILTER_H_
#define SKY_ENGINE_CORE_PAINTING_IMAGE_FILTER_H_
#ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_FILTER_H_
#define FLUTTER_LIB_UI_PAINTING_IMAGE_FILTER_H_
#include "base/memory/ref_counted.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/picture.h"
#include "flutter/tonic/dart_wrappable.h"
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/core/painting/Picture.h"
#include "third_party/skia/include/core/SkImageFilter.h"
namespace blink {
class ImageFilter : public base::RefCountedThreadSafe<ImageFilter>, public DartWrappable {
class ImageFilter : public base::RefCountedThreadSafe<ImageFilter>,
public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
~ImageFilter() override;
static scoped_refptr<ImageFilter> create();
static scoped_refptr<ImageFilter> Create();
void initImage(CanvasImage* image);
void initPicture(Picture*);
void initBlur(double sigmaX, double sigmaY);
void initBlur(double sigma_x, double sigma_y);
sk_sp<SkImageFilter> toSkia() { return filter_; }
const sk_sp<SkImageFilter>& filter() { return filter_; }
static void RegisterNatives(DartLibraryNatives* natives);
......@@ -35,4 +36,4 @@ class ImageFilter : public base::RefCountedThreadSafe<ImageFilter>, public DartW
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_IMAGE_FILTER_H_
#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_FILTER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/ImageShader.h"
#include "flutter/lib/ui/painting/image_shader.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
......@@ -12,7 +12,7 @@
namespace blink {
static void ImageShader_constructor(Dart_NativeArguments args) {
DartCallConstructor(&ImageShader::create, args);
DartCallConstructor(&ImageShader::Create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(ui, ImageShader);
......@@ -29,7 +29,7 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
scoped_refptr<ImageShader> ImageShader::create() {
scoped_refptr<ImageShader> ImageShader::Create() {
return new ImageShader();
}
......@@ -38,7 +38,7 @@ void ImageShader::initWithImage(CanvasImage* image,
SkShader::TileMode tmy,
const Float64List& matrix4) {
DCHECK(image != NULL);
SkMatrix sk_matrix = toSkMatrix(matrix4);
SkMatrix sk_matrix = ToSkMatrix(matrix4);
SkBitmap bitmap;
image->image()->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode);
......
......@@ -2,15 +2,15 @@
// 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_IMAGESHADER_H_
#define SKY_ENGINE_CORE_PAINTING_IMAGESHADER_H_
#ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_SHADER_H_
#define FLUTTER_LIB_UI_PAINTING_IMAGE_SHADER_H_
#include "flutter/lib/ui/painting/gradient.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/matrix.h"
#include "flutter/lib/ui/painting/shader.h"
#include "flutter/tonic/dart_wrappable.h"
#include "flutter/tonic/float64_list.h"
#include "sky/engine/core/painting/CanvasGradient.h"
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/core/painting/Matrix.h"
#include "sky/engine/core/painting/Shader.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkShader.h"
......@@ -18,10 +18,10 @@ namespace blink {
class DartLibraryNatives;
class ImageShader : public Shader {
DEFINE_WRAPPERTYPEINFO();
DEFINE_WRAPPERTYPEINFO();
public:
~ImageShader() override;
static scoped_refptr<ImageShader> create();
static scoped_refptr<ImageShader> Create();
void initWithImage(CanvasImage* image,
SkShader::TileMode tmx,
......@@ -36,4 +36,4 @@ class ImageShader : public Shader {
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_IMAGESHADER_H_
#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_SHADER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/MaskFilter.h"
#include "flutter/lib/ui/painting/mask_filter.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
......@@ -13,7 +13,7 @@
namespace blink {
static void MaskFilter_constructor(Dart_NativeArguments args) {
DartCallConstructor(&MaskFilter::create, args);
DartCallConstructor(&MaskFilter::Create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(ui, MaskFilter);
......@@ -24,14 +24,14 @@ void MaskFilter::RegisterNatives(DartLibraryNatives* natives) {
});
}
scoped_refptr<MaskFilter> MaskFilter::create(
unsigned style, double sigma, unsigned flags) {
scoped_refptr<MaskFilter> MaskFilter::Create(unsigned style, double sigma,
unsigned flags) {
return new MaskFilter(SkBlurMaskFilter::Make(
static_cast<SkBlurStyle>(style), sigma, flags));
}
MaskFilter::MaskFilter(sk_sp<SkMaskFilter> filter)
: filter_(filter) {
: filter_(std::move(filter)) {
}
MaskFilter::~MaskFilter() {
......
......@@ -2,8 +2,8 @@
// 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_MASKFILTER_H_
#define SKY_ENGINE_CORE_PAINTING_MASKFILTER_H_
#ifndef FLUTTER_LIB_UI_PAINTING_MASK_FILTER_H_
#define FLUTTER_LIB_UI_PAINTING_MASK_FILTER_H_
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
......@@ -18,10 +18,10 @@ class MaskFilter : public base::RefCountedThreadSafe<MaskFilter>, public DartWra
DEFINE_WRAPPERTYPEINFO();
public:
~MaskFilter() override;
static scoped_refptr<MaskFilter> create(
unsigned style, double sigma, unsigned flags);
static scoped_refptr<MaskFilter> Create(unsigned style, double sigma,
unsigned flags);
sk_sp<SkMaskFilter> filter() { return filter_; }
const sk_sp<SkMaskFilter>& filter() { return filter_; }
static void RegisterNatives(DartLibraryNatives* natives);
......@@ -33,4 +33,4 @@ class MaskFilter : public base::RefCountedThreadSafe<MaskFilter>, public DartWra
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_MASKFILTER_H_
#endif // FLUTTER_LIB_UI_PAINTING_MASK_FILTER_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 "flutter/lib/ui/painting/matrix.h"
namespace blink {
// Mappings from SkMatrix-index to input-index.
static const int kSkMatrixIndexToMatrix4Index[] = {
0, 4, 12,
1, 5, 13,
3, 7, 15,
};
SkMatrix ToSkMatrix(const Float64List& matrix4) {
DCHECK(matrix4.data());
SkMatrix sk_matrix;
for (int i = 0; i < 9; ++i) {
int matrix4_index = kSkMatrixIndexToMatrix4Index[i];
if (matrix4_index < matrix4.num_elements())
sk_matrix[i] = matrix4[matrix4_index];
else
sk_matrix[i] = 0.0;
}
return sk_matrix;
}
Float64List ToMatrix4(const SkMatrix& sk_matrix) {
Float64List matrix4(Dart_NewTypedData(Dart_TypedData_kFloat64, 16));
for (int i = 0; i < 9; ++i)
matrix4[kSkMatrixIndexToMatrix4Index[i]] = sk_matrix[i];
matrix4[10] = 1.0; // Identity along the z axis.
return matrix4;
}
} // namespace blink
......@@ -2,17 +2,17 @@
// 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_MATRIX_H_
#define SKY_ENGINE_CORE_PAINTING_MATRIX_H_
#ifndef FLUTTER_LIB_UI_PAINTING_MATRIX_H_
#define FLUTTER_LIB_UI_PAINTING_MATRIX_H_
#include "flutter/tonic/float64_list.h"
#include "third_party/skia/include/core/SkMatrix.h"
namespace blink {
SkMatrix toSkMatrix(const Float64List& matrix4);
Float64List toMatrix4(const SkMatrix& sk_matrix);
SkMatrix ToSkMatrix(const Float64List& matrix4);
Float64List ToMatrix4(const SkMatrix& sk_matrix);
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_MATRIX_H_
#endif // FLUTTER_LIB_UI_PAINTING_MATRIX_H_
......@@ -2,20 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/CanvasPath.h"
#include "flutter/lib/ui/painting/path.h"
#include <math.h>
#include "flutter/lib/ui/painting/matrix.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
#include "flutter/tonic/dart_converter.h"
#include "flutter/tonic/dart_library_natives.h"
#include "sky/engine/core/painting/Matrix.h"
namespace blink {
typedef CanvasPath Path;
static void Path_constructor(Dart_NativeArguments args) {
DartCallConstructor(&CanvasPath::create, args);
DartCallConstructor(&CanvasPath::Create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(ui, Path);
......@@ -56,23 +58,128 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
CanvasPath::CanvasPath()
{
CanvasPath::CanvasPath() {
}
CanvasPath::~CanvasPath() {
}
int CanvasPath::getFillType() {
return path_.getFillType();
}
void CanvasPath::setFillType(int fill_type) {
path_.setFillType(static_cast<SkPath::FillType>(fill_type));
}
void CanvasPath::moveTo(float x, float y) {
path_.moveTo(x, y);
}
void CanvasPath::relativeMoveTo(float x, float y) {
path_.rMoveTo(x, y);
}
void CanvasPath::lineTo(float x, float y) {
path_.lineTo(x, y);
}
void CanvasPath::relativeLineTo(float x, float y) {
path_.rLineTo(x, y);
}
void CanvasPath::quadraticBezierTo(float x1, float y1, float x2, float y2) {
path_.quadTo(x1, y1, x2, y2);
}
void CanvasPath::relativeQuadraticBezierTo(float x1, float y1, float x2,
float y2) {
path_.rQuadTo(x1, y1, x2, y2);
}
void CanvasPath::cubicTo(float x1, float y1, float x2, float y2, float x3,
float y3) {
path_.cubicTo(x1, y1, x2, y2, x3, y3);
}
void CanvasPath::relativeCubicTo(float x1, float y1, float x2, float y2,
float x3, float y3) {
path_.rCubicTo(x1, y1, x2, y2, x3, y3);
}
void CanvasPath::conicTo(float x1, float y1, float x2, float y2, float w) {
path_.conicTo(x1, y1, x2, y2, w);
}
void CanvasPath::relativeConicTo(float x1, float y1, float x2, float y2,
float w) {
path_.rConicTo(x1, y1, x2, y2, w);
}
void CanvasPath::arcTo(float left, float top, float right, float bottom,
float startAngle, float sweepAngle, bool forceMoveTo) {
path_.arcTo(SkRect::MakeLTRB(left, top, right, bottom),
startAngle*180.0/M_PI,
sweepAngle*180.0/M_PI,
forceMoveTo);
}
void CanvasPath::addRect(float left, float top, float right, float bottom) {
path_.addRect(SkRect::MakeLTRB(left, top, right, bottom));
}
void CanvasPath::addOval(float left, float top, float right, float bottom) {
path_.addOval(SkRect::MakeLTRB(left, top, right, bottom));
}
void CanvasPath::addArc(float left, float top, float right, float bottom,
float startAngle, float sweepAngle) {
path_.addArc(SkRect::MakeLTRB(left, top, right, bottom),
startAngle*180.0/M_PI,
sweepAngle*180.0/M_PI);
}
void CanvasPath::addPolygon(const Float32List& points, bool close) {
path_.addPoly(reinterpret_cast<const SkPoint*>(points.data()),
points.num_elements() / 2,
close);
}
void CanvasPath::addRRect(const RRect& rrect) {
path_.addRRect(rrect.sk_rrect);
}
void CanvasPath::addPath(CanvasPath* path, double dx, double dy) {
if (path)
path_.addPath(path->path(), dx, dy, SkPath::kAppend_AddPathMode);
}
void CanvasPath::extendWithPath(CanvasPath* path, double dx, double dy) {
if (path)
path_.addPath(path->path(), dx, dy, SkPath::kExtend_AddPathMode);
}
void CanvasPath::close() {
path_.close();
}
void CanvasPath::reset() {
path_.reset();
}
CanvasPath::~CanvasPath()
{
bool CanvasPath::contains(double x, double y) {
return path_.contains(x, y);
}
scoped_refptr<CanvasPath> CanvasPath::shift(double dx, double dy) {
scoped_refptr<CanvasPath> path = CanvasPath::create();
m_path.offset(dx, dy, &path->m_path);
scoped_refptr<CanvasPath> path = CanvasPath::Create();
path_.offset(dx, dy, &path->path_);
return std::move(path);
}
scoped_refptr<CanvasPath> CanvasPath::transform(const Float64List& matrix4) {
scoped_refptr<CanvasPath> path = CanvasPath::create();
m_path.transform(toSkMatrix(matrix4), &path->m_path);
scoped_refptr<CanvasPath> path = CanvasPath::Create();
path_.transform(ToSkMatrix(matrix4), &path->path_);
return std::move(path);
}
......
// 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 FLUTTER_LIB_UI_PAINTING_PATH_H_
#define FLUTTER_LIB_UI_PAINTING_PATH_H_
#include "base/memory/ref_counted.h"
#include "flutter/lib/ui/painting/rrect.h"
#include "flutter/tonic/dart_wrappable.h"
#include "flutter/tonic/float32_list.h"
#include "flutter/tonic/float64_list.h"
#include "third_party/skia/include/core/SkPath.h"
namespace blink {
class DartLibraryNatives;
class CanvasPath : public base::RefCountedThreadSafe<CanvasPath>,
public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
~CanvasPath() override;
static scoped_refptr<CanvasPath> Create() { return new CanvasPath(); }
int getFillType();
void setFillType(int fill_type);
void moveTo(float x, float y);
void relativeMoveTo(float x, float y);
void lineTo(float x, float y);
void relativeLineTo(float x, float y);
void quadraticBezierTo(float x1, float y1, float x2, float y2);
void relativeQuadraticBezierTo(float x1, float y1, float x2, float y2);
void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3);
void relativeCubicTo(float x1, float y1, float x2, float y2, float x3, float y3);
void conicTo(float x1, float y1, float x2, float y2, float w);
void relativeConicTo(float x1, float y1, float x2, float y2, float w);
void arcTo(float left, float top, float right, float bottom, float startAngle, float sweepAngle, bool forceMoveTo);
void addRect(float left, float top, float right, float bottom);
void addOval(float left, float top, float right, float bottom);
void addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle);
void addPolygon(const Float32List& points, bool close);
void addRRect(const RRect& rrect);
void addPath(CanvasPath* path, double dx, double dy);
void extendWithPath(CanvasPath* path, double dx, double dy);
void close();
void reset();
bool contains(double x, double y);
scoped_refptr<CanvasPath> shift(double dx, double dy);
scoped_refptr<CanvasPath> transform(const Float64List& matrix4);
const SkPath& path() const { return path_; }
static void RegisterNatives(DartLibraryNatives* natives);
private:
CanvasPath();
SkPath path_;
};
} // namespace blink
#endif // FLUTTER_LIB_UI_PAINTING_PATH_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/Picture.h"
#include "flutter/lib/ui/painting/picture.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
......@@ -19,24 +19,18 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Picture);
DART_BIND_ALL(Picture, FOR_EACH_BINDING)
scoped_refptr<Picture> Picture::create(sk_sp<SkPicture> skPicture)
{
DCHECK(skPicture);
return new Picture(skPicture);
scoped_refptr<Picture> Picture::Create(sk_sp<SkPicture> picture) {
return new Picture(std::move(picture));
}
Picture::Picture(sk_sp<SkPicture> skPicture)
: m_picture(skPicture)
{
Picture::Picture(sk_sp<SkPicture> picture) : picture_(std::move(picture)) {
}
Picture::~Picture()
{
Picture::~Picture() {
}
void Picture::dispose()
{
ClearDartWrapper();
void Picture::dispose() {
ClearDartWrapper();
}
} // namespace blink
......@@ -2,8 +2,8 @@
// 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_PICTURE_H_
#define SKY_ENGINE_CORE_PAINTING_PICTURE_H_
#ifndef FLUTTER_LIB_UI_PAINTING_PICTURE_H_
#define FLUTTER_LIB_UI_PAINTING_PICTURE_H_
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
......@@ -14,23 +14,23 @@ class Canvas;
class DartLibraryNatives;
class Picture : public base::RefCountedThreadSafe<Picture>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
DEFINE_WRAPPERTYPEINFO();
public:
~Picture() override;
static scoped_refptr<Picture> create(sk_sp<SkPicture> skPicture);
~Picture() override;
static scoped_refptr<Picture> Create(sk_sp<SkPicture> picture);
sk_sp<SkPicture> toSkia() const { return m_picture; }
const sk_sp<SkPicture>& picture() const { return picture_; }
void dispose();
void dispose();
static void RegisterNatives(DartLibraryNatives* natives);
static void RegisterNatives(DartLibraryNatives* natives);
private:
explicit Picture(sk_sp<SkPicture> skPicture);
explicit Picture(sk_sp<SkPicture> picture);
sk_sp<SkPicture> m_picture;
sk_sp<SkPicture> picture_;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_PICTURE_H_
#endif // FLUTTER_LIB_UI_PAINTING_PICTURE_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/RRect.h"
#include "flutter/lib/ui/painting/rrect.h"
#include "flutter/tonic/dart_error.h"
#include "flutter/tonic/float32_list.h"
......
......@@ -2,8 +2,8 @@
// 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_RRECT_H_
#define SKY_ENGINE_CORE_PAINTING_RRECT_H_
#ifndef FLUTTER_LIB_UI_PAINTING_RRECT_H_
#define FLUTTER_LIB_UI_PAINTING_RRECT_H_
#include "dart/runtime/include/dart_api.h"
#include "flutter/tonic/dart_converter.h"
......@@ -27,4 +27,4 @@ struct DartConverter<RRect> {
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_RRECT_H_
#endif // FLUTTER_LIB_UI_PAINTING_RRECT_H_
......@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/Shader.h"
#include "flutter/lib/ui/painting/shader.h"
namespace blink {
IMPLEMENT_WRAPPERTYPEINFO(ui, Shader);
Shader::Shader(sk_sp<SkShader> shader)
: shader_(shader) {
Shader::Shader(sk_sp<SkShader> shader) : shader_(shader) {
}
Shader::~Shader() {
......
......@@ -2,8 +2,8 @@
// 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_SHADER_H_
#define SKY_ENGINE_CORE_PAINTING_SHADER_H_
#ifndef FLUTTER_LIB_UI_PAINTING_SHADER_H_
#define FLUTTER_LIB_UI_PAINTING_SHADER_H_
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
......@@ -16,8 +16,8 @@ class Shader : public base::RefCountedThreadSafe<Shader>, public DartWrappable {
public:
~Shader() override;
sk_sp<SkShader> shader() { return shader_; }
void set_shader(sk_sp<SkShader> shader) { shader_ = shader; }
const sk_sp<SkShader>& shader() { return shader_; }
void set_shader(sk_sp<SkShader> shader) { shader_ = std::move(shader); }
protected:
Shader(sk_sp<SkShader> shader);
......@@ -28,4 +28,4 @@ class Shader : public base::RefCountedThreadSafe<Shader>, public DartWrappable {
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_SHADER_H_
#endif // FLUTTER_LIB_UI_PAINTING_SHADER_H_
......@@ -19,11 +19,6 @@ import 'dart:mojo.internal';
import 'dart:nativewrappers';
import 'dart:typed_data';
part 'Color.dart';
part 'FilterQuality.dart';
part 'Paint.dart';
part 'PaintingStyle.dart';
part 'TransferMode.dart';
part 'compositing.dart';
part 'geometry.dart';
part 'hash_codes.dart';
......
......@@ -28,6 +28,7 @@ source_set("bindings") {
"//base",
"//dart/runtime:libdart",
"//dart/runtime/bin:embedded_dart_io",
"//flutter/lib/ui",
"//flutter/tonic",
"//mojo/public/c/system",
"//mojo/public/cpp/application",
......
......@@ -4,6 +4,14 @@
#include "sky/engine/bindings/dart_ui.h"
#include "flutter/lib/ui/painting/color_filter.h"
#include "flutter/lib/ui/painting/gradient.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/image_filter.h"
#include "flutter/lib/ui/painting/image_shader.h"
#include "flutter/lib/ui/painting/mask_filter.h"
#include "flutter/lib/ui/painting/path.h"
#include "flutter/lib/ui/painting/picture.h"
#include "flutter/tonic/dart_converter.h"
#include "flutter/tonic/dart_error.h"
#include "sky/engine/bindings/dart_runtime_hooks.h"
......@@ -11,14 +19,6 @@
#include "sky/engine/core/compositing/Scene.h"
#include "sky/engine/core/compositing/SceneBuilder.h"
#include "sky/engine/core/painting/Canvas.h"
#include "sky/engine/core/painting/CanvasGradient.h"
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/core/painting/CanvasPath.h"
#include "sky/engine/core/painting/ColorFilter.h"
#include "sky/engine/core/painting/ImageFilter.h"
#include "sky/engine/core/painting/ImageShader.h"
#include "sky/engine/core/painting/MaskFilter.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/PictureRecorder.h"
#include "sky/engine/core/painting/painting.h"
#include "sky/engine/core/text/Paragraph.h"
......
......@@ -11,6 +11,7 @@ source_set("libraries") {
public_deps = [
"//base",
"//flow",
"//flutter/lib/ui",
"//flutter/tonic",
"//mojo/application",
"//mojo/data_pipe_utils",
......
......@@ -16,12 +16,12 @@
#include "flow/layers/picture_layer.h"
#include "flow/layers/shader_mask_layer.h"
#include "flow/layers/transform_layer.h"
#include "flutter/lib/ui/painting/matrix.h"
#include "flutter/lib/ui/painting/shader.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
#include "flutter/tonic/dart_converter.h"
#include "flutter/tonic/dart_library_natives.h"
#include "sky/engine/core/painting/Matrix.h"
#include "sky/engine/core/painting/Shader.h"
#include "third_party/skia/include/core/SkColorFilter.h"
namespace blink {
......@@ -69,7 +69,7 @@ SceneBuilder::~SceneBuilder()
void SceneBuilder::pushTransform(const Float64List& matrix4)
{
SkMatrix sk_matrix = toSkMatrix(matrix4);
SkMatrix sk_matrix = ToSkMatrix(matrix4);
std::unique_ptr<flow::TransformLayer> layer(new flow::TransformLayer());
layer->set_transform(sk_matrix);
addLayer(std::move(layer));
......@@ -114,7 +114,7 @@ void SceneBuilder::pushColorFilter(int color, int transferMode)
void SceneBuilder::pushBackdropFilter(ImageFilter* filter)
{
std::unique_ptr<flow::BackdropFilterLayer> layer(new flow::BackdropFilterLayer());
layer->set_filter(filter->toSkia());
layer->set_filter(filter->filter());
addLayer(std::move(layer));
}
......@@ -161,7 +161,7 @@ void SceneBuilder::addPicture(double dx, double dy, Picture* picture)
return;
std::unique_ptr<flow::PictureLayer> layer(new flow::PictureLayer());
layer->set_offset(SkPoint::Make(dx, dy));
layer->set_picture(picture->toSkia());
layer->set_picture(picture->picture());
m_currentLayer->Add(std::move(layer));
}
......
......@@ -10,15 +10,15 @@
#include "base/memory/ref_counted.h"
#include "flow/layers/container_layer.h"
#include "flutter/lib/ui/painting/image_filter.h"
#include "flutter/lib/ui/painting/path.h"
#include "flutter/lib/ui/painting/picture.h"
#include "flutter/lib/ui/painting/rrect.h"
#include "flutter/lib/ui/painting/shader.h"
#include "flutter/tonic/dart_wrappable.h"
#include "flutter/tonic/float64_list.h"
#include "sky/engine/core/compositing/Scene.h"
#include "sky/engine/core/painting/CanvasPath.h"
#include "sky/engine/core/painting/ImageFilter.h"
#include "sky/engine/core/painting/Paint.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/RRect.h"
#include "sky/engine/core/painting/Shader.h"
namespace blink {
......
......@@ -20,34 +20,12 @@ sky_core_files = [
"editing/PositionWithAffinity.h",
"painting/Canvas.cpp",
"painting/Canvas.h",
"painting/CanvasGradient.cpp",
"painting/CanvasGradient.h",
"painting/CanvasImage.cpp",
"painting/CanvasImage.h",
"painting/CanvasPath.cpp",
"painting/CanvasPath.h",
"painting/ColorFilter.cpp",
"painting/ColorFilter.h",
"painting/ImageFilter.cpp",
"painting/ImageFilter.h",
"painting/ImageShader.cpp",
"painting/ImageShader.h",
"painting/MaskFilter.cpp",
"painting/MaskFilter.h",
"painting/Matrix.cpp",
"painting/Matrix.h",
"painting/painting.cc",
"painting/painting.h",
"painting/Paint.cpp",
"painting/Paint.h",
"painting/Picture.cpp",
"painting/Picture.h",
"painting/painting.cc",
"painting/painting.h",
"painting/PictureRecorder.cpp",
"painting/PictureRecorder.h",
"painting/RRect.cpp",
"painting/RRect.h",
"painting/Shader.cpp",
"painting/Shader.h",
"rendering/BidiRun.h",
"rendering/BidiRunForLine.cpp",
"rendering/BidiRunForLine.h",
......@@ -219,13 +197,7 @@ core_dart_files = get_path_info([
"dart/lerp.dart",
"dart/mojo_services.dart",
"dart/natives.dart",
"dart/painting.dart",
"dart/text.dart",
"dart/window.dart",
"painting/Color.dart",
"painting/FilterQuality.dart",
"painting/Paint.dart",
"painting/PaintingStyle.dart",
"painting/TransferMode.dart",
],
"abspath")
......@@ -6,12 +6,12 @@
#include "sky/engine/core/painting/Canvas.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/matrix.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
#include "flutter/tonic/dart_converter.h"
#include "flutter/tonic/dart_library_natives.h"
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/core/painting/Matrix.h"
#include "sky/engine/core/text/Paragraph.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
......@@ -159,14 +159,14 @@ void Canvas::transform(const Float64List& matrix4)
{
if (!m_canvas)
return;
m_canvas->concat(toSkMatrix(matrix4));
m_canvas->concat(ToSkMatrix(matrix4));
}
void Canvas::setMatrix(const Float64List& matrix4)
{
if (!m_canvas)
return;
m_canvas->setMatrix(toSkMatrix(matrix4));
m_canvas->setMatrix(ToSkMatrix(matrix4));
}
void Canvas::clipRect(double left,
......@@ -320,7 +320,7 @@ void Canvas::drawPicture(Picture* picture)
if (!m_canvas)
return;
DCHECK(picture);
m_canvas->drawPicture(picture->toSkia().get());
m_canvas->drawPicture(picture->picture().get());
}
void Canvas::drawParagraph(Paragraph* paragraph, double x, double y) {
......
......@@ -6,15 +6,15 @@
#define SKY_ENGINE_CORE_PAINTING_CANVAS_H_
#include "base/memory/ref_counted.h"
#include "flutter/lib/ui/painting/path.h"
#include "flutter/lib/ui/painting/picture.h"
#include "flutter/lib/ui/painting/rrect.h"
#include "flutter/tonic/dart_wrappable.h"
#include "flutter/tonic/float32_list.h"
#include "flutter/tonic/float64_list.h"
#include "flutter/tonic/int32_list.h"
#include "sky/engine/core/painting/CanvasPath.h"
#include "sky/engine/core/painting/Paint.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/PictureRecorder.h"
#include "sky/engine/core/painting/RRect.h"
#include "third_party/skia/include/core/SkCanvas.h"
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_PATH_H_
#define SKY_ENGINE_CORE_PAINTING_PATH_H_
#include "math.h"
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
#include "flutter/tonic/float32_list.h"
#include "flutter/tonic/float64_list.h"
#include "sky/engine/core/painting/RRect.h"
#include "third_party/skia/include/core/SkPath.h"
// Note: There's a very similar class in ../../platform/graphics/Path.h
// We should probably rationalise these two.
// (The existence of that class is why this is CanvasPath and not just Path.)
// The Dart side of this is in ../dart/painting.dart
namespace blink {
class DartLibraryNatives;
class CanvasPath : public base::RefCountedThreadSafe<CanvasPath>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
~CanvasPath() override;
static scoped_refptr<CanvasPath> create() { return new CanvasPath(); }
int getFillType() { return m_path.getFillType(); }
void setFillType(int fill_type) { m_path.setFillType(static_cast<SkPath::FillType>(fill_type)); }
void moveTo(float x, float y) { m_path.moveTo(x, y); }
void relativeMoveTo(float x, float y) { m_path.rMoveTo(x, y); }
void lineTo(float x, float y) { m_path.lineTo(x, y); }
void relativeLineTo(float x, float y) { m_path.rLineTo(x, y); }
void quadraticBezierTo(float x1, float y1, float x2, float y2) { m_path.quadTo(x1, y1, x2, y2); }
void relativeQuadraticBezierTo(float x1, float y1, float x2, float y2) { m_path.rQuadTo(x1, y1, x2, y2); }
void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3) { m_path.cubicTo(x1, y1, x2, y2, x3, y3); }
void relativeCubicTo(float x1, float y1, float x2, float y2, float x3, float y3) { m_path.rCubicTo(x1, y1, x2, y2, x3, y3); }
void conicTo(float x1, float y1, float x2, float y2, float w) { m_path.conicTo(x1, y1, x2, y2, w); }
void relativeConicTo(float x1, float y1, float x2, float y2, float w) { m_path.rConicTo(x1, y1, x2, y2, w); }
void arcTo(float left, float top, float right, float bottom, float startAngle, float sweepAngle, bool forceMoveTo) {
m_path.arcTo(SkRect::MakeLTRB(left, top, right, bottom), startAngle*180.0/M_PI, sweepAngle*180.0/M_PI, forceMoveTo);
}
void addRect(float left, float top, float right, float bottom) { m_path.addRect(SkRect::MakeLTRB(left, top, right, bottom)); }
void addOval(float left, float top, float right, float bottom) { m_path.addOval(SkRect::MakeLTRB(left, top, right, bottom)); }
void addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle) {
m_path.addArc(SkRect::MakeLTRB(left, top, right, bottom), startAngle*180.0/M_PI, sweepAngle*180.0/M_PI);
}
void addPolygon(const Float32List& points, bool close) {
m_path.addPoly(reinterpret_cast<const SkPoint*>(points.data()), points.num_elements() / 2, close);
}
void addRRect(const RRect& rrect) { m_path.addRRect(rrect.sk_rrect); }
void addPath(CanvasPath* path, double dx, double dy) {
if (path)
m_path.addPath(path->path(), dx, dy, SkPath::kAppend_AddPathMode);
}
void extendWithPath(CanvasPath* path, double dx, double dy) {
if (path)
m_path.addPath(path->path(), dx, dy, SkPath::kExtend_AddPathMode);
}
void close() { m_path.close(); }
void reset() { m_path.reset(); }
bool contains(double x, double y) { return m_path.contains(x, y); }
scoped_refptr<CanvasPath> shift(double dx, double dy);
scoped_refptr<CanvasPath> transform(const Float64List& matrix4);
const SkPath& path() const { return m_path; }
static void RegisterNatives(DartLibraryNatives* natives);
private:
CanvasPath();
SkPath m_path;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_PATH_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_ui;
Color _scaleAlpha(Color a, double factor) {
return a.withAlpha((a.alpha * factor).round());
}
/// An immutable 32 bit color value in ARGB
class Color {
/// Construct a color from the lower 32 bits of an int.
///
/// Bits 24-31 are the alpha value.
/// Bits 16-23 are the red value.
/// Bits 8-15 are the green value.
/// Bits 0-7 are the blue value.
const Color(int value) : _value = (value & 0xFFFFFFFF);
/// Construct a color from the lower 8 bits of four integers.
const Color.fromARGB(int a, int r, int g, int b) :
_value = ((((a & 0xff) << 24) |
((r & 0xff) << 16) |
((g & 0xff) << 8) |
((b & 0xff) << 0)) & 0xFFFFFFFF);
/// A 32 bit value representing this color.
///
/// Bits 24-31 are the alpha value.
/// Bits 16-23 are the red value.
/// Bits 8-15 are the green value.
/// Bits 0-7 are the blue value.
int get value => _value;
final int _value;
/// The alpha channel of this color in an 8 bit value.
int get alpha => (0xff000000 & _value) >> 24;
/// The alpha channel of this color as a double.
double get opacity => alpha / 0xFF;
/// The red channel of this color in an 8 bit value.
int get red => (0x00ff0000 & _value) >> 16;
/// The green channel of this color in an 8 bit value.
int get green => (0x0000ff00 & _value) >> 8;
/// The blue channel of this color in an 8 bit value.
int get blue => (0x000000ff & _value) >> 0;
/// Returns a new color that matches this color with the alpha channel
/// replaced with a (which ranges from 0 to 255).
Color withAlpha(int a) {
return new Color.fromARGB(a, red, green, blue);
}
/// Returns a new color that matches this color with the alpha channel
/// replaced with the given opacity (which ranges from 0.0 to 1.0).
Color withOpacity(double opacity) {
assert(opacity >= 0.0 && opacity <= 1.0);
return withAlpha((255.0 * opacity).round());
}
/// Returns a new color that matches this color with the red channel replaced
/// with r.
Color withRed(int r) {
return new Color.fromARGB(alpha, r, green, blue);
}
/// Returns a new color that matches this color with the green channel
/// replaced with g.
Color withGreen(int g) {
return new Color.fromARGB(alpha, red, g, blue);
}
/// Returns a new color that matches this color with the blue channel replaced
/// with b.
Color withBlue(int b) {
return new Color.fromARGB(alpha, red, green, b);
}
/// Linearly interpolate between two colors
///
/// If either color is null, this function linearly interpolates from a
/// transparent instance of the other color.
static Color lerp(Color a, Color b, double t) {
if (a == null && b == null)
return null;
if (a == null)
return _scaleAlpha(b, t);
if (b == null)
return _scaleAlpha(a, 1.0 - t);
return new Color.fromARGB(
lerpDouble(a.alpha, b.alpha, t).toInt(),
lerpDouble(a.red, b.red, t).toInt(),
lerpDouble(a.green, b.green, t).toInt(),
lerpDouble(a.blue, b.blue, t).toInt()
);
}
@override
bool operator ==(dynamic other) {
if (other is! Color)
return false;
final Color typedOther = other;
return value == typedOther.value;
}
@override
int get hashCode => _value.hashCode;
@override
String toString() => "Color(0x${_value.toRadixString(16).padLeft(8, '0')})";
}
// 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;
// List of predefined filter quality modes. This list comes from Skia's
// SkFilterQuality.h and the values (order) should be kept in sync.
/// Quality levels for image filters.
///
/// See [Paint.filterQuality].
enum FilterQuality {
/// Fastest possible filtering, albeit also the lowest quality.
///
/// Typically this implies nearest-neighbour filtering.
none,
/// Better quality than [none], faster than [medium].
///
/// Typically this implies bilinear interpolation.
low,
/// Better quality than [low], faster than [high].
///
/// Typically this implies a combination of bilinear interpolation and
/// pyramidal parametric prefiltering (mipmaps).
medium,
/// Best possible quality filtering, albeit also the slowest.
///
/// Typically this implies bicubic interpolation or better.
high,
}
// 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/core/painting/Matrix.h"
namespace blink {
// Mappings from SkMatrix-index to input-index.
static const int kSkMatrixIndexToMatrix4Index[] = {
0, 4, 12,
1, 5, 13,
3, 7, 15,
};
SkMatrix toSkMatrix(const Float64List& matrix4)
{
DCHECK(matrix4.data());
SkMatrix sk_matrix;
for (int i = 0; i < 9; ++i) {
int matrix4_index = kSkMatrixIndexToMatrix4Index[i];
if (matrix4_index < matrix4.num_elements())
sk_matrix[i] = matrix4[matrix4_index];
else
sk_matrix[i] = 0.0;
}
return sk_matrix;
}
Float64List toMatrix4(const SkMatrix& sk_matrix)
{
Float64List matrix4(Dart_NewTypedData(Dart_TypedData_kFloat64, 16));
for (int i = 0; i < 9; ++i)
matrix4[kSkMatrixIndexToMatrix4Index[i]] = sk_matrix[i];
matrix4[10] = 1.0; // Identity along the z axis.
return matrix4;
}
} // namespace blink
......@@ -4,9 +4,9 @@
#include "sky/engine/core/painting/Paint.h"
#include "sky/engine/core/painting/ColorFilter.h"
#include "sky/engine/core/painting/MaskFilter.h"
#include "sky/engine/core/painting/Shader.h"
#include "flutter/lib/ui/painting/color_filter.h"
#include "flutter/lib/ui/painting/mask_filter.h"
#include "flutter/lib/ui/painting/shader.h"
#include "sky/engine/core/script/ui_dart_state.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkMaskFilter.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_ui;
/// Styles to use for line endings.
///
/// See [Paint.strokeCap].
enum StrokeCap {
/// Begin and end contours with a flat edge and no extension.
butt,
/// Begin and end contours with a semi-circle extension.
round,
/// Begin and end contours with a half square extension. This is
/// similar to extending each contour by half the stroke width (as
/// given by [Paint.strokeWidth]).
square,
}
/// A description of the style to use when drawing on a [Canvas].
///
/// Most APIs on [Canvas] take a [Paint] object to describe the style
/// to use for that operation.
class Paint {
/// Whether to paint inside shapes, the edges of shapes, or both.
///
/// If null, defaults to [PaintingStyle.fill].
PaintingStyle style;
static const PaintingStyle _kDefaultStyle = PaintingStyle.fill;
/// How wide to make edges drawn when [style] is set to
/// [PaintingStyle.stroke] or [PaintingStyle.strokeAndFill]. The
/// width is given in logical pixels measured in the direction
/// orthogonal to the direction of the path.
///
/// The values null and 0.0 correspond to a hairline width.
double strokeWidth;
static const double _kDefaultStrokeWidth = 0.0;
/// The kind of finish to place on the end of lines drawn when
/// [style] is set to [PaintingStyle.stroke] or
/// [PaintingStyle.strokeAndFill].
///
/// If null, defaults to [StrokeCap.butt], i.e. no caps.
StrokeCap strokeCap;
static const StrokeCap _kDefaultStrokeCap = StrokeCap.butt;
/// Whether to apply anti-aliasing to lines and images drawn on the
/// canvas.
///
/// Defaults to true. The value null is treated as false.
bool isAntiAlias = true;
/// The color to use when stroking or filling a shape.
///
/// Defaults to black.
///
/// See also:
///
/// * [style], which controls whether to stroke or fill (or both).
/// * [colorFilter], which overrides [color].
/// * [shader], which overrides [color] with more elaborate effects.
///
/// This color is not used when compositing. To colorize a layer, use
/// [colorFilter].
Color color = _kDefaultPaintColor;
static const Color _kDefaultPaintColor = const Color(0xFF000000);
/// A mask filter (for example, a blur) to apply to a shape after it has been
/// drawn but before it has been composited into the image.
///
/// See [MaskFilter] for details.
MaskFilter maskFilter;
/// Controls the performance vs quality trade-off to use when applying
/// filters, such as [maskFilter], or when drawing images, as with
/// [Canvas.drawImageRect] or [Canvas.drawImageNine].
// TODO(ianh): verify that the image drawing methods actually respect this
FilterQuality filterQuality;
/// The shader to use when stroking or filling a shape.
///
/// When this is null, the [color] is used instead.
///
/// See also:
///
/// * [Gradient], a shader that paints a color gradient.
/// * [ImageShader], a shader that tiles an [Image].
/// * [colorFilter], which overrides [shader].
/// * [color], which is used if [shader] and [colorFilter] are null.
Shader shader;
/// A color filter to apply when a shape is drawn or when a layer is
/// composited.
///
/// See [ColorFilter] for details.
///
/// When a shape is being drawn, [colorFilter] overrides [color] and [shader].
ColorFilter colorFilter;
/// A transfer mode to apply when a shape is drawn or a layer is composited.
///
/// The source colors are from the shape being drawn (e.g. from
/// [Canvas.drawPath]) or layer being composited (the graphics that were drawn
/// between the [Canvas.saveLayer] and [Canvas.restore] calls), after applying
/// the [colorFilter], if any.
///
/// The destination colors are from the background onto which the shape or
/// layer is being composited.
///
/// If null, defaults to [TransferMode.srcOver].
TransferMode transferMode;
static const TransferMode _kDefaultTransferMode = TransferMode.srcOver;
// Must match PaintFields enum in Paint.cpp.
dynamic get _value {
// The most common usage is a Paint with no options besides a color and
// anti-aliasing. In this case, save time by just returning the color
// as an int.
if ((style == null || style == _kDefaultStyle) &&
(strokeWidth == null || strokeWidth == _kDefaultStrokeWidth) &&
(strokeCap == null || strokeCap == _kDefaultStrokeCap) &&
isAntiAlias &&
color != null &&
(transferMode == null || transferMode == _kDefaultTransferMode) &&
colorFilter == null &&
maskFilter == null &&
filterQuality == null &&
shader == null) {
return color.value;
}
return <dynamic>[
style?.index,
strokeWidth,
strokeCap?.index,
isAntiAlias,
color.value,
transferMode?.index,
colorFilter,
maskFilter,
filterQuality?.index,
shader,
];
}
@override
String toString() {
StringBuffer result = new StringBuffer();
String semicolon = '';
result.write('Paint(');
if (style == PaintingStyle.stroke || style == PaintingStyle.strokeAndFill) {
result.write('$style');
if (strokeWidth != null && strokeWidth != 0.0)
result.write(' $strokeWidth');
else
result.write(' hairline');
if (strokeCap != null && strokeCap != _kDefaultStrokeCap)
result.write(' $strokeCap');
semicolon = '; ';
}
if (isAntiAlias != true) {
result.write('${semicolon}antialias off');
semicolon = '; ';
}
if (color != _kDefaultPaintColor) {
if (color != null)
result.write('$semicolon$color');
else
result.write('${semicolon}no color');
semicolon = '; ';
}
if (transferMode != null) {
result.write('$semicolon$transferMode');
semicolon = '; ';
}
if (colorFilter != null) {
result.write('${semicolon}colorFilter: $colorFilter');
semicolon = '; ';
}
if (maskFilter != null) {
result.write('${semicolon}maskFilter: $maskFilter');
semicolon = '; ';
}
if (filterQuality != null) {
result.write('${semicolon}filterQuality: $filterQuality');
semicolon = '; ';
}
if (shader != null)
result.write('${semicolon}shader: $shader');
result.write(')');
return result.toString();
}
}
// 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;
// List of predefined painting styles. This list comes from Skia's
// SkPaint.h and the values (order) should be kept in sync.
/// Strategies for painting shapes and paths on a canvas.
///
/// See [Paint.style].
enum PaintingStyle {
/// Apply the [Paint] to the inside of the shape. For example, when
/// applied to the [Paint.drawCircle] call, this results in a disc
/// of the given size being painted.
fill,
/// Apply the [Paint] to the edge of the shape. For example, when
/// applied to the [Paint.drawCircle] call, this results is a hoop
/// of the given size being painted. The line drawn on the edge will
/// be the width given by the [Paint.strokeWidth] property.
stroke,
/// Apply the [Paint] to the inside of the shape and the edge of the
/// shape at the same time. The resulting drawing is similar to what
/// would be achieved by inflating the shape by half the stroke
/// width (as given by [Paint.strokeWidth]), and then using [fill].
strokeAndFill,
}
......@@ -4,12 +4,12 @@
#include "sky/engine/core/painting/PictureRecorder.h"
#include "flutter/lib/ui/painting/picture.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
#include "flutter/tonic/dart_converter.h"
#include "flutter/tonic/dart_library_natives.h"
#include "sky/engine/core/painting/Canvas.h"
#include "sky/engine/core/painting/Picture.h"
namespace blink {
......@@ -54,7 +54,7 @@ scoped_refptr<Picture> PictureRecorder::endRecording()
{
if (!isRecording())
return nullptr;
scoped_refptr<Picture> picture = Picture::create(
scoped_refptr<Picture> picture = Picture::Create(
m_pictureRecorder.finishRecordingAsPicture());
m_canvas->clearSkCanvas();
m_canvas->ClearDartWrapper();
......
// 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;
// List of predefined color transfer modes. This list comes from Skia's
// SkXfermode.h and the values (order) should be kept in sync.
// See: https://skia.org/user/api/skpaint#SkXfermode
/// Algorithms to use when painting on the canvas.
///
/// When drawing a shape or image onto a canvas, different algorithms
/// can be used to blend the pixels. The image below shows the effects
/// of these modes.
///
/// [![Open Skia fiddle to view image.](https://flutter.io/images/transfer_mode.png)](https://fiddle.skia.org/c/864acd0659c7a866ea7296a3184b8bdd)
///
/// See [Paint.transferMode].
enum TransferMode {
clear,
src,
dst,
srcOver,
dstOver,
srcIn,
dstIn,
srcOut,
dstOut,
srcATop,
dstATop,
xor,
plus,
modulate,
// Following blend modes are defined in the CSS Compositing standard.
screen, // The last coeff mode.
overlay,
darken,
lighten,
colorDodge,
colorBurn,
hardLight,
softLight,
difference,
exclusion,
multiply, // The last separable mode.
hue,
saturation,
color,
luminosity,
}
......@@ -7,11 +7,11 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/trace_event/trace_event.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/tonic/dart_invoke.h"
#include "flutter/tonic/dart_persistent_value.h"
#include "flutter/tonic/mojo_converter.h"
#include "flutter/tonic/uint8_list.h"
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/platform/SharedBuffer.h"
#include "sky/engine/platform/image-decoders/ImageDecoder.h"
#include "sky/engine/platform/mojo/data_pipe.h"
......@@ -46,8 +46,8 @@ void InvokeImageCallback(sk_sp<SkImage> image,
if (!image) {
DartInvoke(callback->value(), {Dart_Null()});
} else {
scoped_refptr<CanvasImage> resultImage = CanvasImage::create();
resultImage->setImage(std::move(image));
scoped_refptr<CanvasImage> resultImage = CanvasImage::Create();
resultImage->set_image(std::move(image));
DartInvoke(callback->value(), {ToDart(resultImage)});
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册