diff --git a/flutter/lib/ui/BUILD.gn b/flutter/lib/ui/BUILD.gn index 69c8f1beb2288cb753410ac4df30b7a42f6b7237..91e9a76d40c1b2ec84114ec54ff6bfafce086df6 100644 --- a/flutter/lib/ui/BUILD.gn +++ b/flutter/lib/ui/BUILD.gn @@ -4,9 +4,17 @@ source_set("ui") { sources = [ + "compositing/scene_builder.cc", + "compositing/scene_builder.h", + "compositing/scene.cc", + "compositing/scene.h", + "painting/canvas.cc", + "painting/canvas.h", "painting/gradient.cc", "painting/gradient.h", "painting/image.cc", + "painting/image_decoding.cc", + "painting/image_decoding.h", "painting/image_filter.cc", "painting/image_filter.h", "painting/image.h", @@ -20,6 +28,8 @@ source_set("ui") { "painting/paint.h", "painting/path.cc", "painting/path.h", + "painting/picture_recorder.cc", + "painting/picture_recorder.h", "painting/picture.cc", "painting/picture.h", "painting/rrect.cc", @@ -30,7 +40,12 @@ source_set("ui") { deps = [ "//base", + "//flow", "//flutter/tonic", "//skia", + + # For image_decoding: + "//sky/engine/platform", + "//sky/engine/wtf", ] } diff --git a/sky/engine/core/dart/compositing.dart b/flutter/lib/ui/compositing.dart similarity index 100% rename from sky/engine/core/dart/compositing.dart rename to flutter/lib/ui/compositing.dart diff --git a/sky/engine/core/compositing/Scene.cpp b/flutter/lib/ui/compositing/scene.cc similarity index 96% rename from sky/engine/core/compositing/Scene.cpp rename to flutter/lib/ui/compositing/scene.cc index bb252ae9c61cd98a1c993949f82218ead6a8cf8e..d9f81f4639feedcff7ed2f11c2bb1955c248b256 100644 --- a/sky/engine/core/compositing/Scene.cpp +++ b/flutter/lib/ui/compositing/scene.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sky/engine/core/compositing/Scene.h" +#include "flutter/lib/ui/compositing/scene.h" #include "flutter/tonic/dart_args.h" #include "flutter/tonic/dart_binding_macros.h" diff --git a/sky/engine/core/compositing/Scene.h b/flutter/lib/ui/compositing/scene.h similarity index 88% rename from sky/engine/core/compositing/Scene.h rename to flutter/lib/ui/compositing/scene.h index b8e2f7ef835f4b05e0077eeed8b4c818ca9c31f6..7dd73b563bc99a158813385c935f7f7ab779d47a 100644 --- a/sky/engine/core/compositing/Scene.h +++ b/flutter/lib/ui/compositing/scene.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SKY_ENGINE_CORE_COMPOSITING_SCENE_H_ -#define SKY_ENGINE_CORE_COMPOSITING_SCENE_H_ +#ifndef FLUTTER_LIB_UI_COMPOSITING_SCENE_H_ +#define FLUTTER_LIB_UI_COMPOSITING_SCENE_H_ #include #include @@ -40,4 +40,4 @@ class Scene : public base::RefCountedThreadSafe, public DartWrappable { } // namespace blink -#endif // SKY_ENGINE_CORE_COMPOSITING_SCENE_H_ +#endif // FLUTTER_LIB_UI_COMPOSITING_SCENE_H_ diff --git a/sky/engine/core/compositing/SceneBuilder.cpp b/flutter/lib/ui/compositing/scene_builder.cc similarity index 99% rename from sky/engine/core/compositing/SceneBuilder.cpp rename to flutter/lib/ui/compositing/scene_builder.cc index 5d9d96fb092f1a6ebab3d7652c7e0d32ae0de551..69bc17adc8be5172e01c873013f3a805c3842723 100644 --- a/sky/engine/core/compositing/SceneBuilder.cpp +++ b/flutter/lib/ui/compositing/scene_builder.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sky/engine/core/compositing/SceneBuilder.h" +#include "flutter/lib/ui/compositing/scene_builder.h" #include "flow/layers/backdrop_filter_layer.h" #include "flow/layers/child_scene_layer.h" diff --git a/sky/engine/core/compositing/SceneBuilder.h b/flutter/lib/ui/compositing/scene_builder.h similarity index 92% rename from sky/engine/core/compositing/SceneBuilder.h rename to flutter/lib/ui/compositing/scene_builder.h index 449997f920ddac75d5455d0dd7f909f57860df0e..cee84d65e09651032e50d2d792c735f0168765a6 100644 --- a/sky/engine/core/compositing/SceneBuilder.h +++ b/flutter/lib/ui/compositing/scene_builder.h @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SKY_ENGINE_CORE_COMPOSITING_SCENEBUILDER_H_ -#define SKY_ENGINE_CORE_COMPOSITING_SCENEBUILDER_H_ +#ifndef FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_ +#define FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_ #include #include #include "base/memory/ref_counted.h" #include "flow/layers/container_layer.h" +#include "flutter/lib/ui/compositing/scene.h" #include "flutter/lib/ui/painting/image_filter.h" #include "flutter/lib/ui/painting/path.h" #include "flutter/lib/ui/painting/picture.h" @@ -17,7 +18,6 @@ #include "flutter/lib/ui/painting/shader.h" #include "flutter/tonic/dart_wrappable.h" #include "flutter/tonic/float64_list.h" -#include "sky/engine/core/compositing/Scene.h" namespace blink { @@ -74,4 +74,4 @@ private: } // namespace blink -#endif // SKY_ENGINE_CORE_COMPOSITING_SCENEBUILDER_H_ +#endif // FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_ diff --git a/flutter/lib/ui/dart_ui.gni b/flutter/lib/ui/dart_ui.gni index c112f40b72ffbadbbf9871486cb8dcf31e1ef144..daf350f5c93af3570774dbef22cf6d3b907b93d6 100644 --- a/flutter/lib/ui/dart_ui.gni +++ b/flutter/lib/ui/dart_ui.gni @@ -3,6 +3,7 @@ # found in the LICENSE file. dart_ui_files = [ + "//flutter/lib/ui/compositing.dart", "//flutter/lib/ui/geometry.dart", "//flutter/lib/ui/painting.dart", "//flutter/lib/ui/ui.dart", diff --git a/flutter/lib/ui/painting.dart b/flutter/lib/ui/painting.dart index 1ac895db06f205c508b7c7d1722030d316ee3474..daf524b6faf30b6412e07cff5f7adc740ac200d3 100644 --- a/flutter/lib/ui/painting.dart +++ b/flutter/lib/ui/painting.dart @@ -1363,9 +1363,8 @@ class Canvas extends NativeFieldWrapperClass2 { /// /// Valid only after [Paragraph.layout] has been called on the paragraph. void drawParagraph(Paragraph paragraph, Offset offset) { - _drawParagraph(paragraph, offset.dx, offset.dy); + paragraph._paint(this, offset.dx, offset.dy); } - void _drawParagraph(Paragraph paragraph, double x, double y) native "Canvas_drawParagraph"; /// Draws a sequence of points according to the given [PointMode]. void drawPoints(PointMode pointMode, List points, Paint paint) { diff --git a/flutter/lib/ui/painting/canvas.cc b/flutter/lib/ui/painting/canvas.cc new file mode 100644 index 0000000000000000000000000000000000000000..6d4262d4d5d1c8b634dfc7c6afba84a885024317 --- /dev/null +++ b/flutter/lib/ui/painting/canvas.cc @@ -0,0 +1,415 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/lib/ui/painting/canvas.h" + +#include + +#include "flutter/lib/ui/painting/image.h" +#include "flutter/lib/ui/painting/matrix.h" +#include "flutter/tonic/dart_args.h" +#include "flutter/tonic/dart_binding_macros.h" +#include "flutter/tonic/dart_converter.h" +#include "flutter/tonic/dart_library_natives.h" +#include "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); +} + +IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas); + +#define FOR_EACH_BINDING(V) \ + V(Canvas, save) \ + V(Canvas, saveLayerWithoutBounds) \ + V(Canvas, saveLayer) \ + V(Canvas, restore) \ + V(Canvas, getSaveCount) \ + V(Canvas, translate) \ + V(Canvas, scale) \ + V(Canvas, rotate) \ + V(Canvas, skew) \ + V(Canvas, transform) \ + V(Canvas, setMatrix) \ + 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, drawPoints) \ + V(Canvas, drawVertices) \ + V(Canvas, drawAtlas) + +FOR_EACH_BINDING(DART_NATIVE_CALLBACK) + +void Canvas::RegisterNatives(DartLibraryNatives* natives) { + natives->Register({ + { "Canvas_constructor", Canvas_constructor, 6, true }, +FOR_EACH_BINDING(DART_REGISTER_NATIVE) + }); +} + +scoped_refptr Canvas::Create(PictureRecorder* recorder, + double left, + double top, + double right, + double bottom) { + DCHECK(recorder); + DCHECK(!recorder->isRecording()); + scoped_refptr canvas = new Canvas(recorder->BeginRecording( + SkRect::MakeLTRB(left, top, right, bottom))); + recorder->set_canvas(canvas.get()); + return std::move(canvas); +} + +Canvas::Canvas(SkCanvas* canvas) + : canvas_(canvas) { +} + +Canvas::~Canvas() { +} + +void Canvas::save() { + if (!canvas_) + return; + canvas_->save(); +} + +void Canvas::saveLayerWithoutBounds(const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + canvas_->saveLayer(nullptr, paint.paint()); +} + +void Canvas::saveLayer(double left, + double top, + double right, + double bottom, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom); + canvas_->saveLayer(&bounds, paint.paint()); +} + +void Canvas::restore() { + if (!canvas_) + return; + canvas_->restore(); +} + +int Canvas::getSaveCount() { + if (!canvas_) + return 0; + return canvas_->getSaveCount(); +} + +void Canvas::translate(double dx, double dy) { + if (!canvas_) + return; + canvas_->translate(dx, dy); +} + +void Canvas::scale(double sx, double sy) { + if (!canvas_) + return; + canvas_->scale(sx, sy); +} + +void Canvas::rotate(double radians) { + if (!canvas_) + return; + canvas_->rotate(radians * 180.0/M_PI); +} + +void Canvas::skew(double sx, double sy) { + if (!canvas_) + return; + canvas_->skew(sx, sy); +} + +void Canvas::transform(const Float64List& matrix4) { + if (!canvas_) + return; + canvas_->concat(ToSkMatrix(matrix4)); +} + +void Canvas::setMatrix(const Float64List& matrix4) { + if (!canvas_) + return; + canvas_->setMatrix(ToSkMatrix(matrix4)); +} + +void Canvas::clipRect(double left, + double top, + double right, + double bottom) { + if (!canvas_) + return; + canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom)); +} + +void Canvas::clipRRect(const RRect& rrect) { + if (!canvas_) + return; + canvas_->clipRRect(rrect.sk_rrect, SkRegion::kIntersect_Op); +} + +void Canvas::clipPath(const CanvasPath* path) { + if (!canvas_) + return; + canvas_->clipPath(path->path(), SkRegion::kIntersect_Op); +} + +void Canvas::drawColor(SkColor color, SkXfermode::Mode transfer_mode) { + if (!canvas_) + return; + canvas_->drawColor(color, transfer_mode); +} + +void Canvas::drawLine(double x1, + double y1, + double x2, + double y2, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + canvas_->drawLine(x1, y1, x2, y2, *paint.paint()); +} + +void Canvas::drawPaint(const Paint& paint, const PaintData& paint_data) { + if (!canvas_) + return; + canvas_->drawPaint(*paint.paint()); +} + +void Canvas::drawRect(double left, + double top, + double right, + double bottom, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + canvas_->drawRect(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint()); +} + +void Canvas::drawRRect(const RRect& rrect, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + canvas_->drawRRect(rrect.sk_rrect, *paint.paint()); +} + +void Canvas::drawDRRect(const RRect& outer, + const RRect& inner, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + canvas_->drawDRRect(outer.sk_rrect, inner.sk_rrect, *paint.paint()); +} + +void Canvas::drawOval(double left, + double top, + double right, + double bottom, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + canvas_->drawOval(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint()); +} + +void Canvas::drawCircle(double x, + double y, + double radius, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + canvas_->drawCircle(x, y, radius, *paint.paint()); +} + +void Canvas::drawPath(const CanvasPath* path, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + DCHECK(path); + canvas_->drawPath(path->path(), *paint.paint()); +} + +void Canvas::drawImage(const CanvasImage* image, + double x, + double y, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + DCHECK(image); + canvas_->drawImage(image->image(), x, y, paint.paint()); +} + +void Canvas::drawImageRect(const CanvasImage* image, + double src_left, + double src_top, + double src_right, + double src_bottom, + double dst_left, + double dst_top, + double dst_right, + double dst_bottom, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + DCHECK(image); + SkRect src = SkRect::MakeLTRB(src_left, src_top, src_right, src_bottom); + SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom); + canvas_->drawImageRect(image->image(), + src, + dst, + paint.paint(), + SkCanvas::kFast_SrcRectConstraint); +} + +void Canvas::drawImageNine(const CanvasImage* image, + double center_left, + double center_top, + double center_right, + double center_bottom, + double dst_left, + double dst_top, + double dst_right, + double dst_bottom, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + DCHECK(image); + SkRect center = SkRect::MakeLTRB(center_left, + center_top, + center_right, + center_bottom); + SkIRect icenter; + center.round(&icenter); + SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom); + canvas_->drawImageNine(image->image(), icenter, dst, paint.paint()); +} + +void Canvas::drawPicture(Picture* picture) { + if (!canvas_) + return; + DCHECK(picture); + canvas_->drawPicture(picture->picture().get()); +} + +void Canvas::drawPoints(const Paint& paint, + const PaintData& paint_data, + SkCanvas::PointMode point_mode, + const Float32List& points) { + if (!canvas_) + return; + + static_assert(sizeof(SkPoint) == sizeof(float) * 2, + "SkPoint doesn't use floats."); + + canvas_->drawPoints(point_mode, + points.num_elements() / 2, // SkPoints have two floats. + reinterpret_cast(points.data()), + *paint.paint()); +} + +void Canvas::drawVertices( + const Paint& paint, + const PaintData& paint_data, + SkCanvas::VertexMode vertex_mode, + const Float32List& vertices, + const Float32List& texture_coordinates, + const Int32List& colors, + SkXfermode::Mode transfer_mode, + const Int32List& indices) { + if (!canvas_) + return; + + sk_sp transfer_mode_ptr = SkXfermode::Make(transfer_mode); + + std::vector indices16; + indices16.reserve(indices.num_elements()); + for (int i = 0; i < indices.num_elements(); ++i) + indices16.push_back(indices.data()[i]); + + static_assert(sizeof(SkPoint) == sizeof(float) * 2, "SkPoint doesn't use floats."); + static_assert(sizeof(SkColor) == sizeof(int32_t), "SkColor doesn't use int32_t."); + + canvas_->drawVertices( + vertex_mode, + vertices.num_elements() / 2, // SkPoints have two floats. + reinterpret_cast(vertices.data()), + reinterpret_cast(texture_coordinates.data()), + reinterpret_cast(colors.data()), + transfer_mode_ptr.get(), + indices16.empty() ? nullptr : indices16.data(), + indices16.size(), + *paint.paint()); +} + +void Canvas::drawAtlas( + const Paint& paint, + const PaintData& paint_data, + CanvasImage* atlas, + const Float32List& transforms, + const Float32List& rects, + const Int32List& colors, + SkXfermode::Mode transfer_mode, + const Float32List& cull_rect) { + if (!canvas_) + return; + + sk_sp skImage = atlas->image(); + + static_assert(sizeof(SkRSXform) == sizeof(float) * 4, + "SkRSXform doesn't use floats."); + static_assert(sizeof(SkRect) == sizeof(float) * 4, + "SkRect doesn't use floats."); + + canvas_->drawAtlas( + skImage.get(), + reinterpret_cast(transforms.data()), + reinterpret_cast(rects.data()), + reinterpret_cast(colors.data()), + rects.num_elements() / 4, // SkRect have four floats. + transfer_mode, + reinterpret_cast(cull_rect.data()), + paint.paint()); +} + +void Canvas::Clear() { + canvas_ = nullptr; +} + +bool Canvas::IsRecording() const { + return !!canvas_; +} + +} // namespace blink diff --git a/flutter/lib/ui/painting/canvas.h b/flutter/lib/ui/painting/canvas.h new file mode 100644 index 0000000000000000000000000000000000000000..dffdd3cbdb08c9e23b5bac8ff4cba304590e8d27 --- /dev/null +++ b/flutter/lib/ui/painting/canvas.h @@ -0,0 +1,179 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_LIB_UI_PAINTING_CANVAS_H_ +#define FLUTTER_LIB_UI_PAINTING_CANVAS_H_ + +#include "base/memory/ref_counted.h" +#include "flutter/lib/ui/painting/paint.h" +#include "flutter/lib/ui/painting/path.h" +#include "flutter/lib/ui/painting/picture.h" +#include "flutter/lib/ui/painting/picture_recorder.h" +#include "flutter/lib/ui/painting/rrect.h" +#include "flutter/tonic/dart_wrappable.h" +#include "flutter/tonic/float32_list.h" +#include "flutter/tonic/float64_list.h" +#include "flutter/tonic/int32_list.h" +#include "third_party/skia/include/core/SkCanvas.h" + +namespace blink { +class CanvasImage; +class DartLibraryNatives; + +template <> +struct DartConverter + : public DartConverterInteger {}; + +template <> +struct DartConverter + : public DartConverterInteger {}; + +class Canvas : public base::RefCountedThreadSafe, public DartWrappable { + DEFINE_WRAPPERTYPEINFO(); + public: + static scoped_refptr Create(PictureRecorder* recorder, + double left, + double top, + double right, + double bottom); + + ~Canvas() override; + + void save(); + void saveLayerWithoutBounds(const Paint& paint, + const PaintData& paint_data); + void saveLayer(double left, + double top, + double right, + double bottom, + const Paint& paint, + const PaintData& paint_data); + void restore(); + int getSaveCount(); + + void translate(double dx, double dy); + void scale(double sx, double sy); + void rotate(double radians); + void skew(double sx, double sy); + void transform(const Float64List& matrix4); + void setMatrix(const Float64List& matrix4); + + void clipRect(double left, + double top, + double right, + double bottom); + void clipRRect(const RRect& rrect); + void clipPath(const CanvasPath* path); + + void drawColor(SkColor color, SkXfermode::Mode transfer_mode); + void drawLine(double x1, + double y1, + double x2, + double y2, + const Paint& paint, + const PaintData& paint_data); + void drawPaint(const Paint& paint, + const PaintData& paint_data); + void drawRect(double left, + double top, + double right, + double bottom, + const Paint& paint, + const PaintData& paint_data); + void drawRRect(const RRect& rrect, + const Paint& paint, + const PaintData& paint_data); + void drawDRRect(const RRect& outer, + const RRect& inner, + const Paint& paint, + const PaintData& paint_data); + void drawOval(double left, + double top, + double right, + double bottom, + const Paint& paint, + const PaintData& paint_data); + void drawCircle(double x, + double y, + double radius, + const Paint& paint, + const PaintData& paint_data); + void drawPath(const CanvasPath* path, + const Paint& paint, + const PaintData& paint_data); + void drawImage(const CanvasImage* image, + double x, + double y, + const Paint& paint, + const PaintData& paint_data); + void drawImageRect(const CanvasImage* image, + double src_left, + double src_top, + double src_right, + double src_bottom, + double dst_left, + double dst_top, + double dst_right, + double dst_bottom, + const Paint& paint, + const PaintData& paint_data); + void drawImageNine(const CanvasImage* image, + double center_left, + double center_top, + double center_right, + double center_bottom, + double dst_left, + double dst_top, + double dst_right, + double dst_bottom, + const Paint& paint, + const PaintData& paint_data); + void drawPicture(Picture* picture); + + // The paint argument is first for the following functions because Paint + // unwraps a number of C++ objects. Once we create a view unto a + // Float32List, we cannot re-enter the VM to unwrap objects. That means we + // either need to process the paint argument first. + + void drawPoints(const Paint& paint, + const PaintData& paint_data, + SkCanvas::PointMode point_mode, + const Float32List& points); + + void drawVertices(const Paint& paint, + const PaintData& paint_data, + SkCanvas::VertexMode vertex_mode, + const Float32List& vertices, + const Float32List& texture_coordinates, + const Int32List& colors, + SkXfermode::Mode transfer_mode, + const Int32List& indices); + + void drawAtlas(const Paint& paint, + const PaintData& paint_data, + CanvasImage* atlas, + const Float32List& transforms, + const Float32List& rects, + const Int32List& colors, + SkXfermode::Mode transfer_mode, + const Float32List& cull_rect); + + SkCanvas* canvas() const { return canvas_; } + void Clear(); + bool IsRecording() const; + + static void RegisterNatives(DartLibraryNatives* natives); + + private: + explicit Canvas(SkCanvas* canvas); + + // The SkCanvas is supplied by a call to SkPictureRecorder::beginRecording, + // which does not transfer ownership. For this reason, we hold a raw + // pointer and manually set to null in Clear. + SkCanvas* canvas_; +}; + +} // namespace blink + +#endif // FLUTTER_LIB_UI_PAINTING_CANVAS_H_ diff --git a/sky/engine/core/painting/painting.cc b/flutter/lib/ui/painting/image_decoding.cc similarity index 97% rename from sky/engine/core/painting/painting.cc rename to flutter/lib/ui/painting/image_decoding.cc index fbeacf6e4ab6ad463ce06d1ac5cc4fc6cc7f6235..c027a9d586426881f3e7a0ecd3bce7c4f2b634e4 100644 --- a/sky/engine/core/painting/painting.cc +++ b/flutter/lib/ui/painting/image_decoding.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sky/engine/core/painting/painting.h" +#include "flutter/lib/ui/painting/image_decoding.h" #include "base/bind.h" #include "base/logging.h" @@ -113,7 +113,7 @@ void DecodeImageFromList(Dart_NativeArguments args) { } // namespace -void Painting::RegisterNatives(DartLibraryNatives* natives) { +void ImageDecoding::RegisterNatives(DartLibraryNatives* natives) { natives->Register({ { "decodeImageFromDataPipe", DecodeImageFromDataPipe, 2, true }, { "decodeImageFromList", DecodeImageFromList, 2, true }, diff --git a/sky/engine/core/painting/painting.h b/flutter/lib/ui/painting/image_decoding.h similarity index 65% rename from sky/engine/core/painting/painting.h rename to flutter/lib/ui/painting/image_decoding.h index 760cc49256a46e0fbb4917be75affcb61fd61108..8479570a624e27fe2f72173801b9839076de2a6f 100644 --- a/sky/engine/core/painting/painting.h +++ b/flutter/lib/ui/painting/image_decoding.h @@ -2,18 +2,18 @@ // 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_PAINTING_H_ -#define SKY_ENGINE_CORE_PAINTING_PAINTING_H_ +#ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_DECODING_H_ +#define FLUTTER_LIB_UI_PAINTING_IMAGE_DECODING_H_ #include "flutter/tonic/dart_library_natives.h" namespace blink { -class Painting { +class ImageDecoding { public: static void RegisterNatives(DartLibraryNatives* natives); }; } // namespace blink -#endif // SKY_ENGINE_CORE_PAINTING_PAINTING_H_ +#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODING_H_ diff --git a/flutter/lib/ui/painting/picture.cc b/flutter/lib/ui/painting/picture.cc index 64600ddd1a988a6e7170f968c60ed489280cfbf7..e9eed525045d1c5266e5950694acae4599b4f146 100644 --- a/flutter/lib/ui/painting/picture.cc +++ b/flutter/lib/ui/painting/picture.cc @@ -4,11 +4,11 @@ #include "flutter/lib/ui/painting/picture.h" +#include "flutter/lib/ui/painting/canvas.h" #include "flutter/tonic/dart_args.h" #include "flutter/tonic/dart_binding_macros.h" #include "flutter/tonic/dart_converter.h" #include "flutter/tonic/dart_library_natives.h" -#include "sky/engine/core/painting/Canvas.h" namespace blink { diff --git a/sky/engine/core/painting/PictureRecorder.cpp b/flutter/lib/ui/painting/picture_recorder.cc similarity index 51% rename from sky/engine/core/painting/PictureRecorder.cpp rename to flutter/lib/ui/painting/picture_recorder.cc index 045a760af50c66e76a01775c17c45881aed5ffc9..f98af6e8d2216460d585c8186d19fd53a4f2d43d 100644 --- a/sky/engine/core/painting/PictureRecorder.cpp +++ b/flutter/lib/ui/painting/picture_recorder.cc @@ -2,19 +2,19 @@ // 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 "flutter/lib/ui/painting/picture_recorder.h" +#include "flutter/lib/ui/painting/canvas.h" #include "flutter/lib/ui/painting/picture.h" #include "flutter/tonic/dart_args.h" #include "flutter/tonic/dart_binding_macros.h" #include "flutter/tonic/dart_converter.h" #include "flutter/tonic/dart_library_natives.h" -#include "sky/engine/core/painting/Canvas.h" namespace blink { static void PictureRecorder_constructor(Dart_NativeArguments args) { - DartCallConstructor(&PictureRecorder::create, args); + DartCallConstructor(&PictureRecorder::Create, args); } IMPLEMENT_WRAPPERTYPEINFO(ui, PictureRecorder); @@ -32,40 +32,37 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE) }); } -PictureRecorder::PictureRecorder() -{ +scoped_refptr PictureRecorder::Create() { + return new PictureRecorder(); } -PictureRecorder::~PictureRecorder() -{ +PictureRecorder::PictureRecorder() { } -bool PictureRecorder::isRecording() { - return m_canvas && m_canvas->isRecording(); +PictureRecorder::~PictureRecorder() { } -SkCanvas* PictureRecorder::beginRecording(SkRect bounds) -{ - return m_pictureRecorder.beginRecording(bounds, - &m_rtreeFactory, SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag); +bool PictureRecorder::isRecording() { + return canvas_ && canvas_->IsRecording(); } -scoped_refptr PictureRecorder::endRecording() -{ - if (!isRecording()) - return nullptr; - scoped_refptr picture = Picture::Create( - m_pictureRecorder.finishRecordingAsPicture()); - m_canvas->clearSkCanvas(); - m_canvas->ClearDartWrapper(); - m_canvas = nullptr; - ClearDartWrapper(); - return std::move(picture); +SkCanvas* PictureRecorder::BeginRecording(SkRect bounds) { + return picture_recorder_.beginRecording( + bounds, + &rtree_factory_, + SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag); } -void PictureRecorder::set_canvas(scoped_refptr canvas) -{ - m_canvas = std::move(canvas); +scoped_refptr PictureRecorder::endRecording() { + if (!isRecording()) + return nullptr; + scoped_refptr picture = Picture::Create( + picture_recorder_.finishRecordingAsPicture()); + canvas_->Clear(); + canvas_->ClearDartWrapper(); + canvas_ = nullptr; + ClearDartWrapper(); + return std::move(picture); } } // namespace blink diff --git a/flutter/lib/ui/painting/picture_recorder.h b/flutter/lib/ui/painting/picture_recorder.h new file mode 100644 index 0000000000000000000000000000000000000000..6c4f107037ea570e4a6c5f370e503a977be8bd0f --- /dev/null +++ b/flutter/lib/ui/painting/picture_recorder.h @@ -0,0 +1,45 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_ +#define FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_ + +#include "base/memory/ref_counted.h" +#include "flutter/tonic/dart_wrappable.h" +#include "third_party/skia/include/core/SkPictureRecorder.h" + +namespace blink { +class Canvas; +class DartLibraryNatives; +class Picture; + +class PictureRecorder : public base::RefCountedThreadSafe, + public DartWrappable { + DEFINE_WRAPPERTYPEINFO(); + public: + static scoped_refptr Create(); + + ~PictureRecorder(); + + SkCanvas* BeginRecording(SkRect bounds); + scoped_refptr endRecording(); + bool isRecording(); + + void set_canvas(scoped_refptr canvas) { + canvas_ = std::move(canvas); + } + + static void RegisterNatives(DartLibraryNatives* natives); + + private: + PictureRecorder(); + + SkRTreeFactory rtree_factory_; + SkPictureRecorder picture_recorder_; + scoped_refptr canvas_; +}; + +} // namespace blink + +#endif // FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_ diff --git a/sky/engine/bindings/dart_ui.cc b/sky/engine/bindings/dart_ui.cc index 9e1464f7df1056c299afb44abe29b4e9f514b01b..c849f0bef0b36892ae7dc4e841a4774d87be398e 100644 --- a/sky/engine/bindings/dart_ui.cc +++ b/sky/engine/bindings/dart_ui.cc @@ -4,22 +4,22 @@ #include "sky/engine/bindings/dart_ui.h" +#include "flutter/lib/ui/compositing/scene.h" +#include "flutter/lib/ui/compositing/scene_builder.h" +#include "flutter/lib/ui/painting/canvas.h" #include "flutter/lib/ui/painting/gradient.h" #include "flutter/lib/ui/painting/image.h" +#include "flutter/lib/ui/painting/image_decoding.h" #include "flutter/lib/ui/painting/image_filter.h" #include "flutter/lib/ui/painting/image_shader.h" #include "flutter/lib/ui/painting/mask_filter.h" #include "flutter/lib/ui/painting/path.h" #include "flutter/lib/ui/painting/picture.h" +#include "flutter/lib/ui/painting/picture_recorder.h" #include "flutter/tonic/dart_converter.h" #include "flutter/tonic/dart_error.h" #include "sky/engine/bindings/dart_runtime_hooks.h" #include "sky/engine/bindings/mojo_services.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/PictureRecorder.h" -#include "sky/engine/core/painting/painting.h" #include "sky/engine/core/text/Paragraph.h" #include "sky/engine/core/text/ParagraphBuilder.h" #include "sky/engine/core/window/window.h" @@ -49,11 +49,11 @@ void DartUI::InitForGlobal() { CanvasImage::RegisterNatives(g_natives); CanvasPath::RegisterNatives(g_natives); DartRuntimeHooks::RegisterNatives(g_natives); + ImageDecoding::RegisterNatives(g_natives); ImageFilter::RegisterNatives(g_natives); ImageShader::RegisterNatives(g_natives); MaskFilter::RegisterNatives(g_natives); MojoServices::RegisterNatives(g_natives); - Painting::RegisterNatives(g_natives); Paragraph::RegisterNatives(g_natives); ParagraphBuilder::RegisterNatives(g_natives); Picture::RegisterNatives(g_natives); diff --git a/sky/engine/core/core.gni b/sky/engine/core/core.gni index b86e41085419016ac4651898ba709ec75c1901ab..4f6d100f8c3a24514c5184216570bf4ef20677dd 100644 --- a/sky/engine/core/core.gni +++ b/sky/engine/core/core.gni @@ -9,21 +9,11 @@ sky_core_files = [ "Init.h", "start_up.h", "start_up.cc", - "compositing/Scene.cpp", - "compositing/Scene.h", - "compositing/SceneBuilder.cpp", - "compositing/SceneBuilder.h", "editing/CompositionUnderline.h", "editing/CompositionUnderlineRangeFilter.cpp", "editing/CompositionUnderlineRangeFilter.h", "editing/PositionWithAffinity.cpp", "editing/PositionWithAffinity.h", - "painting/Canvas.cpp", - "painting/Canvas.h", - "painting/painting.cc", - "painting/painting.h", - "painting/PictureRecorder.cpp", - "painting/PictureRecorder.h", "rendering/BidiRun.h", "rendering/BidiRunForLine.cpp", "rendering/BidiRunForLine.h", @@ -189,7 +179,6 @@ if (!flutter_product_mode) { } core_dart_files = get_path_info([ - "dart/compositing.dart", "dart/hash_codes.dart", "dart/hooks.dart", "dart/lerp.dart", diff --git a/sky/engine/core/dart/text.dart b/sky/engine/core/dart/text.dart index e25541fc9991d132a62d6b80ae3c3969c6f26f7b..399f4c4ae55bcb962b98e0b3bc3633710d18358b 100644 --- a/sky/engine/core/dart/text.dart +++ b/sky/engine/core/dart/text.dart @@ -681,6 +681,11 @@ abstract class Paragraph extends NativeFieldWrapperClass2 { /// Word boundaries are defined more precisely in Unicode Standard Annex #29 /// http://www.unicode.org/reports/tr29/#Word_Boundaries List getWordBoundary(int offset) native "Paragraph_getWordBoundary"; + + // Redirecting the paint function in this way solves some dependency problems + // in the C++ code. If we straighten out the C++ dependencies, we can remove + // this indirection. + void _paint(Canvas canvas, double x, double y) native "Paragraph_paint"; } /// Builds a [Paragraph] containing text with the given styling information. diff --git a/sky/engine/core/painting/Canvas.cpp b/sky/engine/core/painting/Canvas.cpp deleted file mode 100644 index 6625a09a0f5a13d4e29b732f65477f1a9ed7afb5..0000000000000000000000000000000000000000 --- a/sky/engine/core/painting/Canvas.cpp +++ /dev/null @@ -1,439 +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. - -#include "math.h" - -#include "sky/engine/core/painting/Canvas.h" - -#include "flutter/lib/ui/painting/image.h" -#include "flutter/lib/ui/painting/matrix.h" -#include "flutter/tonic/dart_args.h" -#include "flutter/tonic/dart_binding_macros.h" -#include "flutter/tonic/dart_converter.h" -#include "flutter/tonic/dart_library_natives.h" -#include "sky/engine/core/text/Paragraph.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); -} - -IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas); - -#define FOR_EACH_BINDING(V) \ - V(Canvas, save) \ - V(Canvas, saveLayerWithoutBounds) \ - V(Canvas, saveLayer) \ - V(Canvas, restore) \ - V(Canvas, getSaveCount) \ - V(Canvas, translate) \ - V(Canvas, scale) \ - V(Canvas, rotate) \ - V(Canvas, skew) \ - V(Canvas, transform) \ - V(Canvas, setMatrix) \ - 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, drawParagraph) \ - V(Canvas, drawPoints) \ - V(Canvas, drawVertices) \ - V(Canvas, drawAtlas) - -FOR_EACH_BINDING(DART_NATIVE_CALLBACK) - -void Canvas::RegisterNatives(DartLibraryNatives* natives) { - natives->Register({ - { "Canvas_constructor", Canvas_constructor, 6, true }, -FOR_EACH_BINDING(DART_REGISTER_NATIVE) - }); -} - -scoped_refptr Canvas::create(PictureRecorder* recorder, - double left, - double top, - double right, - double bottom) { - DCHECK(recorder); - DCHECK(!recorder->isRecording()); - scoped_refptr canvas = new Canvas(recorder->beginRecording( - SkRect::MakeLTRB(left, top, right, bottom))); - recorder->set_canvas(canvas.get()); - return canvas; -} - -Canvas::Canvas(SkCanvas* skCanvas) - : m_canvas(skCanvas) -{ -} - -Canvas::~Canvas() -{ -} - -void Canvas::save() -{ - if (!m_canvas) - return; - m_canvas->save(); -} - -void Canvas::saveLayerWithoutBounds(const Paint& paint, - const PaintData& paint_data) { - if (!m_canvas) - return; - m_canvas->saveLayer(nullptr, paint.paint()); -} - -void Canvas::saveLayer(double left, - double top, - double right, - double bottom, - const Paint& paint, - const PaintData& paint_data) -{ - if (!m_canvas) - return; - SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom); - m_canvas->saveLayer(&bounds, paint.paint()); -} - -void Canvas::restore() -{ - if (!m_canvas) - return; - m_canvas->restore(); -} - -int Canvas::getSaveCount() -{ - if (!m_canvas) - return 0; - return m_canvas->getSaveCount(); -} - -void Canvas::translate(double dx, double dy) -{ - if (!m_canvas) - return; - m_canvas->translate(dx, dy); -} - -void Canvas::scale(double sx, double sy) -{ - if (!m_canvas) - return; - m_canvas->scale(sx, sy); -} - -void Canvas::rotate(double radians) -{ - if (!m_canvas) - return; - m_canvas->rotate(radians * 180.0/M_PI); -} - -void Canvas::skew(double sx, double sy) -{ - if (!m_canvas) - return; - m_canvas->skew(sx, sy); -} - -void Canvas::transform(const Float64List& matrix4) -{ - if (!m_canvas) - return; - m_canvas->concat(ToSkMatrix(matrix4)); -} - -void Canvas::setMatrix(const Float64List& matrix4) -{ - if (!m_canvas) - return; - m_canvas->setMatrix(ToSkMatrix(matrix4)); -} - -void Canvas::clipRect(double left, - double top, - double right, - double bottom) -{ - if (!m_canvas) - return; - m_canvas->clipRect(SkRect::MakeLTRB(left, top, right, bottom)); -} - -void Canvas::clipRRect(const RRect& rrect) -{ - if (!m_canvas) - return; - m_canvas->clipRRect(rrect.sk_rrect, SkRegion::kIntersect_Op); -} - -void Canvas::clipPath(const CanvasPath* path) -{ - if (!m_canvas) - return; - m_canvas->clipPath(path->path(), SkRegion::kIntersect_Op); -} - -void Canvas::drawColor(SkColor color, SkXfermode::Mode transferMode) -{ - if (!m_canvas) - return; - m_canvas->drawColor(color, transferMode); -} - -void Canvas::drawLine(double x1, - double y1, - double x2, - double y2, - const Paint& paint, - const PaintData& paint_data) -{ - if (!m_canvas) - return; - m_canvas->drawLine(x1, y1, x2, y2, *paint.paint()); -} - -void Canvas::drawPaint(const Paint& paint, const PaintData& paint_data) -{ - if (!m_canvas) - return; - m_canvas->drawPaint(*paint.paint()); -} - -void Canvas::drawRect(double left, - double top, - double right, - double bottom, - const Paint& paint, - const PaintData& paint_data) -{ - if (!m_canvas) - return; - m_canvas->drawRect(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint()); -} - -void Canvas::drawRRect(const RRect& rrect, - const Paint& paint, - const PaintData& paint_data) -{ - if (!m_canvas) - return; - m_canvas->drawRRect(rrect.sk_rrect, *paint.paint()); -} - -void Canvas::drawDRRect(const RRect& outer, - const RRect& inner, - const Paint& paint, - const PaintData& paint_data) -{ - if (!m_canvas) - return; - m_canvas->drawDRRect(outer.sk_rrect, inner.sk_rrect, *paint.paint()); -} - -void Canvas::drawOval(double left, - double top, - double right, - double bottom, - const Paint& paint, - const PaintData& paint_data) -{ - if (!m_canvas) - return; - m_canvas->drawOval(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint()); -} - -void Canvas::drawCircle(double x, - double y, - double radius, - const Paint& paint, - const PaintData& paint_data) -{ - if (!m_canvas) - return; - m_canvas->drawCircle(x, y, radius, *paint.paint()); -} - -void Canvas::drawPath(const CanvasPath* path, - const Paint& paint, - const PaintData& paint_data) -{ - if (!m_canvas) - return; - DCHECK(path); - m_canvas->drawPath(path->path(), *paint.paint()); -} - -void Canvas::drawImage(const CanvasImage* image, - double x, - double y, - const Paint& paint, - const PaintData& paint_data) { - if (!m_canvas) - return; - DCHECK(image); - m_canvas->drawImage(image->image(), x, y, paint.paint()); -} - -void Canvas::drawImageRect(const CanvasImage* image, - double srcLeft, - double srcTop, - double srcRight, - double srcBottom, - double dstLeft, - double dstTop, - double dstRight, - double dstBottom, - const Paint& paint, - const PaintData& paint_data) { - if (!m_canvas) - return; - DCHECK(image); - m_canvas->drawImageRect(image->image(), - SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom), - SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom), - paint.paint(), - SkCanvas::kFast_SrcRectConstraint); -} - -void Canvas::drawImageNine(const CanvasImage* image, - double centerLeft, - double centerTop, - double centerRight, - double centerBottom, - double dstLeft, - double dstTop, - double dstRight, - double dstBottom, - const Paint& paint, - const PaintData& paint_data) { - if (!m_canvas) - return; - DCHECK(image); - SkRect center = SkRect::MakeLTRB(centerLeft, centerTop, centerRight, centerBottom); - SkIRect icenter; - center.round(&icenter); - m_canvas->drawImageNine(image->image(), - icenter, - SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom), - paint.paint()); -} - -void Canvas::drawPicture(Picture* picture) -{ - if (!m_canvas) - return; - DCHECK(picture); - m_canvas->drawPicture(picture->picture().get()); -} - -void Canvas::drawParagraph(Paragraph* paragraph, double x, double y) { - if (!m_canvas) - return; - DCHECK(paragraph); - paragraph->paint(this, x, y); -} - -void Canvas::drawPoints(const Paint& paint, - const PaintData& paint_data, - SkCanvas::PointMode pointMode, - const Float32List& points) { - if (!m_canvas) - return; - - static_assert(sizeof(SkPoint) == sizeof(float) * 2, "SkPoint doesn't use floats."); - - m_canvas->drawPoints( - pointMode, - points.num_elements() / 2, // SkPoints have two floats. - reinterpret_cast(points.data()), - *paint.paint() - ); -} - -void Canvas::drawVertices( - const Paint& paint, - const PaintData& paint_data, - SkCanvas::VertexMode vertexMode, - const Float32List& vertices, - const Float32List& textureCoordinates, - const Int32List& colors, - SkXfermode::Mode transferMode, - const Int32List& indices) { - if (!m_canvas) - return; - - sk_sp transferModePtr = SkXfermode::Make(transferMode); - - std::vector indices16; - indices16.reserve(indices.num_elements()); - for (int i = 0; i < indices.num_elements(); ++i) - indices16.push_back(indices.data()[i]); - - static_assert(sizeof(SkPoint) == sizeof(float) * 2, "SkPoint doesn't use floats."); - static_assert(sizeof(SkColor) == sizeof(int32_t), "SkColor doesn't use int32_t."); - - m_canvas->drawVertices( - vertexMode, - vertices.num_elements() / 2, // SkPoints have two floats. - reinterpret_cast(vertices.data()), - reinterpret_cast(textureCoordinates.data()), - reinterpret_cast(colors.data()), - transferModePtr.get(), - indices16.empty() ? nullptr : indices16.data(), - indices16.size(), - *paint.paint() - ); -} - -void Canvas::drawAtlas( - const Paint& paint, - const PaintData& paint_data, - CanvasImage* atlas, - const Float32List& transforms, - const Float32List& rects, - const Int32List& colors, - SkXfermode::Mode transferMode, - const Float32List& cullRect) { - if (!m_canvas) - return; - - sk_sp skImage = atlas->image(); - - static_assert(sizeof(SkRSXform) == sizeof(float) * 4, "SkRSXform doesn't use floats."); - static_assert(sizeof(SkRect) == sizeof(float) * 4, "SkRect doesn't use floats."); - - m_canvas->drawAtlas( - skImage.get(), - reinterpret_cast(transforms.data()), - reinterpret_cast(rects.data()), - reinterpret_cast(colors.data()), - rects.num_elements() / 4, // SkRect have four floats. - transferMode, - reinterpret_cast(cullRect.data()), - paint.paint() - ); -} - -} // namespace blink diff --git a/sky/engine/core/painting/Canvas.h b/sky/engine/core/painting/Canvas.h deleted file mode 100644 index 42c1eae683cbff1d61bcce9ff64aa941491eadb2..0000000000000000000000000000000000000000 --- a/sky/engine/core/painting/Canvas.h +++ /dev/null @@ -1,182 +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_CANVAS_H_ -#define SKY_ENGINE_CORE_PAINTING_CANVAS_H_ - -#include "base/memory/ref_counted.h" -#include "flutter/lib/ui/painting/paint.h" -#include "flutter/lib/ui/painting/path.h" -#include "flutter/lib/ui/painting/picture.h" -#include "flutter/lib/ui/painting/rrect.h" -#include "flutter/tonic/dart_wrappable.h" -#include "flutter/tonic/float32_list.h" -#include "flutter/tonic/float64_list.h" -#include "flutter/tonic/int32_list.h" -#include "sky/engine/core/painting/PictureRecorder.h" -#include "third_party/skia/include/core/SkCanvas.h" - -namespace blink { -class CanvasImage; -class DartLibraryNatives; -class Paragraph; - -template <> -struct DartConverter - : public DartConverterInteger {}; - -template <> -struct DartConverter - : public DartConverterInteger {}; - -class Canvas : public base::RefCountedThreadSafe, public DartWrappable { - DEFINE_WRAPPERTYPEINFO(); -public: - static scoped_refptr create(PictureRecorder* recorder, - double left, - double top, - double right, - double bottom); - - ~Canvas() override; - - void save(); - void saveLayerWithoutBounds(const Paint& paint, - const PaintData& paint_data); - void saveLayer(double left, - double top, - double right, - double bottom, - const Paint& paint, - const PaintData& paint_data); - void restore(); - int getSaveCount(); - - void translate(double dx, double dy); - void scale(double sx, double sy); - void rotate(double radians); - void skew(double sx, double sy); - void transform(const Float64List& matrix4); - void setMatrix(const Float64List& matrix4); - - void clipRect(double left, - double top, - double right, - double bottom); - void clipRRect(const RRect& rrect); - void clipPath(const CanvasPath* path); - - void drawColor(SkColor color, SkXfermode::Mode transferMode); - void drawLine(double x1, - double y1, - double x2, - double y2, - const Paint& paint, - const PaintData& paint_data); - void drawPaint(const Paint& paint, - const PaintData& paint_data); - void drawRect(double left, - double top, - double right, - double bottom, - const Paint& paint, - const PaintData& paint_data); - void drawRRect(const RRect& rrect, - const Paint& paint, - const PaintData& paint_data); - void drawDRRect(const RRect& outer, - const RRect& inner, - const Paint& paint, - const PaintData& paint_data); - void drawOval(double left, - double top, - double right, - double bottom, - const Paint& paint, - const PaintData& paint_data); - void drawCircle(double x, - double y, - double radius, - const Paint& paint, - const PaintData& paint_data); - void drawPath(const CanvasPath* path, - const Paint& paint, - const PaintData& paint_data); - void drawImage(const CanvasImage* image, - double x, - double y, - const Paint& paint, - const PaintData& paint_data); - void drawImageRect(const CanvasImage* image, - double srcLeft, - double srcTop, - double srcRight, - double srcBottom, - double dstLeft, - double dstTop, - double dstRight, - double dstBottom, - const Paint& paint, - const PaintData& paint_data); - void drawImageNine(const CanvasImage* image, - double centerLeft, - double centerTop, - double centerRight, - double centerBottom, - double dstLeft, - double dstTop, - double dstRight, - double dstBottom, - const Paint& paint, - const PaintData& paint_data); - void drawPicture(Picture* picture); - void drawParagraph(Paragraph* paragraph, double x, double y); - - // The paint argument is first for the following functions because Paint - // unwraps a number of C++ objects. Once we create a view unto a - // Float32List, we cannot re-enter the VM to unwrap objects. That means we - // either need to process the paint argument first. - - void drawPoints(const Paint& paint, - const PaintData& paint_data, - SkCanvas::PointMode pointMode, - const Float32List& points); - - void drawVertices(const Paint& paint, - const PaintData& paint_data, - SkCanvas::VertexMode vertexMode, - const Float32List& vertices, - const Float32List& textureCoordinates, - const Int32List& colors, - SkXfermode::Mode transferMode, - const Int32List& indices); - - void drawAtlas(const Paint& paint, - const PaintData& paint_data, - CanvasImage* atlas, - const Float32List& transforms, - const Float32List& rects, - const Int32List& colors, - SkXfermode::Mode transferMode, - const Float32List& cullRect); - - 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); - -private: - // The SkCanvas is supplied by a call to SkPictureRecorder::beginRecording, - // which does not transfer ownership. For this reason, we hold a raw - // pointer and manually set the SkCanvas to null in clearSkCanvas. - SkCanvas* m_canvas; -}; - -} // namespace blink - -#endif // SKY_ENGINE_CORE_PAINTING_CANVAS_H_ diff --git a/sky/engine/core/painting/PictureRecorder.h b/sky/engine/core/painting/PictureRecorder.h deleted file mode 100644 index 5d07a1531c68b775d2fe54ea8784b975104ecad9..0000000000000000000000000000000000000000 --- a/sky/engine/core/painting/PictureRecorder.h +++ /dev/null @@ -1,43 +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_PICTURERECORDER_H_ -#define SKY_ENGINE_CORE_PAINTING_PICTURERECORDER_H_ - -#include "base/memory/ref_counted.h" -#include "flutter/tonic/dart_wrappable.h" -#include "third_party/skia/include/core/SkPictureRecorder.h" - -namespace blink { -class Canvas; -class DartLibraryNatives; -class Picture; - -class PictureRecorder : public base::RefCountedThreadSafe, - public DartWrappable { - DEFINE_WRAPPERTYPEINFO(); -public: - static scoped_refptr create() { return new PictureRecorder(); } - - ~PictureRecorder(); - - SkCanvas* beginRecording(SkRect bounds); - scoped_refptr endRecording(); - bool isRecording(); - - void set_canvas(scoped_refptr canvas); - - static void RegisterNatives(DartLibraryNatives* natives); - -private: - PictureRecorder(); - - SkRTreeFactory m_rtreeFactory; - SkPictureRecorder m_pictureRecorder; - scoped_refptr m_canvas; -}; - -} // namespace blink - -#endif // SKY_ENGINE_CORE_PAINTING_PICTURERECORDER_H_ diff --git a/sky/engine/core/text/Paragraph.cpp b/sky/engine/core/text/Paragraph.cpp index 72c6630f64f8d88b9440140172a679f172a4ac4c..e169de030d97425ef0bd9e3308cab48015931c0d 100644 --- a/sky/engine/core/text/Paragraph.cpp +++ b/sky/engine/core/text/Paragraph.cpp @@ -29,6 +29,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph); V(Paragraph, alphabeticBaseline) \ V(Paragraph, ideographicBaseline) \ V(Paragraph, layout) \ + V(Paragraph, paint) \ V(Paragraph, getWordBoundary) \ V(Paragraph, getRectsForRange) \ V(Paragraph, getPositionForOffset) @@ -87,11 +88,14 @@ void Paragraph::layout(double width) void Paragraph::paint(Canvas* canvas, double x, double y) { + SkCanvas* skCanvas = canvas->canvas(); + if (!skCanvas) + return; + FontCachePurgePreventer fontCachePurgePreventer; // Very simplified painting to allow painting an arbitrary (layer-less) subtree. RenderBox* box = firstChildBox(); - SkCanvas* skCanvas = canvas->skCanvas(); skCanvas->translate(x, y); GraphicsContext context(skCanvas); diff --git a/sky/engine/core/text/Paragraph.h b/sky/engine/core/text/Paragraph.h index b533f20b93eb25b820fbd1d876854c64647bb4f2..e41c1d8b38b72feb36bcef4a2c27ee4a109d1fb1 100644 --- a/sky/engine/core/text/Paragraph.h +++ b/sky/engine/core/text/Paragraph.h @@ -6,8 +6,8 @@ #define SKY_ENGINE_CORE_TEXT_PARAGRAPH_H_ #include "base/memory/ref_counted.h" +#include "flutter/lib/ui/painting/canvas.h" #include "flutter/tonic/dart_wrappable.h" -#include "sky/engine/core/painting/Canvas.h" #include "sky/engine/core/rendering/RenderView.h" #include "sky/engine/core/text/TextBox.h" diff --git a/sky/engine/core/window/window.cc b/sky/engine/core/window/window.cc index 32d3099708935942286d44d70ca9d674824d2eef..1374aa3cdf75c5c02dd3cbdace3acd269c9d55a1 100644 --- a/sky/engine/core/window/window.cc +++ b/sky/engine/core/window/window.cc @@ -4,10 +4,10 @@ #include "sky/engine/core/window/window.h" +#include "flutter/lib/ui/compositing/scene.h" #include "flutter/tonic/dart_converter.h" #include "flutter/tonic/dart_invoke.h" #include "flutter/tonic/dart_library_natives.h" -#include "sky/engine/core/compositing/Scene.h" #include "sky/engine/core/script/ui_dart_state.h" namespace blink { diff --git a/sky/engine/platform/image-decoders/ImageDecoder.h b/sky/engine/platform/image-decoders/ImageDecoder.h index 92c08e3895548747fac083278d6d03599cca703f..53e9a5a1e67d3b5a89ed58206eb6dc06562e08d6 100644 --- a/sky/engine/platform/image-decoders/ImageDecoder.h +++ b/sky/engine/platform/image-decoders/ImageDecoder.h @@ -27,10 +27,10 @@ #ifndef SKY_ENGINE_PLATFORM_IMAGE_DECODERS_IMAGEDECODER_H_ #define SKY_ENGINE_PLATFORM_IMAGE_DECODERS_IMAGEDECODER_H_ -#include "platform/image-decoders/ImageFrame.h" +#include "sky/engine/platform/graphics/ImageSource.h" +#include "sky/engine/platform/image-decoders/ImageFrame.h" #include "sky/engine/platform/PlatformExport.h" #include "sky/engine/platform/SharedBuffer.h" -#include "sky/engine/platform/graphics/ImageSource.h" #include "sky/engine/public/platform/Platform.h" #include "sky/engine/wtf/Assertions.h" #include "sky/engine/wtf/PassOwnPtr.h" diff --git a/sky/engine/public/sky/BUILD.gn b/sky/engine/public/sky/BUILD.gn index 4eb9e6a2a56cd10175fc1de14205358cbb85457e..5fc4d51e88c4c46a4781f16dc6d64c975faa8812 100644 --- a/sky/engine/public/sky/BUILD.gn +++ b/sky/engine/public/sky/BUILD.gn @@ -6,6 +6,7 @@ source_set("sky") { deps = [ "//base", "//flow", + "//flutter/lib/ui", "//mojo/public/cpp/system", "//mojo/services/network/interfaces", "//skia", diff --git a/sky/engine/public/sky/sky_view.cc b/sky/engine/public/sky/sky_view.cc index d1f6510d8b9430f1d7ab26334825979236b6cb5a..b88359471c26f9d5070e2a69d8485f4e10d14d90 100644 --- a/sky/engine/public/sky/sky_view.cc +++ b/sky/engine/public/sky/sky_view.cc @@ -6,7 +6,7 @@ #include "base/bind.h" #include "base/trace_event/trace_event.h" -#include "sky/engine/core/compositing/Scene.h" +#include "flutter/lib/ui/compositing/scene.h" #include "sky/engine/core/script/dart_controller.h" #include "sky/engine/core/script/ui_dart_state.h" #include "sky/engine/core/window/window.h" diff --git a/sky/engine/wtf/BUILD.gn b/sky/engine/wtf/BUILD.gn index 7c4fb4d4b31692caa7bcc6cb1b7f887e47aec168..28ffb107b0a1183501c2b6f756bde25dcc9c4d85 100644 --- a/sky/engine/wtf/BUILD.gn +++ b/sky/engine/wtf/BUILD.gn @@ -4,8 +4,6 @@ import("//testing/test.gni") -visibility = [ "//sky/*" ] - component("wtf") { sources = [ "ASCIICType.h",