From 56e8c972569392270d7a380e42068cb37a881b59 Mon Sep 17 00:00:00 2001 From: NatalyaKovalova Date: Tue, 17 Oct 2017 18:50:22 +0300 Subject: [PATCH 1/8] iOS support: shCGUtils has been moved to "include/utils" because of calling from iOS --- include/utils/{mac => }/SkCGUtils.h | 1 + 1 file changed, 1 insertion(+) rename include/utils/{mac => }/SkCGUtils.h (98%) diff --git a/include/utils/mac/SkCGUtils.h b/include/utils/SkCGUtils.h similarity index 98% rename from include/utils/mac/SkCGUtils.h rename to include/utils/SkCGUtils.h index a0fe666d2c..7f83da8d83 100644 --- a/include/utils/mac/SkCGUtils.h +++ b/include/utils/SkCGUtils.h @@ -17,6 +17,7 @@ #ifdef SK_BUILD_FOR_IOS #include +#include #endif class SkBitmap; From b6e6938fcf6c743785f417757119e9cd7ecb696a Mon Sep 17 00:00:00 2001 From: NatalyaKovalova Date: Tue, 17 Oct 2017 18:56:15 +0300 Subject: [PATCH 2/8] iOS support: CMakeLists changed --- CMakeLists.txt | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a040adc554..5c0f3fb737 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -541,8 +541,43 @@ set_prefix(SKIA_THIRDPARTY_SRC third_party/ etc1/etc1.cpp ktx/ktx.cpp ) +if($ENV{TARGET} MATCHES ".*apple-ios") + add_definitions(-DSK_USE_POSIX_THREADS) + include_directories(include/utils/iOS) + include_directories(src/utils/iOS) + + set_prefix(SKIA_GL_PLATFORM_SRC src/gpu/gl/iOS/ + GrGLCreateNativeInterface_iOS.cpp + SkNativeGLContext_iOS.mm + ) + + set_prefix(SKIA_PORTS_SRC src/ports/ + SkDebug_stdio.cpp + SkFontHost_mac.cpp + SkGlobalInitialization_default.cpp + SkImageDecoder_empty.cpp + SkMemory_malloc.cpp + SkOSFile_posix.cpp + SkOSFile_stdio.cpp + SkTLS_pthread.cpp + ) -if(APPLE) + set(SKIA_FONTS_SRC "") + + set_prefix(SKIA_UTILS_PLATFORM_SRC src/utils/iOS/ + SkImageDecoder_iOS.mm + SkStream_NSData.mm + ) + set_prefix( SKIA_IOS_STUB_SRC src/opts/ + SkMorphology_opts_none.cpp + SkBitmapProcState_opts_none.cpp + SkBlitMask_opts_none.cpp + SkBlitRow_opts_none.cpp + SkBlurImage_opts_none.cpp + SkUtils_opts_none.cpp + SkXfermode_opts_none.cpp + ) +elseif(APPLE) add_definitions(-DSK_USE_POSIX_THREADS) include_directories(include/utils/mac) include_directories(src/utils/mac) @@ -711,7 +746,9 @@ set(SKIA_SRC ${SKIA_UTILS_PLATFORM_SRC} ) -if($ENV{TARGET} MATCHES "(i686|x86_64)-.*") +if($ENV{TARGET} MATCHES ".*apple-ios") + set(SKIA_SRC ${SKIA_SRC} ${SKIA_IOS_STUB_SRC}) +elseif($ENV{TARGET} MATCHES "(i686|x86_64)-.*") set(SKIA_SRC ${SKIA_SRC} ${SKIA_OPTS_SSE2_SRC}) set(SKIA_SRC ${SKIA_SRC} ${SKIA_OPTS_SSSE3_SRC}) if(NOT MSVC) From 3f727167d8edf025d17c8541483cfc9bf200363e Mon Sep 17 00:00:00 2001 From: NatalyaKovalova Date: Tue, 17 Oct 2017 19:23:30 +0300 Subject: [PATCH 3/8] iOS support: stubs for rust part --- src/gl_context.rs | 5 ++++ src/gl_context_ios.rs | 38 +++++++++++++++++++++++++++ src/gl_rasterization_context_ios.rs | 40 +++++++++++++++++++++++++++++ src/lib.rs | 5 ++++ 4 files changed, 88 insertions(+) create mode 100644 src/gl_context_ios.rs create mode 100644 src/gl_rasterization_context_ios.rs diff --git a/src/gl_context.rs b/src/gl_context.rs index 792c26b5ff..349aab7904 100644 --- a/src/gl_context.rs +++ b/src/gl_context.rs @@ -18,6 +18,11 @@ pub use gl_context_cgl::GLPlatformContext; #[cfg(target_os="macos")] pub use gl_context_cgl::PlatformDisplayData; +#[cfg(target_os="ios")] +pub use gl_context_ios::GLPlatformContext; +#[cfg(target_os="ios")] +pub use gl_context_ios::PlatformDisplayData; + #[cfg(target_os="linux")] pub use gl_context_glx::GLPlatformContext; #[cfg(target_os="linux")] diff --git a/src/gl_context_ios.rs b/src/gl_context_ios.rs new file mode 100644 index 0000000000..45f30fba13 --- /dev/null +++ b/src/gl_context_ios.rs @@ -0,0 +1,38 @@ +/* + * Copyright 2015 The Servo Project Developers + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +use euclid::Size2D; +use gleam::gl; +use std::rc::Rc; + +pub struct PlatformDisplayData { +} + +pub struct GLPlatformContext { +} + +impl Drop for GLPlatformContext { + fn drop(&mut self) { + self.drop_current_context(); + } +} + +impl GLPlatformContext { + pub fn new(_: Rc, + _platform_display_data: PlatformDisplayData, + _size: Size2D) + -> Option { + None + } + + pub fn drop_current_context(&self) { + unimplemented!(); + } + + pub fn make_current(&self) { + unimplemented!(); + } +} diff --git a/src/gl_rasterization_context_ios.rs b/src/gl_rasterization_context_ios.rs new file mode 100644 index 0000000000..774966cf58 --- /dev/null +++ b/src/gl_rasterization_context_ios.rs @@ -0,0 +1,40 @@ +/* + * Copyright 2013, 2015 The Servo Project Developers + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +use gl_context::GLContext; + +use euclid::Size2D; +use std::sync::Arc; + +pub struct GLRasterizationContext { + pub gl_context: Arc, +} + +impl Drop for GLRasterizationContext { + fn drop(&mut self) { + } +} + +impl GLRasterizationContext { + pub fn new(_gl_context: Arc, + _size: Size2D) + -> Option { + None + } + + pub fn make_current(&self) { + unimplemented!(); + } + + pub fn flush(&self) { + unimplemented!(); + } + + pub fn flush_to_surface(&self) { + unimplemented!(); + } +} diff --git a/src/lib.rs b/src/lib.rs index 73660f5325..30b9678fc9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,6 +52,11 @@ pub mod gl_context_cgl; #[cfg(target_os="macos")] pub mod gl_rasterization_context_cgl; +#[cfg(target_os="ios")] +pub mod gl_context_ios; +#[cfg(target_os="ios")] +pub mod gl_rasterization_context_ios; + #[cfg(target_os="android")] pub mod gl_context_android; #[cfg(target_os="android")] From c3775f459ea0086e73221c567733bf81016d3412 Mon Sep 17 00:00:00 2001 From: NatalyaKovalova Date: Tue, 17 Oct 2017 19:50:05 +0300 Subject: [PATCH 4/8] iOS support: added mac's SkStream_iOS to iOS --- CMakeLists.txt | 2 +- src/utils/ios/SkStream_iOS.cpp | 67 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/utils/ios/SkStream_iOS.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c0f3fb737..573309dc5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -566,7 +566,7 @@ if($ENV{TARGET} MATCHES ".*apple-ios") set_prefix(SKIA_UTILS_PLATFORM_SRC src/utils/iOS/ SkImageDecoder_iOS.mm - SkStream_NSData.mm + SkStream_iOS.cpp ) set_prefix( SKIA_IOS_STUB_SRC src/opts/ SkMorphology_opts_none.cpp diff --git a/src/utils/ios/SkStream_iOS.cpp b/src/utils/ios/SkStream_iOS.cpp new file mode 100644 index 0000000000..64d2dbb2ca --- /dev/null +++ b/src/utils/ios/SkStream_iOS.cpp @@ -0,0 +1,67 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkCGUtils.h" +#include "SkStream.h" + +// This is used by CGDataProviderCreateWithData + +static void unref_proc(void* info, const void* addr, size_t size) { + SkASSERT(info); + ((SkRefCnt*)info)->unref(); +} + +// These are used by CGDataProviderSequentialCallbacks + +static size_t get_bytes_proc(void* info, void* buffer, size_t bytes) { + SkASSERT(info); + return ((SkStream*)info)->read(buffer, bytes); +} + +static off_t skip_forward_proc(void* info, off_t bytes) { + return ((SkStream*)info)->skip((size_t) bytes); +} + +static void rewind_proc(void* info) { + SkASSERT(info); + ((SkStream*)info)->rewind(); +} + +static void release_info_proc(void* info) { + SkASSERT(info); + ((SkStream*)info)->unref(); +} + +CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) { + stream->ref(); // unref will be called when the provider is deleted + + const void* addr = stream->getMemoryBase(); + if (addr) { + // special-case when the stream is just a block of ram + return CGDataProviderCreateWithData(stream, addr, stream->getLength(), + unref_proc); + } + + CGDataProviderSequentialCallbacks rec; + sk_bzero(&rec, sizeof(rec)); + rec.version = 0; + rec.getBytes = get_bytes_proc; + rec.skipForward = skip_forward_proc; + rec.rewind = rewind_proc; + rec.releaseInfo = release_info_proc; + return CGDataProviderCreateSequential(stream, &rec); +} + +/////////////////////////////////////////////////////////////////////////////// + +#include "SkData.h" + +CGDataProviderRef SkCreateDataProviderFromData(SkData* data) { + data->ref(); + return CGDataProviderCreateWithData(data, data->data(), data->size(), + unref_proc); +} From 667d2a04425a15195528ebf684cb4172d76d5b38 Mon Sep 17 00:00:00 2001 From: NatalyaKovalova Date: Fri, 20 Oct 2017 13:16:15 +0300 Subject: [PATCH 5/8] iOS support: remove an empty drop method for iOS' rasterization context --- src/gl_rasterization_context_ios.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/gl_rasterization_context_ios.rs b/src/gl_rasterization_context_ios.rs index 774966cf58..37da436386 100644 --- a/src/gl_rasterization_context_ios.rs +++ b/src/gl_rasterization_context_ios.rs @@ -14,11 +14,6 @@ pub struct GLRasterizationContext { pub gl_context: Arc, } -impl Drop for GLRasterizationContext { - fn drop(&mut self) { - } -} - impl GLRasterizationContext { pub fn new(_gl_context: Arc, _size: Size2D) From 59a046027f691c31048ee3419a042125d2815d28 Mon Sep 17 00:00:00 2001 From: NatalyaKovalova Date: Fri, 20 Oct 2017 13:18:58 +0300 Subject: [PATCH 6/8] whitespace alignment --- src/utils/ios/SkStream_iOS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ios/SkStream_iOS.cpp b/src/utils/ios/SkStream_iOS.cpp index 64d2dbb2ca..bb71c806e4 100644 --- a/src/utils/ios/SkStream_iOS.cpp +++ b/src/utils/ios/SkStream_iOS.cpp @@ -63,5 +63,5 @@ CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) { CGDataProviderRef SkCreateDataProviderFromData(SkData* data) { data->ref(); return CGDataProviderCreateWithData(data, data->data(), data->size(), - unref_proc); + unref_proc); } From 7dc757c3c6282f9f6005b84cceaa114adaa9a817 Mon Sep 17 00:00:00 2001 From: NatalyaKovalova Date: Fri, 27 Oct 2017 23:37:17 +0300 Subject: [PATCH 7/8] iOS support: add stubs for in gl_rasterization_context( rust ) --- src/gl_rasterization_context.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gl_rasterization_context.rs b/src/gl_rasterization_context.rs index 6592b21128..5d7212ef1b 100644 --- a/src/gl_rasterization_context.rs +++ b/src/gl_rasterization_context.rs @@ -13,6 +13,8 @@ use std::ffi::CString; #[cfg(target_os="macos")] pub use gl_rasterization_context_cgl::GLRasterizationContext; +#[cfg(target_os="ios")] +pub use gl_rasterization_context_ios::GLRasterizationContext; #[cfg(target_os="linux")] pub use gl_rasterization_context_glx::GLRasterizationContext; #[cfg(target_os="android")] From 5ac87cb38ab9e2026d6a6238db3e419bcf6df55e Mon Sep 17 00:00:00 2001 From: NatalyaKovalova Date: Fri, 27 Oct 2017 23:44:59 +0300 Subject: [PATCH 8/8] iOS support: added dependency: rust-offscreen-rendering-context --- Cargo.toml | 4 ++++ src/lib.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index fd9df12bbd..24022cc919 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,3 +50,7 @@ servo-egl = "0.2" [target.'cfg(target_os = "macos")'.dependencies] cgl = "0.2" io-surface = "0.8" + +[target.'cfg(target_os = "ios")'.dependencies] +offscreen_gl_context = {git = "https://github.com/emilio/rust-offscreen-rendering-context"} +objc = "0.2" diff --git a/src/lib.rs b/src/lib.rs index 30b9678fc9..8790dc0b62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,9 @@ extern crate cgl; #[cfg(target_os="macos")] extern crate io_surface; +#[cfg(target_os="ios")] +extern crate offscreen_gl_context; + #[cfg(target_os="linux")] extern crate x11; #[cfg(target_os="linux")]