Skip to content

Commit

Permalink
Cleanup dependencies of core/painting (flutter#2741)
Browse files Browse the repository at this point in the history
This patch removes spurious dependences on other parts of the engine.
  • Loading branch information
abarth authored Jun 11, 2016
1 parent 584d392 commit aa4ee8e
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 88 deletions.
19 changes: 3 additions & 16 deletions sky/engine/core/compositing/SceneBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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)
});
}
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion sky/engine/core/compositing/SceneBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SceneBuilder : public base::RefCountedThreadSafe<SceneBuilder>, public Dar

~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);
Expand Down
9 changes: 8 additions & 1 deletion sky/engine/core/dart/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
2 changes: 2 additions & 0 deletions sky/engine/core/dart/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 8 additions & 9 deletions sky/engine/core/painting/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}

Expand All @@ -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),
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion sky/engine/core/painting/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions sky/engine/core/painting/CanvasColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions sky/engine/core/painting/CanvasGradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion sky/engine/core/painting/CanvasGradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 9 additions & 23 deletions sky/engine/core/painting/ImageShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}

Expand All @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions sky/engine/core/painting/ImageShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);

Expand Down
16 changes: 1 addition & 15 deletions sky/engine/core/painting/Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
5 changes: 0 additions & 5 deletions sky/engine/core/painting/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 0 additions & 3 deletions sky/engine/core/painting/Paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion sky/engine/core/painting/Picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion sky/engine/core/painting/RRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
2 changes: 1 addition & 1 deletion sky/engine/core/painting/RSTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sky/engine/core/painting/Rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sky/engine/core/painting/TransferMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit aa4ee8e

Please sign in to comment.