FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Skia renderer by bjornharrtell · Pull Request #6574 · MapServer/MapServer · GitHub

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (3) .cmake  (1) .cpp  (3) .h  (2) .in  (1) .txt  (1) All 6 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
23 changes: 19 additions & 4 deletions CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ set (MapServer_VERSION_SUFFIX "")

# Set C++ version
# Make CMAKE_CXX_STANDARD available as cache option overridable by user
set(CMAKE_CXX_STANDARD 11
CACHE STRING "C++ standard version to use (default is 11)")
set(CMAKE_CXX_STANDARD 17
CACHE STRING "C++ standard version to use (default is 17)")
message(STATUS "Requiring C++${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down Expand Up @@ -155,6 +155,7 @@ option(WITH_WMS "Enable WMS Server support (requires PROJ support)" ON)
option(WITH_FRIBIDI "Choose if FriBidi glyph shaping support should be built in (usefull for right-to-left languages) (requires HARFBUZZ)" ON)
option(WITH_HARFBUZZ "Choose if Harfbuzz complex text layout should be included (needed for e.g. arabic and hindi) (requires FRIBIDI)" ON)
option(WITH_ICONV "Choose if Iconv Internationalization support should be built in" ON)
option(WITH_SKIA "Choose if Skia rendering support should be built in" ON)
option(WITH_CAIRO "Choose if CAIRO rendering support should be built in (required for SVG and PDF output)" ON)
option(WITH_SVGCAIRO "Choose if SVG symbology support (via libsvgcairo) should be built in (requires cairo, libsvg, libsvg-cairo. Incompatible with librsvg)" OFF)
option(WITH_RSVG "Choose if SVG symbology support (via librsvg) should be built in (requires cairo, librsvg. Incompatible with libsvg-cairo)" OFF)
Expand Down Expand Up @@ -326,14 +327,14 @@ src/mapraster.c src/mapuvraster.c src/mapdummyrenderer.c src/mapobject.c src/map
src/mapwcs.cpp src/maperror.c src/mapogcfilter.cpp src/mapregex.c src/mapwcs11.cpp src/mapfile.c
src/mapogcfiltercommon.cpp src/maprendering.c src/mapwcs20.cpp src/mapogcsld.cpp src/mapmetadata.c
src/mapresample.c src/mapwfs.cpp src/mapgdal.cpp src/mapogcsos.c src/mapscale.c src/mapwfs11.cpp src/mapwfs20.c
src/mapgeomtransform.c src/mapogroutput.cpp src/mapwfslayer.c src/mapagg.cpp src/mapkml.cpp
src/mapgeomtransform.c src/mapogroutput.cpp src/mapwfslayer.c src/mapagg.cpp src/mapskia.cpp src/mapkml.cpp
src/mapgeomutil.cpp src/mapkmlrenderer.cpp src/fontcache.c src/textlayout.c src/maputfgrid.cpp
src/mapogr.cpp src/mapcontour.c src/mapsmoothing.c src/mapv8.cpp ${REGEX_SOURCES} src/kerneldensity.c
src/idw.c src/interpolation.c src/mapflatgeobuf.c src/mapcompositingfilter.c src/mapmvt.c src/mapiconv.c
src/mapgraph.cpp src/mapserv-config.cpp)

