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
diff --git a/example/HelloWorld.h b/example/HelloWorld.h
index a1508c5..ef4e417 100644
--- a/example/HelloWorld.h
+++ b/example/HelloWorld.h
@@ -34,14 +34,14 @@
protected:
SkSurface* createSurface() override {
+ SkSurfaceProps props(INHERITED::getSurfaceProps());
if (kGPU_DeviceType == fType) {
- SkSurfaceProps props(INHERITED::getSurfaceProps());
return SkSurface::NewRenderTargetDirect(fRenderTarget, &props);
}
static const SkImageInfo info = SkImageInfo::MakeN32Premul(
SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this->height()));
- return fSurface = SkSurface::NewRaster(info);
- }
+ return fSurface = SkSurface::NewRaster(info, &props);
+ }
void draw(SkCanvas* canvas) override;
void drawContents(SkCanvas* canvas);
diff --git a/gm/cgm.c b/gm/cgm.c
index 7d09faf..5e57225 100644
--- a/gm/cgm.c
+++ b/gm/cgm.c
@@ -53,7 +53,8 @@
sk_imageinfo_t info = {
W, H, sk_colortype_get_default_8888(), OPAQUE_SK_ALPHATYPE
};
- sk_surface_t* surf = sk_surface_new_raster(&info);
+ sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY };
+ sk_surface_t* surf = sk_surface_new_raster(&info, &surfaceProps);
do_draw(sk_surface_get_canvas(surf));
sk_image_t* img0 = sk_surface_new_image_snapshot(surf);
diff --git a/include/c/sk_surface.h b/include/c/sk_surface.h
index ce7a568..76fc5b6 100644
--- a/include/c/sk_surface.h
+++ b/include/c/sk_surface.h
@@ -15,8 +15,9 @@
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);
+sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t*, const sk_surfaceprops_t*);
+sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t*, void* pixels, size_t rowBytes,
+ const sk_surfaceprops_t* props);
void sk_surface_unref(sk_surface_t*);
/**
diff --git a/include/c/sk_types.h b/include/c/sk_types.h
index 00632e0..17ba929 100644
--- a/include/c/sk_types.h
+++ b/include/c/sk_types.h
@@ -53,6 +53,14 @@
DIFFERENCE_SK_CLIPTYPE,
} sk_cliptype_t;
+typedef enum {
+ UNKNOWN_SK_PIXELGEOMETRY,
+ RGB_H_SK_PIXELGEOMETRY,
+ BGR_H_SK_PIXELGEOMETRY,
+ RGB_V_SK_PIXELGEOMETRY,
+ BGR_V_SK_PIXELGEOMETRY,
+} sk_pixelgeometry_t;
+
sk_colortype_t sk_colortype_get_default_8888();
typedef struct {
@@ -63,6 +71,10 @@
} sk_imageinfo_t;
typedef struct {
+ sk_pixelgeometry_t pixelGeometry;
+} sk_surfaceprops_t;
+
+typedef struct {
float x;
float y;
} sk_point_t;
diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp
index 280897b..5b6210d 100644
--- a/src/c/sk_surface.cpp
+++ b/src/c/sk_surface.cpp
@@ -96,6 +96,30 @@
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 @@
///////////////////////////////////////////////////////////////////////////////////////////
-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 @@
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();
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp
index 28b972b..4e0ba08 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -109,7 +109,7 @@
}
SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) {
- return SkSurface::NewRaster(info);
+ return SkSurface::NewRaster(info, &this->props());
}
void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index cee4d4d..b0e7b8f 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -1993,7 +1993,8 @@
int width = lua2int_def(L, 1, 0);
int height = lua2int_def(L, 2, 0);
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
- SkSurface* surface = SkSurface::NewRaster(info);
+ SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
+ SkSurface* surface = SkSurface::NewRaster(info, &props);
if (NULL == surface) {
lua_pushnil(L);
} else {
diff --git a/tests/CTest.cpp b/tests/CTest.cpp
index 81702ac..413f629 100644
--- a/tests/CTest.cpp
+++ b/tests/CTest.cpp
@@ -18,8 +18,10 @@
1, 1, ct, PREMUL_SK_ALPHATYPE
};
uint32_t pixel[1] = { 0 };
+ sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY };
- sk_surface_t* surface = sk_surface_new_raster_direct(&info, pixel, sizeof(uint32_t));
+ sk_surface_t* surface = sk_surface_new_raster_direct(&info, pixel, sizeof(uint32_t),
+ &surfaceProps);
sk_paint_t* paint = sk_paint_new();
sk_canvas_t* canvas = sk_surface_get_canvas(surface);
diff --git a/tools/skhello.cpp b/tools/skhello.cpp
index 9f05434..b46ba08 100644
--- a/tools/skhello.cpp
+++ b/tools/skhello.cpp
@@ -33,7 +33,8 @@
static bool do_surface(int w, int h, const char path[], const char text[],
const SkPaint& paint) {
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(w, h));
+ SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(w, h, &props));
doDraw(surface->getCanvas(), paint, text);
SkAutoTUnref<SkImage> image(surface->newImageSnapshot());