From 59a12a950f7dc6ba8e3bc755dff81e7a6de3cc68 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Mon, 12 Jan 2015 13:19:56 -0800 Subject: [PATCH 1/2] Move Skia C and Rust interface to Skia This allows using Skia independently of Azure. --- Cargo.toml | 2 +- makefile.cargo | 2 +- src/azure-c.cpp | 62 +------------------------------------------------ src/azure-c.h | 28 +++------------------- src/azure.rs | 35 +++------------------------- src/azure_hl.rs | 45 +++++++++++++++++------------------ src/lib.rs | 10 ++++---- 7 files changed, 34 insertions(+), 150 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d91124d..b28d0a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ build = "make -f makefile.cargo" git = "https://github.com/servo/rust-geom" -[dependencies.skia-sys] +[dependencies.skia] git = "https://github.com/servo/skia" branch = "upstream-2014-06-16" diff --git a/makefile.cargo b/makefile.cargo index 0b32992..be49375 100644 --- a/makefile.cargo +++ b/makefile.cargo @@ -59,7 +59,7 @@ CXXFLAGS += \ $(NULL) endif -SKIA_OUTDIR = $(shell find $(OUT_DIR)/.. -name 'skia-sys-*' -type d) +SKIA_OUTDIR = $(shell find $(OUT_DIR)/.. -name 'skia-*' -type d) FREETYPE_OUTDIR = $(shell find $(OUT_DIR)/.. -name 'freetype-sys-*' -type d) CXXFLAGS += \ diff --git a/src/azure-c.cpp b/src/azure-c.cpp index c68827f..61be59c 100644 --- a/src/azure-c.cpp +++ b/src/azure-c.cpp @@ -170,61 +170,6 @@ AzCreateColorPattern(AzColor *aColor) { return gfxColorPattern; } -extern "C" AzSkiaSharedGLContextRef -AzCreateSkiaSharedGLContext(AzGLNativeContextRef aNativeContext, AzIntSize *aSize) { - GrGLNativeContext* nativeContext = reinterpret_cast(aNativeContext); - SkNativeSharedGLContext *sharedGLContext = new SkNativeSharedGLContext(*nativeContext); - if (sharedGLContext == NULL) { - return NULL; - } - if (!sharedGLContext->init(aSize->width, aSize->height)) { - return NULL; - } - return sharedGLContext; -} - -extern "C" void -AzRetainSkiaSharedGLContext(AzSkiaSharedGLContextRef aGLContext) { - SkNativeSharedGLContext *sharedGLContext = static_cast(aGLContext); - sharedGLContext->ref(); -} - -extern "C" void -AzReleaseSkiaSharedGLContext(AzSkiaSharedGLContextRef aGLContext) { - SkNativeSharedGLContext *sharedGLContext = static_cast(aGLContext); - sharedGLContext->unref(); -} - -extern "C" unsigned int -AzSkiaSharedGLContextGetFBOID(AzSkiaSharedGLContextRef aGLContext) { - SkNativeSharedGLContext *sharedGLContext = static_cast(aGLContext); - return sharedGLContext->getFBOID(); -} - -extern "C" AzSkiaGrGLSharedSurfaceRef -AzSkiaSharedGLContextStealSurface(AzSkiaSharedGLContextRef aGLContext) { - SkNativeSharedGLContext *sharedGLContext = static_cast(aGLContext); - return reinterpret_cast(sharedGLContext->stealSurface()); -} - -extern "C" AzSkiaGrContextRef -AzSkiaSharedGLContextGetGrContext(AzSkiaSharedGLContextRef aGLContext) { - SkNativeSharedGLContext *sharedGLContext = static_cast(aGLContext); - return sharedGLContext->getGrContext(); -} - -extern "C" void -AzSkiaSharedGLContextMakeCurrent(AzSkiaSharedGLContextRef aGLContext) { - SkNativeSharedGLContext *sharedGLContext = static_cast(aGLContext); - sharedGLContext->makeCurrent(); -} - -extern "C" void -AzSkiaSharedGLContextFlush(AzSkiaSharedGLContextRef aGLContext) { - SkNativeSharedGLContext *sharedGLContext = static_cast(aGLContext); - sharedGLContext->flush(); -} - extern "C" AzDrawTargetRef AzCreateDrawTarget(AzBackendType aBackend, AzIntSize *aSize, AzSurfaceFormat aFormat) { gfx::BackendType backendType = static_cast(aBackend); @@ -255,7 +200,7 @@ AzCreateDrawTargetForData(AzBackendType aBackend, unsigned char *aData, AzIntSiz } extern "C" AzDrawTargetRef -AzCreateSkiaDrawTargetForFBO(AzSkiaSharedGLContextRef aGLContext, AzIntSize *aSize, AzSurfaceFormat aFormat) { +AzCreateSkiaDrawTargetForFBO(SkiaSkNativeSharedGLContextRef aGLContext, AzIntSize *aSize, AzSurfaceFormat aFormat) { SkNativeSharedGLContext *sharedGLContext = static_cast(aGLContext); GrContext *grContext = sharedGLContext->getGrContext(); gfx::IntSize *size = reinterpret_cast(aSize); @@ -623,11 +568,6 @@ AzDestroyFontOptions(AzFontOptions* aOptions) { #endif } -extern "C" AzGLContext -AzSkiaGetCurrentGLContext() { - return SkNativeSharedGLContext::GetCurrent(); -} - // FIXME: Needs to take a FillRule extern "C" AzPathBuilderRef AzCreatePathBuilder(AzDrawTargetRef aDrawTarget) { diff --git a/src/azure-c.h b/src/azure-c.h index 36e9661..0fd1e1a 100644 --- a/src/azure-c.h +++ b/src/azure-c.h @@ -1,13 +1,10 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this +/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef MOZILLA_GFX_AZURE_C_H_ #define MOZILLA_GFX_AZURE_C_H_ -#include "GrContext.h" -#include "SkNativeSharedGLContext.h" - +#include "skia-c.h" #include #include @@ -22,11 +19,6 @@ void AzSanityCheck(); // FIXME: This stuff is copy pasted from the azure headers typedef void* AzGradientStopsRef; -typedef void* AzSkiaSharedGLContextRef; -typedef void* AzSkiaSharedGrGLContextRef; -typedef void* AzSkiaGrContextRef; -typedef void* AzSkiaGrGLSharedSurfaceRef; -typedef void* AzSkiaGrGLSharedContextRef; typedef void* AzDrawTargetRef; typedef void* AzPatternRef; typedef void* AzColorPatternRef; @@ -343,20 +335,8 @@ typedef struct _AzNativeFont { void *mFont; } AzNativeFont; -typedef GrGLSharedContext AzGLContext; -typedef GrGLNativeContext* AzGLNativeContextRef; - AzColorPatternRef AzCreateColorPattern(AzColor *aColor); -AzSkiaSharedGLContextRef AzCreateSkiaSharedGLContext(AzGLNativeContextRef aNativeContext, - AzIntSize *aSize); -void AzRetainSkiaSharedGLContext(AzSkiaSharedGLContextRef aGLContext); -void AzReleaseSkiaSharedGLContext(AzSkiaSharedGLContextRef aGLContext); -unsigned int AzSkiaSharedGLContextGetFBOID(AzSkiaSharedGLContextRef aGLContext); -AzSkiaGrContextRef AzSkiaSharedGLContextGetGrContext(AzSkiaSharedGLContextRef aGLContext); -void AzSkiaSharedGLContextMakeCurrent(AzSkiaSharedGLContextRef aGLContext); -void AzSkiaSharedGLContextFlush(AzSkiaSharedGLContextRef aGLContext); - AzDrawTargetRef AzCreateDrawTarget(AzBackendType aBackend, AzIntSize *aSize, AzSurfaceFormat aFormat); @@ -365,7 +345,7 @@ AzDrawTargetRef AzCreateDrawTargetForData(AzBackendType aBackend, AzIntSize *aSize, int32_t aStride, AzSurfaceFormat aFormat); -AzDrawTargetRef AzCreateSkiaDrawTragetForFBO(AzSkiaSharedGLContextRef aGLContext, +AzDrawTargetRef AzCreateSkiaDrawTragetForFBO(SkiaSkNativeSharedGLContextRef aGLContext, AzIntSize *aSize, AzSurfaceFormat aFormat); @@ -491,8 +471,6 @@ AzFontOptions* AzCreateFontOptionsForName(char *aName, AzFontStyle aStyle); AzFontOptions* AzCreateFontOptionsForData(uint8_t *aFontData, uint32_t aFontDataSize); void AzDestroyFontOptions(AzFontOptions* aOptions); -AzGLContext AzSkiaGetCurrentGLContext(); - #ifdef __cplusplus } #endif diff --git a/src/azure.rs b/src/azure.rs index 838663a..3b72a12 100644 --- a/src/azure.rs +++ b/src/azure.rs @@ -10,6 +10,8 @@ use libc::*; +use skia::SkiaSkNativeSharedGLContextRef; + pub type AzFontOptions = *mut c_void; pub type AzFloat = c_float; @@ -393,14 +395,6 @@ pub type AzNativeFont = struct__AzNativeFont; pub type AzGradientStopsRef = *mut c_void; -pub type AzSkiaSharedGLContextRef = *mut c_void; - -pub type AzSkiaSharedGrGLContextRef = *mut c_void; - -pub type AzSkiaGrContextRef = *mut c_void; - -pub type AzSkiaGrGLSharedSurfaceRef = *mut c_void; - pub type AzDrawTargetRef = *mut c_void; pub type AzPatternRef = *mut c_void; @@ -422,12 +416,8 @@ pub type AzDrawSurfaceOptionsRef = *mut AzDrawSurfaceOptions; pub type AzGLContext = *mut c_void; -pub type AzSkiaGrGLSharedContextRef = *mut c_void; - pub type AzGLContextMetadataRef = *mut c_void; -pub type AzGLNativeContextRef = *mut c_void; - pub type AzPathRef = *mut c_void; pub type AzPathBuilderRef = *mut c_void; @@ -445,28 +435,11 @@ pub fn AzCreateColorPattern(aColor: *mut AzColor) -> AzColorPatternRef; pub fn AzReleasePattern(aPattern: AzPatternRef); -pub fn AzCreateSkiaSharedGLContext(aNativeContext: AzGLNativeContextRef, aSize: *mut AzIntSize) - -> AzSkiaSharedGLContextRef; - -pub fn AzRetainSkiaSharedGLContext(aGLContext: AzSkiaSharedGLContextRef); - -pub fn AzReleaseSkiaSharedGLContext(aGLContext: AzSkiaSharedGLContextRef); - -pub fn AzSkiaSharedGLContextGetFBOID(aGLContext: AzSkiaSharedGLContextRef) -> c_uint; - -pub fn AzSkiaSharedGLContextStealSurface(aGLContext: AzSkiaSharedGLContextRef) -> AzSkiaGrGLSharedSurfaceRef; - -pub fn AzSkiaSharedGLContextGetGrContext(aGLContext: AzSkiaSharedGLContextRef) -> AzSkiaGrContextRef; - -pub fn AzSkiaSharedGLContextMakeCurrent(aGLContext: AzSkiaSharedGLContextRef); - -pub fn AzSkiaSharedGLContextFlush(aGLContext: AzSkiaSharedGLContextRef); - pub fn AzCreateDrawTarget(aBackend: AzBackendType, aSize: *mut AzIntSize, aFormat: AzSurfaceFormat) -> AzDrawTargetRef; pub fn AzCreateDrawTargetForData(aBackend: AzBackendType, aData: *mut c_uchar, aSize: *mut AzIntSize, aStride: i32, aFormat: AzSurfaceFormat) -> AzDrawTargetRef; -pub fn AzCreateSkiaDrawTargetForFBO(aGLContext: AzSkiaSharedGLContextRef, aSize: *mut AzIntSize, aFormat: AzSurfaceFormat) -> AzDrawTargetRef; +pub fn AzCreateSkiaDrawTargetForFBO(aGLContext: SkiaSkNativeSharedGLContextRef, aSize: *mut AzIntSize, aFormat: AzSurfaceFormat) -> AzDrawTargetRef; pub fn AzRetainDrawTarget(aTarget: AzDrawTargetRef); @@ -571,8 +544,6 @@ pub fn AzCreateFontOptionsForName(aName: *const c_char, aStyle: enum_AzFontStyle pub fn AzDestroyFontOptions(aOptions: *mut AzFontOptions); -pub fn AzSkiaGetCurrentGLContext() -> AzGLContext; - pub fn AzCreatePathBuilder(aDrawTarget: AzDrawTargetRef) -> AzPathBuilderRef; pub fn AzReleasePathBuilder(aPathBuilder: AzPathBuilderRef); diff --git a/src/azure_hl.rs b/src/azure_hl.rs index d43ba48..0d520fe 100644 --- a/src/azure_hl.rs +++ b/src/azure_hl.rs @@ -26,12 +26,10 @@ use azure::{AzCompositionOp}; use azure::{struct__AzColor, struct__AzGlyphBuffer}; use azure::{struct__AzDrawOptions, struct__AzDrawSurfaceOptions, struct__AzIntSize}; use azure::{struct__AzPoint, struct__AzRect, struct__AzStrokeOptions, struct__AzMatrix5x4}; -use azure::{AzGLContext, AzSkiaSharedGLContextRef}; use azure::{AzCreateColorPattern, AzCreateDrawTarget, AzCreateDrawTargetForData}; use azure::{AzDataSourceSurfaceGetData, AzDataSourceSurfaceGetStride}; use azure::{AzDrawTargetClearRect}; -use azure::{AzDrawTargetCreateSourceSurfaceFromData, AzCreateSkiaSharedGLContext}; -use azure::{AzReleaseSkiaSharedGLContext, AzRetainSkiaSharedGLContext}; +use azure::{AzDrawTargetCreateSourceSurfaceFromData}; use azure::{AzDrawTargetDrawSurface, AzDrawTargetFillRect, AzDrawTargetFlush}; use azure::{AzDrawTargetGetSize, AzDrawTargetGetSnapshot, AzDrawTargetSetTransform}; use azure::{AzDrawTargetStrokeLine, AzDrawTargetStrokeRect, AzDrawTargetFillGlyphs}; @@ -39,13 +37,11 @@ use azure::{AzDrawTargetCreateGradientStops, AzDrawTargetGetFormat}; use azure::{AzReleaseDrawTarget, AzReleasePattern, AzReleaseGradientStops}; use azure::{AzReleaseSourceSurface, AzRetainDrawTarget}; use azure::{AzSourceSurfaceGetDataSurface, AzSourceSurfaceGetFormat}; -use azure::{AzSourceSurfaceGetSize, AzCreateSkiaDrawTargetForFBO, AzSkiaGetCurrentGLContext}; -use azure::{AzSkiaSharedGLContextMakeCurrent, AzSkiaSharedGLContextStealSurface}; -use azure::{AzSkiaSharedGLContextFlush, AzSkiaGrGLSharedSurfaceRef}; +use azure::{AzSourceSurfaceGetSize, AzCreateSkiaDrawTargetForFBO}; use azure::{AzCreatePathBuilder, AzPathBuilderRef, AzPathBuilderMoveTo, AzPathBuilderLineTo}; use azure::{AzPathBuilderArc, AzPathBuilderFinish, AzReleasePathBuilder}; use azure::{AzDrawTargetFill, AzPathRef, AzReleasePath, AzDrawTargetPushClip, AzDrawTargetPopClip}; -use azure::{AzGLNativeContextRef, AzLinearGradientPatternRef, AzMatrix, AzPatternRef}; +use azure::{AzLinearGradientPatternRef, AzMatrix, AzPatternRef}; use azure::{AzCreateLinearGradientPattern, AzDrawTargetPushClipRect}; use azure::{AzDrawTargetDrawSurfaceWithShadow, AzDrawTargetCreateShadowDrawTarget}; use azure::{AzDrawTargetCreateSimilarDrawTarget, AzDrawTargetGetTransform}; @@ -55,16 +51,21 @@ use azure::{AzFilterNodeSetMatrix5x4Attribute, AzFilterNodeSetFilterNodeInput}; use azure::{AzFilterNodeSetFloatArrayAttribute, AzFilterNodeSetBoolAttribute}; use azure::{AzDrawTargetDrawFilter, AzFilterNodeRef, AzFilterType}; -use std::sync::Arc; use geom::matrix2d::Matrix2D; use geom::point::Point2D; use geom::rect::Rect; use geom::size::Size2D; use libc::types::common::c99::{uint8_t, uint16_t}; use libc::size_t; +use skia::SkiaGrGLNativeContextRef; +use skia::{SkiaSkNativeSharedGLContextRef, SkiaSkNativeSharedGLContextCreate}; +use skia::{SkiaSkNativeSharedGLContextRelease, SkiaSkNativeSharedGLContextRetain}; +use skia::{SkiaSkNativeSharedGLContextMakeCurrent, SkiaSkNativeSharedGLContextStealSurface}; +use skia::{SkiaSkNativeSharedGLContextFlush, SkiaGrGLSharedSurfaceRef}; use std::mem; use std::ptr; use std::slice; +use std::sync::Arc; pub trait AsAzureRect { fn as_azure_rect(&self) -> AzRect; @@ -352,7 +353,7 @@ impl BackendType { pub struct DrawTarget { pub azure_draw_target: AzDrawTargetRef, pub data: Option>>, - pub skia_context: Option + pub skia_context: Option } impl Drop for DrawTarget { @@ -361,7 +362,7 @@ impl Drop for DrawTarget { AzReleaseDrawTarget(self.azure_draw_target); match self.skia_context { None => {} - Some(ctx_ref) => { AzReleaseSkiaSharedGLContext(ctx_ref); } + Some(ctx_ref) => { SkiaSkNativeSharedGLContextRelease(ctx_ref); } } } } @@ -377,7 +378,7 @@ impl PartialEq for DrawTarget { /// Contains the GL resources that Skia was holding onto that may be safely extracted. At the /// moment this consists simply of the native surface. pub struct StolenGLResources { - pub surface: AzSkiaGrGLSharedSurfaceRef, + pub surface: SkiaGrGLSharedSurfaceRef, } impl DrawTarget { @@ -423,13 +424,15 @@ impl DrawTarget { } pub fn new_with_fbo(backend: BackendType, - native_graphics_context: AzGLNativeContextRef, + native_graphics_context: SkiaGrGLNativeContextRef, size: Size2D, format: SurfaceFormat) -> DrawTarget { assert!(backend == BackendType::Skia); + let native_surface = native_graphics_context as SkiaGrGLSharedSurfaceRef; let skia_context = unsafe { - AzCreateSkiaSharedGLContext(native_graphics_context, - &mut size.as_azure_int_size()) + SkiaSkNativeSharedGLContextCreate(native_graphics_context, + size.width, + size.height) }; let azure_draw_target = unsafe { AzCreateSkiaDrawTargetForFBO(skia_context, @@ -450,7 +453,7 @@ impl DrawTarget { unsafe { AzRetainDrawTarget(self.azure_draw_target); match self.skia_context { - Some(ctx) => AzRetainSkiaSharedGLContext(ctx), + Some(ctx) => SkiaSkNativeSharedGLContextRetain(ctx), None => (), } } @@ -469,7 +472,7 @@ impl DrawTarget { None => {} Some(ctx) => { unsafe { - AzSkiaSharedGLContextMakeCurrent(ctx); + SkiaSkNativeSharedGLContextMakeCurrent(ctx); } } } @@ -479,7 +482,7 @@ impl DrawTarget { pub fn steal_gl_resources(self) -> Option { self.skia_context.map(|ctx| { StolenGLResources { - surface: unsafe { AzSkiaSharedGLContextStealSurface(ctx) }, + surface: unsafe { SkiaSkNativeSharedGLContextStealSurface(ctx) }, } }) } @@ -509,7 +512,7 @@ impl DrawTarget { AzDrawTargetFlush(self.azure_draw_target); match self.skia_context { None => {} - Some(ctx) => { AzSkiaSharedGLContextFlush(ctx); } + Some(ctx) => { SkiaSkNativeSharedGLContextFlush(ctx); } } } } @@ -1018,12 +1021,6 @@ impl<'a> PatternRef<'a> { } } -pub fn current_gl_context() -> AzGLContext { - unsafe { - AzSkiaGetCurrentGLContext() - } -} - pub struct FilterNode { pub azure_filter_node: AzFilterNodeRef, } diff --git a/src/lib.rs b/src/lib.rs index 5349fb4..aace1bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ extern crate libc; extern crate geom; +extern crate skia; #[cfg(target_os = "linux")] extern crate xlib; #[cfg(target_os = "android")] @@ -58,21 +59,18 @@ pub use azure::{AzFontOptions, AzFloat, enum_AzSurfaceType, AZ_SURFACE_DATA, AzDrawOptions, struct__AzStrokeOptions, AzStrokeOptions, struct__AzDrawSurfaceOptions, AzDrawSurfaceOptions, struct__AzGlyph, AzGlyph, struct__AzGlyphBuffer, AzGlyphBuffer, struct__AzNativeFont, AzNativeFont, AzGradientStopsRef, - AzSkiaSharedGLContextRef, AzSkiaSharedGrGLContextRef, AzSkiaGrContextRef, AzSkiaGrGLSharedSurfaceRef, AzDrawTargetRef, AzPatternRef, AzColorPatternRef, AzScaledFontRef, AzGlyphRenderingOptionsRef, AzSourceSurfaceRef, AzDataSourceSurfaceRef, AzDrawSurfaceOptionsRef, - AzGLContext, AzSkiaGrGLSharedContextRef, AzGLContextMetadataRef, AzGLNativeContextRef, + AzGLContext, AzGLContextMetadataRef, AzPathRef, AzPathBuilderRef, AzSanityCheck, AzCreateColorPattern, - AzCreateSkiaSharedGLContext, AzRetainSkiaSharedGLContext, AzReleaseSkiaSharedGLContext, - AzSkiaSharedGLContextGetFBOID, AzSkiaSharedGLContextStealSurface, AzSkiaSharedGLContextGetGrContext, AzSkiaSharedGLContextMakeCurrent, - AzSkiaSharedGLContextFlush, AzCreateDrawTarget, AzCreateDrawTargetForData, AzCreateSkiaDrawTargetForFBO, + AzCreateDrawTarget, AzCreateDrawTargetForData, AzCreateSkiaDrawTargetForFBO, AzRetainDrawTarget, AzReleaseDrawTarget, AzDrawTargetGetSize, AzDrawTargetFlush, AzDrawTargetClearRect, AzDrawTargetFillRect, AzDrawTargetStrokeRect, AzDrawTargetStrokeLine, AzDrawTargetFill, AzDrawTargetPushClip, AzDrawTargetPopClip, AzDrawTargetFillGlyphs, AzDrawTargetDrawSurface, AzDrawTargetGetSnapshot, AzDrawTargetCreateSourceSurfaceFromData, AzReleaseSourceSurface, AzSourceSurfaceGetSize, AzSourceSurfaceGetFormat, AzSourceSurfaceGetDataSurface, AzDataSourceSurfaceGetData, AzDataSourceSurfaceGetStride, AzCreateScaledFontForNativeFont, AzReleaseScaledFont, AzDrawTargetSetTransform, - AzCreateFontOptionsForName, AzDestroyFontOptions, AzSkiaGetCurrentGLContext, AzCreatePathBuilder, + AzCreateFontOptionsForName, AzDestroyFontOptions, AzCreatePathBuilder, AzReleasePathBuilder, AzPathBuilderMoveTo, AzPathBuilderLineTo, AzPathBuilderFinish, AzReleasePath}; pub mod azure_hl; From ca63bf88292c17e443280cfb5dee62f54ebe0f94 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Tue, 13 Jan 2015 18:26:33 -0800 Subject: [PATCH 2/2] Expose AzCreateDrawTargetSkiaWithGrContextAndFBO as it is in Azure Instead of reaching into the private Skia API to create Skia draw targets, use the Azure API and the newly exposed Skia rust API. This is part of the transition of teasing out the Skia-specific parts of rust-azure. --- src/azure-c.cpp | 7 +++---- src/azure-c.h | 8 +++++--- src/azure.rs | 4 ++-- src/azure_hl.rs | 29 +++++++++++++++++++++-------- src/lib.rs | 2 +- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/azure-c.cpp b/src/azure-c.cpp index 61be59c..9f2a42f 100644 --- a/src/azure-c.cpp +++ b/src/azure-c.cpp @@ -200,13 +200,12 @@ AzCreateDrawTargetForData(AzBackendType aBackend, unsigned char *aData, AzIntSiz } extern "C" AzDrawTargetRef -AzCreateSkiaDrawTargetForFBO(SkiaSkNativeSharedGLContextRef aGLContext, AzIntSize *aSize, AzSurfaceFormat aFormat) { - SkNativeSharedGLContext *sharedGLContext = static_cast(aGLContext); - GrContext *grContext = sharedGLContext->getGrContext(); +AzCreateDrawTargetSkiaWithGrContextAndFBO(SkiaGrContextRef aGrContext, unsigned int aFBOID, AzIntSize *aSize, AzSurfaceFormat aFormat) { + GrContext *grContext = reinterpret_cast(aGrContext); gfx::IntSize *size = reinterpret_cast(aSize); gfx::SurfaceFormat surfaceFormat = static_cast(aFormat); RefPtr target = gfx::Factory::CreateDrawTargetSkiaWithGrContextAndFBO(grContext, - sharedGLContext->getFBOID(), + aFBOID, *size, surfaceFormat); if (target != NULL) { diff --git a/src/azure-c.h b/src/azure-c.h index 0fd1e1a..ff6dd9c 100644 --- a/src/azure-c.h +++ b/src/azure-c.h @@ -345,9 +345,11 @@ AzDrawTargetRef AzCreateDrawTargetForData(AzBackendType aBackend, AzIntSize *aSize, int32_t aStride, AzSurfaceFormat aFormat); -AzDrawTargetRef AzCreateSkiaDrawTragetForFBO(SkiaSkNativeSharedGLContextRef aGLContext, - AzIntSize *aSize, - AzSurfaceFormat aFormat); +AzDrawTargetRef +AzCreateDrawTargetSkiaWithGrContextAndFBO(SkiaGrContextRef aGrContext, + unsigned int aFBOID, + AzIntSize *aSize, + AzSurfaceFormat aFormat); void AzRetainDrawTarget(AzDrawTargetRef aTarget); diff --git a/src/azure.rs b/src/azure.rs index 3b72a12..fc3d671 100644 --- a/src/azure.rs +++ b/src/azure.rs @@ -10,7 +10,7 @@ use libc::*; -use skia::SkiaSkNativeSharedGLContextRef; +use skia::{SkiaGrContextRef, SkiaSkNativeSharedGLContextRef}; pub type AzFontOptions = *mut c_void; pub type AzFloat = c_float; @@ -439,7 +439,7 @@ pub fn AzCreateDrawTarget(aBackend: AzBackendType, aSize: *mut AzIntSize, aForma pub fn AzCreateDrawTargetForData(aBackend: AzBackendType, aData: *mut c_uchar, aSize: *mut AzIntSize, aStride: i32, aFormat: AzSurfaceFormat) -> AzDrawTargetRef; -pub fn AzCreateSkiaDrawTargetForFBO(aGLContext: SkiaSkNativeSharedGLContextRef, aSize: *mut AzIntSize, aFormat: AzSurfaceFormat) -> AzDrawTargetRef; +pub fn AzCreateDrawTargetSkiaWithGrContextAndFBO(aGrContext: SkiaGrContextRef, aFBOID: u32, aSize: *mut AzIntSize, aFormat: AzSurfaceFormat) -> AzDrawTargetRef; pub fn AzRetainDrawTarget(aTarget: AzDrawTargetRef); diff --git a/src/azure_hl.rs b/src/azure_hl.rs index 0d520fe..15dbdbd 100644 --- a/src/azure_hl.rs +++ b/src/azure_hl.rs @@ -37,7 +37,7 @@ use azure::{AzDrawTargetCreateGradientStops, AzDrawTargetGetFormat}; use azure::{AzReleaseDrawTarget, AzReleasePattern, AzReleaseGradientStops}; use azure::{AzReleaseSourceSurface, AzRetainDrawTarget}; use azure::{AzSourceSurfaceGetDataSurface, AzSourceSurfaceGetFormat}; -use azure::{AzSourceSurfaceGetSize, AzCreateSkiaDrawTargetForFBO}; +use azure::{AzSourceSurfaceGetSize, AzCreateDrawTargetSkiaWithGrContextAndFBO}; use azure::{AzCreatePathBuilder, AzPathBuilderRef, AzPathBuilderMoveTo, AzPathBuilderLineTo}; use azure::{AzPathBuilderArc, AzPathBuilderFinish, AzReleasePathBuilder}; use azure::{AzDrawTargetFill, AzPathRef, AzReleasePath, AzDrawTargetPushClip, AzDrawTargetPopClip}; @@ -57,8 +57,9 @@ use geom::rect::Rect; use geom::size::Size2D; use libc::types::common::c99::{uint8_t, uint16_t}; use libc::size_t; -use skia::SkiaGrGLNativeContextRef; +use skia::{SkiaGrGLNativeContextRef, SkiaGrContextRef}; use skia::{SkiaSkNativeSharedGLContextRef, SkiaSkNativeSharedGLContextCreate}; +use skia::{SkiaSkNativeSharedGLContextGetFBOID, SkiaSkNativeSharedGLContextGetGrContext}; use skia::{SkiaSkNativeSharedGLContextRelease, SkiaSkNativeSharedGLContextRetain}; use skia::{SkiaSkNativeSharedGLContextMakeCurrent, SkiaSkNativeSharedGLContextStealSurface}; use skia::{SkiaSkNativeSharedGLContextFlush, SkiaGrGLSharedSurfaceRef}; @@ -430,14 +431,26 @@ impl DrawTarget { assert!(backend == BackendType::Skia); let native_surface = native_graphics_context as SkiaGrGLSharedSurfaceRef; let skia_context = unsafe { - SkiaSkNativeSharedGLContextCreate(native_graphics_context, - size.width, - size.height) + SkiaSkNativeSharedGLContextCreate(native_graphics_context, size.width, size.height) }; + + if skia_context.is_null() { + panic!("null skia shared gl context"); + } + + let gr_context = unsafe { + SkiaSkNativeSharedGLContextGetGrContext(skia_context) + }; + + let fbo_id = unsafe { + SkiaSkNativeSharedGLContextGetFBOID(skia_context) + }; + let azure_draw_target = unsafe { - AzCreateSkiaDrawTargetForFBO(skia_context, - &mut size.as_azure_int_size(), - format.as_azure_surface_format()) + AzCreateDrawTargetSkiaWithGrContextAndFBO(gr_context, + fbo_id, + &mut size.as_azure_int_size(), + format.as_azure_surface_format()) }; if azure_draw_target.is_null() { panic!("null azure draw target"); diff --git a/src/lib.rs b/src/lib.rs index aace1bf..2af20a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,7 +63,7 @@ pub use azure::{AzFontOptions, AzFloat, enum_AzSurfaceType, AZ_SURFACE_DATA, AzGlyphRenderingOptionsRef, AzSourceSurfaceRef, AzDataSourceSurfaceRef, AzDrawSurfaceOptionsRef, AzGLContext, AzGLContextMetadataRef, AzPathRef, AzPathBuilderRef, AzSanityCheck, AzCreateColorPattern, - AzCreateDrawTarget, AzCreateDrawTargetForData, AzCreateSkiaDrawTargetForFBO, + AzCreateDrawTarget, AzCreateDrawTargetForData, AzCreateDrawTargetSkiaWithGrContextAndFBO, AzRetainDrawTarget, AzReleaseDrawTarget, AzDrawTargetGetSize, AzDrawTargetFlush, AzDrawTargetClearRect, AzDrawTargetFillRect, AzDrawTargetStrokeRect, AzDrawTargetStrokeLine, AzDrawTargetFill, AzDrawTargetPushClip, AzDrawTargetPopClip, AzDrawTargetFillGlyphs,