提交 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 @@
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",
]
}
......@@ -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"
......
......@@ -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 <stdint.h>
#include <memory>
......@@ -40,4 +40,4 @@ class Scene : public base::RefCountedThreadSafe<Scene>, public DartWrappable {
} // namespace blink
#endif // SKY_ENGINE_CORE_COMPOSITING_SCENE_H_
#endif // FLUTTER_LIB_UI_COMPOSITING_SCENE_H_
......@@ -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"
......
......@@ -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 <stdint.h>
#include <memory>
#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_
......@@ -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",
......
......@@ -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<Point> points, Paint paint) {
......
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// 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/matrix.h"
......@@ -12,14 +12,13 @@
#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);
DartCallConstructor(&Canvas::Create, args);
}
IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas);
......@@ -52,7 +51,6 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas);
V(Canvas, drawImageRect) \
V(Canvas, drawImageNine) \
V(Canvas, drawPicture) \
V(Canvas, drawParagraph) \
V(Canvas, drawPoints) \
V(Canvas, drawVertices) \
V(Canvas, drawAtlas)
......@@ -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 top,
double right,
double bottom) {
DCHECK(recorder);
DCHECK(!recorder->isRecording());
scoped_refptr<Canvas> canvas = new Canvas(recorder->beginRecording(
SkRect::MakeLTRB(left, top, right, bottom)));
recorder->set_canvas(canvas.get());
return canvas;
DCHECK(recorder);
DCHECK(!recorder->isRecording());
scoped_refptr<Canvas> canvas = new Canvas(recorder->BeginRecording(
SkRect::MakeLTRB(left, top, right, bottom)));
recorder->set_canvas(canvas.get());
return std::move(canvas);
}
Canvas::Canvas(SkCanvas* skCanvas)
: m_canvas(skCanvas)
{
Canvas::Canvas(SkCanvas* canvas)
: canvas_(canvas) {
}
Canvas::~Canvas()
{
Canvas::~Canvas() {
}
void Canvas::save()
{
if (!m_canvas)
return;
m_canvas->save();
void Canvas::save() {
if (!canvas_)
return;
canvas_->save();
}
void Canvas::saveLayerWithoutBounds(const Paint& paint,
const PaintData& paint_data) {
if (!m_canvas)
return;
m_canvas->saveLayer(nullptr, paint.paint());
if (!canvas_)
return;
canvas_->saveLayer(nullptr, paint.paint());
}
void Canvas::saveLayer(double left,
......@@ -107,99 +102,86 @@ void Canvas::saveLayer(double left,
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());
const PaintData& paint_data) {
if (!canvas_)
return;
SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
canvas_->saveLayer(&bounds, paint.paint());
}
void Canvas::restore()
{
if (!m_canvas)
return;
m_canvas->restore();
void Canvas::restore() {
if (!canvas_)
return;
canvas_->restore();
}
int Canvas::getSaveCount()
{
if (!m_canvas)
return 0;
return m_canvas->getSaveCount();
int Canvas::getSaveCount() {
if (!canvas_)
return 0;
return canvas_->getSaveCount();
}
void Canvas::translate(double dx, double dy)
{
if (!m_canvas)
return;
m_canvas->translate(dx, dy);
void Canvas::translate(double dx, double dy) {
if (!canvas_)
return;
canvas_->translate(dx, dy);
}
void Canvas::scale(double sx, double sy)
{
if (!m_canvas)
return;
m_canvas->scale(sx, sy);
void Canvas::scale(double sx, double sy) {
if (!canvas_)
return;
canvas_->scale(sx, sy);
}
void Canvas::rotate(double radians)
{
if (!m_canvas)
return;
m_canvas->rotate(radians * 180.0/M_PI);
void Canvas::rotate(double radians) {
if (!canvas_)
return;
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::skew(double sx, double sy) {
if (!canvas_)
return;
canvas_->skew(sx, sy);
}
void Canvas::transform(const Float64List& matrix4)
{
if (!m_canvas)
return;
m_canvas->concat(ToSkMatrix(matrix4));
void Canvas::transform(const Float64List& matrix4) {
if (!canvas_)
return;
canvas_->concat(ToSkMatrix(matrix4));
}
void Canvas::setMatrix(const Float64List& matrix4)
{
if (!m_canvas)
return;
m_canvas->setMatrix(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 (!m_canvas)
return;
m_canvas->clipRect(SkRect::MakeLTRB(left, top, right, bottom));
double bottom) {
if (!canvas_)
return;
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::clipRRect(const RRect& rrect) {
if (!canvas_)
return;
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::clipPath(const CanvasPath* path) {
if (!canvas_)
return;
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::drawColor(SkColor color, SkXfermode::Mode transfer_mode) {
if (!canvas_)
return;
canvas_->drawColor(color, transfer_mode);
}
void Canvas::drawLine(double x1,
......@@ -207,18 +189,16 @@ void Canvas::drawLine(double x1,
double x2,
double y2,
const Paint& paint,
const PaintData& paint_data)
{
if (!m_canvas)
return;
m_canvas->drawLine(x1, y1, x2, y2, *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 (!m_canvas)
return;
m_canvas->drawPaint(*paint.paint());
void Canvas::drawPaint(const Paint& paint, const PaintData& paint_data) {
if (!canvas_)
return;
canvas_->drawPaint(*paint.paint());
}
void Canvas::drawRect(double left,
......@@ -226,30 +206,27 @@ void Canvas::drawRect(double left,
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());
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 (!m_canvas)
return;
m_canvas->drawRRect(rrect.sk_rrect, *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 (!m_canvas)
return;
m_canvas->drawDRRect(outer.sk_rrect, inner.sk_rrect, *paint.paint());
const PaintData& paint_data) {
if (!canvas_)
return;
canvas_->drawDRRect(outer.sk_rrect, inner.sk_rrect, *paint.paint());
}
void Canvas::drawOval(double left,
......@@ -257,32 +234,29 @@ void Canvas::drawOval(double left,
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());
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 (!m_canvas)
return;
m_canvas->drawCircle(x, y, radius, *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 (!m_canvas)
return;
DCHECK(path);
m_canvas->drawPath(path->path(), *paint.paint());
const PaintData& paint_data) {
if (!canvas_)
return;
DCHECK(path);
canvas_->drawPath(path->path(), *paint.paint());
}
void Canvas::drawImage(const CanvasImage* image,
......@@ -290,101 +264,95 @@ void Canvas::drawImage(const CanvasImage* image,
double y,
const Paint& paint,
const PaintData& paint_data) {
if (!m_canvas)
return;
DCHECK(image);
m_canvas->drawImage(image->image(), x, y, paint.paint());
if (!canvas_)
return;
DCHECK(image);
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,
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 (!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);
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 centerLeft,
double centerTop,
double centerRight,
double centerBottom,
double dstLeft,
double dstTop,
double dstRight,
double dstBottom,
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 (!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);
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 pointMode,
SkCanvas::PointMode point_mode,
const Float32List& points) {
if (!m_canvas)
if (!canvas_)
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(
pointMode,
points.num_elements() / 2, // SkPoints have two floats.
reinterpret_cast<const SkPoint*>(points.data()),
*paint.paint()
);
canvas_->drawPoints(point_mode,
points.num_elements() / 2, // SkPoints have two floats.
reinterpret_cast<const SkPoint*>(points.data()),
*paint.paint());
}
void Canvas::drawVertices(
const Paint& paint,
const PaintData& paint_data,
SkCanvas::VertexMode vertexMode,
SkCanvas::VertexMode vertex_mode,
const Float32List& vertices,
const Float32List& textureCoordinates,
const Float32List& texture_coordinates,
const Int32List& colors,
SkXfermode::Mode transferMode,
SkXfermode::Mode transfer_mode,
const Int32List& indices) {
if (!m_canvas)
if (!canvas_)
return;
sk_sp<SkXfermode> transferModePtr = SkXfermode::Make(transferMode);
sk_sp<SkXfermode> transfer_mode_ptr = SkXfermode::Make(transfer_mode);
std::vector<uint16_t> indices16;
indices16.reserve(indices.num_elements());
......@@ -394,17 +362,16 @@ void Canvas::drawVertices(
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<const SkPoint*>(vertices.data()),
reinterpret_cast<const SkPoint*>(textureCoordinates.data()),
reinterpret_cast<const SkColor*>(colors.data()),
transferModePtr.get(),
indices16.empty() ? nullptr : indices16.data(),
indices16.size(),
*paint.paint()
);
canvas_->drawVertices(
vertex_mode,
vertices.num_elements() / 2, // SkPoints have two floats.
reinterpret_cast<const SkPoint*>(vertices.data()),
reinterpret_cast<const SkPoint*>(texture_coordinates.data()),
reinterpret_cast<const SkColor*>(colors.data()),
transfer_mode_ptr.get(),
indices16.empty() ? nullptr : indices16.data(),
indices16.size(),
*paint.paint());
}
void Canvas::drawAtlas(
......@@ -414,26 +381,35 @@ void Canvas::drawAtlas(
const Float32List& transforms,
const Float32List& rects,
const Int32List& colors,
SkXfermode::Mode transferMode,
const Float32List& cullRect) {
if (!m_canvas)
SkXfermode::Mode transfer_mode,
const Float32List& cull_rect) {
if (!canvas_)
return;
sk_sp<SkImage> 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<const SkRSXform*>(transforms.data()),
reinterpret_cast<const SkRect*>(rects.data()),
reinterpret_cast<const SkColor*>(colors.data()),
rects.num_elements() / 4, // SkRect have four floats.
transferMode,
reinterpret_cast<const SkRect*>(cullRect.data()),
paint.paint()
);
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<const SkRSXform*>(transforms.data()),
reinterpret_cast<const SkRect*>(rects.data()),
reinterpret_cast<const SkColor*>(colors.data()),
rects.num_elements() / 4, // SkRect have four floats.
transfer_mode,
reinterpret_cast<const SkRect*>(cull_rect.data()),
paint.paint());
}
void Canvas::Clear() {
canvas_ = nullptr;
}
bool Canvas::IsRecording() const {
return !!canvas_;
}
} // 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 @@
// 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 },
......
......@@ -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_
......@@ -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 {
......
......@@ -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> 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<Picture> PictureRecorder::endRecording()
{
if (!isRecording())
return nullptr;
scoped_refptr<Picture> 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> canvas)
{
m_canvas = std::move(canvas);
scoped_refptr<Picture> PictureRecorder::endRecording() {
if (!isRecording())
return nullptr;
scoped_refptr<Picture> picture = Picture::Create(
picture_recorder_.finishRecordingAsPicture());
canvas_->Clear();
canvas_->ClearDartWrapper();
canvas_ = nullptr;
ClearDartWrapper();
return std::move(picture);
}
} // namespace blink
......@@ -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_PAINTING_PICTURERECORDER_H_
#define SKY_ENGINE_CORE_PAINTING_PICTURERECORDER_H_
#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"
......@@ -16,28 +16,30 @@ class Picture;
class PictureRecorder : public base::RefCountedThreadSafe<PictureRecorder>,
public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static scoped_refptr<PictureRecorder> create() { return new PictureRecorder(); }
DEFINE_WRAPPERTYPEINFO();
public:
static scoped_refptr<PictureRecorder> Create();
~PictureRecorder();
~PictureRecorder();
SkCanvas* beginRecording(SkRect bounds);
scoped_refptr<Picture> endRecording();
bool isRecording();
SkCanvas* BeginRecording(SkRect bounds);
scoped_refptr<Picture> endRecording();
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:
PictureRecorder();
private:
PictureRecorder();
SkRTreeFactory m_rtreeFactory;
SkPictureRecorder m_pictureRecorder;
scoped_refptr<Canvas> m_canvas;
SkRTreeFactory rtree_factory_;
SkPictureRecorder picture_recorder_;
scoped_refptr<Canvas> canvas_;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_PICTURERECORDER_H_
#endif // FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_
......@@ -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);
......
......@@ -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",
......
......@@ -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<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.
......
// 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);
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);
......
......@@ -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"
......
......@@ -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 {
......
......@@ -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"
......
......@@ -6,6 +6,7 @@ source_set("sky") {
deps = [
"//base",
"//flow",
"//flutter/lib/ui",
"//mojo/public/cpp/system",
"//mojo/services/network/interfaces",
"//skia",
......
......@@ -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"
......
......@@ -4,8 +4,6 @@
import("//testing/test.gni")
visibility = [ "//sky/*" ]
component("wtf") {
sources = [
"ASCIICType.h",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册