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

Cleanup dependencies of core/painting (#2741)

This patch removes spurious dependences on other parts of the engine.
上级 584d3928
......@@ -30,20 +30,10 @@ static void SceneBuilder_constructor(Dart_NativeArguments args) {
DartCallConstructor(&SceneBuilder::create, args);
}
static void SceneBuilder_pushTransform(Dart_NativeArguments args) {
DartArgIterator it(args);
Float64List matrix4 = it.GetNext<Float64List>();
if (it.had_exception())
return;
ExceptionState es;
GetReceiver<SceneBuilder>(args)->pushTransform(matrix4, es);
if (es.had_exception())
Dart_ThrowException(es.GetDartException(args, true));
}
IMPLEMENT_WRAPPERTYPEINFO(ui, SceneBuilder);
#define FOR_EACH_BINDING(V) \
V(SceneBuilder, pushTransform) \
V(SceneBuilder, pushClipRect) \
V(SceneBuilder, pushClipRRect) \
V(SceneBuilder, pushClipPath) \
......@@ -63,7 +53,6 @@ FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
void SceneBuilder::RegisterNatives(DartLibraryNatives* natives) {
natives->Register({
{ "SceneBuilder_constructor", SceneBuilder_constructor, 1, true },
{ "SceneBuilder_pushTransform", SceneBuilder_pushTransform, 2, true },
FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
......@@ -78,11 +67,9 @@ SceneBuilder::~SceneBuilder()
{
}
void SceneBuilder::pushTransform(const Float64List& matrix4, ExceptionState& es)
void SceneBuilder::pushTransform(const Float64List& matrix4)
{
SkMatrix sk_matrix = toSkMatrix(matrix4, es);
if (es.had_exception())
return;
SkMatrix sk_matrix = toSkMatrix(matrix4);
std::unique_ptr<flow::TransformLayer> layer(new flow::TransformLayer());
layer->set_transform(sk_matrix);
addLayer(std::move(layer));
......
......@@ -32,7 +32,7 @@ public:
~SceneBuilder() override;
void pushTransform(const Float64List& matrix4, ExceptionState&);
void pushTransform(const Float64List& matrix4);
void pushClipRect(double left, double right, double top, double bottom);
void pushClipRRect(const RRect& rrect);
void pushClipPath(const CanvasPath* path);
......
......@@ -40,7 +40,14 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
/// The objects are transformed by the given matrix before rasterization.
///
/// See [pop] for details about the operation stack.
void pushTransform(Float64List matrix4) native "SceneBuilder_pushTransform";
void pushTransform(Float64List matrix4) {
if (matrix4 == null)
throw new ArgumentError("[matrix4] argument cannot be null");
if (matrix4.length != 16)
throw new ArgumentError("[matrix4] must have 16 entries.");
_pushTransform(matrix4);
}
void _pushTransform(Float64List matrix4) native "SceneBuilder_pushTransform";
/// Pushes a rectangular clip operation onto the operation stack.
///
......
......@@ -380,6 +380,8 @@ class ImageShader extends Shader {
throw new ArgumentError("[tmy] argument cannot be null");
if (matrix4 == null)
throw new ArgumentError("[matrix4] argument cannot be null");
if (matrix4.length != 16)
throw new ArgumentError("[matrix4] must have 16 entries.");
_constructor();
_initWithImage(image, tmx.index, tmy.index, matrix4);
}
......
......@@ -9,7 +9,6 @@
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/core/painting/Matrix.h"
#include "sky/engine/core/text/Paragraph.h"
#include "sky/engine/platform/geometry/IntRect.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"
......@@ -71,8 +70,8 @@ scoped_refptr<Canvas> Canvas::create(PictureRecorder* recorder,
double top,
double right,
double bottom) {
ASSERT(recorder);
ASSERT(!recorder->isRecording());
DCHECK(recorder);
DCHECK(!recorder->isRecording());
scoped_refptr<Canvas> canvas = new Canvas(recorder->beginRecording(
SkRect::MakeLTRB(left, top, right, bottom)));
recorder->set_canvas(canvas.get());
......@@ -262,14 +261,14 @@ void Canvas::drawPath(const CanvasPath* path, const Paint& paint)
{
if (!m_canvas)
return;
ASSERT(path);
DCHECK(path);
m_canvas->drawPath(path->path(), paint.sk_paint);
}
void Canvas::drawImage(const CanvasImage* image, double x, double y, const Paint& paint) {
if (!m_canvas)
return;
ASSERT(image);
DCHECK(image);
m_canvas->drawImage(image->image(), x, y, paint.paint());
}
......@@ -285,7 +284,7 @@ void Canvas::drawImageRect(const CanvasImage* image,
const Paint& paint) {
if (!m_canvas)
return;
ASSERT(image);
DCHECK(image);
m_canvas->drawImageRect(image->image(),
SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom),
SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom),
......@@ -305,7 +304,7 @@ void Canvas::drawImageNine(const CanvasImage* image,
const Paint& paint) {
if (!m_canvas)
return;
ASSERT(image);
DCHECK(image);
SkRect center = SkRect::MakeLTRB(centerLeft, centerTop, centerRight, centerBottom);
SkIRect icenter;
center.round(&icenter);
......@@ -319,14 +318,14 @@ void Canvas::drawPicture(Picture* picture)
{
if (!m_canvas)
return;
ASSERT(picture);
DCHECK(picture);
m_canvas->drawPicture(picture->toSkia().get());
}
void Canvas::drawParagraph(Paragraph* paragraph, double x, double y) {
if (!m_canvas)
return;
ASSERT(paragraph);
DCHECK(paragraph);
paragraph->paint(this, x, y);
}
......
......@@ -6,7 +6,6 @@
#define SKY_ENGINE_CORE_PAINTING_CANVAS_H_
#include "base/memory/ref_counted.h"
#include "sky/engine/bindings/exception_state.h"
#include "sky/engine/core/painting/CanvasPath.h"
#include "sky/engine/core/painting/Offset.h"
#include "sky/engine/core/painting/Paint.h"
......
......@@ -7,8 +7,6 @@
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "third_party/skia/include/core/SkColor.h"
namespace blink {
......
......@@ -40,8 +40,8 @@ void CanvasGradient::initLinear(const std::vector<Point>& end_points,
const std::vector<CanvasColor>& colors,
const std::vector<float>& color_stops,
SkShader::TileMode tile_mode) {
ASSERT(end_points.size() == 2);
ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr);
DCHECK(end_points.size() == 2);
DCHECK(colors.size() == color_stops.size() || color_stops.data() == nullptr);
SkPoint sk_end_points[2];
for (int i = 0; i < 2; ++i)
sk_end_points[i] = end_points[i].sk_point;
......@@ -61,7 +61,7 @@ void CanvasGradient::initRadial(const Point& center,
const std::vector<CanvasColor>& colors,
const std::vector<float>& color_stops,
SkShader::TileMode tile_mode) {
ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr);
DCHECK(colors.size() == color_stops.size() || color_stops.data() == nullptr);
std::vector<SkColor> sk_colors;
sk_colors.reserve(colors.size());
......
......@@ -17,7 +17,7 @@ class DartLibraryNatives;
template <>
struct DartConverter<SkShader::TileMode> : public DartConverterInteger<SkShader::TileMode> {};
COMPILE_ASSERT(SkShader::kTileModeCount == 3, Need_to_update_TileMode_enum);
static_assert(SkShader::kTileModeCount == 3, "Need to update tile mode enum");
class CanvasGradient : public Shader {
DEFINE_WRAPPERTYPEINFO();
......
......@@ -15,26 +15,17 @@ static void ImageShader_constructor(Dart_NativeArguments args) {
DartCallConstructor(&ImageShader::create, args);
}
static void ImageShader_initWithImage(Dart_NativeArguments args) {
DartArgIterator it(args);
CanvasImage* image = it.GetNext<CanvasImage*>();
SkShader::TileMode tmx = it.GetNext<SkShader::TileMode>();
SkShader::TileMode tmy = it.GetNext<SkShader::TileMode>();
Float64List matrix4 = it.GetNext<Float64List>();
if (it.had_exception())
return;
ExceptionState es;
GetReceiver<ImageShader>(args)->initWithImage(image, tmx, tmy, matrix4, es);
if (es.had_exception())
Dart_ThrowException(es.GetDartException(args, true));
}
IMPLEMENT_WRAPPERTYPEINFO(ui, ImageShader);
#define FOR_EACH_BINDING(V) \
V(ImageShader, initWithImage)
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
void ImageShader::RegisterNatives(DartLibraryNatives* natives) {
natives->Register({
{ "ImageShader_constructor", ImageShader_constructor, 1, true },
{ "ImageShader_initWithImage", ImageShader_initWithImage, 5, true },
FOR_EACH_BINDING(DART_REGISTER_NATIVE)
});
}
......@@ -45,14 +36,9 @@ scoped_refptr<ImageShader> ImageShader::create() {
void ImageShader::initWithImage(CanvasImage* image,
SkShader::TileMode tmx,
SkShader::TileMode tmy,
const Float64List& matrix4,
ExceptionState& es) {
ASSERT(image != NULL);
SkMatrix sk_matrix = toSkMatrix(matrix4, es);
if (es.had_exception())
return;
const Float64List& matrix4) {
DCHECK(image != NULL);
SkMatrix sk_matrix = toSkMatrix(matrix4);
SkBitmap bitmap;
image->image()->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode);
......
......@@ -5,7 +5,6 @@
#ifndef SKY_ENGINE_CORE_PAINTING_IMAGESHADER_H_
#define SKY_ENGINE_CORE_PAINTING_IMAGESHADER_H_
#include "sky/engine/bindings/exception_state.h"
#include "sky/engine/core/painting/CanvasGradient.h"
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/core/painting/Shader.h"
......@@ -27,8 +26,7 @@ class ImageShader : public Shader {
void initWithImage(CanvasImage* image,
SkShader::TileMode tmx,
SkShader::TileMode tmy,
const Float64List& matrix4,
ExceptionState& es);
const Float64List& matrix4);
static void RegisterNatives(DartLibraryNatives* natives);
......
......@@ -13,23 +13,9 @@ static const int kSkMatrixIndexToMatrix4Index[] = {
3, 7, 15,
};
SkMatrix toSkMatrix(const Float64List& matrix4, ExceptionState& es)
{
ASSERT(matrix4.data());
SkMatrix sk_matrix;
if (matrix4.num_elements() != 16) {
es.ThrowTypeError("Incorrect number of elements in matrix.");
return sk_matrix;
}
for (int i = 0; i < 9; ++i)
sk_matrix[i] = matrix4[kSkMatrixIndexToMatrix4Index[i]];
return sk_matrix;
}
SkMatrix toSkMatrix(const Float64List& matrix4)
{
ASSERT(matrix4.data());
DCHECK(matrix4.data());
SkMatrix sk_matrix;
for (int i = 0; i < 9; ++i) {
int matrix4_index = kSkMatrixIndexToMatrix4Index[i];
......
......@@ -5,16 +5,11 @@
#ifndef SKY_ENGINE_CORE_PAINTING_MATRIX_H_
#define SKY_ENGINE_CORE_PAINTING_MATRIX_H_
#include "sky/engine/bindings/exception_state.h"
#include "sky/engine/tonic/float64_list.h"
#include "third_party/skia/include/core/SkMatrix.h"
namespace blink {
// TODO(abarth): Remove this version of toSkMatrix and do the error checking
// inside the VM.
SkMatrix toSkMatrix(const Float64List& matrix4, ExceptionState& es);
SkMatrix toSkMatrix(const Float64List& matrix4);
Float64List toMatrix4(const SkMatrix& sk_matrix);
......
......@@ -8,9 +8,6 @@
#include "sky/engine/core/painting/CanvasColor.h"
#include "sky/engine/core/painting/TransferMode.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "sky/engine/wtf/text/WTFString.h"
#include "third_party/skia/include/core/SkPaint.h"
namespace blink {
......
......@@ -21,7 +21,7 @@ DART_BIND_ALL(Picture, FOR_EACH_BINDING)
scoped_refptr<Picture> Picture::create(sk_sp<SkPicture> skPicture)
{
ASSERT(skPicture);
DCHECK(skPicture);
return new Picture(skPicture);
}
......
......@@ -29,7 +29,7 @@ RRect DartConverter<RRect>::FromDart(Dart_Handle dart_rrect) {
Dart_TypedDataAcquireData(
value, &type, reinterpret_cast<void**>(&data), &num_elements);
DCHECK(!LogIfError(value));
ASSERT(type == Dart_TypedData_kFloat32 && num_elements == 6);
DCHECK(type == Dart_TypedData_kFloat32 && num_elements == 6);
result.sk_rrect.setRectXY(
SkRect::MakeLTRB(data[0], data[1], data[2], data[3]),
......
......@@ -28,7 +28,7 @@ RSTransform DartConverter<RSTransform>::FromDart(Dart_Handle dart_xform) {
Dart_TypedDataAcquireData(
value, &type, reinterpret_cast<void**>(&data), &num_elements);
DCHECK(!LogIfError(value));
ASSERT(type == Dart_TypedData_kFloat32 && num_elements == 4);
DCHECK(type == Dart_TypedData_kFloat32 && num_elements == 4);
SkScalar* dest[] = {
&result.sk_xform.fSCos,
......
......@@ -46,7 +46,7 @@ Rect DartConverter<Rect>::FromDart(Dart_Handle dart_rect) {
Dart_TypedDataAcquireData(
value, &type, reinterpret_cast<void**>(&data), &num_elements);
DCHECK(!LogIfError(value));
ASSERT(type == Dart_TypedData_kFloat32 && num_elements == 4);
DCHECK(type == Dart_TypedData_kFloat32 && num_elements == 4);
SkScalar* dest[] = {
&result.sk_rect.fLeft,
......
......@@ -25,7 +25,7 @@ struct DartConverter<TransferMode>
// 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.
COMPILE_ASSERT(SkXfermode::kLastMode == 28, Need_to_update_TransferMode_dart);
static_assert(SkXfermode::kLastMode == 28, "Need to update transfer mode enum");
} // namespace blink
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册