diff options
author | robertphillips <robertphillips@google.com> | 2015-06-23 06:26:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-23 06:26:08 -0700 |
commit | 702edbd4bc41230902b5fe69d14d15763c27fafe (patch) | |
tree | 7c8f0cef358e47fdb1f6fcf08f9ecf830fcf4bad | |
parent | 0a9af33a929f937e3630cd76c5b36d92344ee06a (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
-rw-r--r-- | example/HelloWorld.h | 6 | ||||
-rw-r--r-- | gm/cgm.c | 3 | ||||
-rw-r--r-- | include/c/sk_surface.h | 5 | ||||
-rw-r--r-- | include/c/sk_types.h | 12 | ||||
-rw-r--r-- | src/c/sk_surface.cpp | 51 | ||||
-rw-r--r-- | src/image/SkSurface_Raster.cpp | 2 | ||||
-rw-r--r-- | src/utils/SkLua.cpp | 3 | ||||
-rw-r--r-- | tests/CTest.cpp | 4 | ||||
-rw-r--r-- | tools/skhello.cpp | 3 |
9 files changed, 74 insertions, 15 deletions
diff --git a/example/HelloWorld.h b/example/HelloWorld.h index a1508c582d..ef4e417ad6 100644 --- a/example/HelloWorld.h +++ b/example/HelloWorld.h @@ -34,14 +34,14 @@ public: 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); @@ -53,7 +53,8 @@ void sk_test_c_api(sk_canvas_t* canvas) { 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 ce7a568959..76fc5b6a66 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 00632e0af3..17ba92972a 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -53,6 +53,14 @@ typedef enum { 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 @@ typedef struct { } 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 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(); diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index 28b972b90c..4e0ba088b1 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp @@ -109,7 +109,7 @@ SkCanvas* SkSurface_Raster::onNewCanvas() { } 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 cee4d4ded8..b0e7b8fb92 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -1993,7 +1993,8 @@ static int lsk_newRasterSurface(lua_State* L) { 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 81702ac7d0..413f629ee3 100644 --- a/tests/CTest.cpp +++ b/tests/CTest.cpp @@ -18,8 +18,10 @@ static void test_c(skiatest::Reporter* reporter) { 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 9f054342a4..b46ba084ab 100644 --- a/tools/skhello.cpp +++ b/tools/skhello.cpp @@ -33,7 +33,8 @@ static void doDraw(SkCanvas* canvas, const SkPaint& paint, const char text[]) { 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()); |