skia: Update to use cairo_backend_t interface

Still hopelessly broken. Requires compiling cairo to use static linking
and then still requires manual linkage to workaround libtool. Lots of
functionality is still absent - we need to either find analogues to some
Cairo operations or implement fallbacks - but it is sufficient to
investigate how Skia functions in direct comparison with Cairo for
tessellation/rasterisation.

Caveat emptor.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2010-04-24 00:50:33 +01:00
parent e849e7c929
commit 1ccd269a3f
17 changed files with 2422 additions and 34 deletions

View file

@ -54,7 +54,7 @@ DISTCLEANFILES += ChangeLog.cache-*
ChangeLog.cache-*..: .git
ChangeLog%: $(srcdir)/ChangeLog%
#ChangeLog%: $(srcdir)/ChangeLog%
$(srcdir)/ChangeLog.cache-% $(srcdir)/ChangeLog.pre-%:
@echo Creating $@

View file

@ -9,7 +9,8 @@ AC_GNU_SOURCE
AC_USE_SYSTEM_EXTENSIONS
AC_CONFIG_SRCDIR(src/cairo.h)
AC_CONFIG_HEADERS(config.h)
AM_INIT_AUTOMAKE([1.9.6 gnu -Wall no-define])
#AM_INIT_AUTOMAKE([1.9.6 gnu -Wall no-define])
AM_INIT_AUTOMAKE([1.9.6])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AC_LIBTOOL_WIN32_DLL dnl Must be called before AC_PROG_LIBTOOL
AC_PROG_LIBTOOL dnl ([1.4]) Don't remove!
@ -199,9 +200,17 @@ CAIRO_ENABLE_SURFACE_BACKEND(skia, Skia, no, [
[AS_HELP_STRING([--with-skia=/path/to/skia],
[directory to find compiled skia sources])],
[skia_DIR="$withval"],
[skia_DIR="`pwd`/../mesa"])
[skia_DIR="`pwd`/../skia"])
AC_ARG_WITH([skia-bulid],
[AS_HELP_STRING([--with-skia-build=(Release|Debug)]
[build of skia to link with, default is Relese])],
[skia_BUILD="$withval"],
[skia_BUILD="Release"])
skia_NONPKGCONFIG_CFLAGS="-I$skia_DIR/include/config -I$skia_DIR/include/core -I$skia_DIR/include/effects"
skia_NONPKGCONFIG_LIBS="$skia_DIR/out/libskia.a"
if test "x$(skia_BUILD)" = x"Relese"; then
skia_NONPKGCONFIG_CFLAGS="-DSK_RELEASE -DSK_CAN_USE_FLOAT $skia_NONPKGCONFIG_CFLAGS"
fi
skia_NONPKGCONFIG_LIBS="--start-group $skia_DIR/out/$skia_BUILD/obj.target/gyp/libeffects.a $skia_DIR/out/$skia_BUILD/obj.target/gyp/libimages.a $skia_DIR/out/$skia_BUILD/obj.target/gyp/libutils.a $skia_DIR/out/$skia_BUILD/obj.target/gyp/libopts.a $skia_DIR/out/$skia_BUILD/obj.target/gyp/libcore.a -end-group"
AC_SUBST(skia_DIR)
])

View file

@ -43,12 +43,13 @@ libcairoperf_la_SOURCES = \
$(libcairoperf_headers)
libcairoperf_la_LIBADD = $(CAIROPERF_LIBS)
cairo_perf_trace_SOURCES = \
cairo_perf_trace_SOURCES = a.cpp \
$(cairo_perf_trace_sources) \
$(cairo_perf_trace_external_sources)
cairo_perf_trace_LDADD = \
$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \
$(LDADD)
$(LDADD) $(CAIRO_LIBS)
skia = -Wl,--start-group @skia_DIR@/out/Debug/obj.target/gyp/libeffects.a @skia_DIR@/out/Debug/obj.target/gyp/libimages.a @skia_DIR@/out/Debug/obj.target/gyp/libutils.a @skia_DIR@/out/Debug/obj.target/gyp/libopts.a @skia_DIR@/out/Debug/obj.target/gyp/libcore.a -Wl,--end-group
cairo_perf_trace_DEPENDENCIES = \
$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \
$(LDADD)

View file

