Skip to content

Commit

Permalink
Merge pull request #196 from HinTak/m116-public
Browse files Browse the repository at this point in the history
M116 public
  • Loading branch information
kyamagu authored Aug 8, 2023
2 parents 5d92743 + 5959274 commit f71fdee
Show file tree
Hide file tree
Showing 58 changed files with 1,307 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
skia
key: linux-aarch64-skia-${{ github.sha }}
- name: Pre-fetch skia deps
run: git config --global core.compression 0 && cd skia && python tools/git-sync-deps
run: git config --global core.compression 0 && cd skia && patch -p1 -i ../patch/skia-m116-minimize-download.patch && python tools/git-sync-deps && patch -p1 -R -i ../patch/skia-m116-minimize-download.patch
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Build skia
Expand Down
81 changes: 81 additions & 0 deletions README.m116.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
This is a partial port of [skia-python](https://github.com/kyamagu/skia-python/)
from `m87` to `m116`, possibly disabling any `m87` APIs that have no close `m116` equivalents.

It concentrates on OT-SVG, and fixing these two issues:

* [SkSVGDOM::renderNode() is not exposed in python](https://github.com/kyamagu/skia-python/issues/192)
* [three-args contructor to SkMemoryStream not exposed.](https://github.com/kyamagu/skia-python/issues/194)

The SVG module left experimental in `m88` upstream. It has received many improvements since.

Some COLRv1-related Skia internals from upstream's on-going effort in this area
are also exposed for access. This experimental functionality is available to
Linux/FreeType users only.

Special mention of [0lru](https://github.com/0lru) who provided a
[draft m98 pull](https://github.com/kyamagu/skia-python/pull/181) for which some ideas
of this update had taken from.

# General overview of changes between `m87` and `m116`

* TL;DR - `m87` users would likely find most existing python scripts work. Some
routines need a new `skia.SamplingOptions()` argument, or
switch from `skia.FilterQuality` to `skia.SamplingOptions()`.
Please report `AttributeError: 'skia.AAA' object has no attribute 'BBB'` errors,
to prioritize fixing remaining differences between `m87` and `m116`.

* The number of public symbols/routines in upstream skia is around 2400,
consistently between `m87` and `m116` (`m88`, `m98`, `m103` were examined).
skia-python `m87` accesses just over ~1000 at link time, and possibly
another 100 or two via `dynamic_cast`'ing at runtime. Less than ~800
of them has exact equivalents in `m116`. A good proportion of
the 200+ differ by additional arguments, often with defaults
(e.g. `skia.SamplingOptions()`). A few with not-useful arguments have them removed.
Some of the rest, like the Image I/O routines and Surface routines,
are considered too often used and too important, and are emulated in m116. The rest ... read on:

* Be **WARN**'ed: some `m87` APIs (about 5% in total, many in the `ImageFilter` namespace)
are removed/disabled when there are no obvious new-equivalents, or not-too-troblesome
emulations with `m116`. The "AttributeError" error mentioned above.

* Where it is possible, when `m87` APIs disappear, emulations with `m116`
is done. So these are "new emulations of old APIs". While they work,
they might be withdrawn/changed later:

Image I/O and decoding routines -
`encodeToData`, `MakeRasterCopy`,
`MakeFromRaster`, `MakeFromBitmap`, `MakeFromEncoded`,
`MakeTextureFromCompressed`, `MakeRasterFromCompressed`,
`MakeFromTexture`, `MakeFromCompressedTexture`,
`MakeCrossContextFromPixmap`, `MakeFromAdoptedTexture`,
`MakeFromYUVATexturesCopy`, `MakeFromYUVATexturesCopyWithExternalBackend`,
`MakeFromYUVATextures`, `MakeFromYUVAPixmaps`, `MakeFromYUVAPixmaps`,
`MakeFromPicture`, `MakeBackendTextureFromSkImage`,
`MakeBackendTextureFromSkImage`
- these are emulated in `m116`. In particular, upstream recommends
using the graphic format encoding/decoding routines directly. Not yet directly exposed in `skia-python`.

Surface methods -
`Surface.MakeRasterN32Premul`, `Surface.MakeRasterDirect`,
`Surface.getBackendTexture`, `Surface.getBackendRenderTarget`,
`Surface.MakeRaster`, `Surface.MakeFromBackendTexture`,
`Surface.MakeFromBackendRenderTarget`, `Surface::MakeRenderTarget`,
`Surface.MakeNull`.
- these are simple renamings; we might add the new names and remove
the old names, and document them as renamed.

* Most `GrContext` class methods were merged into `GrDirectContext` class
methods. For now, we have an alias between those two classes, and
internally, use `GrContext` as it is shorter. In the long term,
people should use `GrDirectContext`, to align with upstream documentation.

* New `SamplingOptions` class; there is only a default constructor for now.
Many APIs changes from `m87` to `m116` concern adding new options with it, or
changing from `FilterQuality` enum to `SamplingOptions`. If you use any
value other than the default `FilterQuality.kMedium_SkFilterQuality`
enum, you'll need to request addition to the `SamplingOptions` class.

* `yuvainfo.PlanarConfig` enums were splitted into a combination of
`yuvainfo.PlaneConfig` and `yuvainfo.Subsampling` enums. Where the former
enum was used in `m87`, it is the equivalent of a combination of the latter
two in `m116`.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ https://kyamagu.github.io/skia-python
- [Tutorial](https://kyamagu.github.io/skia-python/tutorial/)
- [Reference](https://kyamagu.github.io/skia-python/reference.html)

- For information about the `m87` to `m116` changes, and tips on migration: [README.m116](README.m116.md).

## Contributing

Feel free to [post an issue](https://github.com/kyamagu/skia-python/issues) or [PR](https://github.com/kyamagu/skia-python/pulls).
22 changes: 22 additions & 0 deletions patch/gn-newer-gcc-warnings-as-errors.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/src/gn/desc_builder.cc b/src/gn/desc_builder.cc
index 444a5e02..3ef170c3 100644
--- a/src/gn/desc_builder.cc
+++ b/src/gn/desc_builder.cc
@@ -167,7 +167,7 @@ class BaseDescBuilder {
base::ListValue res;
for (const auto& v : vector)
res.GetList().emplace_back(ToBaseValue(v));
- return std::move(res);
+ return res;
}

base::Value ToBaseValue(const Scope* scope) {
@@ -176,7 +176,7 @@ class BaseDescBuilder {
scope->GetCurrentScopeValues(&map);
for (const auto& v : map)
res.SetKey(v.first, ToBaseValue(v.second));
- return std::move(res);
+ return res;
}

base::Value ToBaseValue(const Value& val) {
197 changes: 197 additions & 0 deletions patch/skia-m116-colrv1-freetype.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index eae8c84..8388891 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -24,6 +24,8 @@
#include "src/sfnt/SkOTTable_OS_2.h"

#ifdef SK_TYPEFACE_FACTORY_FREETYPE
+enum class FT_Color_Root_Transform_;
+typedef FT_Color_Root_Transform_ FT_Color_Root_Transform; /* freetype/ftcolor.h */
#include "src/ports/SkFontHost_FreeType_common.h"
#endif

diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h
index 7955049..8551cf7 100644
--- a/src/ports/SkFontConfigTypeface.h
+++ b/src/ports/SkFontConfigTypeface.h
@@ -12,6 +12,8 @@
#include "include/core/SkStream.h"
#include "include/ports/SkFontConfigInterface.h"
#include "src/core/SkFontDescriptor.h"
+enum class FT_Color_Root_Transform_;
+typedef FT_Color_Root_Transform_ FT_Color_Root_Transform; /* freetype/ftcolor.h */
#include "src/ports/SkFontHost_FreeType_common.h"

class SkFontDescriptor;
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index f46bf19..def997a 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -31,7 +31,6 @@
#include "src/core/SkMask.h"
#include "src/core/SkMaskGamma.h"
#include "src/core/SkScalerContext.h"
-#include "src/ports/SkFontHost_FreeType_common.h"
#include "src/sfnt/SkOTUtils.h"
#include "src/sfnt/SkSFNTHeader.h"
#include "src/sfnt/SkTTCFHeader.h"
@@ -49,6 +48,7 @@
#ifdef FT_COLOR_H // 2.10.0
# include <freetype/ftcolor.h>
#endif
+#include "src/ports/SkFontHost_FreeType_common.h"
#include <freetype/freetype.h>
#include <freetype/ftlcdfil.h>
#include <freetype/ftmodapi.h>
diff --git a/src/ports/SkFontHost_FreeType_common.cpp b/src/ports/SkFontHost_FreeType_common.cpp
index 355ee02..22cd6af 100644
--- a/src/ports/SkFontHost_FreeType_common.cpp
+++ b/src/ports/SkFontHost_FreeType_common.cpp
@@ -6,7 +6,6 @@
* found in the LICENSE file.
*/

-#include "src/ports/SkFontHost_FreeType_common.h"

#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
@@ -32,6 +31,7 @@
#ifdef FT_COLOR_H
# include <freetype/ftcolor.h>
#endif
+#include "src/ports/SkFontHost_FreeType_common.h"
#include <freetype/ftimage.h>
#include <freetype/ftoutln.h>
#include <freetype/ftsizes.h>
@@ -1558,6 +1558,41 @@ bool SkScalerContext_FreeType_Base::drawCOLRv1Glyph(FT_Face face,
SkASSERTF(haveLayers, "Could not get COLRv1 layers from '%s'.", face->family_name);
return haveLayers;
}
+/*
+ * This content is mostly just
+ * SkTypeface_FreeType::FaceRec::setupPalette()
+ + + SkScalerContext_FreeType_Base::drawCOLRv1Glyph()
+ +*/
+bool SkScalerContext_FreeType_Base::skia_colrv1_start_glyph(SkCanvas* canvas,
+ FT_Face face,
+ uint16_t glyphId,
+ FT_UShort palette_index,
+ FT_Color_Root_Transform rootTransform
+ ) {
+ uint32_t fForegroundColor{SK_ColorBLACK};
+ FT_Palette_Data paletteData;
+ FT_Palette_Data_Get(face, &paletteData);
+
+ FT_Color* ftPalette = nullptr;
+ FT_Palette_Select(face, palette_index, &ftPalette);
+ std::unique_ptr<SkColor[]> ptr_palette(new SkColor[paletteData.num_palette_entries]);
+ for (int i = 0; i < paletteData.num_palette_entries; ++i) {
+ ptr_palette[i] = SkColorSetARGB(ftPalette[i].alpha,
+ ftPalette[i].red,
+ ftPalette[i].green,
+ ftPalette[i].blue);
+ }
+ SkSpan<SkColor> palette(ptr_palette.get(), paletteData.num_palette_entries);
+
+ VisitedSet activePaints;
+ bool haveLayers = colrv1_start_glyph(canvas, palette,
+ fForegroundColor, // FT_Palette_Get_Foreground_Color?
+ face, glyphId,
+ FT_COLOR_INCLUDE_ROOT_TRANSFORM,
+ &activePaints);
+ SkASSERTF(haveLayers, "Could not get COLRv1 layers from '%s'.", face->family_name);
+ return haveLayers;
+}
#endif // TT_SUPPORT_COLRV1

#ifdef FT_COLOR_H
diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h
index 1d3a8f8..820106a 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -29,6 +29,7 @@ typedef struct FT_FaceRec_* FT_Face;
typedef struct FT_StreamRec_* FT_Stream;
typedef signed long FT_Pos;
typedef struct FT_BBox_ FT_BBox;
+typedef unsigned short FT_UShort; /* freetype/fttypes.h */


#ifdef SK_DEBUG
@@ -41,7 +42,15 @@ const char* SkTraceFtrGetError(int);
#endif


-class SkScalerContext_FreeType_Base : public SkScalerContext {
+class SK_SPI SkScalerContext_FreeType_Base : public SkScalerContext {
+public:
+ static bool computeColrV1GlyphBoundingBox(FT_Face, SkGlyphID, SkRect* bounds);
+ static bool skia_colrv1_start_glyph(SkCanvas* canvas,
+ FT_Face face,
+ uint16_t glyphId,
+ FT_UShort palette_index,
+ FT_Color_Root_Transform rootTransform
+ );
protected:
// See http://freetype.sourceforge.net/freetype2/docs/reference/ft2-bitmap_handling.html#FT_Bitmap_Embolden
// This value was chosen by eyeballing the result in Firefox and trying to match it.
@@ -68,7 +77,6 @@ protected:
* configure size, matrix and load glyphs as needed after using this function to restore the
* state of FT_Face.
*/
- static bool computeColrV1GlyphBoundingBox(FT_Face, SkGlyphID, SkRect* bounds);

struct ScalerContextBits {
static const constexpr uint32_t COLRv0 = 1;
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 25cc9f9..d9af46b 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -23,6 +23,8 @@
#include "src/core/SkFontDescriptor.h"
#include "src/core/SkOSFile.h"
#include "src/core/SkTypefaceCache.h"
+enum class FT_Color_Root_Transform_;
+typedef FT_Color_Root_Transform_ FT_Color_Root_Transform; /* freetype/ftcolor.h */
#include "src/ports/SkFontHost_FreeType_common.h"
#include "src/ports/SkFontMgr_android_parser.h"

diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index cfa39ef..9d61da9 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -16,6 +16,8 @@
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTemplates.h"
#include "src/core/SkFontDescriptor.h"
+enum class FT_Color_Root_Transform_;
+typedef FT_Color_Root_Transform_ FT_Color_Root_Transform; /* freetype/ftcolor.h */
#include "src/ports/SkFontHost_FreeType_common.h"
#include "src/ports/SkFontMgr_custom.h"

diff --git a/src/ports/SkFontMgr_custom.h b/src/ports/SkFontMgr_custom.h
index 1e78f0b..8a22c02 100644
--- a/src/ports/SkFontMgr_custom.h
+++ b/src/ports/SkFontMgr_custom.h
@@ -14,6 +14,8 @@
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkTArray.h"
+enum class FT_Color_Root_Transform_;
+typedef FT_Color_Root_Transform_ FT_Color_Root_Transform; /* freetype/ftcolor.h */
#include "src/ports/SkFontHost_FreeType_common.h"

class SkData;
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 8022ac2..bee83e8 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -22,6 +22,8 @@
#include "src/core/SkFontDescriptor.h"
#include "src/core/SkOSFile.h"
#include "src/core/SkTypefaceCache.h"
+enum class FT_Color_Root_Transform_;
+typedef FT_Color_Root_Transform_ FT_Color_Root_Transform; /* freetype/ftcolor.h */
#include "src/ports/SkFontHost_FreeType_common.h"

#include <fontconfig/fontconfig.h>
Loading

0 comments on commit f71fdee

Please sign in to comment.