浏览代码

Merge branch 'skia' into siyaoH/skiaBase

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
addece2a
共有 6 个文件被更改,包括 135 次插入1 次删除
  1. 66
      com.unity.uiwidgets/Runtime/ui2/painting.cs
  2. 1
      engine/README.md
  3. 6
      engine/src/lib/ui/painting/path.h
  4. 52
      engine/src/lib/ui/painting/path_measure.cc
  5. 3
      engine/src/lib/ui/painting/path_measure.h
  6. 8
      engine/src/shell/platform/unity/unity_surface_manager.cc

66
com.unity.uiwidgets/Runtime/ui2/painting.cs


public Path() : base(Path_constructor()) {
}
private Path(IntPtr ptr) : base(ptr) {
public Path(IntPtr ptr) : base(ptr) {
}
protected override void DisposePtr(IntPtr ptr) {

}
}
public class Tangent {
public Tangent(Offset position, Offset vector) {
D.assert(position != null);
D.assert(vector != null);
this.position = position;
this.vector = vector;
}
public static Tangent fromAngle(Offset position, float angle) {
return new Tangent(position, new Offset(Mathf.Cos(angle), Mathf.Sin(angle)));
}
public readonly Offset position;
public readonly Offset vector;
public float angle => -Mathf.Atan2(vector.dy, vector.dx);
}
public class PathMetric {
public PathMetric(_PathMeasure measure) {
D.assert(measure != null);

public readonly int contourIndex;
readonly _PathMeasure _measure;
public Tangent getTangentForOffset(float distance) {
return _measure.getTangentForOffset(contourIndex, distance);
}
public Path extractPath(float start, float end, bool startWithMoveTo = true) {
return _measure.extractPath(contourIndex, start, end, startWithMoveTo);
}
public override string ToString() {
return $"{GetType()}: length: {length}, isClosed: {isClosed}, contourIndex: {contourIndex}";
}
}

return PathMeasure_length(contourIndex);
}
public unsafe Tangent getTangentForOffset(int contourIndex, float distance) {
D.assert(contourIndex <= currentContourIndex, () => $"Iterator must be advanced before index {contourIndex} can be used.");
float[] posTan = new float[5];
fixed (float* posTanPtr = posTan) {
PathMeasure_getPosTan(contourIndex, distance, posTanPtr);
}
if (posTan[0] == 0.0f) {
return null;
}
else {
return new Tangent(
new Offset(posTan[1], posTan[2]),
new Offset(posTan[3], posTan[4])
);
}
}
public Path extractPath(int contourIndex, float start, float end, bool startWithMoveTo = true) {
D.assert(contourIndex <= currentContourIndex,
() => $"Iterator must be advanced before index {contourIndex} can be used.");
IntPtr pathPtr = PathMeasure_getSegment(contourIndex, start, end, startWithMoveTo);
return new Path(pathPtr);
}
public bool isClosed(int contourIndex) {
D.assert(contourIndex <= currentContourIndex, () => $"Iterator must be advanced before index {contourIndex} can be used.");
return PathMeasure_isClosed(contourIndex);

[DllImport(NativeBindings.dllName)]
static extern float PathMeasure_length(int contourIndex);
[DllImport(NativeBindings.dllName)]
static extern unsafe void PathMeasure_getPosTan(int contourIndex, float distance, float* posTan);
[DllImport(NativeBindings.dllName)]
static extern IntPtr PathMeasure_getSegment(int contourIndex, float start, float end,
bool startWithMoveTo);
[DllImport(NativeBindings.dllName)]

1
engine/README.md


Update out/Debug/args.gn with the following content:
```
clang_win = "C:\Program Files\LLVM"
win_vc = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC"
cc = "clang"
cxx = "clang++"
is_debug = true

6
engine/src/lib/ui/painting/path.h


return fml::MakeRefCounted<CanvasPath>();
}
static fml::RefPtr<CanvasPath> CreateFrom(const SkPath& src) {
fml::RefPtr<CanvasPath> path = CanvasPath::CreateNew();
path->path_ = src;
return path;
}
int getFillType();
void setFillType(int fill_type);

52
engine/src/lib/ui/painting/path_measure.cc


return -1;
}
void CanvasPathMeasure::getPosTan(int contour_index, float distance, float* posTan) {
posTan[0] = 0;
if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
contour_index) >= measures_.size()) {
return;
}
SkPoint pos;
SkVector tan;
bool success = measures_[contour_index]->getPosTan(distance, &pos, &tan);
if (success) {
posTan[0] = 1; // dart code will check for this for success
posTan[1] = pos.x();
posTan[2] = pos.y();
posTan[3] = tan.x();
posTan[4] = tan.y();
}
}
fml::RefPtr<CanvasPath> CanvasPathMeasure::getSegment(int contour_index,
float start_d, float stop_d,
bool start_with_move_to) {
if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
contour_index) >= measures_.size()) {
return CanvasPath::CreateNew();
}
SkPath dst;
bool success = measures_[contour_index]->getSegment(start_d, stop_d, &dst,
start_with_move_to);
if (!success) {
return CanvasPath::CreateNew();
} else {
return CanvasPath::CreateFrom(dst);
}
}
bool CanvasPathMeasure::isClosed(int contour_index) {
if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
contour_index) < measures_.size()) {

UIWIDGETS_API(float) PathMeasure_length(PathMeasure* ptr, int contourIndex) {
return ptr->getLength(contourIndex);
}
UIWIDGETS_API(void)
PathMeasure_getPosTan(PathMeasure* ptr, int contour_index, float distance,
float* posTan) {
ptr->getPosTan(contour_index, distance, posTan);
}
UIWIDGETS_API(CanvasPath*)
PathMeasure_getSegment(PathMeasure* ptr, int contour_index, float start_d,
float stop_d,
bool start_with_move_to) {
const auto path = ptr->getSegment(contour_index, start_d, stop_d, start_with_move_to);
path->AddRef();
return path.get();
}
UIWIDGETS_API(bool) PathMeasure_isClosed(PathMeasure* ptr, int contourIndex) {

3
engine/src/lib/ui/painting/path_measure.h


void setPath(const CanvasPath* path, bool isClosed);
float getLength(int contour_index);
void getPosTan(int contour_index, float distance, float* posTan);
fml::RefPtr<CanvasPath> getSegment(int contour_index, float start_d,
float stop_d, bool start_with_move_to);
bool isClosed(int contour_index);
bool nextContour();

8
engine/src/shell/platform/unity/unity_surface_manager.cc


image_texture->Release();
GLint old_texture_binding_2d;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_texture_binding_2d);
FML_DCHECK(fbo_texture_ == 0);
glGenTextures(1, &fbo_texture_);
glBindTexture(GL_TEXTURE_2D, fbo_texture_);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, fbo_egl_image_);
glBindTexture(GL_TEXTURE_2D, old_texture_binding_2d);
GLint old_framebuffer_binding;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_framebuffer_binding);
FML_DCHECK(fbo_ == 0);
glGenFramebuffers(1, &fbo_);

FML_CHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) ==
GL_FRAMEBUFFER_COMPLETE);
glBindFramebuffer(GL_FRAMEBUFFER, old_framebuffer_binding);
return fbo_;
}

正在加载...
取消
保存