Skip to content
This repository was archived by the owner on Jun 8, 2020. It is now read-only.

Ios support #144

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#ifdef SK_BUILD_FOR_IOS
#include <CoreGraphics/CoreGraphics.h>
#include <MobileCoreServices/MobileCoreServices.h>
#endif

class SkBitmap;
Expand Down
5 changes: 5 additions & 0 deletions src/gl_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
38 changes: 38 additions & 0 deletions src/gl_context_ios.rs
Original file line number Diff line number Diff line change
@@ -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<gl::Gl>,
_platform_display_data: PlatformDisplayData,
_size: Size2D<i32>)
-> Option<GLPlatformContext> {
None
}

pub fn drop_current_context(&self) {
unimplemented!();
}

pub fn make_current(&self) {
unimplemented!();
}
}
2 changes: 2 additions & 0 deletions src/gl_rasterization_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
35 changes: 35 additions & 0 deletions src/gl_rasterization_context_ios.rs
Original file line number Diff line number Diff line change
@@ -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<GLContext>,
}

impl GLRasterizationContext {
pub fn new(_gl_context: Arc<GLContext>,
_size: Size2D<i32>)
-> Option<GLRasterizationContext> {
None
}

pub fn make_current(&self) {
unimplemented!();
}

pub fn flush(&self) {
unimplemented!();
}

pub fn flush_to_surface(&self) {
unimplemented!();
}
}
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down
67 changes: 67 additions & 0 deletions src/utils/ios/SkStream_iOS.cpp
Original file line number Diff line number Diff line change
@@ -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);
}