From b714feca626f1e3989224ab4ef43bff7913a3d19 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 29 Dec 2015 00:06:57 -0800 Subject: [PATCH] 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 | 235 ++++++++++++------- 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 | 26 +- 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, 380 insertions(+), 250 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 487c7e6fd..ad88383c2 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 432045a4d..7054a93c0 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 04163b659..b66f1ebd5 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 693c9d77d..00cb41160 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 (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; - 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; - 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; - for (size_t x = 0; x < indices.size(); x++) { - uint16_t i = indices[x]; - skIndices.append(i); - } - - 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() - ); + if (!m_canvas) + return; + + Vector skVertices; + skVertices.reserveInitialCapacity(vertices.size()); + for (const Point& point : vertices) + skVertices.append(point.sk_point); + + Vector skTextureCoordinates; + skVertices.reserveInitialCapacity(textureCoordinates.size()); + for (const Point& point : textureCoordinates) + skTextureCoordinates.append(point.sk_point); + + Vector skIndices; + skIndices.reserveInitialCapacity(indices.size()); + for (uint16_t i : indices) + skIndices.append(i); + + 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() + ); } 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"); - - 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); - } - - 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); - } - - 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() - ); + if (!m_canvas) + return; + + RefPtr skImage = atlas->image(); + + Vector skXForms; + skXForms.reserveInitialCapacity(transforms.size()); + for (const RSTransform& transform : transforms) + skXForms.append(transform.sk_xform); + + 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 0394135c6..bb31c0618 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 740c68ea9..000000000 --- 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 f63a4ed95..876b6bed5 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 2ab9f87cd..e1cb6aac0 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 deed73987..000000000 --- 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 099d1fa3b..6e4588681 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 5c990b0c6..847ccd9c0 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 646b99eff..000000000 --- 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 5b93b5114..819d8aa88 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/PictureRecorder.h" + #include "sky/engine/core/painting/Canvas.h" #include "sky/engine/core/painting/Picture.h" -#include "sky/engine/core/painting/PictureRecorder.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 358965ed4..5a360bcf0 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 78794c334..000000000 --- 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 518a96310..000000000 --- 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 9863b1457..000000000 --- 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 0253e0757..42e20371a 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 -- GitLab