Skia Gpu renderer

This commit is contained in:
artemp 2013-07-23 14:03:22 +01:00
parent 21858be3ed
commit b1afb1d7bc
3 changed files with 43 additions and 34 deletions

View file

@ -46,10 +46,12 @@
#include <SkCanvas.h> #include <SkCanvas.h>
#include <SkBitmap.h> #include <SkBitmap.h>
#include <SkGpuDevice.h> #include <SkGpuDevice.h>
#include <gl/GrGLInterface.h>
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include <GrGLFunctions.h> #include <gl/GrGLFunctions.h>
#include <GrContextFactory.h> #include <GrContextFactory.h>
#include "/Users/artem/Projects/skia/trunk/src/gpu/gl/GrGLDefines.h"
#include "/Users/artem/Projects/skia/trunk/src/gpu/gl/GrGLUtil.h"
GrContextFactory gGrContextFactory; GrContextFactory gGrContextFactory;
#endif #endif
@ -124,6 +126,7 @@ MapWidget::MapWidget(QWidget *parent)
pen_.setJoinStyle(Qt::RoundJoin); pen_.setJoinStyle(Qt::RoundJoin);
} }
void MapWidget::setTool(eTool tool) void MapWidget::setTool(eTool tool)
{ {
cur_tool_=tool; cur_tool_=tool;
@ -550,6 +553,8 @@ void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
void render_skia(mapnik::Map const& map, double scaling_factor, QPixmap & pix) void render_skia(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{ {
boost::timer::auto_cpu_timer t;
unsigned width=map.width(); unsigned width=map.width();
unsigned height=map.height(); unsigned height=map.height();
@ -559,7 +564,7 @@ void render_skia(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
bitmap.setPixels(buf.raw_data()); bitmap.setPixels(buf.raw_data());
SkCanvas canvas(bitmap); SkCanvas canvas(bitmap);
boost::timer::auto_cpu_timer t;
mapnik::skia_renderer ren(map,canvas,scaling_factor); mapnik::skia_renderer ren(map,canvas,scaling_factor);
try try
{ {
@ -582,42 +587,35 @@ void render_skia(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
} }
void render_skia_gpu(mapnik::Map const& map, double scaling_factor, QPixmap & pix) void render_skia_gpu(GrGLInterface const * cur_interface, mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{ {
std::cerr << "SKIA GPU start " << cur_interface << std::endl ;
std::cerr << "SKIA GPU\n" ; boost::timer::auto_cpu_timer t;
unsigned width=map.width(); unsigned width=map.width();
unsigned height=map.height(); unsigned height=map.height();
mapnik::image_32 buf(width,height);
GrContext* context = GetGrContextFactory()->get(GrContextFactory::kNative_GLContextType); GrContext* context = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) cur_interface);
GrTextureDesc desc; GrBackendRenderTargetDesc desc;
desc.fConfig = kSkia8888_GrPixelConfig; desc.fConfig = kSkia8888_GrPixelConfig;
desc.fFlags = kRenderTarget_GrTextureFlagBit;
desc.fWidth = width; desc.fWidth = width;
desc.fHeight = height; desc.fHeight = height;
desc.fSampleCnt = 0; GR_GL_GetIntegerv(cur_interface, GR_GL_SAMPLES, &desc.fSampleCnt);
GrTexture* texture = context->createUncachedTexture(desc, 0, 0); GR_GL_GetIntegerv(cur_interface, GR_GL_STENCIL_BITS, &desc.fStencilBits);
if (texture) GrGLint buffer;
{ GR_GL_GetIntegerv(cur_interface, GR_GL_FRAMEBUFFER_BINDING, &buffer);
std::cerr << "texture: cache-size=" << context->getGpuTextureCacheBytes() << std::endl; desc.fRenderTargetHandle = buffer;
SkGpuDevice * device = SkGpuDevice::Create(texture); desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
if (device)
{ GrRenderTarget* curRenderTarget = context->wrapBackendRenderTarget(desc);
std::cerr << "device\n" ; SkGpuDevice device(context, curRenderTarget);
SkCanvas canvas(device); SkCanvas canvas(&device);
std::cerr << "render called\n" ;
mapnik::skia_renderer ren(map,canvas,scaling_factor); mapnik::skia_renderer ren(map,canvas,scaling_factor);
ren.apply(); ren.apply();
QImage image((uchar*)buf.raw_data(),width,height,QImage::Format_ARGB32); context->resetContext();
pix = QPixmap::fromImage(image.rgbSwapped()); context->flush();
std::cerr << "SKIA GPU Done" << std::endl;
device->unref();
}
texture->unref();
}
//context->flush();
//context->unref();
} }
@ -644,12 +642,19 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
void MapWidget::updateRenderer(QString const& txt) void MapWidget::updateRenderer(QString const& txt)
{ {
bool auto_swap = true;
if (txt == "AGG") cur_renderer_ = AGG; if (txt == "AGG") cur_renderer_ = AGG;
else if (txt == "Cairo") cur_renderer_ = Cairo; else if (txt == "Cairo") cur_renderer_ = Cairo;
else if (txt == "Grid") cur_renderer_ = Grid; else if (txt == "Grid") cur_renderer_ = Grid;
else if (txt == "Skia") cur_renderer_ = Skia; else if (txt == "Skia") cur_renderer_ = Skia;
else if (txt == "Skia-Gpu") cur_renderer_ = Skia_Gpu; else if (txt == "Skia-Gpu")
{
cur_renderer_ = Skia_Gpu;
auto_swap = false;
}
std::cerr << "Update renderer called" << std::endl; std::cerr << "Update renderer called" << std::endl;
setAutoBufferSwap(auto_swap);
updateMap(); updateMap();
} }
@ -681,7 +686,9 @@ void MapWidget::updateMap()
} }
else if (cur_renderer_ == Skia_Gpu) else if (cur_renderer_ == Skia_Gpu)
{ {
render_skia_gpu(*map_, scaling_factor_, pix_); GrGLInterface const* cur_interface = GrGLCreateNativeInterface();
render_skia_gpu(cur_interface, *map_, scaling_factor_, pix_);
swapBuffers();
} }
else else
{ {

View file

@ -36,6 +36,8 @@
#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#endif #endif
struct GrGLInterface;
class MapWidget : public QGLWidget class MapWidget : public QGLWidget
{ {
Q_OBJECT Q_OBJECT

View file

@ -12,7 +12,7 @@ QMAKE_CXXFLAGS += $$system(mapnik-config --includes --dep-includes)
QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/core" QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/core"
QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/config" QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/config"
QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/gpu" QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/gpu"
QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/gpu/gl" ## QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/gpu/gl"
QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/utils" QMAKE_CXXFLAGS += "-I/Users/artem/Projects/skia/trunk/include/utils"
QMAKE_LFLAGS += $$system(mapnik-config --libs) QMAKE_LFLAGS += $$system(mapnik-config --libs)