Merge pull request #2201 from abarth/rm_canvas_idl

Remove the remaining IDL files
This commit is contained in:
Adam Barth 2015-12-29 10:57:55 -08:00
commit 8fc63eb204
24 changed files with 449 additions and 548 deletions

View File

@ -40,7 +40,6 @@ source_set("bindings") {
"//sky/engine/platform:platform",
"//sky/engine/tonic",
"//sky/engine/wtf",
":generated_bindings",
]
# On iOS (device), precompiled snapshots contain the instruction buffer.
@ -147,188 +146,6 @@ source_set("snapshot_cc") {
]
}
action("compute_interfaces_info_individual") {
sources = core_idl_files
script = "$bindings_scripts_dir/compute_interfaces_info_individual.py"
output_file = "$bindings_output_dir/InterfacesInfoIndividual.pickle"
# TODO(eseidel): This is no longer needed, could pass these as args.
file_list = "$target_gen_dir/${target_name}_file_list.txt"
write_file(file_list, rebase_path(sources, root_build_dir))
# TODO(eseidel): Use depfile instead of this manual list.
inputs = [ "$bindings_scripts_dir/utilities.py" ] + sources
outputs = [
file_list,
output_file,
]
args = [
# TODO(eseidel): Remove component-dir, it is meaningless in sky.
"--component-dir",
"ignored",
"--idl-files-list",
rebase_path(file_list, root_build_dir),
"--interfaces-info-file",
rebase_path(output_file, root_build_dir),
# TODO(eseidel): only-if-changed is always true, remove
"--write-file-only-if-changed=1",
]
}
interfaces_info_individual_path =
"$bindings_output_dir/InterfacesInfoIndividual.pickle"
interfaces_info_overall_path =
"$bindings_output_dir/InterfacesInfoOverall.pickle"
action("compute_interfaces_info_overall") {
script = "$bindings_scripts_dir/compute_interfaces_info_overall.py"
inputs = [
interfaces_info_individual_path,
]
outputs = [
interfaces_info_overall_path,
]
args = [
# TODO(eseidel): only-if-changed is always true, remove
"--write-file-only-if-changed=1",
"--",
]
args += rebase_path(inputs, root_build_dir)
args += rebase_path(outputs, root_build_dir)
deps = [
":compute_interfaces_info_individual",
]
}
# This separate pre-caching step is required to use lex/parse table
# caching in PLY, since PLY itself does not check if the cache is
# valid, and thus may end up using a stale cache if this step hasn"t
# been run to update it.
#
# This action"s dependencies *is* the cache validation.
#
# GYP version: scripts.gyp:cached_lex_yacc_tables
action("cached_lex_yacc_tables") {
script = "scripts/blink_idl_parser.py"
inputs = idl_lexer_parser_files
outputs = [
"$bindings_output_dir/lextab.py",
"$bindings_output_dir/parsetab.pickle",
]
args = [ rebase_path(bindings_output_dir, root_build_dir) ]
}
# Runs the idl_compiler script over a list of sources.
#
# Parameters:
# sources = list of IDL files to compile
# output_dir = string containing the directory to put the output files.
template("idl_compiler") {
output_dir = invoker.output_dir
action_foreach(target_name) {
# TODO(brettw) GYP adds a "-S before the script name to skip "import site" to
# speed up startup. Figure out if we need this and do something similar (not
# really expressible in GN now).
script = "$bindings_scripts_dir/compiler.py"
inputs = idl_lexer_parser_files + idl_compiler_files
inputs += [
"scripts/templates/attributes_cpp.template",
"scripts/templates/callback_interface_cpp.template",
"scripts/templates/callback_interface_dart.template",
"scripts/templates/callback_interface_h.template",
"scripts/templates/interface_base_cpp.template",
"scripts/templates/interface_cpp.template",
"scripts/templates/interface_dart.template",
"scripts/templates/interface_h.template",
"scripts/templates/methods_cpp.template",
]
inputs += [
"$bindings_output_dir/lextab.py",
"$bindings_output_dir/parsetab.pickle",
# "$bindings_output_dir/cached_jinja_templates.stamp",
"//sky/engine/bindings/IDLExtendedAttributes.txt",
# If the dependency structure or public interface info (e.g.,
# [ImplementedAs]) changes, we rebuild all files, since we"re not
# computing dependencies file-by-file in the build.
# This data is generally stable.
interfaces_info_overall_path,
]
sources = invoker.sources
outputs = [
"$output_dir/Dart{{source_name_part}}.cpp",
"$output_dir/Dart{{source_name_part}}.h",
"$output_dir/{{source_name_part}}.dart",
]
args = [
"--output-dir",
rebase_path(output_dir, root_build_dir),
"--interfaces-info",
rebase_path(interfaces_info_overall_path, root_build_dir),
"--write-file-only-if-changed=1", # Always true for Ninja.
"{{source}}",
]
deps = [
":compute_interfaces_info_overall",
":cached_lex_yacc_tables",
# ":cached_jinja_templates",
]
}
}
idl_compiler("compile_idls") {
sources = core_idl_files
output_dir = bindings_output_dir
}
action("generate_dart_globals") {
sources = core_idl_files
script = "$bindings_scripts_dir/compiler.py"
file_list = "$target_gen_dir/${target_name}_file_list.txt"
write_file(file_list, rebase_path(sources, root_build_dir))
inputs = sources + idl_compiler_files
inputs += [
"scripts/templates/global_cpp.template",
"scripts/templates/global_h.template",
]
outputs = [
file_list,
"$bindings_output_dir/DartGlobal.h",
"$bindings_output_dir/DartGlobal.cpp",
]
args = [
"--output-directory",
rebase_path(bindings_output_dir, root_build_dir),
"--generate-globals",
rebase_path(bindings_output_dir, root_build_dir),
rebase_path(file_list, root_build_dir),
]
deps = [
":compile_idls",
]
}
copy("copy_core_dart_files") {
sources = core_dart_files
outputs = [
@ -337,14 +154,13 @@ copy("copy_core_dart_files") {
}
action("generate_dart_ui") {
sources = core_idl_files + core_dart_files
sources = core_dart_files
script = "$bindings_scripts_dir/compiler.py"
file_list = "$target_gen_dir/${target_name}_file_list.txt"
write_file(file_list, rebase_path(sources, root_build_dir))
inputs =
sources + idl_compiler_files + [ "scripts/templates/dart_blink.template" ]
inputs = sources + [ "scripts/templates/dart_blink.template" ]
outputs = [
file_list,
@ -361,36 +177,5 @@ action("generate_dart_ui") {
deps = [
":copy_core_dart_files",
":compile_idls",
]
}
source_set("generated_bindings") {
deps = [
"//base",
"//dart/runtime:libdart",
"//dart/runtime/vm:libdart_platform",
"//mojo/application",
"//mojo/public/c/system",
"//mojo/public/cpp/bindings",
"//mojo/public/cpp/system",
"//mojo/public/cpp/utility",
"//mojo/public/interfaces/application",
"//skia",
"//sky/engine/wtf",
"//third_party/iccjpeg",
"//third_party/libpng",
"//third_party/qcms",
"//third_party/zlib",
":compile_idls",
":generate_dart_globals",
]
include_dirs = [
"..",
"$root_build_dir",
]
sources = get_target_outputs(":compile_idls")
sources += get_target_outputs(":generate_dart_globals")
}

View File

@ -7,50 +7,6 @@ import("//mojo/dart/packages/mojo/sdk_ext_sources.gni")
bindings_scripts_dir = "//sky/engine/bindings/scripts"
bindings_output_dir = "$root_gen_dir/sky/bindings"
idl_lexer_parser_files = [
# PLY (Python Lex-Yacc)
"//third_party/ply/lex.py",
"//third_party/ply/yacc.py",
# Web IDL lexer/parser (base parser)
"//tools/idl_parser/idl_lexer.py",
"//tools/idl_parser/idl_node.py",
"//tools/idl_parser/idl_parser.py",
# Blink IDL lexer/parser/constructor
"scripts/blink_idl_lexer.py",
"scripts/blink_idl_parser.py",
]
idl_compiler_files = [
"scripts/compiler.py",
# Blink IDL front end (ex-lexer/parser)
"scripts/idl_definitions.py",
"scripts/idl_reader.py",
"scripts/idl_types.py",
"scripts/idl_validator.py",
"scripts/interface_dependency_resolver.py",
# Dart Code gen goes here.
"scripts/dart_attributes.py",
"scripts/dart_callback_interface.py",
"scripts/dart_compiler.py",
"scripts/dart_interface.py",
"scripts/dart_methods.py",
"scripts/dart_types.py",
"scripts/dart_utilities.py",
"scripts/code_generator_dart.py",
# The dart files depend on the v8 files. :(
"scripts/v8_attributes.py",
"scripts/v8_globals.py",
"scripts/v8_interface.py",
"scripts/v8_methods.py",
"scripts/v8_types.py",
"scripts/v8_utilities.py",
]
dart_host_toolchain = host_toolchain
if (target_os == "ios" && !use_ios_simulator) {
# During precompilation, a 64 bit Dart VM cannot generate code for a 32 bit

View File

@ -4,17 +4,21 @@
#include "sky/engine/bindings/dart_ui.h"
#include "gen/sky/bindings/DartGlobal.h"
#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/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/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/painting/Picture.h"
#include "sky/engine/core/painting/PictureRecorder.h"
#include "sky/engine/core/text/Paragraph.h"
#include "sky/engine/core/text/ParagraphBuilder.h"
#include "sky/engine/core/window/window.h"
@ -29,17 +33,11 @@ static DartLibraryNatives* g_natives;
Dart_NativeFunction GetNativeFunction(Dart_Handle name,
int argument_count,
bool* auto_setup_scope) {
if (auto result = g_natives->GetNativeFunction(name,
argument_count,
auto_setup_scope))
return result;
return skySnapshotResolver(name, argument_count, auto_setup_scope);
return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope);
}
const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
if (auto result = g_natives->GetSymbol(native_function))
return result;
return skySnapshotSymbolizer(native_function);
return g_natives->GetSymbol(native_function);
}
} // namespace
@ -47,7 +45,10 @@ const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
void DartUI::InitForIsolate() {
if (!g_natives) {
g_natives = new DartLibraryNatives();
Canvas::RegisterNatives(g_natives);
CanvasGradient::RegisterNatives(g_natives);
CanvasImage::RegisterNatives(g_natives);
CanvasPath::RegisterNatives(g_natives);
ColorFilter::RegisterNatives(g_natives);
DartRuntimeHooks::RegisterNatives(g_natives);
DrawLooperLayerInfo::RegisterNatives(g_natives);
@ -57,6 +58,8 @@ void DartUI::InitForIsolate() {
Painting::RegisterNatives(g_natives);
Paragraph::RegisterNatives(g_natives);
ParagraphBuilder::RegisterNatives(g_natives);
Picture::RegisterNatives(g_natives);
PictureRecorder::RegisterNatives(g_natives);
Scene::RegisterNatives(g_natives);
SceneBuilder::RegisterNatives(g_natives);
Window::RegisterNatives(g_natives);

View File

@ -76,7 +76,6 @@ sky_core_files = [
"painting/Size.cpp",
"painting/Size.h",
"painting/TransferMode.h",
"painting/VertexMode.h",
"rendering/BidiRun.h",
"rendering/BidiRunForLine.cpp",
"rendering/BidiRunForLine.h",
@ -233,15 +232,6 @@ sky_core_files = [
"window/window.h",
]
core_idl_files = get_path_info([
"painting/Canvas.idl",
"painting/Image.idl",
"painting/Path.idl",
"painting/Picture.idl",
"painting/PictureRecorder.idl",
],
"abspath")
core_dart_files = get_path_info([
"dart/compositing.dart",
"dart/hash_codes.dart",
@ -263,6 +253,5 @@ core_dart_files = get_path_info([
"painting/Rect.dart",
"painting/Size.dart",
"painting/TransferMode.dart",
"painting/VertexMode.dart",
],
"abspath")

View File

@ -4,6 +4,13 @@
part of dart_ui;
abstract class Image extends NativeFieldWrapperClass2 {
int get width native "Image_width";
int get height native "Image_height";
void dispose() native "Image_dispose";
}
typedef void _ImageDecoderCallback(Image result);
void decodeImageFromDataPipe(int handle, _ImageDecoderCallback callback)
@ -12,6 +19,30 @@ void decodeImageFromDataPipe(int handle, _ImageDecoderCallback callback)
void decodeImageFromList(Uint8List list, _ImageDecoderCallback callback)
native "decodeImageFromList";
class Path extends NativeFieldWrapperClass2 {
void _constructor() native "Path_constructor";
Path() { _constructor(); }
void moveTo(double x, double y) native "Path_moveTo";
void relativeMoveTo(double dx, double dy) native "Path_relativeMoveTo";
void lineTo(double x, double y) native "Path_lineTo";
void relativeLineTo(double dx, double dy) native "Path_relativeLineTo";
void quadraticBezierTo(double x1, double y1, double x2, double y2) native "Path_quadraticBezierTo";
void relativeQuadraticBezierTo(double x1, double y1, double x2, double y2) native "Path_relativeQuadraticBezierTo";
void cubicTo(double x1, double y1, double x2, double y2, double x3, double y3) native "Path_cubicTo";
void relativeCubicTo(double x1, double y1, double x2, double y2, double x3, double y3) native "Path_relativeCubicTo";
void conicTo(double x1, double y1, double x2, double y2, double w) native "Path_conicTo";
void relativeConicTo(double x1, double y1, double x2, double y2, double w) native "Path_relativeConicTo";
void arcTo(Rect rect, double startAngle, double sweepAngle, bool forceMoveTo) native "Path_arcTo";
void addRect(Rect rect) native "Path_addRect";
void addOval(Rect oval) native "Path_addOval";
void addArc(Rect oval, double startAngle, double sweepAngle) native "Path_addArc";
void addRRect(RRect rrect) native "Path_addRRect";
void close() native "Path_close";
void reset() native "Path_reset";
Path shift(Offset offset) native "Path_shift";
}
abstract class DrawLooper extends NativeFieldWrapperClass2 {
}
@ -156,3 +187,133 @@ class ImageShader extends Shader {
}
}
/// Defines how a list of points is interpreted when drawing a set of triangles.
/// See Skia or OpenGL documentation for more details.
enum VertexMode {
triangles,
triangleStrip,
triangleFan,
}
class Canvas extends NativeFieldWrapperClass2 {
void _constructor(PictureRecorder recorder, Rect bounds) native "Canvas_constructor";
Canvas(PictureRecorder recorder, Rect bounds) {
if (recorder == null)
throw new ArgumentError("[recorder] argument cannot be null.");
if (recorder.isRecording)
throw new ArgumentError("You must call endRecording() before reusing a PictureRecorder to create a new Canvas object.");
_constructor(recorder, bounds);
}
void save() native "Canvas_save";
// TODO(jackson): Paint should be optional, but making it optional causes crash
void saveLayer(Rect bounds, Paint paint) native "Canvas_saveLayer";
void restore() native "Canvas_restore";
/// returns 1 for a clean canvas; each call to save() or saveLayer() increments it, and each call to
int getSaveCount() native "Canvas_getSaveCount";
void translate(double dx, double dy) native "Canvas_translate";
void scale(double sx, double sy) native "Canvas_scale";
void rotate(double radians) native "Canvas_rotate";
void skew(double sx, double sy) native "Canvas_skew";
void concat(Float64List matrix4) native "Canvas_concat";
void setMatrix(Float64List matrix4) native "Canvas_setMatrix";
Float64List getTotalMatrix() native "Canvas_getTotalMatrix";
void clipRect(Rect rect) native "Canvas_clipRect";
void clipRRect(RRect rrect) native "Canvas_clipRRect";
void clipPath(Path path) native "Canvas_clipPath";
void drawColor(Color color, TransferMode transferMode) native "Canvas_drawColor";
void drawLine(Point p1, Point p2, Paint paint) native "Canvas_drawLine";
void drawPaint(Paint paint) native "Canvas_drawPaint";
void drawRect(Rect rect, Paint paint) native "Canvas_drawRect";
void drawRRect(RRect rrect, Paint paint) native "Canvas_drawRRect";
void drawDRRect(RRect outer, RRect inner, Paint paint) native "Canvas_drawDRRect";
void drawOval(Rect rect, Paint paint) native "Canvas_drawOval";
void drawCircle(Point c, double radius, Paint paint) native "Canvas_drawCircle";
void drawPath(Path path, Paint paint) native "Canvas_drawPath";
void drawImage(Image image, Point p, Paint paint) native "Canvas_drawImage";
void drawImageRect(Image image, Rect src, Rect dst, Paint paint) native "Canvas_drawImageRect";
void drawImageNine(Image image, Rect center, Rect dst, Paint paint) native "Canvas_drawImageNine";
void drawPicture(Picture picture) native "Canvas_drawPicture";
void _drawVertices(int vertexMode,
List<Point> vertices,
List<Point> textureCoordinates,
List<Color> colors,
TransferMode transferMode,
List<int> indicies,
Paint paint) native "Canvas_drawVertices";
void drawVertices(VertexMode vertexMode,
List<Point> vertices,
List<Point> textureCoordinates,
List<Color> colors,
TransferMode transferMode,
List<int> indicies,
Paint paint) {
int vertexCount = vertices.length;
if (textureCoordinates.isNotEmpty && textureCoordinates.length != vertexCount)
throw new ArgumentError("[vertices] and [textureCoordinates] lengths must match");
if (colors.isNotEmpty && colors.length != vertexCount)
throw new ArgumentError("[vertices] and [colors] lengths must match");
for (Point point in vertices) {
if (point == null)
throw new ArgumentError("[vertices] cannot contain a null");
}
for (Point point in textureCoordinates) {
if (point == null)
throw new ArgumentError("[textureCoordinates] cannot contain a null");
}
_drawVertices(vertexMode.index, vertices, textureCoordinates, colors, transferMode, indicies, paint);
}
// TODO(eseidel): Paint should be optional, but optional doesn't work.
void _drawAtlas(Image image,
List<RSTransform> transforms,
List<Rect> rects,
List<Color> colors,
TransferMode mode,
Rect cullRect,
Paint paint) native "Canvas_drawAtlas";
void drawAtlas(Image image,
List<RSTransform> transforms,
List<Rect> rects,
List<Color> colors,
TransferMode mode,
Rect cullRect,
Paint paint) {
if (transforms.length != rects.length)
throw new ArgumentError("[transforms] and [rects] lengths must match");
if (colors.isNotEmpty && colors.length != rects.length)
throw new ArgumentError("if supplied, [colors] length must match that of [transforms] and [rects]");
for (RSTransform transform in transforms) {
if (transform == null)
throw new ArgumentError("[transforms] cannot contain a null");
}
for (Rect rect in rects) {
if (rect == null)
throw new ArgumentError("[rects] cannot contain a null");
}
_drawAtlas(image, transforms, rects, colors, mode, cullRect, paint);
}
}
abstract class Picture extends NativeFieldWrapperClass2 {
/// Replays the drawing commands on the specified canvas. Note that
/// this has the effect of unfurling this picture into the destination
/// canvas. Using the Canvas drawPicture entry point gives the destination
/// canvas the option of just taking a ref.
void playback(Canvas canvas) native "Picture_playback";
void dispose() native "Picture_dispose";
}
class PictureRecorder extends NativeFieldWrapperClass2 {
void _constructor() native "PictureRecorder_constructor";
PictureRecorder() { _constructor(); }
bool get isRecording native "PictureRecorder_isRecording";
Picture endRecording() native "PictureRecorder_endRecording";
}

View File

@ -9,11 +9,96 @@
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/core/painting/Matrix.h"
#include "sky/engine/platform/geometry/IntRect.h"
#include "third_party/skia/include/core/SkCanvas.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"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace blink {
static void Canvas_constructor(Dart_NativeArguments args) {
DartCallConstructor(&Canvas::create, args);
}
static void Canvas_concat(Dart_NativeArguments args) {
DartArgIterator it(args);
Float64List matrix4 = it.GetNext<Float64List>();
if (it.had_exception())
return;
ExceptionState es;
GetReceiver<Canvas>(args)->concat(matrix4, es);
if (es.had_exception())
Dart_ThrowException(es.GetDartException(args, true));
}
static void Canvas_setMatrix(Dart_NativeArguments args) {
DartArgIterator it(args);
Float64List matrix4 = it.GetNext<Float64List>();
if (it.had_exception())
return;
ExceptionState es;
GetReceiver<Canvas>(args)->setMatrix(matrix4, es);
if (es.had_exception())
Dart_ThrowException(es.GetDartException(args, true));
}
IMPLEMENT_WRAPPERTYPEINFO(Canvas);
#define FOR_EACH_BINDING(V) \
V(Canvas, save) \
V(Canvas, saveLayer) \
V(Canvas, restore) \
V(Canvas, getSaveCount) \
V(Canvas, translate) \
V(Canvas, scale) \
V(Canvas, rotate) \
V(Canvas, skew) \
V(Canvas, getTotalMatrix) \
V(Canvas, clipRect) \
V(Canvas, clipRRect) \
V(Canvas, clipPath) \
V(Canvas, drawColor) \
V(Canvas, drawLine) \
V(Canvas, drawPaint) \
V(Canvas, drawRect) \
V(Canvas, drawRRect) \
V(Canvas, drawDRRect) \
V(Canvas, drawOval) \
V(Canvas, drawCircle) \
V(Canvas, drawPath) \
V(Canvas, drawImage) \
V(Canvas, drawImageRect) \
V(Canvas, drawImageNine) \
V(Canvas, drawPicture) \
V(Canvas, drawVertices) \
V(Canvas, drawAtlas)
// These are custom because of ExceptionState:
// V(Canvas, concat)
// V(Canvas, setMatrix)
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
void Canvas::RegisterNatives(DartLibraryNatives* natives) {
natives->Register({
{ "Canvas_constructor", Canvas_constructor, 3, true },
{ "Canvas_concat", Canvas_concat, 2, true },
{ "Canvas_setMatrix", Canvas_setMatrix, 2, true },
FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
PassRefPtr<Canvas> Canvas::create(PictureRecorder* recorder,
Rect& bounds) {
ASSERT(recorder);
ASSERT(!recorder->isRecording());
PassRefPtr<Canvas> canvas = adoptRef(new Canvas(recorder->beginRecording(bounds)));
recorder->set_canvas(canvas.get());
return canvas;
}
Canvas::Canvas(SkCanvas* skCanvas)
: m_canvas(skCanvas)
{
@ -102,7 +187,7 @@ void Canvas::setMatrix(const Float64List& matrix4, ExceptionState& es)
m_canvas->setMatrix(sk_matrix);
}
Float64List Canvas::getTotalMatrix() const
Float64List Canvas::getTotalMatrix()
{
// Maybe we should throw an exception instead of returning an empty matrix?
SkMatrix sk_matrix;
@ -132,7 +217,7 @@ void Canvas::clipPath(const CanvasPath* path)
m_canvas->clipPath(path->path(), SkRegion::kIntersect_Op);
}
void Canvas::drawColor(SkColor color, SkXfermode::Mode transferMode)
void Canvas::drawColor(CanvasColor color, TransferMode transferMode)
{
if (!m_canvas)
return;
@ -231,97 +316,73 @@ void Canvas::drawVertices(SkCanvas::VertexMode vertexMode,
const Vector<Point>& vertices,
const Vector<Point>& textureCoordinates,
const Vector<SkColor>& colors,
SkXfermode::Mode transferMode,
TransferMode transferMode,
const Vector<int>& indices,
const Paint& paint,
ExceptionState& es)
const Paint& paint)
{
if (!m_canvas)
return;
size_t vertexCount = vertices.size();
if (!m_canvas)
return;
if (textureCoordinates.size() && textureCoordinates.size() != vertexCount)
return es.ThrowRangeError("vertices and textureCoordinates lengths must match");
if (colors.size() && colors.size() != vertexCount)
return es.ThrowRangeError("vertices and colors lengths must match");
Vector<SkPoint> skVertices;
skVertices.reserveInitialCapacity(vertices.size());
for (const Point& point : vertices)
skVertices.append(point.sk_point);
Vector<SkPoint> skVertices;
for (size_t x = 0; x < vertices.size(); x++) {
const Point& point = vertices[x];
if (point.is_null)
return es.ThrowRangeError("vertices contained a null");
skVertices.append(point.sk_point);
}
Vector<SkPoint> skTextureCoordinates;
skVertices.reserveInitialCapacity(textureCoordinates.size());
for (const Point& point : textureCoordinates)
skTextureCoordinates.append(point.sk_point);
Vector<SkPoint> skTextureCoordinates;
for (size_t x = 0; x < textureCoordinates.size(); x++) {
const Point& point = textureCoordinates[x];
if (point.is_null)
return es.ThrowRangeError("textureCoordinates contained a null");
skTextureCoordinates.append(point.sk_point);
}
Vector<uint16_t> skIndices;
skIndices.reserveInitialCapacity(indices.size());
for (uint16_t i : indices)
skIndices.append(i);
Vector<uint16_t> skIndices;
for (size_t x = 0; x < indices.size(); x++) {
uint16_t i = indices[x];
skIndices.append(i);
}
RefPtr<SkXfermode> transferModePtr = adoptRef(SkXfermode::Create(transferMode));
RefPtr<SkXfermode> transferModePtr = adoptRef(SkXfermode::Create(transferMode));
m_canvas->drawVertices(
vertexMode,
skVertices.size(),
skVertices.data(),
skTextureCoordinates.isEmpty() ? nullptr : skTextureCoordinates.data(),
colors.isEmpty() ? nullptr : colors.data(),
transferModePtr.get(),
skIndices.isEmpty() ? nullptr : skIndices.data(),
skIndices.size(),
*paint.paint()
);
m_canvas->drawVertices(
vertexMode,
skVertices.size(),
skVertices.data(),
skTextureCoordinates.isEmpty() ? nullptr : skTextureCoordinates.data(),
colors.isEmpty() ? nullptr : colors.data(),
transferModePtr.get(),
skIndices.isEmpty() ? nullptr : skIndices.data(),
skIndices.size(),
*paint.paint()
);
}
void Canvas::drawAtlas(CanvasImage* atlas,
const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
const Vector<SkColor>& colors, SkXfermode::Mode mode,
const Rect& cullRect, const Paint& paint, ExceptionState& es)
const Vector<SkColor>& colors, TransferMode mode,
const Rect& cullRect, const Paint& paint)
{
if (!m_canvas)
return;
RefPtr<SkImage> skImage = atlas->image();
if (transforms.size() != rects.size())
return es.ThrowRangeError("transforms and rects lengths must match");
if (colors.size() && colors.size() != rects.size())
return es.ThrowRangeError("if supplied, colors length must match that of transforms and rects");
if (!m_canvas)
return;
Vector<SkRSXform> skXForms;
for (size_t x = 0; x < transforms.size(); x++) {
const RSTransform& transform = transforms[x];
if (transform.is_null)
return es.ThrowRangeError("transforms contained a null");
skXForms.append(transform.sk_xform);
}
RefPtr<SkImage> skImage = atlas->image();
Vector<SkRect> skRects;
for (size_t x = 0; x < rects.size(); x++) {
const Rect& rect = rects[x];
if (rect.is_null)
return es.ThrowRangeError("rects contained a null");
skRects.append(rect.sk_rect);
}
Vector<SkRSXform> skXForms;
skXForms.reserveInitialCapacity(transforms.size());
for (const RSTransform& transform : transforms)
skXForms.append(transform.sk_xform);
m_canvas->drawAtlas(
skImage.get(),
skXForms.data(),
skRects.data(),
colors.isEmpty() ? nullptr : colors.data(),
skXForms.size(),
mode,
cullRect.is_null ? nullptr : &cullRect.sk_rect,
paint.paint()
);
Vector<SkRect> skRects;
skRects.reserveInitialCapacity(rects.size());
for (const Rect& rect : rects)
skRects.append(rect.sk_rect);
m_canvas->drawAtlas(
skImage.get(),
skXForms.data(),
skRects.data(),
colors.isEmpty() ? nullptr : colors.data(),
skXForms.size(),
mode,
cullRect.is_null ? nullptr : &cullRect.sk_rect,
paint.paint()
);
}
} // namespace blink

View File

@ -16,7 +16,6 @@
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/core/painting/Size.h"
#include "sky/engine/core/painting/RSTransform.h"
#include "sky/engine/core/painting/VertexMode.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/tonic/float64_list.h"
#include "sky/engine/wtf/PassRefPtr.h"
@ -24,37 +23,16 @@
#include "third_party/skia/include/core/SkCanvas.h"
namespace blink {
class DartLibraryNatives;
class CanvasImage;
template <>
struct DartConverter<SkCanvas::VertexMode> : public DartConverterInteger<SkCanvas::VertexMode> {};
class Canvas : public RefCounted<Canvas>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtr<Canvas> create(SkCanvas* skCanvas) {
ASSERT(skCanvas);
return adoptRef(new Canvas(skCanvas));
}
// TODO(ianh): fix crashes here https://github.com/domokit/mojo/issues/326
static PassRefPtr<Canvas> create(PictureRecorder* recorder,
Rect& bounds,
ExceptionState& es) {
ASSERT(recorder);
if (recorder->isRecording()) {
es.ThrowTypeError(
"You must call PictureRecorder.endRecording() before reusing a"
" PictureRecorder to create a new Canvas object.");
// TODO(iansf): We should return a nullptr here, I think, but doing
// so will require modifying the dart template code to
// to correctly handle constructors that throw
// exceptions. For now, just let it return a dart
// object that may cause a crash later on -- if the
// dart code catches the error, it will leak a canvas
// but it won't crash.
}
PassRefPtr<Canvas> canvas = create(recorder->beginRecording(bounds));
recorder->set_canvas(canvas.get());
return canvas;
}
static PassRefPtr<Canvas> create(PictureRecorder* recorder, Rect& bounds);
~Canvas() override;
@ -70,13 +48,13 @@ public:
void concat(const Float64List& matrix4, ExceptionState&);
void setMatrix(const Float64List& matrix4, ExceptionState&);
Float64List getTotalMatrix() const;
Float64List getTotalMatrix();
void clipRect(const Rect& rect);
void clipRRect(const RRect& rrect);
void clipPath(const CanvasPath* path);
void drawColor(SkColor color, SkXfermode::Mode transferMode);
void drawColor(CanvasColor color, TransferMode transferMode);
void drawLine(const Point& p1, const Point& p2, const Paint& paint);
void drawPaint(const Paint& paint);
void drawRect(const Rect& rect, const Paint& paint);
@ -94,20 +72,21 @@ public:
const Vector<Point>& vertices,
const Vector<Point>& textureCoordinates,
const Vector<SkColor>& colors,
SkXfermode::Mode transferMode,
TransferMode transferMode,
const Vector<int>& indices,
const Paint& paint,
ExceptionState& es);
const Paint& paint);
void drawAtlas(CanvasImage* atlas,
const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
const Vector<SkColor>& colors, SkXfermode::Mode mode,
const Rect& cullRect, const Paint& paint, ExceptionState&);
const Vector<SkColor>& colors, TransferMode mode,
const Rect& cullRect, const Paint& paint);
SkCanvas* skCanvas() { return m_canvas; }
void clearSkCanvas() { m_canvas = nullptr; }
bool isRecording() const { return !!m_canvas; }
static void RegisterNatives(DartLibraryNatives* natives);
protected:
explicit Canvas(SkCanvas* skCanvas);

View File

@ -1,48 +0,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.
// TODO(mpcomplete): Figure out a better SkMatrix representation.
[
Constructor(PictureRecorder recorder, Rect bounds),
RaisesException=Constructor,
] interface Canvas {
void save();
// TODO(jackson): Paint should be optional, but making it optional causes crash
void saveLayer(Rect bounds, /* optional */ Paint paint);
void restore();
int getSaveCount(); // returns 1 for a clean canvas; each call to save() or saveLayer() increments it, and each call to restore() decrements it.
void translate(float dx, float dy);
void scale(float sx, float sy);
void rotate(float radians);
void skew(float sx, float sy);
[RaisesException] void concat(Float64List matrix4);
[RaisesException] void setMatrix(Float64List matrix4);
Float64List getTotalMatrix();
void clipRect(Rect rect);
void clipRRect(RRect rrect);
void clipPath(Path path);
void drawColor(Color color, TransferMode transferMode);
void drawLine(Point p1, Point p2, Paint paint);
void drawPaint(Paint paint);
void drawRect(Rect rect, Paint paint);
void drawRRect(RRect rrect, Paint paint);
void drawDRRect(RRect outer, RRect inner, Paint paint);
void drawOval(Rect rect, Paint paint);
void drawCircle(Point c, float radius, Paint paint);
void drawPath(Path path, Paint paint);
void drawImage(Image image, Point p, Paint paint);
void drawImageRect(Image image, Rect src, Rect dst, Paint paint);
void drawImageNine(Image image, Rect center, Rect dst, Paint paint);
void drawPicture(Picture picture);
[RaisesException] void drawVertices(VertexMode vertexMode, sequence<Point> vertices, sequence<Point> textureCoordinates, sequence<Color> colors, TransferMode transferMode, sequence<long> indicies, Paint paint);
// TODO(eseidel): Paint should be optional, but optional doesn't work.
[RaisesException] void drawAtlas(Image image,
sequence<RSTransform> transforms, sequence<Rect> rects,
sequence<Color> colors, TransferMode mode, Rect cullRect, Paint paint);
};

View File

@ -4,19 +4,41 @@
#include "sky/engine/core/painting/CanvasImage.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 CanvasImage Image;
IMPLEMENT_WRAPPERTYPEINFO(Image);
#define FOR_EACH_BINDING(V) \
V(Image, width) \
V(Image, height) \
V(Image, dispose)
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
void CanvasImage::RegisterNatives(DartLibraryNatives* natives) {
natives->Register({
FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
CanvasImage::CanvasImage() {
}
CanvasImage::~CanvasImage() {
}
int CanvasImage::width() const {
int CanvasImage::width() {
return image_->width();
}
int CanvasImage::height() const {
int CanvasImage::height() {
return image_->height();
}

View File

@ -10,6 +10,7 @@
#include "third_party/skia/include/core/SkImage.h"
namespace blink {
class DartLibraryNatives;
class CanvasImage final : public RefCounted<CanvasImage>,
public DartWrappable {
@ -18,13 +19,15 @@ class CanvasImage final : public RefCounted<CanvasImage>,
~CanvasImage() override;
static PassRefPtr<CanvasImage> create() { return adoptRef(new CanvasImage); }
int width() const;
int height() const;
int width();
int height();
void dispose();
SkImage* image() const { return image_.get(); }
void setImage(PassRefPtr<SkImage> image) { image_ = image; }
static void RegisterNatives(DartLibraryNatives* natives);
private:
CanvasImage();

View File

@ -4,8 +4,50 @@
#include "sky/engine/core/painting/CanvasPath.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 CanvasPath Path;
static void Path_constructor(Dart_NativeArguments args) {
DartCallConstructor(&CanvasPath::create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(Path);
#define FOR_EACH_BINDING(V) \
V(Path, moveTo) \
V(Path, relativeMoveTo) \
V(Path, lineTo) \
V(Path, relativeLineTo) \
V(Path, quadraticBezierTo) \
V(Path, relativeQuadraticBezierTo) \
V(Path, cubicTo) \
V(Path, relativeCubicTo) \
V(Path, conicTo) \
V(Path, relativeConicTo) \
V(Path, arcTo) \
V(Path, addRect) \
V(Path, addOval) \
V(Path, addArc) \
V(Path, addRRect) \
V(Path, close) \
V(Path, reset) \
V(Path, shift)
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
void CanvasPath::RegisterNatives(DartLibraryNatives* natives) {
natives->Register({
{ "Path_constructor", Path_constructor, 1, true },
FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
CanvasPath::CanvasPath()
{
}

View File

@ -20,6 +20,7 @@
// (The existence of that class is why this is CanvasPath and not just Path.)
namespace blink {
class DartLibraryNatives;
class CanvasPath : public RefCounted<CanvasPath>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
@ -64,6 +65,8 @@ public:
PassRefPtr<CanvasPath> shift(const Offset& offset);
static void RegisterNatives(DartLibraryNatives* natives);
private:
CanvasPath();

View File

@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "sky/engine/core/painting/DrawLooperLayerInfo.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"

View File

@ -1,14 +0,0 @@
// Copyright 2013 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.
[
Constructor(),
ImplementedAs=CanvasImage,
] interface Image {
// TODO(ianh): convert this to a Size
readonly attribute long width; // width in number of image pixels
readonly attribute long height; // height in number of image pixels
void dispose();
};

View File

@ -1,30 +0,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.
[
Constructor(),
ImplementedAs=CanvasPath,
] interface Path {
void moveTo(float x, float y);
void relativeMoveTo(float dx, float dy);
void lineTo(float x, float y);
void relativeLineTo(float dx, float dy);
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(Rect rect, float startAngle, float sweepAngle, boolean forceMoveTo); // angles in radians
void addRect(Rect rect);
void addOval(Rect oval);
void addArc(Rect oval, float startAngle, float sweepAngle); // angles in radians
void addRRect(RRect rrect);
void close();
void reset();
Path shift(Offset offset);
};

View File

@ -5,9 +5,21 @@
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/Canvas.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 {
IMPLEMENT_WRAPPERTYPEINFO(Picture);
#define FOR_EACH_BINDING(V) \
V(Picture, playback) \
V(Picture, dispose)
DART_BIND_ALL(Picture, FOR_EACH_BINDING)
PassRefPtr<Picture> Picture::create(PassRefPtr<SkPicture> skPicture)
{
ASSERT(skPicture);

View File

@ -11,8 +11,8 @@
#include "third_party/skia/include/core/SkPicture.h"
namespace blink {
class Canvas;
class DartLibraryNatives;
class Picture : public RefCounted<Picture>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
@ -25,6 +25,8 @@ public:
void playback(Canvas* canvas);
void dispose();
static void RegisterNatives(DartLibraryNatives* natives);
private:
explicit Picture(PassRefPtr<SkPicture> skPicture);

View File

@ -1,12 +0,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.
interface Picture {
// Replays the drawing commands on the specified canvas. Note that
// this has the effect of unfurling this picture into the destination
// canvas. Using the Canvas drawPicture entry point gives the destination
// canvas the option of just taking a ref.
void playback(Canvas canvas);
void dispose();
};

View File

@ -2,12 +2,36 @@
// 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/Canvas.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/PictureRecorder.h"
#include "sky/engine/core/painting/Canvas.h"
#include "sky/engine/core/painting/Picture.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 PictureRecorder_constructor(Dart_NativeArguments args) {
DartCallConstructor(&PictureRecorder::create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(PictureRecorder);
#define FOR_EACH_BINDING(V) \
V(PictureRecorder, isRecording) \
V(PictureRecorder, endRecording)
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
void PictureRecorder::RegisterNatives(DartLibraryNatives* natives) {
natives->Register({
{ "PictureRecorder_constructor", PictureRecorder_constructor, 1, true },
FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
PictureRecorder::PictureRecorder()
{
}

View File

@ -12,8 +12,8 @@
#include "third_party/skia/include/core/SkPictureRecorder.h"
namespace blink {
class Canvas;
class DartLibraryNatives;
class Picture;
class PictureRecorder : public RefCounted<PictureRecorder>,
@ -33,6 +33,8 @@ public:
void set_canvas(PassRefPtr<Canvas> canvas);
static void RegisterNatives(DartLibraryNatives* natives);
private:
PictureRecorder();

View File

@ -1,8 +0,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.
[
Constructor()
] interface PictureRecorder {
Picture endRecording();
};

View File

@ -1,12 +0,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;
/// Defines how a list of points is interpreted when drawing a set of triangles. See Skia or OpenGL documentation for more details.
enum VertexMode {
triangles,
triangleStrip,
triangleFan,
}

View File

@ -1,21 +0,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.
#ifndef SKY_ENGINE_CORE_PAINTING_VERTEXMODE_H_
#define SKY_ENGINE_CORE_PAINTING_VERTEXMODE_H_
#include "sky/engine/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace blink {
class VertexMode {};
template <>
struct DartConverter<VertexMode>
: public DartConverterEnum<SkCanvas::VertexMode> {};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_VERTEXMODE_H_

View File

@ -6,6 +6,7 @@
#define SKY_ENGINE_TONIC_DART_ARGS_H_
#include <type_traits>
#include <utility>
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_wrappable.h"
@ -92,7 +93,7 @@ struct DartArgHolder {
template<typename T>
void DartReturn(T result, Dart_NativeArguments args) {
DartConverter<T>::SetReturnValue(args, result);
DartConverter<T>::SetReturnValue(args, std::move(result));
}
template <typename IndicesType, typename T>