浏览代码

update free, equals

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
3ad69800
共有 19 个文件被更改,包括 653 次插入444 次删除
  1. 5
      Samples/UIWidgetsSamples_2019_4/Assets/TextTest.cs
  2. 18
      com.unity.uiwidgets/Runtime/ui/painting/shader.cs
  3. 78
      com.unity.uiwidgets/Runtime/ui2/painting.cs
  4. 781
      com.unity.uiwidgets/Runtime/ui2/text.cs
  5. 23
      engine/Build.bee.cs
  6. 12
      engine/README.md
  7. 6
      engine/src/lib/ui/text/font_collection.cc
  8. 13
      engine/src/lib/ui/text/paragraph_builder.cc
  9. 2
      engine/src/lib/ui/text/paragraph_builder.h
  10. 115
      engine/src/lib/ui/text/paragraph.cc
  11. 13
      engine/src/lib/ui/text/paragraph.h
  12. 1
      engine/src/render_api.h
  13. 2
      engine/src/runtime/runtime_delegate.h
  14. 2
      engine/src/shell/common/engine.cc
  15. 2
      engine/src/shell/common/engine.h
  16. 2
      engine/src/shell/common/shell.cc
  17. 9
      engine/src/shell/common/lists.cc
  18. 13
      engine/src/shell/common/lists.h
  19. 0
      /engine/src/lib/ui/text

5
Samples/UIWidgetsSamples_2019_4/Assets/TextTest.cs


using PictureRecorder = Unity.UIWidgets.ui2.PictureRecorder;
using Rect = Unity.UIWidgets.ui.Rect;
using SceneBuilder = Unity.UIWidgets.ui2.SceneBuilder;
using TextBaseline = Unity.UIWidgets.ui2.TextBaseline;
using TextDecoration = Unity.UIWidgets.ui2.TextDecoration;
using TextDecorationStyle = Unity.UIWidgets.ui2.TextDecorationStyle;
using TextPosition = Unity.UIWidgets.ui2.TextPosition;

pb.addText("test push one more style");
pb.pop();
pb.addText("test pop style");
pb.addPlaceholder(10, 10, PlaceholderAlignment.baseline, TextBaseline.alphabetic);
var p = pb.build();
p.layout(new ParagraphConstraints(300));
var wordBoundary = p.getWordBoundary(new TextPosition(10));

