From b714feca626f1e3989224ab4ef43bff7913a3d19 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 29 Dec 2015 00:06:57 -0800 Subject: [PATCH 1/2] Remove IDL from Canvas and related interfaces After this patch, Path is the only interface using IDL. --- sky/engine/bindings/dart_ui.cc | 8 + sky/engine/core/core.gni | 6 - sky/engine/core/dart/painting.dart | 137 ++++++++++++ sky/engine/core/painting/Canvas.cpp | 219 ++++++++++++------- sky/engine/core/painting/Canvas.h | 47 ++-- sky/engine/core/painting/Canvas.idl | 48 ---- sky/engine/core/painting/CanvasImage.cpp | 26 ++- sky/engine/core/painting/CanvasImage.h | 7 +- sky/engine/core/painting/Image.idl | 14 -- sky/engine/core/painting/Picture.cpp | 12 + sky/engine/core/painting/Picture.h | 4 +- sky/engine/core/painting/Picture.idl | 12 - sky/engine/core/painting/PictureRecorder.cpp | 28 ++- sky/engine/core/painting/PictureRecorder.h | 4 +- sky/engine/core/painting/PictureRecorder.idl | 8 - sky/engine/core/painting/VertexMode.dart | 12 - sky/engine/core/painting/VertexMode.h | 21 -- sky/engine/tonic/dart_args.h | 3 +- 18 files changed, 373 insertions(+), 243 deletions(-) delete mode 100644 sky/engine/core/painting/Canvas.idl delete mode 100644 sky/engine/core/painting/Image.idl delete mode 100644 sky/engine/core/painting/Picture.idl delete mode 100644 sky/engine/core/painting/PictureRecorder.idl delete mode 100644 sky/engine/core/painting/VertexMode.dart delete mode 100644 sky/engine/core/painting/VertexMode.h diff --git a/sky/engine/bindings/dart_ui.cc b/sky/engine/bindings/dart_ui.cc index 487c7e6fdbf..ad88383c219 100644 --- a/sky/engine/bindings/dart_ui.cc +++ b/sky/engine/bindings/dart_ui.cc @@ -8,13 +8,17 @@ #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/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" @@ -47,7 +51,9 @@ 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); ColorFilter::RegisterNatives(g_natives); DartRuntimeHooks::RegisterNatives(g_natives); DrawLooperLayerInfo::RegisterNatives(g_natives); @@ -57,6 +63,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); diff --git a/sky/engine/core/core.gni b/sky/engine/core/core.gni index 432045a4dd3..7054a93c06a 100644 --- a/sky/engine/core/core.gni +++ b/sky/engine/core/core.gni @@ -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", @@ -234,11 +233,7 @@ sky_core_files = [ ] core_idl_files = get_path_info([ - "painting/Canvas.idl", - "painting/Image.idl", "painting/Path.idl", - "painting/Picture.idl", - "painting/PictureRecorder.idl", ], "abspath") @@ -263,6 +258,5 @@ core_dart_files = get_path_info([ "painting/Rect.dart", "painting/Size.dart", "painting/TransferMode.dart", - "painting/VertexMode.dart", ], "abspath") diff --git a/sky/engine/core/dart/painting.dart b/sky/engine/core/dart/painting.dart index 04163b659ad..b66f1ebd59a 100644 --- a/sky/engine/core/dart/painting.dart +++ b/sky/engine/core/dart/painting.dart @@ -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) @@ -156,3 +163,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 vertices, + List textureCoordinates, + List colors, + TransferMode transferMode, + List indicies, + Paint paint) native "Canvas_drawVertices"; + + void drawVertices(VertexMode vertexMode, + List vertices, + List textureCoordinates, + List colors, + TransferMode transferMode, + List 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 transforms, + List rects, + List colors, + TransferMode mode, + Rect cullRect, + Paint paint) native "Canvas_drawAtlas"; + + void drawAtlas(Image image, + List transforms, + List rects, + List 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"; +} diff --git a/sky/engine/core/painting/Canvas.cpp b/sky/engine/core/painting/Canvas.cpp index 693c9d77d9a..00cb4116070 100644 --- a/sky/engine/core/painting/Canvas.cpp +++ b/sky/engine/core/painting/Canvas.cpp @@ -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(); + if (it.had_exception()) + return; + ExceptionState es; + GetReceiver(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(); + if (it.had_exception()) + return; + ExceptionState es; + GetReceiver(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::create(PictureRecorder* recorder, + Rect& bounds) { + ASSERT(recorder); + ASSERT(!recorder->isRecording()); + PassRefPtr 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& vertices, const Vector& textureCoordinates, const Vector& colors, - SkXfermode::Mode transferMode, + TransferMode transferMode, const Vector& 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 skVertices; + skVertices.reserveInitialCapacity(vertices.size()); + for (const Point& point : vertices) + skVertices.append(point.sk_point); - Vector 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 skTextureCoordinates; + skVertices.reserveInitialCapacity(textureCoordinates.size()); + for (const Point& point : textureCoordinates) + skTextureCoordinates.append(point.sk_point); - Vector 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 skIndices; + skIndices.reserveInitialCapacity(indices.size()); + for (uint16_t i : indices) + skIndices.append(i); - Vector skIndices; - for (size_t x = 0; x < indices.size(); x++) { - uint16_t i = indices[x]; - skIndices.append(i); - } + RefPtr transferModePtr = adoptRef(SkXfermode::Create(transferMode)); - RefPtr 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& transforms, const Vector& rects, - const Vector& colors, SkXfermode::Mode mode, - const Rect& cullRect, const Paint& paint, ExceptionState& es) + const Vector& colors, TransferMode mode, + const Rect& cullRect, const Paint& paint) { - if (!m_canvas) - return; - RefPtr 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 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 = atlas->image(); - Vector 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 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 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 diff --git a/sky/engine/core/painting/Canvas.h b/sky/engine/core/painting/Canvas.h index 0394135c699..bb31c06187b 100644 --- a/sky/engine/core/painting/Canvas.h +++ b/sky/engine/core/painting/Canvas.h @@ -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 : public DartConverterInteger {}; + class Canvas : public RefCounted, public DartWrappable { DEFINE_WRAPPERTYPEINFO(); public: - static PassRefPtr create(SkCanvas* skCanvas) { - ASSERT(skCanvas); - return adoptRef(new Canvas(skCanvas)); - } - - // TODO(ianh): fix crashes here https://github.com/domokit/mojo/issues/326 - static PassRefPtr 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 = create(recorder->beginRecording(bounds)); - recorder->set_canvas(canvas.get()); - return canvas; - } + static PassRefPtr 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& vertices, const Vector& textureCoordinates, const Vector& colors, - SkXfermode::Mode transferMode, + TransferMode transferMode, const Vector& indices, - const Paint& paint, - ExceptionState& es); + const Paint& paint); void drawAtlas(CanvasImage* atlas, const Vector& transforms, const Vector& rects, - const Vector& colors, SkXfermode::Mode mode, - const Rect& cullRect, const Paint& paint, ExceptionState&); + const Vector& 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); diff --git a/sky/engine/core/painting/Canvas.idl b/sky/engine/core/painting/Canvas.idl deleted file mode 100644 index 740c68ea9b9..00000000000 --- a/sky/engine/core/painting/Canvas.idl +++ /dev/null @@ -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 vertices, sequence textureCoordinates, sequence colors, TransferMode transferMode, sequence indicies, Paint paint); - - // TODO(eseidel): Paint should be optional, but optional doesn't work. - [RaisesException] void drawAtlas(Image image, - sequence transforms, sequence rects, - sequence colors, TransferMode mode, Rect cullRect, Paint paint); -}; diff --git a/sky/engine/core/painting/CanvasImage.cpp b/sky/engine/core/painting/CanvasImage.cpp index f63a4ed955d..876b6bed589 100644 --- a/sky/engine/core/painting/CanvasImage.cpp +++ b/sky/engine/core/painting/CanvasImage.cpp @@ -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(); } diff --git a/sky/engine/core/painting/CanvasImage.h b/sky/engine/core/painting/CanvasImage.h index 2ab9f87cdc6..e1cb6aac01c 100644 --- a/sky/engine/core/painting/CanvasImage.h +++ b/sky/engine/core/painting/CanvasImage.h @@ -10,6 +10,7 @@ #include "third_party/skia/include/core/SkImage.h" namespace blink { +class DartLibraryNatives; class CanvasImage final : public RefCounted, public DartWrappable { @@ -18,13 +19,15 @@ class CanvasImage final : public RefCounted, ~CanvasImage() override; static PassRefPtr 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 image) { image_ = image; } + static void RegisterNatives(DartLibraryNatives* natives); + private: CanvasImage(); diff --git a/sky/engine/core/painting/Image.idl b/sky/engine/core/painting/Image.idl deleted file mode 100644 index deed739872b..00000000000 --- a/sky/engine/core/painting/Image.idl +++ /dev/null @@ -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(); -}; diff --git a/sky/engine/core/painting/Picture.cpp b/sky/engine/core/painting/Picture.cpp index 099d1fa3b98..6e4588681bb 100644 --- a/sky/engine/core/painting/Picture.cpp +++ b/sky/engine/core/painting/Picture.cpp @@ -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::create(PassRefPtr skPicture) { ASSERT(skPicture); diff --git a/sky/engine/core/painting/Picture.h b/sky/engine/core/painting/Picture.h index 5c990b0c644..847ccd9c074 100644 --- a/sky/engine/core/painting/Picture.h +++ b/sky/engine/core/painting/Picture.h @@ -11,8 +11,8 @@ #include "third_party/skia/include/core/SkPicture.h" namespace blink { - class Canvas; +class DartLibraryNatives; class Picture : public RefCounted, 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); diff --git a/sky/engine/core/painting/Picture.idl b/sky/engine/core/painting/Picture.idl deleted file mode 100644 index 646b99eff4c..00000000000 --- a/sky/engine/core/painting/Picture.idl +++ /dev/null @@ -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(); -}; diff --git a/sky/engine/core/painting/PictureRecorder.cpp b/sky/engine/core/painting/PictureRecorder.cpp index 5b93b511489..819d8aa8813 100644 --- a/sky/engine/core/painting/PictureRecorder.cpp +++ b/sky/engine/core/painting/PictureRecorder.cpp @@ -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() { } diff --git a/sky/engine/core/painting/PictureRecorder.h b/sky/engine/core/painting/PictureRecorder.h index 358965ed4dd..5a360bcf038 100644 --- a/sky/engine/core/painting/PictureRecorder.h +++ b/sky/engine/core/painting/PictureRecorder.h @@ -12,8 +12,8 @@ #include "third_party/skia/include/core/SkPictureRecorder.h" namespace blink { - class Canvas; +class DartLibraryNatives; class Picture; class PictureRecorder : public RefCounted, @@ -33,6 +33,8 @@ public: void set_canvas(PassRefPtr canvas); + static void RegisterNatives(DartLibraryNatives* natives); + private: PictureRecorder(); diff --git a/sky/engine/core/painting/PictureRecorder.idl b/sky/engine/core/painting/PictureRecorder.idl deleted file mode 100644 index 78794c334a6..00000000000 --- a/sky/engine/core/painting/PictureRecorder.idl +++ /dev/null @@ -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(); -}; diff --git a/sky/engine/core/painting/VertexMode.dart b/sky/engine/core/painting/VertexMode.dart deleted file mode 100644 index 518a963106e..00000000000 --- a/sky/engine/core/painting/VertexMode.dart +++ /dev/null @@ -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, -} diff --git a/sky/engine/core/painting/VertexMode.h b/sky/engine/core/painting/VertexMode.h deleted file mode 100644 index 9863b1457f8..00000000000 --- a/sky/engine/core/painting/VertexMode.h +++ /dev/null @@ -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 - : public DartConverterEnum {}; - -} // namespace blink - -#endif // SKY_ENGINE_CORE_PAINTING_VERTEXMODE_H_ diff --git a/sky/engine/tonic/dart_args.h b/sky/engine/tonic/dart_args.h index 0253e075771..42e20371a78 100644 --- a/sky/engine/tonic/dart_args.h +++ b/sky/engine/tonic/dart_args.h @@ -6,6 +6,7 @@ #define SKY_ENGINE_TONIC_DART_ARGS_H_ #include +#include #include "sky/engine/tonic/dart_converter.h" #include "sky/engine/tonic/dart_wrappable.h" @@ -92,7 +93,7 @@ struct DartArgHolder { template void DartReturn(T result, Dart_NativeArguments args) { - DartConverter::SetReturnValue(args, result); + DartConverter::SetReturnValue(args, std::move(result)); } template From 03e39488282405fb525b60ef2c0c568e98f6f1f3 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 29 Dec 2015 00:41:30 -0800 Subject: [PATCH 2/2] Remove Path.idl This patch removes the last IDL file from the build and unhooks the bulk of the IDL compiler from the build system. A later patch will actually delete the IDL compiler. --- sky/engine/bindings/BUILD.gn | 219 +----------------- sky/engine/bindings/bindings.gni | 44 ---- sky/engine/bindings/dart_ui.cc | 13 +- sky/engine/core/core.gni | 5 - sky/engine/core/dart/painting.dart | 24 ++ sky/engine/core/painting/CanvasPath.cpp | 42 ++++ sky/engine/core/painting/CanvasPath.h | 3 + .../core/painting/DrawLooperLayerInfo.cpp | 1 + sky/engine/core/painting/Path.idl | 30 --- 9 files changed, 76 insertions(+), 305 deletions(-) delete mode 100644 sky/engine/core/painting/Path.idl diff --git a/sky/engine/bindings/BUILD.gn b/sky/engine/bindings/BUILD.gn index 2d2ff101cb4..7bc030ad148 100644 --- a/sky/engine/bindings/BUILD.gn +++ b/sky/engine/bindings/BUILD.gn @@ -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") -} diff --git a/sky/engine/bindings/bindings.gni b/sky/engine/bindings/bindings.gni index 237ed0f5dbd..90c87b42590 100644 --- a/sky/engine/bindings/bindings.gni +++ b/sky/engine/bindings/bindings.gni @@ -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 diff --git a/sky/engine/bindings/dart_ui.cc b/sky/engine/bindings/dart_ui.cc index ad88383c219..d24472da75b 100644 --- a/sky/engine/bindings/dart_ui.cc +++ b/sky/engine/bindings/dart_ui.cc @@ -4,13 +4,13 @@ #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" @@ -33,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 @@ -54,6 +48,7 @@ void DartUI::InitForIsolate() { 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); diff --git a/sky/engine/core/core.gni b/sky/engine/core/core.gni index 7054a93c06a..2ddf5bb70ab 100644 --- a/sky/engine/core/core.gni +++ b/sky/engine/core/core.gni @@ -232,11 +232,6 @@ sky_core_files = [ "window/window.h", ] -core_idl_files = get_path_info([ - "painting/Path.idl", - ], - "abspath") - core_dart_files = get_path_info([ "dart/compositing.dart", "dart/hash_codes.dart", diff --git a/sky/engine/core/dart/painting.dart b/sky/engine/core/dart/painting.dart index b66f1ebd59a..a191fa1d33b 100644 --- a/sky/engine/core/dart/painting.dart +++ b/sky/engine/core/dart/painting.dart @@ -19,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 { } diff --git a/sky/engine/core/painting/CanvasPath.cpp b/sky/engine/core/painting/CanvasPath.cpp index 51f740037de..f890fb9fcca 100644 --- a/sky/engine/core/painting/CanvasPath.cpp +++ b/sky/engine/core/painting/CanvasPath.cpp @@ -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() { } diff --git a/sky/engine/core/painting/CanvasPath.h b/sky/engine/core/painting/CanvasPath.h index 31bd816e1f2..fb83550ea0a 100644 --- a/sky/engine/core/painting/CanvasPath.h +++ b/sky/engine/core/painting/CanvasPath.h @@ -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, public DartWrappable { DEFINE_WRAPPERTYPEINFO(); @@ -64,6 +65,8 @@ public: PassRefPtr shift(const Offset& offset); + static void RegisterNatives(DartLibraryNatives* natives); + private: CanvasPath(); diff --git a/sky/engine/core/painting/DrawLooperLayerInfo.cpp b/sky/engine/core/painting/DrawLooperLayerInfo.cpp index 785d0dbda36..ae7235f2fc7 100644 --- a/sky/engine/core/painting/DrawLooperLayerInfo.cpp +++ b/sky/engine/core/painting/DrawLooperLayerInfo.cpp @@ -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" diff --git a/sky/engine/core/painting/Path.idl b/sky/engine/core/painting/Path.idl deleted file mode 100644 index dcc4d23db3a..00000000000 --- a/sky/engine/core/painting/Path.idl +++ /dev/null @@ -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); -};