Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sky/engine/bindings/exception_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Dart_Handle ExceptionState::GetDartException(Dart_NativeArguments args,
// TODO(abarth): Still don't understand autoscope.
DCHECK(auto_scope);
// TODO(eseidel): This should be a real exception object!
if (!message_.isEmpty()) {
CString utf8 = message_.utf8();
return Dart_NewStringFromUTF8(reinterpret_cast<const unsigned char*>(utf8.data()), utf8.length());
}
return Dart_NewStringFromCString("Exception support missing. See exception_state.cc");
}

Expand Down
4 changes: 4 additions & 0 deletions sky/engine/bindings/scripts/dart_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class methods.
'unrestricted float': 'float',
# Pass these by value, not pointer.
'Color': 'SkColor',
'RSTransform': 'RSTransform',
# These direct conversions appear to be working around
# dart_value_to_cpp_value using CPP_SPECIAL_CONVERSION_RULES directly
# instead of calling cpp_type.
Expand All @@ -124,6 +125,7 @@ class methods.
'MojoDataPipeConsumer': 'mojo::ScopedDataPipeConsumerHandle',
'TileMode': 'SkShader::TileMode',
'TransferMode': 'SkXfermode::Mode',
'FilterQuality': 'SkFilterQuality',
'PaintingStyle': 'SkPaint::Style',
}

