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

Remove more calls to Dart_GetField (#2745)

This patch removes a number of the classes that were generating
Dart_GetField calls, particularly related to drawAtlas and drawVertices.
The functions that used these classes now use primatives instead, which
is more efficient.
上级 b6d85726
......@@ -15,12 +15,10 @@
#include "sky/engine/core/compositing/Scene.h"
#include "sky/engine/core/painting/CanvasPath.h"
#include "sky/engine/core/painting/ImageFilter.h"
#include "sky/engine/core/painting/Offset.h"
#include "sky/engine/core/painting/Paint.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/Point.h"
#include "sky/engine/core/painting/RRect.h"
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/core/painting/Shader.h"
namespace blink {
......
......@@ -38,8 +38,6 @@ sky_core_files = [
"painting/MaskFilter.h",
"painting/Matrix.cpp",
"painting/Matrix.h",
"painting/Offset.cpp",
"painting/Offset.h",
"painting/painting.cc",
"painting/painting.h",
"painting/Paint.cpp",
......@@ -50,15 +48,10 @@ sky_core_files = [
"painting/PictureRecorder.h",
"painting/Point.cpp",
"painting/Point.h",
"painting/Rect.cpp",
"painting/Rect.h",
"painting/RRect.cpp",
"painting/RRect.h",
"painting/RSTransform.cpp",
"painting/RSTransform.h",
"painting/Shader.cpp",
"painting/Shader.h",
"painting/TransferMode.h",
"rendering/BidiRun.h",
"rendering/BidiRunForLine.cpp",
"rendering/BidiRunForLine.h",
......
......@@ -128,15 +128,25 @@ class Path extends NativeFieldWrapperClass2 {
///
/// The line segment added if [forceMoveTo] is false starts at the
/// current point and ends at the start of the arc.
void arcTo(Rect rect, double startAngle, double sweepAngle, bool forceMoveTo) native "Path_arcTo";
void arcTo(Rect rect, double startAngle, double sweepAngle, bool forceMoveTo) {
_arcTo(rect.left, rect.top, rect.right, rect.bottom, startAngle, sweepAngle, forceMoveTo);
}
void _arcTo(double left, double top, double right, double bottom,
double startAngle, double sweepAngle, bool forceMoveTo) native "Path_arcTo";
/// Adds a new subpath that consists of four lines that outline the
/// given rectangle.
void addRect(Rect rect) native "Path_addRect";
void addRect(Rect rect) {
_addRect(rect.left, rect.top, rect.right, rect.bottom);
}
void _addRect(double left, double top, double right, double bottom) native "Path_addRect";
/// Adds a new subpath that consists of a curve that forms the
/// ellipse that fills the given rectangle.
void addOval(Rect oval) native "Path_addOval";
void addOval(Rect oval) {
_addOval(oval.left, oval.top, oval.right, oval.bottom);
}
void _addOval(double left, double top, double right, double bottom) native "Path_addOval";
/// Adds a new subpath with one arc segment that consists of the arc
/// that follows the edge of the oval bounded by the given
......@@ -146,7 +156,11 @@ class Path extends NativeFieldWrapperClass2 {
/// crosses the horizontal line that intersects the center of the
/// rectangle and with positive angles going clockwise around the
/// oval.
void addArc(Rect oval, double startAngle, double sweepAngle) native "Path_addArc";
void addArc(Rect oval, double startAngle, double sweepAngle) {
_addArc(oval.left, oval.top, oval.right, oval.bottom, startAngle, sweepAngle);
}
void _addArc(double left, double top, double right, double bottom,
double startAngle, double sweepAngle) native "Path_addArc";
/// Adds a new subpath that consists of the straight lines and
/// curves needed to form the rounded rectangle described by the
......@@ -167,11 +181,13 @@ class Path extends NativeFieldWrapperClass2 {
/// path was used with [Canvas.clipPath].)
///
/// Returns true if the point is in the path, and false otherwise.
bool contains(Point position) native "Path_contains";
bool contains(Point position) => _contains(position.x, position.y);
bool _contains(double x, double y) native "Path_contains";
/// Returns a copy of the path with all the segments of every
/// subpath translated by the given offset.
Path shift(Offset offset) native "Path_shift";
Path shift(Offset offset) => _shift(offset.dx, offset.dy);
Path _shift(double dx, double dy) native "Path_shift";
}
/// Styles to use for blurs in [MaskFilter] objects.
......@@ -263,9 +279,9 @@ class ColorFilter extends NativeFieldWrapperClass2 {
/// to the [Paint.transferMode], using the output of this filter as the source
/// and the background as the destination.
ColorFilter.mode(Color color, TransferMode transferMode) {
_constructor(color, transferMode);
_constructor(color.value, transferMode.index);
}
void _constructor(Color color, TransferMode transferMode) native "ColorFilter_constructor";
void _constructor(int color, int transferMode) native "ColorFilter_constructor";
}
/// A filter operation to apply to a raster image.
......@@ -703,59 +719,108 @@ class Canvas extends NativeFieldWrapperClass2 {
TransferMode transferMode,
List<int> indicies,
Paint paint) {
int vertexCount = vertices.length;
final int vertexCount = vertices.length;
if (textureCoordinates.isNotEmpty && textureCoordinates.length != vertexCount)
throw new ArgumentError("[vertices] and [textureCoordinates] lengths must match");
if (colors.isNotEmpty && colors.length != vertexCount)
throw new ArgumentError("[vertices] and [colors] lengths must match");
for (Point point in vertices) {
if (point == null)
throw new ArgumentError("[vertices] cannot contain a null");
final Float32List vertexBuffer = new Float32List(vertexCount * 2);
for (int i = 0; i < vertexCount; ++i) {
final int xIndex = i * 2;
final int yIndex = xIndex + 1;
final Point vertex = vertices[i];
vertexBuffer[xIndex] = vertex.x;
vertexBuffer[yIndex] = vertex.y;
}
Float32List textureCoordinateBuffer;
if (textureCoordinates.isNotEmpty) {
textureCoordinateBuffer = new Float32List(vertexCount * 2);
for (int i = 0; i < vertexCount; ++i) {
final int xIndex = i * 2;
final int yIndex = xIndex + 1;
final Point textureCoordinate = textureCoordinates[i];
textureCoordinateBuffer[xIndex] = textureCoordinate.x;
textureCoordinateBuffer[yIndex] = textureCoordinate.y;
}
}
for (Point point in textureCoordinates) {
if (point == null)
throw new ArgumentError("[textureCoordinates] cannot contain a null");
Int32List colorBuffer;
if (colors.isNotEmpty) {
colorBuffer = new Int32List(vertexCount);
for (int i = 0; i < vertexCount; ++i)
colorBuffer[i] = colors[i].value;
}
_drawVertices(vertexMode.index, vertices, textureCoordinates, colors, transferMode, indicies, paint);
final Int32List indexBuffer = new Int32List.fromList(indicies);
_drawVertices(
vertexMode.index, vertexBuffer, textureCoordinateBuffer, colorBuffer,
transferMode.index, indexBuffer, paint
);
}
// TODO(abarth): Convert to primitives.
void _drawVertices(int vertexMode,
List<Point> vertices,
List<Point> textureCoordinates,
List<Color> colors,
TransferMode transferMode,
List<int> indicies,
Float32List vertices,
Float32List textureCoordinates,
Int32List colors,
int transferMode,
Int32List indicies,
Paint paint) native "Canvas_drawVertices";
void drawAtlas(Image image,
// TODO(eseidel): Paint should be optional, but optional doesn't work.
void drawAtlas(Image atlas,
List<RSTransform> transforms,
List<Rect> rects,
List<Color> colors,
TransferMode mode,
TransferMode transferMode,
Rect cullRect,
Paint paint) {
if (transforms.length != rects.length)
final int rectCount = rects.length;
if (transforms.length != rectCount)
throw new ArgumentError("[transforms] and [rects] lengths must match");
if (colors.isNotEmpty && colors.length != rects.length)
if (colors.isNotEmpty && colors.length != rectCount)
throw new ArgumentError("if supplied, [colors] length must match that of [transforms] and [rects]");
for (RSTransform transform in transforms) {
if (transform == null)
throw new ArgumentError("[transforms] cannot contain a null");
final Float32List rstTransformBuffer = new Float32List(rectCount);
final Float32List rectBuffer = new Float32List(rectCount);
for (int i = 0; i < rectCount; ++i) {
final int index0 = i * 4;
final int index1 = index0 + 1;
final int index2 = index0 + 2;
final int index3 = index0 + 3;
final RSTransform rstTransform = transforms[i];
final Rect rect = rects[i];
rstTransformBuffer[index0] = rstTransform.scos;
rstTransformBuffer[index1] = rstTransform.ssin;
rstTransformBuffer[index2] = rstTransform.tx;
rstTransformBuffer[index3] = rstTransform.ty;
rectBuffer[index0] = rect.left;
rectBuffer[index1] = rect.top;
rectBuffer[index2] = rect.right;
rectBuffer[index3] = rect.bottom;
}
for (Rect rect in rects) {
if (rect == null)
throw new ArgumentError("[rects] cannot contain a null");
Int32List colorBuffer;
if (colors.isNotEmpty) {
colorBuffer = new Int32List(rectCount);
for (int i = 0; i < rectCount; ++i)
colorBuffer[i] = colors[i].value;
}
_drawAtlas(image, transforms, rects, colors, mode, cullRect, paint);
final Float32List cullRectBuffer = cullRect?._value;
_drawAtlas(atlas, rstTransformBuffer, rectBuffer, colorBuffer, transferMode.index, cullRectBuffer, paint);
}
// TODO(abarth): Convert to primitives.
void _drawAtlas(Image image,
List<RSTransform> transforms,
List<Rect> rects,
List<Color> colors,
TransferMode mode,
Rect cullRect,
// TODO(eseidel): Paint should be optional, but optional doesn't work.
void _drawAtlas(Image atlas,
Float32List rstTransforms,
Float32List rects,
Int32List colors,
int transferMode,
Float32List cullRect,
Paint paint) native "Canvas_drawAtlas";
}
......
......@@ -670,10 +670,10 @@ abstract class Paragraph extends NativeFieldWrapperClass2 {
/// Returns the text position closest to the given offset.
TextPosition getPositionForOffset(Offset offset) {
List<int> encoded = _getPositionForOffset(offset);
List<int> encoded = _getPositionForOffset(offset.dx, offset.dy);
return new TextPosition(offset: encoded[0], affinity: TextAffinity.values[encoded[1]]);
}
List<int> _getPositionForOffset(Offset offset) native "Paragraph_getPositionForOffset";
List<int> _getPositionForOffset(double dx, double dy) native "Paragraph_getPositionForOffset";
/// Returns the [start, end] of the word at the given offset. Characters not
/// part of a word, such as spaces, symbols, and punctuation, have word breaks
......@@ -716,4 +716,3 @@ class ParagraphBuilder extends NativeFieldWrapperClass2 {
Paragraph build(ParagraphStyle style) => _build(style._encoded, style._fontFamily, style._fontSize, style._lineHeight);
Paragraph _build(Int32List encoded, String fontFamily, double fontSize, double lineHeight) native "ParagraphBuilder_build";
}
......@@ -329,86 +329,65 @@ void Canvas::drawParagraph(Paragraph* paragraph, double x, double y) {
paragraph->paint(this, x, y);
}
void Canvas::drawVertices(SkCanvas::VertexMode vertexMode,
const std::vector<Point>& vertices,
const std::vector<Point>& textureCoordinates,
const std::vector<CanvasColor>& colors,
TransferMode transferMode,
const std::vector<int>& indices,
const Paint& paint)
{
void Canvas::drawVertices(
SkCanvas::VertexMode vertexMode,
const Float32List& vertices,
const Float32List& textureCoordinates,
const Int32List& colors,
int transferMode,
const Int32List& indices,
const Paint& paint) {
if (!m_canvas)
return;
std::vector<SkPoint> skVertices;
skVertices.reserve(vertices.size());
for (const Point& point : vertices)
skVertices.push_back(point.sk_point);
std::vector<SkPoint> skTextureCoordinates;
skVertices.reserve(textureCoordinates.size());
for (const Point& point : textureCoordinates)
skTextureCoordinates.push_back(point.sk_point);
std::vector<SkColor> skColors;
skColors.reserve(colors.size());
for (const CanvasColor& color : colors)
skColors.push_back(color);
sk_sp<SkXfermode> transferModePtr = SkXfermode::Make(
static_cast<SkXfermode::Mode>(transferMode));
std::vector<uint16_t> skIndices;
skIndices.reserve(indices.size());
for (uint16_t i : indices)
skIndices.push_back(i);
std::vector<uint16_t> indices16;
indices16.reserve(indices.num_elements());
for (int i = 0; i < indices.num_elements(); ++i)
indices16.push_back(indices.data()[i]);
sk_sp<SkXfermode> transferModePtr = SkXfermode::Make(transferMode);
static_assert(sizeof(SkPoint) == sizeof(float) * 2, "SkPoint doesn't use floats.");
m_canvas->drawVertices(
vertexMode,
skVertices.size(),
skVertices.data(),
skTextureCoordinates.empty() ? nullptr : skTextureCoordinates.data(),
skColors.empty() ? nullptr : skColors.data(),
vertices.num_elements(),
reinterpret_cast<const SkPoint*>(vertices.data()),
reinterpret_cast<const SkPoint*>(textureCoordinates.data()),
reinterpret_cast<const SkColor*>(colors.data()),
transferModePtr.get(),
skIndices.empty() ? nullptr : skIndices.data(),
skIndices.size(),
indices16.empty() ? nullptr : indices16.data(),
indices16.size(),
*paint.paint()
);
}
void Canvas::drawAtlas(CanvasImage* atlas,
const std::vector<RSTransform>& transforms, const std::vector<Rect>& rects,
const std::vector<CanvasColor>& colors, TransferMode mode,
const Rect& cullRect, const Paint& paint)
{
void Canvas::drawAtlas(
CanvasImage* atlas,
const Float32List& transforms,
const Float32List& rects,
const Int32List& colors,
int transferMode,
const Float32List& cullRect,
const Paint& paint) {
if (!m_canvas)
return;
sk_sp<SkImage> skImage = atlas->image();
std::vector<SkRSXform> skXForms;
skXForms.reserve(transforms.size());
for (const RSTransform& transform : transforms)
skXForms.push_back(transform.sk_xform);
std::vector<SkRect> skRects;
skRects.reserve(rects.size());
for (const Rect& rect : rects)
skRects.push_back(rect.sk_rect);
std::vector<SkColor> skColors;
skColors.reserve(colors.size());
for (const CanvasColor& color : colors)
skColors.push_back(color);
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(),
skXForms.data(),
skRects.data(),
skColors.empty() ? nullptr : skColors.data(),
skXForms.size(),
mode,
cullRect.is_null ? nullptr : &cullRect.sk_rect,
paint.paint()
skImage.get(),
reinterpret_cast<const SkRSXform*>(transforms.data()),
reinterpret_cast<const SkRect*>(rects.data()),
reinterpret_cast<const SkColor*>(colors.data()),
rects.num_elements(),
static_cast<SkXfermode::Mode>(transferMode),
reinterpret_cast<const SkRect*>(cullRect.data()),
paint.paint()
);
}
......
......@@ -7,16 +7,14 @@
#include "base/memory/ref_counted.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/CanvasPath.h"
#include "sky/engine/core/painting/Offset.h"
#include "sky/engine/core/painting/Paint.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/PictureRecorder.h"
#include "sky/engine/core/painting/Point.h"
#include "sky/engine/core/painting/RRect.h"
#include "sky/engine/core/painting/RSTransform.h"
#include "sky/engine/core/painting/Rect.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace blink {
......@@ -104,19 +102,20 @@ public:
void drawParagraph(Paragraph* paragraph, double x, double y);
void drawVertices(SkCanvas::VertexMode vertexMode,
const std::vector<Point>& vertices,
const std::vector<Point>& textureCoordinates,
const std::vector<CanvasColor>& colors,
TransferMode transferMode,
const std::vector<int>& indices,
const Paint& paint);
const Float32List& vertices,
const Float32List& textureCoordinates,
const Int32List& colors,
int transferMode,
const Int32List& indices,
const Paint& paint);
void drawAtlas(CanvasImage* atlas,
const std::vector<RSTransform>& transforms,
const std::vector<Rect>& rects,
const std::vector<CanvasColor>& colors,
TransferMode mode,
const Rect& cullRect, const Paint& paint);
const Float32List& transforms,
const Float32List& rects,
const Int32List& colors,
int transferMode,
const Float32List& cullRect,
const Paint& paint);
SkCanvas* skCanvas() { return m_canvas; }
void clearSkCanvas() { m_canvas = nullptr; }
......
......@@ -6,7 +6,6 @@
#define SKY_ENGINE_CORE_PAINTING_CANVASCOLOR_H_
#include "flutter/tonic/dart_wrappable.h"
#include "sky/engine/core/painting/Rect.h"
#include "third_party/skia/include/core/SkColor.h"
namespace blink {
......
......@@ -57,9 +57,9 @@ CanvasPath::~CanvasPath()
{
}
scoped_refptr<CanvasPath> CanvasPath::shift(const Offset& offset) {
scoped_refptr<CanvasPath> CanvasPath::shift(double dx, double dy) {
scoped_refptr<CanvasPath> path = CanvasPath::create();
m_path.offset(offset.sk_size.width(), offset.sk_size.height(), &path->m_path);
m_path.offset(dx, dy, &path->m_path);
return std::move(path);
}
......
......@@ -9,10 +9,7 @@
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
#include "sky/engine/core/painting/Offset.h"
#include "sky/engine/core/painting/Point.h"
#include "sky/engine/core/painting/RRect.h"
#include "sky/engine/core/painting/Rect.h"
#include "third_party/skia/include/core/SkPath.h"
// Note: There's a very similar class in ../../platform/graphics/Path.h
......@@ -40,32 +37,22 @@ public:
void relativeCubicTo(float x1, float y1, float x2, float y2, float x3, float y3) { m_path.rCubicTo(x1, y1, x2, y2, x3, y3); }
void conicTo(float x1, float y1, float x2, float y2, float w) { m_path.conicTo(x1, y1, x2, y2, w); }
void relativeConicTo(float x1, float y1, float x2, float y2, float w) { m_path.rConicTo(x1, y1, x2, y2, w); }
void arcTo(const Rect& rect, float startAngle, float sweepAngle, bool forceMoveTo) {
m_path.arcTo(rect.sk_rect, startAngle*180.0/M_PI, sweepAngle*180.0/M_PI, forceMoveTo);
void arcTo(float left, float top, float right, float bottom, float startAngle, float sweepAngle, bool forceMoveTo) {
m_path.arcTo(SkRect::MakeLTRB(left, top, right, bottom), startAngle*180.0/M_PI, sweepAngle*180.0/M_PI, forceMoveTo);
}
void addRect(const Rect& rect) { m_path.addRect(rect.sk_rect); }
void addOval(const Rect& oval) { m_path.addOval(oval.sk_rect); }
void addArc(const Rect& rect, float startAngle, float sweepAngle) {
m_path.addArc(rect.sk_rect, startAngle*180.0/M_PI, sweepAngle*180.0/M_PI);
void addRect(float left, float top, float right, float bottom) { m_path.addRect(SkRect::MakeLTRB(left, top, right, bottom)); }
void addOval(float left, float top, float right, float bottom) { m_path.addOval(SkRect::MakeLTRB(left, top, right, bottom)); }
void addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle) {
m_path.addArc(SkRect::MakeLTRB(left, top, right, bottom), startAngle*180.0/M_PI, sweepAngle*180.0/M_PI);
}
void addRRect(const RRect& rrect) { m_path.addRRect(rrect.sk_rrect); }
void close()
{
m_path.close();
}
void reset()
{
m_path.reset();
}
bool contains(const Point& point) { return m_path.contains(point.sk_point.x(), point.sk_point.y()); }
void close() { m_path.close(); }
void reset() { m_path.reset(); }
bool contains(double x, double y) { return m_path.contains(x, y); }
scoped_refptr<CanvasPath> shift(double dx, double dy);
const SkPath& path() const { return m_path; }
scoped_refptr<CanvasPath> shift(const Offset& offset);
static void RegisterNatives(DartLibraryNatives* natives);
private:
......
......@@ -23,9 +23,11 @@ void ColorFilter::RegisterNatives(DartLibraryNatives* natives) {
});
}
scoped_refptr<ColorFilter> ColorFilter::create(CanvasColor color,
TransferMode transfer_mode) {
return new ColorFilter(SkColorFilter::MakeModeFilter(color, transfer_mode));
scoped_refptr<ColorFilter> ColorFilter::create(int color,
int transfer_mode) {
return new ColorFilter(SkColorFilter::MakeModeFilter(
static_cast<SkColor>(color),
static_cast<SkXfermode::Mode>(transfer_mode)));
}
ColorFilter::ColorFilter(sk_sp<SkColorFilter> filter)
......
......@@ -7,8 +7,6 @@
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
#include "sky/engine/core/painting/CanvasColor.h"
#include "sky/engine/core/painting/TransferMode.h"
#include "third_party/skia/include/core/SkColorFilter.h"
namespace blink {
......@@ -18,8 +16,7 @@ class ColorFilter : public base::RefCountedThreadSafe<ColorFilter>, public DartW
DEFINE_WRAPPERTYPEINFO();
public:
~ColorFilter() override;
static scoped_refptr<ColorFilter> create(CanvasColor color,
TransferMode transfer_mode);
static scoped_refptr<ColorFilter> create(int color, int transfer_mode);
sk_sp<SkColorFilter> filter() { return filter_; }
......
// 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 "sky/engine/core/painting/Offset.h"
#include "base/logging.h"
#include "flutter/tonic/dart_error.h"
#include "sky/engine/core/script/ui_dart_state.h"
namespace blink {
// Convert handle.x,y ==> SkSize.
Offset DartConverter<Offset>::FromDart(Dart_Handle handle) {
DCHECK(!LogIfError(handle));
Dart_Handle dx_value =
Dart_GetField(handle, UIDartState::Current()->dx_handle());
Dart_Handle dy_value =
Dart_GetField(handle, UIDartState::Current()->dy_handle());
double dx = 0.0, dy = 0.0;
Dart_Handle err = Dart_DoubleValue(dx_value, &dx);
DCHECK(!LogIfError(err));
err = Dart_DoubleValue(dy_value, &dy);
DCHECK(!LogIfError(err));
Offset result;
result.sk_size.set(dx, dy);
result.is_null = false;
return result;
}
Offset DartConverter<Offset>::FromArguments(
Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
return FromDart(Dart_GetNativeArgument(args, index));
}
} // 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 SKY_ENGINE_CORE_PAINTING_OFFSET_H_
#define SKY_ENGINE_CORE_PAINTING_OFFSET_H_
#include "dart/runtime/include/dart_api.h"
#include "flutter/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkSize.h"
namespace blink {
// Very simple wrapper for SkSize to add a null state.
class Offset {
public:
SkSize sk_size;
bool is_null;
};
template <>
struct DartConverter<Offset> {
static Offset FromDart(Dart_Handle handle);
static Offset FromArguments(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_OFFSET_H_
......@@ -4,11 +4,9 @@
#include "sky/engine/core/painting/Paint.h"
#include "sky/engine/core/painting/CanvasColor.h"
#include "sky/engine/core/painting/ColorFilter.h"
#include "sky/engine/core/painting/MaskFilter.h"
#include "sky/engine/core/painting/Shader.h"
#include "sky/engine/core/painting/TransferMode.h"
#include "sky/engine/core/script/ui_dart_state.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkMaskFilter.h"
......
......@@ -6,16 +6,10 @@
#define SKY_ENGINE_CORE_PAINTING_PAINT_H_
#include "flutter/tonic/dart_wrappable.h"
#include "sky/engine/core/painting/CanvasColor.h"
#include "sky/engine/core/painting/TransferMode.h"
#include "third_party/skia/include/core/SkPaint.h"
namespace blink {
class ColorFilter;
class MaskFilter;
class Shader;
class Paint {
public:
SkPaint sk_paint;
......
......@@ -7,7 +7,6 @@
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
#include "sky/engine/core/painting/Rect.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
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.
#include "sky/engine/core/painting/RSTransform.h"
#include "base/logging.h"
#include "flutter/tonic/dart_error.h"
#include "sky/engine/core/script/ui_dart_state.h"
namespace blink {
// Convert dart_xform._value[0...3] ==> RSTransform
RSTransform DartConverter<RSTransform>::FromDart(Dart_Handle dart_xform) {
RSTransform result;
result.is_null = true;
if (Dart_IsNull(dart_xform))
return result;
Dart_Handle value =
Dart_GetField(dart_xform, UIDartState::Current()->value_handle());
if (Dart_IsNull(value))
return result;
Dart_TypedData_Type type;
float* data = nullptr;
intptr_t num_elements = 0;
Dart_TypedDataAcquireData(
value, &type, reinterpret_cast<void**>(&data), &num_elements);
DCHECK(!LogIfError(value));
DCHECK(type == Dart_TypedData_kFloat32 && num_elements == 4);
SkScalar* dest[] = {
&result.sk_xform.fSCos,
&result.sk_xform.fSSin,
&result.sk_xform.fTx,
&result.sk_xform.fTy
};
for (intptr_t i = 0; i < 4; ++i)
*dest[i] = data[i];
Dart_TypedDataReleaseData(value);
result.is_null = false;
return result;
}
} // 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 SKY_ENGINE_CORE_PAINTING_RSTRANSFORM_H_
#define SKY_ENGINE_CORE_PAINTING_RSTRANSFORM_H_
#include "dart/runtime/include/dart_api.h"
#include "flutter/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkRSXform.h"
namespace blink {
// Very simple wrapper for SkRSXform to add a null state.
class RSTransform {
public:
SkRSXform sk_xform;
bool is_null;
};
template <>
struct DartConverter<RSTransform> {
static RSTransform FromDart(Dart_Handle handle);
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_RSTRANSFORM_H_
// 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 "sky/engine/core/painting/Rect.h"
#include "base/logging.h"
#include "flutter/tonic/dart_class_library.h"
#include "flutter/tonic/dart_error.h"
#include "sky/engine/core/script/ui_dart_state.h"
namespace blink {
Dart_Handle DartConverter<Rect>::ToDart(const Rect& val) {
if (val.is_null)
return Dart_Null();
DartClassLibrary& class_library = DartState::Current()->class_library();
Dart_Handle type = Dart_HandleFromPersistent(
class_library.GetClass("ui", "Rect"));
DCHECK(!LogIfError(type));
const int argc = 4;
Dart_Handle argv[argc] = {
blink::ToDart(val.sk_rect.fLeft),
blink::ToDart(val.sk_rect.fTop),
blink::ToDart(val.sk_rect.fRight),
blink::ToDart(val.sk_rect.fBottom),
};
return Dart_New(type, blink::ToDart("fromLTRB"), argc, argv);
}
// Convert dart_rect._value[0...3] ==> SkRect
Rect DartConverter<Rect>::FromDart(Dart_Handle dart_rect) {
Rect result;
result.is_null = true;
if (Dart_IsNull(dart_rect))
return result;
Dart_Handle value =
Dart_GetField(dart_rect, UIDartState::Current()->value_handle());
if (Dart_IsNull(value))
return result;
Dart_TypedData_Type type;
float* data = nullptr;
intptr_t num_elements = 0;
Dart_TypedDataAcquireData(
value, &type, reinterpret_cast<void**>(&data), &num_elements);
DCHECK(!LogIfError(value));
DCHECK(type == Dart_TypedData_kFloat32 && num_elements == 4);
SkScalar* dest[] = {
&result.sk_rect.fLeft,
&result.sk_rect.fTop,
&result.sk_rect.fRight,
&result.sk_rect.fBottom
};
for (intptr_t i = 0; i < 4; ++i)
*dest[i] = data[i];
Dart_TypedDataReleaseData(value);
result.is_null = false;
return result;
}
Rect DartConverter<Rect>::FromArguments(Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
Dart_Handle dart_rect = Dart_GetNativeArgument(args, index);
DCHECK(!LogIfError(dart_rect));
return FromDart(dart_rect);
}
} // 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 SKY_ENGINE_CORE_PAINTING_RECT_H_
#define SKY_ENGINE_CORE_PAINTING_RECT_H_
#include "dart/runtime/include/dart_api.h"
#include "flutter/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkRect.h"
namespace blink {
// Very simple wrapper for SkRect to add a null state.
class Rect {
public:
Rect() : is_null(true) { }
explicit Rect(SkRect r) : sk_rect(std::move(r)), is_null(false) { }
SkRect sk_rect;
bool is_null;
};
template <>
struct DartConverter<Rect> {
static Dart_Handle ToDart(const Rect& val);
static Rect FromDart(Dart_Handle handle);
static Rect FromArguments(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_RECT_H_
// 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_TRANSFERMODE_H_
#define SKY_ENGINE_CORE_PAINTING_TRANSFERMODE_H_
#include "flutter/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkXfermode.h"
namespace blink {
struct TransferMode {
SkXfermode::Mode mode;
TransferMode() : mode() { }
TransferMode(SkXfermode::Mode mode) : mode(mode) { }
operator SkXfermode::Mode() { return mode; }
};
template <>
struct DartConverter<TransferMode>
: public DartConverterEnum<SkXfermode::Mode> {};
// If this fails, it's because SkXfermode has changed. We need to change
// TransferMode.dart to ensure the TransferMode enum is in sync with the C++
// values.
static_assert(SkXfermode::kLastMode == 28, "Need to update transfer mode enum");
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_TRANSFERMODE_H_
......@@ -9,7 +9,6 @@
#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/Rect.h"
#include "sky/engine/core/rendering/PaintInfo.h"
#include "sky/engine/core/rendering/RenderText.h"
#include "sky/engine/core/rendering/style/RenderStyle.h"
......@@ -146,8 +145,8 @@ int Paragraph::absoluteOffsetForPosition(const PositionWithAffinity& position) {
return 0;
}
Dart_Handle Paragraph::getPositionForOffset(const Offset& offset) {
LayoutPoint point(offset.sk_size.width(), offset.sk_size.height());
Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) {
LayoutPoint point(dx, dy);
PositionWithAffinity position = m_renderView->positionForPoint(point);
Dart_Handle result = Dart_NewList(2);
Dart_ListSetAt(result, 0, ToDart(absoluteOffsetForPosition(position)));
......
......@@ -8,7 +8,6 @@
#include "base/memory/ref_counted.h"
#include "flutter/tonic/dart_wrappable.h"
#include "sky/engine/core/painting/Canvas.h"
#include "sky/engine/core/painting/Offset.h"
#include "sky/engine/core/rendering/RenderView.h"
#include "sky/engine/core/text/TextBox.h"
......@@ -35,7 +34,7 @@ public:
void paint(Canvas* canvas, double x, double y);
std::vector<TextBox> getRectsForRange(unsigned start, unsigned end);
Dart_Handle getPositionForOffset(const Offset& offset);
Dart_Handle getPositionForOffset(double dx, double dy);
Dart_Handle getWordBoundary(unsigned offset);
RenderView* renderView() const { return m_renderView.get(); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册