{
Debug.Log($"{textBox.bottom} {textBox.direction} {textBox.left} {textBox.right}");
}
foreach (var lineMetrics in p.computeLineMetrics())
{
Debug.Log($"{lineMetrics.height} {lineMetrics.lineNumber}");

18
com.unity.uiwidgets/Runtime/ui/painting/shader.cs


return true;
}
return _listEquals(colors, other.colors) &&
_listEquals(positions, other.positions);
return colors.equalsList(other.colors) &&
positions.equalsList(other.positions);
}
public override bool Equals(object obj) {

return hashCode;
}
}
static bool _listEquals<T>(List<T> left, List<T> right) {
if (left.Count != right.Count) {
return false;
}
for (int i = 0; i < left.Count; i++) {
if (!left[i].Equals(right[i])) {
return false;
}
}
return true;
}
}
}

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


}
}
internal static T[] range<T>(this T[] data, int index, int length)
{
T[] result = new T[length];
Array.Copy(data, index, result, 0, length);
return result;
}
internal static uint[] _encodeColorList(List<Color> colors) {
int colorCount = colors.Count;
var result = new uint[colorCount];

static extern IntPtr PictureRecorder_endRecording(IntPtr ptr);
}
public class Shadow {
public class Shadow : IEquatable<Shadow> {
public Shadow(
Color color,
Offset offset,

static readonly int _kYOffset = 2 << 2;
static readonly int _kBlurOffset = 3 << 2;
readonly Color color;
public readonly Color color;
readonly Offset offset;
public readonly Offset offset;
readonly float blurRadius;
public readonly float blurRadius;
static float convertRadiusToSigma(float radius) {
public static float convertRadiusToSigma(float radius) {
return radius * 0.57735f + 0.5f;
}

result.Add(b[i].scale(t));
return result;
}
public override bool Equals(object obj) {
if (ReferenceEquals(this, obj))
return true;
return obj is Shadow other
&& other.color == color
&& other.offset == offset
&& other.blurRadius == blurRadius;
}
public override int GetHashCode() {
int hashcode = color.GetHashCode();
hashcode = (hashcode ^ 397) ^ offset.GetHashCode();
hashcode = (hashcode ^ 397) ^ blurRadius.GetHashCode();
return hashcode;
}
public static byte[] _encodeShadows(List<Shadow> shadows) {
internal static byte[] _encodeShadows(List<Shadow> shadows) {
if (shadows == null)
return new byte[0];

}
public override string ToString() => $"TextShadow({color}, {offset}, {blurRadius})";
public bool Equals(Shadow other)
{
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return Equals(color, other.color) && Equals(offset, other.offset) && blurRadius.Equals(other.blurRadius);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != GetType()) {
return false;
}
return Equals((Shadow) obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (color != null ? color.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (offset != null ? offset.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ blurRadius.GetHashCode();
return hashCode;
}
}
}
delegate void _Callback<T>(T result);

781
com.unity.uiwidgets/Runtime/ui2/text.cs
文件差异内容过多而无法显示
查看文件

23
engine/Build.bee.cs


"src/lib/ui/compositing/scene_builder.cc",
"src/lib/ui/compositing/scene_builder.h",
"src/lib/ui/txt/icu_util.h",
"src/lib/ui/txt/icu_util.cc",
"src/lib/ui/txt/asset_manager_font_provider.cc",
"src/lib/ui/txt/asset_manager_font_provider.h",
"src/lib/ui/txt/paragraph_builder.cc",
"src/lib/ui/txt/paragraph_builder.h",
"src/lib/ui/txt/font_collection.cc",
"src/lib/ui/txt/font_collection.h",
"src/lib/ui/txt/paragraph.cc",
"src/lib/ui/txt/paragraph.h",
"src/lib/ui/text/icu_util.h",
"src/lib/ui/text/icu_util.cc",
"src/lib/ui/text/asset_manager_font_provider.cc",
"src/lib/ui/text/asset_manager_font_provider.h",
"src/lib/ui/text/paragraph_builder.cc",
"src/lib/ui/text/paragraph_builder.h",
"src/lib/ui/text/font_collection.cc",
"src/lib/ui/text/font_collection.h",
"src/lib/ui/text/paragraph.cc",
"src/lib/ui/text/paragraph.h",
"src/lib/ui/painting/canvas.cc",
"src/lib/ui/painting/canvas.h",

"src/shell/common/canvas_spy.h",
"src/shell/common/engine.cc",
"src/shell/common/engine.h",
"src/shell/common/lists.h",
"src/shell/common/lists.cc",
"src/shell/common/persistent_cache.cc",
"src/shell/common/persistent_cache.h",
"src/shell/common/pipeline.cc",

12
engine/README.md


python ./flutter/tools/gn --unoptimized
ninja -C .\out\host_debug_unopt\ flutter/fml:fml_lib
```
powershell 
```
$env:GYP_MSVS_OVERRIDE_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"
$env:FLUTTER_ROOT="E:\c\src" # target to flutter
$env:SKIA_ROOT="C:\Users\siyao\skia_repo\skia\" # target to skia
```
## Create symbolic

cd third_party   \\ create the directory if not exists
mklink /D skia <SKIA_ROOT>
```
powershell (run as administrator)
```
cd <uiwidigets_dir>\engine
cd third_party   # create the directory if not exists
New-Item -Path skia -ItemType SymbolicLink -Value C:\Users\siyao\skia_repo\skia\ 
```
Flutter engine txt include skia header in this pattern 'third_party/skia/*', so without symbolic, the txt lib will include skia
header file in flutter engine, instead of headers in skia repo.

6
engine/src/lib/ui/text/font_collection.cc


#include "include/core/SkGraphics.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypeface.h"
#include "lib/ui/txt/asset_manager_font_provider.h"
#include "asset_manager_font_provider.h"
#include "lib/ui/ui_mono_state.h"
#include "lib/ui/window/window.h"
#include "rapidjson/document.h"

typedef void (*LoadFontCallback)(Mono_Handle callback_handle);
UIWIDGETS_API(void)
LoadFontFromList(uint8_t* font_data, int size,
Font_LoadFontFromList(uint8_t* font_data, int size,
LoadFontCallback loadFontCallback, Mono_Handle callbackHandle,
char* family_name) {
FontCollection& font_collection =

font_asset->value.GetString());
}
}
collection_->SetAssetFontManager(
sk_make_sp<txt::AssetFontManager>(std::move(font_provider)));
}

13
engine/src/lib/ui/text/paragraph_builder.cc


#pragma once
#include "paragraph_builder.h"
#include "lib/ui/ui_mono_state.h"

FontCollection& font_collection =
UIMonoState::Current()->window()->client()->GetFontCollection();
#if FLUTTER_ENABLE_SKSHAPER
#define FLUTTER_PARAGRAPH_BUILDER txt::ParagraphBuilder::CreateSkiaBuilder
#else
#define FLUTTER_PARAGRAPH_BUILDER txt::ParagraphBuilder::CreateTxtBuilder
#endif
m_paragraphBuilder =
FLUTTER_PARAGRAPH_BUILDER(style, font_collection.GetFontCollection());
m_paragraphBuilder = txt::ParagraphBuilder::CreateTxtBuilder(
style, font_collection.GetFontCollection());
}
ParagraphBuilder::~ParagraphBuilder() = default;

}
UIWIDGETS_API(Paragraph*)
ParagraphBuilder_build(ParagraphBuilder* ptr /*, IntPtr outParagraph*/) {
ParagraphBuilder_build(ParagraphBuilder* ptr) {
auto paragraph = ptr->build();
paragraph->AddRef();
return paragraph.get();

2
engine/src/lib/ui/text/paragraph_builder.h


#include "flutter/fml/memory/ref_counted.h"
#include "flutter/third_party/txt/src/txt/paragraph.h"
#include "flutter/third_party/txt/src/txt/paragraph_builder.h"
#include "lib/ui/txt/font_collection.h"
#include "font_collection.h"
#include "paragraph.h"
#include "src/lib/ui/painting/canvas.h"

115
engine/src/lib/ui/text/paragraph.cc


#pragma once
#include "flutter/third_party/txt/src/txt/paragraph.h"
#include "lib/ui/ui_mono_state.h"
namespace uiwidgets {
Paragraph::Paragraph(std::unique_ptr<txt::Paragraph> paragraph)

m_paragraph->Paint(sk_canvas, x, y);
}
static Float32List EncodeTextBoxes(
const std::vector<txt::Paragraph::TextBox>& boxes) {
// Layout:
// First value is the number of values.
// Then there are boxes.size() groups of 5 which are LTRBD, where D is the
// text direction index.
Float32List result = {new float[boxes.size() * 5], boxes.size() * 5};
unsigned long position = 0;
for (unsigned long i = 0; i < boxes.size(); i++) {
const txt::Paragraph::TextBox& box = boxes[i];
result.data[position++] = box.rect.fLeft;
result.data[position++] = box.rect.fTop;
result.data[position++] = box.rect.fRight;
result.data[position++] = box.rect.fBottom;
result.data[position++] = static_cast<float>(box.direction);
}
return result;
}
static void EncodeTextBoxes(const std::vector<txt::Paragraph::TextBox>& boxes,
float* result) {
// Layout:

}
}
int Paragraph::getRectsForRangeSize(unsigned start, unsigned end,
unsigned boxHeightStyle,
unsigned boxWidthStyle) {
std::vector<txt::Paragraph::TextBox> boxes = m_paragraph->GetRectsForRange(
start, end, static_cast<txt::Paragraph::RectHeightStyle>(boxHeightStyle),
static_cast<txt::Paragraph::RectWidthStyle>(boxWidthStyle));
return boxes.size() * 5;
}
void Paragraph::getRectsForRange(float* data, unsigned start, unsigned end,
unsigned boxHeightStyle,
unsigned boxWidthStyle) {
Float32List* Paragraph::getRectsForRange(unsigned start, unsigned end,
unsigned boxHeightStyle,
unsigned boxWidthStyle) {
EncodeTextBoxes(boxes, data);
return &EncodeTextBoxes(boxes);
int Paragraph::getRectsForPlaceholdersSize() {
Float32List* Paragraph::getRectsForPlaceholders() {
return boxes.size() * 5;
}
void Paragraph::getRectsForPlaceholders(float* data) {
std::vector<txt::Paragraph::TextBox> boxes =
m_paragraph->GetRectsForPlaceholders();
return EncodeTextBoxes(boxes, data);
return &EncodeTextBoxes(boxes);
}
void Paragraph::getPositionForOffset(float dx, float dy, int* offset) {

boundaryPtr[1] = line_end;
}
int Paragraph::computeLineMetricsSize() {
Float32List* Paragraph::computeLineMetrics() {
return metrics.size() * 9;
}
void Paragraph::computeLineMetrics(float* result) {
std::vector<txt::LineMetrics> metrics = m_paragraph->GetLineMetrics();
// Layout:
// boxes.size() groups of 9 which are the line metrics
// properties
int size = metrics.size() * 9;
Float32List result = {new float[size], size};
result[position++] = static_cast<float>(line.hard_break);
result[position++] = line.ascent;
result[position++] = line.descent;
result[position++] = line.unscaled_ascent;
result.data[position++] = static_cast<float>(line.hard_break);
result.data[position++] = line.ascent;
result.data[position++] = line.descent;
result.data[position++] = line.unscaled_ascent;
result[position++] = round(line.ascent + line.descent);
result[position++] = line.width;
result[position++] = line.left;
result[position++] = line.baseline;
result[position++] = static_cast<float>(line.line_number);
result.data[position++] = round(line.ascent + line.descent);
result.data[position++] = line.width;
result.data[position++] = line.left;
result.data[position++] = line.baseline;
result.data[position++] = static_cast<float>(line.line_number);
return &result;
}
UIWIDGETS_API(float) Paragraph_width(Paragraph* ptr) { return ptr->width(); }

ptr->layout(width);
}
UIWIDGETS_API(int)
Paragraph_getRectsForRangeSize(Paragraph* ptr, int start, int end,
int boxHeightStyle, int boxWidthStyle) {
return ptr->getRectsForRangeSize(start, end, boxHeightStyle, boxWidthStyle);
}
UIWIDGETS_API(void)
Paragraph_getRectsForRange(Paragraph* ptr, float* data, int start, int end,
UIWIDGETS_API(Float32List*)
Paragraph_getRectsForRange(Paragraph* ptr, int start, int end,
ptr->getRectsForRange(data, start, end, boxHeightStyle, boxWidthStyle);
return ptr->getRectsForRange(start, end, boxHeightStyle, boxWidthStyle);
UIWIDGETS_API(int)
Paragraph_getRectsForPlaceholdersSize(Paragraph* ptr) {
return ptr->getRectsForPlaceholdersSize();
}
UIWIDGETS_API(void)
Paragraph_getRectsForPlaceholders(Paragraph* ptr, float* data) {
ptr->getRectsForPlaceholders(data);
UIWIDGETS_API(Float32List*)
Paragraph_getRectsForPlaceholders(Paragraph* ptr) {
return ptr->getRectsForPlaceholders();
}
UIWIDGETS_API(void)

ptr->paint(canvas, x, y);
}
UIWIDGETS_API(int) Paragraph_computeLineMetricsSize(Paragraph* ptr) {
return ptr->computeLineMetricsSize();
}
UIWIDGETS_API(void) Paragraph_computeLineMetrics(Paragraph* ptr, float* data) {
ptr->computeLineMetrics(data);
UIWIDGETS_API(Float32List*)
Paragraph_computeLineMetrics(Paragraph* ptr, float* data) {
return ptr->computeLineMetrics();
}
UIWIDGETS_API(void) Paragraph_dispose(Paragraph* ptr) { ptr->Release(); }

13
engine/src/lib/ui/text/paragraph.h


#include "flutter/fml/memory/ref_counted.h"
#include "flutter/third_party/txt/src/txt/paragraph.h"
#include "shell/common/lists.h"
#include "lib/ui/ui_mono_state.h"
namespace uiwidgets {

void layout(float width);
void paint(Canvas* canvas, float x, float y);
int getRectsForRangeSize(unsigned start, unsigned end,
unsigned boxHeightStyle, unsigned boxWidthStyle);
void getRectsForRange(float* data, unsigned start, unsigned end,
Float32List* getRectsForRange(unsigned start, unsigned end,
int getRectsForPlaceholdersSize();
void getRectsForPlaceholders(float* data);
Float32List* getRectsForPlaceholders();
int computeLineMetricsSize();
void computeLineMetrics(float* data);
Float32List* computeLineMetrics();
size_t GetAllocationSize();
std::unique_ptr<txt::Paragraph> m_paragraph;

1
engine/src/render_api.h


#pragma once
#include "Unity/IUnityGraphics.h"
#include "src/lib/ui/txt/paragraph.h"
class RenderAPI {
public:
virtual ~RenderAPI() {}

2
engine/src/runtime/runtime_delegate.h


#include <vector>
#include "flow/layers/layer_tree.h"
#include "lib/ui/txt/font_collection.h"
#include "lib/ui/text/font_collection.h"
#include "lib/ui/window/platform_message.h"

2
engine/src/shell/common/engine.cc


#include "flutter/fml/paths.h"
#include "flutter/fml/trace_event.h"
#include "flutter/fml/unique_fd.h"
#include "lib/ui/txt/font_collection.h"
#include "lib/ui/text/font_collection.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPictureRecorder.h"
#include "rapidjson/document.h"

2
engine/src/shell/common/engine.h


#include "flutter/fml/memory/weak_ptr.h"
#include "lib/ui/painting/image_decoder.h"
#include "lib/ui/snapshot_delegate.h"
#include "lib/ui/txt/font_collection.h"
#include "lib/ui/text/font_collection.h"
#include <flutter/fml/concurrent_message_loop.h>
#include "include/core/SkPicture.h"

2
engine/src/shell/common/shell.cc


#include "flutter/fml/unique_fd.h"
#include "include/core/SkGraphics.h"
#include "include/utils/SkBase64.h"
#include "lib/ui/txt/icu_util.h"
#include "lib/ui/text/icu_util.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include "runtime/start_up.h"

9
engine/src/shell/common/lists.cc


#pragma once
#include "lists.h"
namespace uiwidgets {
namespace {
UIWIDGETS_API(void) Lists_Free(void* data) { delete []data; } // namespace
} // namespace
} // namespace uiwidgets

13
engine/src/shell/common/lists.h


#pragma once
#include "runtime/mono_api.h"
namespace uiwidgets {
#define DATALIST(T, N) \
extern "C" struct N { \
T* data; \
int length; \
};
DATALIST(float, Float32List)
DATALIST(int, Int32List)
DATALIST(char, CharList)
} // namespace uiwidgets

/engine/src/lib/ui/txt → /engine/src/lib/ui/text

正在加载...
取消
保存