Skip to content

Commit 7381f67

Browse files
livecodefraserlivecodeali
authored andcommitted
Update libgraphics to account for Skia API changes
The biggest impact is the removal of custom blend modes in Skia. This forces us to drop support for legacy blend modes as we can no longer emulate them. On the plus side, only using the built-in Skia blend modes will result in faster blending. (cherry picked from commit 2ffc8ef)
1 parent c8d7bc6 commit 7381f67

22 files changed

Lines changed: 640 additions & 3250 deletions

config/android.gypi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
'objcopy': '<!(echo ${OBJCOPY:-objcopy})',
2828
'objdump': '<!(echo ${OBJDUMP:-objdump})',
2929
'strip': '<!(echo ${STRIP:-strip})',
30+
31+
'android_ndk_path%': '<(android_ndk_path)',
3032
},
3133

3234
'target_defaults':

docs/notes/feature-skia-update.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Update Skia (graphics library)
2+
3+
This major Skia update improves both rendering quality and performance.
4+
It also opens the door to substantial future improvements and feature
5+
additions. In order to allow this, support for certain legacy drawing
6+
features has had to be removed. In particular, legacy blend modes (also
7+
known as bitmap effects) are no longer supported. Similarly, the legacy
8+
'XY', 'SqrtXY', 'Diamond' and 'Spiral' gradient types are no longer
9+
supported.
10+

engine/engine.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
'product_prefix': '',
363363
'product_extension': '',
364364
'product_dir': '<(PRODUCT_DIR)', # Shared libraries are not placed in PRODUCT_DIR by default
365-
'type': 'shared_library',
365+
'type': 'loadable_module', # Shared library imples --whole-archive
366366

367367
'sources':
368368
[

engine/src/aclip.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ Boolean MCAudioClip::open_audio() //plays a sound immediately
652652
else
653653
return True;
654654
}
655-
#elif defined _LINUX
655+
#elif defined TARGET_PLATFORM_LINUX
656656
// TS-2007-11-20 : Stopping LINUX from playing any sound - for 2.9.0-DP-2
657657
// TS-2007-12-04 : Adding in support for ESD
658658
Boolean MCAudioClip::open_audio()
@@ -745,7 +745,7 @@ Boolean MCAudioClip::play()
745745
return False;
746746
}
747747
return True;
748-
#elif defined(_LINUX)
748+
#elif defined(TARGET_PLATFORM_LINUX)
749749
if (looping || curindex < size)
750750
{
751751
while (True)

engine/src/em-fontlist.cpp

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class MCFontnode : public MCDLlist
5454

5555

5656
// Forward declarations
57-
static MCSysFontHandle emscripten_get_font_by_name(MCNameRef p_name, uint16_t p_style);
58-
static MCSysFontHandle emscripten_get_font_from_file(MCStringRef p_file);
57+
static sk_sp<SkTypeface> emscripten_get_font_by_name(MCNameRef p_name, uint16_t p_style);
58+
static sk_sp<SkTypeface> emscripten_get_font_from_file(MCStringRef p_file);
5959

6060

6161
/* ================================================================
@@ -70,11 +70,11 @@ MCFontnode::MCFontnode(MCNameRef p_name,
7070
m_requested_style(p_style)
7171
{
7272
// Load the font as requested
73-
m_font_info.fid = emscripten_get_font_by_name(p_name, p_style);
73+
auto t_typeface = emscripten_get_font_by_name(p_name, p_style);
7474

7575
// Calculate the metrics for this typeface and size
7676
SkPaint t_paint;
77-
t_paint.setTypeface((SkTypeface*)m_font_info.fid);
77+
t_paint.setTypeface(t_typeface);
7878
t_paint.setTextSize(p_size);
7979

8080
SkPaint::FontMetrics t_metrics;
@@ -86,7 +86,7 @@ MCFontnode::MCFontnode(MCNameRef p_name,
8686
m_font_info.m_descent = t_metrics.fDescent;
8787
m_font_info.m_leading = t_metrics.fLeading;
8888
m_font_info.m_xheight = t_metrics.fXHeight;
89-
89+
m_font_info.fid = reinterpret_cast<MCSysFontHandle>(t_typeface.release());
9090
m_font_info.size = p_size;
9191
}
9292

@@ -253,45 +253,46 @@ MCFontlist::getfontstructinfo(MCNameRef & r_name,
253253
}
254254

255255

256-
MCSysFontHandle emscripten_get_font_by_name(MCNameRef p_name,
257-
uint16_t p_style)
256+
sk_sp<SkTypeface> emscripten_get_font_by_name(MCNameRef p_name,
257+
uint16_t p_style)
258258
{
259259
/* Decode style */
260260
bool t_italic = (0 != (p_style & FA_ITALIC));
261261
bool t_bold = (0x05 < (p_style & FA_WEIGHT));
262-
SkTypeface::Style t_style;
263-
if (t_italic && t_bold)
264-
{
265-
t_style = SkTypeface::kBoldItalic;
266-
}
267-
else if (t_italic)
268-
{
269-
t_style = SkTypeface::kItalic;
270-
}
271-
else if (t_bold)
272-
{
273-
t_style = SkTypeface::kBold;
274-
}
275-
else
276-
{
277-
t_style = SkTypeface::kNormal;
278-
}
279262

280-
MCAutoStringRefAsSysString t_sys_name;
263+
SkFontStyle::Weight t_weight;
264+
SkFontStyle::Width t_width;
265+
SkFontStyle::Slant t_slant;
266+
267+
if (t_bold)
268+
t_weight = SkFontStyle::kBold_Weight;
269+
else
270+
t_weight = SkFontStyle::kNormal_Weight;
271+
272+
t_width = SkFontStyle::kNormal_Width;
273+
274+
if (t_italic)
275+
t_slant = SkFontStyle::kItalic_Slant;
276+
else
277+
t_slant = SkFontStyle::kUpright_Slant;
278+
279+
SkFontStyle t_style(t_weight, t_width, t_slant);
280+
281+
MCAutoStringRefAsSysString t_sys_name;
281282
/* UNCHECKED */ t_sys_name.Lock(MCNameGetString(p_name));
282283

283-
MCSysFontHandle t_handle =
284-
MCSysFontHandle(SkTypeface::CreateFromName(*t_sys_name, t_style));
285-
MCAssert(nil != t_handle);
286-
return t_handle;
284+
sk_sp<SkTypeface> t_typeface = SkTypeface::MakeFromName(*t_sys_name, t_style);
285+
286+
return t_typeface;
287287
}
288288