@ -306,7 +306,10 @@ cairo_win32_sources = cairo-win32-surface.c cairo-win32-printing-surface.c
cairo_win32_font_sources = cairo-win32-font.c
cairo_skia_headers = cairo-skia.h
cairo_skia_cxx_sources = cairo-skia-surface.cpp
cairo_skia_cxx_sources = \
skia/cairo-skia-context.cpp \
skia/cairo-skia-surface.cpp \
$(NULL)
cairo_os2_headers = cairo-os2.h
cairo_os2_private = cairo-os2-private.h

View file

@ -38,6 +38,8 @@
#include "cairoint.h"
CAIRO_BEGIN_DECLS
cairo_private void
_cairo_arc_path (cairo_t *cr,
double xc,
@ -54,4 +56,6 @@ _cairo_arc_path_negative (cairo_t *cr,
double angle1,
double angle2);
CAIRO_END_DECLS
#endif /* CAIRO_ARC_PRIVATE_H */

View file

@ -40,6 +40,7 @@
typedef enum _cairo_backend_type {
CAIRO_TYPE_DEFAULT,
CAIRO_TYPE_SKIA,
} cairo_backend_type_t;
struct _cairo_backend {

View file

@ -41,6 +41,7 @@
#include "cairo-boxes-private.h"
#include "cairo-compiler-private.h"
#include "cairo-error-private.h"
#include "cairo-path-fixed-private.h"
#include "cairo-reference-count-private.h"

View file

@ -111,4 +111,6 @@ _cairo_composite_rectangles_intersect_mask_extents (cairo_composite_rectangles_t
cairo_private void
_cairo_composite_rectangles_fini (cairo_composite_rectangles_t *extents);
CAIRO_END_DECLS
#endif /* CAIRO_COMPOSITE_RECTANGLES_PRIVATE_H */

View file

@ -46,6 +46,10 @@
CAIRO_BEGIN_DECLS
/* Sure wish C had a real enum type so that this would be distinct
* from #cairo_status_t. Oh well, without that, I'll use this bogus 100
* offset. We want to keep it fit in int8_t as the compiler may choose
* that for #cairo_status_t */
enum _cairo_int_status {
CAIRO_INT_STATUS_SUCCESS = 0,
@ -97,6 +101,8 @@ enum _cairo_int_status {
CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN,
};
typedef enum _cairo_int_status cairo_int_status_t;
#define _cairo_status_is_error(status) \
(status != CAIRO_STATUS_SUCCESS && status < CAIRO_STATUS_LAST_STATUS)
@ -107,7 +113,7 @@ static inline cairo_status_t
_cairo_public_status (cairo_int_status_t status)
{
assert (status <= CAIRO_INT_STATUS_LAST_STATUS);
return status;
return (cairo_status_t) status;
}
cairo_private cairo_status_t

View file

@ -40,6 +40,8 @@
#include "cairoint.h"
#include "cairo-atomic-private.h"
CAIRO_BEGIN_DECLS
#if HAS_ATOMIC_OPS
/* Keep a stash of recently freed clip_paths, since we need to
* reallocate them frequently.
@ -130,4 +132,6 @@ typedef int freed_pool_t;
#endif
CAIRO_END_DECLS
#endif /* CAIRO_FREED_POOL_PRIVATE_H */

View file

@ -55,24 +55,6 @@ cairo_skia_surface_create_for_data (unsigned char *data,
int height,
int stride);
cairo_public unsigned char *
cairo_skia_surface_get_data (cairo_surface_t *surface);
cairo_public cairo_format_t
cairo_skia_surface_get_format (cairo_surface_t *surface);
cairo_public int
cairo_skia_surface_get_width (cairo_surface_t *surface);
cairo_public int
cairo_skia_surface_get_height (cairo_surface_t *surface);
cairo_public int
cairo_skia_surface_get_stride (cairo_surface_t *surface);
cairo_public cairo_surface_t *
cairo_skia_surface_get_image (cairo_surface_t *surface);
CAIRO_END_DECLS
#else

View file

@ -44,6 +44,8 @@
#include "cairo-list-private.h"
#include "cairo-reference-count-private.h"
CAIRO_BEGIN_DECLS
/**
* SECTION:cairo-types
* @Title: Types
@ -225,12 +227,6 @@ typedef enum _cairo_paginated_mode {
CAIRO_PAGINATED_MODE_FALLBACK /* paint fallback images */
} cairo_paginated_mode_t;
/* Sure wish C had a real enum type so that this would be distinct
* from #cairo_status_t. Oh well, without that, I'll use this bogus 100
* offset. We want to keep it fit in int8_t as the compiler may choose
* that for #cairo_status_t */
typedef enum _cairo_int_status cairo_int_status_t;
typedef enum _cairo_internal_surface_type {
CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT = 0x1000,
CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED,
@ -419,4 +415,7 @@ typedef struct _cairo_scaled_glyph {
void *surface_private; /* for the surface backend */
} cairo_scaled_glyph_t;
CAIRO_END_DECLS
#endif /* CAIRO_TYPES_PRIVATE_H */

View file

@ -71,6 +71,7 @@
#include <pixman.h>
#include "cairo-compiler-private.h"
#include "cairo-error-private.h"
#if CAIRO_HAS_PS_SURFACE || CAIRO_HAS_SCRIPT_SURFACE || CAIRO_HAS_XML_SURFACE
#define CAIRO_HAS_DEFLATE_STREAM 1

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,110 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2005 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
* The Original Code is the cairo graphics library.
*
* The Initial Developer of the Original Code is Red Hat, Inc.
*
* Contributor(s):
* Carl D. Worth <cworth@redhat.com>
*/
#ifndef CAIRO_SKIA_CONTEXT_PRIVATE_H
#define CAIRO_SKIA_CONTEXT_PRIVATE_H
#include "cairo-private.h"
#include "cairo-image-surface-private.h"
#include <SkBitmap.h>
#include <SkCanvas.h>
#include <SkPaint.h>
#include <SkPath.h>
typedef struct _cairo_skia_context cairo_skia_context_t;
typedef struct _cairo_skia_surface cairo_skia_surface_t;
struct _cairo_skia_context {
cairo_t base;
cairo_skia_surface_t *original;
cairo_skia_surface_t *target;
cairo_matrix_t matrix;
SkCanvas *canvas;
SkPaint *paint;
SkPath *path;
cairo_surface_t *source;
cairo_image_surface_t *source_image;
void *source_extra;
};
struct _cairo_skia_surface {
cairo_image_surface_t image;
SkBitmap *bitmap;
};
static inline bool
format_to_sk_config (cairo_format_t format,
SkBitmap::Config& config,
bool& opaque)
{
opaque = false;
switch (format) {
case CAIRO_FORMAT_ARGB32:
config = SkBitmap::kARGB_8888_Config;
break;
case CAIRO_FORMAT_RGB24:
config = SkBitmap::kARGB_8888_Config;
opaque = true;
break;
case CAIRO_FORMAT_RGB16_565:
config = SkBitmap::kRGB_565_Config;
opaque = true;
break;
case CAIRO_FORMAT_A8:
config = SkBitmap::kA8_Config;
break;
case CAIRO_FORMAT_A1:
config = SkBitmap::kA1_Config;
break;
case CAIRO_FORMAT_RGB30:
case CAIRO_FORMAT_INVALID:
default:
return false;
}
return true;
}
cairo_private cairo_t *
_cairo_skia_context_create (void *target);
#endif /* CAIRO_SKIA_CONTEXT_PRIVATE_H */

View file

@ -0,0 +1,525 @@
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2007 Mozilla Corporation
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
* The Original Code is the cairo graphics library.
*
* The Initial Developer of the Original Code is Mozilla Corporation.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@mozilla.com>
*/
#include "cairoint.h"
#include "cairo-skia.h"
#include "cairo-skia-private.h"
#include "cairo-composite-rectangles-private.h"
#include "cairo-error-private.h"
static cairo_skia_surface_t *
_cairo_skia_surface_create_internal (SkBitmap::Config config,
bool opaque,
unsigned char *data,
int width,
int height,
int stride);
static cairo_surface_t *
_cairo_skia_surface_create_similar (void *asurface,
cairo_content_t content,
int width,
int height)
{
cairo_skia_surface_t *surface = (cairo_skia_surface_t *) asurface;
SkBitmap::Config config;
bool opaque;
if (content == surface->image.base.content)
{
config = surface->bitmap->getConfig ();
opaque = surface->bitmap->isOpaque ();
}
else if (! format_to_sk_config (_cairo_format_from_content (content),
config, opaque))
{
return NULL;
}
return &_cairo_skia_surface_create_internal (config, opaque,
NULL,
width, height,
0)->image.base;
}
static cairo_status_t
_cairo_skia_surface_finish (void *asurface)
{
cairo_skia_surface_t *surface = (cairo_skia_surface_t *) asurface;
cairo_surface_finish (&surface->image.base);
delete surface->bitmap;
return CAIRO_STATUS_SUCCESS;
}
static cairo_surface_t *
_cairo_skia_surface_map_to_image (void *asurface,
const cairo_rectangle_int_t *extents)
{
cairo_skia_surface_t *surface = (cairo_skia_surface_t *) asurface;
surface->bitmap->lockPixels ();
if (extents->width < surface->image.width ||
extents->height < surface->image.height)
{
return _cairo_surface_create_for_rectangle_int (&surface->image.base,
extents);
}
return cairo_surface_reference (&surface->image.base);
}
static cairo_int_status_t
_cairo_skia_surface_unmap_image (void *asurface,
cairo_image_surface_t *image)
{
cairo_skia_surface_t *surface = (cairo_skia_surface_t *) asurface;
surface->bitmap->unlockPixels ();
return CAIRO_INT_STATUS_SUCCESS;
}
static cairo_status_t
_cairo_skia_surface_acquire_source_image (void *asurface,
cairo_image_surface_t **image_out,
void **image_extra)
{
cairo_skia_surface_t *surface = (cairo_skia_surface_t *) asurface;
surface->bitmap->lockPixels ();
*image_out = &surface->image;
*image_extra = NULL;
return CAIRO_STATUS_SUCCESS;
}
static void
_cairo_skia_surface_release_source_image (void *asurface,
cairo_image_surface_t *image,
void *image_extra)
{
cairo_skia_surface_t *surface = (cairo_skia_surface_t *) asurface;
surface->bitmap->unlockPixels ();
}
static cairo_bool_t
_cairo_skia_surface_get_extents (void *asurface,
cairo_rectangle_int_t *extents)
{
cairo_skia_surface_t *surface = (cairo_skia_surface_t *) asurface;
extents->x = extents->y = 0;
extents->width = surface->image.width;
extents->height = surface->image.height;
return TRUE;
}
static void
_cairo_skia_surface_get_font_options (void *abstract_surface,
cairo_font_options_t *options)
{
_cairo_font_options_init_default (options);
cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
_cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_ON);
}
static cairo_rectangle_t *
to_rectangle (cairo_rectangle_t *rf,
cairo_rectangle_int_t *ri)
{
rf->x = ri->x;
rf->y = ri->y;
rf->width = ri->width;
rf->height = ri->height;
return rf;
}
static cairo_int_status_t
_cairo_foreign_surface_paint (void *abstract_surface,
cairo_operator_t op,
const cairo_pattern_t *source,
const cairo_clip_t *clip)
{
cairo_surface_t *surface = (cairo_surface_t *) abstract_surface;
cairo_surface_t *image;
cairo_rectangle_int_t extents;
cairo_rectangle_t rect;
cairo_composite_rectangles_t composite;
cairo_int_status_t status;
_cairo_surface_get_extents (surface, &extents);
status = _cairo_composite_rectangles_init_for_paint (&composite, &extents,
op, source,
clip);
if (unlikely (status))
return status;
image = cairo_surface_map_to_image (surface,
to_rectangle(&rect, &composite.unbounded));
status = (cairo_int_status_t)
_cairo_surface_paint (image, op, source, clip);
cairo_surface_unmap_image (surface, image);
_cairo_composite_rectangles_fini (&composite);
return status;
}
static cairo_int_status_t
_cairo_foreign_surface_mask (void *abstract_surface,
cairo_operator_t op,
const cairo_pattern_t *source,
const cairo_pattern_t *mask,
const cairo_clip_t *clip)
{
cairo_surface_t *surface =(cairo_surface_t *) abstract_surface;
cairo_surface_t *image;
cairo_rectangle_int_t extents;
cairo_rectangle_t rect;
cairo_composite_rectangles_t composite;
cairo_int_status_t status;
_cairo_surface_get_extents (surface, &extents);
status = _cairo_composite_rectangles_init_for_mask (&composite, &extents,
op, source, mask,
clip);
if (unlikely (status))
return status;
image = cairo_surface_map_to_image (surface,
to_rectangle(&rect, &composite.unbounded));
status = (cairo_int_status_t)
_cairo_surface_mask (image, op, source, mask, clip);
cairo_surface_unmap_image (surface, image);
_cairo_composite_rectangles_fini (&composite);
return status;
}
static cairo_int_status_t
_cairo_foreign_surface_stroke (void *abstract_surface,
cairo_operator_t op,
const cairo_pattern_t *source,
const cairo_path_fixed_t *path,
const cairo_stroke_style_t*style,
const cairo_matrix_t *ctm,
const cairo_matrix_t *ctm_inverse,
double tolerance,
cairo_antialias_t antialias,
const cairo_clip_t *clip)
{
cairo_surface_t *surface =(cairo_surface_t *) abstract_surface;
cairo_surface_t *image;
cairo_composite_rectangles_t composite;
cairo_rectangle_int_t extents;
cairo_rectangle_t rect;
cairo_int_status_t status;
_cairo_surface_get_extents (surface, &extents);
status = _cairo_composite_rectangles_init_for_stroke (&composite, &extents,
op, source,
path, style, ctm,
clip);
if (unlikely (status))
return status;
image = cairo_surface_map_to_image (surface,
to_rectangle(&rect, &composite.unbounded));
status = (cairo_int_status_t)
_cairo_surface_stroke (image, op, source, path, style, ctm, ctm_inverse, tolerance, antialias, clip);
cairo_surface_unmap_image (surface, image);
_cairo_composite_rectangles_fini (&composite);
return status;
}
static cairo_int_status_t
_cairo_foreign_surface_fill (void *abstract_surface,
cairo_operator_t op,
const cairo_pattern_t *source,
const cairo_path_fixed_t *path,
cairo_fill_rule_t fill_rule,
double tolerance,
cairo_antialias_t antialias,
const cairo_clip_t *clip)
{
cairo_surface_t *surface =(cairo_surface_t *) abstract_surface;
cairo_surface_t *image;
cairo_composite_rectangles_t composite;
cairo_rectangle_int_t extents;
cairo_rectangle_t rect;
cairo_int_status_t status;
_cairo_surface_get_extents (surface, &extents);
status = _cairo_composite_rectangles_init_for_fill (&composite, &extents,
op, source, path,
clip);
if (unlikely (status))
return status;
image = cairo_surface_map_to_image (surface,
to_rectangle(&rect, &composite.unbounded));
status = (cairo_int_status_t)
_cairo_surface_fill (image, op, source, path, fill_rule, tolerance, antialias, clip);
cairo_surface_unmap_image (surface, image);
_cairo_composite_rectangles_fini (&composite);
return status;
}
static cairo_int_status_t
_cairo_foreign_surface_glyphs (void *abstract_surface,
cairo_operator_t op,
const cairo_pattern_t *source,
cairo_glyph_t *glyphs,
int num_glyphs,
cairo_scaled_font_t *scaled_font,
const cairo_clip_t *clip,
int *num_remaining)
{
cairo_surface_t *surface =(cairo_surface_t *) abstract_surface;
cairo_surface_t *image;
cairo_composite_rectangles_t composite;
cairo_rectangle_int_t extents;
cairo_rectangle_t rect;
cairo_int_status_t status;
cairo_bool_t overlap;
_cairo_surface_get_extents (surface, &extents);
status = _cairo_composite_rectangles_init_for_glyphs (&composite, &extents,
op, source,
scaled_font,
glyphs, num_glyphs,
clip,
&overlap);
if (unlikely (status))
return status;
image = cairo_surface_map_to_image (surface,
to_rectangle(&rect, &composite.unbounded));
status = (cairo_int_status_t)
_cairo_surface_show_text_glyphs (image,
op, source,
NULL, 0,
glyphs, num_glyphs,
NULL, 0, (cairo_text_cluster_flags_t)0,
scaled_font,
clip);
cairo_surface_unmap_image (surface, image);
_cairo_composite_rectangles_fini (&composite);
*num_remaining = 0;
return status;
}
static const struct _cairo_surface_backend
cairo_skia_surface_backend = {
CAIRO_SURFACE_TYPE_SKIA,
_cairo_skia_surface_finish,
_cairo_skia_context_create,
_cairo_skia_surface_create_similar,
NULL, //_cairo_skia_surface_create_similar_image,
_cairo_skia_surface_map_to_image,
_cairo_skia_surface_unmap_image,
_cairo_skia_surface_acquire_source_image,
_cairo_skia_surface_release_source_image,
NULL, NULL,
NULL, /* clone similar */
NULL, /* composite */
NULL, /* fill_rectangles */
NULL, /* composite_trapezoids */
NULL, /* create_span_renderer */
NULL, /* check_span_renderer */
NULL, /* copy_page */
NULL, /* show_page */
_cairo_skia_surface_get_extents,
NULL, /* old_show_glyphs */
_cairo_skia_surface_get_font_options,
NULL, /* flush */
NULL, /* mark_dirty_rectangle */
NULL, /* scaled_font_fini */
NULL, /* scaled_glyph_fini */
/* XXX native surface functions? */
_cairo_foreign_surface_paint,
_cairo_foreign_surface_mask,
_cairo_foreign_surface_stroke,
_cairo_foreign_surface_fill,
_cairo_foreign_surface_glyphs
};
/*
* Surface constructors
*/
static inline pixman_format_code_t
sk_config_to_pixman_format_code (SkBitmap::Config config,
bool opaque)
{
switch (config) {
case SkBitmap::kARGB_8888_Config:
return opaque ? PIXMAN_x8r8g8b8 : PIXMAN_a8r8g8b8;
case SkBitmap::kA8_Config:
return PIXMAN_a8;
case SkBitmap::kA1_Config:
return PIXMAN_a1;
case SkBitmap::kRGB_565_Config:
return PIXMAN_r5g6b5;
case SkBitmap::kARGB_4444_Config:
return PIXMAN_a4r4g4b4;
case SkBitmap::kNo_Config:
case SkBitmap::kIndex8_Config:
case SkBitmap::kRLE_Index8_Config:
case SkBitmap::kConfigCount:
default:
ASSERT_NOT_REACHED;
return (pixman_format_code_t) -1;
}
}
static cairo_skia_surface_t *
_cairo_skia_surface_create_internal (SkBitmap::Config config,
bool opaque,
unsigned char *data,
int width,
int height,
int stride)
{
cairo_skia_surface_t *surface;
pixman_image_t *pixman_image;
pixman_format_code_t pixman_format;
surface = (cairo_skia_surface_t *) malloc (sizeof (cairo_skia_surface_t));
if (unlikely (surface == NULL))
return (cairo_skia_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
pixman_format = sk_config_to_pixman_format_code (config, opaque);
pixman_image = pixman_image_create_bits (pixman_format,
width, height,
(uint32_t *) data, stride);
if (unlikely (pixman_image == NULL))
return (cairo_skia_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
_cairo_surface_init (&surface->image.base,
&cairo_skia_surface_backend,
NULL, /* device */
_cairo_content_from_pixman_format (pixman_format));
_cairo_image_surface_init (&surface->image, pixman_image, pixman_format);
surface->bitmap = new SkBitmap;
surface->bitmap->setConfig (config, width, height, surface->image.stride);
surface->bitmap->setIsOpaque (opaque);
surface->bitmap->setPixels (surface->image.data);
surface->image.base.is_clear = data == NULL;
return surface;
}
cairo_surface_t *
cairo_skia_surface_create (cairo_format_t format,
int width,
int height)
{
SkBitmap::Config config;
bool opaque;
if (! CAIRO_FORMAT_VALID (format) ||
! format_to_sk_config (format, config, opaque))
{
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
}
return &_cairo_skia_surface_create_internal (config, opaque, NULL, width, height, 0)->image.base;
}
cairo_surface_t *
cairo_skia_surface_create_for_data (unsigned char *data,
cairo_format_t format,
int width,
int height,
int stride)
{
SkBitmap::Config config;
bool opaque;
if (! CAIRO_FORMAT_VALID (format) ||
! format_to_sk_config (format, config, opaque))
{
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
}
return &_cairo_skia_surface_create_internal (config, opaque, data, width, height, stride)->image.base;
}
/***
Todo:
*** Skia:
- mask()
*** Sk:
High:
- antialiased clipping?
Medium:
- implement clip path reset (to avoid restore/save)
- implement complex radial patterns (2 centers and 2 radii)
Low:
- implement EXTEND_NONE
***/

View file

@ -433,8 +433,8 @@ run:
check-valgrind:
$(MAKE) $(AM_MAKEFLAGS) check TESTS_ENVIRONMENT='$(TESTS_ENVIRONMENT) CAIRO_TEST_MODE="$(MODE),foreground CAIRO_TEST_TIMEOUT=0" $(top_builddir)/libtool --mode=execute valgrind $(VALGRIND_FLAGS)' 2>&1 | tee valgrind-log
%.log: %.c cairo-test-suite
-./cairo-test-suite $(<:.c=)
#%.log: %.c cairo-test-suite
#-./cairo-test-suite $(<:.c=)
NOLOG_TESTS_LOG = $(NOLOG_TESTS:=.log)