set(mapserver_HEADERS
src/cgiutil.h src/dejavu-sans-condensed.h src/dxfcolor.h src/fontcache.h src/hittest.h src/mapagg.h
src/cgiutil.h src/dejavu-sans-condensed.h src/dxfcolor.h src/fontcache.h src/hittest.h src/mapagg.h src/mapskia.h
src/mapaxisorder.h src/mapcopy.h src/mapentities.h src/maperror.h src/mapfile.h src/mapgml.h src/maphash.h
src/maphttp.h src/mapio.h src/mapkmlrenderer.h src/maplibxml2.h src/mapogcfilter.h src/mapogcsld.h
src/mapoglcontext.h src/mapoglrenderer.h src/mapowscommon.h src/mapows.h src/mapparser.h src/mapogcapi.h
Expand Down Expand Up @@ -549,6 +550,19 @@ if(WITH_CAIRO)
endif(CAIRO_FOUND)
endif (WITH_CAIRO)


if(WITH_SKIA)
find_package(Skia)
if(SKIA_FOUND)
include_directories(${SKIA_INCLUDE_DIRS})
ms_link_libraries( ${SKIA_LIBRARY})
list(APPEND ALL_INCLUDE_DIRS ${SKIA_INCLUDE_DIR})
set (USE_SKIA 1)
else(SKIA_FOUND)
report_optional_not_found(SKIA)
endif(SKIA_FOUND)
endif (WITH_SKIA)

if(WITH_MYSQL)
find_package(MySQL)
if(MYSQL_FOUND)
Expand Down Expand Up @@ -959,6 +973,7 @@ status_optional_component("GIF" "${USE_GIF}" "${GIF_LIBRARY}")
status_optional_component("MYSQL" "${USE_MYSQL}" "${MYSQL_LIBRARY}")
status_optional_component("FRIBIDI" "${USE_FRIBIDI}" "${FRIBIDI_LIBRARY}")
status_optional_component("HARFBUZZ" "${USE_HARFBUZZ}" "${HARFBUZZ_LIBRARY}")
status_optional_component("SKIA" "${USE_SKIA}" "${SKIA_LIBRARY}")
status_optional_component("CAIRO" "${USE_CAIRO}" "${CAIRO_LIBRARY}")
status_optional_component("SVGCAIRO" "${USE_SVG_CAIRO}" "${SVGCAIRO_LIBRARY}")
status_optional_component("RSVG" "${USE_RSVG}" "${RSVG_LIBRARY}")
Expand Down
11 changes: 11 additions & 0 deletions cmake/FindSkia.cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Look for the header file.
find_path(SKIA_INCLUDE_DIR NAMES fastcgi.h)

# Look for the library.
find_library(SKIA_LIBRARY NAMES skia libskia)

set(SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR})
set(SKIA_LIBRARIES ${SKIA_LIBRARY})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Skia DEFAULT_MSG SKIA_LIBRARY SKIA_INCLUDE_DIR)
mark_as_advanced(SKIA_LIBRARY SKIA_INCLUDE_DIR)
3 changes: 3 additions & 0 deletions src/maperror.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ char *msGetVersion() {
strcat(version, " SUPPORTS=PROJ");
strcat(version, " SUPPORTS=AGG");
strcat(version, " SUPPORTS=FREETYPE");
#ifdef USE_SKIA
strcat(version, " SUPPORTS=SKIA");
#endif
#ifdef USE_CAIRO
strcat(version, " SUPPORTS=CAIRO");
#endif
Expand Down
28 changes: 28 additions & 0 deletions src/mapoutput.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ struct defaultOutputFormatEntry defaultoutputformats[] = {
{"png24", "AGG/PNG", "image/png; mode=24bit"},
{"jpegpng", "AGG/MIXED", "image/vnd.jpeg-png"},
{"jpegpng8", "AGG/MIXED", "image/vnd.jpeg-png8"},
#ifdef USE_SKIA
{"png","SKIA/PNG","image/png"},
{"jpeg","SKIA/JPEG","image/jpeg"},
{"png8","SKIA/PNG8","image/png; mode=8bit"},
{"png24","SKIA/PNG","image/png; mode=24bit"},
#endif
#ifdef USE_CAIRO
{"pdf", "CAIRO/PDF", "application/x-pdf"},
{"svg", "CAIRO/SVG", "image/svg+xml"},
Expand Down Expand Up @@ -211,6 +217,24 @@ outputFormatObj *msCreateDefaultOutputFormat(mapObj *map, const char *driver,
format->extension = msStrdup("jpg");
format->renderer = MS_RENDER_WITH_AGG;
}
#if defined(USE_SKIA)
else if( strcasecmp(driver,"SKIA/PNG") == 0 ) {
if(!name) name="png";
format = msAllocOutputFormat( map, name, driver );
format->mimetype = msStrdup("image/png");
format->imagemode = MS_IMAGEMODE_RGB;
format->extension = msStrdup("png");
format->renderer = MS_RENDER_WITH_SKIA;
}
else if( strcasecmp(driver,"SKIA/JPEG") == 0 ) {
if(!name) name="jpeg";
format = msAllocOutputFormat( map, name, driver );
format->mimetype = msStrdup("image/jpeg");
format->imagemode = MS_IMAGEMODE_RGB;
format->extension = msStrdup("jpg");
format->renderer = MS_RENDER_WITH_SKIA;
}
#endif
#if defined(USE_PBF)
else if (strcasecmp(driver, "MVT") == 0) {
if (!name)
Expand Down Expand Up @@ -1071,6 +1095,10 @@ int msInitializeRendererVTable(outputFormatObj *format) {
switch (format->renderer) {
case MS_RENDER_WITH_AGG:
return msPopulateRendererVTableAGG(format->vtable);
#ifdef USE_SKIA
case MS_RENDER_WITH_SKIA:
return msPopulateRendererVTableSkia(format->vtable);
#endif
case MS_RENDER_WITH_UTFGRID:
return msPopulateRendererVTableUTFGrid(format->vtable);
#ifdef USE_PBF
Expand Down
1 change: 1 addition & 0 deletions src/maprendering.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ int msDrawShadeSymbol(mapObj *map, imageObj *image, shapeObj *p,
*/
if (symbol->type == MS_SYMBOL_VECTOR && style->gap == 0 &&
(image->format->renderer == MS_RENDER_WITH_AGG ||
image->format->renderer == MS_RENDER_WITH_SKIA ||
image->format->renderer == MS_RENDER_WITH_CAIRO_RASTER)) {
seamless = 1;
}
Expand Down
1 change: 1 addition & 0 deletions src/mapserver-config.h.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#cmakedefine USE_WMS_LYR 1
#cmakedefine USE_CURL 1
#cmakedefine USE_CAIRO 1
#cmakedefine USE_SKIA 1
#cmakedefine USE_GEOS 1
#cmakedefine USE_GIF 1
#cmakedefine USE_JPEG 1
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ static __inline long int MS_NINT(double __x) {
#define MS_RENDER_WITH_KML 106
#define MS_RENDER_WITH_UTFGRID 107
#define MS_RENDER_WITH_MVT 108
#define MS_RENDER_WITH_SKIA 109

#ifndef SWIG

Expand Down Expand Up @@ -3953,6 +3954,7 @@ MS_DLL_EXPORT int msPopulateRendererVTableCairoSVG(rendererVTableObj *renderer);
MS_DLL_EXPORT int msPopulateRendererVTableCairoPDF(rendererVTableObj *renderer);
MS_DLL_EXPORT int msPopulateRendererVTableOGL(rendererVTableObj *renderer);
MS_DLL_EXPORT int msPopulateRendererVTableAGG(rendererVTableObj *renderer);
MS_DLL_EXPORT int msPopulateRendererVTableSkia(rendererVTableObj *renderer);
MS_DLL_EXPORT int msPopulateRendererVTableUTFGrid(rendererVTableObj *renderer);
MS_DLL_EXPORT int msPopulateRendererVTableKML(rendererVTableObj *renderer);
MS_DLL_EXPORT int msPopulateRendererVTableOGR(rendererVTableObj *renderer);
Expand Down
203 changes: 203 additions & 0 deletions src/mapskia.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#include "mapserver.h"
#include <include/core/SkSurface.h>
#include <include/core/SkCanvas.h>
#include <include/core/SkPath.h>

SkColor4f skiaColor(colorObj *color)
{
return SkColor4f { color->red/255.0f, color->green/255.0f, color->blue/255.0f, color->alpha/255.0f };
}

int skia2StartNewLayer(imageObj * /*img*/, mapObj * /*map*/, layerObj * /*layer*/)
{
return MS_SUCCESS;
}

int skia2CloseNewLayer(imageObj * /*img*/, mapObj * /*map*/, layerObj * /*layer*/)
{
return MS_SUCCESS;
}

imageObj *skia2CreateImage(int width, int height, outputFormatObj *format, colorObj * bg)
{
imageObj *image = NULL;
if (format->imagemode != MS_IMAGEMODE_RGB && format->imagemode != MS_IMAGEMODE_RGBA) {
msSetError(MS_MISCERR,
"Skia driver only supports RGB or RGBA pixel models.", "skia2CreateImage()");
return image;
}
if (width > 0 && height > 0) {
image = (imageObj *) calloc(1, sizeof (imageObj));
MS_CHECK_ALLOC(image, sizeof (imageObj), NULL);
SkAlphaType alpha = format->transparent ? SkAlphaType::kPremul_SkAlphaType : SkAlphaType::kOpaque_SkAlphaType;
SkColorType ct = format->transparent ? SkColorType::kRGBA_8888_SkColorType : SkColorType::kRGB_888x_SkColorType;
SkImageInfo imageInfo = SkImageInfo::Make(width, height, ct, alpha);
SkSurface *s = SkSurface::MakeRaster(imageInfo).release();
SkCanvas *c = s->getCanvas();
c->clear(skiaColor(bg));
image->img.plugin = (void*) s;
} else {
msSetError(MS_RENDERERERR, "Cannot create Skia surface of size %dx%d.",
"skia2CreateImage()", width, height);
}

return image;
}

int skia2SaveImage(imageObj * /*img*/, mapObj* /*map*/, FILE * /*fp*/, outputFormatObj * /*format*/)
{
return MS_FAILURE;
}

int skia2FreeImage(imageObj * image)
{
SkSurface *s = (SkSurface *) image->img.plugin;
delete s;
image->img.plugin = NULL;
return MS_SUCCESS;
}

void skiaRenderPath(shapeObj *p, SkCanvas *c, SkPaint &paint) {
SkPath path;
lineObj *line = p->line;
pointObj *point = line->point;
lineObj *lend = &(p->line[p->numlines]);
pointObj *pend = &(line->point[line->numpoints]);
while (1) {
path.moveTo(point->x, point->y);
point++;
while (point < pend) {
path.lineTo(point->x, point->y);
point++;
}
line++;
if (line >= lend)
break;
point = line->point;
pend = &(line->point[line->numpoints]);
}
c->drawPath(path, paint);
}

int skia2RenderLine(imageObj *image, shapeObj *p, strokeStyleObj *style)
{
SkSurface *s = (SkSurface *) image->img.plugin;
SkCanvas *c = s->getCanvas();
SkPaint paint(skiaColor(style->color));
paint.setStyle(SkPaint::Style::kStroke_Style);
paint.setStrokeWidth(style->width);
paint.setAntiAlias(style->antialiased);
skiaRenderPath(p, c, paint);
return MS_SUCCESS;
}

int skia2RenderPolygon(imageObj *image, shapeObj *p, colorObj *color)
{
SkSurface *s = (SkSurface *) image->img.plugin;
SkCanvas *c = s->getCanvas();
SkPaint paint(skiaColor(color));
paint.setStyle(SkPaint::Style::kFill_Style);
skiaRenderPath(p, c, paint);
return MS_SUCCESS;
}

int skiaInitializeRasterBuffer(rasterBufferObj *rb, int width, int height, int mode)
{
rb->type = MS_BUFFER_BYTE_RGBA;
rb->data.rgba.pixel_step = 4;
rb->data.rgba.row_step = rb->data.rgba.pixel_step * width;
rb->width = width;
rb->height = height;
int nBytes = rb->data.rgba.row_step * height;
rb->data.rgba.pixels = (unsigned char*)msSmallCalloc(nBytes,sizeof(unsigned char));
rb->data.rgba.r = &(rb->data.rgba.pixels[0]);
rb->data.rgba.g = &(rb->data.rgba.pixels[1]);
rb->data.rgba.b = &(rb->data.rgba.pixels[2]);
if(mode == MS_IMAGEMODE_RGBA)
rb->data.rgba.a = &(rb->data.rgba.pixels[3]);
return MS_SUCCESS;
}

int skiaGetRasterBufferHandle(imageObj *image, rasterBufferObj * rb)
{
SkSurface *s = (SkSurface *) image->img.plugin;
SkPixmap p;
s->peekPixels(&p);
rb->type = MS_BUFFER_BYTE_RGBA;
rb->data.rgba.pixels = (unsigned char *) p.addr();
rb->data.rgba.row_step = p.rowBytes();
rb->data.rgba.pixel_step = 4;
rb->width = s->width();
rb->height = s->height();
rb->data.rgba.r = &(rb->data.rgba.pixels[0]);
rb->data.rgba.g = &(rb->data.rgba.pixels[1]);
rb->data.rgba.b = &(rb->data.rgba.pixels[2]);
if(!s->imageInfo().isOpaque())
rb->data.rgba.a = &(rb->data.rgba.pixels[3]);
else
rb->data.rgba.a = NULL;
return MS_SUCCESS;
}

int skiaGetRasterBufferCopy(imageObj *image, rasterBufferObj *rb)
{
SkSurface *s = (SkSurface *) image->img.plugin;
SkPixmap p;
s->peekPixels(&p);
skiaInitializeRasterBuffer(rb, image->width, image->height, MS_IMAGEMODE_RGBA);
int nBytes = p.rowBytes() * p.height();
memcpy(rb->data.rgba.pixels, p.addr(), nBytes);
return MS_FAILURE;
}

int skia2FreeSymbol(symbolObj * /*symbol*/)
{
return MS_SUCCESS;
}

int msPopulateRendererVTableSkia(rendererVTableObj * renderer)
{
renderer->supports_pixel_buffer = 1;
renderer->use_imagecache = 0;
renderer->supports_clipping = 0;
renderer->supports_svg = 0;
renderer->default_transform_mode = MS_TRANSFORM_SIMPLIFY;

/*renderer->compositeRasterBuffer = &aggCompositeRasterBuffer;
agg2InitCache(&(MS_RENDERER_CACHE(renderer)));
renderer->cleanup = agg2Cleanup;

renderer->renderPolygonTiled = &agg2RenderPolygonTiled;
renderer->renderLineTiled = &agg2RenderLineTiled;

renderer->renderGlyphs = &agg2RenderGlyphsPath;

renderer->renderVectorSymbol = &agg2RenderVectorSymbol;

renderer->renderPixmapSymbol = &agg2RenderPixmapSymbol;

renderer->renderEllipseSymbol = &agg2RenderEllipseSymbol;

renderer->renderTile = &agg2RenderTile;

renderer->mergeRasterBuffer = &agg2MergeRasterBuffer;
renderer->loadImageFromFile = msLoadMSRasterBufferFromFile;*/

renderer->getRasterBufferHandle = &skiaGetRasterBufferHandle;
renderer->getRasterBufferCopy = skiaGetRasterBufferCopy;
renderer->initializeRasterBuffer = skiaInitializeRasterBuffer;

renderer->renderLine = &skia2RenderLine;
renderer->renderPolygon = &skia2RenderPolygon;

renderer->startLayer = &skia2StartNewLayer;
renderer->endLayer = &skia2CloseNewLayer;

renderer->freeImage = &skia2FreeImage;
renderer->createImage = &skia2CreateImage;
renderer->saveImage = &skia2SaveImage;

renderer->freeSymbol = &skia2FreeSymbol;

return MS_SUCCESS;
}
Empty file added src/mapskia.h
Empty file.
1 change: 1 addition & 0 deletions src/mapwcs11.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static char *msWCSGetFormatsList11(mapObj *map, layerObj *layer)
switch (map->outputformatlist[i]->renderer) {
/* seeminly normal raster format */
case MS_RENDER_WITH_AGG:
case MS_RENDER_WITH_SKIA:
case MS_RENDER_WITH_RAWDATA:
tokens[numtokens++] = msStrdup(map->outputformatlist[i]->name);
break;
Expand Down
1 change: 1 addition & 0 deletions src/mapwcs20.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,7 @@ static char *msWCSGetFormatsList20(mapObj *map, layerObj *layer) {
switch (map->outputformatlist[i]->renderer) {
/* seemingly normal raster format */
case MS_RENDER_WITH_AGG:
case MS_RENDER_WITH_SKIA:
case MS_RENDER_WITH_RAWDATA:
tokens[numtokens++] = msStrdup(map->outputformatlist[i]->name);
break;
Expand Down

Back | FazBrowse Home | New Git URL