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

Move Canvas into //flutter/lib/ui (#2754)

This patch moves the remainder of painting and compositing into their
new home (and updates their style to match Google C++ Style).
上级 9bc546ab
...@@ -4,9 +4,17 @@ ...@@ -4,9 +4,17 @@
source_set("ui") { source_set("ui") {
sources = [ 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.cc",
"painting/gradient.h", "painting/gradient.h",
"painting/image.cc", "painting/image.cc",
"painting/image_decoding.cc",
"painting/image_decoding.h",
"painting/image_filter.cc", "painting/image_filter.cc",
"painting/image_filter.h", "painting/image_filter.h",
"painting/image.h", "painting/image.h",
...@@ -20,6 +28,8 @@ source_set("ui") { ...@@ -20,6 +28,8 @@ source_set("ui") {
"painting/paint.h", "painting/paint.h",
"painting/path.cc", "painting/path.cc",
"painting/path.h", "painting/path.h",
"painting/picture_recorder.cc",
"painting/picture_recorder.h",
"painting/picture.cc", "painting/picture.cc",
"painting/picture.h", "painting/picture.h",
"painting/rrect.cc", "painting/rrect.cc",
...@@ -30,7 +40,12 @@ source_set("ui") { ...@@ -30,7 +40,12 @@ source_set("ui") {
deps = [ deps = [
"//base", "//base",
"//flow",
"//flutter/tonic", "//flutter/tonic",
"//skia", "//skia",
# For image_decoding:
"//sky/engine/platform",
"//sky/engine/wtf",
] ]
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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_args.h"
#include "flutter/tonic/dart_binding_macros.h" #include "flutter/tonic/dart_binding_macros.h"
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_COMPOSITING_SCENE_H_ #ifndef FLUTTER_LIB_UI_COMPOSITING_SCENE_H_
#define SKY_ENGINE_CORE_COMPOSITING_SCENE_H_ #define FLUTTER_LIB_UI_COMPOSITING_SCENE_H_
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>
...@@ -40,4 +40,4 @@ class Scene : public base::RefCountedThreadSafe<Scene>, public DartWrappable { ...@@ -40,4 +40,4 @@ class Scene : public base::RefCountedThreadSafe<Scene>, public DartWrappable {
} // namespace blink } // namespace blink
#endif // SKY_ENGINE_CORE_COMPOSITING_SCENE_H_ #endif // FLUTTER_LIB_UI_COMPOSITING_SCENE_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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/backdrop_filter_layer.h"
#include "flow/layers/child_scene_layer.h" #include "flow/layers/child_scene_layer.h"
......
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_COMPOSITING_SCENEBUILDER_H_ #ifndef FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_
#define SKY_ENGINE_CORE_COMPOSITING_SCENEBUILDER_H_ #define FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "flow/layers/container_layer.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/image_filter.h"
#include "flutter/lib/ui/painting/path.h" #include "flutter/lib/ui/painting/path.h"
#include "flutter/lib/ui/painting/picture.h" #include "flutter/lib/ui/painting/picture.h"
...@@ -17,7 +18,6 @@ ...@@ -17,7 +18,6 @@
#include "flutter/lib/ui/painting/shader.h" #include "flutter/lib/ui/painting/shader.h"
#include "flutter/tonic/dart_wrappable.h" #include "flutter/tonic/dart_wrappable.h"
#include "flutter/tonic/float64_list.h" #include "flutter/tonic/float64_list.h"
#include "sky/engine/core/compositing/Scene.h"
namespace blink { namespace blink {
...@@ -74,4 +74,4 @@ private: ...@@ -74,4 +74,4 @@ private:
} // namespace blink } // namespace blink
#endif // SKY_ENGINE_CORE_COMPOSITING_SCENEBUILDER_H_ #endif // FLUTTER_LIB_UI_COMPOSITING_SCENE_BUILDER_H_
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
dart_ui_files = [ dart_ui_files = [
"//flutter/lib/ui/compositing.dart",
"//flutter/lib/ui/geometry.dart", "//flutter/lib/ui/geometry.dart",
"//flutter/lib/ui/painting.dart", "//flutter/lib/ui/painting.dart",
"//flutter/lib/ui/ui.dart", "//flutter/lib/ui/ui.dart",
......
...@@ -1363,9 +1363,8 @@ class Canvas extends NativeFieldWrapperClass2 { ...@@ -1363,9 +1363,8 @@ class Canvas extends NativeFieldWrapperClass2 {
/// ///
/// Valid only after [Paragraph.layout] has been called on the paragraph. /// Valid only after [Paragraph.layout] has been called on the paragraph.
void drawParagraph(Paragraph paragraph, Offset offset) { 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]. /// Draws a sequence of points according to the given [PointMode].
void drawPoints(PointMode pointMode, List<Point> points, Paint paint) { void drawPoints(PointMode pointMode, List<Point> points, Paint paint) {
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "math.h" #include "flutter/lib/ui/painting/canvas.h"
#include "sky/engine/core/painting/Canvas.h" #include <math.h>
#include "flutter/lib/ui/painting/image.h" #include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/matrix.h" #include "flutter/lib/ui/painting/matrix.h"
...@@ -12,14 +12,13 @@ ...@@ -12,14 +12,13 @@
#include "flutter/tonic/dart_binding_macros.h" #include "flutter/tonic/dart_binding_macros.h"
#include "flutter/tonic/dart_converter.h" #include "flutter/tonic/dart_converter.h"
#include "flutter/tonic/dart_library_natives.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/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
namespace blink { namespace blink {
static void Canvas_constructor(Dart_NativeArguments args) { static void Canvas_constructor(Dart_NativeArguments args) {
DartCallConstructor(&Canvas::create, args); DartCallConstructor(&Canvas::Create, args);
} }
IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas); IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas);
...@@ -52,7 +51,6 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas); ...@@ -52,7 +51,6 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas);
V(Canvas, drawImageRect) \ V(Canvas, drawImageRect) \
V(Canvas, drawImageNine) \ V(Canvas, drawImageNine) \
V(Canvas, drawPicture) \ V(Canvas, drawPicture) \
V(Canvas, drawParagraph) \
V(Canvas, drawPoints) \ V(Canvas, drawPoints) \
V(Canvas, drawVertices) \ V(Canvas, drawVertices) \
V(Canvas, drawAtlas) V(Canvas, drawAtlas)
...@@ -66,40 +64,37 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE) ...@@ -66,40 +64,37 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE)
}); });
} }
scoped_refptr<Canvas> Canvas::create(PictureRecorder* recorder, scoped_refptr<Canvas> Canvas::Create(PictureRecorder* recorder,
double left, double left,
double top, double top,
double right, double right,
double bottom) { double bottom) {
DCHECK(recorder); DCHECK(recorder);
DCHECK(!recorder->isRecording()); DCHECK(!recorder->isRecording());
scoped_refptr<Canvas> canvas = new Canvas(recorder->beginRecording( scoped_refptr<Canvas> canvas = new Canvas(recorder->BeginRecording(
SkRect::MakeLTRB(left, top, right, bottom))); SkRect::MakeLTRB(left, top, right, bottom)));
recorder->set_canvas(canvas.get()); recorder->set_canvas(canvas.get());
return canvas; return std::move(canvas);
} }
Canvas::Canvas(SkCanvas* skCanvas) Canvas::Canvas(SkCanvas* canvas)
: m_canvas(skCanvas) : canvas_(canvas) {
{
} }
Canvas::~Canvas() Canvas::~Canvas() {
{
} }
void Canvas::save() void Canvas::save() {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->save(); canvas_->save();
} }
void Canvas::saveLayerWithoutBounds(const Paint& paint, void Canvas::saveLayerWithoutBounds(const Paint& paint,
const PaintData& paint_data) { const PaintData& paint_data) {
if (!m_canvas) if (!canvas_)
return; return;
m_canvas->saveLayer(nullptr, paint.paint()); canvas_->saveLayer(nullptr, paint.paint());
} }
void Canvas::saveLayer(double left, void Canvas::saveLayer(double left,
...@@ -107,99 +102,86 @@ void Canvas::saveLayer(double left, ...@@ -107,99 +102,86 @@ void Canvas::saveLayer(double left,
double right, double right,
double bottom, double bottom,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) const PaintData& paint_data) {
{ if (!canvas_)
if (!m_canvas)
return; return;
SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom); SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
m_canvas->saveLayer(&bounds, paint.paint()); canvas_->saveLayer(&bounds, paint.paint());
} }
void Canvas::restore() void Canvas::restore() {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->restore(); canvas_->restore();
} }
int Canvas::getSaveCount() int Canvas::getSaveCount() {
{ if (!canvas_)
if (!m_canvas)
return 0; return 0;
return m_canvas->getSaveCount(); return canvas_->getSaveCount();
} }
void Canvas::translate(double dx, double dy) void Canvas::translate(double dx, double dy) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->translate(dx, dy); canvas_->translate(dx, dy);
} }
void Canvas::scale(double sx, double sy) void Canvas::scale(double sx, double sy) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->scale(sx, sy); canvas_->scale(sx, sy);
} }
void Canvas::rotate(double radians) void Canvas::rotate(double radians) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->rotate(radians * 180.0/M_PI); canvas_->rotate(radians * 180.0/M_PI);
} }
void Canvas::skew(double sx, double sy) void Canvas::skew(double sx, double sy) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->skew(sx, sy); canvas_->skew(sx, sy);
} }
void Canvas::transform(const Float64List& matrix4) void Canvas::transform(const Float64List& matrix4) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->concat(ToSkMatrix(matrix4)); canvas_->concat(ToSkMatrix(matrix4));
} }
void Canvas::setMatrix(const Float64List& matrix4) void Canvas::setMatrix(const Float64List& matrix4) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->setMatrix(ToSkMatrix(matrix4)); canvas_->setMatrix(ToSkMatrix(matrix4));
} }
void Canvas::clipRect(double left, void Canvas::clipRect(double left,
double top, double top,
double right, double right,
double bottom) double bottom) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->clipRect(SkRect::MakeLTRB(left, top, right, bottom)); canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom));
} }
void Canvas::clipRRect(const RRect& rrect) void Canvas::clipRRect(const RRect& rrect) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->clipRRect(rrect.sk_rrect, SkRegion::kIntersect_Op); canvas_->clipRRect(rrect.sk_rrect, SkRegion::kIntersect_Op);
} }
void Canvas::clipPath(const CanvasPath* path) void Canvas::clipPath(const CanvasPath* path) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->clipPath(path->path(), SkRegion::kIntersect_Op); canvas_->clipPath(path->path(), SkRegion::kIntersect_Op);
} }
void Canvas::drawColor(SkColor color, SkXfermode::Mode transferMode) void Canvas::drawColor(SkColor color, SkXfermode::Mode transfer_mode) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->drawColor(color, transferMode); canvas_->drawColor(color, transfer_mode);
} }
void Canvas::drawLine(double x1, void Canvas::drawLine(double x1,
...@@ -207,18 +189,16 @@ void Canvas::drawLine(double x1, ...@@ -207,18 +189,16 @@ void Canvas::drawLine(double x1,
double x2, double x2,
double y2, double y2,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) const PaintData& paint_data) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->drawLine(x1, y1, x2, y2, *paint.paint()); canvas_->drawLine(x1, y1, x2, y2, *paint.paint());
} }
void Canvas::drawPaint(const Paint& paint, const PaintData& paint_data) void Canvas::drawPaint(const Paint& paint, const PaintData& paint_data) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->drawPaint(*paint.paint()); canvas_->drawPaint(*paint.paint());
} }
void Canvas::drawRect(double left, void Canvas::drawRect(double left,
...@@ -226,30 +206,27 @@ void Canvas::drawRect(double left, ...@@ -226,30 +206,27 @@ void Canvas::drawRect(double left,
double right, double right,
double bottom, double bottom,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) const PaintData& paint_data) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->drawRect(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint()); canvas_->drawRect(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint());
} }
void Canvas::drawRRect(const RRect& rrect, void Canvas::drawRRect(const RRect& rrect,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) const PaintData& paint_data) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->drawRRect(rrect.sk_rrect, *paint.paint()); canvas_->drawRRect(rrect.sk_rrect, *paint.paint());
} }
void Canvas::drawDRRect(const RRect& outer, void Canvas::drawDRRect(const RRect& outer,
const RRect& inner, const RRect& inner,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) const PaintData& paint_data) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->drawDRRect(outer.sk_rrect, inner.sk_rrect, *paint.paint()); canvas_->drawDRRect(outer.sk_rrect, inner.sk_rrect, *paint.paint());
} }
void Canvas::drawOval(double left, void Canvas::drawOval(double left,
...@@ -257,32 +234,29 @@ void Canvas::drawOval(double left, ...@@ -257,32 +234,29 @@ void Canvas::drawOval(double left,
double right, double right,
double bottom, double bottom,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) const PaintData& paint_data) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->drawOval(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint()); canvas_->drawOval(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint());
} }
void Canvas::drawCircle(double x, void Canvas::drawCircle(double x,
double y, double y,
double radius, double radius,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) const PaintData& paint_data) {
{ if (!canvas_)
if (!m_canvas)
return; return;
m_canvas->drawCircle(x, y, radius, *paint.paint()); canvas_->drawCircle(x, y, radius, *paint.paint());
} }
void Canvas::drawPath(const CanvasPath* path, void Canvas::drawPath(const CanvasPath* path,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) const PaintData& paint_data) {
{ if (!canvas_)
if (!m_canvas)
return; return;
DCHECK(path); DCHECK(path);
m_canvas->drawPath(path->path(), *paint.paint()); canvas_->drawPath(path->path(), *paint.paint());
} }
void Canvas::drawImage(const CanvasImage* image, void Canvas::drawImage(const CanvasImage* image,
...@@ -290,101 +264,95 @@ void Canvas::drawImage(const CanvasImage* image, ...@@ -290,101 +264,95 @@ void Canvas::drawImage(const CanvasImage* image,
double y, double y,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) { const PaintData& paint_data) {
if (!m_canvas) if (!canvas_)
return; return;
DCHECK(image); DCHECK(image);
m_canvas->drawImage(image->image(), x, y, paint.paint()); canvas_->drawImage(image->image(), x, y, paint.paint());
} }
void Canvas::drawImageRect(const CanvasImage* image, void Canvas::drawImageRect(const CanvasImage* image,
double srcLeft, double src_left,
double srcTop, double src_top,
double srcRight, double src_right,
double srcBottom, double src_bottom,
double dstLeft, double dst_left,
double dstTop, double dst_top,
double dstRight, double dst_right,
double dstBottom, double dst_bottom,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) { const PaintData& paint_data) {
if (!m_canvas) if (!canvas_)
return; return;
DCHECK(image); DCHECK(image);
m_canvas->drawImageRect(image->image(), SkRect src = SkRect::MakeLTRB(src_left, src_top, src_right, src_bottom);
SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom), SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom);
SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom), canvas_->drawImageRect(image->image(),
src,
dst,
paint.paint(), paint.paint(),
SkCanvas::kFast_SrcRectConstraint); SkCanvas::kFast_SrcRectConstraint);
} }
void Canvas::drawImageNine(const CanvasImage* image, void Canvas::drawImageNine(const CanvasImage* image,
double centerLeft, double center_left,
double centerTop, double center_top,
double centerRight, double center_right,
double centerBottom, double center_bottom,
double dstLeft, double dst_left,
double dstTop, double dst_top,
double dstRight, double dst_right,
double dstBottom, double dst_bottom,
const Paint& paint, const Paint& paint,
const PaintData& paint_data) { const PaintData& paint_data) {
if (!m_canvas) if (!canvas_)
return; return;
DCHECK(image); DCHECK(image);
SkRect center = SkRect::MakeLTRB(centerLeft, centerTop, centerRight, centerBottom); SkRect center = SkRect::MakeLTRB(center_left,
center_top,
center_right,
center_bottom);
SkIRect icenter; SkIRect icenter;
center.round(&icenter); center.round(&icenter);
m_canvas->drawImageNine(image->image(), SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom);
icenter, canvas_->drawImageNine(image->image(), icenter, dst, paint.paint());
SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom),
paint.paint());
} }
void Canvas::drawPicture(Picture* picture) void Canvas::drawPicture(Picture* picture) {
{ if (!canvas_)
if (!m_canvas)
return; return;
DCHECK(picture); DCHECK(picture);
m_canvas->drawPicture(picture->picture().get()); 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, void Canvas::drawPoints(const Paint& paint,
const PaintData& paint_data, const PaintData& paint_data,
SkCanvas::PointMode pointMode, SkCanvas::PointMode point_mode,
const Float32List& points) { const Float32List& points) {
if (!m_canvas) if (!canvas_)
return; return;
static_assert(sizeof(SkPoint) == sizeof(float) * 2, "SkPoint doesn't use floats."); static_assert(sizeof(SkPoint) == sizeof(float) * 2,
"SkPoint doesn't use floats.");
m_canvas->drawPoints( canvas_->drawPoints(point_mode,
pointMode,
points.num_elements() / 2, // SkPoints have two floats. points.num_elements() / 2, // SkPoints have two floats.
reinterpret_cast<const SkPoint*>(points.data()), reinterpret_cast<const SkPoint*>(points.data()),
*paint.paint() *paint.paint());
);
} }
void Canvas::drawVertices( void Canvas::drawVertices(
const Paint& paint, const Paint& paint,
const PaintData& paint_data, const PaintData& paint_data,
SkCanvas::VertexMode vertexMode, SkCanvas::VertexMode vertex_mode,
const Float32List& vertices, const Float32List& vertices,
const Float32List& textureCoordinates, const Float32List& texture_coordinates,
const Int32List& colors, const Int32List& colors,
SkXfermode::Mode transferMode, SkXfermode::Mode transfer_mode,
const Int32List& indices) { const Int32List& indices) {
if (!m_canvas) if (!canvas_)
return; return;
sk_sp<SkXfermode> transferModePtr = SkXfermode::Make(transferMode); sk_sp<SkXfermode> transfer_mode_ptr = SkXfermode::Make(transfer_mode);
std::vector<uint16_t> indices16; std::vector<uint16_t> indices16;
indices16.reserve(indices.num_elements()); indices16.reserve(indices.num_elements());
...@@ -394,17 +362,16 @@ void Canvas::drawVertices( ...@@ -394,17 +362,16 @@ void Canvas::drawVertices(
static_assert(sizeof(SkPoint) == sizeof(float) * 2, "SkPoint doesn't use floats."); 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."); static_assert(sizeof(SkColor) == sizeof(int32_t), "SkColor doesn't use int32_t.");
m_canvas->drawVertices( canvas_->drawVertices(
vertexMode, vertex_mode,
vertices.num_elements() / 2, // SkPoints have two floats. vertices.num_elements() / 2, // SkPoints have two floats.
reinterpret_cast<const SkPoint*>(vertices.data()), reinterpret_cast<const SkPoint*>(vertices.data()),
reinterpret_cast<const SkPoint*>(textureCoordinates.data()), reinterpret_cast<const SkPoint*>(texture_coordinates.data()),
reinterpret_cast<const SkColor*>(colors.data()), reinterpret_cast<const SkColor*>(colors.data()),
transferModePtr.get(), transfer_mode_ptr.get(),
indices16.empty() ? nullptr : indices16.data(), indices16.empty() ? nullptr : indices16.data(),
indices16.size(), indices16.size(),
*paint.paint() *paint.paint());
);
} }
void Canvas::drawAtlas( void Canvas::drawAtlas(
...@@ -414,26 +381,35 @@ void Canvas::drawAtlas( ...@@ -414,26 +381,35 @@ void Canvas::drawAtlas(
const Float32List& transforms, const Float32List& transforms,
const Float32List& rects, const Float32List& rects,
const Int32List& colors, const Int32List& colors,
SkXfermode::Mode transferMode, SkXfermode::Mode transfer_mode,
const Float32List& cullRect) { const Float32List& cull_rect) {
if (!m_canvas) if (!canvas_)
return; return;
sk_sp<SkImage> skImage = atlas->image(); sk_sp<SkImage> skImage = atlas->image();
static_assert(sizeof(SkRSXform) == sizeof(float) * 4, "SkRSXform doesn't use floats."); static_assert(sizeof(SkRSXform) == sizeof(float) * 4,
static_assert(sizeof(SkRect) == sizeof(float) * 4, "SkRect doesn't use floats."); "SkRSXform doesn't use floats.");
static_assert(sizeof(SkRect) == sizeof(float) * 4,
"SkRect doesn't use floats.");
m_canvas->drawAtlas( canvas_->drawAtlas(
skImage.get(), skImage.get(),
reinterpret_cast<const SkRSXform*>(transforms.data()), reinterpret_cast<const SkRSXform*>(transforms.data()),
reinterpret_cast<const SkRect*>(rects.data()), reinterpret_cast<const SkRect*>(rects.data()),
reinterpret_cast<const SkColor*>(colors.data()), reinterpret_cast<const SkColor*>(colors.data()),
rects.num_elements() / 4, // SkRect have four floats. rects.num_elements() / 4, // SkRect have four floats.
transferMode, transfer_mode,
reinterpret_cast<const SkRect*>(cullRect.data()), reinterpret_cast<const SkRect*>(cull_rect.data()),
paint.paint() paint.paint());
); }
void Canvas::Clear() {
canvas_ = nullptr;
}
bool Canvas::IsRecording() const {
return !!canvas_;
} }
} // namespace blink } // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef 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<SkCanvas::PointMode>
: public DartConverterInteger<SkCanvas::PointMode> {};
template <>
struct DartConverter<SkCanvas::VertexMode>
: public DartConverterInteger<SkCanvas::VertexMode> {};
class Canvas : public base::RefCountedThreadSafe<Canvas>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static scoped_refptr<Canvas> 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_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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/bind.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -113,7 +113,7 @@ void DecodeImageFromList(Dart_NativeArguments args) { ...@@ -113,7 +113,7 @@ void DecodeImageFromList(Dart_NativeArguments args) {
} // namespace } // namespace
void Painting::RegisterNatives(DartLibraryNatives* natives) { void ImageDecoding::RegisterNatives(DartLibraryNatives* natives) {
natives->Register({ natives->Register({
{ "decodeImageFromDataPipe", DecodeImageFromDataPipe, 2, true }, { "decodeImageFromDataPipe", DecodeImageFromDataPipe, 2, true },
{ "decodeImageFromList", DecodeImageFromList, 2, true }, { "decodeImageFromList", DecodeImageFromList, 2, true },
......
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_PAINTING_PAINTING_H_ #ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_DECODING_H_
#define SKY_ENGINE_CORE_PAINTING_PAINTING_H_ #define FLUTTER_LIB_UI_PAINTING_IMAGE_DECODING_H_
#include "flutter/tonic/dart_library_natives.h" #include "flutter/tonic/dart_library_natives.h"
namespace blink { namespace blink {
class Painting { class ImageDecoding {
public: public:
static void RegisterNatives(DartLibraryNatives* natives); static void RegisterNatives(DartLibraryNatives* natives);
}; };
} // namespace blink } // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_PAINTING_H_ #endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODING_H_
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
#include "flutter/lib/ui/painting/picture.h" #include "flutter/lib/ui/painting/picture.h"
#include "flutter/lib/ui/painting/canvas.h"
#include "flutter/tonic/dart_args.h" #include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h" #include "flutter/tonic/dart_binding_macros.h"
#include "flutter/tonic/dart_converter.h" #include "flutter/tonic/dart_converter.h"
#include "flutter/tonic/dart_library_natives.h" #include "flutter/tonic/dart_library_natives.h"
#include "sky/engine/core/painting/Canvas.h"
namespace blink { namespace blink {
......
...@@ -2,19 +2,19 @@ ...@@ -2,19 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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/lib/ui/painting/picture.h"
#include "flutter/tonic/dart_args.h" #include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h" #include "flutter/tonic/dart_binding_macros.h"
#include "flutter/tonic/dart_converter.h" #include "flutter/tonic/dart_converter.h"
#include "flutter/tonic/dart_library_natives.h" #include "flutter/tonic/dart_library_natives.h"
#include "sky/engine/core/painting/Canvas.h"
namespace blink { namespace blink {
static void PictureRecorder_constructor(Dart_NativeArguments args) { static void PictureRecorder_constructor(Dart_NativeArguments args) {
DartCallConstructor(&PictureRecorder::create, args); DartCallConstructor(&PictureRecorder::Create, args);
} }
IMPLEMENT_WRAPPERTYPEINFO(ui, PictureRecorder); IMPLEMENT_WRAPPERTYPEINFO(ui, PictureRecorder);
...@@ -32,40 +32,37 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE) ...@@ -32,40 +32,37 @@ FOR_EACH_BINDING(DART_REGISTER_NATIVE)
}); });
} }
PictureRecorder::PictureRecorder() scoped_refptr<PictureRecorder> PictureRecorder::Create() {
{ return new PictureRecorder();
} }
PictureRecorder::~PictureRecorder() PictureRecorder::PictureRecorder() {
{ }
PictureRecorder::~PictureRecorder() {
} }
bool PictureRecorder::isRecording() { bool PictureRecorder::isRecording() {
return m_canvas && m_canvas->isRecording(); return canvas_ && canvas_->IsRecording();
} }
SkCanvas* PictureRecorder::beginRecording(SkRect bounds) SkCanvas* PictureRecorder::BeginRecording(SkRect bounds) {
{ return picture_recorder_.beginRecording(
return m_pictureRecorder.beginRecording(bounds, bounds,
&m_rtreeFactory, SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag); &rtree_factory_,
SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag);
} }
scoped_refptr<Picture> PictureRecorder::endRecording() scoped_refptr<Picture> PictureRecorder::endRecording() {
{
if (!isRecording()) if (!isRecording())
return nullptr; return nullptr;
scoped_refptr<Picture> picture = Picture::Create( scoped_refptr<Picture> picture = Picture::Create(
m_pictureRecorder.finishRecordingAsPicture()); picture_recorder_.finishRecordingAsPicture());
m_canvas->clearSkCanvas(); canvas_->Clear();
m_canvas->ClearDartWrapper(); canvas_->ClearDartWrapper();
m_canvas = nullptr; canvas_ = nullptr;
ClearDartWrapper(); ClearDartWrapper();
return std::move(picture); return std::move(picture);
} }
void PictureRecorder::set_canvas(scoped_refptr<Canvas> canvas)
{
m_canvas = std::move(canvas);
}
} // namespace blink } // namespace blink
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_PAINTING_PICTURERECORDER_H_ #ifndef FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_
#define SKY_ENGINE_CORE_PAINTING_PICTURERECORDER_H_ #define FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h" #include "flutter/tonic/dart_wrappable.h"
...@@ -17,27 +17,29 @@ class Picture; ...@@ -17,27 +17,29 @@ class Picture;
class PictureRecorder : public base::RefCountedThreadSafe<PictureRecorder>, class PictureRecorder : public base::RefCountedThreadSafe<PictureRecorder>,
public DartWrappable { public DartWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static scoped_refptr<PictureRecorder> create() { return new PictureRecorder(); } static scoped_refptr<PictureRecorder> Create();
~PictureRecorder(); ~PictureRecorder();
SkCanvas* beginRecording(SkRect bounds); SkCanvas* BeginRecording(SkRect bounds);
scoped_refptr<Picture> endRecording(); scoped_refptr<Picture> endRecording();
bool isRecording(); bool isRecording();
void set_canvas(scoped_refptr<Canvas> canvas); void set_canvas(scoped_refptr<Canvas> canvas) {
canvas_ = std::move(canvas);
}
static void RegisterNatives(DartLibraryNatives* natives); static void RegisterNatives(DartLibraryNatives* natives);
private: private:
PictureRecorder(); PictureRecorder();
SkRTreeFactory m_rtreeFactory; SkRTreeFactory rtree_factory_;
SkPictureRecorder m_pictureRecorder; SkPictureRecorder picture_recorder_;
scoped_refptr<Canvas> m_canvas; scoped_refptr<Canvas> canvas_;
}; };
} // namespace blink } // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_PICTURERECORDER_H_ #endif // FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_
...@@ -4,22 +4,22 @@ ...@@ -4,22 +4,22 @@
#include "sky/engine/bindings/dart_ui.h" #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/gradient.h"
#include "flutter/lib/ui/painting/image.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_filter.h"
#include "flutter/lib/ui/painting/image_shader.h" #include "flutter/lib/ui/painting/image_shader.h"
#include "flutter/lib/ui/painting/mask_filter.h" #include "flutter/lib/ui/painting/mask_filter.h"
#include "flutter/lib/ui/painting/path.h" #include "flutter/lib/ui/painting/path.h"
#include "flutter/lib/ui/painting/picture.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_converter.h"
#include "flutter/tonic/dart_error.h" #include "flutter/tonic/dart_error.h"
#include "sky/engine/bindings/dart_runtime_hooks.h" #include "sky/engine/bindings/dart_runtime_hooks.h"
#include "sky/engine/bindings/mojo_services.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/Paragraph.h"
#include "sky/engine/core/text/ParagraphBuilder.h" #include "sky/engine/core/text/ParagraphBuilder.h"
#include "sky/engine/core/window/window.h" #include "sky/engine/core/window/window.h"
...@@ -49,11 +49,11 @@ void DartUI::InitForGlobal() { ...@@ -49,11 +49,11 @@ void DartUI::InitForGlobal() {
CanvasImage::RegisterNatives(g_natives); CanvasImage::RegisterNatives(g_natives);
CanvasPath::RegisterNatives(g_natives); CanvasPath::RegisterNatives(g_natives);
DartRuntimeHooks::RegisterNatives(g_natives); DartRuntimeHooks::RegisterNatives(g_natives);
ImageDecoding::RegisterNatives(g_natives);
ImageFilter::RegisterNatives(g_natives); ImageFilter::RegisterNatives(g_natives);
ImageShader::RegisterNatives(g_natives); ImageShader::RegisterNatives(g_natives);
MaskFilter::RegisterNatives(g_natives); MaskFilter::RegisterNatives(g_natives);
MojoServices::RegisterNatives(g_natives); MojoServices::RegisterNatives(g_natives);
Painting::RegisterNatives(g_natives);
Paragraph::RegisterNatives(g_natives); Paragraph::RegisterNatives(g_natives);
ParagraphBuilder::RegisterNatives(g_natives); ParagraphBuilder::RegisterNatives(g_natives);
Picture::RegisterNatives(g_natives); Picture::RegisterNatives(g_natives);
......
...@@ -9,21 +9,11 @@ sky_core_files = [ ...@@ -9,21 +9,11 @@ sky_core_files = [
"Init.h", "Init.h",
"start_up.h", "start_up.h",
"start_up.cc", "start_up.cc",
"compositing/Scene.cpp",
"compositing/Scene.h",
"compositing/SceneBuilder.cpp",
"compositing/SceneBuilder.h",
"editing/CompositionUnderline.h", "editing/CompositionUnderline.h",
"editing/CompositionUnderlineRangeFilter.cpp", "editing/CompositionUnderlineRangeFilter.cpp",
"editing/CompositionUnderlineRangeFilter.h", "editing/CompositionUnderlineRangeFilter.h",
"editing/PositionWithAffinity.cpp", "editing/PositionWithAffinity.cpp",
"editing/PositionWithAffinity.h", "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/BidiRun.h",
"rendering/BidiRunForLine.cpp", "rendering/BidiRunForLine.cpp",
"rendering/BidiRunForLine.h", "rendering/BidiRunForLine.h",
...@@ -189,7 +179,6 @@ if (!flutter_product_mode) { ...@@ -189,7 +179,6 @@ if (!flutter_product_mode) {
} }
core_dart_files = get_path_info([ core_dart_files = get_path_info([
"dart/compositing.dart",
"dart/hash_codes.dart", "dart/hash_codes.dart",
"dart/hooks.dart", "dart/hooks.dart",
"dart/lerp.dart", "dart/lerp.dart",
......
...@@ -681,6 +681,11 @@ abstract class Paragraph extends NativeFieldWrapperClass2 { ...@@ -681,6 +681,11 @@ abstract class Paragraph extends NativeFieldWrapperClass2 {
/// Word boundaries are defined more precisely in Unicode Standard Annex #29 /// Word boundaries are defined more precisely in Unicode Standard Annex #29
/// http://www.unicode.org/reports/tr29/#Word_Boundaries /// http://www.unicode.org/reports/tr29/#Word_Boundaries
List<int> getWordBoundary(int offset) native "Paragraph_getWordBoundary"; List<int> 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. /// Builds a [Paragraph] containing text with the given styling information.
......
// 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<SkCanvas::PointMode>
: public DartConverterInteger<SkCanvas::PointMode> {};
template <>
struct DartConverter<SkCanvas::VertexMode>
: public DartConverterInteger<SkCanvas::VertexMode> {};
class Canvas : public base::RefCountedThreadSafe<Canvas>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static scoped_refptr<Canvas> 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_
...@@ -29,6 +29,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph); ...@@ -29,6 +29,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph);
V(Paragraph, alphabeticBaseline) \ V(Paragraph, alphabeticBaseline) \
V(Paragraph, ideographicBaseline) \ V(Paragraph, ideographicBaseline) \
V(Paragraph, layout) \ V(Paragraph, layout) \
V(Paragraph, paint) \
V(Paragraph, getWordBoundary) \ V(Paragraph, getWordBoundary) \
V(Paragraph, getRectsForRange) \ V(Paragraph, getRectsForRange) \
V(Paragraph, getPositionForOffset) V(Paragraph, getPositionForOffset)
...@@ -87,11 +88,14 @@ void Paragraph::layout(double width) ...@@ -87,11 +88,14 @@ void Paragraph::layout(double width)
void Paragraph::paint(Canvas* canvas, double x, double y) void Paragraph::paint(Canvas* canvas, double x, double y)
{ {
SkCanvas* skCanvas = canvas->canvas();
if (!skCanvas)
return;
FontCachePurgePreventer fontCachePurgePreventer; FontCachePurgePreventer fontCachePurgePreventer;
// Very simplified painting to allow painting an arbitrary (layer-less) subtree. // Very simplified painting to allow painting an arbitrary (layer-less) subtree.
RenderBox* box = firstChildBox(); RenderBox* box = firstChildBox();
SkCanvas* skCanvas = canvas->skCanvas();
skCanvas->translate(x, y); skCanvas->translate(x, y);
GraphicsContext context(skCanvas); GraphicsContext context(skCanvas);
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#define SKY_ENGINE_CORE_TEXT_PARAGRAPH_H_ #define SKY_ENGINE_CORE_TEXT_PARAGRAPH_H_
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "flutter/lib/ui/painting/canvas.h"
#include "flutter/tonic/dart_wrappable.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/rendering/RenderView.h"
#include "sky/engine/core/text/TextBox.h" #include "sky/engine/core/text/TextBox.h"
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
#include "sky/engine/core/window/window.h" #include "sky/engine/core/window/window.h"
#include "flutter/lib/ui/compositing/scene.h"
#include "flutter/tonic/dart_converter.h" #include "flutter/tonic/dart_converter.h"
#include "flutter/tonic/dart_invoke.h" #include "flutter/tonic/dart_invoke.h"
#include "flutter/tonic/dart_library_natives.h" #include "flutter/tonic/dart_library_natives.h"
#include "sky/engine/core/compositing/Scene.h"
#include "sky/engine/core/script/ui_dart_state.h" #include "sky/engine/core/script/ui_dart_state.h"
namespace blink { namespace blink {
......
...@@ -27,10 +27,10 @@ ...@@ -27,10 +27,10 @@
#ifndef SKY_ENGINE_PLATFORM_IMAGE_DECODERS_IMAGEDECODER_H_ #ifndef SKY_ENGINE_PLATFORM_IMAGE_DECODERS_IMAGEDECODER_H_
#define 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/PlatformExport.h"
#include "sky/engine/platform/SharedBuffer.h" #include "sky/engine/platform/SharedBuffer.h"
#include "sky/engine/platform/graphics/ImageSource.h"
#include "sky/engine/public/platform/Platform.h" #include "sky/engine/public/platform/Platform.h"
#include "sky/engine/wtf/Assertions.h" #include "sky/engine/wtf/Assertions.h"
#include "sky/engine/wtf/PassOwnPtr.h" #include "sky/engine/wtf/PassOwnPtr.h"
......
...@@ -6,6 +6,7 @@ source_set("sky") { ...@@ -6,6 +6,7 @@ source_set("sky") {
deps = [ deps = [
"//base", "//base",
"//flow", "//flow",
"//flutter/lib/ui",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//mojo/services/network/interfaces", "//mojo/services/network/interfaces",
"//skia", "//skia",
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/trace_event/trace_event.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/dart_controller.h"
#include "sky/engine/core/script/ui_dart_state.h" #include "sky/engine/core/script/ui_dart_state.h"
#include "sky/engine/core/window/window.h" #include "sky/engine/core/window/window.h"
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
import("//testing/test.gni") import("//testing/test.gni")
visibility = [ "//sky/*" ]
component("wtf") { component("wtf") {
sources = [ sources = [
"ASCIICType.h", "ASCIICType.h",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册