mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #1905 from jason-simmons/canvas_rrect_marshal
Marshal RRect using a DartConverter (as is done for Rect)
This commit is contained in:
commit
92e31b8aeb
@ -125,6 +125,7 @@ CPP_SPECIAL_CONVERSION_RULES = {
|
||||
'Paint': 'Paint',
|
||||
'Point': 'Point',
|
||||
'Rect': 'Rect',
|
||||
'RRect': 'RRect',
|
||||
'Size': 'Size',
|
||||
'MojoDataPipeConsumer': 'mojo::ScopedDataPipeConsumerHandle',
|
||||
'TileMode': 'SkShader::TileMode',
|
||||
@ -385,6 +386,7 @@ DART_TO_CPP_VALUE = {
|
||||
'Offset': pass_by_value_format('Offset'),
|
||||
'Paint': pass_by_value_format('Paint'),
|
||||
'Point': pass_by_value_format('Point'),
|
||||
'RRect': pass_by_value_format('RRect'),
|
||||
'RSTransform': pass_by_value_format('RSTransform'),
|
||||
'Rect': pass_by_value_format('Rect'),
|
||||
'Size': pass_by_value_format('Size'),
|
||||
|
||||
@ -46,10 +46,10 @@ void SceneBuilder::pushClipRect(const Rect& rect)
|
||||
addLayer(std::move(layer));
|
||||
}
|
||||
|
||||
void SceneBuilder::pushClipRRect(const RRect* rrect, const Rect& bounds)
|
||||
void SceneBuilder::pushClipRRect(const RRect& rrect, const Rect& bounds)
|
||||
{
|
||||
std::unique_ptr<sky::compositor::ClipRRectLayer> layer(new sky::compositor::ClipRRectLayer());
|
||||
layer->set_clip_rrect(rrect->rrect());
|
||||
layer->set_clip_rrect(rrect.sk_rrect);
|
||||
addLayer(std::move(layer));
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ public:
|
||||
|
||||
void pushTransform(const Float64List& matrix4, ExceptionState&);
|
||||
void pushClipRect(const Rect& rect);
|
||||
void pushClipRRect(const RRect* rrect, const Rect& bounds);
|
||||
void pushClipRRect(const RRect& rrect, const Rect& bounds);
|
||||
void pushClipPath(const CanvasPath* path, const Rect& bounds);
|
||||
void pushOpacity(int alpha, const Rect& bounds);
|
||||
void pushColorFilter(SkColor color, SkXfermode::Mode transferMode, const Rect& bounds);
|
||||
|
||||
@ -272,7 +272,6 @@ core_idl_files = get_path_info([
|
||||
"painting/Path.idl",
|
||||
"painting/Picture.idl",
|
||||
"painting/PictureRecorder.idl",
|
||||
"painting/RRect.idl",
|
||||
"painting/Shader.idl",
|
||||
"text/Paragraph.idl",
|
||||
"text/ParagraphBuilder.idl",
|
||||
@ -300,6 +299,7 @@ core_dart_files = get_path_info([
|
||||
"painting/PaintingStyle.dart",
|
||||
"painting/Point.dart",
|
||||
"painting/Rect.dart",
|
||||
"painting/RRect.dart",
|
||||
"painting/RSTransform.dart",
|
||||
"painting/Size.dart",
|
||||
"painting/TransferMode.dart",
|
||||
|
||||
@ -118,11 +118,11 @@ void Canvas::clipRect(const Rect& rect)
|
||||
m_canvas->clipRect(rect.sk_rect);
|
||||
}
|
||||
|
||||
void Canvas::clipRRect(const RRect* rrect)
|
||||
void Canvas::clipRRect(const RRect& rrect)
|
||||
{
|
||||
if (!m_canvas)
|
||||
return;
|
||||
m_canvas->clipRRect(rrect->rrect(), SkRegion::kIntersect_Op, true);
|
||||
m_canvas->clipRRect(rrect.sk_rrect, SkRegion::kIntersect_Op, true);
|
||||
}
|
||||
|
||||
void Canvas::clipPath(const CanvasPath* path)
|
||||
@ -160,21 +160,18 @@ void Canvas::drawRect(const Rect& rect, const Paint& paint)
|
||||
m_canvas->drawRect(rect.sk_rect, paint.sk_paint);
|
||||
}
|
||||
|
||||
void Canvas::drawRRect(const RRect* rrect, const Paint& paint)
|
||||
void Canvas::drawRRect(const RRect& rrect, const Paint& paint)
|
||||
{
|
||||
if (!m_canvas)
|
||||
return;
|
||||
ASSERT(rrect);
|
||||
m_canvas->drawRRect(rrect->rrect(), paint.sk_paint);
|
||||
m_canvas->drawRRect(rrect.sk_rrect, paint.sk_paint);
|
||||
}
|
||||
|
||||
void Canvas::drawDRRect(const RRect* outer, const RRect* inner, const Paint& paint)
|
||||
void Canvas::drawDRRect(const RRect& outer, const RRect& inner, const Paint& paint)
|
||||
{
|
||||
if (!m_canvas)
|
||||
return;
|
||||
ASSERT(outer);
|
||||
ASSERT(inner);
|
||||
m_canvas->drawDRRect(outer->rrect(), inner->rrect(), paint.sk_paint);
|
||||
m_canvas->drawDRRect(outer.sk_rrect, inner.sk_rrect, paint.sk_paint);
|
||||
}
|
||||
|
||||
void Canvas::drawOval(const Rect& rect, const Paint& paint)
|
||||
|
||||
@ -74,15 +74,15 @@ public:
|
||||
Float64List getTotalMatrix() const;
|
||||
|
||||
void clipRect(const Rect& rect);
|
||||
void clipRRect(const RRect* rrect);
|
||||
void clipRRect(const RRect& rrect);
|
||||
void clipPath(const CanvasPath* path);
|
||||
|
||||
void drawColor(SkColor color, SkXfermode::Mode transferMode);
|
||||
void drawLine(const Point& p1, const Point& p2, const Paint& paint);
|
||||
void drawPaint(const Paint& paint);
|
||||
void drawRect(const Rect& rect, const Paint& paint);
|
||||
void drawRRect(const RRect* rrect, const Paint& paint);
|
||||
void drawDRRect(const RRect* outer, const RRect* inner, const Paint& paint);
|
||||
void drawRRect(const RRect& rrect, const Paint& paint);
|
||||
void drawDRRect(const RRect& outer, const RRect& inner, const Paint& paint);
|
||||
void drawOval(const Rect& rect, const Paint& paint);
|
||||
void drawCircle(const Point& c, float radius, const Paint& paint);
|
||||
void drawPath(const CanvasPath* path, const Paint& paint);
|
||||
|
||||
@ -4,26 +4,50 @@
|
||||
|
||||
#include "sky/engine/core/painting/RRect.h"
|
||||
|
||||
#include "sky/engine/core/script/dom_dart_state.h"
|
||||
#include "sky/engine/tonic/dart_error.h"
|
||||
#include "sky/engine/tonic/dart_value.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
RRect::RRect()
|
||||
{
|
||||
// Construct an SkRRect from a Dart RRect object.
|
||||
// The Dart RRect has a _value field which is a Float32List containing
|
||||
// [left, top, right, bottom, xRad, yRad]
|
||||
RRect DartConverter<RRect>::FromDart(Dart_Handle dart_rrect) {
|
||||
RRect result;
|
||||
result.is_null = true;
|
||||
if (Dart_IsNull(dart_rrect))
|
||||
return result;
|
||||
|
||||
Dart_Handle value =
|
||||
Dart_GetField(dart_rrect, 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 == 6);
|
||||
|
||||
result.sk_rrect.setRectXY(
|
||||
SkRect::MakeLTRB(data[0], data[1], data[2], data[3]),
|
||||
data[4], data[5]);
|
||||
|
||||
Dart_TypedDataReleaseData(value);
|
||||
|
||||
result.is_null = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
RRect::~RRect()
|
||||
{
|
||||
}
|
||||
|
||||
void RRect::setRectXY(const Rect& rect, float xRad, float yRad)
|
||||
{
|
||||
m_rrect.setRectXY(rect.sk_rect, xRad, yRad);
|
||||
}
|
||||
|
||||
PassRefPtr<RRect> RRect::shift(const Offset& offset) {
|
||||
RefPtr<RRect> rrect = RRect::create();
|
||||
rrect->m_rrect = m_rrect;
|
||||
rrect->m_rrect.offset(offset.sk_size.width(), offset.sk_size.height());
|
||||
return rrect.release();
|
||||
RRect DartConverter<RRect>::FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
Dart_Handle dart_rrect = Dart_GetNativeArgument(args, index);
|
||||
DCHECK(!LogIfError(dart_rrect));
|
||||
return FromDart(dart_rrect);
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
||||
37
sky/engine/core/painting/RRect.dart
Normal file
37
sky/engine/core/painting/RRect.dart
Normal file
@ -0,0 +1,37 @@
|
||||
part of dart_ui;
|
||||
|
||||
// A rounded rectangle.
|
||||
class RRect {
|
||||
RRect();
|
||||
|
||||
/// Initialize with the same radii for all four corners.
|
||||
RRect.fromRectXY(Rect rect, double xRadius, double yRadius) {
|
||||
setRectXY(rect, xRadius, yRadius);
|
||||
}
|
||||
|
||||
final Float32List _value = new Float32List(6);
|
||||
|
||||
// TODO(jsimmons): remove this so this class will be immutable.
|
||||
void setRectXY(Rect rect, double xRadius, double yRadius) {
|
||||
_value
|
||||
..[0] = rect.left
|
||||
..[1] = rect.top
|
||||
..[2] = rect.right
|
||||
..[3] = rect.bottom
|
||||
..[4] = xRadius
|
||||
..[5] = yRadius;
|
||||
}
|
||||
|
||||
/// Returns a new RRect translated by the given offset.
|
||||
RRect shift(Offset offset) {
|
||||
result = new RRect();
|
||||
result._value
|
||||
..[0] = _value[0] + offset.dx
|
||||
..[1] = _value[1] + offset.dy
|
||||
..[2] = _value[2] + offset.dx
|
||||
..[3] = _value[3] + offset.dy
|
||||
..[4] = _value[4]
|
||||
..[5] = _value[5];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -5,35 +5,24 @@
|
||||
#ifndef SKY_ENGINE_CORE_PAINTING_RRECT_H_
|
||||
#define SKY_ENGINE_CORE_PAINTING_RRECT_H_
|
||||
|
||||
#include "sky/engine/core/painting/Offset.h"
|
||||
#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 "dart/runtime/include/dart_api.h"
|
||||
#include "sky/engine/tonic/dart_converter.h"
|
||||
#include "third_party/skia/include/core/SkRRect.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class RRect : public RefCounted<RRect>, public DartWrappable {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
public:
|
||||
~RRect() override;
|
||||
static PassRefPtr<RRect> create()
|
||||
{
|
||||
return adoptRef(new RRect);
|
||||
}
|
||||
class RRect {
|
||||
public:
|
||||
SkRRect sk_rrect;
|
||||
bool is_null;
|
||||
};
|
||||
|
||||
void setRectXY(const Rect& rect, float xRad, float yRad);
|
||||
|
||||
const SkRRect& rrect() const { return m_rrect; }
|
||||
void setRRect(const SkRRect& rrect) { m_rrect = rrect; }
|
||||
|
||||
PassRefPtr<RRect> shift(const Offset& offset);
|
||||
|
||||
private:
|
||||
RRect();
|
||||
|
||||
SkRRect m_rrect;
|
||||
template <>
|
||||
struct DartConverter<RRect> {
|
||||
static RRect FromDart(Dart_Handle handle);
|
||||
static RRect FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
// 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.
|
||||
|
||||
[
|
||||
Constructor(),
|
||||
] interface RRect {
|
||||
void setRectXY(Rect rect, float xRad, float yRad);
|
||||
|
||||
RRect shift(Offset offset);
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user