289-
MCSysFontHandle emscripten_get_font_from_file(MCStringRef p_file)
289+
sk_sp<SkTypeface> emscripten_get_font_from_file(MCStringRef p_file)
290290
{
291291
MCAutoStringRefAsSysString t_sys_path;
292292
/* UNCHECKED */ t_sys_path.Lock(p_file);
293293

294-
MCSysFontHandle t_handle = (MCSysFontHandle)SkTypeface::CreateFromFile(*t_sys_path);
295-
MCAssert(t_handle != nil);
296-
return t_handle;
294+
sk_sp<SkTypeface> t_typeface = SkTypeface::MakeFromFile(*t_sys_path);
295+
MCAssert(t_typeface != nil);
296+
return t_typeface;
297297
}
298+

engine/src/graphicscontext.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ void MCGraphicsContext::setfunction(uint1 p_function)
404404
switch (p_function)
405405
{
406406
case GXblendClear:
407+
case GXclear:
407408
t_blend_mode = kMCGBlendModeClear;
408409
break;
409410
case GXblendSrcOver:
@@ -432,6 +433,7 @@ void MCGraphicsContext::setfunction(uint1 p_function)
432433
t_blend_mode = kMCGBlendModeDestinationAtop;
433434
break;
434435
case GXblendXor:
436+
case GXxor:
435437
t_blend_mode = kMCGBlendModeXor;
436438
break;
437439
case GXblendPlus:
@@ -469,11 +471,10 @@ void MCGraphicsContext::setfunction(uint1 p_function)
469471
break;
470472
case GXblendExclusion:
471473
t_blend_mode = kMCGBlendModeExclusion;
472-
break;
473-
474-
case GXclear:
475-
t_blend_mode = kMCGBlendModeLegacyClear;
476474
break;
475+
476+
// Legacy blend modes with no equivalent in Skia
477+
477478
case GXand:
478479
t_blend_mode = kMCGBlendModeLegacyAnd;
479480
break;
@@ -486,9 +487,6 @@ void MCGraphicsContext::setfunction(uint1 p_function)
486487
case GXnoop:
487488
t_blend_mode = kMCGBlendModeLegacyNoop;
488489
break;
489-
case GXxor:
490-
t_blend_mode = kMCGBlendModeLegacyXor;
491-
break;
492490
case GXor:
493491
t_blend_mode = kMCGBlendModeLegacyOr;
494492
break;

engine/src/linux.stubs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,11 @@ gobject libgobject-2.0.so.0
626626
g_free: (pointer) -> ()
627627
g_object_ref: (pointer) -> (pointer)
628628
g_object_unref: (pointer) -> ()
629-
g_type_class_peek: (integer) -> (pointer)
630-
g_type_class_ref: (integer) -> (pointer)
629+
g_type_class_peek: (pointer) -> (pointer)
630+
g_type_class_ref: (pointer) -> (pointer)
631631
g_type_class_unref: (pointer) -> ()
632-
g_type_check_instance_cast: (pointer, integer) -> (pointer)
633-
g_type_check_instance_is_a: (pointer, integer) -> (integer)
632+
g_type_check_instance_cast: (pointer, pointer) -> (pointer)
633+
g_type_check_instance_is_a: (pointer, pointer) -> (integer)
634634
g_type_init: () -> ()
635635
@ g_object_get
636636
g_object_get_valist: (pointer, pointer, pointer) -> ()
@@ -661,11 +661,3 @@ esd libesd.so.0
661661
esd_play_stream: (integer, integer, pointer, pointer) -> (integer)
662662
esd_open_sound: (pointer) -> (integer)
663663

664-
fontconfig libfontconfig.so.1
665-
FcInit: () -> (integer)
666-
FcInitLoadConfigAndFonts: () -> (pointer)
667-
FcConfigAppFontAddFile: (pointer, pointer) -> (integer)
668-
FcConfigAppFontClear: (pointer) -> ()
669-
FcConfigBuildFonts: (pointer) -> (integer)
670-
FcConfigSetCurrent: (pointer) -> (integer)
671-

engine/src/lnxdc.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
5656
static Boolean pserror;
5757
Bool debugtest = False;
5858

59-
extern "C" int initialise_weak_link_fontconfig(void);
60-
6159
////////////////////////////////////////////////////////////////////////////////
6260

6361
MCGFloat MCResGetSystemScale(void)
@@ -478,23 +476,6 @@ bool MCScreenDC::loadfont(MCStringRef p_path, bool p_globally, void*& r_loaded_f
478476
if (p_globally)
479477
return false;
480478

481-
// If it has already been determined that the weak link to the fontconfig library
482-
// cannot be resolved then just return false, as we cannot load a font otherwise.
483-
if (!s_can_use_fontconfig)
484-
return false;
485-
486-
// Try to resolve the weak link
487-
if (!s_fontconfig_resolved)
488-
{
489-
if (initialise_weak_link_fontconfig() == 0)
490-
{
491-
s_can_use_fontconfig = false;
492-
return false;
493-
}
494-
495-
s_fontconfig_resolved = true;
496-
}
497-
498479
if (!FcInit())
499480
return false;
500481

engine/src/mblandroidtypeface.cpp

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,56 @@ bool MCAndroidTypefaceCreateWithData(void *p_data, uint32_t p_length, MCAndroidT
2727
{
2828
bool t_success = true;
2929

30-
SkMemoryStream *t_stream;
31-
t_stream = nil;
30+
SkMemoryStream *t_stream = nil;
3231
if (t_success)
3332
{
3433
t_stream = new (nothrow) SkMemoryStream(p_data, p_length, false);
3534
t_success = t_stream != nil;
3635
}
3736

38-
SkTypeface *t_type_face;
39-
t_type_face = nil;
37+
sk_sp<SkTypeface> t_type_face;
4038
if (t_success)
4139
{
42-
t_type_face = SkTypeface::CreateFromStream(t_stream);
40+
t_type_face = SkTypeface::MakeFromStream(t_stream);
4341
t_success = t_type_face != nil;
4442
}
43+
44+
// SkTypeface::MakeFromStream takes ownership of the stream
45+
if (!t_success && t_stream != nil)
46+
delete t_stream;
4547

4648
if (t_success)
47-
r_typeface = (MCAndroidTypefaceRef)t_type_face;
48-
else
49-
{
50-
if (t_stream != nil)
51-
delete t_stream;
52-
}
49+
r_typeface = (MCAndroidTypefaceRef)(t_type_face.release());
5350

5451
return t_success;
5552
}
5653

5754
bool MCAndroidTypefaceCreateWithName(const char *p_name, bool p_bold, bool p_italic, MCAndroidTypefaceRef &r_typeface)
5855
{
59-
SkTypeface::Style t_style = SkTypeface::kNormal;
56+
SkFontStyle::Weight t_weight;
57+
SkFontStyle::Width t_width;
58+
SkFontStyle::Slant t_slant;
59+
6060
if (p_bold)
61-
{
62-
if (p_italic)
63-
t_style = SkTypeface::kBoldItalic;
64-
else
65-
t_style = SkTypeface::kBold;
66-
}
67-
else if (p_italic)
68-
t_style = SkTypeface::kItalic;
61+
t_weight = SkFontStyle::kBold_Weight;
62+
else
63+
t_weight = SkFontStyle::kNormal_Weight;
64+
65+
t_width = SkFontStyle::kNormal_Width;
66+
67+
if (p_italic)
68+
t_slant = SkFontStyle::kItalic_Slant;
69+
else
70+
t_slant = SkFontStyle::kUpright_Slant;
6971

70-
SkTypeface *t_typeface = nil;
71-
t_typeface = SkTypeface::CreateFromName(p_name, t_style);
72+
SkFontStyle t_style(t_weight, t_width, t_slant);
73+
74+
sk_sp<SkTypeface> t_typeface = SkTypeface::MakeFromName(p_name, t_style);
7275

7376
if (t_typeface == nil)
7477
return false;
7578

76-
r_typeface = (MCAndroidTypefaceRef)t_typeface;
79+
r_typeface = (MCAndroidTypefaceRef)(t_typeface.release());
7780
return true;
7881
}
7982

@@ -87,10 +90,12 @@ void MCAndroidTypefaceRelease(MCAndroidTypefaceRef p_typeface)
8790

8891
bool MCAndroidTypefaceGetMetrics(MCAndroidTypefaceRef p_typeface, uint32_t p_size, float &r_ascent, float &r_descent, float &r_leading, float &r_xheight)
8992
{
90-
bool t_success = true;
91-
93+
// Skia APIs expect typefaces to be passed as shared pointers
94+
sk_sp<SkTypeface> t_typeface((SkTypeface*)p_typeface);
95+
t_typeface->ref();
96+
9297
SkPaint t_paint;
93-
t_paint.setTypeface((SkTypeface*)p_typeface);
98+
t_paint.setTypeface(t_typeface);
9499
t_paint.setTextSize(p_size);
95100

96101
SkPaint::FontMetrics t_metrics;
@@ -108,8 +113,12 @@ bool MCAndroidTypefaceGetMetrics(MCAndroidTypefaceRef p_typeface, uint32_t p_siz
108113

109114
bool MCAndroidTypefaceMeasureText(MCAndroidTypefaceRef p_typeface, uint32_t p_size, const char *p_text, uint32_t p_text_length, bool p_utf16, float &r_length)
110115
{
111-
SkPaint t_paint;
112-
t_paint.setTypeface((SkTypeface*)p_typeface);
116+
// Skia APIs expect typefaces to be passed as shared pointers
117+
sk_sp<SkTypeface> t_typeface((SkTypeface*)p_typeface);
118+
t_typeface->ref();
119+
120+
SkPaint t_paint;
121+
t_paint.setTypeface(t_typeface);
113122
t_paint.setTextSize(p_size);
114123

115124
t_paint.setTextEncoding(p_utf16 ? SkPaint::kUTF16_TextEncoding : SkPaint::kUTF8_TextEncoding);

libgraphics/include/graphics.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ typedef struct __MCGRegion *MCGRegionRef;
4747

4848
typedef uint32_t MCGPixelFormat;
4949

50-
// IM_2013-08-21: [[ RefactorGraphics ]] set iOS pixel format to RGBA
51-
#if defined(ANDROID) || defined(TARGET_SUBPLATFORM_IPHONE) || defined(_LINUX) || defined(__EMSCRIPTEN__)
52-
#define kMCGPixelFormatNative kMCGPixelFormatRGBA
53-
// IM-2013-11-01: [[ Bug 11198 ]] Set PPC pixel format to ARGB
54-
#elif defined(__ppc__)
55-
#define kMCGPixelFormatNative kMCGPixelFormatARGB
50+
#if defined(ANDROID) || defined(TARGET_SUBPLATFORM_IPHONE) || defined(_LINUX) || defined(__EMSCRIPTEN__) || defined(__MAC__)
51+
# define kMCGPixelFormatNative kMCGPixelFormatRGBA
52+
#elif defined(WIN32)
53+
# define kMCGPixelFormatNative kMCGPixelFormatBGRA
5654
#else
57-
#define kMCGPixelFormatNative kMCGPixelFormatBGRA
55+
# error "Unknown pixel format for this platform"
5856
#endif
5957

6058
// IM-2013-11-01: [[ RefactorGraphics ]] Reverse component shift values on big-endian architectures

0 commit comments

Comments
 (0)