Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
b714feca
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b714feca
编写于
12月 29, 2015
作者:
A
Adam Barth
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove IDL from Canvas and related interfaces
After this patch, Path is the only interface using IDL.
上级
c8d01823
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
380 addition
and
250 deletion
+380
-250
sky/engine/bindings/dart_ui.cc
sky/engine/bindings/dart_ui.cc
+8
-0
sky/engine/core/core.gni
sky/engine/core/core.gni
+0
-6
sky/engine/core/dart/painting.dart
sky/engine/core/dart/painting.dart
+137
-0
sky/engine/core/painting/Canvas.cpp
sky/engine/core/painting/Canvas.cpp
+148
-87
sky/engine/core/painting/Canvas.h
sky/engine/core/painting/Canvas.h
+13
-34
sky/engine/core/painting/Canvas.idl
sky/engine/core/painting/Canvas.idl
+0
-48
sky/engine/core/painting/CanvasImage.cpp
sky/engine/core/painting/CanvasImage.cpp
+24
-2
sky/engine/core/painting/CanvasImage.h
sky/engine/core/painting/CanvasImage.h
+5
-2
sky/engine/core/painting/Image.idl
sky/engine/core/painting/Image.idl
+0
-14
sky/engine/core/painting/Picture.cpp
sky/engine/core/painting/Picture.cpp
+12
-0
sky/engine/core/painting/Picture.h
sky/engine/core/painting/Picture.h
+3
-1
sky/engine/core/painting/Picture.idl
sky/engine/core/painting/Picture.idl
+0
-12
sky/engine/core/painting/PictureRecorder.cpp
sky/engine/core/painting/PictureRecorder.cpp
+25
-1
sky/engine/core/painting/PictureRecorder.h
sky/engine/core/painting/PictureRecorder.h
+3
-1
sky/engine/core/painting/PictureRecorder.idl
sky/engine/core/painting/PictureRecorder.idl
+0
-8
sky/engine/core/painting/VertexMode.dart
sky/engine/core/painting/VertexMode.dart
+0
-12
sky/engine/core/painting/VertexMode.h
sky/engine/core/painting/VertexMode.h
+0
-21
sky/engine/tonic/dart_args.h
sky/engine/tonic/dart_args.h
+2
-1
未找到文件。
sky/engine/bindings/dart_ui.cc
浏览文件 @
b714feca
...
...
@@ -8,13 +8,17 @@
#include "sky/engine/bindings/dart_runtime_hooks.h"
#include "sky/engine/core/compositing/Scene.h"
#include "sky/engine/core/compositing/SceneBuilder.h"
#include "sky/engine/core/painting/Canvas.h"
#include "sky/engine/core/painting/CanvasGradient.h"
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/core/painting/ColorFilter.h"
#include "sky/engine/core/painting/DrawLooperLayerInfo.h"
#include "sky/engine/core/painting/ImageShader.h"
#include "sky/engine/core/painting/LayerDrawLooperBuilder.h"
#include "sky/engine/core/painting/MaskFilter.h"
#include "sky/engine/core/painting/painting.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/PictureRecorder.h"
#include "sky/engine/core/text/Paragraph.h"
#include "sky/engine/core/text/ParagraphBuilder.h"
#include "sky/engine/core/window/window.h"
...
...
@@ -47,7 +51,9 @@ const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
void
DartUI
::
InitForIsolate
()
{
if
(
!
g_natives
)
{
g_natives
=
new
DartLibraryNatives
();
Canvas
::
RegisterNatives
(
g_natives
);
CanvasGradient
::
RegisterNatives
(
g_natives
);
CanvasImage
::
RegisterNatives
(
g_natives
);
ColorFilter
::
RegisterNatives
(
g_natives
);
DartRuntimeHooks
::
RegisterNatives
(
g_natives
);
DrawLooperLayerInfo
::
RegisterNatives
(
g_natives
);
...
...
@@ -57,6 +63,8 @@ void DartUI::InitForIsolate() {
Painting
::
RegisterNatives
(
g_natives
);
Paragraph
::
RegisterNatives
(
g_natives
);
ParagraphBuilder
::
RegisterNatives
(
g_natives
);
Picture
::
RegisterNatives
(
g_natives
);
PictureRecorder
::
RegisterNatives
(
g_natives
);
Scene
::
RegisterNatives
(
g_natives
);
SceneBuilder
::
RegisterNatives
(
g_natives
);
Window
::
RegisterNatives
(
g_natives
);
...
...
sky/engine/core/core.gni
浏览文件 @
b714feca
...
...
@@ -76,7 +76,6 @@ sky_core_files = [
"painting/Size.cpp",
"painting/Size.h",
"painting/TransferMode.h",
"painting/VertexMode.h",
"rendering/BidiRun.h",
"rendering/BidiRunForLine.cpp",
"rendering/BidiRunForLine.h",
...
...
@@ -234,11 +233,7 @@ sky_core_files = [
]
core_idl_files = get_path_info([
"painting/Canvas.idl",
"painting/Image.idl",
"painting/Path.idl",
"painting/Picture.idl",
"painting/PictureRecorder.idl",
],
"abspath")
...
...
@@ -263,6 +258,5 @@ core_dart_files = get_path_info([
"painting/Rect.dart",
"painting/Size.dart",
"painting/TransferMode.dart",
"painting/VertexMode.dart",
],
"abspath")
sky/engine/core/dart/painting.dart
浏览文件 @
b714feca
...
...
@@ -4,6 +4,13 @@
part of
dart_ui
;
abstract
class
Image
extends
NativeFieldWrapperClass2
{
int
get
width
native
"Image_width"
;
int
get
height
native
"Image_height"
;
void
dispose
()
native
"Image_dispose"
;
}
typedef
void
_ImageDecoderCallback
(
Image
result
);
void
decodeImageFromDataPipe
(
int
handle
,
_ImageDecoderCallback
callback
)
...
...
@@ -156,3 +163,133 @@ class ImageShader extends Shader {
}
}
/// Defines how a list of points is interpreted when drawing a set of triangles.
/// See Skia or OpenGL documentation for more details.
enum
VertexMode
{
triangles
,
triangleStrip
,
triangleFan
,
}
class
Canvas
extends
NativeFieldWrapperClass2
{
void
_constructor
(
PictureRecorder
recorder
,
Rect
bounds
)
native
"Canvas_constructor"
;
Canvas
(
PictureRecorder
recorder
,
Rect
bounds
)
{
if
(
recorder
==
null
)
throw
new
ArgumentError
(
"[recorder] argument cannot be null."
);
if
(
recorder
.
isRecording
)
throw
new
ArgumentError
(
"You must call endRecording() before reusing a PictureRecorder to create a new Canvas object."
);
_constructor
(
recorder
,
bounds
);
}
void
save
()
native
"Canvas_save"
;
// TODO(jackson): Paint should be optional, but making it optional causes crash
void
saveLayer
(
Rect
bounds
,
Paint
paint
)
native
"Canvas_saveLayer"
;
void
restore
()
native
"Canvas_restore"
;
/// returns 1 for a clean canvas; each call to save() or saveLayer() increments it, and each call to
int
getSaveCount
()
native
"Canvas_getSaveCount"
;
void
translate
(
double
dx
,
double
dy
)
native
"Canvas_translate"
;
void
scale
(
double
sx
,
double
sy
)
native
"Canvas_scale"
;
void
rotate
(
double
radians
)
native
"Canvas_rotate"
;
void
skew
(
double
sx
,
double
sy
)
native
"Canvas_skew"
;
void
concat
(
Float64List
matrix4
)
native
"Canvas_concat"
;
void
setMatrix
(
Float64List
matrix4
)
native
"Canvas_setMatrix"
;
Float64List
getTotalMatrix
()
native
"Canvas_getTotalMatrix"
;
void
clipRect
(
Rect
rect
)
native
"Canvas_clipRect"
;
void
clipRRect
(
RRect
rrect
)
native
"Canvas_clipRRect"
;
void
clipPath
(
Path
path
)
native
"Canvas_clipPath"
;
void
drawColor
(
Color
color
,
TransferMode
transferMode
)
native
"Canvas_drawColor"
;
void
drawLine
(
Point
p1
,
Point
p2
,
Paint
paint
)
native
"Canvas_drawLine"
;
void
drawPaint
(
Paint
paint
)
native
"Canvas_drawPaint"
;
void
drawRect
(
Rect
rect
,
Paint
paint
)
native
"Canvas_drawRect"
;
void
drawRRect
(
RRect
rrect
,
Paint
paint
)
native
"Canvas_drawRRect"
;
void
drawDRRect
(
RRect
outer
,
RRect
inner
,
Paint
paint
)
native
"Canvas_drawDRRect"
;
void
drawOval
(
Rect
rect
,
Paint
paint
)
native
"Canvas_drawOval"
;
void
drawCircle
(
Point
c
,
double
radius
,
Paint
paint
)
native
"Canvas_drawCircle"
;
void
drawPath
(
Path
path
,
Paint
paint
)
native
"Canvas_drawPath"
;
void
drawImage
(
Image
image
,
Point
p
,
Paint
paint
)
native
"Canvas_drawImage"
;
void
drawImageRect
(
Image
image
,
Rect
src
,
Rect
dst
,
Paint
paint
)
native
"Canvas_drawImageRect"
;
void
drawImageNine
(
Image
image
,
Rect
center
,
Rect
dst
,
Paint
paint
)
native
"Canvas_drawImageNine"
;
void
drawPicture
(
Picture
picture
)
native
"Canvas_drawPicture"
;
void
_drawVertices
(
int
vertexMode
,
List
<
Point
>
vertices
,
List
<
Point
>
textureCoordinates
,
List
<
Color
>
colors
,
TransferMode
transferMode
,
List
<
int
>
indicies
,
Paint
paint
)
native
"Canvas_drawVertices"
;
void
drawVertices
(
VertexMode
vertexMode
,
List
<
Point
>
vertices
,
List
<
Point
>
textureCoordinates
,
List
<
Color
>
colors
,
TransferMode
transferMode
,
List
<
int
>
indicies
,
Paint
paint
)
{
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"
);
}
for
(
Point
point
in
textureCoordinates
)
{
if
(
point
==
null
)
throw
new
ArgumentError
(
"[textureCoordinates] cannot contain a null"
);
}
_drawVertices
(
vertexMode
.
index
,
vertices
,
textureCoordinates
,
colors
,
transferMode
,
indicies
,
paint
);
}
// TODO(eseidel): Paint should be optional, but optional doesn't work.
void
_drawAtlas
(
Image
image
,
List
<
RSTransform
>
transforms
,
List
<
Rect
>
rects
,
List
<
Color
>
colors
,
TransferMode
mode
,
Rect
cullRect
,
Paint
paint
)
native
"Canvas_drawAtlas"
;
void
drawAtlas
(
Image
image
,
List
<
RSTransform
>
transforms
,
List
<
Rect
>
rects
,
List
<
Color
>
colors
,
TransferMode
mode
,
Rect
cullRect
,
Paint
paint
)
{
if
(
transforms
.
length
!=
rects
.
length
)
throw
new
ArgumentError
(
"[transforms] and [rects] lengths must match"
);
if
(
colors
.
isNotEmpty
&&
colors
.
length
!=
rects
.
length
)
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"
);
}
for
(
Rect
rect
in
rects
)
{
if
(
rect
==
null
)
throw
new
ArgumentError
(
"[rects] cannot contain a null"
);
}
_drawAtlas
(
image
,
transforms
,
rects
,
colors
,
mode
,
cullRect
,
paint
);
}
}
abstract
class
Picture
extends
NativeFieldWrapperClass2
{
/// Replays the drawing commands on the specified canvas. Note that
/// this has the effect of unfurling this picture into the destination
/// canvas. Using the Canvas drawPicture entry point gives the destination
/// canvas the option of just taking a ref.
void
playback
(
Canvas
canvas
)
native
"Picture_playback"
;
void
dispose
()
native
"Picture_dispose"
;
}
class
PictureRecorder
extends
NativeFieldWrapperClass2
{
void
_constructor
()
native
"PictureRecorder_constructor"
;
PictureRecorder
()
{
_constructor
();
}
bool
get
isRecording
native
"PictureRecorder_isRecording"
;
Picture
endRecording
()
native
"PictureRecorder_endRecording"
;
}
sky/engine/core/painting/Canvas.cpp
浏览文件 @
b714feca
...
...
@@ -9,11 +9,96 @@
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/core/painting/Matrix.h"
#include "sky/engine/platform/geometry/IntRect.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_library_natives.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace
blink
{
static
void
Canvas_constructor
(
Dart_NativeArguments
args
)
{
DartCallConstructor
(
&
Canvas
::
create
,
args
);
}
static
void
Canvas_concat
(
Dart_NativeArguments
args
)
{
DartArgIterator
it
(
args
);
Float64List
matrix4
=
it
.
GetNext
<
Float64List
>
();
if
(
it
.
had_exception
())
return
;
ExceptionState
es
;
GetReceiver
<
Canvas
>
(
args
)
->
concat
(
matrix4
,
es
);
if
(
es
.
had_exception
())
Dart_ThrowException
(
es
.
GetDartException
(
args
,
true
));
}
static
void
Canvas_setMatrix
(
Dart_NativeArguments
args
)
{
DartArgIterator
it
(
args
);
Float64List
matrix4
=
it
.
GetNext
<
Float64List
>
();
if
(
it
.
had_exception
())
return
;
ExceptionState
es
;
GetReceiver
<
Canvas
>
(
args
)
->
setMatrix
(
matrix4
,
es
);
if
(
es
.
had_exception
())
Dart_ThrowException
(
es
.
GetDartException
(
args
,
true
));
}
IMPLEMENT_WRAPPERTYPEINFO
(
Canvas
);
#define FOR_EACH_BINDING(V) \
V(Canvas, save) \
V(Canvas, saveLayer) \
V(Canvas, restore) \
V(Canvas, getSaveCount) \
V(Canvas, translate) \
V(Canvas, scale) \
V(Canvas, rotate) \
V(Canvas, skew) \
V(Canvas, getTotalMatrix) \
V(Canvas, clipRect) \
V(Canvas, clipRRect) \
V(Canvas, clipPath) \
V(Canvas, drawColor) \
V(Canvas, drawLine) \
V(Canvas, drawPaint) \
V(Canvas, drawRect) \
V(Canvas, drawRRect) \
V(Canvas, drawDRRect) \
V(Canvas, drawOval) \
V(Canvas, drawCircle) \
V(Canvas, drawPath) \
V(Canvas, drawImage) \
V(Canvas, drawImageRect) \
V(Canvas, drawImageNine) \
V(Canvas, drawPicture) \
V(Canvas, drawVertices) \
V(Canvas, drawAtlas)
// These are custom because of ExceptionState:
// V(Canvas, concat)
// V(Canvas, setMatrix)
FOR_EACH_BINDING
(
DART_NATIVE_CALLBACK
)
void
Canvas
::
RegisterNatives
(
DartLibraryNatives
*
natives
)
{
natives
->
Register
({
{
"Canvas_constructor"
,
Canvas_constructor
,
3
,
true
},
{
"Canvas_concat"
,
Canvas_concat
,
2
,
true
},
{
"Canvas_setMatrix"
,
Canvas_setMatrix
,
2
,
true
},
FOR_EACH_BINDING
(
DART_REGISTER_NATIVE
)
});
}
PassRefPtr
<
Canvas
>
Canvas
::
create
(
PictureRecorder
*
recorder
,
Rect
&
bounds
)
{
ASSERT
(
recorder
);
ASSERT
(
!
recorder
->
isRecording
());
PassRefPtr
<
Canvas
>
canvas
=
adoptRef
(
new
Canvas
(
recorder
->
beginRecording
(
bounds
)));
recorder
->
set_canvas
(
canvas
.
get
());
return
canvas
;
}
Canvas
::
Canvas
(
SkCanvas
*
skCanvas
)
:
m_canvas
(
skCanvas
)
{
...
...
@@ -102,7 +187,7 @@ void Canvas::setMatrix(const Float64List& matrix4, ExceptionState& es)
m_canvas
->
setMatrix
(
sk_matrix
);
}
Float64List
Canvas
::
getTotalMatrix
()
const
Float64List
Canvas
::
getTotalMatrix
()
{
// Maybe we should throw an exception instead of returning an empty matrix?
SkMatrix
sk_matrix
;
...
...
@@ -132,7 +217,7 @@ void Canvas::clipPath(const CanvasPath* path)
m_canvas
->
clipPath
(
path
->
path
(),
SkRegion
::
kIntersect_Op
);
}
void
Canvas
::
drawColor
(
SkColor
color
,
SkXfermode
::
Mode
transferMode
)
void
Canvas
::
drawColor
(
CanvasColor
color
,
Transfer
Mode
transferMode
)
{
if
(
!
m_canvas
)
return
;
...
...
@@ -231,97 +316,73 @@ void Canvas::drawVertices(SkCanvas::VertexMode vertexMode,
const
Vector
<
Point
>&
vertices
,
const
Vector
<
Point
>&
textureCoordinates
,
const
Vector
<
SkColor
>&
colors
,
SkXfermode
::
Mode
transferMode
,
Transfer
Mode
transferMode
,
const
Vector
<
int
>&
indices
,
const
Paint
&
paint
,
ExceptionState
&
es
)
const
Paint
&
paint
)
{
if
(
!
m_canvas
)
return
;
size_t
vertexCount
=
vertices
.
size
();
if
(
textureCoordinates
.
size
()
&&
textureCoordinates
.
size
()
!=
vertexCount
)
return
es
.
ThrowRangeError
(
"vertices and textureCoordinates lengths must match"
);
if
(
colors
.
size
()
&&
colors
.
size
()
!=
vertexCount
)
return
es
.
ThrowRangeError
(
"vertices and colors lengths must match"
);
Vector
<
SkPoint
>
skVertices
;
for
(
size_t
x
=
0
;
x
<
vertices
.
size
();
x
++
)
{
const
Point
&
point
=
vertices
[
x
];
if
(
point
.
is_null
)
return
es
.
ThrowRangeError
(
"vertices contained a null"
);
skVertices
.
append
(
point
.
sk_point
);
}
Vector
<
SkPoint
>
skTextureCoordinates
;
for
(
size_t
x
=
0
;
x
<
textureCoordinates
.
size
();
x
++
)
{
const
Point
&
point
=
textureCoordinates
[
x
];
if
(
point
.
is_null
)
return
es
.
ThrowRangeError
(
"textureCoordinates contained a null"
);
skTextureCoordinates
.
append
(
point
.
sk_point
);
}
Vector
<
uint16_t
>
skIndices
;
for
(
size_t
x
=
0
;
x
<
indices
.
size
();
x
++
)
{
uint16_t
i
=
indices
[
x
];
skIndices
.
append
(
i
);
}
RefPtr
<
SkXfermode
>
transferModePtr
=
adoptRef
(
SkXfermode
::
Create
(
transferMode
));
m_canvas
->
drawVertices
(
vertexMode
,
skVertices
.
size
(),
skVertices
.
data
(),
skTextureCoordinates
.
isEmpty
()
?
nullptr
:
skTextureCoordinates
.
data
(),
colors
.
isEmpty
()
?
nullptr
:
colors
.
data
(),
transferModePtr
.
get
(),
skIndices
.
isEmpty
()
?
nullptr
:
skIndices
.
data
(),
skIndices
.
size
(),
*
paint
.
paint
()
);
if
(
!
m_canvas
)
return
;
Vector
<
SkPoint
>
skVertices
;
skVertices
.
reserveInitialCapacity
(
vertices
.
size
());
for
(
const
Point
&
point
:
vertices
)
skVertices
.
append
(
point
.
sk_point
);
Vector
<
SkPoint
>
skTextureCoordinates
;
skVertices
.
reserveInitialCapacity
(
textureCoordinates
.
size
());
for
(
const
Point
&
point
:
textureCoordinates
)
skTextureCoordinates
.
append
(
point
.
sk_point
);
Vector
<
uint16_t
>
skIndices
;
skIndices
.
reserveInitialCapacity
(
indices
.
size
());
for
(
uint16_t
i
:
indices
)
skIndices
.
append
(
i
);
RefPtr
<
SkXfermode
>
transferModePtr
=
adoptRef
(
SkXfermode
::
Create
(
transferMode
));
m_canvas
->
drawVertices
(
vertexMode
,
skVertices
.
size
(),
skVertices
.
data
(),
skTextureCoordinates
.
isEmpty
()
?
nullptr
:
skTextureCoordinates
.
data
(),
colors
.
isEmpty
()
?
nullptr
:
colors
.
data
(),
transferModePtr
.
get
(),
skIndices
.
isEmpty
()
?
nullptr
:
skIndices
.
data
(),
skIndices
.
size
(),
*
paint
.
paint
()
);
}
void
Canvas
::
drawAtlas
(
CanvasImage
*
atlas
,
const
Vector
<
RSTransform
>&
transforms
,
const
Vector
<
Rect
>&
rects
,
const
Vector
<
SkColor
>&
colors
,
SkXfermode
::
Mode
mode
,
const
Rect
&
cullRect
,
const
Paint
&
paint
,
ExceptionState
&
es
)
const
Vector
<
SkColor
>&
colors
,
Transfer
Mode
mode
,
const
Rect
&
cullRect
,
const
Paint
&
paint
)
{
if
(
!
m_canvas
)
return
;
RefPtr
<
SkImage
>
skImage
=
atlas
->
image
();
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
()
);
if
(
!
m_canvas
)
return
;
RefPtr
<
SkImage
>
skImage
=
atlas
->
image
();
Vector
<
SkRSXform
>
skXForms
;
skXForms
.
reserveInitialCapacity
(
transforms
.
size
());
for
(
const
RSTransform
&
transform
:
transforms
)
skXForms
.
append
(
transform
.
sk_xform
);
Vector
<
SkRect
>
skRects
;
skRects
.
reserveInitialCapacity
(
rects
.
size
());
for
(
const
Rect
&
rect
:
rects
)
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
()
);
}
}
// namespace blink
sky/engine/core/painting/Canvas.h
浏览文件 @
b714feca
...
...
@@ -16,7 +16,6 @@
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/core/painting/Size.h"
#include "sky/engine/core/painting/RSTransform.h"
#include "sky/engine/core/painting/VertexMode.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/tonic/float64_list.h"
#include "sky/engine/wtf/PassRefPtr.h"
...
...
@@ -24,37 +23,16 @@
#include "third_party/skia/include/core/SkCanvas.h"
namespace
blink
{
class
DartLibraryNatives
;
class
CanvasImage
;
template
<
>
struct
DartConverter
<
SkCanvas
::
VertexMode
>
:
public
DartConverterInteger
<
SkCanvas
::
VertexMode
>
{};
class
Canvas
:
public
RefCounted
<
Canvas
>
,
public
DartWrappable
{
DEFINE_WRAPPERTYPEINFO
();
public:
static
PassRefPtr
<
Canvas
>
create
(
SkCanvas
*
skCanvas
)
{
ASSERT
(
skCanvas
);
return
adoptRef
(
new
Canvas
(
skCanvas
));
}
// TODO(ianh): fix crashes here https://github.com/domokit/mojo/issues/326
static
PassRefPtr
<
Canvas
>
create
(
PictureRecorder
*
recorder
,
Rect
&
bounds
,
ExceptionState
&
es
)
{
ASSERT
(
recorder
);
if
(
recorder
->
isRecording
())
{
es
.
ThrowTypeError
(
"You must call PictureRecorder.endRecording() before reusing a"
" PictureRecorder to create a new Canvas object."
);
// TODO(iansf): We should return a nullptr here, I think, but doing
// so will require modifying the dart template code to
// to correctly handle constructors that throw
// exceptions. For now, just let it return a dart
// object that may cause a crash later on -- if the
// dart code catches the error, it will leak a canvas
// but it won't crash.
}
PassRefPtr
<
Canvas
>
canvas
=
create
(
recorder
->
beginRecording
(
bounds
));
recorder
->
set_canvas
(
canvas
.
get
());
return
canvas
;
}
static
PassRefPtr
<
Canvas
>
create
(
PictureRecorder
*
recorder
,
Rect
&
bounds
);
~
Canvas
()
override
;
...
...
@@ -70,13 +48,13 @@ public:
void
concat
(
const
Float64List
&
matrix4
,
ExceptionState
&
);
void
setMatrix
(
const
Float64List
&
matrix4
,
ExceptionState
&
);
Float64List
getTotalMatrix
()
const
;
Float64List
getTotalMatrix
();
void
clipRect
(
const
Rect
&
rect
);
void
clipRRect
(
const
RRect
&
rrect
);
void
clipPath
(
const
CanvasPath
*
path
);
void
drawColor
(
SkColor
color
,
SkXfermode
::
Mode
transferMode
);
void
drawColor
(
CanvasColor
color
,
Transfer
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
);
...
...
@@ -94,20 +72,21 @@ public:
const
Vector
<
Point
>&
vertices
,
const
Vector
<
Point
>&
textureCoordinates
,
const
Vector
<
SkColor
>&
colors
,
SkXfermode
::
Mode
transferMode
,
Transfer
Mode
transferMode
,
const
Vector
<
int
>&
indices
,
const
Paint
&
paint
,
ExceptionState
&
es
);
const
Paint
&
paint
);
void
drawAtlas
(
CanvasImage
*
atlas
,
const
Vector
<
RSTransform
>&
transforms
,
const
Vector
<
Rect
>&
rects
,
const
Vector
<
SkColor
>&
colors
,
SkXfermode
::
Mode
mode
,
const
Rect
&
cullRect
,
const
Paint
&
paint
,
ExceptionState
&
);
const
Vector
<
SkColor
>&
colors
,
Transfer
Mode
mode
,
const
Rect
&
cullRect
,
const
Paint
&
paint
);
SkCanvas
*
skCanvas
()
{
return
m_canvas
;
}
void
clearSkCanvas
()
{
m_canvas
=
nullptr
;
}
bool
isRecording
()
const
{
return
!!
m_canvas
;
}
static
void
RegisterNatives
(
DartLibraryNatives
*
natives
);
protected:
explicit
Canvas
(
SkCanvas
*
skCanvas
);
...
...
sky/engine/core/painting/Canvas.idl
已删除
100644 → 0
浏览文件 @
c8d01823
//
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
.
//
TODO
(
mpcomplete
):
Figure
out
a
better
SkMatrix
representation
.
[
Constructor
(
PictureRecorder
recorder
,
Rect
bounds
),
RaisesException
=
Constructor
,
]
interface
Canvas
{
void
save
()
;
//
TODO
(
jackson
):
Paint
should
be
optional
,
but
making
it
optional
causes
crash
void
saveLayer
(
Rect
bounds
,
/*
optional
*/
Paint
paint
)
;
void
restore
()
;
int
getSaveCount
()
; // returns 1 for a clean canvas; each call to save() or saveLayer() increments it, and each call to restore() decrements it.
void
translate
(
float
dx
,
float
dy
)
;
void
scale
(
float
sx
,
float
sy
)
;
void
rotate
(
float
radians
)
;
void
skew
(
float
sx
,
float
sy
)
;
[
RaisesException
]
void
concat
(
Float64List
matrix4
)
;
[
RaisesException
]
void
setMatrix
(
Float64List
matrix4
)
;
Float64List
getTotalMatrix
()
;
void
clipRect
(
Rect
rect
)
;
void
clipRRect
(
RRect
rrect
)
;
void
clipPath
(
Path
path
)
;
void
drawColor
(
Color
color
,
TransferMode
transferMode
)
;
void
drawLine
(
Point
p1
,
Point
p2
,
Paint
paint
)
;
void
drawPaint
(
Paint
paint
)
;
void
drawRect
(
Rect
rect
,
Paint
paint
)
;
void
drawRRect
(
RRect
rrect
,
Paint
paint
)
;
void
drawDRRect
(
RRect
outer
,
RRect
inner
,
Paint
paint
)
;
void
drawOval
(
Rect
rect
,
Paint
paint
)
;
void
drawCircle
(
Point
c
,
float
radius
,
Paint
paint
)
;
void
drawPath
(
Path
path
,
Paint
paint
)
;
void
drawImage
(
Image
image
,
Point
p
,
Paint
paint
)
;
void
drawImageRect
(
Image
image
,
Rect
src
,
Rect
dst
,
Paint
paint
)
;
void
drawImageNine
(
Image
image
,
Rect
center
,
Rect
dst
,
Paint
paint
)
;
void
drawPicture
(
Picture
picture
)
;
[
RaisesException
]
void
drawVertices
(
VertexMode
vertexMode
,
sequence
<
Point
>
vertices
,
sequence
<
Point
>
textureCoordinates
,
sequence
<
Color
>
colors
,
TransferMode
transferMode
,
sequence
<
long
>
indicies
,
Paint
paint
)
;
//
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);
};
sky/engine/core/painting/CanvasImage.cpp
浏览文件 @
b714feca
...
...
@@ -4,19 +4,41 @@
#include "sky/engine/core/painting/CanvasImage.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_library_natives.h"
namespace
blink
{
typedef
CanvasImage
Image
;
IMPLEMENT_WRAPPERTYPEINFO
(
Image
);
#define FOR_EACH_BINDING(V) \
V(Image, width) \
V(Image, height) \
V(Image, dispose)
FOR_EACH_BINDING
(
DART_NATIVE_CALLBACK
)
void
CanvasImage
::
RegisterNatives
(
DartLibraryNatives
*
natives
)
{
natives
->
Register
({
FOR_EACH_BINDING
(
DART_REGISTER_NATIVE
)
});
}
CanvasImage
::
CanvasImage
()
{
}
CanvasImage
::~
CanvasImage
()
{
}
int
CanvasImage
::
width
()
const
{
int
CanvasImage
::
width
()
{
return
image_
->
width
();
}
int
CanvasImage
::
height
()
const
{
int
CanvasImage
::
height
()
{
return
image_
->
height
();
}
...
...
sky/engine/core/painting/CanvasImage.h
浏览文件 @
b714feca
...
...
@@ -10,6 +10,7 @@
#include "third_party/skia/include/core/SkImage.h"
namespace
blink
{
class
DartLibraryNatives
;
class
CanvasImage
final
:
public
RefCounted
<
CanvasImage
>
,
public
DartWrappable
{
...
...
@@ -18,13 +19,15 @@ class CanvasImage final : public RefCounted<CanvasImage>,
~
CanvasImage
()
override
;
static
PassRefPtr
<
CanvasImage
>
create
()
{
return
adoptRef
(
new
CanvasImage
);
}
int
width
()
const
;
int
height
()
const
;
int
width
();
int
height
();
void
dispose
();
SkImage
*
image
()
const
{
return
image_
.
get
();
}
void
setImage
(
PassRefPtr
<
SkImage
>
image
)
{
image_
=
image
;
}
static
void
RegisterNatives
(
DartLibraryNatives
*
natives
);
private:
CanvasImage
();
...
...
sky/engine/core/painting/Image.idl
已删除
100644 → 0
浏览文件 @
c8d01823
//
Copyright
2013
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
(),
ImplementedAs
=
CanvasImage
,
]
interface
Image
{
//
TODO
(
ianh
):
convert
this
to
a
Size
readonly
attribute
long
width
; // width in number of image pixels
readonly
attribute
long
height
; // height in number of image pixels
void
dispose
()
;
}
;
sky/engine/core/painting/Picture.cpp
浏览文件 @
b714feca
...
...
@@ -5,9 +5,21 @@
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/Canvas.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_library_natives.h"
namespace
blink
{
IMPLEMENT_WRAPPERTYPEINFO
(
Picture
);
#define FOR_EACH_BINDING(V) \
V(Picture, playback) \
V(Picture, dispose)
DART_BIND_ALL
(
Picture
,
FOR_EACH_BINDING
)
PassRefPtr
<
Picture
>
Picture
::
create
(
PassRefPtr
<
SkPicture
>
skPicture
)
{
ASSERT
(
skPicture
);
...
...
sky/engine/core/painting/Picture.h
浏览文件 @
b714feca
...
...
@@ -11,8 +11,8 @@
#include "third_party/skia/include/core/SkPicture.h"
namespace
blink
{
class
Canvas
;
class
DartLibraryNatives
;
class
Picture
:
public
RefCounted
<
Picture
>
,
public
DartWrappable
{
DEFINE_WRAPPERTYPEINFO
();
...
...
@@ -25,6 +25,8 @@ public:
void
playback
(
Canvas
*
canvas
);
void
dispose
();
static
void
RegisterNatives
(
DartLibraryNatives
*
natives
);
private:
explicit
Picture
(
PassRefPtr
<
SkPicture
>
skPicture
);
...
...
sky/engine/core/painting/Picture.idl
已删除
100644 → 0
浏览文件 @
c8d01823
//
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
.
interface
Picture
{
//
Replays
the
drawing
commands
on
the
specified
canvas
.
Note
that
//
this
has
the
effect
of
unfurling
this
picture
into
the
destination
//
canvas
.
Using
the
Canvas
drawPicture
entry
point
gives
the
destination
//
canvas
the
option
of
just
taking
a
ref
.
void
playback
(
Canvas
canvas
)
;
void
dispose
()
;
}
;
sky/engine/core/painting/PictureRecorder.cpp
浏览文件 @
b714feca
...
...
@@ -2,12 +2,36 @@
// 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/PictureRecorder.h"
#include "sky/engine/core/painting/Canvas.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/painting/PictureRecorder.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_library_natives.h"
namespace
blink
{
static
void
PictureRecorder_constructor
(
Dart_NativeArguments
args
)
{
DartCallConstructor
(
&
PictureRecorder
::
create
,
args
);
}
IMPLEMENT_WRAPPERTYPEINFO
(
PictureRecorder
);
#define FOR_EACH_BINDING(V) \
V(PictureRecorder, isRecording) \
V(PictureRecorder, endRecording)
FOR_EACH_BINDING
(
DART_NATIVE_CALLBACK
)
void
PictureRecorder
::
RegisterNatives
(
DartLibraryNatives
*
natives
)
{
natives
->
Register
({
{
"PictureRecorder_constructor"
,
PictureRecorder_constructor
,
1
,
true
},
FOR_EACH_BINDING
(
DART_REGISTER_NATIVE
)
});
}
PictureRecorder
::
PictureRecorder
()
{
}
...
...
sky/engine/core/painting/PictureRecorder.h
浏览文件 @
b714feca
...
...
@@ -12,8 +12,8 @@
#include "third_party/skia/include/core/SkPictureRecorder.h"
namespace
blink
{
class
Canvas
;
class
DartLibraryNatives
;
class
Picture
;
class
PictureRecorder
:
public
RefCounted
<
PictureRecorder
>
,
...
...
@@ -33,6 +33,8 @@ public:
void
set_canvas
(
PassRefPtr
<
Canvas
>
canvas
);
static
void
RegisterNatives
(
DartLibraryNatives
*
natives
);
private:
PictureRecorder
();
...
...
sky/engine/core/painting/PictureRecorder.idl
已删除
100644 → 0
浏览文件 @
c8d01823
//
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
PictureRecorder
{
Picture
endRecording
()
;
}
;
sky/engine/core/painting/VertexMode.dart
已删除
100644 → 0
浏览文件 @
c8d01823
// 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_ui
;
/// Defines how a list of points is interpreted when drawing a set of triangles. See Skia or OpenGL documentation for more details.
enum
VertexMode
{
triangles
,
triangleStrip
,
triangleFan
,
}
sky/engine/core/painting/VertexMode.h
已删除
100644 → 0
浏览文件 @
c8d01823
// 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_VERTEXMODE_H_
#define SKY_ENGINE_CORE_PAINTING_VERTEXMODE_H_
#include "sky/engine/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace
blink
{
class
VertexMode
{};
template
<
>
struct
DartConverter
<
VertexMode
>
:
public
DartConverterEnum
<
SkCanvas
::
VertexMode
>
{};
}
// namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_VERTEXMODE_H_
sky/engine/tonic/dart_args.h
浏览文件 @
b714feca
...
...
@@ -6,6 +6,7 @@
#define SKY_ENGINE_TONIC_DART_ARGS_H_
#include <type_traits>
#include <utility>
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_wrappable.h"
...
...
@@ -92,7 +93,7 @@ struct DartArgHolder {
template
<
typename
T
>
void
DartReturn
(
T
result
,
Dart_NativeArguments
args
)
{
DartConverter
<
T
>::
SetReturnValue
(
args
,
result
);
DartConverter
<
T
>::
SetReturnValue
(
args
,
std
::
move
(
result
)
);
}
template
<
typename
IndicesType
,
typename
T
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录