separate c headers

BUG=skia:

Review URL: https://codereview.chromium.org/728323002
This commit is contained in:
reed 2014-11-17 06:15:42 -08:00 committed by Commit bot
parent 1379b87ae4
commit 73c2501120
8 changed files with 297 additions and 96 deletions

33
include/c/sk_canvas.h Normal file
View File

@ -0,0 +1,33 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
// DO NOT USE -- FOR INTERNAL TESTING ONLY
#ifndef sk_canvas_DEFINED
#define sk_canvas_DEFINED
#include "sk_types.h"
SK_C_PLUS_PLUS_BEGIN_GUARD
void sk_canvas_save(sk_canvas_t*);
void sk_canvas_save_layer(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
void sk_canvas_restore(sk_canvas_t*);
void sk_canvas_translate(sk_canvas_t*, float dx, float dy);
void sk_canvas_scale(sk_canvas_t*, float sx, float sy);
void sk_canvas_draw_paint(sk_canvas_t*, const sk_paint_t*);
void sk_canvas_draw_rect(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
void sk_canvas_draw_oval(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
void sk_canvas_draw_path(sk_canvas_t*, const sk_path_t*, const sk_paint_t*);
void sk_canvas_draw_image(sk_canvas_t*, const sk_image_t*, float x, float y, const sk_paint_t*);
SK_C_PLUS_PLUS_END_GUARD
#endif

31
include/c/sk_image.h Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
// DO NOT USE -- FOR INTERNAL TESTING ONLY
#ifndef sk_image_DEFINED
#define sk_image_DEFINED
#include "sk_types.h"
SK_C_PLUS_PLUS_BEGIN_GUARD
/**
* Return a new image that has made a copy of the provided pixels, or NULL on failure.
* Balance with a call to sk_image_unref().
*/
sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, size_t rowBytes);
void sk_image_ref(const sk_image_t*);
void sk_image_unref(const sk_image_t*);
int sk_image_get_width(const sk_image_t*);
int sk_image_get_height(const sk_image_t*);
uint32_t sk_image_get_unique_id(const sk_image_t*);
SK_C_PLUS_PLUS_END_GUARD
#endif

27
include/c/sk_paint.h Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
// DO NOT USE -- FOR INTERNAL TESTING ONLY
#ifndef sk_paint_DEFINED
#define sk_paint_DEFINED
#include "sk_types.h"
SK_C_PLUS_PLUS_BEGIN_GUARD
sk_paint_t* sk_paint_new();
void sk_paint_delete(sk_paint_t*);
bool sk_paint_is_antialias(const sk_paint_t*);
void sk_paint_set_antialias(sk_paint_t*, bool);
sk_color_t sk_paint_get_color(const sk_paint_t*);
void sk_paint_set_color(sk_paint_t*, sk_color_t);
SK_C_PLUS_PLUS_END_GUARD
#endif

45
include/c/sk_path.h Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
// DO NOT USE -- FOR INTERNAL TESTING ONLY
#ifndef sk_path_DEFINED
#define sk_path_DEFINED
#include "sk_types.h"
SK_C_PLUS_PLUS_BEGIN_GUARD
typedef enum {
CW_SK_PATH_DIRECTION,
CCW_SK_PATH_DIRECTION,
} sk_path_direction_t;
sk_path_t* sk_path_new();
void sk_path_delete(sk_path_t*);
void sk_path_move_to(sk_path_t*, float x, float y);
void sk_path_line_to(sk_path_t*, float x, float y);
void sk_path_quad_to(sk_path_t*, float x0, float y0, float x1, float y1);
void sk_path_conic_to(sk_path_t*, float x0, float y0, float x1, float y1, float w);
void sk_path_cubic_to(sk_path_t*, float x0, float y0, float x1, float y1, float x2, float y2);
void sk_path_close(sk_path_t*);
void sk_path_add_rect(sk_path_t*, const sk_rect_t*, sk_path_direction_t);
void sk_path_add_oval(sk_path_t*, const sk_rect_t*, sk_path_direction_t);
/**
* If the path is empty, return false and set the rect parameter to [0, 0, 0, 0].
* else return true and set the rect parameter to the bounds of the control-points
* of the path.
*/
bool sk_path_get_bounds(const sk_path_t*, sk_rect_t*);
SK_C_PLUS_PLUS_END_GUARD
#endif

View File

@ -8,103 +8,12 @@
// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
// DO NOT USE -- FOR INTERNAL TESTING ONLY
#ifndef sk_types_DEFINED
#define sk_types_DEFINED
#ifndef sk_surface_DEFINED
#define sk_surface_DEFINED
#include <stdint.h>
#include <stddef.h>
#include "sk_types.h"
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef uint32_t sk_color_t;
#define sk_color_set_argb(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
#define sk_color_get_a(c) (((c) >> 24) & 0xFF)
#define sk_color_get_r(c) (((c) >> 16) & 0xFF)
#define sk_color_get_g(c) (((c) >> 8) & 0xFF)
#define sk_color_get_b(c) (((c) >> 0) & 0xFF)
typedef enum {
UNKNOWN_SK_COLORTYPE,
RGBA_8888_SK_COLORTYPE,
BGRA_8888_SK_COLORTYPE,
ALPHA_8_SK_COLORTYPE,
} sk_colortype_t;
typedef enum {
OPAQUE_SK_ALPHATYPE,
PREMUL_SK_ALPHATYPE,
UNPREMUL_SK_ALPHATYPE,
} sk_alphatype_t;
sk_colortype_t sk_colortype_get_default_8888();
typedef struct {
int32_t width;
int32_t height;
sk_colortype_t colorType;
sk_alphatype_t alphaType;
} sk_imageinfo_t;
typedef struct {
float left;
float top;
float right;
float bottom;
} sk_rect_t;
typedef struct sk_path_t sk_path_t;
sk_path_t* sk_path_new();
void sk_path_delete(sk_path_t*);
void sk_path_move_to(sk_path_t*, float x, float y);
void sk_path_line_to(sk_path_t*, float x, float y);
void sk_path_quad_to(sk_path_t*, float x0, float y0, float x1, float y1);
void sk_path_close(sk_path_t*);
typedef struct sk_paint_t sk_paint_t;
sk_paint_t* sk_paint_new();
void sk_paint_delete(sk_paint_t*);
bool sk_paint_is_antialias(const sk_paint_t*);
void sk_paint_set_antialias(sk_paint_t*, bool);
sk_color_t sk_paint_get_color(const sk_paint_t*);
void sk_paint_set_color(sk_paint_t*, sk_color_t);
typedef struct sk_canvas_t sk_canvas_t;
typedef struct sk_image_t sk_image_t;
void sk_canvas_save(sk_canvas_t*);
void sk_canvas_save_layer(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
void sk_canvas_restore(sk_canvas_t*);
void sk_canvas_translate(sk_canvas_t*, float dx, float dy);
void sk_canvas_scale(sk_canvas_t*, float sx, float sy);
void sk_canvas_draw_paint(sk_canvas_t*, const sk_paint_t*);
void sk_canvas_draw_rect(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
void sk_canvas_draw_oval(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
void sk_canvas_draw_path(sk_canvas_t*, const sk_path_t*, const sk_paint_t*);
void sk_canvas_draw_image(sk_canvas_t*, const sk_image_t*, float x, float y, const sk_paint_t*);
/**
* Return a new image that has made a copy of the provided pixels, or NULL on failure.
* Balance with a call to sk_image_unref().
*/
sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, size_t rowBytes);
void sk_image_ref(const sk_image_t*);
void sk_image_unref(const sk_image_t*);
int sk_image_get_width(const sk_image_t*);
int sk_image_get_height(const sk_image_t*);
uint32_t sk_image_get_unique_id(const sk_image_t*);
typedef struct sk_surface_t sk_surface_t;
SK_C_PLUS_PLUS_BEGIN_GUARD
sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t*);
sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t*, void* pixels, size_t rowBytes);
@ -115,12 +24,17 @@ void sk_surface_delete(sk_surface_t*);
* so the returned object is only valid while the owning surface is valid.
*/
sk_canvas_t* sk_surface_get_canvas(sk_surface_t*);
/**
* Call sk_image_unref() when the returned image is no longer used.
*/
sk_image_t* sk_surface_new_image_snapshot(sk_surface_t*);
#ifdef __cplusplus
class SkCanvas;
void sk_test_capi(SkCanvas*);
}
#endif
SK_C_PLUS_PLUS_END_GUARD
#endif

82
include/c/sk_types.h Normal file
View File

@ -0,0 +1,82 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
// DO NOT USE -- FOR INTERNAL TESTING ONLY
#ifndef sk_types_DEFINED
#define sk_types_DEFINED
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
#define SK_C_PLUS_PLUS_BEGIN_GUARD extern "C" {
#define SK_C_PLUS_PLUS_END_GUARD }
#else
#include <stdbool.h>
#define SK_C_PLUS_PLUS_BEGIN_GUARD
#define SK_C_PLUS_PLUS_END_GUARD
#endif
///////////////////////////////////////////////////////////////////////////////////////
SK_C_PLUS_PLUS_BEGIN_GUARD
typedef uint32_t sk_color_t;
#define sk_color_set_argb(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
#define sk_color_get_a(c) (((c) >> 24) & 0xFF)
#define sk_color_get_r(c) (((c) >> 16) & 0xFF)
#define sk_color_get_g(c) (((c) >> 8) & 0xFF)
#define sk_color_get_b(c) (((c) >> 0) & 0xFF)
typedef enum {
UNKNOWN_SK_COLORTYPE,
RGBA_8888_SK_COLORTYPE,
BGRA_8888_SK_COLORTYPE,
ALPHA_8_SK_COLORTYPE,
} sk_colortype_t;
typedef enum {
OPAQUE_SK_ALPHATYPE,
PREMUL_SK_ALPHATYPE,
UNPREMUL_SK_ALPHATYPE,
} sk_alphatype_t;
sk_colortype_t sk_colortype_get_default_8888();
typedef struct {
int32_t width;
int32_t height;
sk_colortype_t colorType;
sk_alphatype_t alphaType;
} sk_imageinfo_t;
typedef struct {
float left;
float top;
float right;
float bottom;
} sk_rect_t;
typedef struct sk_canvas_t sk_canvas_t;
typedef struct sk_image_t sk_image_t;
typedef struct sk_paint_t sk_paint_t;
typedef struct sk_path_t sk_path_t;
typedef struct sk_surface_t sk_surface_t;
//////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
class SkCanvas;
void sk_test_capi(SkCanvas*);
#endif
SK_C_PLUS_PLUS_END_GUARD
#endif

View File

@ -5,6 +5,10 @@
* found in the LICENSE file.
*/
#include "sk_canvas.h"
#include "sk_image.h"
#include "sk_paint.h"
#include "sk_path.h"
#include "sk_surface.h"
#include "SkCanvas.h"
@ -87,10 +91,34 @@ static bool from_c_info(const sk_imageinfo_t& cinfo, SkImageInfo* info) {
return true;
}
const struct {
sk_path_direction_t fC;
SkPath::Direction fSk;
} gPathDirMap[] = {
{ CW_SK_PATH_DIRECTION, SkPath::kCW_Direction },
{ CCW_SK_PATH_DIRECTION, SkPath::kCCW_Direction },
};
static bool from_c_path_direction(sk_path_direction_t cdir, SkPath::Direction* dir) {
for (size_t i = 0; i < SK_ARRAY_COUNT(gPathDirMap); ++i) {
if (gPathDirMap[i].fC == cdir) {
if (dir) {
*dir = gPathDirMap[i].fSk;
}
return true;
}
}
return false;
}
static const SkRect& AsRect(const sk_rect_t& crect) {
return reinterpret_cast<const SkRect&>(crect);
}
static SkRect* as_rect(sk_rect_t* crect) {
return reinterpret_cast<SkRect*>(crect);
}
static const SkPath& AsPath(const sk_path_t& cpath) {
return reinterpret_cast<const SkPath&>(cpath);
}
@ -208,10 +236,48 @@ void sk_path_quad_to(sk_path_t* cpath, float x0, float y0, float x1, float y1) {
as_path(cpath)->quadTo(x0, y0, x1, y1);
}
void sk_path_conic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float w) {
as_path(cpath)->conicTo(x0, y0, x1, y1, w);
}
void sk_path_cubic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float x2, float y2) {
as_path(cpath)->cubicTo(x0, y0, x1, y1, x2, y2);
}
void sk_path_close(sk_path_t* cpath) {
as_path(cpath)->close();
}
void sk_path_add_rect(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir) {
SkPath::Direction dir;
if (!from_c_path_direction(cdir, &dir)) {
return;
}
as_path(cpath)->addRect(AsRect(*crect), dir);
}
void sk_path_add_oval(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir) {
SkPath::Direction dir;
if (!from_c_path_direction(cdir, &dir)) {
return;
}
as_path(cpath)->addOval(AsRect(*crect), dir);
}
bool sk_path_get_bounds(const sk_path_t* cpath, sk_rect_t* crect) {
const SkPath& path = AsPath(*cpath);
SkRect* rect = as_rect(crect);
if (path.isEmpty()) {
if (rect) {
rect->setEmpty();
}
return false;
}
*rect = path.getBounds();
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
void sk_canvas_save(sk_canvas_t* ccanvas) {

View File

@ -5,7 +5,10 @@
* found in the LICENSE file.
*/
#include "sk_canvas.h"
#include "sk_paint.h"
#include "sk_surface.h"
#include "Test.h"
static void test_c(skiatest::Reporter* reporter) {