Expand Down Expand Up @@ -370,10 +372,12 @@ def pass_by_value_format(typename, null_check="{null_check}"):
'Float32List': pass_by_value_format('Float32List'),
'Offset': pass_by_value_format('Offset'),
'Point': pass_by_value_format('Point'),
'RSTransform': pass_by_value_format('RSTransform'),
'Rect': pass_by_value_format('Rect'),
'Size': pass_by_value_format('Size'),
'TileMode': pass_by_value_format('TileMode', ''),
'TransferMode': pass_by_value_format('TransferMode', ''),
'FilterQuality': pass_by_value_format('FilterQuality', ''),
'PaintingStyle': pass_by_value_format('PaintingStyle', ''),
'MojoDataPipeConsumer': pass_by_value_format('mojo::ScopedDataPipeConsumerHandle'),
}
Expand Down
5 changes: 5 additions & 0 deletions sky/engine/core/core.gni
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ sky_core_files = [
"painting/DrawLooperAddLayerCallback.h",
"painting/DrawLooperLayerInfo.cpp",
"painting/DrawLooperLayerInfo.h",
"painting/FilterQuality.h",
"painting/LayerDrawLooperBuilder.cpp",
"painting/LayerDrawLooperBuilder.h",
"painting/LayoutRoot.cpp",
Expand Down Expand Up @@ -463,6 +464,8 @@ sky_core_files = [
"painting/Point.h",
"painting/RRect.cpp",
"painting/RRect.h",
"painting/RSTransform.cpp",
"painting/RSTransform.h",
"painting/Rect.cpp",
"painting/Rect.h",
"painting/Shader.cpp",
Expand Down Expand Up @@ -706,12 +709,14 @@ core_dart_files = get_path_info([
"painting/Color.dart",
"painting/ColorFilter.dart",
"painting/DrawLooperLayerInfo.dart",
"painting/FilterQuality.dart",
"painting/Gradient.dart",
"painting/MaskFilter.dart",
"painting/Offset.dart",
"painting/OffsetBase.dart",
"painting/PaintingStyle.dart",
"painting/Point.dart",
"painting/RSTransform.dart",
"painting/Rect.dart",
"painting/Size.dart",
"painting/TransferMode.dart",
Expand Down
42 changes: 42 additions & 0 deletions sky/engine/core/painting/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,46 @@ void Canvas::drawPaintingNode(PaintingNode* paintingNode, const Point& p)
translate(-p.sk_point.x(), -p.sk_point.y());
}

void Canvas::drawAtlas(CanvasImage* atlas,
const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
const Vector<SkColor>& colors, SkXfermode::Mode mode,
const Rect& cullRect, Paint* paint, ExceptionState& es)
{
if (!m_canvas)
return;
RefPtr<SkImage> skImage = adoptRef(SkImage::NewFromBitmap(atlas->bitmap()));
if (transforms.size() != rects.size())
return es.ThrowRangeError("transforms and rects lengths must match");
if (colors.size() && colors.size() != rects.size())
return es.ThrowRangeError("if supplied, colors length must match that of transforms and rects");

Vector<SkRSXform> skXForms;
for (size_t x = 0; x < transforms.size(); x++) {
const RSTransform& transform = transforms[x];
if (transform.is_null)
return es.ThrowRangeError("transforms contained a null");
skXForms.append(transform.sk_xform);
}

Vector<SkRect> skRects;
for (size_t x = 0; x < rects.size(); x++) {
const Rect& rect = rects[x];
if (rect.is_null)
return es.ThrowRangeError("rects contained a null");
skRects.append(rect.sk_rect);
}

m_canvas->drawAtlas(
skImage.get(),
skXForms.data(),
skRects.data(),
colors.isEmpty() ? nullptr : colors.data(),
skXForms.size(),
mode,
cullRect.is_null ? nullptr : &cullRect.sk_rect,
paint ? &paint->paint() : nullptr
);
}


} // namespace blink
6 changes: 6 additions & 0 deletions sky/engine/core/painting/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "sky/engine/core/painting/RRect.h"
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/core/painting/Size.h"
#include "sky/engine/core/painting/RSTransform.h"
#include "sky/engine/platform/graphics/DisplayList.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/tonic/float32_list.h"
Expand Down Expand Up @@ -86,6 +87,11 @@ class Canvas : public RefCounted<Canvas>, public DartWrappable {
void drawDrawable(Drawable* drawable);
void drawPaintingNode(PaintingNode* paintingNode, const Point& p);

void drawAtlas(CanvasImage* atlas,
const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
const Vector<SkColor>& colors, SkXfermode::Mode mode,
const Rect& cullRect, Paint* paint, ExceptionState&);

SkCanvas* skCanvas() { return m_canvas; }
void clearSkCanvas() { m_canvas = nullptr; }
bool isRecording() const { return !!m_canvas; }
Expand Down
5 changes: 5 additions & 0 deletions sky/engine/core/painting/Canvas.idl
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@
void drawPicture(Picture picture);
void drawDrawable(Drawable drawable);
void drawPaintingNode(PaintingNode paintingNode, Point p);

// TODO(eseidel): Paint should be optional, but optional doesn't work.
[RaisesException] void drawAtlas(Image image,
sequence<RSTransform> transforms, sequence<Rect> rects,
sequence<Color> colors, TransferMode mode, Rect cullRect, Paint paint);
};
14 changes: 14 additions & 0 deletions sky/engine/core/painting/FilterQuality.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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.

part of dart.sky;

/// List of predefined filter quality modes. This list comes from Skia's
/// SkFitlerQuality.h and the values (order) should be kept in sync.
enum FilterQuality {
none,
low,
medium,
high,
}
26 changes: 26 additions & 0 deletions sky/engine/core/painting/FilterQuality.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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_FILTERQUALITY_H_
#define SKY_ENGINE_CORE_PAINTING_FILTERQUALITY_H_

#include "sky/engine/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkXfermode.h"

namespace blink {

class FilterQuality {};

template <>
struct DartConverter<FilterQuality>
: public DartConverterEnum<SkFilterQuality> {};

// If this fails, it's because SkFilterQuality has changed. We need to change
// FilterQuality.dart to ensure the FilterQuality enum is in sync with the C++
// values.
COMPILE_ASSERT(SkFilterQuality::kHigh_SkFilterQuality == 3, Need_to_update_FilterQuality_dart);

} // namespace blink

#endif // SKY_ENGINE_CORE_PAINTING_FILTERQUALITY_H_
4 changes: 4 additions & 0 deletions sky/engine/core/painting/Paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ void Paint::setTransferMode(SkXfermode::Mode transfer_mode) {
paint_.setXfermodeMode(transfer_mode);
}

void Paint::setFilterQuality(SkFilterQuality filter_quality) {
paint_.setFilterQuality(filter_quality);
}

String Paint::toString() const {
StringBuilder result;

Expand Down
2 changes: 2 additions & 0 deletions sky/engine/core/painting/Paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "sky/engine/core/painting/CanvasColor.h"
#include "sky/engine/core/painting/PaintingStyle.h"
#include "sky/engine/core/painting/TransferMode.h"
#include "sky/engine/core/painting/FilterQuality.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
Expand Down Expand Up @@ -44,6 +45,7 @@ class Paint : public RefCounted<Paint>, public DartWrappable {
void setShader(Shader* shader);
void setStyle(SkPaint::Style style);
void setTransferMode(SkXfermode::Mode transfer_mode);
void setFilterQuality(SkFilterQuality filter_quality);

const SkPaint& paint() const { return paint_; }
void setPaint(const SkPaint& paint) { paint_ = paint; }
Expand Down
1 change: 1 addition & 0 deletions sky/engine/core/painting/Paint.idl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
void setShader(Shader shader);
void setStyle(PaintingStyle style);
void setTransferMode(TransferMode transferMode);
void setFilterQuality(FilterQuality filterQuality);

DOMString toString();
};
57 changes: 57 additions & 0 deletions sky/engine/core/painting/RSTransform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 "sky/engine/core/script/dom_dart_state.h"
#include "sky/engine/tonic/dart_error.h"
#include "sky/engine/tonic/dart_value.h"
#include "base/logging.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, DOMDartState::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));
ASSERT(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;
}

RSTransform DartConverter<RSTransform>::FromArgumentsWithNullCheck(Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
Dart_Handle dart_xform = Dart_GetNativeArgument(args, index);
DCHECK(!LogIfError(dart_xform));
return FromDart(dart_xform);
}

} // namespace blink
22 changes: 22 additions & 0 deletions sky/engine/core/painting/RSTransform.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

part of dart.sky;

// Modeled after Skia's SkRSXform
class RSTransform {
RSTransform(double scos, double ssin, double tx, double ty) {
_value
..[0] = scos
..[1] = ssin
..[2] = tx
..[3] = ty;
}

final Float32List _value = new Float32List(4);
double get scos => _value[0];
double get ssin => _value[1];
double get tx => _value[2];
double get ty => _value[3];
}
32 changes: 32 additions & 0 deletions sky/engine/core/painting/RSTransform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 "sky/engine/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);
static RSTransform FromArgumentsWithNullCheck(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
};

} // namespace blink

#endif // SKY_ENGINE_CORE_PAINTING_RSTRANSFORM_H_
18 changes: 10 additions & 8 deletions sky/engine/core/painting/Rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@

namespace blink {

// Convert dart_rect._value[0...3] ==> SkRect.
Rect DartConverter<Rect>::FromArgumentsWithNullCheck(Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
// Convert dart_rect._value[0...3] ==> SkRect
Rect DartConverter<Rect>::FromDart(Dart_Handle dart_rect) {
Rect result;
result.is_null = true;

Dart_Handle dart_rect = Dart_GetNativeArgument(args, index);
DCHECK(!LogIfError(dart_rect));

if (Dart_IsNull(dart_rect))
return result;

Expand Down Expand Up @@ -52,4 +46,12 @@ Rect DartConverter<Rect>::FromArgumentsWithNullCheck(Dart_NativeArguments args,
return result;
}

Rect DartConverter<Rect>::FromArgumentsWithNullCheck(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
1 change: 1 addition & 0 deletions sky/engine/core/painting/Rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Rect {

template <>
struct DartConverter<Rect> {
static Rect FromDart(Dart_Handle handle);
static Rect FromArgumentsWithNullCheck(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
Expand Down
Loading