aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/c
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2015-06-23 06:26:08 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-23 06:26:08 -0700
commit702edbd4bc41230902b5fe69d14d15763c27fafe (patch)
tree7c8f0cef358e47fdb1f6fcf08f9ecf830fcf4bad /src/c
parent0a9af33a929f937e3630cd76c5b36d92344ee06a (diff)
Propagate SkSurfaceProps to more call sites
Start moving to a world where everyone provides surface properties. Most notably this exposes a portion of SkSurfaceProps to the C API. BUG=skia:3934 Review URL: https://codereview.chromium.org/1195003003
Diffstat (limited to 'src/c')
-rw-r--r--src/c/sk_surface.cpp51
1 files changed, 46 insertions, 5 deletions
diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp
index 280897b354..5b6210d19d 100644
--- a/src/c/sk_surface.cpp
+++ b/src/c/sk_surface.cpp
@@ -96,6 +96,30 @@ static bool from_c_info(const sk_imageinfo_t& cinfo, SkImageInfo* info) {
return true;
}
+const struct {
+ sk_pixelgeometry_t fC;
+ SkPixelGeometry fSK;
+} gPixelGeometryMap[] = {
+ { UNKNOWN_SK_PIXELGEOMETRY, kUnknown_SkPixelGeometry },
+ { RGB_H_SK_PIXELGEOMETRY, kRGB_H_SkPixelGeometry },
+ { BGR_H_SK_PIXELGEOMETRY, kBGR_H_SkPixelGeometry },
+ { RGB_V_SK_PIXELGEOMETRY, kRGB_V_SkPixelGeometry },
+ { BGR_V_SK_PIXELGEOMETRY, kBGR_V_SkPixelGeometry },
+};
+
+
+static bool from_c_pixelgeometry(sk_pixelgeometry_t cGeom, SkPixelGeometry* skGeom) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gPixelGeometryMap); ++i) {
+ if (gPixelGeometryMap[i].fC == cGeom) {
+ if (skGeom) {
+ *skGeom = gPixelGeometryMap[i].fSK;
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
static void from_c_matrix(const sk_matrix_t* cmatrix, SkMatrix* matrix) {
matrix->setAll(cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2],
cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5],
@@ -391,21 +415,35 @@ void sk_canvas_draw_picture(sk_canvas_t* ccanvas, const sk_picture_t* cpicture,
///////////////////////////////////////////////////////////////////////////////////////////
-sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo) {
+sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo,
+ const sk_surfaceprops_t* props) {
SkImageInfo info;
if (!from_c_info(*cinfo, &info)) {
return NULL;
}
- return (sk_surface_t*)SkSurface::NewRaster(info);
+ SkPixelGeometry geo = kUnknown_SkPixelGeometry;
+ if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) {
+ return NULL;
+ }
+
+ SkSurfaceProps surfProps(0, geo);
+ return (sk_surface_t*)SkSurface::NewRaster(info, &surfProps);
}
sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pixels,
- size_t rowBytes) {
+ size_t rowBytes,
+ const sk_surfaceprops_t* props) {
SkImageInfo info;
if (!from_c_info(*cinfo, &info)) {
return NULL;
}
- return (sk_surface_t*)SkSurface::NewRasterDirect(info, pixels, rowBytes);
+ SkPixelGeometry geo = kUnknown_SkPixelGeometry;
+ if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) {
+ return NULL;
+ }
+
+ SkSurfaceProps surfProps(0, geo);
+ return (sk_surface_t*)SkSurface::NewRasterDirect(info, pixels, rowBytes, &surfProps);
}
void sk_surface_unref(sk_surface_t* csurf) {
@@ -596,7 +634,10 @@ void sk_test_capi(SkCanvas* canvas) {
cinfo.colorType = (sk_colortype_t)kN32_SkColorType;
cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType;
- sk_surface_t* csurface = sk_surface_new_raster(&cinfo);
+ sk_surfaceprops_t surfaceprops;
+ surfaceprops.pixelGeometry = UNKNOWN_SK_PIXELGEOMETRY;
+
+ sk_surface_t* csurface = sk_surface_new_raster(&cinfo, &surfaceprops);
sk_canvas_t* ccanvas = sk_surface_get_canvas(csurface);
sk_paint_t* cpaint = sk_paint_new();