diff --git a/CMakeLists.txt b/CMakeLists.txt index a040adc554..573309dc5c 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_iOS.cpp + ) + 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) 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/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; 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.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")] diff --git a/src/gl_rasterization_context_ios.rs b/src/gl_rasterization_context_ios.rs new file mode 100644 index 0000000000..37da436386 --- /dev/null +++ b/src/gl_rasterization_context_ios.rs @@ -0,0 +1,35 @@ +/* + * 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 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..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")] @@ -52,6 +55,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")] diff --git a/src/utils/ios/SkStream_iOS.cpp b/src/utils/ios/SkStream_iOS.cpp new file mode 100644 index 0000000000..bb71c806e4 --- /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); +}